Project

General

Profile

1
package eu.dnetlib.enabling.datasources.common;
2

    
3
import java.sql.Timestamp;
4
import java.util.Objects;
5
import java.util.Set;
6

    
7
import javax.persistence.CascadeType;
8
import javax.persistence.Column;
9
import javax.persistence.FetchType;
10
import javax.persistence.Id;
11
import javax.persistence.MappedSuperclass;
12
import javax.persistence.OneToMany;
13
import javax.persistence.Transient;
14

    
15
import com.google.common.collect.ComparisonChain;
16
import com.google.common.collect.Sets;
17
import com.google.gson.Gson;
18

    
19
/**
20
 * Api
21
 */
22
@MappedSuperclass
23
public class Api<AP extends ApiParam> implements Comparable<Api<AP>> {
24

    
25
	@Id
26
	protected String id = null;
27
	protected String protocol = null;
28
	protected String datasource = null;
29
	protected String contentdescription = null;
30
	protected Boolean active = false;
31
	protected Boolean removable = true;
32
	protected String typology = null;
33
	protected String compatibility;
34

    
35
	@Transient
36
	protected boolean compatibilityOverrided = false;
37

    
38
	@Column(name = "metadata_identifier_path")
39
	protected String metadataIdentifierPath;
40

    
41
	@Column(name = "last_collection_total")
42
	protected Integer lastCollectionTotal;
43

    
44
	@Column(name = "last_collection_date")
45
	protected Timestamp lastCollectionDate;
46

    
47
	@Column(name = "last_collection_mdid")
48
	protected String lastCollectionMdid;
49

    
50
	@Column(name = "last_aggregation_total")
51
	protected Integer lastAggregationTotal;
52

    
53
	@Column(name = "last_aggregation_date")
54
	protected Timestamp lastAggregationDate;
55

    
56
	@Column(name = "last_aggregation_mdid")
57
	protected String lastAggregationMdid;
58

    
59
	@Column(name = "last_download_total")
60
	protected Integer lastDownloadTotal;
61

    
62
	@Column(name = "last_download_date")
63
	protected Timestamp lastDownloadDate;
64

    
65
	@Column(name = "last_download_objid")
66
	protected String lastDownloadObjid;
67

    
68
	@Column(name = "last_validation_job")
69
	protected String lastValidationJob;
70
	protected String baseurl = null;
71

    
72
	@OneToMany(mappedBy = "id.api", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
73
	protected Set<AP> apiParams = Sets.newHashSet();
74

    
75
	public Api() {}
76

    
77
	public String getId() {
78
		return id;
79
	}
80

    
81
	public String getProtocol() {
82
		return protocol;
83
	}
84

    
85
	public String getDatasource() {
86
		return datasource;
87
	}
88

    
89
	public String getContentdescription() {
90
		return contentdescription;
91
	}
92

    
93
	public Boolean getActive() {
94
		return active;
95
	}
96

    
97
	public Boolean getRemovable() {
98
		return removable;
99
	}
100

    
101
	public String getTypology() {
102
		return typology;
103
	}
104

    
105
	public String getCompatibility() {
106
		return compatibility;
107
	}
108

    
109
	public boolean isCompatibilityOverrided() {
110
		return compatibilityOverrided;
111
	}
112

    
113
	public String getMetadataIdentifierPath() {
114
		return metadataIdentifierPath;
115
	}
116

    
117
	public Integer getLastCollectionTotal() {
118
		return lastCollectionTotal;
119
	}
120

    
121
	public Timestamp getLastCollectionDate() {
122
		return lastCollectionDate;
123
	}
124

    
125
	public String getLastCollectionMdid() {
126
		return lastCollectionMdid;
127
	}
128

    
129
	public Integer getLastAggregationTotal() {
130
		return lastAggregationTotal;
131
	}
132

    
133
	public Timestamp getLastAggregationDate() {
134
		return lastAggregationDate;
135
	}
136

    
137
	public String getLastAggregationMdid() {
138
		return lastAggregationMdid;
139
	}
140

    
141
	public Integer getLastDownloadTotal() {
142
		return lastDownloadTotal;
143
	}
144

    
145
	public Timestamp getLastDownloadDate() {
146
		return lastDownloadDate;
147
	}
148

    
149
	public String getLastDownloadObjid() {
150
		return lastDownloadObjid;
151
	}
152

    
153
	public String getLastValidationJob() {
154
		return lastValidationJob;
155
	}
156

    
157
	public String getBaseurl() {
158
		return baseurl;
159
	}
160

    
161
	public Set<AP> getApiParams() {
162
		return apiParams;
163
	}
164

    
165
	public Api<AP> setId(final String id) {
166
		this.id = id;
167
		return this;
168
	}
169

    
170
	public Api<AP> setProtocol(final String protocol) {
171
		this.protocol = protocol;
172
		return this;
173
	}
174

    
175
	public Api<AP> setDatasource(final String datasource) {
176
		this.datasource = datasource;
177
		return this;
178
	}
179

    
180
	public Api<AP> setContentdescription(final String contentdescription) {
181
		this.contentdescription = contentdescription;
182
		return this;
183
	}
184

    
185
	public Api<AP> setActive(final Boolean active) {
186
		this.active = active;
187
		return this;
188
	}
189

    
190
	public Api<AP> setRemovable(final Boolean removable) {
191
		this.removable = removable;
192
		return this;
193
	}
194

    
195
	public Api<AP> setTypology(final String typology) {
196
		this.typology = typology;
197
		return this;
198
	}
199

    
200
	public Api<AP> setCompatibility(final String compatibility) {
201
		this.compatibility = compatibility;
202
		return this;
203
	}
204

    
205
	public Api<AP> setCompatibilityOverrided(final boolean compatibilityOverrided) {
206
		this.compatibilityOverrided = compatibilityOverrided;
207
		return this;
208
	}
209

    
210
	public Api<AP> setMetadataIdentifierPath(final String metadataIdentifierPath) {
211
		this.metadataIdentifierPath = metadataIdentifierPath;
212
		return this;
213
	}
214

    
215
	public Api<AP> setLastCollectionTotal(final Integer lastCollectionTotal) {
216
		this.lastCollectionTotal = lastCollectionTotal;
217
		return this;
218
	}
219

    
220
	public Api<AP> setLastCollectionDate(final Timestamp lastCollectionDate) {
221
		this.lastCollectionDate = lastCollectionDate;
222
		return this;
223
	}
224

    
225
	public Api<AP> setLastCollectionMdid(final String lastCollectionMdid) {
226
		this.lastCollectionMdid = lastCollectionMdid;
227
		return this;
228
	}
229

    
230
	public Api<AP> setLastAggregationTotal(final Integer lastAggregationTotal) {
231
		this.lastAggregationTotal = lastAggregationTotal;
232
		return this;
233
	}
234

    
235
	public Api<AP> setLastAggregationDate(final Timestamp lastAggregationDate) {
236
		this.lastAggregationDate = lastAggregationDate;
237
		return this;
238
	}
239

    
240
	public Api<AP> setLastAggregationMdid(final String lastAggregationMdid) {
241
		this.lastAggregationMdid = lastAggregationMdid;
242
		return this;
243
	}
244

    
245
	public Api<AP> setLastDownloadTotal(final Integer lastDownloadTotal) {
246
		this.lastDownloadTotal = lastDownloadTotal;
247
		return this;
248
	}
249

    
250
	public Api<AP> setLastDownloadDate(final Timestamp lastDownloadDate) {
251
		this.lastDownloadDate = lastDownloadDate;
252
		return this;
253
	}
254

    
255
	public Api<AP> setLastDownloadObjid(final String lastDownloadObjid) {
256
		this.lastDownloadObjid = lastDownloadObjid;
257
		return this;
258
	}
259

    
260
	public Api<AP> setLastValidationJob(final String lastValidationJob) {
261
		this.lastValidationJob = lastValidationJob;
262
		return this;
263
	}
264

    
265
	public Api<AP> setBaseurl(final String baseurl) {
266
		this.baseurl = baseurl;
267
		return this;
268
	}
269

    
270
	public Api<AP> setApiParams(final Set<AP> apiParams) {
271
		this.apiParams = apiParams;
272
		return this;
273
	}
274

    
275
	@Override
276
	public boolean equals(final Object o) {
277
		if (this == o) { return true; }
278
		if (o == null || getClass() != o.getClass()) { return false; }
279
		final Api<?> api = (Api<?>) o;
280
		return Objects.equals(this.id, api.id);
281
	}
282

    
283
	/*
284
	 * (non-Javadoc)
285
	 *
286
	 * @see eu.dnetlib.openaire.exporter.model.datasource.db.ApiInterface#hashCode()
287
	 */
288

    
289
	@Override
290
	public int hashCode() {
291
		return Objects.hash(id);
292
	}
293

    
294
	@Override
295
	public String toString() {
296
		return new Gson().toJson(this);
297
	}
298

    
299
	@Override
300
	public int compareTo(final Api<AP> a) {
301
		return ComparisonChain.start()
302
				.compare(getId(), a.getId())
303
				.result();
304
	}
305

    
306
}
(3-3/20)