1 |
41842
|
sandro.lab
|
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 |
|
|
}
|