2 |
2 |
|
3 |
3 |
import org.apache.commons.logging.Log;
|
4 |
4 |
import org.apache.commons.logging.LogFactory;
|
|
5 |
import org.dom4j.DocumentHelper;
|
|
6 |
import org.dom4j.Element;
|
5 |
7 |
|
6 |
8 |
import com.google.common.base.Function;
|
7 |
9 |
|
8 |
10 |
import eu.dnetlib.enabling.datasources.rmi.DatasourceDesc;
|
|
11 |
import eu.dnetlib.enabling.datasources.rmi.IfaceDesc;
|
|
12 |
import eu.dnetlib.miscutils.datetime.DateUtils;
|
9 |
13 |
|
10 |
14 |
public class DatasourceDescToProfile implements Function<DatasourceDesc, String> {
|
11 |
15 |
|
... | ... | |
22 |
26 |
}
|
23 |
27 |
|
24 |
28 |
public static String convert(final DatasourceDesc ds) throws Exception {
|
25 |
|
// TODO Auto-generated method stub
|
26 |
|
return null;
|
|
29 |
final Element root = DocumentHelper.createElement("RESOURCE_PROFILE");
|
|
30 |
|
|
31 |
final Element header = root.addElement("HEADER");
|
|
32 |
header.addElement("RESOURCE_IDENTIFIER").addAttribute("value", "");
|
|
33 |
header.addElement("RESOURCE_TYPE").addAttribute("value", "RepositoryServiceResourceType");
|
|
34 |
header.addElement("RESOURCE_KIND").addAttribute("value", "RepositoryServiceResources");
|
|
35 |
header.addElement("RESOURCE_URI").addAttribute("value", "");
|
|
36 |
header.addElement("DATE_OF_CREATION").addAttribute("value", DateUtils.now_ISO8601());
|
|
37 |
header.addElement("PROTOCOL");
|
|
38 |
|
|
39 |
final Element body = root.addElement("BODY");
|
|
40 |
final Element conf = body.addElement("CONFIGURATION");
|
|
41 |
conf.addElement("DATASOURCE_TYPE").setText(ds.getDatasourceClass());
|
|
42 |
|
|
43 |
final Element origId = conf.addElement("DATASOURCE_ORIGINAL_ID");
|
|
44 |
origId.addAttribute("provenance", "OPENAIRE");
|
|
45 |
origId.setText(ds.getId());
|
|
46 |
|
|
47 |
conf.addElement("DATASOURCE_AGGREGATED").setText("false");
|
|
48 |
conf.addElement("ENVIRONMENTS").addElement("ENVIRONMENT").setText("OPENAIRE");
|
|
49 |
conf.addElement("TYPOLOGY").setText(ds.getTypology());
|
|
50 |
conf.addElement("MAX_SIZE_OF_DATASTRUCTURE").setText("0");
|
|
51 |
conf.addElement("AVAILABLE_DISKSPACE").setText("0");
|
|
52 |
conf.addElement("MAX_NUMBER_OF_DATASTRUCTURE").setText("0");
|
|
53 |
|
|
54 |
conf.addElement("OFFICIAL_NAME").setText(ds.getOfficialName());
|
|
55 |
conf.addElement("ENGLISH_NAME").setText(ds.getEnglishName());
|
|
56 |
conf.addElement("ICON_URI").setText("");
|
|
57 |
conf.addElement("COUNTRY").setText(ds.getCountryCode());
|
|
58 |
|
|
59 |
final Element location = conf.addElement("LOCATION");
|
|
60 |
location.addElement("LONGITUDE").setText("" + ds.getLongitude());
|
|
61 |
location.addElement("LATITUDE").setText("" + ds.getLatitude());
|
|
62 |
location.addElement("TIMEZONE").setText("" + ds.getTimezone());
|
|
63 |
|
|
64 |
conf.addElement("REPOSITORY_WEBPAGE").setText(ds.getWebsiteUrl());
|
|
65 |
conf.addElement("REPOSITORY_INSTITUTION").setText(ds.getOrganization());
|
|
66 |
conf.addElement("ADMIN_INFO").setText("");
|
|
67 |
|
|
68 |
final Element ifaces = conf.addElement("INTERFACES");
|
|
69 |
for (IfaceDesc ifc : ds.getInterfaces()) {
|
|
70 |
ifaces.add(IfaceDescToNode.convert(ifc));
|
|
71 |
}
|
|
72 |
final Element extraFields = conf.addElement("EXTRA_FIELDS");
|
|
73 |
addExtraField(extraFields, "ACTIVATION_ID", ds.getActivationId());
|
|
74 |
addExtraField(extraFields, "NamespacePrefix", ds.getNamespacePrefix());
|
|
75 |
addExtraField(extraFields, "aggregatorName", ds.getAggregator());
|
|
76 |
addExtraField(extraFields, "dateOfCollection", "" + ds.getDateOfCollection());
|
|
77 |
addExtraField(extraFields, "dateOfValidation", "" + ds.getDateOfValidation());
|
|
78 |
conf.addElement("REGISTERED_BY");
|
|
79 |
|
|
80 |
final Element status = body.addElement("STATUS");
|
|
81 |
status.addElement("NUMBER_OF_OBJECTS").setText("0");
|
|
82 |
status.addElement("LAST_UPDATE").addAttribute("value", "");
|
|
83 |
|
|
84 |
final Element qos = body.addElement("QOS");
|
|
85 |
qos.addElement("AVAILABILITY").setText("0");
|
|
86 |
qos.addElement("CAPACITY");
|
|
87 |
qos.addElement("THROUGHPUT").setText("0");
|
|
88 |
|
|
89 |
body.addElement("SECURITY_PARAMETERS");
|
|
90 |
body.addElement("BLACKBOARD");
|
|
91 |
|
|
92 |
return root.asXML();
|
27 |
93 |
}
|
|
94 |
|
|
95 |
private static void addExtraField(final Element extraFields, final String field, final String value) {
|
|
96 |
final Element f = extraFields.addElement("FIELD");
|
|
97 |
f.addElement("key").setText(field);
|
|
98 |
f.addElement("value").setText(value);
|
|
99 |
}
|
28 |
100 |
}
|
partial implementation