Revision 50862
Added by Panagiotis Kanakakis about 6 years ago
Converter.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.repo.manager.service.utils; |
2 | 2 |
|
3 |
import com.fasterxml.jackson.core.JsonProcessingException; |
|
4 | 3 |
import com.fasterxml.jackson.databind.ObjectMapper; |
5 | 4 |
import eu.dnetlib.domain.data.Repository; |
6 | 5 |
import eu.dnetlib.domain.data.RepositoryInterface; |
... | ... | |
22 | 21 |
public static Repository jsonToRepositoryObject(JSONObject repositoryObject) throws JSONException { |
23 | 22 |
|
24 | 23 |
Repository repository = new Repository(); |
25 |
|
|
24 |
|
|
25 |
|
|
26 |
LOGGER.debug("datasource response -> " + repositoryObject); |
|
26 | 27 |
JSONObject datasource = repositoryObject.getJSONObject("datasource"); |
27 | 28 |
|
28 | 29 |
if( datasource.equals(null)) |
... | ... | |
30 | 31 |
|
31 | 32 |
repository.setActivationId(datasource.get("activationId").toString()); |
32 | 33 |
repository.setAggregator(datasource.get("aggregator").toString()); |
33 |
// repository.setCertificates(datasource.get("certificates").toString());
|
|
34 |
// repository.setCitationGuidelineUrl(datasource.get("citationguidelineurl").toString());
|
|
34 |
repository.setCertificates(datasource.get("certificates").toString()); |
|
35 |
repository.setCitationGuidelineUrl(datasource.get("citationguidelineurl").toString()); |
|
35 | 36 |
repository.setCollectedFrom( datasource.get("collectedfrom").toString()); |
36 | 37 |
|
37 | 38 |
repository.setContactEmail(datasource.get("contactemail").toString()); |
38 | 39 |
if(repository.getContactEmail().equals("null")) |
39 | 40 |
repository.setContactEmail(""); |
40 | 41 |
|
41 |
// repository.setDatabaseAccessRestriction(datasource.get("databaseaccessrestriction").toString());
|
|
42 |
// repository.setDatabaseAccessType(datasource.get("databaseaccesstype").toString());
|
|
43 |
// repository.setDataUploadRestriction(datasource.get("datauploadrestriction").toString());
|
|
44 |
// repository.setDataUploadType(datasource.get("datauploadtype").toString());
|
|
42 |
repository.setDatabaseAccessRestriction(datasource.get("databaseaccessrestriction").toString()); |
|
43 |
repository.setDatabaseAccessType(datasource.get("databaseaccesstype").toString()); |
|
44 |
repository.setDataUploadRestriction(datasource.get("datauploadrestriction").toString()); |
|
45 |
repository.setDataUploadType(datasource.get("datauploadtype").toString()); |
|
45 | 46 |
repository.setDateOfCollection(convertStringToDate( datasource.get("dateofcollection").toString())); |
46 | 47 |
repository.setDateOfValidation(convertStringToDate( datasource.get("dateofvalidation").toString())); |
47 | 48 |
|
... | ... | |
68 | 69 |
|
69 | 70 |
repository.setLongitude(toDouble(datasource.get("longitude").toString())); |
70 | 71 |
//datasource.get("managed"); |
71 |
// repository.setMissionStatementUrl(datasource.get("missionstatementurl").toString());
|
|
72 |
repository.setMissionStatementUrl(datasource.get("missionstatementurl").toString()); |
|
72 | 73 |
repository.setNamespacePrefix(datasource.get("namespaceprefix").toString()); |
73 |
// repository.setOdContentTypes(datasource.get("od_contenttypes").toString());
|
|
74 |
repository.setOdContentTypes(datasource.get("od_contenttypes").toString()); |
|
74 | 75 |
repository.setOfficialName(datasource.get("officialname").toString()); |
75 | 76 |
if(repository.getOfficialName().equals("null")) |
76 | 77 |
repository.setOfficialName(""); |
77 | 78 |
|
78 |
// repository.setPidSystems(datasource.get("pidsystems").toString());
|
|
79 |
repository.setPidSystems(datasource.get("pidsystems").toString()); |
|
79 | 80 |
//datasource.get("platform"); |
80 |
// repository.setProvenanceActionClass( datasource.get("provenanceaction").toString());
|
|
81 |
// repository.setQualityManagementKind(datasource.get("qualitymanagementkind").toString());
|
|
81 |
repository.setProvenanceActionClass( datasource.get("provenanceaction").toString()); |
|
82 |
repository.setQualityManagementKind(datasource.get("qualitymanagementkind").toString()); |
|
82 | 83 |
repository.setRegisteredBy(datasource.get("registeredby").toString()); |
83 | 84 |
|
84 | 85 |
if(Objects.equals(repository.getRegisteredBy(),"null")) |
85 | 86 |
repository.setRegistered(true); |
86 | 87 |
|
87 |
// repository.setReleaseEndDate(convertStringToDate(datasource.get("releaseenddate").toString()));
|
|
88 |
// repository.setReleaseStartDate(convertStringToDate(datasource.get("releasestartdate").toString()));
|
|
89 |
// repository.setServiceProvider(Boolean.valueOf(datasource.get("serviceprovider").toString()));
|
|
88 |
repository.setReleaseEndDate(convertStringToDate(datasource.get("releaseenddate").toString())); |
|
89 |
repository.setReleaseStartDate(convertStringToDate(datasource.get("releasestartdate").toString())); |
|
90 |
repository.setServiceProvider(Boolean.valueOf(datasource.get("serviceprovider").toString())); |
|
90 | 91 |
//datasource.get("subjects"); |
91 | 92 |
Double timezone = toDouble(datasource.get("timezone").toString()); |
92 | 93 |
repository.setTimezone(timezone!=null?timezone:0.0); |
93 | 94 |
repository.setTypology(datasource.get("platform").toString()); |
94 |
// repository.setVersioning(Boolean.valueOf(datasource.get("versioning").toString()));
|
|
95 |
repository.setVersioning(Boolean.valueOf(datasource.get("versioning").toString())); |
|
95 | 96 |
repository.setWebsiteUrl(datasource.get("websiteurl").toString()); |
96 | 97 |
repository.setDatasourceClass(datasource.get("typology").toString()); |
97 | 98 |
|
98 | 99 |
//TODO change organization to list |
99 |
JSONArray organizations = ((JSONArray)datasource.get("organizations")); |
|
100 |
if(organizations.length() != 0) { |
|
101 |
repository.setOrganization(((JSONArray) datasource.get("organizations")).getJSONObject(0).get("legalname").toString()); |
|
102 |
String countryCode = ((JSONArray) datasource.get("organizations")).getJSONObject(0).get("country").toString(); |
|
103 |
repository.setCountryCode(countryCode); |
|
104 |
} |
|
100 |
repository.setOrganization( ((JSONArray)datasource.get("organizations")).getJSONObject(0).get("legalname").toString()); |
|
101 |
String countryCode = ((JSONArray)datasource.get("organizations")).getJSONObject(0).get("country").toString(); |
|
102 |
repository.setCountryCode(countryCode); |
|
105 | 103 |
|
106 |
|
|
104 |
|
|
107 | 105 |
String collectedFrom = datasource.get("collectedfrom").toString(); |
108 | 106 |
//TODO check data consistency |
109 | 107 |
String type = "UNKNOWN"; |
... | ... | |
114 | 112 |
} else if (collectedFrom.equalsIgnoreCase("infrastruct_::openaire")) { |
115 | 113 |
type = "journal"; |
116 | 114 |
} |
115 |
|
|
117 | 116 |
repository.setDatasourceType(type); |
117 |
|
|
118 |
|
|
118 | 119 |
return repository; |
119 | 120 |
} |
120 | 121 |
|
... | ... | |
159 | 160 |
return resultSet; |
160 | 161 |
} |
161 | 162 |
|
162 |
public static List<RepositoryInterface> jsonToRepositoryInterfaceList(JSONObject json) throws JSONException {
|
|
163 |
public static List<RepositoryInterface> jsonToRepositoryInterfaceList(JSONArray rs) throws JSONException {
|
|
163 | 164 |
|
164 | 165 |
List<RepositoryInterface> resultSet = new ArrayList<>(); |
165 |
JSONArray rs = json.getJSONArray("api"); |
|
166 | 166 |
for(int i=0;i<rs.length();i++) |
167 | 167 |
resultSet.add(jsonToRepositoryInterfaceObject( rs.getJSONObject(i)) ); |
168 | 168 |
return resultSet; |
... | ... | |
175 | 175 |
repositoryInterface.setBaseUrl(repositoryInterfaceObject.get("baseurl").toString()); |
176 | 176 |
repositoryInterface.setContentDescription(repositoryInterfaceObject.get("contentdescription").toString()); |
177 | 177 |
repositoryInterface.setId(repositoryInterfaceObject.get("id").toString()); |
178 |
// repositoryInterface.setMetadataIdentifierPath(repositoryInterfaceObject.get("metadataIdentifierPath").toString());
|
|
178 |
repositoryInterface.setMetadataIdentifierPath(repositoryInterfaceObject.get("metadataIdentifierPath").toString()); |
|
179 | 179 |
repositoryInterface.setAccessProtocol(repositoryInterfaceObject.get("protocol").toString()); |
180 | 180 |
repositoryInterface.setTypology(repositoryInterfaceObject.get("typology").toString()); |
181 | 181 |
repositoryInterface.setDesiredCompatibilityLevel(repositoryInterfaceObject.get("compatibility").toString()); |
182 |
//repositoryInterface.setActive(Boolean.parseBoolean(repositoryInterfaceObject.get("active").toString()));
|
|
182 |
repositoryInterface.setActive(Boolean.parseBoolean(repositoryInterfaceObject.get("active").toString())); |
|
183 | 183 |
repositoryInterface.setRemovable(Boolean.parseBoolean(repositoryInterfaceObject.get("removable").toString())); |
184 | 184 |
repositoryInterface.setCompliance(repositoryInterfaceObject.get("compatibility").toString()); |
185 | 185 |
|
... | ... | |
187 | 187 |
Map<String, String> extraFields = new HashMap<>(); |
188 | 188 |
|
189 | 189 |
ObjectMapper mapper = new ObjectMapper(); |
190 |
JSONArray apiparams = repositoryInterfaceObject.getJSONArray("apiParams");
|
|
190 |
JSONArray apiparams = repositoryInterfaceObject.getJSONArray("apiparam");
|
|
191 | 191 |
|
192 | 192 |
for(int i=0;i<apiparams.length();i++) |
193 | 193 |
accessParams.put(apiparams.getJSONObject(i).getString("param"),apiparams.getJSONObject(i).getString("value")); |
... | ... | |
302 | 302 |
return list; |
303 | 303 |
} |
304 | 304 |
|
305 |
public static List<AggregationDetails> getAggregationHistoryFromJson(JSONObject datasourceInfo) throws JSONException {
|
|
305 |
public static List<AggregationDetails> getAggregationHistoryFromJson(JSONObject repositoryObject) throws JSONException {
|
|
306 | 306 |
|
307 |
|
|
308 |
if(datasourceInfo.get("aggregationHistory").toString().equals("[]")) |
|
307 |
/* if( repositoryObject.get("aggregationHistory").toString().equals("[]") || |
|
308 |
repositoryObject.get("aggregationHistory")!= null) |
|
309 |
return null;*/ |
|
310 |
if(repositoryObject.get("aggregationHistory").toString().equals("[]")) |
|
309 | 311 |
return null; |
310 | 312 |
|
311 |
JSONArray rs = new JSONArray(datasourceInfo.get("aggregationHistory").toString()); |
|
313 |
|
|
314 |
JSONArray rs = new JSONArray(repositoryObject.get("aggregationHistory").toString()); |
|
315 |
|
|
316 |
LOGGER.debug(rs.length()); |
|
317 |
|
|
312 | 318 |
List<AggregationDetails> aggregationDetailsList = new ArrayList<>(); |
313 | 319 |
for(int i=0;i<rs.length();i++) |
314 | 320 |
aggregationDetailsList.add(jsonToAggregationDetails(rs.getJSONObject(i))); |
... | ... | |
327 | 333 |
return aggregationDetails; |
328 | 334 |
} |
329 | 335 |
|
330 |
public static AggregationDetails getLastCollectionFromJson(JSONObject datasourceInfo) throws JSONException {
|
|
336 |
public static AggregationDetails getLastCollectionFromJson(JSONObject repositoryObject) throws JSONException {
|
|
331 | 337 |
|
332 |
if( datasourceInfo.get("lastCollection").equals(null))
|
|
338 |
if( repositoryObject.get("lastCollection").equals(null))
|
|
333 | 339 |
return null; |
334 | 340 |
|
335 |
return jsonToAggregationDetails(datasourceInfo.getJSONObject("lastCollection"));
|
|
341 |
return jsonToAggregationDetails(repositoryObject.getJSONObject("lastCollection"));
|
|
336 | 342 |
} |
337 | 343 |
|
338 |
public static AggregationDetails getLastTransformationFromJson(JSONObject datasourceInfo) throws JSONException {
|
|
344 |
public static AggregationDetails getLastTransformationFromJson(JSONObject repositoryObject) throws JSONException {
|
|
339 | 345 |
|
340 |
if( datasourceInfo.get("lastTransformation").equals(null))
|
|
346 |
if( repositoryObject.get("lastTransformation").equals(null))
|
|
341 | 347 |
return null; |
342 | 348 |
|
343 |
return jsonToAggregationDetails(datasourceInfo.getJSONObject("lastTransformation"));
|
|
349 |
return jsonToAggregationDetails(repositoryObject.getJSONObject("lastTransformation"));
|
|
344 | 350 |
} |
345 | 351 |
|
346 | 352 |
public static List<Timezone> toTimezones(List<String> timezones) { |
Also available in: Unified diff
Moving branch folders to trunk.