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
import javax.persistence.*;
7

    
8
import com.google.common.collect.ComparisonChain;
9
import com.google.gson.Gson;
10

    
11
/**
12
 * Api
13
 */
14
@MappedSuperclass
15
public class Api<AP extends ApiParam> implements Comparable<Api<AP>> {
16

    
17
	@Id
18
	protected String id = null;
19
	protected String protocol = null;
20
	protected String datasource = null;
21
	protected String contentdescription = null;
22
	protected Boolean active = false;
23
	protected Boolean removable = false;
24
	protected String typology = null;
25
	protected String compatibility;
26

    
27
	@Transient
28
	protected boolean compatibilityOverrided = false;
29

    
30
	@Column(name = "metadata_identifier_path")
31
	protected String metadataIdentifierPath;
32

    
33
	@Column(name = "last_collection_total")
34
	protected Integer lastCollectionTotal;
35

    
36
	@Column(name = "last_collection_date")
37
	protected Timestamp lastCollectionDate;
38

    
39
	@Column(name = "last_collection_mdid")
40
	protected String lastCollectionMdid;
41

    
42
	@Column(name = "last_aggregation_total")
43
	protected Integer lastAggregationTotal;
44

    
45
	@Column(name = "last_aggregation_date")
46
	protected Timestamp lastAggregationDate;
47

    
48
	@Column(name = "last_aggregation_mdid")
49
	protected String lastAggregationMdid;
50

    
51
	@Column(name = "last_download_total")
52
	protected Integer lastDownloadTotal;
53

    
54
	@Column(name = "last_download_date")
55
	protected Timestamp lastDownloadDate;
56

    
57
	@Column(name = "last_download_objid")
58
	protected String lastDownloadObjid;
59

    
60
	@Column(name = "last_validation_job")
61
	protected String lastValidationJob;
62
	protected String baseurl = null;
63

    
64
	@OneToMany(mappedBy = "id.api", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
65
	protected Set<AP> apiParams;
66

    
67
	public Api() {}
68

    
69
	public String getId() {
70
		return id;
71
	}
72

    
73
	public String getProtocol() {
74
		return protocol;
75
	}
76

    
77
	public String getDatasource() {
78
		return datasource;
79
	}
80

    
81
	public String getContentdescription() {
82
		return contentdescription;
83
	}
84

    
85
	public Boolean getActive() {
86
		return active;
87
	}
88

    
89
	public Boolean getRemovable() {
90
		return removable;
91
	}
92

    
93
	public String getTypology() {
94
		return typology;
95
	}
96

    
97
	public String getCompatibility() {
98
		return compatibility;
99
	}
100

    
101
	public boolean isCompatibilityOverrided() {
102
		return compatibilityOverrided;
103
	}
104

    
105
	public String getMetadataIdentifierPath() {
106
		return metadataIdentifierPath;
107
	}
108

    
109
	public Integer getLastCollectionTotal() {
110
		return lastCollectionTotal;
111
	}
112

    
113
	public Timestamp getLastCollectionDate() {
114
		return lastCollectionDate;
115
	}
116

    
117
	public String getLastCollectionMdid() {
118
		return lastCollectionMdid;
119
	}
120

    
121
	public Integer getLastAggregationTotal() {
122
		return lastAggregationTotal;
123
	}
124

    
125
	public Timestamp getLastAggregationDate() {
126
		return lastAggregationDate;
127
	}
128

    
129
	public String getLastAggregationMdid() {
130
		return lastAggregationMdid;
131
	}
132

    
133
	public Integer getLastDownloadTotal() {
134
		return lastDownloadTotal;
135
	}
136

    
137
	public Timestamp getLastDownloadDate() {
138
		return lastDownloadDate;
139
	}
140

    
141
	public String getLastDownloadObjid() {
142
		return lastDownloadObjid;
143
	}
144

    
145
	public String getLastValidationJob() {
146
		return lastValidationJob;
147
	}
148

    
149
	public String getBaseurl() {
150
		return baseurl;
151
	}
152

    
153
	public Set<AP> getApiParams() {
154
		return apiParams;
155
	}
156

    
157
	public Api<AP> setId(final String id) {
158
		this.id = id;
159
		return this;
160
	}
161

    
162
	public Api<AP> setProtocol(final String protocol) {
163
		this.protocol = protocol;
164
		return this;
165
	}
166

    
167
	public Api<AP> setDatasource(final String datasource) {
168
		this.datasource = datasource;
169
		return this;
170
	}
171

    
172
	public Api<AP> setContentdescription(final String contentdescription) {
173
		this.contentdescription = contentdescription;
174
		return this;
175
	}
176

    
177
	public Api<AP> setActive(final Boolean active) {
178
		this.active = active;
179
		return this;
180
	}
181

    
182
	public Api<AP> setRemovable(final Boolean removable) {
183
		this.removable = removable;
184
		return this;
185
	}
186

    
187
	public Api<AP> setTypology(final String typology) {
188
		this.typology = typology;
189
		return this;
190
	}
191

    
192
	public Api<AP> setCompatibility(final String compatibility) {
193
		this.compatibility = compatibility;
194
		return this;
195
	}
196

    
197
	public Api<AP> setCompatibilityOverrided(final boolean compatibilityOverrided) {
198
		this.compatibilityOverrided = compatibilityOverrided;
199
		return this;
200
	}
201

    
202
	public Api<AP> setMetadataIdentifierPath(final String metadataIdentifierPath) {
203
		this.metadataIdentifierPath = metadataIdentifierPath;
204
		return this;
205
	}
206

    
207
	public Api<AP> setLastCollectionTotal(final Integer lastCollectionTotal) {
208
		this.lastCollectionTotal = lastCollectionTotal;
209
		return this;
210
	}
211

    
212
	public Api<AP> setLastCollectionDate(final Timestamp lastCollectionDate) {
213
		this.lastCollectionDate = lastCollectionDate;
214
		return this;
215
	}
216

    
217
	public Api<AP> setLastCollectionMdid(final String lastCollectionMdid) {
218
		this.lastCollectionMdid = lastCollectionMdid;
219
		return this;
220
	}
221

    
222
	public Api<AP> setLastAggregationTotal(final Integer lastAggregationTotal) {
223
		this.lastAggregationTotal = lastAggregationTotal;
224
		return this;
225
	}
226

    
227
	public Api<AP> setLastAggregationDate(final Timestamp lastAggregationDate) {
228
		this.lastAggregationDate = lastAggregationDate;
229
		return this;
230
	}
231

    
232
	public Api<AP> setLastAggregationMdid(final String lastAggregationMdid) {
233
		this.lastAggregationMdid = lastAggregationMdid;
234
		return this;
235
	}
236

    
237
	public Api<AP> setLastDownloadTotal(final Integer lastDownloadTotal) {
238
		this.lastDownloadTotal = lastDownloadTotal;
239
		return this;
240
	}
241

    
242
	public Api<AP> setLastDownloadDate(final Timestamp lastDownloadDate) {
243
		this.lastDownloadDate = lastDownloadDate;
244
		return this;
245
	}
246

    
247
	public Api<AP> setLastDownloadObjid(final String lastDownloadObjid) {
248
		this.lastDownloadObjid = lastDownloadObjid;
249
		return this;
250
	}
251

    
252
	public Api<AP> setLastValidationJob(final String lastValidationJob) {
253
		this.lastValidationJob = lastValidationJob;
254
		return this;
255
	}
256

    
257
	public Api<AP> setBaseurl(final String baseurl) {
258
		this.baseurl = baseurl;
259
		return this;
260
	}
261

    
262
	public Api<AP> setApiParams(final Set<AP> apiParams) {
263
		this.apiParams = apiParams;
264
		return this;
265
	}
266

    
267
	@Override
268
	public boolean equals(final Object o) {
269
		if (this == o) { return true; }
270
		if (o == null || getClass() != o.getClass()) { return false; }
271
		final Api<?> api = (Api<?>) o;
272
		return Objects.equals(this.id, api.id);
273
	}
274

    
275
	/*
276
	 * (non-Javadoc)
277
	 *
278
	 * @see eu.dnetlib.openaire.exporter.model.datasource.db.ApiInterface#hashCode()
279
	 */
280

    
281
	@Override
282
	public int hashCode() {
283
		return Objects.hash(id);
284
	}
285

    
286
	@Override
287
	public String toString() {
288
		return new Gson().toJson(this);
289
	}
290

    
291
	@Override
292
	public int compareTo(final Api<AP> a) {
293
		return ComparisonChain.start()
294
				.compare(getId(), a.getId())
295
				.result();
296
	}
297

    
298
}
(3-3/20)