Project

General

Profile

« Previous | Next » 

Revision 41842

added dnet-datasource manager service

View differences:

modules/dnet-core-services/trunk/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 eu.dnetlib.rmi.datasource.IfaceDesc;
6
import org.dom4j.DocumentHelper;
7
import org.dom4j.Element;
8

  
9
public class IfaceDescToNode {
10

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

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

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

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

  
29
		ifcNode.addElement("BASE_URL").setText(iface.getBaseUrl());
30
		;
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-core-services/trunk/src/main/java/eu/dnetlib/enabling/datasources/XmlBrowsableField.java
1
package eu.dnetlib.enabling.datasources;
2

  
3
import eu.dnetlib.rmi.datasource.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-core-services/trunk/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.*;
6
import java.util.stream.Collectors;
7
import javax.annotation.Resource;
8

  
9
import com.google.common.collect.Sets;
10
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
11
import eu.dnetlib.enabling.tools.AbstractBaseService;
12
import eu.dnetlib.rmi.datasource.*;
13
import eu.dnetlib.rmi.enabling.*;
14
import org.antlr.stringtemplate.StringTemplate;
15
import org.apache.commons.io.IOUtils;
16
import org.apache.commons.lang3.StringEscapeUtils;
17
import org.apache.commons.lang3.StringUtils;
18
import org.apache.commons.lang3.math.NumberUtils;
19
import org.apache.commons.logging.Log;
20
import org.apache.commons.logging.LogFactory;
21
import org.dom4j.Document;
22
import org.dom4j.Element;
23
import org.dom4j.Node;
24
import org.dom4j.io.SAXReader;
25
import org.quartz.CronExpression;
26
import org.springframework.beans.factory.annotation.Required;
27
import org.springframework.core.io.ClassPathResource;
28

  
29
public class DatasourceManagerServiceImpl extends AbstractBaseService implements DatasourceManagerService {
30

  
31
	private static final Log log = LogFactory.getLog(DatasourceManagerServiceImpl.class);
32

  
33
	private static final String REPOSITORY_RESOURCE_TYPE = "RepositoryServiceResourceType";
34

  
35
	private List<XmlBrowsableField> browsableFields;
36

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

  
39
	private ClassPathResource browseRepoApisQueryTmpl = new ClassPathResource("/eu/dnetlib/enabling/datasources/templates/browseRepoApis.xquery.st");
40
	private ClassPathResource findRepoApisQueryTmpl = new ClassPathResource("/eu/dnetlib/enabling/datasources/templates/findRepoApis.xquery.st");
41
	private ClassPathResource findReposMapQuery = new ClassPathResource("/eu/dnetlib/enabling/datasources/templates/findReposMap.xquery");
42
	private ClassPathResource simpleFindReposQueryTmpl = new ClassPathResource("/eu/dnetlib/enabling/datasources/templates/simpleFindRepos.xquery.st");
43

  
44
	@Resource
45
	private UniqueServiceLocator serviceLocator;
46

  
47
	private String fixDsId(final String dsId) throws DatasourceManagerServiceException {
48
		if (dsId.endsWith("_UGVuZGluZ1JlcG9zaXRvcnlSZXNvdXJjZXMvUmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZVR5cGU=")
49
				|| dsId.endsWith("_UmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZXMvUmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZVR5cGU=")) {
50
			return dsId;
51
		} else {
52
			try {
53
				return serviceLocator
54
						.getService(ISLookUpService.class)
55
						.getResourceProfileByQuery(
56
								"for $x in collection("
57
										+ "'/db/DRIVER/RepositoryServiceResources/RepositoryServiceResourceType',"
58
										+ "'/db/DRIVER/PendingRepositoryResources/RepositoryServiceResourceType') "
59
										+ "where $x//DATASOURCE_ORIGINAL_ID = '" + dsId + "' "
60
										+ "return $x//RESOURCE_IDENTIFIER/@value/string()");
61
			} catch (Exception e) {
62
				throw new DatasourceManagerServiceException("Invalid id: " + dsId, e);
63
			}
64
		}
65
	}
66

  
67
	@Override
68
	public boolean addDatasource(final DatasourceDesc ds) throws DatasourceManagerServiceException {
69
		try {
70
			final String profile = DatasourceDescToProfile.convert(ds);
71
			serviceLocator.getService(ISRegistryService.class).registerProfile(profile);
72
			return true;
73
		} catch (Exception e) {
74
			log.error("Error registering profile", e);
75
			throw new DatasourceManagerServiceException("Error registering profile", e);
76
		}
77
	}
78

  
79
	@Override
80
	public boolean deleteDatasource(final String dsId) throws DatasourceManagerServiceException {
81
		return _deleteDatasource(fixDsId(dsId));
82
	}
83

  
84
	private boolean _deleteDatasource(final String dsId) throws DatasourceManagerServiceException {
85
		try {
86
			return serviceLocator.getService(ISRegistryService.class).deleteProfile(dsId);
87
		} catch (ISRegistryException e) {
88
			log.error("Error deleting profile " + dsId, e);
89
			throw new DatasourceManagerServiceException("Error deleting profile " + dsId, e);
90
		}
91
	}
92

  
93
	@Override
94
	public DatasourceDesc getDatasource(final String dsId) throws DatasourceManagerServiceException {
95
		return _getDatasource(fixDsId(dsId));
96
	}
97

  
98
	private DatasourceDesc _getDatasource(final String dsId) throws DatasourceManagerServiceException {
99
		try {
100
			final String profile = serviceLocator.getService(ISLookUpService.class).getResourceProfile(dsId);
101
			return ProfileToDatasourceDesc.convert(profile);
102
		} catch (Exception e) {
103
			log.error("Error accessing profile " + dsId, e);
104
			throw new DatasourceManagerServiceException("Error accessing profile " + dsId, e);
105
		}
106
	}
107

  
108
	@Override
109
	public List<DatasourceDesc> listAllDatasources() throws DatasourceManagerServiceException {
110
		return listDatasourcesUsingFilter(null, null, null, null);
111
	}
112

  
113
	@Override
114
	public List<DatasourceDesc> listDatasourcesUsingFilter(final String compliance,
115
			final String contentDescription,
116
			final String iisProcessingWorkflow,
117
			final String collectedFrom)
118
			throws DatasourceManagerServiceException {
119
		try {
120
			final StringTemplate st = new StringTemplate();
121
			st.setTemplate(IOUtils.toString(findReposQueryTmpl.getInputStream()));
122

  
123
			final Map<String, String> conds = new HashMap<>();
124

  
125
			if (StringUtils.isNotBlank(compliance)) {
126
				conds.put("//INTERFACE/@compliance", compliance);
127
			}
128
			if (StringUtils.isNotBlank(contentDescription)) {
129
				conds.put("//INTERFACE/@contentDescription", contentDescription);
130
			}
131
			if (StringUtils.isNotBlank(iisProcessingWorkflow)) {
132
				// NOT USED
133
			}
134
			if (StringUtils.isNotBlank(collectedFrom)) {
135
				// NOT USED
136
			}
137

  
138
			if (!conds.isEmpty()) {
139
				st.setAttribute("conds", conds);
140
			}
141

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

  
144
			return list.stream().map(new ProfileToDatasourceDesc()).collect(Collectors.toList());
145
		} catch (Exception e) {
146
			log.error("Error listing datasources", e);
147
			throw new DatasourceManagerServiceException("Error listing datasources", e);
148
		}
149
	}
150

  
151
	@Override
152
	public boolean updateLevelOfCompliance(final String dsId, final String ifaceId, final String level) throws DatasourceManagerServiceException {
153
		return _updateLevelOfCompliance(fixDsId(dsId), ifaceId, level);
154
	}
155

  
156
	private boolean _updateLevelOfCompliance(final String dsId, final String ifaceId, final String level) throws DatasourceManagerServiceException {
157
		try {
158
			return serviceLocator.getService(ISRegistryService.class)
159
					.updateProfileNode(dsId, "//INTERFACE[@id = '" + ifaceId + "']/@compliance", "'" + level + "'");
160
		} catch (Exception e) {
161
			log.error("Error updating profile: " + dsId, e);
162
			throw new DatasourceManagerServiceException("Error updating profile: " + dsId, e);
163
		}
164
	}
165

  
166
	@Override
167
	public boolean updateBaseUrl(final String dsId, final String ifaceId, final String baseUrl) throws DatasourceManagerServiceException {
168
		return _updateBaseUrl(fixDsId(dsId), ifaceId, baseUrl);
169
	}
170

  
171
	private boolean _updateBaseUrl(final String dsId, final String ifaceId, final String baseUrl) throws DatasourceManagerServiceException {
172
		try {
173
			return serviceLocator.getService(ISRegistryService.class)
174
					.updateProfileNode(dsId, "//INTERFACE[@id = '" + ifaceId + "']/BASE_URL", "<BASE_URL>" + baseUrl + "</BASE_URL>");
175
		} catch (Exception e) {
176
			log.error("Error updating profile: " + dsId, e);
177
			throw new DatasourceManagerServiceException("Error updating profile: " + dsId, e);
178
		}
179
	}
180

  
181
	@Override
182
	public boolean updateActivationStatus(final String dsId, final String ifaceId, final boolean active) throws DatasourceManagerServiceException {
183
		return _updateActivationStatus(fixDsId(dsId), ifaceId, active);
184
	}
185

  
186
	private boolean _updateActivationStatus(final String dsId, final String ifaceId, final boolean active) throws DatasourceManagerServiceException {
187
		try {
188
			return serviceLocator.getService(ISRegistryService.class)
189
					.updateProfileNode(dsId, "//INTERFACE[@id = '" + ifaceId + "']/@active", "'" + active + "'");
190
		} catch (Exception e) {
191
			log.error("Error updating profile: " + dsId, e);
192
			throw new DatasourceManagerServiceException("Error updating profile: " + dsId, e);
193
		}
194
	}
195

  
196
	@Override
197
	public boolean updateContentDescription(final String dsId, final String ifaceId, final String desc) throws DatasourceManagerServiceException {
198
		return _updateContentDescription(fixDsId(dsId), ifaceId, desc);
199
	}
200

  
201
	private boolean _updateContentDescription(final String dsId, final String ifaceId, final String desc) throws DatasourceManagerServiceException {
202
		try {
203
			return serviceLocator.getService(ISRegistryService.class)
204
					.updateProfileNode(dsId, "//INTERFACE[@id = '" + ifaceId + "']/@contentDescription", "'" + desc + "'");
205
		} catch (Exception e) {
206
			log.error("Error updating profile: " + dsId, e);
207
			throw new DatasourceManagerServiceException("Error updating profile: " + dsId, e);
208
		}
209
	}
210

  
211
	@Override
212
	public boolean setIisProcessingWorkflow(final String dsId, final String ifaceId, final String wf) throws DatasourceManagerServiceException {
213
		throw new DatasourceManagerServiceException("NOT IMPLEMENTED");
214
	}
215

  
216
	@Override
217
	public boolean updateExtraField(final String dsId, final String ifaceId, final String field, final String value, final boolean preserveOriginal)
218
			throws DatasourceManagerServiceException {
219
		return _updateExtraField(fixDsId(dsId), ifaceId, field, value, preserveOriginal);
220
	}
221

  
222
	private boolean _updateExtraField(final String dsId, final String ifaceId, final String field, final String value, final boolean preserveOriginal)
223
			throws DatasourceManagerServiceException {
224
		try {
225
			final String profile = serviceLocator.getService(ISLookUpService.class).getResourceProfile(dsId);
226
			final Document doc = new SAXReader().read(new StringReader(profile));
227

  
228
			final Node ifcNode = doc.selectSingleNode("//INTERFACE[@id = '" + ifaceId + "']");
229
			final Node node = ifcNode.selectSingleNode("./INTERFACE_EXTRA_FIELD[@name = '" + field + "']");
230
			if (node != null) {
231
				node.setText(value);
232
			} else {
233
				final Element e = ((Element) ifcNode).addElement("INTERFACE_EXTRA_FIELD");
234
				e.addAttribute("name", field);
235
				e.setText(value);
236
			}
237
			return serviceLocator.getService(ISRegistryService.class).updateProfile(dsId, doc.asXML(), REPOSITORY_RESOURCE_TYPE);
238
		} catch (Exception e) {
239
			log.error("Error updating profile: " + dsId, e);
240
			throw new DatasourceManagerServiceException("Error updating profile: " + dsId, e);
241
		}
242
	}
243

  
244
	@Override
245
	public boolean updateAccessParam(final String dsId, final String ifaceId, final String field, final String value, final boolean preserveOriginal)
246
			throws DatasourceManagerServiceException {
247
		return _updateAccessParam(fixDsId(dsId), ifaceId, field, value, preserveOriginal);
248
	}
249

  
250
	private boolean _updateAccessParam(final String dsId, final String ifaceId, final String field, final String value, final boolean preserveOriginal)
251
			throws DatasourceManagerServiceException {
252
		try {
253
			final String profile = serviceLocator.getService(ISLookUpService.class).getResourceProfile(dsId);
254
			final Document doc = new SAXReader().read(new StringReader(profile));
255

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

  
259
			return serviceLocator.getService(ISRegistryService.class).updateProfile(dsId, doc.asXML(), REPOSITORY_RESOURCE_TYPE);
260
		} catch (Exception e) {
261
			log.error("Error updating profile: " + dsId, e);
262
			throw new DatasourceManagerServiceException("Error updating profile: " + dsId, e);
263
		}
264
	}
265

  
266
	@Override
267
	public boolean deleteAccessParamOrExtraField(final String dsId, final String ifaceId, final String field) throws DatasourceManagerServiceException {
268
		return _deleteAccessParamOrExtraField(fixDsId(dsId), ifaceId, field);
269
	}
270

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

  
276
			final Node ef = doc.selectSingleNode("//INTERFACE[@id = '" + ifaceId + "']/INTERFACE_EXTRA_FIELD[@name = '" + field + "']");
277
			if (ef != null) {
278
				ef.detach();
279
			}
280
			final Node ap = doc.selectSingleNode("//INTERFACE[@id = '" + ifaceId + "']/ACCESS_PROTOCOL/@" + field);
281
			if (ap != null) {
282
				ap.detach();
283

  
284
			}
285
			return serviceLocator.getService(ISRegistryService.class).updateProfile(dsId, doc.asXML(), REPOSITORY_RESOURCE_TYPE);
286
		} catch (Exception e) {
287
			log.error("Error updating profile: " + dsId, e);
288
			throw new DatasourceManagerServiceException("Error updating profile: " + dsId, e);
289
		}
290
	}
291

  
292
	@Override
293
	public boolean addInterface(final String dsId, final IfaceDesc iface) throws DatasourceManagerServiceException {
294
		return _addInterface(fixDsId(dsId), iface);
295
	}
296

  
297
	private boolean _addInterface(final String dsId, final IfaceDesc iface) throws DatasourceManagerServiceException {
298
		try {
299
			final String profile = serviceLocator.getService(ISLookUpService.class).getResourceProfile(dsId);
300
			final Document doc = new SAXReader().read(new StringReader(profile));
301

  
302
			final Node node = doc.selectSingleNode("//INTERFACE[@id = '" + iface.getId() + "']");
303
			if (node != null) {
304
				node.detach();
305
			}
306

  
307
			((Element) doc.selectSingleNode("//INTERFACES")).add(IfaceDescToNode.convert(iface));
308

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

  
316
	@Override
317
	public boolean deleteInterface(final String dsId, final String ifaceId) throws DatasourceManagerServiceException {
318
		return _deleteInterface(fixDsId(dsId), ifaceId);
319
	}
320

  
321
	private boolean _deleteInterface(final String dsId, final String ifaceId) throws DatasourceManagerServiceException {
322
		try {
323
			final String profile = serviceLocator.getService(ISLookUpService.class).getResourceProfile(dsId);
324
			final Document doc = new SAXReader().read(new StringReader(profile));
325

  
326
			final Node node = doc.selectSingleNode("//INTERFACE[@id = '" + ifaceId + "']");
327
			if (node != null) {
328
				node.detach();
329
			}
330

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

  
338
	@Override
339
	public boolean updateSQL(final String dsId, final String sql, final boolean delete) throws DatasourceManagerServiceException {
340
		throw new DatasourceManagerServiceException("NOT IMPLEMENTED");
341
	}
342

  
343
	@Override
344
	public Date findNextScheduledExecution(final String dsId, final String ifaceId) throws DatasourceManagerServiceException {
345
		return _findNextScheduledExecution(fixDsId(dsId), ifaceId);
346
	}
347

  
348
	private Date _findNextScheduledExecution(final String dsId, final String ifaceId) throws DatasourceManagerServiceException {
349
		final String xquery = "/*[.//DATAPROVIDER/@interface='" + ifaceId + "' and .//SCHEDULING/@enabled='true']//CRON/text()";
350
		try {
351
			final String cronExpression = serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(xquery);
352
			final CronExpression cron = new CronExpression(cronExpression);
353
			return cron.getNextValidTimeAfter(new Date());
354
		} catch (ISLookUpDocumentNotFoundException e) {
355
			// When the value is not found a null value must be returned
356
			return null;
357
		} catch (ISLookUpException e) {
358
			log.error("Error in xquery: " + xquery, e);
359
			throw new DatasourceManagerServiceException("Error in xquery: " + xquery, e);
360
		} catch (ParseException e) {
361
			log.error("Error parsing cron expression", e);
362
			throw new DatasourceManagerServiceException("Error parsing cron expression", e);
363
		}
364
	}
365

  
366
	@Override
367
	public boolean bulkUpdateApiExtraFields(final String repoId, final String ifaceId, final Map<String, String> fields)
368
			throws DatasourceManagerServiceException {
369
		try {
370
			final String profile = serviceLocator.getService(ISLookUpService.class).getResourceProfile(repoId);
371

  
372
			final SAXReader reader = new SAXReader();
373
			final Document doc = reader.read(new StringReader(profile));
374

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

  
378
				while (iface.selectNodes("./INTERFACE_EXTRA_FIELD").size() > 0) {
379
					iface.selectSingleNode("./INTERFACE_EXTRA_FIELD").detach();
380
				}
381

  
382
				fields.entrySet().forEach(e -> {
383
					if (e.getValue() != null && !e.getValue().isEmpty()) {
384
						final Element field = iface.addElement("INTERFACE_EXTRA_FIELD");
385
						field.addAttribute("name", e.getKey());
386
						field.addText(e.getValue());
387
					}
388
				});
389
				serviceLocator.getService(ISRegistryService.class).updateProfile(repoId, doc.asXML(), REPOSITORY_RESOURCE_TYPE);
390
			} else {
391
				log.error("Invalid interface: " + ifaceId);
392
				throw new DatasourceManagerServiceException("Missing interface: " + ifaceId);
393
			}
394
		} catch (Exception e) {
395
			log.error("Error updating API of profile: " + repoId);
396
			throw new DatasourceManagerServiceException("Error updating API of profile: " + repoId, e);
397
		}
398
		return true;
399

  
400
	}
401

  
402
	@Override
403
	public boolean bulkUpdateApiAccessParams(final String dsId, final String ifaceId, final Map<String, String> params)
404
			throws DatasourceManagerServiceException {
405
		return _bulkUpdateApiAccessParams(fixDsId(dsId), ifaceId, params);
406
	}
407

  
408
	private boolean _bulkUpdateApiAccessParams(final String repoId, final String ifaceId, final Map<String, String> params)
409
			throws DatasourceManagerServiceException {
410
		try {
411
			final String profile = serviceLocator.getService(ISLookUpService.class).getResourceProfile(repoId);
412

  
413
			final SAXReader reader = new SAXReader();
414
			final Document doc = reader.read(new StringReader(profile));
415

  
416
			final Element accessNode = (Element) doc.selectSingleNode("//INTERFACE[@id='" + ifaceId + "']/ACCESS_PROTOCOL");
417
			if (accessNode != null) {
418
				while (accessNode.attributes().size() > 0) {
419
					accessNode.selectSingleNode("@*").detach();
420
				}
421
				for (Map.Entry<String, String> e : params.entrySet()) {
422
					if (e.getValue() != null && !e.getValue().isEmpty()) {
423
						if (e.getKey().equalsIgnoreCase("baseUrl")) {
424
							doc.selectSingleNode("//INTERFACE[@id='" + ifaceId + "']/BASE_URL").setText(e.getValue());
425
						} else {
426
							accessNode.addAttribute(e.getKey(), e.getValue());
427
						}
428
					}
429
				}
430
				serviceLocator.getService(ISRegistryService.class).updateProfile(repoId, doc.asXML(), REPOSITORY_RESOURCE_TYPE);
431
			} else {
432
				log.error("Invalid interface: " + ifaceId);
433
				throw new DatasourceManagerServiceException("Missing interface: " + ifaceId);
434
			}
435
		} catch (Exception e) {
436
			log.error("Error updating API of profile: " + repoId);
437
			throw new DatasourceManagerServiceException("Error updating API of profile: " + repoId, e);
438
		}
439
		return true;
440
	}
441

  
442
	@Override
443
	public boolean overrideCompliance(final String dsId, final String ifaceId, final String level) throws DatasourceManagerServiceException {
444
		return _overrideCompliance(fixDsId(dsId), ifaceId, level);
445
	}
446

  
447
	private boolean _overrideCompliance(final String repoId, final String ifaceId, final String compliance) throws DatasourceManagerServiceException {
448
		try {
449
			final String profile = serviceLocator.getService(ISLookUpService.class).getResourceProfile(repoId);
450

  
451
			final SAXReader reader = new SAXReader();
452
			final Document doc = reader.read(new StringReader(profile));
453

  
454
			final Element iface = (Element) doc.selectSingleNode("//INTERFACE[@id='" + ifaceId + "']");
455
			if (iface != null) {
456
				final Map<String, String> fields = new HashMap<>();
457

  
458
				if (!StringUtils.isEmpty(compliance)) {
459
					fields.put(DatasourceConstants.OVERRIDING_COMPLIANCE_FIELD, compliance);
460
				}
461

  
462
				while (iface.selectNodes("./INTERFACE_EXTRA_FIELD").size() > 0) {
463
					final Node node = iface.selectSingleNode("./INTERFACE_EXTRA_FIELD");
464
					final String name = node.valueOf("@name");
465

  
466
					if (!name.equals(DatasourceConstants.OVERRIDING_COMPLIANCE_FIELD)) {
467
						fields.put(node.valueOf("@name"), node.getText());
468
					}
469
					node.detach();
470
				}
471

  
472
				for (Map.Entry<String, String> e : fields.entrySet()) {
473
					if (e.getValue() != null && !e.getValue().isEmpty()) {
474
						final Element field = iface.addElement("INTERFACE_EXTRA_FIELD");
475
						field.addAttribute("name", e.getKey());
476
						field.addText(e.getValue());
477
					}
478
				}
479
				serviceLocator.getService(ISRegistryService.class).updateProfile(repoId, doc.asXML(), REPOSITORY_RESOURCE_TYPE);
480
			} else {
481
				log.error("Invalid interface: " + ifaceId);
482
				throw new DatasourceManagerServiceException("Missing interface: " + ifaceId);
483
			}
484
		} catch (Exception e) {
485
			log.error("Error updating API of profile: " + repoId);
486
			throw new DatasourceManagerServiceException("Error updating API of profile: " + repoId, e);
487
		}
488

  
489
		return true;
490
	}
491

  
492
	@Override
493
	public List<BrowsableField> listBrowsableFields() throws DatasourceManagerServiceException {
494
		return getBrowsableFields().stream().map(f -> new BrowsableField(f.getId(), f.getLabel())).collect(Collectors.toList());
495
	}
496

  
497
	@Override
498
	public List<BrowseTerm> browseField(final String f) throws DatasourceManagerServiceException {
499

  
500
		final List<BrowseTerm> list = new ArrayList<>();
501

  
502
		try {
503
			final XmlBrowsableField field = findBrowseField(f);
504
			if (field != null) {
505
				final StringTemplate st = new StringTemplate(IOUtils.toString(browseRepoApisQueryTmpl.getInputStream()));
506
				st.setAttribute("xpath", field.getXpath());
507

  
508
				final Map<String, String> terms = fetchVocabularyTerms(field.getVocabulary());
509

  
510
				for (String s : serviceLocator.getService(ISLookUpService.class).quickSearchProfile(st.toString())) {
511
					final String[] arr = s.split("@-@-@");
512
					final String id = arr[0].trim();
513
					final int count = NumberUtils.toInt(arr[1].trim(), 0);
514
					list.add(new BrowseTerm(id, findLabel(id, terms), count));
515
				}
516
			}
517
		} catch (Exception e) {
518
			log.error("Error browsing field " + f, e);
519
		}
520

  
521
		return list;
522
	}
523

  
524
	private String findLabel(final String code, final Map<String, String> terms) {
525
		return terms.containsKey(code) ? terms.get(code) : code;
526
	}
527

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

  
532
		final Map<String, String> map = new HashMap<>();
533
		for (String s : serviceLocator.getService(ISLookUpService.class).quickSearchProfile(xquery)) {
534
			final String[] arr = s.split("@@@");
535
			map.put(arr[0].trim(), arr[1].trim());
536
		}
537
		return map;
538
	}
539

  
540
	private XmlBrowsableField findBrowseField(final String id) {
541
		for (XmlBrowsableField f : getBrowsableFields()) {
542
			if (f.getId().equals(id)) { return f; }
543
		}
544
		return null;
545
	}
546

  
547
	@Override
548
	public List<SearchInterfacesEntry> searchInterface(final String field, final String value) throws DatasourceManagerServiceException {
549
		try {
550

  
551
			final StringTemplate st = new StringTemplate();
552
			st.setTemplate(IOUtils.toString(findRepoApisQueryTmpl.getInputStream()));
553

  
554
			if (field.equalsIgnoreCase("__search__")) {
555
				st.setAttribute("cond", "contains(../..//(*|@*)/lower-case(.), '" + StringEscapeUtils.escapeXml(value.toLowerCase()) + "')");
556
			} else {
557
				final XmlBrowsableField f = findBrowseField(field);
558
				if (f != null) {
559
					st.setAttribute("cond", f.getXpath() + "='" + StringEscapeUtils.escapeXml(value) + "'");
560
				} else {
561
					return new ArrayList<>();
562
				}
563
			}
564

  
565
			final String query = st.toString();
566

  
567
			final SAXReader reader = new SAXReader();
568

  
569
			return serviceLocator.getService(ISLookUpService.class).quickSearchProfile(query).stream()
570
					.map(it -> convertSearchInterface(it, reader)).collect(Collectors.toList());
571

  
572
		} catch (Exception e) {
573
			log.error("Error searching field " + field + " - value: " + value, e);
574
		}
575
		return new ArrayList<>();
576
	}
577

  
578
	private SearchInterfacesEntry convertSearchInterface(final String s, final SAXReader reader) {
579
		final SearchInterfacesEntry iface = new SearchInterfacesEntry();
580
		try {
581
			final Document doc = reader.read(new StringReader(s));
582
			final String country = doc.valueOf("//REPO/@country");
583

  
584
			iface.setRepoId(doc.valueOf("//REPO/@id"));
585
			iface.setRepoCountry(StringUtils.isEmpty(country) ? "-" : country.toUpperCase());
586
			iface.setRepoName(doc.valueOf("//REPO/@name"));
587
			iface.setRepoPrefix(doc.valueOf("//REPO/@prefix"));
588

  
589
			final Node ifcNode = doc.selectSingleNode("//INTERFACE");
590

  
591
			iface.setId(ifcNode.valueOf("./@id"));
592
			iface.setActive(Boolean.valueOf(ifcNode.valueOf("./@active")));
593
			iface.setProtocol(ifcNode.valueOf("./ACCESS_PROTOCOL/text()"));
594

  
595
			final String overCompliance = ifcNode.valueOf("./INTERFACE_EXTRA_FIELD[@name='overriding_compliance']");
596
			if (StringUtils.isEmpty(overCompliance)) {
597
				iface.setCompliance(ifcNode.valueOf("@compliance"));
598
			} else {
599
				iface.setCompliance(overCompliance);
600
			}
601

  
602
			final String lastAggregationDate = ifcNode.valueOf("./INTERFACE_EXTRA_FIELD[@name='last_aggregation_date']");
603
			if (!StringUtils.isEmpty(lastAggregationDate)) {
604
				iface.setAggrDate(lastAggregationDate);
605
			} else {
606
				final String lastDownloadDate = ifcNode.valueOf("./INTERFACE_EXTRA_FIELD[@name='last_download_date']");
607
				if (!StringUtils.isEmpty(lastDownloadDate)) {
608
					iface.setAggrDate(lastDownloadDate);
609
				}
610
			}
611
			final String lastAggregationTotal = ifcNode.valueOf("./INTERFACE_EXTRA_FIELD[@name='last_aggregation_total']");
612
			if (StringUtils.isEmpty(lastAggregationTotal)) {
613
				final String lastDownloadTotal = ifcNode.valueOf("./INTERFACE_EXTRA_FIELD[@name='last_download_total']");
614
				if (StringUtils.isEmpty(lastDownloadTotal)) {
615
					iface.setAggrTotal(0);
616
				} else {
617
					iface.setAggrTotal(NumberUtils.toInt(lastDownloadTotal, 0));
618
				}
619
			} else {
620
				iface.setAggrTotal(NumberUtils.toInt(lastAggregationTotal, 0));
621
			}
622
		} catch (Exception e) {
623
			log.error(e);
624
		}
625
		return iface;
626
	}
627

  
628
	private RepositoryMapEntry convertRepositoryMapEntry(final String s, final SAXReader reader) {
629

  
630
		final RepositoryMapEntry r = new RepositoryMapEntry();
631

  
632
		try {
633
			final Document doc = reader.read(new StringReader(s));
634
			r.setId(doc.valueOf("//dsId"));
635
			r.setName(doc.valueOf("//name"));
636
			r.setLat(Float.parseFloat(doc.valueOf("//lat")));
637
			r.setLng(Float.parseFloat(doc.valueOf("//lng")));
638
		} catch (Exception e) {
639
			log.error(e);
640

  
641
		}
642
		return r;
643

  
644
	}
645

  
646
	@Override
647
	public List<RepositoryMapEntry> getRepositoryMap() throws DatasourceManagerServiceException {
648
		try {
649
			final SAXReader reader = new SAXReader();
650

  
651
			final String query = IOUtils.toString(findReposMapQuery.getInputStream());
652
			return serviceLocator.getService(ISLookUpService.class).quickSearchProfile(query)
653
					.stream()
654
					.map(it -> convertRepositoryMapEntry(it, reader))
655
					.collect(Collectors.toList());
656

  
657
		} catch (Exception e) {
658
			log.error("Error obtaing repo map entries", e);
659
		}
660
		return new ArrayList<>();
661
	}
662

  
663
	private List<XmlBrowsableField> getBrowsableFields() {
664
		return browsableFields;
665
	}
666

  
667
	@Required
668
	public void setBrowsableFields(final List<XmlBrowsableField> browsableFields) {
669
		this.browsableFields = browsableFields;
670
	}
671

  
672
	@Override
673
	public List<SimpleDatasourceDesc> simpleListDatasourcesByType(final String type) throws DatasourceManagerServiceException {
674
		try {
675
			final List<SimpleDatasourceDesc> list = new ArrayList<>();
676

  
677
			final StringTemplate st = new StringTemplate(IOUtils.toString(simpleFindReposQueryTmpl.getInputStream()));
678
			st.setAttribute("type", type);
679

  
680
			for (String s : serviceLocator.getService(ISLookUpService.class).quickSearchProfile(st.toString())) {
681
				final SimpleDatasourceDesc r = new SimpleDatasourceDesc();
682
				final String[] arr = s.split("@=@");
683
				r.setId(arr[0].trim());
684
				r.setName(arr[1].trim());
685
				r.setOrigId(arr[2].trim());
686
				r.setApis(Sets.newHashSet(arr[3].replaceAll("\\s", "").split(",")));
687
				r.setValid("true".equals(arr[4].trim()));
688
				r.setTypology(type);
689
				list.add(r);
690
			}
691

  
692
			Collections.sort(list);
693

  
694
			return list;
695
		} catch (Exception e) {
696
			log.error("Error listing repos", e);
697
		}
698
		return new ArrayList<>();
699
	}
700

  
701
}
modules/dnet-core-services/trunk/src/main/java/eu/dnetlib/enabling/datasources/DatasourceDescToProfile.java
1
package eu.dnetlib.enabling.datasources;
2

  
3
import java.util.function.Function;
4

  
5
import eu.dnetlib.miscutils.datetime.DateUtils;
6
import eu.dnetlib.rmi.datasource.DatasourceDesc;
7
import eu.dnetlib.rmi.datasource.IfaceDesc;
8
import org.apache.commons.logging.Log;
9
import org.apache.commons.logging.LogFactory;
10
import org.dom4j.DocumentHelper;
11
import org.dom4j.Element;
12

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  
81
		return root.asXML();
82
	}
83

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

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

  
3
import java.io.StringReader;
4
import java.util.function.Function;
5

  
6
import eu.dnetlib.miscutils.datetime.DateUtils;
7
import eu.dnetlib.rmi.datasource.DatasourceDesc;
8
import eu.dnetlib.rmi.datasource.IfaceDesc;
9
import org.apache.commons.lang3.BooleanUtils;
10
import org.apache.commons.lang3.math.NumberUtils;
11
import org.apache.commons.logging.Log;
12
import org.apache.commons.logging.LogFactory;
13
import org.dom4j.Document;
14
import org.dom4j.Element;
15
import org.dom4j.Node;
16
import org.dom4j.io.SAXReader;
17

  
18
public class ProfileToDatasourceDesc implements Function<String, DatasourceDesc> {
19

  
20
	private static final Log log = LogFactory.getLog(ProfileToDatasourceDesc.class);
21

  
22
	public static DatasourceDesc convert(final String profile) throws Exception {
23
		final SAXReader reader = new SAXReader();
24
		final Document doc = reader.read(new StringReader(profile));
25

  
26
		final DatasourceDesc ds = new DatasourceDesc();
27
		ds.setId(doc.valueOf("//RESOURCE_IDENTIFIER/@value"));
28
		ds.setDatasourceClass(doc.valueOf("//DATASOURCE_TYPE"));
29
		ds.setTypology(doc.valueOf("//TYPOLOGY"));
30
		ds.setOfficialName(doc.valueOf("//OFFICIAL_NAME"));
31
		ds.setEnglishName(doc.valueOf("//ENGLISH_NAME"));
32
		ds.setCountryCode(doc.valueOf("//COUNTRY"));
33
		ds.setLongitude(NumberUtils.toDouble(doc.valueOf("//LOCATION/LONGITUDE"), 0.0));
34
		ds.setLatitude(NumberUtils.toDouble(doc.valueOf("//LOCATION/LATITUDE"), 0.0));
35
		ds.setTimezone(NumberUtils.toDouble(doc.valueOf("//LOCATION/TIMEZONE"), 0.0));
36
		ds.setWebsiteUrl(doc.valueOf("//REPOSITORY_WEBPAGE"));
37
		ds.setOrganization(doc.valueOf("//REPOSITORY_INSTITUTION"));
38
		ds.setContactEmail(doc.valueOf("//ADMIN_INFO"));
39

  
40
		for (Object o : doc.selectNodes("//INTERFACES/INTERFACE")) {
41
			final Element n = (Element) o;
42

  
43
			final IfaceDesc ifc = new IfaceDesc();
44

  
45
			ifc.setId(n.valueOf("@id"));
46
			ifc.setCompliance(n.valueOf("@compliance"));
47
			ifc.setTypology(n.valueOf("@typology"));
48
			ifc.setContentDescription(n.valueOf("@contentDescription"));
49
			ifc.setActive(BooleanUtils.toBoolean(n.valueOf("@active")));
50
			ifc.setRemovable(BooleanUtils.toBoolean(n.valueOf("@removable")));
51
			ifc.setBaseUrl(n.valueOf("./BASE_URL"));
52
			ifc.setAccessProtocol(n.valueOf("./ACCESS_PROTOCOL"));
53

  
54
			for (Object o1 : n.selectNodes("./ACCESS_PROTOCOL/@*")) {
55
				final Node attr = (Node) o1;
56
				ifc.getAccessParams().put(attr.getName(), attr.getText());
57
			}
58
			for (Object o1 : n.selectNodes("./INTERFACE_EXTRA_FIELD")) {
59
				final Node f = (Node) o1;
60
				ifc.getExtraFields().put(f.valueOf("@name"), f.getText());
61
			}
62

  
63
			ds.getInterfaces().add(ifc);
64
		}
65

  
66
		final DateUtils dateUtils = new DateUtils();
67
		for (Object o : doc.selectNodes("//EXTRA_FIELDS/EXTRA_FIELD")) {
68
			final String k = ((Element) o).valueOf("./key").trim();
69
			final String v = ((Element) o).valueOf("./value").trim();
70

  
71
			if (k.equalsIgnoreCase("ACTIVATION_ID")) {
72
				ds.setActivationId(v);
73
			} else if (k.equalsIgnoreCase("NamespacePrefix")) {
74
				ds.setNamespacePrefix(v);
75
			} else if (k.equalsIgnoreCase("aggregatorName")) {
76
				ds.setAggregator(v);
77
			} else if (k.equalsIgnoreCase("dateOfCollection")) {
78
				ds.setDateOfCollection(dateUtils.parse(v));
79
			} else if (k.equalsIgnoreCase("dateOfValidation")) {
80
				ds.setDateOfValidation(dateUtils.parse(v));
81
			}
82
		}
83

  
84
		return ds;
85
	}
86

  
87
	@Override
88
	public DatasourceDesc apply(final String profile) {
89
		try {
90
			return ProfileToDatasourceDesc.convert(profile);
91
		} catch (Exception e) {
92
			log.error("Error convering profile", e);
93
			return null;
94
		}
95
	}
96
}
modules/dnet-core-services/trunk/src/main/resources/eu/dnetlib/enabling/datasources/applicationContext-datasource-manager-service.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
       xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:p="http://www.springframework.org/schema/p"
4
       xmlns:http="http://cxf.apache.org/transports/http/configuration" xmlns="http://www.springframework.org/schema/beans"
5
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
6
                                    http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd
7
                            http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
8

  
9
	<bean id="datasourceManagerService"
10
	      class="eu.dnetlib.enabling.datasources.DatasourceManagerServiceImpl">
11
		<property name="browsableFields">
12
			<list>
13
				<bean class="eu.dnetlib.enabling.datasources.XmlBrowsableField"
14
				      p:id="country" p:label="Datasource countries" p:xpath="../../COUNTRY/text()"
15
				      p:vocabulary="dnet:countries"/>
16
				<bean class="eu.dnetlib.enabling.datasources.XmlBrowsableField"
17
				      p:id="type" p:label="API typologies" p:xpath="@typology/string()"
18
				      p:vocabulary="dnet:datasource_typologies"/>
19
				<bean class="eu.dnetlib.enabling.datasources.XmlBrowsableField"
20
				      p:id="protocol" p:label="API protocols" p:xpath="ACCESS_PROTOCOL/text()"
21
				      p:vocabulary="dnet:protocols"/>
22
				<bean class="eu.dnetlib.enabling.datasources.XmlBrowsableField"
23
				      p:id="compliance" p:label="API compatibility levels"
24
				      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)))"
25
				      p:vocabulary="dnet:compatibilityLevel"/>
26
			</list>
27
		</property>
28
	</bean>
29

  
30
	<!-- endpoints -->
31
	<jaxws:endpoint id="datasourceManagerServiceEndpoint"
32
	                implementor="#datasourceManagerService"
33
	                implementorClass="eu.dnetlib.enabling.datasources.rmi.DatasourceManagerService"
34
	                address="/datasourceManager"/>
35

  
36

  
37
</beans>
modules/dnet-core-services/trunk/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-core-services/trunk/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-core-services/trunk/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-core-services/trunk/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-core-services/trunk/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

Also available in: Unified diff