Project

General

Profile

« Previous | Next » 

Revision 42526

[maven-release-plugin] copy for tag dnet-datasource-manager-service-1.0.3

View differences:

modules/dnet-datasource-manager-service/tags/dnet-datasource-manager-service-1.0.3/deploy.info
1
{"type_source": "SVN", "goal": "package -U -T 4C source:jar", "url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet40/modules/dnet-datasource-manager-service/trunk/", "deploy_repository": "dnet4-snapshots", "version": "4", "mail": "sandro.labruzzo@isti.cnr.it,michele.artini@isti.cnr.it, claudio.atzori@isti.cnr.it, alessia.bardi@isti.cnr.it", "deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet4-snapshots", "name": "dnet-datasource-manager-service"}
modules/dnet-datasource-manager-service/tags/dnet-datasource-manager-service-1.0.3/src/main/java/eu/dnetlib/enabling/datasources/IfaceDescToNode.java
1
package eu.dnetlib.enabling.datasources;
2

  
3
import java.util.Map.Entry;
4

  
5
import org.dom4j.DocumentHelper;
6
import org.dom4j.Element;
7

  
8
import eu.dnetlib.enabling.datasources.rmi.IfaceDesc;
9

  
10
public class IfaceDescToNode {
11

  
12
	public static Element convert(final IfaceDesc iface) throws Exception {
13

  
14
		final Element ifcNode = DocumentHelper.createElement("INTERFACE");
15
		ifcNode.addAttribute("id", iface.getId());
16
		ifcNode.addAttribute("label", iface.getTypology() + " (" + iface.getCompliance() + ")");
17
		ifcNode.addAttribute("compliance", iface.getCompliance());
18
		ifcNode.addAttribute("typology", iface.getTypology());
19
		ifcNode.addAttribute("contentDescription", iface.getContentDescription());
20
		ifcNode.addAttribute("active", Boolean.toString(iface.getActive()));
21
		ifcNode.addAttribute("removable", Boolean.toString(iface.getRemovable()));
22

  
23
		final Element acProtoNode = ifcNode.addElement("ACCESS_PROTOCOL");
24

  
25
		for (Entry<String, String> e : iface.getAccessParams().entrySet()) {
26
			acProtoNode.addAttribute(e.getKey(), e.getValue());
27
		}
28
		acProtoNode.setText(iface.getAccessProtocol());
29

  
30
		ifcNode.addElement("BASE_URL").setText(iface.getBaseUrl());
31

  
32
		for (Entry<String, String> e : iface.getExtraFields().entrySet()) {
33
			final Element field = ifcNode.addElement("INTERFACE_EXTRA_FIELD");
34
			field.addAttribute("name", e.getKey());
35
			field.setText(e.getValue());
36
		}
37

  
38
		return ifcNode;
39
	}
40
}
modules/dnet-datasource-manager-service/tags/dnet-datasource-manager-service-1.0.3/src/main/java/eu/dnetlib/enabling/datasources/XmlBrowsableField.java
1
package eu.dnetlib.enabling.datasources;
2

  
3
import eu.dnetlib.enabling.datasources.rmi.BrowsableField;
4

  
5
public class XmlBrowsableField extends BrowsableField {
6

  
7
	private String xpath;
8
	private String vocabulary;
9

  
10
	public XmlBrowsableField() {
11
		super();
12
	}
13

  
14
	public XmlBrowsableField(final String id, final String label) {
15
		super(id, label);
16
	}
17

  
18
	public XmlBrowsableField(final String id, final String label, final String xpath, final String vocabulary) {
19
		super(id, label);
20
		this.xpath = xpath;
21
		this.vocabulary = vocabulary;
22
	}
23

  
24
	public String getXpath() {
25
		return xpath;
26
	}
27

  
28
	public void setXpath(final String xpath) {
29
		this.xpath = xpath;
30
	}
31

  
32
	public String getVocabulary() {
33
		return vocabulary;
34
	}
35

  
36
	public void setVocabulary(final String vocabulary) {
37
		this.vocabulary = vocabulary;
38
	}
39

  
40
}
modules/dnet-datasource-manager-service/tags/dnet-datasource-manager-service-1.0.3/src/main/java/eu/dnetlib/enabling/datasources/DatasourceManagerServiceImpl.java
1
package eu.dnetlib.enabling.datasources;
2

  
3
import java.io.StringReader;
4
import java.text.ParseException;
5
import java.util.Collections;
6
import java.util.Date;
7
import java.util.List;
8
import java.util.Map;
9

  
10
import javax.annotation.Resource;
11

  
12
import org.antlr.stringtemplate.StringTemplate;
13
import org.apache.commons.io.IOUtils;
14
import org.apache.commons.lang.StringEscapeUtils;
15
import org.apache.commons.lang.StringUtils;
16
import org.apache.commons.lang.math.NumberUtils;
17
import org.apache.commons.logging.Log;
18
import org.apache.commons.logging.LogFactory;
19
import org.dom4j.Document;
20
import org.dom4j.Element;
21
import org.dom4j.Node;
22
import org.dom4j.io.SAXReader;
23
import org.quartz.CronExpression;
24
import org.springframework.beans.factory.annotation.Required;
25
import org.springframework.core.io.ClassPathResource;
26

  
27
import com.google.common.base.Function;
28
import com.google.common.collect.Lists;
29
import com.google.common.collect.Maps;
30
import com.google.common.collect.Sets;
31

  
32
import eu.dnetlib.enabling.datasources.rmi.BrowsableField;
33
import eu.dnetlib.enabling.datasources.rmi.BrowseTerm;
34
import eu.dnetlib.enabling.datasources.rmi.DatasourceConstants;
35
import eu.dnetlib.enabling.datasources.rmi.DatasourceDesc;
36
import eu.dnetlib.enabling.datasources.rmi.DatasourceManagerService;
37
import eu.dnetlib.enabling.datasources.rmi.DatasourceManagerServiceException;
38
import eu.dnetlib.enabling.datasources.rmi.IfaceDesc;
39
import eu.dnetlib.enabling.datasources.rmi.RepositoryMapEntry;
40
import eu.dnetlib.enabling.datasources.rmi.SearchInterfacesEntry;
41
import eu.dnetlib.enabling.datasources.rmi.SimpleDatasourceDesc;
42
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpDocumentNotFoundException;
43
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
44
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
45
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryException;
46
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService;
47
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
48
import eu.dnetlib.enabling.tools.AbstractBaseService;
49

  
50
public class DatasourceManagerServiceImpl extends AbstractBaseService implements DatasourceManagerService {
51

  
52
	private static final Log log = LogFactory.getLog(DatasourceManagerServiceImpl.class);
53

  
54
	private static final String REPOSITORY_RESOURCE_TYPE = "RepositoryServiceResourceType";
55

  
56
	private List<XmlBrowsableField> browsableFields;
57

  
58
	private ClassPathResource findReposQueryTmpl = new ClassPathResource("/eu/dnetlib/enabling/datasources/templates/findRepos.xquery.st");
59

  
60
	private ClassPathResource browseRepoApisQueryTmpl = new ClassPathResource("/eu/dnetlib/enabling/datasources/templates/browseRepoApis.xquery.st");
61
	private ClassPathResource findRepoApisQueryTmpl = new ClassPathResource("/eu/dnetlib/enabling/datasources/templates/findRepoApis.xquery.st");
62
	private ClassPathResource findReposMapQuery = new ClassPathResource("/eu/dnetlib/enabling/datasources/templates/findReposMap.xquery");
63
	private ClassPathResource simpleFindReposQueryTmpl = new ClassPathResource("/eu/dnetlib/enabling/datasources/templates/simpleFindRepos.xquery.st");
64

  
65
	@Resource
66
	private UniqueServiceLocator serviceLocator;
67

  
68
	private String fixDsId(final String dsId) throws DatasourceManagerServiceException {
69
		if (dsId.endsWith("_UGVuZGluZ1JlcG9zaXRvcnlSZXNvdXJjZXMvUmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZVR5cGU=")
70
				|| dsId.endsWith("_UmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZXMvUmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZVR5cGU=")) {
71
			return dsId;
72
		} else {
73
			try {
74
				return serviceLocator
75
						.getService(ISLookUpService.class)
76
						.getResourceProfileByQuery(
77
								"for $x in collection("
78
										+ "'/db/DRIVER/RepositoryServiceResources/RepositoryServiceResourceType',"
79
										+ "'/db/DRIVER/PendingRepositoryResources/RepositoryServiceResourceType') "
80
										+ "where $x//DATASOURCE_ORIGINAL_ID = '" + dsId + "' "
81
										+ "return $x//RESOURCE_IDENTIFIER/@value/string()");
82
			} catch (Exception e) {
83
				throw new DatasourceManagerServiceException("Invalid id: " + dsId, e);
84
			}
85
		}
86
	}
87

  
88
	@Override
89
	public boolean addDatasource(final DatasourceDesc ds) throws DatasourceManagerServiceException {
90
		try {
91
			final String profile = DatasourceDescToProfile.convert(ds);
92
			serviceLocator.getService(ISRegistryService.class).registerProfile(profile);
93
			return true;
94
		} catch (Exception e) {
95
			log.error("Error registering profile", e);
96
			throw new DatasourceManagerServiceException("Error registering profile", e);
97
		}
98
	}
99

  
100
	@Override
101
	public boolean deleteDatasource(final String dsId) throws DatasourceManagerServiceException {
102
		return _deleteDatasource(fixDsId(dsId));
103
	}
104

  
105
	private boolean _deleteDatasource(final String dsId) throws DatasourceManagerServiceException {
106
		try {
107
			return serviceLocator.getService(ISRegistryService.class).deleteProfile(dsId);
108
		} catch (ISRegistryException e) {
109
			log.error("Error deleting profile " + dsId, e);
110
			throw new DatasourceManagerServiceException("Error deleting profile " + dsId, e);
111
		}
112
	}
113

  
114
	@Override
115
	public DatasourceDesc getDatasource(final String dsId) throws DatasourceManagerServiceException {
116
		return _getDatasource(fixDsId(dsId));
117
	}
118

  
119
	private DatasourceDesc _getDatasource(final String dsId) throws DatasourceManagerServiceException {
120
		try {
121
			final String profile = serviceLocator.getService(ISLookUpService.class).getResourceProfile(dsId);
122
			return ProfileToDatasourceDesc.convert(profile);
123
		} catch (Exception e) {
124
			log.error("Error accessing profile " + dsId, e);
125
			throw new DatasourceManagerServiceException("Error accessing profile " + dsId, e);
126
		}
127
	}
128

  
129
	@Override
130
	public List<DatasourceDesc> listAllDatasources() throws DatasourceManagerServiceException {
131
		return listDatasourcesUsingFilter(null, null, null, null);
132
	}
133

  
134
	@Override
135
	public List<DatasourceDesc> listDatasourcesUsingFilter(final String compliance,
136
			final String contentDescription,
137
			final String iisProcessingWorkflow,
138
			final String collectedFrom)
139
			throws DatasourceManagerServiceException {
140
		try {
141
			final StringTemplate st = new StringTemplate();
142
			st.setTemplate(IOUtils.toString(findReposQueryTmpl.getInputStream()));
143

  
144
			final Map<String, String> conds = Maps.newHashMap();
145

  
146
			if (StringUtils.isNotBlank(compliance)) {
147
				conds.put("//INTERFACE/@compliance", compliance);
148
			}
149
			if (StringUtils.isNotBlank(contentDescription)) {
150
				conds.put("//INTERFACE/@contentDescription", contentDescription);
151
			}
152
			if (StringUtils.isNotBlank(iisProcessingWorkflow)) {
153
				// NOT USED
154
			}
155
			if (StringUtils.isNotBlank(collectedFrom)) {
156
				// NOT USED
157
			}
158

  
159
			if (!conds.isEmpty()) {
160
				st.setAttribute("conds", conds);
161
			}
162

  
163
			final List<String> list = serviceLocator.getService(ISLookUpService.class).quickSearchProfile(st.toString());
164

  
165
			return Lists.transform(list, new ProfileToDatasourceDesc());
166
		} catch (Exception e) {
167
			log.error("Error listing datasources", e);
168
			throw new DatasourceManagerServiceException("Error listing datasources", e);
169
		}
170
	}
171

  
172
	@Override
173
	public boolean updateLevelOfCompliance(final String dsId, final String ifaceId, final String level) throws DatasourceManagerServiceException {
174
		return _updateLevelOfCompliance(fixDsId(dsId), ifaceId, level);
175
	}
176

  
177
	private boolean _updateLevelOfCompliance(final String dsId, final String ifaceId, final String level) throws DatasourceManagerServiceException {
178
		try {
179
			return serviceLocator.getService(ISRegistryService.class)
180
					.updateProfileNode(dsId, "//INTERFACE[@id = '" + ifaceId + "']/@compliance", "'" + level + "'");
181
		} catch (Exception e) {
182
			log.error("Error updating profile: " + dsId, e);
183
			throw new DatasourceManagerServiceException("Error updating profile: " + dsId, e);
184
		}
185
	}
186

  
187
	@Override
188
	public boolean updateBaseUrl(final String dsId, final String ifaceId, final String baseUrl) throws DatasourceManagerServiceException {
189
		return _updateBaseUrl(fixDsId(dsId), ifaceId, baseUrl);
190
	}
191

  
192
	private boolean _updateBaseUrl(final String dsId, final String ifaceId, final String baseUrl) throws DatasourceManagerServiceException {
193
		try {
194
			return serviceLocator.getService(ISRegistryService.class)
195
					.updateProfileNode(dsId, "//INTERFACE[@id = '" + ifaceId + "']/BASE_URL", "<BASE_URL>" + baseUrl + "</BASE_URL>");
196
		} catch (Exception e) {
197
			log.error("Error updating profile: " + dsId, e);
198
			throw new DatasourceManagerServiceException("Error updating profile: " + dsId, e);
199
		}
200
	}
201

  
202
	@Override
203
	public boolean updateActivationStatus(final String dsId, final String ifaceId, final boolean active) throws DatasourceManagerServiceException {
204
		return _updateActivationStatus(fixDsId(dsId), ifaceId, active);
205
	}
206

  
207
	private boolean _updateActivationStatus(final String dsId, final String ifaceId, final boolean active) throws DatasourceManagerServiceException {
208
		try {
209
			return serviceLocator.getService(ISRegistryService.class)
210
					.updateProfileNode(dsId, "//INTERFACE[@id = '" + ifaceId + "']/@active", "'" + active + "'");
211
		} catch (Exception e) {
212
			log.error("Error updating profile: " + dsId, e);
213
			throw new DatasourceManagerServiceException("Error updating profile: " + dsId, e);
214
		}
215
	}
216

  
217
	@Override
218
	public boolean updateContentDescription(final String dsId, final String ifaceId, final String desc) throws DatasourceManagerServiceException {
219
		return _updateContentDescription(fixDsId(dsId), ifaceId, desc);
220
	}
221

  
222
	private boolean _updateContentDescription(final String dsId, final String ifaceId, final String desc) throws DatasourceManagerServiceException {
223
		try {
224
			return serviceLocator.getService(ISRegistryService.class)
225
					.updateProfileNode(dsId, "//INTERFACE[@id = '" + ifaceId + "']/@contentDescription", "'" + desc + "'");
226
		} catch (Exception e) {
227
			log.error("Error updating profile: " + dsId, e);
228
			throw new DatasourceManagerServiceException("Error updating profile: " + dsId, e);
229
		}
230
	}
231

  
232
	@Override
233
	public boolean setIisProcessingWorkflow(final String dsId, final String ifaceId, final String wf) throws DatasourceManagerServiceException {
234
		throw new DatasourceManagerServiceException("NOT IMPLEMENTED");
235
	}
236

  
237
	@Override
238
	public boolean updateExtraField(final String dsId, final String ifaceId, final String field, final String value, final boolean preserveOriginal)
239
			throws DatasourceManagerServiceException {
240
		return _updateExtraField(fixDsId(dsId), ifaceId, field, value, preserveOriginal);
241
	}
242

  
243
	private boolean _updateExtraField(final String dsId, final String ifaceId, final String field, final String value, final boolean preserveOriginal)
244
			throws DatasourceManagerServiceException {
245
		try {
246
			final String profile = serviceLocator.getService(ISLookUpService.class).getResourceProfile(dsId);
247
			final Document doc = new SAXReader().read(new StringReader(profile));
248

  
249
			final Node ifcNode = doc.selectSingleNode("//INTERFACE[@id = '" + ifaceId + "']");
250
			final Node node = ifcNode.selectSingleNode("./INTERFACE_EXTRA_FIELD[@name = '" + field + "']");
251
			if (node != null) {
252
				node.setText(value);
253
			} else {
254
				final Element e = ((Element) ifcNode).addElement("INTERFACE_EXTRA_FIELD");
255
				e.addAttribute("name", field);
256
				e.setText(value);
257
			}
258
			return serviceLocator.getService(ISRegistryService.class).updateProfile(dsId, doc.asXML(), REPOSITORY_RESOURCE_TYPE);
259
		} catch (Exception e) {
260
			log.error("Error updating profile: " + dsId, e);
261
			throw new DatasourceManagerServiceException("Error updating profile: " + dsId, e);
262
		}
263
	}
264

  
265
	@Override
266
	public boolean updateAccessParam(final String dsId, final String ifaceId, final String field, final String value, final boolean preserveOriginal)
267
			throws DatasourceManagerServiceException {
268
		return _updateAccessParam(fixDsId(dsId), ifaceId, field, value, preserveOriginal);
269
	}
270

  
271
	private boolean _updateAccessParam(final String dsId, final String ifaceId, final String field, final String value, final boolean preserveOriginal)
272
			throws DatasourceManagerServiceException {
273
		try {
274
			final String profile = serviceLocator.getService(ISLookUpService.class).getResourceProfile(dsId);
275
			final Document doc = new SAXReader().read(new StringReader(profile));
276

  
277
			final Node node = doc.selectSingleNode("//INTERFACE[@id = '" + ifaceId + "']/ACCESS_PROTOCOL");
278
			((Element) node).addAttribute(field, value);
279

  
280
			return serviceLocator.getService(ISRegistryService.class).updateProfile(dsId, doc.asXML(), REPOSITORY_RESOURCE_TYPE);
281
		} catch (Exception e) {
282
			log.error("Error updating profile: " + dsId, e);
283
			throw new DatasourceManagerServiceException("Error updating profile: " + dsId, e);
284
		}
285
	}
286

  
287
	@Override
288
	public boolean deleteAccessParamOrExtraField(final String dsId, final String ifaceId, final String field) throws DatasourceManagerServiceException {
289
		return _deleteAccessParamOrExtraField(fixDsId(dsId), ifaceId, field);
290
	}
291

  
292
	private boolean _deleteAccessParamOrExtraField(final String dsId, final String ifaceId, final String field) throws DatasourceManagerServiceException {
293
		try {
294
			final String profile = serviceLocator.getService(ISLookUpService.class).getResourceProfile(dsId);
295
			final Document doc = new SAXReader().read(new StringReader(profile));
296

  
297
			final Node ef = doc.selectSingleNode("//INTERFACE[@id = '" + ifaceId + "']/INTERFACE_EXTRA_FIELD[@name = '" + field + "']");
298
			if (ef != null) {
299
				ef.detach();
300
			}
301
			final Node ap = doc.selectSingleNode("//INTERFACE[@id = '" + ifaceId + "']/ACCESS_PROTOCOL/@" + field);
302
			if (ap != null) {
303
				ap.detach();
304

  
305
			}
306
			return serviceLocator.getService(ISRegistryService.class).updateProfile(dsId, doc.asXML(), REPOSITORY_RESOURCE_TYPE);
307
		} catch (Exception e) {
308
			log.error("Error updating profile: " + dsId, e);
309
			throw new DatasourceManagerServiceException("Error updating profile: " + dsId, e);
310
		}
311
	}
312

  
313
	@Override
314
	public boolean addInterface(final String dsId, final IfaceDesc iface) throws DatasourceManagerServiceException {
315
		return _addInterface(fixDsId(dsId), iface);
316
	}
317

  
318
	private boolean _addInterface(final String dsId, final IfaceDesc iface) throws DatasourceManagerServiceException {
319
		try {
320
			final String profile = serviceLocator.getService(ISLookUpService.class).getResourceProfile(dsId);
321
			final Document doc = new SAXReader().read(new StringReader(profile));
322

  
323
			final Node node = doc.selectSingleNode("//INTERFACE[@id = '" + iface.getId() + "']");
324
			if (node != null) {
325
				node.detach();
326
			}
327

  
328
			((Element) doc.selectSingleNode("//INTERFACES")).add(IfaceDescToNode.convert(iface));
329

  
330
			return serviceLocator.getService(ISRegistryService.class).updateProfile(dsId, doc.asXML(), REPOSITORY_RESOURCE_TYPE);
331
		} catch (Exception e) {
332
			log.error("Error updating profile: " + dsId, e);
333
			throw new DatasourceManagerServiceException("Error updating profile: " + dsId, e);
334
		}
335
	}
336

  
337
	@Override
338
	public boolean deleteInterface(final String dsId, final String ifaceId) throws DatasourceManagerServiceException {
339
		return _deleteInterface(fixDsId(dsId), ifaceId);
340
	}
341

  
342
	private boolean _deleteInterface(final String dsId, final String ifaceId) throws DatasourceManagerServiceException {
343
		try {
344
			final String profile = serviceLocator.getService(ISLookUpService.class).getResourceProfile(dsId);
345
			final Document doc = new SAXReader().read(new StringReader(profile));
346

  
347
			final Node node = doc.selectSingleNode("//INTERFACE[@id = '" + ifaceId + "']");
348
			if (node != null) {
349
				node.detach();
350
			}
351

  
352
			return serviceLocator.getService(ISRegistryService.class).updateProfile(dsId, doc.asXML(), REPOSITORY_RESOURCE_TYPE);
353
		} catch (Exception e) {
354
			log.error("Error updating profile: " + dsId, e);
355
			throw new DatasourceManagerServiceException("Error updating profile: " + dsId, e);
356
		}
357
	}
358

  
359
	@Override
360
	public boolean updateSQL(final String dsId, final String sql, final boolean delete) throws DatasourceManagerServiceException {
361
		throw new DatasourceManagerServiceException("NOT IMPLEMENTED");
362
	}
363

  
364
	@Override
365
	public Date findNextScheduledExecution(final String dsId, final String ifaceId) throws DatasourceManagerServiceException {
366
		return _findNextScheduledExecution(fixDsId(dsId), ifaceId);
367
	}
368

  
369
	private Date _findNextScheduledExecution(final String dsId, final String ifaceId) throws DatasourceManagerServiceException {
370
		final String xquery = "/*[.//DATAPROVIDER/@interface='" + ifaceId + "' and .//SCHEDULING/@enabled='true']//CRON/text()";
371
		try {
372
			final String cronExpression = serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(xquery);
373
			final CronExpression cron = new CronExpression(cronExpression);
374
			return cron.getNextValidTimeAfter(new Date());
375
		} catch (ISLookUpDocumentNotFoundException e) {
376
			// When the value is not found a null value must be returned
377
			return null;
378
		} catch (ISLookUpException e) {
379
			log.error("Error in xquery: " + xquery, e);
380
			throw new DatasourceManagerServiceException("Error in xquery: " + xquery, e);
381
		} catch (ParseException e) {
382
			log.error("Error parsing cron expression", e);
383
			throw new DatasourceManagerServiceException("Error parsing cron expression", e);
384
		}
385
	}
386

  
387
	@Override
388
	public boolean bulkUpdateApiExtraFields(final String repoId, final String ifaceId, final Map<String, String> fields)
389
			throws DatasourceManagerServiceException {
390
		try {
391
			final String profile = serviceLocator.getService(ISLookUpService.class).getResourceProfile(repoId);
392

  
393
			final SAXReader reader = new SAXReader();
394
			final Document doc = reader.read(new StringReader(profile));
395

  
396
			final Element iface = (Element) doc.selectSingleNode("//INTERFACE[@id='" + ifaceId + "']");
397
			if (iface != null) {
398

  
399
				while (iface.selectNodes("./INTERFACE_EXTRA_FIELD").size() > 0) {
400
					iface.selectSingleNode("./INTERFACE_EXTRA_FIELD").detach();
401
				}
402
				for (Map.Entry<String, String> e : fields.entrySet()) {
403
					if (e.getValue() != null && !e.getValue().isEmpty()) {
404
						final Element field = iface.addElement("INTERFACE_EXTRA_FIELD");
405
						field.addAttribute("name", e.getKey());
406
						field.addText(e.getValue());
407
					}
408
				}
409
				serviceLocator.getService(ISRegistryService.class).updateProfile(repoId, doc.asXML(), REPOSITORY_RESOURCE_TYPE);
410
			} else {
411
				log.error("Invalid interface: " + ifaceId);
412
				throw new DatasourceManagerServiceException("Missing interface: " + ifaceId);
413
			}
414
		} catch (Exception e) {
415
			log.error("Error updating API of profile: " + repoId);
416
			throw new DatasourceManagerServiceException("Error updating API of profile: " + repoId, e);
417
		}
418
		return true;
419

  
420
	}
421

  
422
	@Override
423
	public boolean bulkUpdateApiAccessParams(final String dsId, final String ifaceId, final Map<String, String> params)
424
			throws DatasourceManagerServiceException {
425
		return _bulkUpdateApiAccessParams(fixDsId(dsId), ifaceId, params);
426
	}
427

  
428
	private boolean _bulkUpdateApiAccessParams(final String repoId, final String ifaceId, final Map<String, String> params)
429
			throws DatasourceManagerServiceException {
430
		try {
431
			final String profile = serviceLocator.getService(ISLookUpService.class).getResourceProfile(repoId);
432

  
433
			final SAXReader reader = new SAXReader();
434
			final Document doc = reader.read(new StringReader(profile));
435

  
436
			final Element accessNode = (Element) doc.selectSingleNode("//INTERFACE[@id='" + ifaceId + "']/ACCESS_PROTOCOL");
437
			if (accessNode != null) {
438
				while (accessNode.attributes().size() > 0) {
439
					accessNode.selectSingleNode("@*").detach();
440
				}
441
				for (Map.Entry<String, String> e : params.entrySet()) {
442
					if (e.getValue() != null && !e.getValue().isEmpty()) {
443
						if (e.getKey().equalsIgnoreCase("baseUrl")) {
444
							doc.selectSingleNode("//INTERFACE[@id='" + ifaceId + "']/BASE_URL").setText(e.getValue());
445
						} else {
446
							accessNode.addAttribute(e.getKey(), e.getValue());
447
						}
448
					}
449
				}
450
				serviceLocator.getService(ISRegistryService.class).updateProfile(repoId, doc.asXML(), REPOSITORY_RESOURCE_TYPE);
451
			} else {
452
				log.error("Invalid interface: " + ifaceId);
453
				throw new DatasourceManagerServiceException("Missing interface: " + ifaceId);
454
			}
455
		} catch (Exception e) {
456
			log.error("Error updating API of profile: " + repoId);
457
			throw new DatasourceManagerServiceException("Error updating API of profile: " + repoId, e);
458
		}
459
		return true;
460
	}
461

  
462
	@Override
463
	public boolean overrideCompliance(final String dsId, final String ifaceId, final String level) throws DatasourceManagerServiceException {
464
		return _overrideCompliance(fixDsId(dsId), ifaceId, level);
465
	}
466

  
467
	private boolean _overrideCompliance(final String repoId, final String ifaceId, final String compliance) throws DatasourceManagerServiceException {
468
		try {
469
			final String profile = serviceLocator.getService(ISLookUpService.class).getResourceProfile(repoId);
470

  
471
			final SAXReader reader = new SAXReader();
472
			final Document doc = reader.read(new StringReader(profile));
473

  
474
			final Element iface = (Element) doc.selectSingleNode("//INTERFACE[@id='" + ifaceId + "']");
475
			if (iface != null) {
476
				final Map<String, String> fields = Maps.newHashMap();
477

  
478
				if (!StringUtils.isEmpty(compliance)) {
479
					fields.put(DatasourceConstants.OVERRIDING_COMPLIANCE_FIELD, compliance);
480
				}
481

  
482
				while (iface.selectNodes("./INTERFACE_EXTRA_FIELD").size() > 0) {
483
					final Node node = iface.selectSingleNode("./INTERFACE_EXTRA_FIELD");
484
					final String name = node.valueOf("@name");
485

  
486
					if (!name.equals(DatasourceConstants.OVERRIDING_COMPLIANCE_FIELD)) {
487
						fields.put(node.valueOf("@name"), node.getText());
488
					}
489
					node.detach();
490
				}
491

  
492
				for (Map.Entry<String, String> e : fields.entrySet()) {
493
					if (e.getValue() != null && !e.getValue().isEmpty()) {
494
						final Element field = iface.addElement("INTERFACE_EXTRA_FIELD");
495
						field.addAttribute("name", e.getKey());
496
						field.addText(e.getValue());
497
					}
498
				}
499
				serviceLocator.getService(ISRegistryService.class).updateProfile(repoId, doc.asXML(), REPOSITORY_RESOURCE_TYPE);
500
			} else {
501
				log.error("Invalid interface: " + ifaceId);
502
				throw new DatasourceManagerServiceException("Missing interface: " + ifaceId);
503
			}
504
		} catch (Exception e) {
505
			log.error("Error updating API of profile: " + repoId);
506
			throw new DatasourceManagerServiceException("Error updating API of profile: " + repoId, e);
507
		}
508

  
509
		return true;
510
	}
511

  
512
	@Override
513
	public List<BrowsableField> listBrowsableFields() throws DatasourceManagerServiceException {
514
		return Lists.transform(getBrowsableFields(), new Function<XmlBrowsableField, BrowsableField>() {
515

  
516
			@Override
517
			public BrowsableField apply(final XmlBrowsableField f) {
518
				return new BrowsableField(f.getId(), f.getLabel());
519
			}
520
		});
521
	}
522

  
523
	@Override
524
	public List<BrowseTerm> browseField(final String f) throws DatasourceManagerServiceException {
525

  
526
		final List<BrowseTerm> list = Lists.newArrayList();
527

  
528
		try {
529
			final XmlBrowsableField field = findBrowseField(f);
530
			if (field != null) {
531
				final StringTemplate st = new StringTemplate(IOUtils.toString(browseRepoApisQueryTmpl.getInputStream()));
532
				st.setAttribute("xpath", field.getXpath());
533

  
534
				final Map<String, String> terms = fetchVocabularyTerms(field.getVocabulary());
535

  
536
				for (String s : serviceLocator.getService(ISLookUpService.class).quickSearchProfile(st.toString())) {
537
					final String[] arr = s.split("@-@-@");
538
					final String id = arr[0].trim();
539
					final int count = NumberUtils.toInt(arr[1].trim(), 0);
540
					list.add(new BrowseTerm(id, findLabel(id, terms), count));
541
				}
542
			}
543
		} catch (Exception e) {
544
			log.error("Error browsing field " + f, e);
545
		}
546

  
547
		return list;
548
	}
549

  
550
	private String findLabel(final String code, final Map<String, String> terms) {
551
		return terms.containsKey(code) ? terms.get(code) : code;
552
	}
553

  
554
	public Map<String, String> fetchVocabularyTerms(final String voc) throws ISLookUpException {
555
		final String xquery = "for $x in collection('/db/DRIVER/VocabularyDSResources/VocabularyDSResourceType')[.//VOCABULARY_NAME/@code = '"
556
				+ voc.trim() + "']//TERM return concat($x/@code, ' @@@ ', $x/@english_name)";
557

  
558
		final Map<String, String> map = Maps.newHashMap();
559
		for (String s : serviceLocator.getService(ISLookUpService.class).quickSearchProfile(xquery)) {
560
			final String[] arr = s.split("@@@");
561
			map.put(arr[0].trim(), arr[1].trim());
562
		}
563
		return map;
564
	}
565

  
566
	private XmlBrowsableField findBrowseField(final String id) {
567
		for (XmlBrowsableField f : getBrowsableFields()) {
568
			if (f.getId().equals(id)) { return f; }
569
		}
570
		return null;
571
	}
572

  
573
	@Override
574
	public List<SearchInterfacesEntry> searchInterface(final String field, final String value) throws DatasourceManagerServiceException {
575
		try {
576

  
577
			final StringTemplate st = new StringTemplate();
578
			st.setTemplate(IOUtils.toString(findRepoApisQueryTmpl.getInputStream()));
579

  
580
			if (field.equalsIgnoreCase("__search__")) {
581
				st.setAttribute("cond", "contains(../..//(*|@*)/lower-case(.), '" + StringEscapeUtils.escapeXml(value.toLowerCase()) + "')");
582
			} else {
583
				final XmlBrowsableField f = findBrowseField(field);
584
				if (f != null) {
585
					st.setAttribute("cond", f.getXpath() + "='" + StringEscapeUtils.escapeXml(value) + "'");
586
				} else {
587
					return Lists.newArrayList();
588
				}
589
			}
590

  
591
			final String query = st.toString();
592

  
593
			final SAXReader reader = new SAXReader();
594

  
595
			final List<String> list = serviceLocator.getService(ISLookUpService.class).quickSearchProfile(query);
596

  
597
			return Lists.transform(list, new Function<String, SearchInterfacesEntry>() {
598

  
599
				@Override
600
				public SearchInterfacesEntry apply(final String s) {
601
					final SearchInterfacesEntry iface = new SearchInterfacesEntry();
602
					try {
603
						final Document doc = reader.read(new StringReader(s));
604
						final String country = doc.valueOf("//REPO/@country");
605

  
606
						iface.setRepoId(doc.valueOf("//REPO/@id"));
607
						iface.setRepoCountry(StringUtils.isEmpty(country) ? "-" : country.toUpperCase());
608
						iface.setRepoName(doc.valueOf("//REPO/@name"));
609
						iface.setRepoPrefix(doc.valueOf("//REPO/@prefix"));
610

  
611
						final Node ifcNode = doc.selectSingleNode("//INTERFACE");
612

  
613
						iface.setId(ifcNode.valueOf("./@id"));
614
						iface.setActive(Boolean.valueOf(ifcNode.valueOf("./@active")));
615
						iface.setProtocol(ifcNode.valueOf("./ACCESS_PROTOCOL/text()"));
616

  
617
						final String overCompliance = ifcNode.valueOf("./INTERFACE_EXTRA_FIELD[@name='overriding_compliance']");
618
						if (StringUtils.isEmpty(overCompliance)) {
619
							iface.setCompliance(ifcNode.valueOf("@compliance"));
620
						} else {
621
							iface.setCompliance(overCompliance);
622
						}
623

  
624
						final String lastAggregationDate = ifcNode.valueOf("./INTERFACE_EXTRA_FIELD[@name='last_aggregation_date']");
625
						if (!StringUtils.isEmpty(lastAggregationDate)) {
626
							iface.setAggrDate(lastAggregationDate);
627
						} else {
628
							final String lastDownloadDate = ifcNode.valueOf("./INTERFACE_EXTRA_FIELD[@name='last_download_date']");
629
							if (!StringUtils.isEmpty(lastDownloadDate)) {
630
								iface.setAggrDate(lastDownloadDate);
631
							}
632
						}
633
						final String lastAggregationTotal = ifcNode.valueOf("./INTERFACE_EXTRA_FIELD[@name='last_aggregation_total']");
634
						if (StringUtils.isEmpty(lastAggregationTotal)) {
635
							final String lastDownloadTotal = ifcNode.valueOf("./INTERFACE_EXTRA_FIELD[@name='last_download_total']");
636
							if (StringUtils.isEmpty(lastDownloadTotal)) {
637
								iface.setAggrTotal(0);
638
							} else {
639
								iface.setAggrTotal(NumberUtils.toInt(lastDownloadTotal, 0));
640
							}
641
						} else {
642
							iface.setAggrTotal(NumberUtils.toInt(lastAggregationTotal, 0));
643
						}
644
					} catch (Exception e) {
645
						log.error(e);
646
					}
647
					return iface;
648
				}
649
			});
650
		} catch (Exception e) {
651
			log.error("Error searching field " + field + " - value: " + value, e);
652
		}
653
		return Lists.newArrayList();
654
	}
655

  
656
	@Override
657
	public List<RepositoryMapEntry> getRepositoryMap() throws DatasourceManagerServiceException {
658
		try {
659
			final SAXReader reader = new SAXReader();
660

  
661
			final String query = IOUtils.toString(findReposMapQuery.getInputStream());
662
			final List<String> list = serviceLocator.getService(ISLookUpService.class).quickSearchProfile(query);
663
			return Lists.transform(list, new Function<String, RepositoryMapEntry>() {
664

  
665
				@Override
666
				public RepositoryMapEntry apply(final String s) {
667
					final RepositoryMapEntry r = new RepositoryMapEntry();
668

  
669
					try {
670
						final Document doc = reader.read(new StringReader(s));
671
						r.setId(doc.valueOf("//dsId"));
672
						r.setName(doc.valueOf("//name"));
673
						r.setLat(Float.parseFloat(doc.valueOf("//lat")));
674
						r.setLng(Float.parseFloat(doc.valueOf("//lng")));
675
					} catch (Exception e) {
676
						log.error(e);
677
					}
678
					return r;
679
				}
680
			});
681
		} catch (Exception e) {
682
			log.error("Error obtaing repo map entries", e);
683
		}
684
		return Lists.newArrayList();
685
	}
686

  
687
	private List<XmlBrowsableField> getBrowsableFields() {
688
		return browsableFields;
689
	}
690

  
691
	@Required
692
	public void setBrowsableFields(final List<XmlBrowsableField> browsableFields) {
693
		this.browsableFields = browsableFields;
694
	}
695

  
696
	@Override
697
	public List<SimpleDatasourceDesc> simpleListDatasourcesByType(final String type) throws DatasourceManagerServiceException {
698
		try {
699
			final List<SimpleDatasourceDesc> list = Lists.newArrayList();
700

  
701
			final StringTemplate st = new StringTemplate(IOUtils.toString(simpleFindReposQueryTmpl.getInputStream()));
702
			st.setAttribute("type", type);
703

  
704
			for (String s : serviceLocator.getService(ISLookUpService.class).quickSearchProfile(st.toString())) {
705
				final SimpleDatasourceDesc r = new SimpleDatasourceDesc();
706
				final String[] arr = s.split("@=@");
707
				r.setId(arr[0].trim());
708
				r.setName(arr[1].trim());
709
				r.setOrigId(arr[2].trim());
710
				r.setApis(Sets.newHashSet(arr[3].replaceAll("\\s", "").split(",")));
711
				r.setValid("true".equals(arr[4].trim()));
712
				r.setTypology(type);
713
				list.add(r);
714
			}
715

  
716
			Collections.sort(list);
717

  
718
			return list;
719
		} catch (Exception e) {
720
			log.error("Error listing repos", e);
721
		}
722
		return Lists.newArrayList();
723
	}
724

  
725
}
modules/dnet-datasource-manager-service/tags/dnet-datasource-manager-service-1.0.3/src/main/java/eu/dnetlib/enabling/datasources/DatasourceDescToProfile.java
1
package eu.dnetlib.enabling.datasources;
2

  
3
import com.google.common.base.Function;
4
import eu.dnetlib.enabling.datasources.rmi.DatasourceDesc;
5
import eu.dnetlib.enabling.datasources.rmi.IfaceDesc;
6
import eu.dnetlib.miscutils.datetime.DateUtils;
7
import org.apache.commons.logging.Log;
8
import org.apache.commons.logging.LogFactory;
9
import org.dom4j.DocumentHelper;
10
import org.dom4j.Element;
11

  
12
public class DatasourceDescToProfile implements Function<DatasourceDesc, String> {
13

  
14
	private static final Log log = LogFactory.getLog(DatasourceDescToProfile.class);
15

  
16
	public static String convert(final DatasourceDesc ds) throws Exception {
17
		final Element root = DocumentHelper.createElement("RESOURCE_PROFILE");
18

  
19
		final Element header = root.addElement("HEADER");
20
		header.addElement("RESOURCE_IDENTIFIER").addAttribute("value", "");
21
		header.addElement("RESOURCE_TYPE").addAttribute("value", "RepositoryServiceResourceType");
22
		header.addElement("RESOURCE_KIND").addAttribute("value", "RepositoryServiceResources");
23
		header.addElement("RESOURCE_URI").addAttribute("value", "");
24
		header.addElement("DATE_OF_CREATION").addAttribute("value", DateUtils.now_ISO8601());
25
		header.addElement("PROTOCOL");
26

  
27
		final Element body = root.addElement("BODY");
28
		final Element conf = body.addElement("CONFIGURATION");
29
		conf.addElement("DATASOURCE_TYPE").setText(ds.getDatasourceClass());
30

  
31
		final Element origId = conf.addElement("DATASOURCE_ORIGINAL_ID");
32
		origId.addAttribute("provenance", "D-NET");
33
		origId.setText(ds.getId());
34

  
35
		conf.addElement("DATASOURCE_AGGREGATED").setText("false");
36
		conf.addElement("ENVIRONMENTS");
37
		conf.addElement("TYPOLOGY").setText(ds.getTypology());
38
		conf.addElement("MAX_SIZE_OF_DATASTRUCTURE").setText("0");
39
		conf.addElement("AVAILABLE_DISKSPACE").setText("0");
40
		conf.addElement("MAX_NUMBER_OF_DATASTRUCTURE").setText("0");
41

  
42
		conf.addElement("OFFICIAL_NAME").setText(ds.getOfficialName());
43
		conf.addElement("ENGLISH_NAME").setText(ds.getEnglishName());
44
		conf.addElement("ICON_URI").setText(ds.getLogoUrl());
45
		conf.addElement("COUNTRY").setText(ds.getCountryCode());
46

  
47
		final Element location = conf.addElement("LOCATION");
48
		location.addElement("LONGITUDE").setText("" + ds.getLongitude());
49
		location.addElement("LATITUDE").setText("" + ds.getLatitude());
50
		location.addElement("TIMEZONE").setText("" + ds.getTimezone());
51

  
52
		conf.addElement("REPOSITORY_WEBPAGE").setText(ds.getWebsiteUrl());
53
		conf.addElement("REPOSITORY_INSTITUTION").setText(ds.getOrganization());
54
		conf.addElement("ADMIN_INFO").setText(ds.getContactEmail());
55

  
56
		final Element ifaces = conf.addElement("INTERFACES");
57
		for (IfaceDesc ifc : ds.getInterfaces()) {
58
			ifaces.add(IfaceDescToNode.convert(ifc));
59
		}
60
		final Element extraFields = conf.addElement("EXTRA_FIELDS");
61
		addExtraField(extraFields, "ACTIVATION_ID", ds.getActivationId());
62
		addExtraField(extraFields, "NamespacePrefix", ds.getNamespacePrefix());
63
		addExtraField(extraFields, "aggregatorName", ds.getAggregator());
64
		addExtraField(extraFields, "dateOfCollection", "" + ds.getDateOfCollection());
65
		addExtraField(extraFields, "dateOfValidation", "" + ds.getDateOfValidation());
66
		conf.addElement("REGISTERED_BY");
67

  
68
		final Element status = body.addElement("STATUS");
69
		status.addElement("NUMBER_OF_OBJECTS").setText("0");
70
		status.addElement("LAST_UPDATE").addAttribute("value", "");
71

  
72
		final Element qos = body.addElement("QOS");
73
		qos.addElement("AVAILABILITY").setText("0");
74
		qos.addElement("CAPACITY");
75
		qos.addElement("THROUGHPUT").setText("0");
76

  
77
		body.addElement("SECURITY_PARAMETERS");
78
		body.addElement("BLACKBOARD");
79

  
80
		return root.asXML();
81
	}
82

  
83
	private static void addExtraField(final Element extraFields, final String field, final String value) {
84
		final Element f = extraFields.addElement("FIELD");
85
		f.addElement("key").setText(field);
86
		f.addElement("value").setText(value != null ? value : "");
87
	}
88

  
89
	@Override
90
	public String apply(final DatasourceDesc ds) {
91
		try {
92
			return DatasourceDescToProfile.convert(ds);
93
		} catch (Exception e) {
94
			log.error("Error convering profile", e);
95
			return null;
96
		}
97
	}
98
}
modules/dnet-datasource-manager-service/tags/dnet-datasource-manager-service-1.0.3/src/main/java/eu/dnetlib/enabling/datasources/ProfileToDatasourceDesc.java
1
package eu.dnetlib.enabling.datasources;
2

  
3
import java.io.StringReader;
4

  
5
import org.apache.commons.lang.BooleanUtils;
6
import org.apache.commons.lang.math.NumberUtils;
7
import org.apache.commons.logging.Log;
8
import org.apache.commons.logging.LogFactory;
9
import org.dom4j.Document;
10
import org.dom4j.Element;
11
import org.dom4j.Node;
12
import org.dom4j.io.SAXReader;
13

  
14
import com.google.common.base.Function;
15

  
16
import eu.dnetlib.enabling.datasources.rmi.DatasourceDesc;
17
import eu.dnetlib.enabling.datasources.rmi.IfaceDesc;
18
import eu.dnetlib.miscutils.datetime.DateUtils;
19

  
20
public class ProfileToDatasourceDesc implements Function<String, DatasourceDesc> {
21

  
22
	private static final Log log = LogFactory.getLog(ProfileToDatasourceDesc.class);
23

  
24
	@Override
25
	public DatasourceDesc apply(final String profile) {
26
		try {
27
			return ProfileToDatasourceDesc.convert(profile);
28
		} catch (Exception e) {
29
			log.error("Error convering profile", e);
30
			return null;
31
		}
32
	}
33

  
34
	public static DatasourceDesc convert(final String profile) throws Exception {
35
		final SAXReader reader = new SAXReader();
36
		final Document doc = reader.read(new StringReader(profile));
37

  
38
		final DatasourceDesc ds = new DatasourceDesc();
39
		ds.setId(doc.valueOf("//RESOURCE_IDENTIFIER/@value"));
40
		ds.setDatasourceClass(doc.valueOf("//DATASOURCE_TYPE"));
41
		ds.setTypology(doc.valueOf("//TYPOLOGY"));
42
		ds.setOfficialName(doc.valueOf("//OFFICIAL_NAME"));
43
		ds.setEnglishName(doc.valueOf("//ENGLISH_NAME"));
44
		ds.setCountryCode(doc.valueOf("//COUNTRY"));
45
		ds.setLongitude(NumberUtils.toDouble(doc.valueOf("//LOCATION/LONGITUDE"), 0.0));
46
		ds.setLatitude(NumberUtils.toDouble(doc.valueOf("//LOCATION/LATITUDE"), 0.0));
47
		ds.setTimezone(NumberUtils.toDouble(doc.valueOf("//LOCATION/TIMEZONE"), 0.0));
48
		ds.setWebsiteUrl(doc.valueOf("//REPOSITORY_WEBPAGE"));
49
		ds.setOrganization(doc.valueOf("//REPOSITORY_INSTITUTION"));
50
		ds.setContactEmail(doc.valueOf("//ADMIN_INFO"));
51

  
52
		for (Object o : doc.selectNodes("//INTERFACES/INTERFACE")) {
53
			final Element n = (Element) o;
54

  
55
			final IfaceDesc ifc = new IfaceDesc();
56

  
57
			ifc.setId(n.valueOf("@id"));
58
			ifc.setCompliance(n.valueOf("@compliance"));
59
			ifc.setTypology(n.valueOf("@typology"));
60
			ifc.setContentDescription(n.valueOf("@contentDescription"));
61
			ifc.setActive(BooleanUtils.toBoolean(n.valueOf("@active")));
62
			ifc.setRemovable(BooleanUtils.toBoolean(n.valueOf("@removable")));
63
			ifc.setBaseUrl(n.valueOf("./BASE_URL"));
64
			ifc.setAccessProtocol(n.valueOf("./ACCESS_PROTOCOL"));
65

  
66
			for (Object o1 : n.selectNodes("./ACCESS_PROTOCOL/@*")) {
67
				final Node attr = (Node) o1;
68
				ifc.getAccessParams().put(attr.getName(), attr.getText());
69
			}
70
			for (Object o1 : n.selectNodes("./INTERFACE_EXTRA_FIELD")) {
71
				final Node f = (Node) o1;
72
				ifc.getExtraFields().put(f.valueOf("@name"), f.getText());
73
			}
74

  
75
			ds.getInterfaces().add(ifc);
76
		}
77

  
78
		final DateUtils dateUtils = new DateUtils();
79
		for (Object o : doc.selectNodes("//EXTRA_FIELDS/EXTRA_FIELD")) {
80
			final String k = ((Element) o).valueOf("./key").trim();
81
			final String v = ((Element) o).valueOf("./value").trim();
82

  
83
			if (k.equalsIgnoreCase("ACTIVATION_ID")) {
84
				ds.setActivationId(v);
85
			} else if (k.equalsIgnoreCase("NamespacePrefix")) {
86
				ds.setNamespacePrefix(v);
87
			} else if (k.equalsIgnoreCase("aggregatorName")) {
88
				ds.setAggregator(v);
89
			} else if (k.equalsIgnoreCase("dateOfCollection")) {
90
				ds.setDateOfCollection(dateUtils.parse(v));
91
			} else if (k.equalsIgnoreCase("dateOfValidation")) {
92
				ds.setDateOfValidation(dateUtils.parse(v));
93
			}
94
		}
95

  
96
		return ds;
97
	}
98
}
modules/dnet-datasource-manager-service/tags/dnet-datasource-manager-service-1.0.3/src/main/resources/eu/dnetlib/enabling/datasources/applicationContext-datasource-manager-service.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<beans xmlns="http://www.springframework.org/schema/beans"
3
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
4
	xmlns:sec="http://cxf.apache.org/configuration/security" xmlns:wsa="http://cxf.apache.org/ws/addressing"
5
	xmlns:p="http://www.springframework.org/schema/p" xmlns:http="http://cxf.apache.org/transports/http/configuration"
6
	xmlns:t="http://dnetlib.eu/springbeans/t" xmlns:template="http://dnetlib.eu/springbeans/template"
7
	xmlns:util="http://www.springframework.org/schema/util"
8
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
9
                                    http://cxf.apache.org/ws/addressing http://cxf.apache.org/schemas/ws-addr-conf.xsd
10
                                    http://cxf.apache.org/configuration/security http://cxf.apache.org/schemas/configuration/security.xsd
11
                                    http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd
12
                            http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
13
                            http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
14
                            http://dnetlib.eu/springbeans/template http://dnetlib.eu/springbeans/template.xsd">
15

  
16
	<bean id="datasourceManagerService"
17
		class="eu.dnetlib.enabling.datasources.DatasourceManagerServiceImpl">
18
		<property name="browsableFields">
19
			<list>
20
				<bean class="eu.dnetlib.enabling.datasources.XmlBrowsableField"
21
					p:id="country" p:label="Datasource countries" p:xpath="../../COUNTRY/text()"
22
					p:vocabulary="dnet:countries" />
23
				<bean class="eu.dnetlib.enabling.datasources.XmlBrowsableField"
24
					p:id="type" p:label="API typologies" p:xpath="@typology/string()"
25
					p:vocabulary="dnet:datasource_typologies" />
26
				<bean class="eu.dnetlib.enabling.datasources.XmlBrowsableField"
27
					p:id="protocol" p:label="API protocols" p:xpath="ACCESS_PROTOCOL/text()"
28
					p:vocabulary="dnet:protocols" />
29
				<bean class="eu.dnetlib.enabling.datasources.XmlBrowsableField"
30
					p:id="compliance" p:label="API compatibility levels"
31
					p:xpath="concat(substring(./INTERFACE_EXTRA_FIELD[@name='overriding_compliance'], 1, number(boolean(./INTERFACE_EXTRA_FIELD[@name='overriding_compliance'])) * string-length(./INTERFACE_EXTRA_FIELD[@name='overriding_compliance'])), substring(@compliance, 1, number(not(boolean(./INTERFACE_EXTRA_FIELD[@name='overriding_compliance']))) * string-length(@compliance)))"
32
					p:vocabulary="dnet:compatibilityLevel" />
33
			</list>
34
		</property>
35
	</bean>
36

  
37
	<!-- endpoints -->
38
	<jaxws:endpoint id="datasourceManagerServiceEndpoint"
39
		implementor="#datasourceManagerService"
40
		implementorClass="eu.dnetlib.enabling.datasources.rmi.DatasourceManagerService"
41
		address="/datasourceManager" />
42

  
43
	<template:instance name="serviceRegistrationManager"
44
		t:serviceRegistrationManagerClass="eu.dnetlib.enabling.tools.registration.ValidatingServiceRegistrationManagerImpl"
45
		t:name="datasourceManagerServiceRegistrationManager" t:service="datasourceManagerService"
46
		t:endpoint="datasourceManagerServiceEndpoint" t:jobScheduler="jobScheduler" />
47

  
48
</beans>
modules/dnet-datasource-manager-service/tags/dnet-datasource-manager-service-1.0.3/src/main/resources/eu/dnetlib/enabling/datasources/templates/findReposMap.xquery
1
for $x in
2
	collection('/db/DRIVER/RepositoryServiceResources/RepositoryServiceResourceType')
3
where 
4
	$x//NUMBER_OF_OBJECTS != 0 and not($x//LATITUDE = 0 and $x//LONGITUDE = 0) 
5
return 
6
<ds>
7
	<dsId>{$x//RESOURCE_IDENTIFIER/@value/string()}</dsId>
8
	<name>{$x//OFFICIAL_NAME/text()}</name>
9
	<lat>{$x//LATITUDE/text()}</lat>
10
	<lng>{$x//LONGITUDE/text()}</lng>
11
</ds>
modules/dnet-datasource-manager-service/tags/dnet-datasource-manager-service-1.0.3/src/main/resources/eu/dnetlib/enabling/datasources/templates/findRepoApis.xquery.st
1
for \$x in 
2
collection('/db/DRIVER/RepositoryServiceResources/RepositoryServiceResourceType')//INTERFACE[$cond$]
3
return 
4
	<ROW>
5
		<REPO 
6
			id="{\$x/../../../../HEADER/RESOURCE_IDENTIFIER/@value/string()}" 
7
			name="{\$x/../../OFFICIAL_NAME/text()}" 
8
			country="{\$x/../../COUNTRY/text()}" 
9
			prefix="{\$x/../..//EXTRA_FIELDS/FIELD[./key='NamespacePrefix']/value}" />
10
		{\$x}
11
	</ROW>
modules/dnet-datasource-manager-service/tags/dnet-datasource-manager-service-1.0.3/src/main/resources/eu/dnetlib/enabling/datasources/templates/simpleFindRepos.xquery.st
1
for \$x in
2
	collection('/db/DRIVER/RepositoryServiceResources/RepositoryServiceResourceType')
3
where
4
	\$x//DATASOURCE_TYPE = '$type$'
5
return
6
	concat(\$x//RESOURCE_IDENTIFIER/@value, ' @=@ ', \$x//OFFICIAL_NAME, ' @=@ ', \$x//DATASOURCE_ORIGINAL_ID, ' @=@ ', string-join(\$x//INTERFACE/@id, ','), ' @=@ true'),
7
for \$x in
8
	collection('/db/DRIVER/PendingRepositoryResources/RepositoryServiceResourceType')
9
where
10
	\$x//DATASOURCE_TYPE = '$type$'
11
return
12
	concat(\$x//RESOURCE_IDENTIFIER/@value, ' @=@ ', \$x//OFFICIAL_NAME, ' @=@ ', \$x//DATASOURCE_ORIGINAL_ID, ' @=@ ', string-join(\$x//INTERFACE/@id, ','), ' @=@ false')
modules/dnet-datasource-manager-service/tags/dnet-datasource-manager-service-1.0.3/src/main/resources/eu/dnetlib/enabling/datasources/templates/browseRepoApis.xquery.st
1
let \$list := collection('/db/DRIVER/RepositoryServiceResources/RepositoryServiceResourceType')//INTERFACE/$xpath$
2

  
3
for \$x in distinct-values(\$list) 
4
where string-length(\$x) > 0
5
return concat(\$x, ' @-@-@ ', count(\$list[.=\$x]))
modules/dnet-datasource-manager-service/tags/dnet-datasource-manager-service-1.0.3/src/main/resources/eu/dnetlib/enabling/datasources/templates/findRepos.xquery.st
1
for \$x in collection('/db/DRIVER/RepositoryServiceResources/RepositoryServiceResourceType')
2
$if(conds)$
3
	where $conds.keys:{xpath| \$x$xpath$ = '$conds.(xpath)$'}; separator=" and "$
4
$endif$
5
return \$x
6
,
7
for \$x in collection('/db/DRIVER/PendingRepositoryResources/RepositoryServiceResourceType')
8
$if(conds)$
9
	where $conds.keys:{xpath| \$x$xpath$ = '$conds.(xpath)$'}; separator=" and "$
10
$endif$
11
return \$x
modules/dnet-datasource-manager-service/tags/dnet-datasource-manager-service-1.0.3/.springBeans
1
<?xml version="1.0" encoding="UTF-8"?>
2
<beansProjectDescription>
3
	<version>1</version>
4
	<pluginVersion><![CDATA[3.6.2.201410090854-RELEASE]]></pluginVersion>
5
	<configSuffixes>
6
		<configSuffix><![CDATA[xml]]></configSuffix>
7
	</configSuffixes>
8
	<enableImports><![CDATA[false]]></enableImports>
9
	<configs>
10
		<config>src/main/resources/eu/dnetlib/enabling/datasources/applicationContext-datasource-manager-service.xml</config>
11
	</configs>
12
	<autoconfigs>
13
	</autoconfigs>
14
	<configSets>
15
	</configSets>
16
</beansProjectDescription>
modules/dnet-datasource-manager-service/tags/dnet-datasource-manager-service-1.0.3/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3
	<parent>
4
    		<groupId>eu.dnetlib</groupId>
5
	        <artifactId>dnet-parent</artifactId>
6
                <version>1.0.0</version>
7
  	</parent>
8
	<modelVersion>4.0.0</modelVersion>
9
	<groupId>eu.dnetlib</groupId>
10
	<artifactId>dnet-datasource-manager-service</artifactId>
11
	<packaging>jar</packaging>
12
	<version>1.0.3</version>
13
	<scm>
14
		<developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/dnet-datasource-manager-service/tags/dnet-datasource-manager-service-1.0.3</developerConnection>
15
	</scm>
16
	<dependencies>
17
		<dependency>
18
			<groupId>eu.dnetlib</groupId>
19
			<artifactId>dnet-datasource-manager-rmi</artifactId>
20
			<version>[4.0.0, 5.0.0)</version>
21
		</dependency>
22
		<dependency>
23
			<groupId>eu.dnetlib</groupId>
24
			<artifactId>cnr-service-common</artifactId>
25
			<version>[2.1.0,3.0.0)</version>
26
		</dependency>
27
		<dependency>
28
  		    <groupId>junit</groupId>
29
    		    <artifactId>junit</artifactId>
30
      		    <version>${junit.version}</version>
31
	            <scope>test</scope>
32
    		</dependency>
33
	</dependencies>
34
</project>

Also available in: Unified diff