Revision 41339
Added by Michele Artini over 8 years ago
ISLookupClient.java | ||
---|---|---|
5 | 5 |
import java.util.List; |
6 | 6 |
import java.util.Map; |
7 | 7 |
import java.util.Set; |
8 |
|
|
8 | 9 |
import javax.annotation.PostConstruct; |
9 | 10 |
import javax.annotation.Resource; |
10 |
import javax.xml.transform.stream.StreamSource; |
|
11 | 11 |
|
12 |
import org.apache.commons.logging.Log; |
|
13 |
import org.apache.commons.logging.LogFactory; |
|
14 |
import org.dom4j.DocumentException; |
|
15 |
import org.dom4j.Node; |
|
16 |
import org.dom4j.io.SAXReader; |
|
17 |
import org.springframework.beans.factory.annotation.Required; |
|
18 |
|
|
12 | 19 |
import com.google.common.base.Function; |
13 | 20 |
import com.google.common.collect.Lists; |
14 | 21 |
import com.google.common.collect.Maps; |
15 | 22 |
import com.google.common.collect.Sets; |
16 | 23 |
import com.google.gson.Gson; |
17 | 24 |
import com.google.gson.reflect.TypeToken; |
25 |
|
|
26 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpDocumentNotFoundException; |
|
18 | 27 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException; |
19 | 28 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; |
20 | 29 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
21 | 30 |
import eu.dnetlib.functionality.modular.ui.workflows.objects.WorkflowItem; |
22 | 31 |
import eu.dnetlib.functionality.modular.ui.workflows.objects.WorkflowParamUI; |
23 |
import eu.dnetlib.miscutils.functional.xml.ApplyXslt; |
|
24 |
import org.apache.commons.logging.Log; |
|
25 |
import org.apache.commons.logging.LogFactory; |
|
26 |
import org.dom4j.DocumentException; |
|
27 |
import org.dom4j.Node; |
|
28 |
import org.dom4j.io.SAXReader; |
|
29 |
import org.springframework.beans.factory.annotation.Required; |
|
30 | 32 |
|
31 | 33 |
public class ISLookupClient { |
32 | 34 |
|
33 | 35 |
private static final Log log = LogFactory.getLog(ISLookupClient.class); |
34 |
private static final ApplyXslt workflowToHTML = new ApplyXslt(new StreamSource( |
|
35 |
ISLookupClient.class.getResourceAsStream("/eu/dnetlib/functionality/modular/ui/workflows/xslt/wf_profile2html.xslt"))); |
|
36 |
|
|
36 | 37 |
@Resource |
37 | 38 |
private UniqueServiceLocator serviceLocator; |
38 | 39 |
private String categoryUisJson; |
... | ... | |
42 | 43 |
@PostConstruct |
43 | 44 |
private void init() { |
44 | 45 |
log.info("Initialing categoryUis map using JSON: " + getCategoryUisJson()); |
45 |
this.categoryUis = new Gson().fromJson(getCategoryUisJson(), new TypeToken<Map<String, List<WorkflowParamUI.UI>>>() { |
|
46 |
}.getType()); |
|
46 |
this.categoryUis = new Gson().fromJson(getCategoryUisJson(), new TypeToken<Map<String, List<WorkflowParamUI.UI>>>() {}.getType()); |
|
47 | 47 |
} |
48 | 48 |
|
49 | 49 |
public List<String> listSimpleWorflowSections() { |
50 | 50 |
final String xquery = "distinct-values(//WORKFLOW_NAME/@menuSection/string())"; |
51 | 51 |
try { |
52 |
return serviceLocator.getService(ISLookUpService.class).quickSearchProfile(xquery); |
|
53 |
} catch (ISLookUpException e) { |
|
52 |
return this.serviceLocator.getService(ISLookUpService.class).quickSearchProfile(xquery);
|
|
53 |
} catch (final ISLookUpException e) {
|
|
54 | 54 |
log.error("Error obtaining worflowSections", e); |
55 | 55 |
return Lists.newArrayList(); |
56 | 56 |
} |
... | ... | |
70 | 70 |
+ " order by $x//WORKFLOW_NAME return concat($x//RESOURCE_IDENTIFIER/@value, ' ==@== ', $x//WORKFLOW_NAME, ' ==@== ', $x//WORKFLOW_DESCRIPTION)"; |
71 | 71 |
|
72 | 72 |
try { |
73 |
return Lists.transform(serviceLocator.getService(ISLookUpService.class).quickSearchProfile(query), new Function<String, WorkflowItem>() { |
|
73 |
return Lists.transform(this.serviceLocator.getService(ISLookUpService.class).quickSearchProfile(query), new Function<String, WorkflowItem>() { |
|
74 |
|
|
74 | 75 |
@Override |
75 | 76 |
public WorkflowItem apply(final String s) { |
76 | 77 |
final String[] arr = s.split("==@=="); |
77 | 78 |
return new WorkflowItem(arr[0].trim(), arr[1].trim(), arr[2].trim()); |
78 | 79 |
} |
79 | 80 |
}); |
80 |
} catch (ISLookUpException e) { |
|
81 |
} catch (final ISLookUpException e) {
|
|
81 | 82 |
log.error("Error obtaining wfs using query: " + query, e); |
82 | 83 |
return Lists.newArrayList(); |
83 | 84 |
} |
... | ... | |
85 | 86 |
|
86 | 87 |
public String getProfile(final String id) { |
87 | 88 |
try { |
88 |
return serviceLocator.getService(ISLookUpService.class).getResourceProfile(id); |
|
89 |
} catch (ISLookUpException e) { |
|
89 |
return this.serviceLocator.getService(ISLookUpService.class).getResourceProfile(id);
|
|
90 |
} catch (final ISLookUpException e) {
|
|
90 | 91 |
log.error("Error finding profile: " + id, e); |
91 | 92 |
return null; |
92 | 93 |
} |
93 | 94 |
} |
94 | 95 |
|
96 |
public String getRepoProfile(final String id) throws ISLookUpException { |
|
97 |
try { |
|
98 |
return this.serviceLocator.getService(ISLookUpService.class).getResourceProfile(id); |
|
99 |
} catch (final ISLookUpDocumentNotFoundException e) { |
|
100 |
return this.serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery( |
|
101 |
"collection('/db/DRIVER/RepositoryServiceResources/RepositoryServiceResourceType')/*[.//DATASOURCE_ORIGINAL_ID='" + id + "']"); |
|
102 |
} |
|
103 |
} |
|
104 |
|
|
95 | 105 |
public Set<String> getNotConfiguredNodes(final String id) { |
96 | 106 |
final String query = "for $x in (/*[.//RESOURCE_IDENTIFIER/@value='" + id + "']//NODE) " |
97 | 107 |
+ "where count($x//PARAM[@required='true' and string-length(normalize-space(.)) = 0]) > 0 " + "return $x/@name/string()"; |
98 | 108 |
|
99 | 109 |
try { |
100 |
final List<String> list = serviceLocator.getService(ISLookUpService.class).quickSearchProfile(query); |
|
110 |
final List<String> list = this.serviceLocator.getService(ISLookUpService.class).quickSearchProfile(query);
|
|
101 | 111 |
return Sets.newHashSet(list); |
102 |
} catch (Exception e) { |
|
112 |
} catch (final Exception e) {
|
|
103 | 113 |
log.error("Error executing xquery: " + query, e); |
104 | 114 |
return Sets.newHashSet(); |
105 | 115 |
} |
... | ... | |
112 | 122 |
+ "return concat($x//RESOURCE_IDENTIFIER/@value, ' @@@ ', $x//WORKFLOW_NAME)"; |
113 | 123 |
|
114 | 124 |
try { |
115 |
for (String s : serviceLocator.getService(ISLookUpService.class).quickSearchProfile(query)) {
|
|
116 |
String[] arr = s.split("@@@"); |
|
125 |
for (final String s : this.serviceLocator.getService(ISLookUpService.class).quickSearchProfile(query)) {
|
|
126 |
final String[] arr = s.split("@@@");
|
|
117 | 127 |
map.put(arr[0].trim(), arr[1].trim()); |
118 | 128 |
} |
119 |
} catch (Exception e) { |
|
129 |
} catch (final Exception e) {
|
|
120 | 130 |
log.error("Error executing xquery: " + query, e); |
121 | 131 |
} |
122 | 132 |
return map; |
... | ... | |
126 | 136 |
final String query = "distinct-values(for $x in collection('/db/DRIVER/WorkflowDSResources/WorkflowDSResourceType') " |
127 | 137 |
+ "where string-length($x//DATASOURCE/@id) > 0 return $x//WORKFLOW_TYPE/@text())"; |
128 | 138 |
try { |
129 |
return serviceLocator.getService(ISLookUpService.class).quickSearchProfile(query); |
|
130 |
} catch (ISLookUpException e) { |
|
139 |
return this.serviceLocator.getService(ISLookUpService.class).quickSearchProfile(query);
|
|
140 |
} catch (final ISLookUpException e) {
|
|
131 | 141 |
log.error("Error executing xquery: " + query, e); |
132 | 142 |
return Lists.newArrayList(); |
133 | 143 |
} |
... | ... | |
137 | 147 |
final String query = "/*[.//RESOURCE_IDENTIFIER/@value='" + dsId + "']//OFFICIAL_NAME/text()"; |
138 | 148 |
|
139 | 149 |
try { |
140 |
return serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(query); |
|
141 |
} catch (ISLookUpException e) { |
|
150 |
return this.serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(query);
|
|
151 |
} catch (final ISLookUpException e) {
|
|
142 | 152 |
log.error("Error executing xquery: " + query, e); |
143 | 153 |
return "UNKNOWN"; |
144 | 154 |
} |
145 | 155 |
} |
146 | 156 |
|
147 | 157 |
public Map<String, List<WorkflowParamUI.UI>> getCategoryUis() { |
148 |
return categoryUis; |
|
158 |
return this.categoryUis;
|
|
149 | 159 |
} |
150 | 160 |
|
151 | 161 |
public String getCategoryUisJson() { |
152 |
return categoryUisJson; |
|
162 |
return this.categoryUisJson;
|
|
153 | 163 |
} |
154 | 164 |
|
155 | 165 |
@Required |
... | ... | |
171 | 181 |
+ "<disabled>{$y//CONFIGURATION/@start=\"DISABLED\" or $y//CONFIGURATION/@status !=\"EXECUTABLE\"}</disabled>\n" |
172 | 182 |
+ "</res>"; |
173 | 183 |
try { |
174 |
final List<String> list = serviceLocator.getService(ISLookUpService.class).quickSearchProfile(query); |
|
184 |
final List<String> list = this.serviceLocator.getService(ISLookUpService.class).quickSearchProfile(query);
|
|
175 | 185 |
return Lists.transform(list, new Function<String, Map<String, String>>() { |
176 | 186 |
|
177 |
private SAXReader reader = new SAXReader(); |
|
187 |
private final SAXReader reader = new SAXReader();
|
|
178 | 188 |
|
179 | 189 |
@Override |
180 | 190 |
public Map<String, String> apply(final String s) { |
181 | 191 |
try { |
182 | 192 |
final Map<String, String> map = new HashMap<String, String>(); |
183 |
for (Object o : reader.read(new StringReader(s)).selectNodes("/res/*")) {
|
|
193 |
for (final Object o : this.reader.read(new StringReader(s)).selectNodes("/res/*")) {
|
|
184 | 194 |
map.put(((Node) o).getName(), ((Node) o).getText()); |
185 | 195 |
} |
186 | 196 |
return map; |
187 |
} catch (DocumentException e) { |
|
197 |
} catch (final DocumentException e) {
|
|
188 | 198 |
throw new RuntimeException(e); |
189 | 199 |
} |
190 | 200 |
} |
191 | 201 |
}); |
192 |
} catch (ISLookUpException e) { |
|
202 |
} catch (final ISLookUpException e) {
|
|
193 | 203 |
log.error("Error executing xquery: " + query, e); |
194 | 204 |
return Lists.newArrayList(); |
195 | 205 |
} |
Also available in: Unified diff
override compliance