1
|
package eu.dnetlib.enabling.datasources;
|
2
|
|
3
|
import java.util.Map.Entry;
|
4
|
import java.util.function.Function;
|
5
|
|
6
|
import org.apache.commons.logging.Log;
|
7
|
import org.apache.commons.logging.LogFactory;
|
8
|
import org.dom4j.DocumentHelper;
|
9
|
import org.dom4j.Element;
|
10
|
import org.dom4j.Node;
|
11
|
|
12
|
import eu.dnetlib.clients.dsManager.DatasourceDesc;
|
13
|
import eu.dnetlib.clients.dsManager.IfaceDesc;
|
14
|
import eu.dnetlib.miscutils.datetime.DateUtils;
|
15
|
|
16
|
public class DatasourceDescToProfile implements Function<DatasourceDesc, String> {
|
17
|
|
18
|
private static final Log log = LogFactory.getLog(DatasourceDescToProfile.class);
|
19
|
|
20
|
public static String convert(final DatasourceDesc ds) throws Exception {
|
21
|
final Element root = DocumentHelper.createElement("RESOURCE_PROFILE");
|
22
|
|
23
|
final Element header = root.addElement("HEADER");
|
24
|
header.addElement("RESOURCE_IDENTIFIER").addAttribute("value", "");
|
25
|
header.addElement("RESOURCE_TYPE").addAttribute("value", "datasource");
|
26
|
header.addElement("RESOURCE_KIND").addAttribute("value", "entity");
|
27
|
header.addElement("RESOURCE_URI").addAttribute("value", "");
|
28
|
header.addElement("DATE_OF_CREATION").addAttribute("value", DateUtils.now_ISO8601());
|
29
|
header.addElement("PROTOCOL");
|
30
|
|
31
|
final Element body = root.addElement("BODY");
|
32
|
final Element conf = body.addElement("CONFIGURATION");
|
33
|
conf.addElement("DATASOURCE_TYPE").setText(ds.getDatasourceClass());
|
34
|
|
35
|
final Element origId = conf.addElement("DATASOURCE_ORIGINAL_ID");
|
36
|
origId.addAttribute("provenance", "D-NET");
|
37
|
origId.setText(ds.getId());
|
38
|
|
39
|
conf.addElement("DATASOURCE_AGGREGATED").setText("false");
|
40
|
conf.addElement("ENVIRONMENTS");
|
41
|
conf.addElement("TYPOLOGY").setText(ds.getTypology());
|
42
|
conf.addElement("MAX_SIZE_OF_DATASTRUCTURE").setText("0");
|
43
|
conf.addElement("AVAILABLE_DISKSPACE").setText("0");
|
44
|
conf.addElement("MAX_NUMBER_OF_DATASTRUCTURE").setText("0");
|
45
|
|
46
|
conf.addElement("OFFICIAL_NAME").setText(ds.getOfficialName());
|
47
|
conf.addElement("ENGLISH_NAME").setText(ds.getEnglishName());
|
48
|
conf.addElement("ICON_URI").setText(ds.getLogoUrl());
|
49
|
conf.addElement("COUNTRY").setText(ds.getCountryCode());
|
50
|
|
51
|
final Element location = conf.addElement("LOCATION");
|
52
|
location.addElement("LONGITUDE").setText("" + ds.getLongitude());
|
53
|
location.addElement("LATITUDE").setText("" + ds.getLatitude());
|
54
|
location.addElement("TIMEZONE").setText("" + ds.getTimezone());
|
55
|
|
56
|
conf.addElement("REPOSITORY_WEBPAGE").setText(ds.getWebsiteUrl());
|
57
|
conf.addElement("REPOSITORY_INSTITUTION").setText(ds.getOrganization());
|
58
|
conf.addElement("ADMIN_INFO").setText(ds.getContactEmail());
|
59
|
|
60
|
final Element ifaces = conf.addElement("INTERFACES");
|
61
|
for (final IfaceDesc ifc : ds.getInterfaces()) {
|
62
|
ifaces.add(ifaceDescToNode(ifc));
|
63
|
}
|
64
|
final Element extraFields = conf.addElement("EXTRA_FIELDS");
|
65
|
addExtraField(extraFields, "ACTIVATION_ID", ds.getActivationId());
|
66
|
addExtraField(extraFields, "NamespacePrefix", ds.getNamespacePrefix());
|
67
|
addExtraField(extraFields, "aggregatorName", ds.getAggregator());
|
68
|
addExtraField(extraFields, "dateOfCollection", "" + ds.getDateOfCollection());
|
69
|
addExtraField(extraFields, "dateOfValidation", "" + ds.getDateOfValidation());
|
70
|
conf.addElement("REGISTERED_BY");
|
71
|
|
72
|
final Element status = body.addElement("STATUS");
|
73
|
status.addElement("NUMBER_OF_OBJECTS").setText("0");
|
74
|
status.addElement("LAST_UPDATE").addAttribute("value", DateUtils.now_ISO8601());
|
75
|
|
76
|
final Element qos = body.addElement("QOS");
|
77
|
qos.addElement("AVAILABILITY").setText("0");
|
78
|
qos.addElement("CAPACITY");
|
79
|
qos.addElement("THROUGHPUT").setText("0");
|
80
|
|
81
|
body.addElement("SECURITY_PARAMETERS");
|
82
|
body.addElement("BLACKBOARD");
|
83
|
|
84
|
System.out.println("aaaaaaaaaaaaaa " + root.asXML());
|
85
|
|
86
|
return root.asXML();
|
87
|
}
|
88
|
|
89
|
public static Node ifaceDescToNode(final IfaceDesc iface) throws Exception {
|
90
|
|
91
|
final Element ifcNode = DocumentHelper.createElement("INTERFACE");
|
92
|
ifcNode.addAttribute("id", iface.getId());
|
93
|
ifcNode.addAttribute("label", iface.getTypology() + " (" + iface.getCompliance() + ")");
|
94
|
ifcNode.addAttribute("compliance", iface.getCompliance());
|
95
|
ifcNode.addAttribute("typology", iface.getTypology());
|
96
|
ifcNode.addAttribute("contentDescription", iface.getContentDescription());
|
97
|
ifcNode.addAttribute("active", Boolean.toString(iface.isActive()));
|
98
|
ifcNode.addAttribute("removable", Boolean.toString(iface.isRemovable()));
|
99
|
|
100
|
final Element acProtoNode = ifcNode.addElement("ACCESS_PROTOCOL");
|
101
|
|
102
|
for (final Entry<String, String> e : iface.getAccessParams().entrySet()) {
|
103
|
acProtoNode.addAttribute(e.getKey(), e.getValue());
|
104
|
}
|
105
|
acProtoNode.setText(iface.getAccessProtocol());
|
106
|
|
107
|
ifcNode.addElement("BASE_URL").setText(iface.getBaseUrl());;
|
108
|
|
109
|
for (final Entry<String, String> e : iface.getExtraFields().entrySet()) {
|
110
|
final Element field = ifcNode.addElement("INTERFACE_EXTRA_FIELD");
|
111
|
field.addAttribute("name", e.getKey());
|
112
|
field.setText(e.getValue());
|
113
|
}
|
114
|
|
115
|
return ifcNode;
|
116
|
}
|
117
|
|
118
|
private static void addExtraField(final Element extraFields, final String field, final String value) {
|
119
|
final Element f = extraFields.addElement("FIELD");
|
120
|
f.addElement("key").setText(field);
|
121
|
f.addElement("value").setText(value);
|
122
|
}
|
123
|
|
124
|
@Override
|
125
|
public String apply(final DatasourceDesc ds) {
|
126
|
try {
|
127
|
return DatasourceDescToProfile.convert(ds);
|
128
|
} catch (final Exception e) {
|
129
|
log.error("Error convering profile", e);
|
130
|
return null;
|
131
|
}
|
132
|
}
|
133
|
}
|