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.lang3.StringUtils;
|
9
|
import org.apache.commons.logging.Log;
|
10
|
import org.apache.commons.logging.LogFactory;
|
11
|
import org.dom4j.DocumentHelper;
|
12
|
import org.dom4j.Element;
|
13
|
|
14
|
public class DatasourceDescToProfile implements Function<DatasourceDesc, String> {
|
15
|
|
16
|
private static final Log log = LogFactory.getLog(DatasourceDescToProfile.class);
|
17
|
|
18
|
public static String convert(final DatasourceDesc ds) throws Exception {
|
19
|
final Element root = DocumentHelper.createElement("RESOURCE_PROFILE");
|
20
|
|
21
|
final Element header = root.addElement("HEADER");
|
22
|
header.addElement("RESOURCE_IDENTIFIER").addAttribute("value", "");
|
23
|
header.addElement("RESOURCE_TYPE").addAttribute("value", "RepositoryServiceResourceType");
|
24
|
header.addElement("RESOURCE_KIND").addAttribute("value", "RepositoryServiceResources");
|
25
|
header.addElement("RESOURCE_URI").addAttribute("value", "");
|
26
|
header.addElement("DATE_OF_CREATION").addAttribute("value", DateUtils.now_ISO8601());
|
27
|
header.addElement("PROTOCOL");
|
28
|
|
29
|
final Element body = root.addElement("BODY");
|
30
|
final Element conf = body.addElement("CONFIGURATION");
|
31
|
conf.addElement("DATASOURCE_TYPE").setText(ds.getDatasourceClass());
|
32
|
|
33
|
final Element origId = conf.addElement("DATASOURCE_ORIGINAL_ID");
|
34
|
origId.addAttribute("provenance", "D-NET");
|
35
|
origId.setText(ds.getId());
|
36
|
|
37
|
conf.addElement("DATASOURCE_AGGREGATED").setText("false");
|
38
|
conf.addElement("ENVIRONMENTS");
|
39
|
conf.addElement("TYPOLOGY").setText(ds.getTypology());
|
40
|
conf.addElement("MAX_SIZE_OF_DATASTRUCTURE").setText("0");
|
41
|
conf.addElement("AVAILABLE_DISKSPACE").setText("0");
|
42
|
conf.addElement("MAX_NUMBER_OF_DATASTRUCTURE").setText("0");
|
43
|
|
44
|
conf.addElement("OFFICIAL_NAME").setText(ds.getOfficialName());
|
45
|
conf.addElement("ENGLISH_NAME").setText(ds.getEnglishName());
|
46
|
conf.addElement("ICON_URI").setText(ds.getLogoUrl());
|
47
|
conf.addElement("COUNTRY").setText(ds.getCountryCode());
|
48
|
|
49
|
final Element location = conf.addElement("LOCATION");
|
50
|
location.addElement("LONGITUDE").setText("" + ds.getLongitude());
|
51
|
location.addElement("LATITUDE").setText("" + ds.getLatitude());
|
52
|
location.addElement("TIMEZONE").setText("" + ds.getTimezone());
|
53
|
|
54
|
conf.addElement("REPOSITORY_WEBPAGE").setText(ds.getWebsiteUrl());
|
55
|
conf.addElement("REPOSITORY_INSTITUTION").setText(ds.getOrganization());
|
56
|
conf.addElement("ADMIN_INFO").setText(ds.getContactEmail());
|
57
|
|
58
|
final Element ifaces = conf.addElement("INTERFACES");
|
59
|
for (IfaceDesc ifc : ds.getInterfaces()) {
|
60
|
ifaces.add(IfaceDescToNode.convert(ifc));
|
61
|
}
|
62
|
final Element extraFields = conf.addElement("EXTRA_FIELDS");
|
63
|
addExtraField(extraFields, "ACTIVATION_ID", ds.getActivationId());
|
64
|
addExtraField(extraFields, "NamespacePrefix", ds.getNamespacePrefix());
|
65
|
addExtraField(extraFields, "aggregatorName", ds.getAggregator());
|
66
|
addExtraField(extraFields, "dateOfCollection", "" + ds.getDateOfCollection());
|
67
|
addExtraField(extraFields, "dateOfValidation", "" + ds.getDateOfValidation());
|
68
|
conf.addElement("REGISTERED_BY");
|
69
|
|
70
|
final Element status = body.addElement("STATUS");
|
71
|
status.addElement("NUMBER_OF_OBJECTS").setText("0");
|
72
|
status.addElement("LAST_UPDATE").addAttribute("value", "");
|
73
|
|
74
|
final Element qos = body.addElement("QOS");
|
75
|
qos.addElement("AVAILABILITY").setText("0");
|
76
|
qos.addElement("CAPACITY");
|
77
|
qos.addElement("THROUGHPUT").setText("0");
|
78
|
|
79
|
body.addElement("SECURITY_PARAMETERS");
|
80
|
body.addElement("BLACKBOARD");
|
81
|
|
82
|
return root.asXML();
|
83
|
}
|
84
|
|
85
|
private static void addExtraField(final Element extraFields, final String field, final String value) {
|
86
|
if (StringUtils.isEmpty(value))
|
87
|
return;
|
88
|
final Element f = extraFields.addElement("FIELD");
|
89
|
f.addElement("key").setText(field);
|
90
|
f.addElement("value").setText(value);
|
91
|
}
|
92
|
|
93
|
@Override
|
94
|
public String apply(final DatasourceDesc ds) {
|
95
|
try {
|
96
|
return DatasourceDescToProfile.convert(ds);
|
97
|
} catch (Exception e) {
|
98
|
log.error("Error convering profile", e);
|
99
|
return null;
|
100
|
}
|
101
|
}
|
102
|
}
|