Project

General

Profile

1 54525 panagiotis
package eu.dnetlib.repo.manager.utils;
2 49236 panagiotis
3 54457 panagiotis
import com.fasterxml.jackson.core.JsonProcessingException;
4 50051 panagiotis
import com.fasterxml.jackson.databind.ObjectMapper;
5 49236 panagiotis
import eu.dnetlib.domain.data.Repository;
6
import eu.dnetlib.domain.data.RepositoryInterface;
7 57890 ioannis.di
import eu.dnetlib.repo.manager.domain.AggregationDetails;
8 54525 panagiotis
import eu.dnetlib.repo.manager.domain.RepositorySnippet;
9 57741 ioannis.di
import eu.dnetlib.repo.manager.domain.Timezone;
10 51330 panagiotis
import org.apache.commons.codec.digest.DigestUtils;
11 49763 panagiotis
import org.apache.log4j.Logger;
12 49236 panagiotis
import org.json.JSONArray;
13 49362 panagiotis
import org.json.JSONException;
14 49236 panagiotis
import org.json.JSONObject;
15 61441 antonis.le
import org.springframework.stereotype.Component;
16 49236 panagiotis
17 51330 panagiotis
import java.io.BufferedReader;
18
import java.io.IOException;
19
import java.io.InputStream;
20
import java.io.InputStreamReader;
21 49236 panagiotis
import java.text.ParseException;
22
import java.text.SimpleDateFormat;
23
import java.util.*;
24
25 61441 antonis.le
@Component
26 49236 panagiotis
public class Converter {
27
28 49763 panagiotis
    private static final Logger LOGGER = Logger.getLogger(Converter.class);
29 51330 panagiotis
30 62318 antonis.le
    public Repository toRepository(JSONObject repositoryObject) throws JSONException {
31 49763 panagiotis
32 49236 panagiotis
        Repository repository = new Repository();
33 61441 antonis.le
34 62020 spyroukon
//        JSONObject datasource = repositoryObject.getJSONObject("datasource");
35
        JSONObject datasource = repositoryObject;
36 49236 panagiotis
37 52781 panagiotis
        //if( datasource.equals(null))
38
        //    return null;
39 49898 panagiotis
40 51525 panagiotis
        repository.setId(datasource.get("id").toString());
41
        repository.setOfficialName(datasource.get("officialname").toString());
42 49898 panagiotis
43 61441 antonis.le
        repository.setEnglishName(datasource.get("englishname").toString());
44
        if (repository.getEnglishName().equals("null"))
45 49898 panagiotis
            repository.setEnglishName("");
46
47 51525 panagiotis
        repository.setWebsiteUrl(datasource.get("websiteurl").toString());
48 61441 antonis.le
        if (repository.getWebsiteUrl().equals("null"))
49 51549 panagiotis
            repository.setWebsiteUrl("");
50
51 49236 panagiotis
        repository.setLogoUrl(datasource.get("logourl").toString());
52 61441 antonis.le
        if (repository.getLogoUrl().equals("null"))
53 49898 panagiotis
            repository.setLogoUrl("");
54
55 51525 panagiotis
        repository.setContactEmail(datasource.get("contactemail").toString());
56 61441 antonis.le
        if (repository.getContactEmail().equals("null"))
57 51549 panagiotis
            repository.setContactEmail("");
58
59
60 61441 antonis.le
        repository.setLatitude(toDouble(datasource.get("latitude").toString()));
61 49236 panagiotis
        repository.setLongitude(toDouble(datasource.get("longitude").toString()));
62 51525 panagiotis
        Double timezone = toDouble(datasource.get("timezone").toString());
63 61441 antonis.le
        repository.setTimezone(timezone != null ? timezone : 0.0);
64 49236 panagiotis
        repository.setNamespacePrefix(datasource.get("namespaceprefix").toString());
65 51525 panagiotis
        repository.setOdLanguages(datasource.get("languages").toString());
66 62318 antonis.le
        repository.setDateOfValidation(toDate(datasource.get("dateofvalidation").toString()));
67 49898 panagiotis
68 51525 panagiotis
        /*  typology -> platform
69
         *  datasource class -> typology */
70
        repository.setTypology(datasource.get("platform").toString());
71 61441 antonis.le
        if (repository.getTypology().equals("null"))
72 51525 panagiotis
            repository.setTypology("");
73 62267 spyroukon
74
//        // TODO: enable in future release
75
//        /* 07-04-2022 | "typology" -> "eoscDatasourceType" */
76
//        try { // FIXME: remove attemp to get typology if eoscDatasourceType fails
77
//            repository.setDatasourceClass(datasource.get("eoscDatasourceType").toString());
78
//        } catch (JSONException e) {
79
//            repository.setDatasourceClass(datasource.get("typology").toString());
80
//        }
81 51525 panagiotis
        repository.setDatasourceClass(datasource.get("typology").toString());
82 62267 spyroukon
//        <--
83 51525 panagiotis
84 62318 antonis.le
        repository.setDateOfCollection(toDate(datasource.get("dateofcollection").toString()));
85 51525 panagiotis
        repository.setActivationId(datasource.get("activationId").toString());
86
87
        repository.setDescription(datasource.get("description").toString());
88 61441 antonis.le
        if (repository.getDescription().equals("null"))
89 51525 panagiotis
            repository.setDescription("");
90
91
        repository.setIssn(datasource.get("issn").toString());
92
        repository.setLissn(datasource.get("lissn").toString());
93 61441 antonis.le
        if (repository.getLissn().equals("null"))
94 51549 panagiotis
            repository.setLissn("");
95 51525 panagiotis
        repository.setEissn(datasource.get("eissn").toString());
96 61441 antonis.le
        if (repository.getEissn().equals("null"))
97 51549 panagiotis
            repository.setEissn("");
98 49236 panagiotis
        repository.setRegisteredBy(datasource.get("registeredby").toString());
99 50219 panagiotis
100 51525 panagiotis
        /* managed field */
101
        repository.setRegistered(Boolean.parseBoolean(datasource.get("managed").toString()));
102 50219 panagiotis
103 51525 panagiotis
        //subjects
104 51549 panagiotis
105 51525 panagiotis
        repository.setAggregator(datasource.get("aggregator").toString());
106 51549 panagiotis
        repository.setCollectedFrom(datasource.get("collectedfrom").toString());
107 49898 panagiotis
108 51525 panagiotis
        //TODO change organization to list
109 61441 antonis.le
        JSONArray organizations = ((JSONArray) datasource.get("organizations"));
110
        if (organizations.length() != 0) {
111 51525 panagiotis
            repository.setOrganization(((JSONArray) datasource.get("organizations")).getJSONObject(0).get("legalname").toString());
112
            String countryCode = ((JSONArray) datasource.get("organizations")).getJSONObject(0).get("country").toString();
113
            repository.setCountryCode(countryCode);
114
        }
115
116 62020 spyroukon
        repository.setConsentTermsOfUse(convertStringToBoolean(datasource.get("consentTermsOfUse").toString()));
117 62267 spyroukon
        repository.setConsentTermsOfUseDate(null);
118
        repository.setLastConsentTermsOfUseDate(null);
119 62020 spyroukon
        try {
120 62318 antonis.le
            repository.setConsentTermsOfUseDate(toDate(datasource.get("consentTermsOfUseDate").toString()));
121
            repository.setLastConsentTermsOfUseDate(toDate(datasource.get("lastConsentTermsOfUseDate").toString()));
122 62020 spyroukon
        } catch (JSONException e) {
123 62318 antonis.le
            LOGGER.error("Error setting consentTermsOfUseDate date and lastConsentTermsOfUseDate", e);
124 62020 spyroukon
        }
125
        repository.setFullTextDownload(convertStringToBoolean(datasource.get("fullTextDownload").toString()));
126
127 51525 panagiotis
        /* identities field  */
128
129 49236 panagiotis
        return repository;
130
    }
131
132 62318 antonis.le
    public List<RepositorySnippet> jsonToRepositorySnippetList(JSONObject json) throws JSONException {
133 62020 spyroukon
134 53113 panagiotis
        List<RepositorySnippet> resultSet = new ArrayList<>();
135
        JSONArray rs = json.getJSONArray("datasourceInfo");
136 61441 antonis.le
        for (int i = 0; i < rs.length(); i++)
137 62318 antonis.le
            resultSet.add(toRepositorySnippet(rs.getJSONObject(i)));
138 53113 panagiotis
        return resultSet;
139
    }
140
141 62318 antonis.le
    public RepositorySnippet toRepositorySnippet(JSONObject repositorySnippetObject) throws JSONException {
142 53113 panagiotis
143
144
        RepositorySnippet repositorySnippet = new RepositorySnippet();
145
146
//        JSONObject datasource = repositorySnippetObject.getJSONObject("datasource");
147
148
149
        repositorySnippet.setId(repositorySnippetObject.get("id").toString());
150
        repositorySnippet.setOfficialname(repositorySnippetObject.get("officialname").toString());
151
152 61441 antonis.le
        repositorySnippet.setEnglishname(repositorySnippetObject.get("englishname").toString());
153
        if (repositorySnippet.getEnglishname().equals("null"))
154 53113 panagiotis
            repositorySnippet.setEnglishname("");
155
156
        repositorySnippet.setWebsiteurl(repositorySnippetObject.get("websiteurl").toString());
157 61441 antonis.le
        if (repositorySnippet.getWebsiteurl().equals("null"))
158 53113 panagiotis
            repositorySnippet.setWebsiteurl("");
159
160
        repositorySnippet.setRegisteredby(repositorySnippetObject.get("registeredby").toString());
161 61441 antonis.le
        if (repositorySnippet.getRegisteredby().equals("null"))
162 53113 panagiotis
            repositorySnippet.setRegisteredby("");
163 62020 spyroukon
164
        repositorySnippet.setConsentTermsOfUse(repositorySnippetObject.get("consenttermsofuse").toString());
165
        repositorySnippet.setFullTextDownload(repositorySnippetObject.get("fulltextdownload").toString());
166 62318 antonis.le
        repositorySnippet.setConsentTermsOfUseDate(toDate(repositorySnippetObject.get("consenttermsofusedate").toString()));
167 62020 spyroukon
168 53113 panagiotis
        return repositorySnippet;
169
170
    }
171
172 62318 antonis.le
    public List<Repository> toRepositoryList(JSONObject json) throws JSONException {
173 49236 panagiotis
174
        List<Repository> resultSet = new ArrayList<>();
175 50219 panagiotis
        JSONArray rs = json.getJSONArray("datasourceInfo");
176 61441 antonis.le
        for (int i = 0; i < rs.length(); i++)
177 62318 antonis.le
            resultSet.add(toRepository(rs.getJSONObject(i)));
178 49236 panagiotis
        return resultSet;
179
    }
180
181 62318 antonis.le
    public List<RepositoryInterface> toRepositoryInterfaceList(JSONObject json) throws JSONException {
182 49988 panagiotis
183
        List<RepositoryInterface> resultSet = new ArrayList<>();
184 50631 panagiotis
        JSONArray rs = json.getJSONArray("api");
185 61441 antonis.le
        for (int i = 0; i < rs.length(); i++)
186 62318 antonis.le
            resultSet.add(toRepositoryInterface(rs.getJSONObject(i)));
187 49988 panagiotis
        return resultSet;
188
    }
189
190 62318 antonis.le
    public RepositoryInterface toRepositoryInterface(JSONObject repositoryInterfaceObject) throws JSONException {
191 49236 panagiotis
192
        RepositoryInterface repositoryInterface = new RepositoryInterface();
193
194 49763 panagiotis
        repositoryInterface.setId(repositoryInterfaceObject.get("id").toString());
195
        repositoryInterface.setAccessProtocol(repositoryInterfaceObject.get("protocol").toString());
196 51525 panagiotis
        repositoryInterface.setContentDescription(repositoryInterfaceObject.get("contentdescription").toString());
197 62267 spyroukon
198
        //        /* 07-04-2022 | "typology" -> "eoscDatasourceType" */
199
//        // TODO: enable in future release
200
//        try { // FIXME: remove attemp to get typology if eoscDatasourceType fails
201
//            repositoryInterface.setTypology(repositoryInterfaceObject.get("eoscDatasourceType").toString());
202
//        } catch (JSONException e) {
203
//            repositoryInterface.setTypology(repositoryInterfaceObject.get("typology").toString());
204
//        }
205 49763 panagiotis
        repositoryInterface.setTypology(repositoryInterfaceObject.get("typology").toString());
206 62267 spyroukon
//        <--
207
208 50051 panagiotis
        repositoryInterface.setCompliance(repositoryInterfaceObject.get("compatibility").toString());
209 51330 panagiotis
        repositoryInterface.setLastCollectionDate(repositoryInterfaceObject.get("lastCollectionDate").toString());
210 49236 panagiotis
211 51525 panagiotis
        repositoryInterface.setBaseUrl(repositoryInterfaceObject.get("baseurl").toString());
212
        repositoryInterface.setRemovable(Boolean.parseBoolean(repositoryInterfaceObject.get("removable").toString()));
213 51330 panagiotis
214 51525 panagiotis
215 61441 antonis.le
        // repositoryInterface.setMetadataIdentifierPath(repositoryInterfaceObject.get("metadataIdentifierPath").toString());
216 51525 panagiotis
        repositoryInterface.setDesiredCompatibilityLevel(repositoryInterfaceObject.get("compatibility").toString());
217
        //repositoryInterface.setActive(Boolean.parseBoolean(repositoryInterfaceObject.get("active").toString()));
218
219
220 50051 panagiotis
        Map<String, String> accessParams = new HashMap<>();
221
        Map<String, String> extraFields = new HashMap<>();
222
223
        ObjectMapper mapper = new ObjectMapper();
224 50631 panagiotis
        JSONArray apiparams = repositoryInterfaceObject.getJSONArray("apiParams");
225 50051 panagiotis
226 61441 antonis.le
        for (int i = 0; i < apiparams.length(); i++)
227
            accessParams.put(apiparams.getJSONObject(i).getString("param"), apiparams.getJSONObject(i).getString("value"));
228 50051 panagiotis
229 51525 panagiotis
        repositoryInterface.setAccessParams(accessParams);
230
231 49236 panagiotis
        return repositoryInterface;
232
    }
233
234 62318 antonis.le
    public String toJson(Repository repository) throws JSONException, JsonProcessingException {
235 49236 panagiotis
236 61441 antonis.le
        HashMap<String, Object> repositoryMap = new HashMap<>();
237 54702 panagiotis
        ObjectMapper mapper = new ObjectMapper();
238 51330 panagiotis
239 61441 antonis.le
        repositoryMap.put("id", repository.getId());
240
        repositoryMap.put("openaireId", getOpenaireId(repository.getId()));
241
        repositoryMap.put("officialname", repository.getOfficialName());
242
        repositoryMap.put("englishname", repository.getEnglishName());
243
        repositoryMap.put("websiteurl", repository.getWebsiteUrl());
244
        repositoryMap.put("logourl", repository.getLogoUrl());
245
        repositoryMap.put("contactemail", repository.getContactEmail());
246
        repositoryMap.put("longitude", repository.getLongitude().toString());
247
        repositoryMap.put("latitude", repository.getLatitude().toString());
248
        repositoryMap.put("timezone", repository.getTimezone());
249 51525 panagiotis
250 61441 antonis.le
        repositoryMap.put("namespaceprefix", repository.getNamespacePrefix() != null ? repository.getNamespacePrefix() : "");
251
        repositoryMap.put("languages", repository.getOdLanguages() != null ? repository.getOdLanguages() : "");
252 54457 panagiotis
253 62318 antonis.le
        repositoryMap.put("dateofcollection", repository.getDateOfCollection() != null ? toString(repository.getDateOfCollection()) : "");
254 54457 panagiotis
255 51525 panagiotis
        /*
256 61441 antonis.le
         * typology -> platform
257
         * datasource class -> typology
258
         * */
259 62267 spyroukon
//        repositoryMap.put("eoscDatasourceType", repository.getDatasourceClass()); // TODO: enable in future release
260 61441 antonis.le
        repositoryMap.put("platform", repository.getTypology());
261 51525 panagiotis
262 62318 antonis.le
        repositoryMap.put("dateofvalidation", repository.getDateOfCollection() != null ? toString(repository.getDateOfCollection()) : "");
263 61441 antonis.le
        repositoryMap.put("activationId", repository.getActivationId() != null ? repository.getActivationId() : "");
264 54457 panagiotis
265 61441 antonis.le
        repositoryMap.put("description", repository.getDescription());
266 54457 panagiotis
267 61441 antonis.le
        repositoryMap.put("eissn", repository.getEissn() != null ? repository.getEissn() : "");
268
        repositoryMap.put("issn", repository.getIssn() != null ? repository.getIssn() : "");
269
        repositoryMap.put("lissn", repository.getLissn() != null ? repository.getLissn() : "");
270 54457 panagiotis
271 61441 antonis.le
        repositoryMap.put("registeredby", repository.getRegisteredBy());
272 51525 panagiotis
273 61441 antonis.le
        repositoryMap.put("aggregator", repository.getAggregator() != null ? repository.getAggregator() : "");
274
        repositoryMap.put("collectedfrom", repository.getCollectedFrom() != null ? repository.getCollectedFrom() : "");
275 51330 panagiotis
276 61441 antonis.le
        repositoryMap.put("managed", repository.isRegistered());
277 51330 panagiotis
278 61441 antonis.le
        Map<String, String> organization = new HashMap<>();
279
        organization.put("legalname", repository.getOrganization());
280
        organization.put("country", repository.getCountryCode());
281
        organization.put("legalshortname", "");
282
        organization.put("websiteurl", "");
283
        organization.put("logourl", "");
284 51525 panagiotis
285 54702 panagiotis
        List organizations = new ArrayList();
286
        organizations.add(organization);
287 61441 antonis.le
        repositoryMap.put("organizations", organizations);
288 51525 panagiotis
289 54457 panagiotis
        //TODO check identitites
290 54702 panagiotis
        //Map<String,String> identity = new HashMap<>();
291 56896 antonis.le
292
        if (repository.getPiwikInfo() != null) {
293 57535 antonis.le
            Map<String, Object> identity = new HashMap<>();
294
            HashSet<Map<String, Object>> identities = new HashSet<>();
295 56896 antonis.le
296 57535 antonis.le
            identity.put("issuertype", "piwik");
297
            identity.put("pid", "piwik:" + repository.getPiwikInfo().getSiteId());
298 56896 antonis.le
299 57535 antonis.le
            identities.add(identity);
300
301 56896 antonis.le
            repositoryMap.put("identities", identities);
302
        }
303
304 61441 antonis.le
        repositoryMap.put("subjects", "");
305 62020 spyroukon
        repositoryMap.put("consentTermsOfUse", repository.getConsentTermsOfUse());
306
        repositoryMap.put("fullTextDownload", repository.getFullTextDownload());
307 62318 antonis.le
        repositoryMap.put("consentTermsOfUseDate", toString(repository.getConsentTermsOfUseDate()));
308
        repositoryMap.put("lastConsentTermsOfUseDate", toString(repository.getLastConsentTermsOfUseDate()));
309 51525 panagiotis
310 54702 panagiotis
        return mapper.writeValueAsString(repositoryMap);
311 49236 panagiotis
    }
312
313 62318 antonis.le
    public String toJson(Repository repository, RepositoryInterface repositoryInterface) throws JSONException {
314 49236 panagiotis
315
        JSONObject jsonObject = new JSONObject();
316
317 61441 antonis.le
        jsonObject.put("id", repositoryInterface.getId());
318
        jsonObject.put("protocol", repositoryInterface.getAccessProtocol());
319
        jsonObject.put("datasource", repository.getId());
320
        jsonObject.put("contentdescription", repositoryInterface.getContentDescription());
321
        jsonObject.put("typology", repositoryInterface.getTypology());
322
        jsonObject.put("compatibility", repositoryInterface.getDesiredCompatibilityLevel());
323
        jsonObject.put("compatibilityOverride", repositoryInterface.getDesiredCompatibilityLevel());
324 51525 panagiotis
325 61441 antonis.le
        jsonObject.put("lastCollectionTotal", "");
326 51525 panagiotis
327 61441 antonis.le
        jsonObject.put("lastCollectionDate", repositoryInterface.getLastCollectionDate());
328
        jsonObject.put("lastAggregationTotal", "");
329
        jsonObject.put("lastAggregationDate", "");
330
        jsonObject.put("lastDownloadTotal", "");
331
        jsonObject.put("lastDownloadDate", "");
332 51525 panagiotis
333 61441 antonis.le
        jsonObject.put("baseurl", repositoryInterface.getBaseUrl());
334
        jsonObject.put("removable", repositoryInterface.isRemovable());
335 50051 panagiotis
336 61441 antonis.le
337 50051 panagiotis
        JSONArray apiparams = new JSONArray();
338 61441 antonis.le
        for (String param : repositoryInterface.getAccessParams().keySet()) {
339 50051 panagiotis
            JSONObject jo = new JSONObject();
340 61441 antonis.le
            jo.put("param", param);
341
            jo.put("value", repositoryInterface.getAccessParams().get(param));
342 50051 panagiotis
            apiparams.put(jo);
343
        }
344 61441 antonis.le
        jsonObject.put("apiParams", apiparams);
345 50051 panagiotis
346
347 51525 panagiotis
//        jsonObject.put("metadataIdentifierPath",repositoryInterface.getMetadataIdentifierPath());
348 50051 panagiotis
349 51525 panagiotis
350 49236 panagiotis
        return jsonObject.toString();
351
    }
352
353 62318 antonis.le
    public ArrayList<String> readFile(String filename) {
354 49236 panagiotis
        String line;
355
        ArrayList<String> list = new ArrayList<String>();
356
        try {
357 49790 panagiotis
            //InputStream in = Converter.class.getResourceAsStream("resources/eu/dnetlib/repo/manager/service/utils/"+filename);
358 49813 panagiotis
            InputStream in = Converter.class.getClass().getResourceAsStream("/eu/**/" + filename);
359 49770 panagiotis
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
360 61441 antonis.le
            while ((line = br.readLine()) != null) {
361 49236 panagiotis
                list.add(line.trim());
362
            }
363
            br.close();
364
        } catch (IOException e) {
365 49770 panagiotis
            LOGGER.debug("Error opening file!");
366 56766 ioannis.di
            LOGGER.error(e);
367 49236 panagiotis
        }
368
        return list;
369
    }
370 49763 panagiotis
371 62318 antonis.le
    public List<AggregationDetails> toAggregationHistory(JSONArray aggregationInfo) throws JSONException {
372 56636 antonis.le
        List<AggregationDetails> aggregationDetailsList = new ArrayList<>();
373 49763 panagiotis
374 62272 antonis.le
        for (int i = 0; i < aggregationInfo.length(); i++)
375 62318 antonis.le
            aggregationDetailsList.add(toAggregationDetails(aggregationInfo.getJSONObject(i)));
376 56636 antonis.le
377 49763 panagiotis
        return aggregationDetailsList;
378
    }
379
380 62318 antonis.le
    public List<Timezone> toTimezones(List<String> timezones) {
381 49763 panagiotis
382
        List<Timezone> tmz = new ArrayList<>();
383 61441 antonis.le
        for (String t : timezones) {
384 49763 panagiotis
            String[] s = t.split("\t");
385 61441 antonis.le
            tmz.add(new Timezone(s[1], Double.parseDouble(s[0])));
386 49763 panagiotis
        }
387
        return tmz;
388
    }
389 51330 panagiotis
390 62318 antonis.le
    private String getOpenaireId(String repositoryId) {
391 51330 panagiotis
        if (repositoryId != null && repositoryId.contains("::"))
392
            return repositoryId.split("::")[0] + "::" + DigestUtils.md5Hex(repositoryId.split("::")[1]);
393
        return null;
394
    }
395 53113 panagiotis
396 62318 antonis.le
    private Boolean convertStringToBoolean(String value) {
397
        return value.equals("null") ? null : Boolean.valueOf(value);
398
    }
399
400
    private Date toDate(String date) {
401
402
        if (Objects.equals(date, "null"))
403
            return null;
404
405
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
406
        try {
407
            return formatter.parse(date);
408
        } catch (ParseException e) {
409
            LOGGER.error(e);
410
        }
411
        return null;
412
    }
413
414
    private String toString(Date date) {
415
416
        if (Objects.equals(date, null))
417
            return null;
418
419
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
420
        return formatter.format(date);
421
    }
422
423
    private Double toDouble(String number) {
424
        if (Objects.equals(number, "null"))
425
            return 0.0;
426
        else
427
            return Double.valueOf(number);
428
    }
429
430
    private AggregationDetails toAggregationDetails(JSONObject aggregationObject) throws JSONException {
431
432
        AggregationDetails aggregationDetails = new AggregationDetails();
433
434
        if (aggregationObject.has("collectionMode"))
435
            aggregationDetails.setCollectionMode(aggregationObject.get("collectionMode").toString());
436
        if (aggregationObject.has("indexedVersion"))
437
            aggregationDetails.setIndexedVersion(Boolean.parseBoolean(aggregationObject.get("indexedVersion").toString()));
438
439
        aggregationDetails.setAggregationStage(aggregationObject.get("aggregationStage").toString());
440
        aggregationDetails.setDate(toDate(aggregationObject.get("date").toString()));
441
        aggregationDetails.setNumberOfRecords(Integer.parseInt(aggregationObject.get("numberOfRecords").toString()));
442
443
        return aggregationDetails;
444
    }
445 56636 antonis.le
}