Project

General

Profile

« Previous | Next » 

Revision 33874

partial implementation

View differences:

modules/dnet-datasource-manager-service/trunk/src/main/java/eu/dnetlib/enabling/datasources/IfaceDescToNode.java
1 1
package eu.dnetlib.enabling.datasources;
2 2

  
3
import org.dom4j.Node;
3
import java.util.Map.Entry;
4 4

  
5
import org.dom4j.DocumentHelper;
6
import org.dom4j.Element;
7

  
5 8
import eu.dnetlib.enabling.datasources.rmi.IfaceDesc;
6 9

  
7 10
public class IfaceDescToNode {
8 11

  
9
	public static Node convert(final IfaceDesc iface) throws Exception {
10
		// TODO Auto-generated method stub
11
		return null;
12
	public static Element convert(final IfaceDesc iface) throws Exception {
13

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

  
23
		final Element acProtoNode = ifcNode.addElement("ACCESS_PROTOCOL");
24
		final Element baseUrlNode = ifcNode.addElement("BASE_URL");
25
		for (Entry<String, String> e : iface.getAccessParams().entrySet()) {
26
			if (e.getKey().equalsIgnoreCase("BASEURL") || e.getKey().equalsIgnoreCase("BASE_URL")) {
27
				baseUrlNode.setText(e.getValue());;
28
			} else {
29
				acProtoNode.addAttribute(e.getKey(), e.getValue());
30
			}
31
		}
32
		acProtoNode.setText(iface.getAccessProtocol());
33

  
34
		for (Entry<String, String> e : iface.getExtraFields().entrySet()) {
35
			final Element field = ifcNode.addElement("INTERFACE_EXTRA_FIELD");
36
			field.addAttribute("name", e.getKey());
37
			field.setText(e.getValue());
38
		}
39

  
40
		return ifcNode;
12 41
	}
13 42
}
modules/dnet-datasource-manager-service/trunk/src/main/java/eu/dnetlib/enabling/datasources/DatasourceDescToProfile.java
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
}

Also available in: Unified diff