Project

General

Profile

« Previous | Next » 

Revision 51943

saving attribute: api.removable

View differences:

modules/dnet-openaire-datasource-manager/trunk/src/main/java/eu/dnetlib/enabling/datasources/DatasourceFunctions.java
5 5
import java.sql.Date;
6 6
import java.sql.SQLException;
7 7
import java.sql.Timestamp;
8
import java.util.*;
8
import java.util.Arrays;
9
import java.util.HashMap;
10
import java.util.List;
11
import java.util.Map;
12
import java.util.Objects;
9 13
import java.util.stream.Collectors;
10 14

  
11
import eu.dnetlib.enabling.datasources.common.*;
12
import eu.dnetlib.miscutils.datetime.DateUtils;
13 15
import org.apache.commons.lang3.BooleanUtils;
14 16
import org.apache.commons.lang3.StringUtils;
15 17
import org.apache.commons.logging.Log;
......
21 23
import org.springframework.core.io.ClassPathResource;
22 24
import org.springframework.core.io.Resource;
23 25

  
26
import eu.dnetlib.enabling.datasources.common.Api;
27
import eu.dnetlib.enabling.datasources.common.ApiParam;
28
import eu.dnetlib.enabling.datasources.common.ApiParamImpl;
29
import eu.dnetlib.enabling.datasources.common.Datasource;
30
import eu.dnetlib.enabling.datasources.common.Identity;
31
import eu.dnetlib.enabling.datasources.common.Organization;
32
import eu.dnetlib.enabling.datasources.common.SearchApisEntry;
33
import eu.dnetlib.enabling.datasources.common.SimpleDatasource;
34
import eu.dnetlib.miscutils.datetime.DateUtils;
35

  
24 36
public class DatasourceFunctions {
25 37

  
26
    private static final Log log = LogFactory.getLog(DatasourceFunctions.class);
38
	private static final Log log = LogFactory.getLog(DatasourceFunctions.class);
27 39

  
28
    private static final Resource baseDsProfile = new ClassPathResource("/eu/dnetlib/enabling/datasources/templates/datasource_base.xml");
40
	private static final Resource baseDsProfile = new ClassPathResource("/eu/dnetlib/enabling/datasources/templates/datasource_base.xml");
29 41

  
42
	public static SimpleDatasource mapToSimpleDs(final Map<String, Object> map) {
43
		final SimpleDatasource ds = new SimpleDatasource();
44
		ds.setId(castObject(map.get("id"), String.class));
45
		ds.setName(castObject(map.get("name"), String.class));
46
		ds.setOrigId(castObject(map.get("id"), String.class));
47
		ds.setTypology(castObject(map.get("typology"), String.class));
48
		ds.setValid(true);
49
		try {
50
			final Array arr = castObject(map.get("apis"), Array.class);
30 51

  
31
    public static SimpleDatasource mapToSimpleDs(final Map<String, Object> map) {
32
        final SimpleDatasource ds = new SimpleDatasource();
33
        ds.setId(castObject(map.get("id"), String.class));
34
        ds.setName(castObject(map.get("name"), String.class));
35
        ds.setOrigId(castObject(map.get("id"), String.class));
36
        ds.setTypology(castObject(map.get("typology"), String.class));
37
        ds.setValid(true);
38
        try {
39
            final Array arr = castObject(map.get("apis"), Array.class);
52
			if (arr != null && ((Object[]) arr.getArray()).length > 0) {
53
				ds.setApis(Arrays.stream((Object[]) arr.getArray())
54
						.filter(Objects::nonNull)
55
						.map(Object::toString)
56
						.collect(Collectors.toSet()));
57
			}
58
		} catch (final SQLException e) {
59
			log.error("Error parsing array (apis)", e);
60
			throw new RuntimeException("Error parsing array (apis)", e);
61
		}
40 62

  
41
            if (arr != null && ((Object[]) arr.getArray()).length > 0) {
42
                ds.setApis(Arrays.stream((Object[]) arr.getArray())
43
                        .filter(Objects::nonNull)
44
                        .map(Object::toString)
45
                        .collect(Collectors.toSet()));
46
            }
47
        } catch (final SQLException e) {
48
            log.error("Error parsing array (apis)", e);
49
            throw new RuntimeException("Error parsing array (apis)", e);
50
        }
63
		return ds;
64
	}
51 65

  
52
        return ds;
53
    }
66
	public static Datasource<Organization<?>, Identity> mapToDatasource(final Map<String, Object> map) {
67
		final Datasource<Organization<?>, Identity> ds = new Datasource<>();
68
		ds.setId(castObject(map.get("id"), String.class));
69
		ds.setOfficialname(castObject(map.get("officialname"), String.class));
70
		ds.setEnglishname(castObject(map.get("englishname"), String.class));
71
		ds.setWebsiteurl(castObject(map.get("websiteurl"), String.class));
72
		ds.setLogourl(castObject(map.get("logourl"), String.class));
73
		ds.setContactemail(castObject(map.get("contactemail"), String.class));
74
		ds.setLatitude(castObject(map.get("latitude"), Double.class));
75
		ds.setLongitude(castObject(map.get("longitude"), Double.class));
76
		ds.setTimezone(castObject(map.get("timezone"), String.class));
77
		ds.setNamespaceprefix(castObject(map.get("namespaceprefix"), String.class));
78
		ds.setLanguages(castObject(map.get("languages"), String.class));
79
		ds.setOd_contenttypes(castObject(map.get("od_contenttypes"), String.class));
80
		ds.setCollectedfrom(castObject(map.get("collectedfrom"), String.class));
81
		ds.setDateofvalidation(castObject(map.get("dateofvalidation"), Date.class));
82
		ds.setTypology(castObject(map.get("typology"), String.class));
83
		ds.setProvenanceaction(castObject(map.get("provenanceaction"), String.class));
84
		ds.setDateofcollection(castObject(map.get("dateofcollection"), Date.class));
85
		ds.setPlatform(castObject(map.get("platform"), String.class));
86
		ds.setActivationId(castObject(map.get("activationId"), String.class));
87
		ds.setDescription(castObject(map.get("description"), String.class));
88
		ds.setReleasestartdate(castObject(map.get("releasestartdate"), Date.class));
89
		ds.setReleaseenddate(castObject(map.get("releaseenddate"), Date.class));
90
		ds.setMissionstatementurl(castObject(map.get("missionstatementurl"), String.class));
91
		ds.setDataprovider(castObject(map.get("dataprovider"), Boolean.class));
92
		ds.setServiceprovider(castObject(map.get("serviceprovider"), Boolean.class));
93
		ds.setDatabaseaccesstype(castObject(map.get("databaseaccesstype"), String.class));
94
		ds.setDatauploadtype(castObject(map.get("datauploadtype"), String.class));
95
		ds.setDatabaseaccessrestriction(castObject(map.get("databaseaccessrestriction"), String.class));
96
		ds.setDatauploadrestriction(castObject(map.get("datauploadrestriction"), String.class));
97
		ds.setVersioning(castObject(map.get("versioning"), Boolean.class));
98
		ds.setCitationguidelineurl(castObject(map.get("citationguidelineurl"), String.class));
99
		ds.setQualitymanagementkind(castObject(map.get("qualitymanagementkind"), String.class));
100
		ds.setPidsystems(castObject(map.get("pidsystems"), String.class));
101
		ds.setCertificates(castObject(map.get("certificates"), String.class));
102
		ds.setAggregator(castObject(map.get("aggregator"), String.class));
103
		ds.setIssn(castObject(map.get("issn"), String.class));
104
		ds.setEissn(castObject(map.get("eissn"), String.class));
105
		ds.setLissn(castObject(map.get("lissn"), String.class));
106
		ds.setRegisteredby(castObject(map.get("registeredby"), String.class));
107
		ds.setSubjects(castObject(map.get("subjects"), String.class));
108
		ds.setManaged(castObject(map.get("managed"), Boolean.class));
109
		return ds;
110
	}
54 111

  
112
	public static Identity mapToDsIdentity(final Map<String, Object> map) {
113
		final Identity id = new Identity();
114
		id.setPid(castObject(map.get("pid"), String.class));
115
		id.setIssuertype(castObject(map.get("issuertype"), String.class));
116
		return id;
117
	}
55 118

  
56
    public static Datasource<Organization<?>, Identity> mapToDatasource(final Map<String, Object> map) {
57
        final Datasource<Organization<?>, Identity> ds = new Datasource<>();
58
        ds.setId(castObject(map.get("id"), String.class));
59
        ds.setOfficialname(castObject(map.get("officialname"), String.class));
60
        ds.setEnglishname(castObject(map.get("englishname"), String.class));
61
        ds.setWebsiteurl(castObject(map.get("websiteurl"), String.class));
62
        ds.setLogourl(castObject(map.get("logourl"), String.class));
63
        ds.setContactemail(castObject(map.get("contactemail"), String.class));
64
        ds.setLatitude(castObject(map.get("latitude"), Double.class));
65
        ds.setLongitude(castObject(map.get("longitude"), Double.class));
66
        ds.setTimezone(castObject(map.get("timezone"), String.class));
67
        ds.setNamespaceprefix(castObject(map.get("namespaceprefix"), String.class));
68
        ds.setLanguages(castObject(map.get("languages"), String.class));
69
        ds.setOd_contenttypes(castObject(map.get("od_contenttypes"), String.class));
70
        ds.setCollectedfrom(castObject(map.get("collectedfrom"), String.class));
71
        ds.setDateofvalidation(castObject(map.get("dateofvalidation"), Date.class));
72
        ds.setTypology(castObject(map.get("typology"), String.class));
73
        ds.setProvenanceaction(castObject(map.get("provenanceaction"), String.class));
74
        ds.setDateofcollection(castObject(map.get("dateofcollection"), Date.class));
75
        ds.setPlatform(castObject(map.get("platform"), String.class));
76
        ds.setActivationId(castObject(map.get("activationId"), String.class));
77
        ds.setDescription(castObject(map.get("description"), String.class));
78
        ds.setReleasestartdate(castObject(map.get("releasestartdate"), Date.class));
79
        ds.setReleaseenddate(castObject(map.get("releaseenddate"), Date.class));
80
        ds.setMissionstatementurl(castObject(map.get("missionstatementurl"), String.class));
81
        ds.setDataprovider(castObject(map.get("dataprovider"), Boolean.class));
82
        ds.setServiceprovider(castObject(map.get("serviceprovider"), Boolean.class));
83
        ds.setDatabaseaccesstype(castObject(map.get("databaseaccesstype"), String.class));
84
        ds.setDatauploadtype(castObject(map.get("datauploadtype"), String.class));
85
        ds.setDatabaseaccessrestriction(castObject(map.get("databaseaccessrestriction"), String.class));
86
        ds.setDatauploadrestriction(castObject(map.get("datauploadrestriction"), String.class));
87
        ds.setVersioning(castObject(map.get("versioning"), Boolean.class));
88
        ds.setCitationguidelineurl(castObject(map.get("citationguidelineurl"), String.class));
89
        ds.setQualitymanagementkind(castObject(map.get("qualitymanagementkind"), String.class));
90
        ds.setPidsystems(castObject(map.get("pidsystems"), String.class));
91
        ds.setCertificates(castObject(map.get("certificates"), String.class));
92
        ds.setAggregator(castObject(map.get("aggregator"), String.class));
93
        ds.setIssn(castObject(map.get("issn"), String.class));
94
        ds.setEissn(castObject(map.get("eissn"), String.class));
95
        ds.setLissn(castObject(map.get("lissn"), String.class));
96
        ds.setRegisteredby(castObject(map.get("registeredby"), String.class));
97
        ds.setSubjects(castObject(map.get("subjects"), String.class));
98
        ds.setManaged(castObject(map.get("managed"), Boolean.class));
99
        return ds;
100
    }
119
	public static Organization<Datasource<?, ?>> mapToDsOrganization(final Map<String, Object> map) {
120
		final Organization<Datasource<?, ?>> org = new Organization<>();
121
		org.setId(castObject(map.get("id"), String.class));
122
		org.setLegalshortname(castObject(map.get("legalshortname"), String.class));
123
		org.setLegalname(castObject(map.get("legalname"), String.class));
124
		org.setWebsiteurl(castObject(map.get("websiteurl"), String.class));
125
		org.setLogourl(castObject(map.get("logourl"), String.class));
126
		org.setCountry(castObject(map.get("country"), String.class));
127
		org.setCollectedfrom(castObject(map.get("collectedfrom"), String.class));
128
		org.setDateofcollection(castObject(map.get("dateofcollection"), Date.class));
129
		org.setProvenanceaction(castObject(map.get("provenanceaction"), String.class));
130
		return org;
131
	}
101 132

  
102
    public static Identity mapToDsIdentity(final Map<String, Object> map) {
103
        final Identity id = new Identity();
104
        id.setPid(castObject(map.get("pid"), String.class));
105
        id.setIssuertype(castObject(map.get("issuertype"), String.class));
106
        return id;
107
    }
133
	public static SearchApisEntry mapToSearchApisEntry(final Map<String, Object> map) {
134
		final SearchApisEntry a = new SearchApisEntry();
135
		a.setId(castObject(map.get("id"), String.class));
136
		a.setCompliance(castObject(map.get("compliance"), String.class));
137
		a.setActive(castObject(map.get("active"), Boolean.class));
138
		a.setRepoId(castObject(map.get("dsId"), String.class));
139
		a.setRepoName(castObject(map.get("name"), String.class));
140
		a.setRepoCountry(castObject(map.get("country"), String.class));
141
		a.setRepoPrefix(castObject(map.get("prefix"), String.class));
142
		a.setAggrDate(castObject(map.get("aggrDate"), String.class));
143
		a.setAggrTotal(castObject(map.get("aggrTotal"), Integer.class));
144
		a.setProtocol(castObject(map.get("protocol"), String.class));
145
		a.setAlternativeName(castObject(map.get("alternativeName"), String.class));
146
		a.setRepoOrganization(castObject(map.get("organization"), String.class));
147
		return a;
148
	}
108 149

  
109
    public static Organization<Datasource<?, ?>> mapToDsOrganization(final Map<String, Object> map) {
110
        final Organization<Datasource<?, ?>> org = new Organization<>();
111
        org.setId(castObject(map.get("id"), String.class));
112
        org.setLegalshortname(castObject(map.get("legalshortname"), String.class));
113
        org.setLegalname(castObject(map.get("legalname"), String.class));
114
        org.setWebsiteurl(castObject(map.get("websiteurl"), String.class));
115
        org.setLogourl(castObject(map.get("logourl"), String.class));
116
        org.setCountry(castObject(map.get("country"), String.class));
117
        org.setCollectedfrom(castObject(map.get("collectedfrom"), String.class));
118
        org.setDateofcollection(castObject(map.get("dateofcollection"), Date.class));
119
        org.setProvenanceaction(castObject(map.get("provenanceaction"), String.class));
120
        return org;
121
    }
150
	public static Api<ApiParam> mapToApi(final Map<String, Object> map) {
151
		final Api<ApiParam> a = new Api<>();
152
		a.setId(castObject(map.get("id"), String.class));
153
		a.setProtocol(castObject(map.get("protocol"), String.class));
154
		a.setDatasource(castObject(map.get("datasource"), String.class));
155
		a.setContentdescription(castObject(map.get("contentdescription"), String.class));
156
		a.setActive(castObject(map.get("active"), Boolean.class));
157
		a.setRemovable(castObject(map.get("removable"), Boolean.class));
158
		a.setTypology(castObject(map.get("typology"), String.class));
159
		a.setCompatibility(castObject(map.get("compatibility"), String.class));
160
		a.setCompatibilityOverrided(castObject(map.get("isCompatibilityOverrided"), Boolean.class));
161
		a.setMetadataIdentifierPath(castObject(map.get("metadataIdentifierPath"), String.class));
162
		a.setLastCollectionTotal(castObject(map.get("lastCollectionTotal"), Integer.class));
163
		a.setLastCollectionDate(castObject(map.get("lastCollectionDate"), Timestamp.class));
164
		a.setLastCollectionMdid(castObject(map.get("lastCollectionMdid"), String.class));
165
		a.setLastAggregationTotal(castObject(map.get("lastAggregationTotal"), Integer.class));
166
		a.setLastAggregationDate(castObject(map.get("lastAggregationDate"), Timestamp.class));
167
		a.setLastAggregationMdid(castObject(map.get("lastAggregationMdid"), String.class));
168
		a.setLastDownloadTotal(castObject(map.get("lastDownloadTotal"), Integer.class));
169
		a.setLastDownloadDate(castObject(map.get("lastDownloadDate"), Timestamp.class));
170
		a.setLastDownloadObjid(castObject(map.get("lastDownloadObjid"), String.class));
171
		a.setLastValidationJob(castObject(map.get("lastValidationJob"), String.class));
172
		a.setBaseurl(castObject(map.get("baseUrl"), String.class));
173
		try {
174
			final Array arr = castObject(map.get("params"), Array.class);
175
			if (arr != null) {
176
				a.setApiParams(Arrays.stream((Object[]) arr.getArray())
177
						.filter(Objects::nonNull)
178
						.map(Object::toString)
179
						.map(s -> {
180
							final ApiParam p = new ApiParamImpl();
181
							p.setParam(StringUtils.substringBefore(s, "="));
182
							p.setValue(StringUtils.substringAfter(s, "="));
183
							return p;
184
						})
185
						.collect(Collectors.toSet()));
186
			}
187
		} catch (final SQLException e) {
188
			log.error("Error parsing array params", e);
189
			throw new RuntimeException("Error parsing array params", e);
190
		}
122 191

  
123
    public static SearchApisEntry mapToSearchApisEntry(final Map<String, Object> map) {
124
        final SearchApisEntry a = new SearchApisEntry();
125
        a.setId(castObject(map.get("id"), String.class));
126
        a.setCompliance(castObject(map.get("compliance"), String.class));
127
        a.setActive(castObject(map.get("active"), Boolean.class));
128
        a.setRepoId(castObject(map.get("dsId"), String.class));
129
        a.setRepoName(castObject(map.get("name"), String.class));
130
        a.setRepoCountry(castObject(map.get("country"), String.class));
131
        a.setRepoPrefix(castObject(map.get("prefix"), String.class));
132
        a.setAggrDate(castObject(map.get("aggrDate"), String.class));
133
        a.setAggrTotal(castObject(map.get("aggrTotal"), Integer.class));
134
        a.setProtocol(castObject(map.get("protocol"), String.class));
135
        a.setAlternativeName(castObject(map.get("alternativeName"), String.class));
136
        a.setRepoOrganization(castObject(map.get("organization"), String.class));
137
        return a;
138
    }
192
		return a;
193
	}
139 194

  
140
    public static Api<ApiParam> mapToApi(final Map<String, Object> map) {
141
        final Api<ApiParam> a = new Api<>();
142
        a.setId(castObject(map.get("id"), String.class));
143
        a.setProtocol(castObject(map.get("protocol"), String.class));
144
        a.setDatasource(castObject(map.get("datasource"), String.class));
145
        a.setContentdescription(castObject(map.get("contentdescription"), String.class));
146
        a.setActive(castObject(map.get("active"), Boolean.class));
147
        a.setRemovable(castObject(map.get("removable"), Boolean.class));
148
        a.setTypology(castObject(map.get("typology"), String.class));
149
        a.setCompatibility(castObject(map.get("compatibility"), String.class));
150
        a.setCompatibilityOverrided(castObject(map.get("isCompatibilityOverrided"), Boolean.class));
151
        a.setMetadataIdentifierPath(castObject(map.get("metadataIdentifierPath"), String.class));
152
        a.setLastCollectionTotal(castObject(map.get("lastCollectionTotal"), Integer.class));
153
        a.setLastCollectionDate(castObject(map.get("lastCollectionDate"), Timestamp.class));
154
        a.setLastCollectionMdid(castObject(map.get("lastCollectionMdid"), String.class));
155
        a.setLastAggregationTotal(castObject(map.get("lastAggregationTotal"), Integer.class));
156
        a.setLastAggregationDate(castObject(map.get("lastAggregationDate"), Timestamp.class));
157
        a.setLastAggregationMdid(castObject(map.get("lastAggregationMdid"), String.class));
158
        a.setLastDownloadTotal(castObject(map.get("lastDownloadTotal"), Integer.class));
159
        a.setLastDownloadDate(castObject(map.get("lastDownloadDate"), Timestamp.class));
160
        a.setLastDownloadObjid(castObject(map.get("lastDownloadObjid"), String.class));
161
        a.setLastValidationJob(castObject(map.get("lastValidationJob"), String.class));
162
        a.setBaseurl(castObject(map.get("baseUrl"), String.class));
163
        try {
164
            final Array arr = castObject(map.get("params"), Array.class);
165
            if (arr != null) {
166
                a.setApiParams(Arrays.stream((Object[]) arr.getArray())
167
                        .filter(Objects::nonNull)
168
                        .map(Object::toString)
169
                        .map(s -> {
170
                            final ApiParam p = new ApiParamImpl();
171
                            p.setParam(StringUtils.substringBefore(s, "="));
172
                            p.setValue(StringUtils.substringAfter(s, "="));
173
                            return p;
174
                        })
175
                        .collect(Collectors.toSet()));
176
            }
177
        } catch (final SQLException e) {
178
            log.error("Error parsing array params", e);
179
            throw new RuntimeException("Error parsing array params", e);
180
        }
195
	public static String dsToProfile(final Datasource<Organization<?>, Identity> ds, final List<Api<ApiParam>> apis, final String profId)
196
			throws DocumentException, IOException {
197
		final Document doc = new SAXReader().read(baseDsProfile.getInputStream());
181 198

  
182
        return a;
183
    }
199
		setValue(doc, "//DATASOURCE_TYPE", ds.getTypology());
200
		setValue(doc, "//DATASOURCE_ORIGINAL_ID", ds.getId());
201
		setValue(doc, "//TYPOLOGY", ds.getPlatform());
202
		setValue(doc, "//OFFICIAL_NAME", ds.getOfficialname());
203
		setValue(doc, "//ENGLISH_NAME", ds.getEnglishname());
204
		setValue(doc, "//ICON_URI", ds.getLogourl());
205
		setValue(doc, "//COUNTRY", ds.getOrganizations().stream().map(Organization::getCountry).findFirst().orElse(""));
206
		setValue(doc, "//LONGITUDE", ds.getLongitude());
207
		setValue(doc, "//LATITUDE", ds.getLatitude());
208
		setValue(doc, "//TIMEZONE", ds.getTimezone());
209
		setValue(doc, "//REPOSITORY_WEBPAGE", ds.getWebsiteurl());
210
		setValue(doc, "//REPOSITORY_INSTITUTION", ds.getOrganizations().stream().map(Organization::getLegalname).findFirst().orElse(""));
211
		setValue(doc, "//ADMIN_INFO", ds.getContactemail());
212
		setValue(doc, "//REGISTERED_BY", ds.getRegisteredby());
213
		setValue(doc, "//LAST_UPDATE/@value", DateUtils.now_ISO8601());
184 214

  
185
    public static String dsToProfile(final Datasource<Organization<?>, Identity> ds, final List<Api<ApiParam>> apis, final String profId)
186
            throws DocumentException, IOException {
187
        final Document doc = new SAXReader().read(baseDsProfile.getInputStream());
215
		final Element ef = (Element) doc.selectSingleNode("//EXTRA_FIELDS");
216
		addExtraField(ef, "OpenAireDataSourceId", ds.getId());
217
		addExtraField(ef, "NamespacePrefix", ds.getNamespaceprefix());
218
		addExtraField(ef, "VERIFIED", "NO");
219
		addExtraField(ef, "aggregatorName", ds.getAggregator());
220
		addExtraField(ef, "dateOfValidation", ds.getDateofvalidation());
221
		addExtraField(ef, "dateOfCollection", ds.getDateofcollection());
222
		addExtraField(ef, "mergeHomonyms", "NO");
223
		addExtraField(ef, "ACTID", ds.getActivationId());
188 224

  
189
        setValue(doc, "//DATASOURCE_TYPE", ds.getTypology());
190
        setValue(doc, "//DATASOURCE_ORIGINAL_ID", ds.getId());
191
        setValue(doc, "//TYPOLOGY", ds.getPlatform());
192
        setValue(doc, "//OFFICIAL_NAME", ds.getOfficialname());
193
        setValue(doc, "//ENGLISH_NAME", ds.getEnglishname());
194
        setValue(doc, "//ICON_URI", ds.getLogourl());
195
        setValue(doc, "//COUNTRY", ds.getOrganizations().stream().map(Organization::getCountry).findFirst().orElse(""));
196
        setValue(doc, "//LONGITUDE", ds.getLongitude());
197
        setValue(doc, "//LATITUDE", ds.getLatitude());
198
        setValue(doc, "//TIMEZONE", ds.getTimezone());
199
        setValue(doc, "//REPOSITORY_WEBPAGE", ds.getWebsiteurl());
200
        setValue(doc, "//REPOSITORY_INSTITUTION", ds.getOrganizations().stream().map(Organization::getLegalname).findFirst().orElse(""));
201
        setValue(doc, "//ADMIN_INFO", ds.getContactemail());
202
        setValue(doc, "//REGISTERED_BY", ds.getRegisteredby());
203
        setValue(doc, "//LAST_UPDATE/@value", DateUtils.now_ISO8601());
225
		if (apis != null) {
226
			final Element ifaces = (Element) doc.selectSingleNode("//INTERFACES");
227
			apis.forEach(api -> addInterface(ifaces, api));
228
		}
229
		return doc.asXML();
230
	}
204 231

  
205
        final Element ef = (Element) doc.selectSingleNode("//EXTRA_FIELDS");
206
        addExtraField(ef, "OpenAireDataSourceId", ds.getId());
207
        addExtraField(ef, "NamespacePrefix", ds.getNamespaceprefix());
208
        addExtraField(ef, "VERIFIED", "NO");
209
        addExtraField(ef, "aggregatorName", ds.getAggregator());
210
        addExtraField(ef, "dateOfValidation", ds.getDateofvalidation());
211
        addExtraField(ef, "dateOfCollection", ds.getDateofcollection());
212
        addExtraField(ef, "mergeHomonyms", "NO");
213
        addExtraField(ef, "ACTID", ds.getActivationId());
232
	private static void setValue(final Document doc, final String xpath, final Object value) {
233
		if (value != null) {
234
			doc.selectSingleNode(xpath).setText(value.toString());
235
		}
236
	}
214 237

  
215
        if (apis != null) {
216
            final Element ifaces = (Element) doc.selectSingleNode("//INTERFACES");
217
            apis.forEach(api -> addInterface(ifaces, api));
218
        }
219
        return doc.asXML();
220
    }
238
	private static void addInterface(final Element ifaces, final Api<?> api) {
221 239

  
222
    private static void setValue(final Document doc, final String xpath, final Object value) {
223
        if (value != null) {
224
            doc.selectSingleNode(xpath).setText(value.toString());
225
        }
226
    }
240
		final Element ifc = ifaces.addElement("INTERFACE");
241
		ifc.addAttribute("id", api.getId());
242
		ifc.addAttribute("label", String.format("%s (%s)",
243
				StringUtils.defaultIfBlank(api.getTypology(), "-"),
244
				StringUtils.defaultIfBlank(api.getCompatibility(), "-")));
245
		ifc.addAttribute("typology", StringUtils.defaultIfBlank(api.getTypology(), ""));
246
		ifc.addAttribute("active", "" + BooleanUtils.toBooleanDefaultIfNull(api.getActive(), false));
247
		ifc.addAttribute("compliance", StringUtils.defaultIfBlank(api.getCompatibility(), ""));
248
		ifc.addAttribute("contentDescription", StringUtils.defaultIfBlank(api.getContentdescription(), ""));
249
		ifc.addAttribute("removable", "" + BooleanUtils.toBooleanDefaultIfNull(api.getRemovable(), false));
227 250

  
228
    private static void addInterface(final Element ifaces, final Api<?> api) {
251
		final Element ap = ifc.addElement("ACCESS_PROTOCOL");
252
		api.getApiParams().forEach(p -> ap.addAttribute(p.getParam(), p.getValue()));
253
		ap.setText(StringUtils.defaultIfBlank(api.getProtocol(), ""));
254
		ifc.addElement("BASE_URL").setText(StringUtils.defaultIfBlank(api.getBaseurl(), ""));
229 255

  
230
        final Element ifc = ifaces.addElement("INTERFACE");
231
        ifc.addAttribute("id", api.getId());
232
        ifc.addAttribute("label", String.format("%s (%s)",
233
                StringUtils.defaultIfBlank(api.getTypology(), "-"),
234
                StringUtils.defaultIfBlank(api.getCompatibility(), "-")));
235
        ifc.addAttribute("typology", StringUtils.defaultIfBlank(api.getTypology(), ""));
236
        ifc.addAttribute("active", "" + BooleanUtils.toBooleanDefaultIfNull(api.getActive(), false));
237
        ifc.addAttribute("compliance", StringUtils.defaultIfBlank(api.getCompatibility(), ""));
238
        ifc.addAttribute("contentDescription", StringUtils.defaultIfBlank(api.getContentdescription(), ""));
239
        ifc.addAttribute("removable", "" + BooleanUtils.toBooleanDefaultIfNull(api.getRemovable(), false));
256
		if (api.isCompatibilityOverrided()) {
257
			addInterfaceExtraField(ifc, "overriding_compliance", true);
258
		}
240 259

  
241
        final Element ap = ifc.addElement("ACCESS_PROTOCOL");
242
        api.getApiParams().forEach(p -> ap.addAttribute(p.getParam(), p.getValue()));
243
        ap.setText(StringUtils.defaultIfBlank(api.getProtocol(), ""));
244
        ifc.addElement("BASE_URL").setText(StringUtils.defaultIfBlank(api.getBaseurl(), ""));
260
		addInterfaceExtraField(ifc, "metadata_identifier_path", api.getMetadataIdentifierPath());
261
		addInterfaceExtraField(ifc, "last_collection_date", api.getLastCollectionDate());
262
		addInterfaceExtraField(ifc, "last_collection_mdId", api.getLastCollectionMdid());
263
		addInterfaceExtraField(ifc, "last_collection_total", api.getLastCollectionTotal());
264
		addInterfaceExtraField(ifc, "last_aggregation_date", api.getLastAggregationDate());
265
		addInterfaceExtraField(ifc, "last_aggregation_mdId", api.getLastAggregationMdid());
266
		addInterfaceExtraField(ifc, "last_aggregation_total", api.getLastAggregationTotal());
267
		addInterfaceExtraField(ifc, "last_download_date", api.getLastDownloadDate());
268
		addInterfaceExtraField(ifc, "last_download_objId", api.getLastDownloadObjid());
269
		addInterfaceExtraField(ifc, "last_download_total", api.getLastDownloadTotal());
270
	}
245 271

  
246
        if (api.isCompatibilityOverrided()) {
247
            addInterfaceExtraField(ifc, "overriding_compliance", true);
248
        }
272
	private static void addExtraField(final Element parent, final String field, final Object value) {
273
		if (value != null && StringUtils.isNotBlank(value.toString())) {
274
			final Element f = parent.addElement("FIELD");
275
			f.addElement("key").setText(field);
276
			f.addElement("value").setText(value.toString());
277
		}
278
	}
249 279

  
250
        addInterfaceExtraField(ifc, "metadata_identifier_path", api.getMetadataIdentifierPath());
251
        addInterfaceExtraField(ifc, "last_collection_date", api.getLastCollectionDate());
252
        addInterfaceExtraField(ifc, "last_collection_mdId", api.getLastCollectionMdid());
253
        addInterfaceExtraField(ifc, "last_collection_total", api.getLastCollectionTotal());
254
        addInterfaceExtraField(ifc, "last_aggregation_date", api.getLastAggregationDate());
255
        addInterfaceExtraField(ifc, "last_aggregation_mdId", api.getLastAggregationMdid());
256
        addInterfaceExtraField(ifc, "last_aggregation_total", api.getLastAggregationTotal());
257
        addInterfaceExtraField(ifc, "last_download_date", api.getLastDownloadDate());
258
        addInterfaceExtraField(ifc, "last_download_objId", api.getLastDownloadObjid());
259
        addInterfaceExtraField(ifc, "last_download_total", api.getLastDownloadTotal());
260
    }
280
	private static void addInterfaceExtraField(final Element parent, final String field, final Object value) {
281
		if (value != null && StringUtils.isNotBlank(value.toString())) {
282
			final Element f = parent.addElement("INTERFACE_EXTRA_FIELD");
283
			f.addAttribute("name", field);
284
			f.setText(value.toString());
285
		}
286
	}
261 287

  
262
    private static void addExtraField(final Element parent, final String field, final Object value) {
263
        if (value != null && StringUtils.isNotBlank(value.toString())) {
264
            final Element f = parent.addElement("FIELD");
265
            f.addElement("key").setText(field);
266
            f.addElement("value").setText(value.toString());
267
        }
268
    }
288
	public static Map<String, Object> dsToMap(final Datasource<Organization<?>, Identity> ds) {
289
		final Map<String, Object> map = new HashMap<>();
269 290

  
270
    private static void addInterfaceExtraField(final Element parent, final String field, final Object value) {
271
        if (value != null && StringUtils.isNotBlank(value.toString())) {
272
            final Element f = parent.addElement("INTERFACE_EXTRA_FIELD");
273
            f.addAttribute("name", field);
274
            f.setText(value.toString());
275
        }
276
    }
291
		map.put("id", ds.getId());
292
		map.put("officialname", ds.getOfficialname());
293
		map.put("englishname", ds.getEnglishname());
294
		map.put("websiteurl", ds.getWebsiteurl());
295
		map.put("logourl", ds.getLogourl());
296
		map.put("contactemail", ds.getContactemail());
297
		map.put("latitude", ds.getLatitude());
298
		map.put("longitude", ds.getLongitude());
299
		map.put("timezone", ds.getTimezone());
300
		map.put("namespaceprefix", ds.getNamespaceprefix());
301
		map.put("languages", ds.getLanguages());
302
		map.put("od_contenttypes", ds.getOd_contenttypes());
303
		map.put("collectedfrom", ds.getCollectedfrom());
304
		map.put("dateofvalidation", ds.getDateofvalidation());
305
		map.put("typology", ds.getTypology());
306
		map.put("provenanceaction", ds.getProvenanceaction());
307
		map.put("platform", ds.getPlatform());
308
		map.put("activationid", ds.getActivationId());
309
		map.put("description", ds.getDescription());
310
		map.put("releasestartdate", ds.getReleasestartdate());
311
		map.put("releaseenddate", ds.getReleaseenddate());
312
		map.put("missionstatementurl", ds.getMissionstatementurl());
313
		map.put("dataprovider", ds.getDataprovider());
314
		map.put("serviceprovider", ds.getServiceprovider());
315
		map.put("databaseaccesstype", ds.getDatabaseaccesstype());
316
		map.put("datauploadtype", ds.getDatauploadtype());
317
		map.put("databaseaccessrestriction", ds.getDatabaseaccessrestriction());
318
		map.put("datauploadrestriction", ds.getDatauploadrestriction());
319
		map.put("versioning", ds.getVersioning());
320
		map.put("citationguidelineurl", ds.getCitationguidelineurl());
321
		map.put("qualitymanagementkind", ds.getQualitymanagementkind());
322
		map.put("pidsystems", ds.getPidsystems());
323
		map.put("certificates", ds.getCertificates());
324
		map.put("aggregator", ds.getAggregator());
325
		map.put("issn", ds.getIssn());
326
		map.put("eissn", ds.getEissn());
327
		map.put("lissn", ds.getLissn());
328
		map.put("registeredby", ds.getRegisteredby());
329
		map.put("subjects", ds.getSubjects());
330
		map.put("managed", ds.getManaged());
277 331

  
278
    public static Map<String, Object> dsToMap(final Datasource<Organization<?>, Identity> ds) {
279
        final Map<String, Object> map = new HashMap<>();
332
		return map;
333
	}
280 334

  
281
        map.put("id", ds.getId());
282
        map.put("officialname", ds.getOfficialname());
283
        map.put("englishname", ds.getEnglishname());
284
        map.put("websiteurl", ds.getWebsiteurl());
285
        map.put("logourl", ds.getLogourl());
286
        map.put("contactemail", ds.getContactemail());
287
        map.put("latitude", ds.getLatitude());
288
        map.put("longitude", ds.getLongitude());
289
        map.put("timezone", ds.getTimezone());
290
        map.put("namespaceprefix", ds.getNamespaceprefix());
291
        map.put("languages", ds.getLanguages());
292
        map.put("od_contenttypes", ds.getOd_contenttypes());
293
        map.put("collectedfrom", ds.getCollectedfrom());
294
        map.put("dateofvalidation", ds.getDateofvalidation());
295
        map.put("typology", ds.getTypology());
296
        map.put("provenanceaction", ds.getProvenanceaction());
297
        map.put("platform", ds.getPlatform());
298
        map.put("activationid", ds.getActivationId());
299
        map.put("description", ds.getDescription());
300
        map.put("releasestartdate", ds.getReleasestartdate());
301
        map.put("releaseenddate", ds.getReleaseenddate());
302
        map.put("missionstatementurl", ds.getMissionstatementurl());
303
        map.put("dataprovider", ds.getDataprovider());
304
        map.put("serviceprovider", ds.getServiceprovider());
305
        map.put("databaseaccesstype", ds.getDatabaseaccesstype());
306
        map.put("datauploadtype", ds.getDatauploadtype());
307
        map.put("databaseaccessrestriction", ds.getDatabaseaccessrestriction());
308
        map.put("datauploadrestriction", ds.getDatauploadrestriction());
309
        map.put("versioning", ds.getVersioning());
310
        map.put("citationguidelineurl", ds.getCitationguidelineurl());
311
        map.put("qualitymanagementkind", ds.getQualitymanagementkind());
312
        map.put("pidsystems", ds.getPidsystems());
313
        map.put("certificates", ds.getCertificates());
314
        map.put("aggregator", ds.getAggregator());
315
        map.put("issn", ds.getIssn());
316
        map.put("eissn", ds.getEissn());
317
        map.put("lissn", ds.getLissn());
318
        map.put("registeredby", ds.getRegisteredby());
319
        map.put("subjects", ds.getSubjects());
320
        map.put("managed", ds.getManaged());
335
	public static Map<String, Object> orgToMap(final String dsId, final Organization<?> org) {
336
		final Map<String, Object> map = new HashMap<>();
337
		map.put("dsId", dsId);
338
		map.put("orgId", org.getId());
339
		map.put("legalname", org.getLegalname());
340
		map.put("legalshortname", org.getLegalshortname());
341
		map.put("websiteurl", org.getWebsiteurl());
342
		map.put("logourl", org.getLogourl());
343
		map.put("country", org.getCountry());
344
		return map;
345
	}
321 346

  
322
        return map;
323
    }
347
	public static Map<String, Object> apiToMap(final Api<?> api) {
348
		final Map<String, Object> map = new HashMap<>();
349
		map.put("apiId", api.getId());
350
		map.put("protocol", api.getProtocol());
351
		map.put("baseUrl", api.getBaseurl());
352
		map.put("dsId", api.getDatasource());
353
		map.put("contentDescription", api.getContentdescription());
354
		map.put("typology", api.getTypology());
355
		map.put("compatibility", api.getCompatibility());
356
		map.put("metadataIdentifierPath", api.getMetadataIdentifierPath());
357
		map.put("removable", api.getRemovable());
358
		// The other fields are not required in the INSERT operation
359
		return map;
360
	}
324 361

  
325
    public static Map<String, Object> orgToMap(final String dsId, final Organization<?> org) {
326
        final Map<String, Object> map = new HashMap<>();
327
        map.put("dsId", dsId);
328
        map.put("orgId", org.getId());
329
        map.put("legalname", org.getLegalname());
330
        map.put("legalshortname", org.getLegalshortname());
331
        map.put("websiteurl", org.getWebsiteurl());
332
        map.put("logourl", org.getLogourl());
333
        map.put("country", org.getCountry());
334
        return map;
335
    }
362
	@SuppressWarnings("unchecked")
363
	private static <T> T castObject(final Object o, final Class<T> clazz) {
364
		if (o == null) { return null; }
365
		if (clazz.isInstance(o)) { return (T) o; }
366
		throw new IllegalArgumentException("Type not managed: " + clazz.getSimpleName());
367
	}
336 368

  
337
    public static Map<String, Object> apiToMap(final Api<?> api) {
338
        final Map<String, Object> map = new HashMap<>();
339
        map.put("apiId", api.getId());
340
        map.put("protocol", api.getProtocol());
341
        map.put("baseUrl", api.getBaseurl());
342
        map.put("dsId", api.getDatasource());
343
        map.put("contentDescription", api.getContentdescription());
344
        map.put("typology", api.getTypology());
345
        map.put("compatibility", api.getCompatibility());
346
        map.put("metadataIdentifierPath", api.getMetadataIdentifierPath());
347
        // The other fields are not required in the INSERT operation
348
        return map;
349
    }
350

  
351
    @SuppressWarnings("unchecked")
352
    private static <T> T castObject(final Object o, final Class<T> clazz) {
353
        if (o == null) {
354
            return null;
355
        }
356
        if (clazz.isInstance(o)) {
357
            return (T) o;
358
        }
359
        throw new IllegalArgumentException("Type not managed: " + clazz.getSimpleName());
360
    }
361

  
362 369
}
modules/dnet-openaire-datasource-manager/trunk/src/main/resources/eu/dnetlib/enabling/datasources/queries/insertApi.sql
6 6
	contentdescription,
7 7
	typology,
8 8
	compatibility,
9
	metadata_identifier_path
9
	metadata_identifier_path,
10
	removable
10 11
) VALUES (
11 12
	:apiId,
12 13
	:protocol, 
......
15 16
	:contentDescription,
16 17
	:typology,
17 18
	:compatibility,
18
	:metadataIdentifierPath
19
	:metadataIdentifierPath,
20
	:removable
19 21
)

Also available in: Unified diff