Revision 45556
Added by Michele Artini over 7 years ago
DefaultServiceClientLocator.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.clients.locators; |
2 | 2 |
|
3 | 3 |
import java.io.StringReader; |
4 |
import java.io.StringWriter; |
|
5 | 4 |
import java.util.Comparator; |
6 |
import java.util.HashMap; |
|
7 |
import java.util.Map; |
|
8 | 5 |
import java.util.Optional; |
9 | 6 |
|
10 |
import org.apache.commons.lang3.math.NumberUtils; |
|
11 | 7 |
import org.apache.commons.logging.Log; |
12 | 8 |
import org.apache.commons.logging.LogFactory; |
13 | 9 |
import org.dom4j.Document; |
14 | 10 |
import org.dom4j.DocumentException; |
15 |
import org.dom4j.Element; |
|
16 | 11 |
import org.dom4j.io.SAXReader; |
17 | 12 |
import org.springframework.beans.BeansException; |
18 | 13 |
import org.springframework.beans.factory.BeanFactory; |
... | ... | |
68 | 63 |
|
69 | 64 |
log.debug("searching for service: " + type); |
70 | 65 |
|
71 |
final String xquery = "for $x in collection('/db/DRIVER/ServiceResources/" + type + "ResourceType') return $x";
|
|
66 |
final String xquery = "for $x in collection('/db/DRIVER/DnetService/" + type + ") return $x";
|
|
72 | 67 |
|
73 | 68 |
try { |
74 | 69 |
final Optional<ServiceRunningInstance> instance = isLookup.find(xquery) |
... | ... | |
100 | 95 |
private synchronized ServiceRunningInstance obtainRunningInstance(final String profile) { |
101 | 96 |
try { |
102 | 97 |
final Document doc = reader.read(new StringReader(profile)); |
103 |
final String url = doc.valueOf("//PROTOCOL[@name = 'SOAP']/@address"); |
|
104 |
final String id = doc.valueOf("//RESOURCE_IDENTIFIER/@value"); |
|
105 |
final Map<String, String> props = new HashMap<>(); |
|
106 |
final int usedDiskspace = NumberUtils.toInt(doc.valueOf("//USED_DISKSPACE"), 0); |
|
107 |
final int handledDataStructures = NumberUtils.toInt(doc.valueOf("//HANDLED_DATASTRUCTURE"), 0);; |
|
98 |
final String url = doc.valueOf("/profile/baseUrl").trim(); |
|
99 |
final String id = doc.valueOf("/profile/id").trim(); |
|
108 | 100 |
|
109 |
for (final Object o : doc.selectNodes("//SERVICE_PROPERTIES/PROPERTY")) { |
|
110 |
final Element p = (Element) o; |
|
111 |
props.put(p.valueOf("@key"), p.valueOf("@value")); |
|
112 |
} |
|
101 |
// TODO: call the service to obtain the ServiceRunningInstance |
|
113 | 102 |
|
114 |
return new ServiceRunningInstance(id, url, usedDiskspace, handledDataStructures, props);
|
|
103 |
return new ServiceRunningInstance(id, url); |
|
115 | 104 |
} catch (final DocumentException e) { |
116 | 105 |
log.error("Error parsing profile: " + profile, e); |
117 | 106 |
throw new RuntimeException("Error parsing profile: " + profile, e); |
118 | 107 |
} |
119 | 108 |
} |
120 | 109 |
|
121 |
private String obtainServiceProfile(final String profileId) { |
|
122 |
final StringWriter sw = new StringWriter(); |
|
123 |
sw.append("let $uri:=/RESOURCE_PROFILE/HEADER[./RESOURCE_IDENTIFIER/@value='"); |
|
124 |
sw.append(profileId); |
|
125 |
sw.append("']/RESOURCE_URI/@value/string()"); |
|
126 |
sw.append("\n\n"); |
|
127 |
sw.append("for $x in collection('/db/DRIVER/ServiceResources')"); |
|
128 |
sw.append("\n"); |
|
129 |
sw.append("where $x/RESOURCE_PROFILE/HEADER/RESOURCE_URI/@value = $uri"); |
|
130 |
sw.append("\n"); |
|
131 |
sw.append("return $x"); |
|
110 |
private String obtainServiceProfile(final String id) { |
|
132 | 111 |
|
133 |
final String xq = sw.toString();
|
|
112 |
// TODO: gestire il caso in cui profileID รจ il profilo di una DS
|
|
134 | 113 |
|
135 | 114 |
try { |
136 |
return isLookup.findOne(xq);
|
|
115 |
return isLookup.getProfile(id);
|
|
137 | 116 |
} catch (final ISLookUpException e) { |
138 |
log.error("cannot locate service using query: " + xq, e);
|
|
139 |
throw new DnetGenericRuntimeException("cannot locate service using query: " + xq, e);
|
|
117 |
log.error("cannot locate service by id: " + id, e);
|
|
118 |
throw new DnetGenericRuntimeException("cannot locate service by id: " + id, e);
|
|
140 | 119 |
} |
141 | 120 |
} |
142 | 121 |
|
Also available in: Unified diff