Revision 33047
Added by Sandro La Bruzzo over 9 years ago
modules/dnet-modular-repositories-ui/tags/dnet-modular-repositories-ui-3.0.2/deploy.info | ||
---|---|---|
1 |
{"type_source": "SVN", "goal": "package -U -T 4C source:jar", "url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet40/modules/dnet-modular-repositories-ui/trunk/", "deploy_repository": "dnet4-snapshots", "version": "4", "mail": "sandro.labruzzo@isti.cnr.it,michele.artini@isti.cnr.it, claudio.atzori@isti.cnr.it, alessia.bardi@isti.cnr.it", "deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet4-snapshots", "name": "dnet-modular-repositories-ui"} |
modules/dnet-modular-repositories-ui/tags/dnet-modular-repositories-ui-3.0.2/src/main/java/eu/dnetlib/functionality/modular/ui/repositories/RepoApisEntryPointController.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.modular.ui.repositories; |
|
2 |
|
|
3 |
import java.io.StringReader; |
|
4 |
import java.util.ArrayList; |
|
5 |
import java.util.Collections; |
|
6 |
import java.util.List; |
|
7 |
import java.util.Set; |
|
8 |
|
|
9 |
import javax.annotation.Resource; |
|
10 |
import javax.servlet.http.HttpServletRequest; |
|
11 |
import javax.servlet.http.HttpServletResponse; |
|
12 |
|
|
13 |
import org.dom4j.Document; |
|
14 |
import org.dom4j.Element; |
|
15 |
import org.dom4j.Node; |
|
16 |
import org.dom4j.io.SAXReader; |
|
17 |
import org.springframework.beans.factory.annotation.Required; |
|
18 |
import org.springframework.ui.ModelMap; |
|
19 |
|
|
20 |
import com.google.common.base.Splitter; |
|
21 |
import com.google.common.collect.Lists; |
|
22 |
import com.google.common.collect.Sets; |
|
23 |
import com.google.gson.Gson; |
|
24 |
|
|
25 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException; |
|
26 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; |
|
27 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
28 |
import eu.dnetlib.functionality.modular.ui.ModuleEntryPoint; |
|
29 |
import eu.dnetlib.functionality.modular.ui.repositories.objects.VocabularyEntry; |
|
30 |
import eu.dnetlib.miscutils.collections.Pair; |
|
31 |
|
|
32 |
public class RepoApisEntryPointController extends ModuleEntryPoint { |
|
33 |
|
|
34 |
@Resource |
|
35 |
private UniqueServiceLocator serviceLocator; |
|
36 |
|
|
37 |
@Resource |
|
38 |
private RepoUIUtils repoUIUtils; |
|
39 |
|
|
40 |
private String compatibilityLevelsVocabulary; |
|
41 |
|
|
42 |
public class RepoHIWorkflow implements Comparable<RepoHIWorkflow> { |
|
43 |
|
|
44 |
private String id; |
|
45 |
private String name; |
|
46 |
private Set<String> ifaceTypes; |
|
47 |
private Set<String> compliances; |
|
48 |
private List<Pair<String, String>> fields; |
|
49 |
|
|
50 |
/** |
|
51 |
* Instantiates a new repo hi workflow. |
|
52 |
* |
|
53 |
* @param id |
|
54 |
* the id |
|
55 |
* @param name |
|
56 |
* the name |
|
57 |
* @param ifaceTypes |
|
58 |
* the iface types |
|
59 |
* @param compliances |
|
60 |
* the compliances |
|
61 |
* @param fields |
|
62 |
* the fields |
|
63 |
*/ |
|
64 |
public RepoHIWorkflow(final String id, final String name, final Set<String> ifaceTypes, final Set<String> compliances, |
|
65 |
final List<Pair<String, String>> fields) { |
|
66 |
super(); |
|
67 |
this.id = id; |
|
68 |
this.name = name; |
|
69 |
this.ifaceTypes = ifaceTypes; |
|
70 |
this.compliances = compliances; |
|
71 |
this.fields = fields; |
|
72 |
} |
|
73 |
|
|
74 |
public String getId() { |
|
75 |
return id; |
|
76 |
} |
|
77 |
|
|
78 |
public String getName() { |
|
79 |
return name; |
|
80 |
} |
|
81 |
|
|
82 |
public Set<String> getIfaceTypes() { |
|
83 |
return ifaceTypes; |
|
84 |
} |
|
85 |
|
|
86 |
public Set<String> getCompliances() { |
|
87 |
return compliances; |
|
88 |
} |
|
89 |
|
|
90 |
@Override |
|
91 |
public int compareTo(final RepoHIWorkflow o) { |
|
92 |
return getName().compareTo(o.getName()); |
|
93 |
} |
|
94 |
|
|
95 |
/** |
|
96 |
* @return the fields |
|
97 |
*/ |
|
98 |
public List<Pair<String, String>> getFields() { |
|
99 |
return fields; |
|
100 |
} |
|
101 |
|
|
102 |
/** |
|
103 |
* @param fields |
|
104 |
* the fields to set |
|
105 |
*/ |
|
106 |
public void setFields(final List<Pair<String, String>> fields) { |
|
107 |
this.fields = fields; |
|
108 |
} |
|
109 |
|
|
110 |
} |
|
111 |
|
|
112 |
private RepoHIWorkflow parseQuery(final String input) { |
|
113 |
|
|
114 |
SAXReader reader = new SAXReader(); |
|
115 |
try { |
|
116 |
Document doc = reader.read(new StringReader(input)); |
|
117 |
Element rootNode = doc.getRootElement(); |
|
118 |
Node node = doc.selectSingleNode("//id"); |
|
119 |
String id = node.getText(); |
|
120 |
node = doc.selectSingleNode("//name"); |
|
121 |
String name = node != null ? node.getText() : ""; |
|
122 |
node = doc.selectSingleNode("//types"); |
|
123 |
String type = node != null ? node.getText() : ""; |
|
124 |
final Set<String> ifcTypes = Sets.newHashSet(Splitter.on(",").omitEmptyStrings().trimResults().split(type)); |
|
125 |
node = doc.selectSingleNode("//compliances"); |
|
126 |
String compliance = node != null ? node.getText() : ""; |
|
127 |
final Set<String> compliances = Sets.newHashSet(Splitter.on(",").omitEmptyStrings().trimResults().split(compliance)); |
|
128 |
List<Node> nodes = doc.selectNodes(".//FIELD"); |
|
129 |
List<Pair<String, String>> fields = new ArrayList<Pair<String, String>>(); |
|
130 |
if (nodes != null) { |
|
131 |
for (Node currentNode : nodes) { |
|
132 |
String key = currentNode.valueOf("@name"); |
|
133 |
String value = currentNode.getText(); |
|
134 |
fields.add(new Pair<String, String>(key, value)); |
|
135 |
} |
|
136 |
} |
|
137 |
return new RepoHIWorkflow(id, name, ifcTypes, compliances, fields); |
|
138 |
|
|
139 |
} catch (Exception e) { |
|
140 |
return null; |
|
141 |
} |
|
142 |
} |
|
143 |
|
|
144 |
private List<RepoHIWorkflow> listRepoHIWorkflows() throws ISLookUpException { |
|
145 |
|
|
146 |
final String xquery = "for $x in collection('/db/DRIVER/WorkflowDSResources/WorkflowDSResourceType') where $x//WORKFLOW_TYPE='REPO_HI' return <result> <id>{$x//RESOURCE_IDENTIFIER/@value/string()}</id> <name>{$x//WORKFLOW_NAME/text()}</name> <types>{$x//PARAM[@name='expectedInterfaceTypologyPrefixes']/text()}</types> <compliances>{$x//PARAM[@name='expectedCompliancePrefixes']/text()}</compliances> {$x//FIELD} </result>"; |
|
147 |
|
|
148 |
// final String xquery = "for $x in collection('/db/DRIVER/WorkflowDSResources/WorkflowDSResourceType') " |
|
149 |
// + "where $x//WORKFLOW_TYPE='REPO_HI' " |
|
150 |
// + |
|
151 |
// "return concat($x//RESOURCE_IDENTIFIER/@value, ' @@@ ', $x//WORKFLOW_NAME, ' @@@ ', $x//PARAM[@name='expectedInterfaceTypologyPrefixes'], ' @@@ ', $x//PARAM[@name='expectedCompliancePrefixes'])"; |
|
152 |
|
|
153 |
final List<RepoHIWorkflow> list = Lists.newArrayList(); |
|
154 |
for (String s : serviceLocator.getService(ISLookUpService.class).quickSearchProfile(xquery)) { |
|
155 |
RepoHIWorkflow repoHiInfo = parseQuery(s); |
|
156 |
if (repoHiInfo != null) { |
|
157 |
list.add(repoHiInfo); |
|
158 |
} |
|
159 |
} |
|
160 |
Collections.sort(list); |
|
161 |
return list; |
|
162 |
} |
|
163 |
|
|
164 |
private List<VocabularyEntry> listCompatibilityLevels() throws ISLookUpException { |
|
165 |
final String xquery = "for $x in collection('/db/DRIVER/VocabularyDSResources/VocabularyDSResourceType')[.//VOCABULARY_NAME/@code = '" |
|
166 |
+ getCompatibilityLevelsVocabulary().trim() + "']//TERM return concat($x/@code, ' @@@ ', $x/@english_name)"; |
|
167 |
|
|
168 |
final List<VocabularyEntry> list = Lists.newArrayList(); |
|
169 |
for (String s : serviceLocator.getService(ISLookUpService.class).quickSearchProfile(xquery)) { |
|
170 |
final String[] arr = s.split("@@@"); |
|
171 |
list.add(new VocabularyEntry(arr[0].trim(), arr[1].trim())); |
|
172 |
} |
|
173 |
Collections.sort(list); |
|
174 |
|
|
175 |
return list; |
|
176 |
} |
|
177 |
|
|
178 |
@Override |
|
179 |
protected void initialize(final ModelMap map, final HttpServletRequest request, final HttpServletResponse response) throws Exception { |
|
180 |
map.addAttribute("availableRepohiWfs", new Gson().toJson(listRepoHIWorkflows())); |
|
181 |
map.addAttribute("compatibilityLevels", new Gson().toJson(listCompatibilityLevels())); |
|
182 |
map.addAttribute("browseFields", repoUIUtils.getBrowseFieldsJson()); |
|
183 |
} |
|
184 |
|
|
185 |
public String getCompatibilityLevelsVocabulary() { |
|
186 |
return compatibilityLevelsVocabulary; |
|
187 |
} |
|
188 |
|
|
189 |
@Required |
|
190 |
public void setCompatibilityLevelsVocabulary(final String compatibilityLevelsVocabulary) { |
|
191 |
this.compatibilityLevelsVocabulary = compatibilityLevelsVocabulary; |
|
192 |
} |
|
193 |
|
|
194 |
} |
modules/dnet-modular-repositories-ui/tags/dnet-modular-repositories-ui-3.0.2/src/main/java/eu/dnetlib/functionality/modular/ui/repositories/RepositoriesGoogleMapEntryPointController.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.modular.ui.repositories; |
|
2 |
|
|
3 |
import javax.servlet.http.HttpServletRequest; |
|
4 |
import javax.servlet.http.HttpServletResponse; |
|
5 |
|
|
6 |
import org.springframework.ui.ModelMap; |
|
7 |
|
|
8 |
import eu.dnetlib.functionality.modular.ui.ModuleEntryPoint; |
|
9 |
|
|
10 |
public class RepositoriesGoogleMapEntryPointController extends ModuleEntryPoint { |
|
11 |
|
|
12 |
@Override |
|
13 |
protected void initialize(final ModelMap map, final HttpServletRequest request, final HttpServletResponse response) throws Exception {} |
|
14 |
|
|
15 |
} |
modules/dnet-modular-repositories-ui/tags/dnet-modular-repositories-ui-3.0.2/src/main/java/eu/dnetlib/functionality/modular/ui/repositories/RepoUIUtils.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.modular.ui.repositories; |
|
2 |
|
|
3 |
import java.io.StringReader; |
|
4 |
import java.util.Collections; |
|
5 |
import java.util.List; |
|
6 |
import java.util.Map; |
|
7 |
import java.util.Set; |
|
8 |
|
|
9 |
import javax.annotation.Resource; |
|
10 |
|
|
11 |
import org.antlr.stringtemplate.StringTemplate; |
|
12 |
import org.apache.commons.io.IOUtils; |
|
13 |
import org.apache.commons.lang.StringEscapeUtils; |
|
14 |
import org.apache.commons.lang.StringUtils; |
|
15 |
import org.apache.commons.lang.math.NumberUtils; |
|
16 |
import org.apache.commons.logging.Log; |
|
17 |
import org.apache.commons.logging.LogFactory; |
|
18 |
import org.dom4j.Document; |
|
19 |
import org.dom4j.Node; |
|
20 |
import org.dom4j.io.SAXReader; |
|
21 |
import org.springframework.beans.factory.annotation.Required; |
|
22 |
import org.springframework.core.io.ClassPathResource; |
|
23 |
|
|
24 |
import com.google.common.base.Function; |
|
25 |
import com.google.common.collect.Lists; |
|
26 |
import com.google.common.collect.Maps; |
|
27 |
import com.google.common.collect.Sets; |
|
28 |
|
|
29 |
import eu.dnetlib.data.collector.rmi.CollectorService; |
|
30 |
import eu.dnetlib.data.collector.rmi.ProtocolDescriptor; |
|
31 |
import eu.dnetlib.datasource.common.utils.DefaultDatasourceUpdater; |
|
32 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException; |
|
33 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; |
|
34 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
35 |
import eu.dnetlib.functionality.modular.ui.repositories.objects.RepoEntry; |
|
36 |
import eu.dnetlib.functionality.modular.ui.repositories.objects.RepoInterfaceEntry; |
|
37 |
import eu.dnetlib.functionality.modular.ui.repositories.objects.RepoMapEntry; |
|
38 |
import eu.dnetlib.functionality.modular.ui.repositories.objects.RepoMetaWfEntry; |
|
39 |
import eu.dnetlib.functionality.modular.ui.repositories.objects.SimpleParamEntry; |
|
40 |
import eu.dnetlib.functionality.modular.ui.repositories.objects.SimpleRepoInterfaceEntry; |
|
41 |
import eu.dnetlib.msro.workflows.util.WorkflowsConstants.WorkflowStatus; |
|
42 |
|
|
43 |
public class RepoUIUtils { |
|
44 |
|
|
45 |
@Resource |
|
46 |
private UniqueServiceLocator serviceLocator; |
|
47 |
|
|
48 |
private ClassPathResource browseRepoApisQueryTmpl = new ClassPathResource( |
|
49 |
"/eu/dnetlib/functionality/modular/ui/repositories/templates/browseRepoApis.xquery.st"); |
|
50 |
|
|
51 |
private ClassPathResource getRepoApiQueryTmpl = new ClassPathResource("/eu/dnetlib/functionality/modular/ui/repositories/templates/getRepoApi.xquery.st"); |
|
52 |
|
|
53 |
private ClassPathResource findRepoApisQueryTmpl = new ClassPathResource( |
|
54 |
"/eu/dnetlib/functionality/modular/ui/repositories/templates/findRepoApis.xquery.st"); |
|
55 |
|
|
56 |
private ClassPathResource findReposQueryTmpl = new ClassPathResource("/eu/dnetlib/functionality/modular/ui/repositories/templates/findRepos.xquery.st"); |
|
57 |
|
|
58 |
private ClassPathResource findReposMapQuery = new ClassPathResource("/eu/dnetlib/functionality/modular/ui/repositories/templates/findReposMap.xquery"); |
|
59 |
|
|
60 |
private static final Log log = LogFactory.getLog(RepoUIUtils.class); |
|
61 |
|
|
62 |
private String browseFieldsJson; |
|
63 |
|
|
64 |
private Map<String, List<String>> parametersMap = Maps.newHashMap(); |
|
65 |
|
|
66 |
public List<SimpleParamEntry> browseRepoField(final String xpath, final String vocabulary) throws Exception { |
|
67 |
final StringTemplate st = new StringTemplate(IOUtils.toString(browseRepoApisQueryTmpl.getInputStream())); |
|
68 |
st.setAttribute("xpath", xpath); |
|
69 |
|
|
70 |
final Map<String, String> voc = getVocabulary(vocabulary); |
|
71 |
|
|
72 |
final List<SimpleParamEntry> list = Lists.newArrayList(); |
|
73 |
for (String s : serviceLocator.getService(ISLookUpService.class).quickSearchProfile(st.toString())) { |
|
74 |
final String[] arr = s.split("@-@-@"); |
|
75 |
final String id = arr[0].trim(); |
|
76 |
final String count = arr[1].trim(); |
|
77 |
list.add(new SimpleParamEntry(id, findLabel(id, voc), count)); |
|
78 |
} |
|
79 |
|
|
80 |
return list; |
|
81 |
} |
|
82 |
|
|
83 |
public List<SimpleRepoInterfaceEntry> listApis(final String param, final String value, final String xpath) throws Exception { |
|
84 |
final StringTemplate st = new StringTemplate(); |
|
85 |
if (param.equalsIgnoreCase("__search__")) { |
|
86 |
st.setTemplate(IOUtils.toString(findRepoApisQueryTmpl.getInputStream())); |
|
87 |
st.setAttribute("cond", "contains(../..//(*|@*)/lower-case(.), '" + StringEscapeUtils.escapeXml(value.toLowerCase()) + "')"); |
|
88 |
} else { |
|
89 |
st.setTemplate(IOUtils.toString(findRepoApisQueryTmpl.getInputStream())); |
|
90 |
st.setAttribute("cond", xpath + "='" + StringEscapeUtils.escapeXml(value) + "'"); |
|
91 |
} |
|
92 |
|
|
93 |
final String query = st.toString(); |
|
94 |
|
|
95 |
final SAXReader reader = new SAXReader(); |
|
96 |
|
|
97 |
final List<SimpleRepoInterfaceEntry> list = Lists.transform(serviceLocator.getService(ISLookUpService.class).quickSearchProfile(query), |
|
98 |
new Function<String, SimpleRepoInterfaceEntry>() { |
|
99 |
|
|
100 |
@Override |
|
101 |
public SimpleRepoInterfaceEntry apply(final String s) { |
|
102 |
final SimpleRepoInterfaceEntry iface = new SimpleRepoInterfaceEntry(); |
|
103 |
try { |
|
104 |
final Document doc = reader.read(new StringReader(s)); |
|
105 |
final String country = doc.valueOf("//REPO/@country"); |
|
106 |
|
|
107 |
iface.setRepoId(doc.valueOf("//REPO/@id")); |
|
108 |
iface.setRepoCountry(StringUtils.isEmpty(country) ? "-" : country.toUpperCase()); |
|
109 |
iface.setRepoName(doc.valueOf("//REPO/@name")); |
|
110 |
iface.setRepoPrefix(doc.valueOf("//REPO/@prefix")); |
|
111 |
|
|
112 |
final Node ifcNode = doc.selectSingleNode("//INTERFACE"); |
|
113 |
|
|
114 |
iface.setId(ifcNode.valueOf("./@id")); |
|
115 |
iface.setActive(Boolean.valueOf(ifcNode.valueOf("./@active"))); |
|
116 |
iface.setProtocol(ifcNode.valueOf("./ACCESS_PROTOCOL/text()")); |
|
117 |
|
|
118 |
final String overCompliance = ifcNode.valueOf("./INTERFACE_EXTRA_FIELD[@name='overriding_compliance']"); |
|
119 |
if (StringUtils.isEmpty(overCompliance)) { |
|
120 |
iface.setCompliance(ifcNode.valueOf("@compliance")); |
|
121 |
} else { |
|
122 |
iface.setCompliance(overCompliance); |
|
123 |
} |
|
124 |
|
|
125 |
final String lastAggregationDate = ifcNode.valueOf("./INTERFACE_EXTRA_FIELD[@name='last_aggregation_date']"); |
|
126 |
if (!StringUtils.isEmpty(lastAggregationDate)) { |
|
127 |
iface.setAggrDate(lastAggregationDate); |
|
128 |
} else { |
|
129 |
final String lastDownloadDate = ifcNode.valueOf("./INTERFACE_EXTRA_FIELD[@name='last_download_date']"); |
|
130 |
if (!StringUtils.isEmpty(lastDownloadDate)) { |
|
131 |
iface.setAggrDate(lastDownloadDate); |
|
132 |
} |
|
133 |
} |
|
134 |
final String lastAggregationTotal = ifcNode.valueOf("./INTERFACE_EXTRA_FIELD[@name='last_aggregation_total']"); |
|
135 |
if (StringUtils.isEmpty(lastAggregationTotal)) { |
|
136 |
final String lastDownloadTotal = ifcNode.valueOf("./INTERFACE_EXTRA_FIELD[@name='last_download_total']"); |
|
137 |
if (StringUtils.isEmpty(lastDownloadTotal)) { |
|
138 |
iface.setAggrTotal(0); |
|
139 |
} else { |
|
140 |
iface.setAggrTotal(NumberUtils.toInt(lastDownloadTotal, 0)); |
|
141 |
} |
|
142 |
} else { |
|
143 |
iface.setAggrTotal(NumberUtils.toInt(lastAggregationTotal, 0)); |
|
144 |
} |
|
145 |
} catch (Exception e) { |
|
146 |
log.error(e); |
|
147 |
} |
|
148 |
return iface; |
|
149 |
} |
|
150 |
}); |
|
151 |
return list; |
|
152 |
} |
|
153 |
|
|
154 |
public RepoInterfaceEntry getApi(final String repoId, final String ifaceId) throws Exception { |
|
155 |
final RepoInterfaceEntry ifc = new RepoInterfaceEntry(); |
|
156 |
|
|
157 |
final StringTemplate st = new StringTemplate(IOUtils.toString(getRepoApiQueryTmpl.getInputStream())); |
|
158 |
st.setAttribute("dsId", repoId); |
|
159 |
st.setAttribute("ifaceId", ifaceId); |
|
160 |
|
|
161 |
final String query = st.toString(); |
|
162 |
|
|
163 |
final SAXReader reader = new SAXReader(); |
|
164 |
|
|
165 |
final String s = serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(query); |
|
166 |
|
|
167 |
final Document doc = reader.read(new StringReader(s)); |
|
168 |
|
|
169 |
ifc.setId(doc.valueOf("/api/id")); |
|
170 |
ifc.setLabel(doc.valueOf("/api/label")); |
|
171 |
ifc.setRepoId(doc.valueOf("/api/repo/@id")); |
|
172 |
ifc.setRepoName(doc.valueOf("/api/repo/text()")); |
|
173 |
ifc.setRepoCountry(doc.valueOf("/api/repo/@country")); |
|
174 |
ifc.setRepoPrefix(doc.valueOf("/api/repo/@prefix")); |
|
175 |
|
|
176 |
final String protocol = doc.valueOf("/api/protocol"); |
|
177 |
ifc.setProtocol(protocol); |
|
178 |
|
|
179 |
final Set<String> toVerifyParams = getParameterNamesForProtocol(ifc.getProtocol()); |
|
180 |
for (Object o : doc.selectNodes("/api/commonParams/param")) { |
|
181 |
final Node n = (Node) o; |
|
182 |
ifc.getCommonParams().add(new SimpleParamEntry(n.valueOf("@name"), n.getText())); |
|
183 |
} |
|
184 |
|
|
185 |
log.debug("****** " + toVerifyParams); |
|
186 |
for (Object o : doc.selectNodes("/api/accessParams/param")) { |
|
187 |
final Node n = (Node) o; |
|
188 |
final String pname = n.valueOf("@name"); |
|
189 |
if (toVerifyParams.contains(pname)) { |
|
190 |
ifc.getAccessParams().add(new SimpleParamEntry(pname, n.getText())); |
|
191 |
toVerifyParams.remove(pname); |
|
192 |
} else { |
|
193 |
log.warn("Invalid param [" + pname + "] for protocol " + protocol + " in repo " + repoId); |
|
194 |
} |
|
195 |
} |
|
196 |
for (String pname : toVerifyParams) { |
|
197 |
ifc.getAccessParams().add(new SimpleParamEntry(pname, "")); |
|
198 |
log.info("Adding missing param [" + pname + "] for protocol " + protocol + " in repo " + repoId); |
|
199 |
} |
|
200 |
|
|
201 |
for (Object o : doc.selectNodes("/api/extraFields/field")) { |
|
202 |
final Node n = (Node) o; |
|
203 |
final String name = n.valueOf("@name"); |
|
204 |
final String value = n.getText(); |
|
205 |
if (name.equalsIgnoreCase(DefaultDatasourceUpdater.OVERRIDING_COMPLIANCE_FIELD)) { |
|
206 |
for (SimpleParamEntry e : ifc.getCommonParams()) { |
|
207 |
if (e.getName().equals("compliance")) { |
|
208 |
// The original compliance (assigned by the validator) is stored in otherValue |
|
209 |
e.setOtherValue(e.getValue()); |
|
210 |
e.setValue(value); |
|
211 |
} |
|
212 |
} |
|
213 |
} else if (name.equalsIgnoreCase("last_aggregation_date")) { |
|
214 |
ifc.setAggrDate(value); |
|
215 |
} else if (name.equalsIgnoreCase("last_aggregation_total")) { |
|
216 |
ifc.setAggrTotal(NumberUtils.toInt(value, 0)); |
|
217 |
} else if (name.equalsIgnoreCase("last_aggregation_mdId")) { |
|
218 |
ifc.setAggrMdId(value); |
|
219 |
} else if (name.equalsIgnoreCase("last_collection_date")) { |
|
220 |
ifc.setCollDate(value); |
|
221 |
} else if (name.equalsIgnoreCase("last_collection_total")) { |
|
222 |
ifc.setCollTotal(NumberUtils.toInt(value, 0)); |
|
223 |
} else if (name.equalsIgnoreCase("last_collection_mdId")) { |
|
224 |
ifc.setCollMdId(value); |
|
225 |
} else if (name.equalsIgnoreCase("last_download_date")) { |
|
226 |
ifc.setDownloadDate(value); |
|
227 |
} else if (name.equalsIgnoreCase("last_download_total")) { |
|
228 |
ifc.setDownloadTotal(NumberUtils.toInt(value, 0)); |
|
229 |
} else if (name.equalsIgnoreCase("last_download_objId")) { |
|
230 |
ifc.setDownloadObjId(value); |
|
231 |
} else { |
|
232 |
ifc.getOtherParams().add(new SimpleParamEntry(name, value)); |
|
233 |
} |
|
234 |
} |
|
235 |
|
|
236 |
for (Object o : doc.selectNodes("//metaWF")) { |
|
237 |
final Node n = (Node) o; |
|
238 |
|
|
239 |
final String id = n.valueOf("./id"); |
|
240 |
final String name = n.valueOf("./name"); |
|
241 |
final String status = n.valueOf("./status"); |
|
242 |
final String repoByeWfId = n.valueOf("./destroyWorkflow"); |
|
243 |
|
|
244 |
int progress = 0; |
|
245 |
try { |
|
246 |
switch (WorkflowStatus.valueOf(status)) { |
|
247 |
case MISSING: |
|
248 |
progress = 0; |
|
249 |
break; |
|
250 |
case ASSIGNED: |
|
251 |
progress = 25; |
|
252 |
break; |
|
253 |
case WAIT_SYS_SETTINGS: |
|
254 |
progress = 50; |
|
255 |
break; |
|
256 |
case WAIT_USER_SETTINGS: |
|
257 |
progress = 75; |
|
258 |
break; |
|
259 |
case EXECUTABLE: |
|
260 |
progress = 100; |
|
261 |
break; |
|
262 |
} |
|
263 |
} catch (Exception e) { |
|
264 |
progress = 0; |
|
265 |
} |
|
266 |
ifc.getMetaWFs().add(new RepoMetaWfEntry(id, name, status, repoByeWfId, progress)); |
|
267 |
} |
|
268 |
|
|
269 |
return ifc; |
|
270 |
} |
|
271 |
|
|
272 |
public List<RepoEntry> listRepositories(final String type) throws Exception { |
|
273 |
final List<RepoEntry> list = Lists.newArrayList(); |
|
274 |
|
|
275 |
final StringTemplate st = new StringTemplate(IOUtils.toString(findReposQueryTmpl.getInputStream())); |
|
276 |
st.setAttribute("type", type); |
|
277 |
|
|
278 |
for (String s : serviceLocator.getService(ISLookUpService.class).quickSearchProfile(st.toString())) { |
|
279 |
final RepoEntry r = new RepoEntry(); |
|
280 |
final String[] arr = s.split("@=@"); |
|
281 |
r.setId(arr[0].trim()); |
|
282 |
r.setName(arr[1].trim()); |
|
283 |
r.setValid("true".equals(arr[2].trim())); |
|
284 |
list.add(r); |
|
285 |
} |
|
286 |
|
|
287 |
Collections.sort(list); |
|
288 |
|
|
289 |
return list; |
|
290 |
} |
|
291 |
|
|
292 |
public List<RepoMapEntry> listRepositories_asMap() throws Exception { |
|
293 |
final SAXReader reader = new SAXReader(); |
|
294 |
|
|
295 |
final String query = IOUtils.toString(findReposMapQuery.getInputStream()); |
|
296 |
final List<RepoMapEntry> list = Lists.transform(serviceLocator.getService(ISLookUpService.class).quickSearchProfile(query), |
|
297 |
new Function<String, RepoMapEntry>() { |
|
298 |
|
|
299 |
@Override |
|
300 |
public RepoMapEntry apply(final String s) { |
|
301 |
final RepoMapEntry r = new RepoMapEntry(); |
|
302 |
|
|
303 |
try { |
|
304 |
final Document doc = reader.read(new StringReader(s)); |
|
305 |
r.setId(doc.valueOf("//dsId")); |
|
306 |
r.setName(doc.valueOf("//name")); |
|
307 |
r.setTot(Integer.parseInt(doc.valueOf("//size"))); |
|
308 |
r.setLat(Float.parseFloat(doc.valueOf("//lat"))); |
|
309 |
r.setLng(Float.parseFloat(doc.valueOf("//lng"))); |
|
310 |
} catch (Exception e) { |
|
311 |
log.error(e); |
|
312 |
} |
|
313 |
return r; |
|
314 |
} |
|
315 |
}); |
|
316 |
|
|
317 |
return list; |
|
318 |
} |
|
319 |
|
|
320 |
private String findLabel(final String id, final Map<String, String> vocabulary) { |
|
321 |
if (vocabulary.containsKey(id)) { |
|
322 |
return vocabulary.get(id); |
|
323 |
} else { |
|
324 |
return id; |
|
325 |
} |
|
326 |
} |
|
327 |
|
|
328 |
private Map<String, String> getVocabulary(final String vocabulary) throws ISLookUpException { |
|
329 |
final String query = "for $x in collection('/db/DRIVER/VocabularyDSResources/VocabularyDSResourceType')[.//VOCABULARY_NAME/@code = '" + vocabulary |
|
330 |
+ "']//TERM return concat($x/@code, ' @-@-@ ', $x/@english_name)"; |
|
331 |
|
|
332 |
final Map<String, String> map = Maps.newHashMap(); |
|
333 |
for (String s : serviceLocator.getService(ISLookUpService.class).quickSearchProfile(query)) { |
|
334 |
String[] arr = s.split("@-@-@"); |
|
335 |
map.put(arr[0].trim(), arr[1].trim()); |
|
336 |
} |
|
337 |
|
|
338 |
return map; |
|
339 |
} |
|
340 |
|
|
341 |
private Set<String> getParameterNamesForProtocol(final String protocol) { |
|
342 |
if (parametersMap.isEmpty()) { |
|
343 |
for (ProtocolDescriptor d : serviceLocator.getService(CollectorService.class).listProtocols()) { |
|
344 |
parametersMap.put(d.getName().toLowerCase(), d.getParams()); |
|
345 |
} |
|
346 |
} |
|
347 |
final Set<String> res = Sets.newHashSet(); |
|
348 |
if (parametersMap.containsKey(protocol.toLowerCase())) { |
|
349 |
res.add("baseUrl"); |
|
350 |
res.addAll(parametersMap.get(protocol.toLowerCase())); |
|
351 |
} |
|
352 |
|
|
353 |
return res; |
|
354 |
} |
|
355 |
|
|
356 |
public String getBrowseFieldsJson() { |
|
357 |
return browseFieldsJson; |
|
358 |
} |
|
359 |
|
|
360 |
@Required |
|
361 |
public void setBrowseFieldsJson(final String browseFieldsJson) { |
|
362 |
this.browseFieldsJson = browseFieldsJson; |
|
363 |
} |
|
364 |
|
|
365 |
} |
modules/dnet-modular-repositories-ui/tags/dnet-modular-repositories-ui-3.0.2/src/main/java/eu/dnetlib/functionality/modular/ui/repositories/RepoInternalController.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.modular.ui.repositories; |
|
2 |
|
|
3 |
import java.io.StringReader; |
|
4 |
import java.util.List; |
|
5 |
import java.util.Map; |
|
6 |
|
|
7 |
import javax.annotation.Resource; |
|
8 |
import javax.servlet.http.HttpServletResponse; |
|
9 |
|
|
10 |
import net.sf.ehcache.Cache; |
|
11 |
import net.sf.ehcache.Element; |
|
12 |
|
|
13 |
import org.apache.commons.io.IOUtils; |
|
14 |
import org.apache.commons.lang.StringUtils; |
|
15 |
import org.apache.commons.logging.Log; |
|
16 |
import org.apache.commons.logging.LogFactory; |
|
17 |
import org.springframework.stereotype.Controller; |
|
18 |
import org.springframework.ui.ModelMap; |
|
19 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
20 |
import org.springframework.web.bind.annotation.RequestParam; |
|
21 |
import org.springframework.web.bind.annotation.ResponseBody; |
|
22 |
|
|
23 |
import com.google.common.collect.Maps; |
|
24 |
import com.google.gson.Gson; |
|
25 |
|
|
26 |
import eu.dnetlib.datasource.common.utils.DatasourceUpdater; |
|
27 |
import eu.dnetlib.enabling.datasources.rmi.DatasourceManagerService; |
|
28 |
import eu.dnetlib.enabling.datasources.rmi.DatasourceManagerServiceException; |
|
29 |
import eu.dnetlib.enabling.datasources.rmi.IfaceDesc; |
|
30 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; |
|
31 |
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService; |
|
32 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
33 |
import eu.dnetlib.functionality.modular.ui.repositories.objects.RepoEntry; |
|
34 |
import eu.dnetlib.functionality.modular.ui.repositories.objects.RepoInterfaceEntry; |
|
35 |
import eu.dnetlib.functionality.modular.ui.repositories.objects.RepoMapEntry; |
|
36 |
import eu.dnetlib.functionality.modular.ui.repositories.objects.SimpleParamEntry; |
|
37 |
import eu.dnetlib.functionality.modular.ui.repositories.objects.SimpleRepoInterfaceEntry; |
|
38 |
import eu.dnetlib.functionality.modular.ui.workflows.objects.sections.WorkflowSectionGrouper; |
|
39 |
import eu.dnetlib.miscutils.functional.xml.ApplyXslt; |
|
40 |
import eu.dnetlib.msro.workflows.sarasvati.loader.WorkflowExecutor; |
|
41 |
import eu.dnetlib.msro.workflows.util.WorkflowsConstants; |
|
42 |
|
|
43 |
@Controller |
|
44 |
public class RepoInternalController { |
|
45 |
|
|
46 |
@Resource |
|
47 |
private UniqueServiceLocator serviceLocator; |
|
48 |
|
|
49 |
@Resource(name = "datasourceUpdater") |
|
50 |
private DatasourceUpdater datasourceUpdater; |
|
51 |
|
|
52 |
@Resource |
|
53 |
private WorkflowSectionGrouper workflowSectionGrouper; |
|
54 |
|
|
55 |
@Resource |
|
56 |
private WorkflowExecutor workflowExecutor; |
|
57 |
|
|
58 |
@Resource |
|
59 |
private RepoUIUtils repoUIUtils; |
|
60 |
|
|
61 |
@Resource(name = "repoUIJsonCache") |
|
62 |
private Cache repoUIJsonCache; |
|
63 |
|
|
64 |
private static final Log log = LogFactory.getLog(RepoInternalController.class); |
|
65 |
|
|
66 |
@RequestMapping(value = "/ui/browseRepoField.do") |
|
67 |
public @ResponseBody |
|
68 |
List<SimpleParamEntry> browseRepoField(@RequestParam(value = "xpath", required = true) final String xpath, |
|
69 |
@RequestParam(value = "vocabulary", required = true) final String vocabulary) throws Exception { |
|
70 |
return repoUIUtils.browseRepoField(xpath, vocabulary); |
|
71 |
} |
|
72 |
|
|
73 |
@SuppressWarnings("unchecked") |
|
74 |
@RequestMapping(value = "/ui/listApis.do") |
|
75 |
public @ResponseBody |
|
76 |
List<SimpleRepoInterfaceEntry> listApis( |
|
77 |
@RequestParam(value = "param", required = true) final String param, |
|
78 |
@RequestParam(value = "value", required = true) final String value, |
|
79 |
@RequestParam(value = "xpath", required = true) final String xpath, |
|
80 |
@RequestParam(value = "refresh", required = false) final String refresh) throws Exception { |
|
81 |
|
|
82 |
final String cacheKey = "list@@@" + param + "@@@" + value; |
|
83 |
|
|
84 |
final Element elem = repoUIJsonCache.get(cacheKey); |
|
85 |
|
|
86 |
if (elem != null && refresh == null) { |
|
87 |
return (List<SimpleRepoInterfaceEntry>) elem.getObjectValue(); |
|
88 |
} else { |
|
89 |
log.info("Refreshing " + cacheKey + " cache..."); |
|
90 |
final List<SimpleRepoInterfaceEntry> list = repoUIUtils.listApis(param, value, xpath); |
|
91 |
repoUIJsonCache.put(new Element(cacheKey, list)); |
|
92 |
return list; |
|
93 |
} |
|
94 |
} |
|
95 |
|
|
96 |
@RequestMapping(value = "/ui/listRepositories.map") |
|
97 |
public @ResponseBody |
|
98 |
List<RepoMapEntry> listRepositories_asMap() throws Exception { |
|
99 |
return repoUIUtils.listRepositories_asMap(); |
|
100 |
} |
|
101 |
|
|
102 |
@RequestMapping(value = "/ui/listRepositories.json") |
|
103 |
public @ResponseBody |
|
104 |
List<RepoEntry> listRepositories(@RequestParam(value = "type", required = true) final String type) throws Exception { |
|
105 |
return repoUIUtils.listRepositories(type); |
|
106 |
} |
|
107 |
|
|
108 |
@RequestMapping(value = "/ui/validateRepo.do") |
|
109 |
public @ResponseBody |
|
110 |
String listRepositories(@RequestParam(value = "id", required = true) final String id, |
|
111 |
@RequestParam(value = "b", required = true) final boolean b) throws Exception { |
|
112 |
|
|
113 |
final String query = "count(/*[.//RESOURCE_TYPE/@value='MetaWorkflowDSResourceType' and .//DATAPROVIDER/@id='" + id + "'])"; |
|
114 |
if (!b && Integer.parseInt(serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(query)) > 0) { throw new Exception("Repo " + id |
|
115 |
+ " can be invalidated: it is related to some metawfs"); } |
|
116 |
|
|
117 |
final String newId = b ? |
|
118 |
serviceLocator.getService(ISRegistryService.class).validateProfile(id) : |
|
119 |
serviceLocator.getService(ISRegistryService.class).invalidateProfile(id); |
|
120 |
|
|
121 |
repoUIJsonCache.removeAll(); |
|
122 |
|
|
123 |
return newId; |
|
124 |
} |
|
125 |
|
|
126 |
@RequestMapping(value = "/ui/getRepoDetails.do") |
|
127 |
public void getRepoDetails(final HttpServletResponse response, @RequestParam(value = "id", required = true) final String id) throws Exception { |
|
128 |
final String profile = serviceLocator.getService(ISLookUpService.class).getResourceProfile(id); |
|
129 |
|
|
130 |
final ApplyXslt xslt = new ApplyXslt(IOUtils.toString(getClass().getResourceAsStream( |
|
131 |
"/eu/dnetlib/functionality/modular/ui/repositories/xslt/repoDetails.xslt"))); |
|
132 |
|
|
133 |
IOUtils.copy(new StringReader(xslt.evaluate(profile)), response.getOutputStream()); |
|
134 |
} |
|
135 |
|
|
136 |
@RequestMapping("/ui/repoMetaWf.new") |
|
137 |
public @ResponseBody |
|
138 |
String newDataProviderWorkflow(@RequestParam(value = "id", required = true) final String repoId, |
|
139 |
@RequestParam(value = "name", required = true) final String repoName, |
|
140 |
@RequestParam(value = "iface", required = true) final String ifaceId, |
|
141 |
@RequestParam(value = "wf", required = true) final String wfId) throws Exception { |
|
142 |
|
|
143 |
final Map<String, Object> params = Maps.newHashMap(); |
|
144 |
params.put(WorkflowsConstants.DATAPROVIDER_ID, repoId); |
|
145 |
params.put(WorkflowsConstants.DATAPROVIDER_NAME, repoName); |
|
146 |
params.put(WorkflowsConstants.DATAPROVIDER_INTERFACE, ifaceId); |
|
147 |
|
|
148 |
return workflowExecutor.startProcess(wfId, params); |
|
149 |
} |
|
150 |
|
|
151 |
@RequestMapping("/ui/repoMetaWf.destroy") |
|
152 |
public @ResponseBody |
|
153 |
String destroyDataProviderWorkflow(@RequestParam(value = "destroyWf", required = true) final String destroyWfId) |
|
154 |
throws Exception { |
|
155 |
return workflowExecutor.startProcess(destroyWfId, null); |
|
156 |
} |
|
157 |
|
|
158 |
@RequestMapping("/ui/repoApi.get") |
|
159 |
public @ResponseBody |
|
160 |
RepoInterfaceEntry getRepoApi(@RequestParam(value = "repoId", required = true) final String repoId, |
|
161 |
@RequestParam(value = "ifaceId", required = true) final String ifaceId) throws Exception { |
|
162 |
return repoUIUtils.getApi(repoId, ifaceId); |
|
163 |
} |
|
164 |
|
|
165 |
@SuppressWarnings("unchecked") |
|
166 |
@RequestMapping("/ui/repoApi.update") |
|
167 |
public @ResponseBody |
|
168 |
boolean updateRepoApi( |
|
169 |
@RequestParam(value = "id", required = true) final String repoId, |
|
170 |
@RequestParam(value = "iface", required = true) final String ifaceId, |
|
171 |
@RequestParam(value = "accessParams", required = true) final String accessParamsJson) throws Exception { |
|
172 |
if (!StringUtils.isEmpty(accessParamsJson)) { |
|
173 |
datasourceUpdater.updateApiAccessParams(repoId, ifaceId, new Gson().fromJson(accessParamsJson, Map.class)); |
|
174 |
} |
|
175 |
return true; |
|
176 |
} |
|
177 |
|
|
178 |
@RequestMapping("/ui/repoApiCompliance.update") |
|
179 |
public @ResponseBody |
|
180 |
boolean updateRepoApiCompliance(@RequestParam(value = "id", required = true) final String repoId, |
|
181 |
@RequestParam(value = "iface", required = true) final String ifaceId, |
|
182 |
@RequestParam(value = "compliance", required = true) final String compliance) throws Exception { |
|
183 |
|
|
184 |
log.debug("SET COMPLIANCE TO " + compliance); |
|
185 |
|
|
186 |
datasourceUpdater.overrideCompliance(repoId, ifaceId, compliance); |
|
187 |
|
|
188 |
repoUIJsonCache.removeAll(); |
|
189 |
|
|
190 |
return true; |
|
191 |
} |
|
192 |
|
|
193 |
@RequestMapping("/ui/repoApiCompliance.reset") |
|
194 |
public @ResponseBody |
|
195 |
boolean resetRepoApiCompliance(@RequestParam(value = "id", required = true) final String repoId, |
|
196 |
@RequestParam(value = "iface", required = true) final String ifaceId) throws Exception { |
|
197 |
|
|
198 |
log.debug("RESET COMPLIANCE"); |
|
199 |
|
|
200 |
datasourceUpdater.overrideCompliance(repoId, ifaceId, null); |
|
201 |
|
|
202 |
repoUIJsonCache.removeAll(); |
|
203 |
|
|
204 |
return true; |
|
205 |
} |
|
206 |
|
|
207 |
@RequestMapping("/ui/repos/repoApi.html") |
|
208 |
public void resetRepoApiCompliance(final ModelMap map) throws Exception {} |
|
209 |
|
|
210 |
@RequestMapping("/ui/repoApi.new") |
|
211 |
public @ResponseBody |
|
212 |
boolean addRepoApi(@RequestParam(value = "repoId", required = true) final String repoId, |
|
213 |
@RequestParam(value = "iface", required = true) final IfaceDesc iface) throws DatasourceManagerServiceException { |
|
214 |
final DatasourceManagerService dsManager = serviceLocator.getService(DatasourceManagerService.class); |
|
215 |
return dsManager.addInterface(repoId, iface); |
|
216 |
} |
|
217 |
} |
modules/dnet-modular-repositories-ui/tags/dnet-modular-repositories-ui-3.0.2/src/main/java/eu/dnetlib/functionality/modular/ui/repositories/AddRepoApiEntryPointController.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.modular.ui.repositories; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.Collections; |
|
5 |
import java.util.List; |
|
6 |
import java.util.Map; |
|
7 |
|
|
8 |
import javax.annotation.Resource; |
|
9 |
import javax.servlet.http.HttpServletRequest; |
|
10 |
import javax.servlet.http.HttpServletResponse; |
|
11 |
|
|
12 |
import org.springframework.beans.factory.annotation.Required; |
|
13 |
import org.springframework.ui.ModelMap; |
|
14 |
|
|
15 |
import com.google.common.base.Function; |
|
16 |
import com.google.common.collect.Lists; |
|
17 |
import com.google.common.collect.Maps; |
|
18 |
import com.google.gson.Gson; |
|
19 |
|
|
20 |
import eu.dnetlib.data.collector.rmi.CollectorService; |
|
21 |
import eu.dnetlib.data.collector.rmi.ProtocolDescriptor; |
|
22 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException; |
|
23 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; |
|
24 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
25 |
import eu.dnetlib.functionality.modular.ui.ModuleEntryPoint; |
|
26 |
import eu.dnetlib.functionality.modular.ui.repositories.objects.VocabularyEntry; |
|
27 |
|
|
28 |
public class AddRepoApiEntryPointController extends ModuleEntryPoint { |
|
29 |
|
|
30 |
private String datasourceTypeVocabulary; |
|
31 |
private String complianceVocabulary; |
|
32 |
private String contentDescriptionsVocabulary; |
|
33 |
private String protocolsVocabulary; |
|
34 |
|
|
35 |
@Resource |
|
36 |
private UniqueServiceLocator serviceLocator; |
|
37 |
|
|
38 |
@Override |
|
39 |
protected void initialize(final ModelMap map, final HttpServletRequest request, final HttpServletResponse response) throws Exception { |
|
40 |
final Gson gson = new Gson(); |
|
41 |
map.addAttribute("types", gson.toJson(fetchVocabularyTerms(datasourceTypeVocabulary))); |
|
42 |
map.addAttribute("compliances", gson.toJson(fetchVocabularyTerms(complianceVocabulary))); |
|
43 |
map.addAttribute("contentDescriptions", gson.toJson(fetchVocabularyTerms(contentDescriptionsVocabulary))); |
|
44 |
map.addAttribute("protocols", gson.toJson(listProtocols())); |
|
45 |
} |
|
46 |
|
|
47 |
private List<ProtocolDescriptor> listProtocols() throws ISLookUpException { |
|
48 |
final Map<String, List<String>> mapParams = Maps.newHashMap(); |
|
49 |
for (ProtocolDescriptor pd : serviceLocator.getService(CollectorService.class).listProtocols()) { |
|
50 |
mapParams.put(pd.getName().trim().toLowerCase(), pd.getParams()); |
|
51 |
} |
|
52 |
|
|
53 |
return Lists.transform(fetchVocabularyTerms(protocolsVocabulary), new Function<VocabularyEntry, ProtocolDescriptor>() { |
|
54 |
|
|
55 |
@Override |
|
56 |
public ProtocolDescriptor apply(final VocabularyEntry e) { |
|
57 |
final ProtocolDescriptor pd = new ProtocolDescriptor(); |
|
58 |
pd.setName(e.getId()); |
|
59 |
if (mapParams.containsKey(e.getId().toLowerCase().trim())) { |
|
60 |
pd.setParams(mapParams.get(e.getId().toLowerCase().trim())); |
|
61 |
} else { |
|
62 |
pd.setParams(new ArrayList<String>()); |
|
63 |
} |
|
64 |
return pd; |
|
65 |
} |
|
66 |
|
|
67 |
}); |
|
68 |
} |
|
69 |
|
|
70 |
private List<VocabularyEntry> fetchVocabularyTerms(final String voc) throws ISLookUpException { |
|
71 |
final String xquery = "for $x in collection('/db/DRIVER/VocabularyDSResources/VocabularyDSResourceType')[.//VOCABULARY_NAME/@code = '" |
|
72 |
+ voc.trim() + "']//TERM return concat($x/@code, ' @@@ ', $x/@english_name)"; |
|
73 |
|
|
74 |
final List<VocabularyEntry> list = Lists.newArrayList(); |
|
75 |
for (String s : serviceLocator.getService(ISLookUpService.class).quickSearchProfile(xquery)) { |
|
76 |
final String[] arr = s.split("@@@"); |
|
77 |
list.add(new VocabularyEntry(arr[0].trim(), arr[1].trim())); |
|
78 |
} |
|
79 |
Collections.sort(list); |
|
80 |
|
|
81 |
return list; |
|
82 |
} |
|
83 |
|
|
84 |
public String getDatasourceTypeVocabulary() { |
|
85 |
return datasourceTypeVocabulary; |
|
86 |
} |
|
87 |
|
|
88 |
@Required |
|
89 |
public void setDatasourceTypeVocabulary(final String datasourceTypeVocabulary) { |
|
90 |
this.datasourceTypeVocabulary = datasourceTypeVocabulary; |
|
91 |
} |
|
92 |
|
|
93 |
public String getComplianceVocabulary() { |
|
94 |
return complianceVocabulary; |
|
95 |
} |
|
96 |
|
|
97 |
@Required |
|
98 |
public void setComplianceVocabulary(final String complianceVocabulary) { |
|
99 |
this.complianceVocabulary = complianceVocabulary; |
|
100 |
} |
|
101 |
|
|
102 |
public String getContentDescriptionsVocabulary() { |
|
103 |
return contentDescriptionsVocabulary; |
|
104 |
} |
|
105 |
|
|
106 |
@Required |
|
107 |
public void setContentDescriptionsVocabulary(final String contentDescriptionsVocabulary) { |
|
108 |
this.contentDescriptionsVocabulary = contentDescriptionsVocabulary; |
|
109 |
} |
|
110 |
|
|
111 |
public String getProtocolsVocabulary() { |
|
112 |
return protocolsVocabulary; |
|
113 |
} |
|
114 |
|
|
115 |
@Required |
|
116 |
public void setProtocolsVocabulary(final String protocolsVocabulary) { |
|
117 |
this.protocolsVocabulary = protocolsVocabulary; |
|
118 |
} |
|
119 |
|
|
120 |
} |
modules/dnet-modular-repositories-ui/tags/dnet-modular-repositories-ui-3.0.2/src/main/java/eu/dnetlib/functionality/modular/ui/repositories/objects/SimpleRepoInterfaceEntry.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.modular.ui.repositories.objects; |
|
2 |
|
|
3 |
public class SimpleRepoInterfaceEntry implements Comparable<SimpleRepoInterfaceEntry> { |
|
4 |
|
|
5 |
private String id; |
|
6 |
private String compliance; |
|
7 |
private String protocol; |
|
8 |
private boolean active; |
|
9 |
private String repoId = "unknown"; |
|
10 |
private String repoName = "unknown"; |
|
11 |
private String repoCountry = "-"; |
|
12 |
private String repoPrefix = ""; |
|
13 |
private String aggrDate = ""; |
|
14 |
private int aggrTotal = 0; |
|
15 |
|
|
16 |
public String getId() { |
|
17 |
return id; |
|
18 |
} |
|
19 |
|
|
20 |
public void setId(final String id) { |
|
21 |
this.id = id; |
|
22 |
} |
|
23 |
|
|
24 |
public String getCompliance() { |
|
25 |
return compliance; |
|
26 |
} |
|
27 |
|
|
28 |
public void setCompliance(final String compliance) { |
|
29 |
this.compliance = compliance; |
|
30 |
} |
|
31 |
|
|
32 |
public boolean isActive() { |
|
33 |
return active; |
|
34 |
} |
|
35 |
|
|
36 |
public void setActive(final boolean active) { |
|
37 |
this.active = active; |
|
38 |
} |
|
39 |
|
|
40 |
|
|
41 |
public String getRepoId() { |
|
42 |
return repoId; |
|
43 |
} |
|
44 |
|
|
45 |
public void setRepoId(String repoId) { |
|
46 |
this.repoId = repoId; |
|
47 |
} |
|
48 |
|
|
49 |
public String getRepoName() { |
|
50 |
return repoName; |
|
51 |
} |
|
52 |
|
|
53 |
public void setRepoName(String repoName) { |
|
54 |
this.repoName = repoName; |
|
55 |
} |
|
56 |
|
|
57 |
public String getRepoCountry() { |
|
58 |
return repoCountry; |
|
59 |
} |
|
60 |
|
|
61 |
public void setRepoCountry(String repoCountry) { |
|
62 |
this.repoCountry = repoCountry; |
|
63 |
} |
|
64 |
|
|
65 |
public String getRepoPrefix() { |
|
66 |
return repoPrefix; |
|
67 |
} |
|
68 |
|
|
69 |
public void setRepoPrefix(String repoPrefix) { |
|
70 |
this.repoPrefix = repoPrefix; |
|
71 |
} |
|
72 |
|
|
73 |
@Override |
|
74 |
public int compareTo(final SimpleRepoInterfaceEntry e) { |
|
75 |
return compliance.compareTo(e.getCompliance()); |
|
76 |
} |
|
77 |
|
|
78 |
public String getAggrDate() { |
|
79 |
return aggrDate; |
|
80 |
} |
|
81 |
|
|
82 |
public void setAggrDate(String aggrDate) { |
|
83 |
this.aggrDate = aggrDate; |
|
84 |
} |
|
85 |
|
|
86 |
public int getAggrTotal() { |
|
87 |
return aggrTotal; |
|
88 |
} |
|
89 |
|
|
90 |
public void setAggrTotal(int aggrTotal) { |
|
91 |
this.aggrTotal = aggrTotal; |
|
92 |
} |
|
93 |
|
|
94 |
public String getProtocol() { |
|
95 |
return protocol; |
|
96 |
} |
|
97 |
|
|
98 |
public void setProtocol(String protocol) { |
|
99 |
this.protocol = protocol; |
|
100 |
} |
|
101 |
|
|
102 |
|
|
103 |
} |
modules/dnet-modular-repositories-ui/tags/dnet-modular-repositories-ui-3.0.2/src/main/java/eu/dnetlib/functionality/modular/ui/repositories/objects/RepoMapEntry.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.modular.ui.repositories.objects; |
|
2 |
|
|
3 |
import java.io.Serializable; |
|
4 |
|
|
5 |
public class RepoMapEntry implements Serializable { |
|
6 |
|
|
7 |
/** |
|
8 |
* |
|
9 |
*/ |
|
10 |
private static final long serialVersionUID = -2051481347934357434L; |
|
11 |
|
|
12 |
private String id; |
|
13 |
private String name; |
|
14 |
private int tot; |
|
15 |
private float lat; |
|
16 |
private float lng; |
|
17 |
|
|
18 |
public String getId() { |
|
19 |
return id; |
|
20 |
} |
|
21 |
|
|
22 |
public void setId(final String id) { |
|
23 |
this.id = id; |
|
24 |
} |
|
25 |
|
|
26 |
public String getName() { |
|
27 |
return name; |
|
28 |
} |
|
29 |
|
|
30 |
public void setName(final String name) { |
|
31 |
this.name = name; |
|
32 |
} |
|
33 |
|
|
34 |
public int getTot() { |
|
35 |
return tot; |
|
36 |
} |
|
37 |
|
|
38 |
public void setTot(final int tot) { |
|
39 |
this.tot = tot; |
|
40 |
} |
|
41 |
|
|
42 |
public float getLat() { |
|
43 |
return lat; |
|
44 |
} |
|
45 |
|
|
46 |
public void setLat(final float lat) { |
|
47 |
this.lat = lat; |
|
48 |
} |
|
49 |
|
|
50 |
public float getLng() { |
|
51 |
return lng; |
|
52 |
} |
|
53 |
|
|
54 |
public void setLng(final float lng) { |
|
55 |
this.lng = lng; |
|
56 |
} |
|
57 |
|
|
58 |
} |
modules/dnet-modular-repositories-ui/tags/dnet-modular-repositories-ui-3.0.2/src/main/java/eu/dnetlib/functionality/modular/ui/repositories/objects/RepoEntry.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.modular.ui.repositories.objects; |
|
2 |
|
|
3 |
public class RepoEntry implements Comparable<RepoEntry> { |
|
4 |
|
|
5 |
private String id; |
|
6 |
private String name; |
|
7 |
private boolean valid ; |
|
8 |
|
|
9 |
public String getId() { |
|
10 |
return id; |
|
11 |
} |
|
12 |
|
|
13 |
public void setId(String id) { |
|
14 |
this.id = id; |
|
15 |
} |
|
16 |
|
|
17 |
public String getName() { |
|
18 |
return name; |
|
19 |
} |
|
20 |
|
|
21 |
public void setName(String name) { |
|
22 |
this.name = name; |
|
23 |
} |
|
24 |
|
|
25 |
public boolean isValid() { |
|
26 |
return valid; |
|
27 |
} |
|
28 |
|
|
29 |
public void setValid(boolean valid) { |
|
30 |
this.valid = valid; |
|
31 |
} |
|
32 |
|
|
33 |
@Override |
|
34 |
public int compareTo(RepoEntry e) { |
|
35 |
return getName().compareTo(e.getName()); |
|
36 |
} |
|
37 |
|
|
38 |
} |
modules/dnet-modular-repositories-ui/tags/dnet-modular-repositories-ui-3.0.2/src/main/java/eu/dnetlib/functionality/modular/ui/repositories/objects/RepoInterfaceEntry.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.modular.ui.repositories.objects; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
import com.google.common.collect.Lists; |
|
6 |
|
|
7 |
public class RepoInterfaceEntry extends SimpleRepoInterfaceEntry { |
|
8 |
|
|
9 |
private String label; |
|
10 |
private String collDate = ""; |
|
11 |
private int collTotal = 0; |
|
12 |
private String collMdId = ""; |
|
13 |
private String aggrMdId = ""; |
|
14 |
private String downloadDate = ""; |
|
15 |
private int downloadTotal = 0; |
|
16 |
private String downloadObjId = ""; |
|
17 |
private List<SimpleParamEntry> commonParams = Lists.newArrayList(); |
|
18 |
private List<SimpleParamEntry> accessParams = Lists.newArrayList(); |
|
19 |
private List<SimpleParamEntry> otherParams = Lists.newArrayList(); |
|
20 |
private List<RepoMetaWfEntry> metaWFs = Lists.newArrayList(); |
|
21 |
|
|
22 |
public String getLabel() { |
|
23 |
return label; |
|
24 |
} |
|
25 |
|
|
26 |
public void setLabel(final String label) { |
|
27 |
this.label = label; |
|
28 |
} |
|
29 |
|
|
30 |
public String getCollDate() { |
|
31 |
return collDate; |
|
32 |
} |
|
33 |
|
|
34 |
public void setCollDate(String collDate) { |
|
35 |
this.collDate = collDate; |
|
36 |
} |
|
37 |
|
|
38 |
public int getCollTotal() { |
|
39 |
return collTotal; |
|
40 |
} |
|
41 |
|
|
42 |
public void setCollTotal(int collTotal) { |
|
43 |
this.collTotal = collTotal; |
|
44 |
} |
|
45 |
|
|
46 |
public List<SimpleParamEntry> getCommonParams() { |
|
47 |
return commonParams; |
|
48 |
} |
|
49 |
|
|
50 |
public void setCommonParams(final List<SimpleParamEntry> commonParams) { |
|
51 |
this.commonParams = commonParams; |
|
52 |
} |
|
53 |
|
|
54 |
public List<SimpleParamEntry> getAccessParams() { |
|
55 |
return accessParams; |
|
56 |
} |
|
57 |
|
|
58 |
public void setAccessParams(final List<SimpleParamEntry> accessParams) { |
|
59 |
this.accessParams = accessParams; |
|
60 |
} |
|
61 |
|
|
62 |
public List<SimpleParamEntry> getOtherParams() { |
|
63 |
return otherParams; |
|
64 |
} |
|
65 |
|
|
66 |
public void setOtherParams(List<SimpleParamEntry> otherParams) { |
|
67 |
this.otherParams = otherParams; |
|
68 |
} |
|
69 |
|
|
70 |
public List<RepoMetaWfEntry> getMetaWFs() { |
|
71 |
return metaWFs; |
|
72 |
} |
|
73 |
|
|
74 |
public void setMetaWFs(final List<RepoMetaWfEntry> metaWFs) { |
|
75 |
this.metaWFs = metaWFs; |
|
76 |
} |
|
77 |
|
|
78 |
public String getAggrMdId() { |
|
79 |
return aggrMdId; |
|
80 |
} |
|
81 |
|
|
82 |
public void setAggrMdId(String aggrMdId) { |
|
83 |
this.aggrMdId = aggrMdId; |
|
84 |
} |
|
85 |
|
|
86 |
public String getCollMdId() { |
|
87 |
return collMdId; |
|
88 |
} |
|
89 |
|
|
90 |
public void setCollMdId(String collMdId) { |
|
91 |
this.collMdId = collMdId; |
|
92 |
} |
|
93 |
|
|
94 |
public String getDownloadDate() { |
|
95 |
return downloadDate; |
|
96 |
} |
|
97 |
|
|
98 |
public void setDownloadDate(String downloadDate) { |
|
99 |
this.downloadDate = downloadDate; |
|
100 |
} |
|
101 |
|
|
102 |
public int getDownloadTotal() { |
|
103 |
return downloadTotal; |
|
104 |
} |
|
105 |
|
|
106 |
public void setDownloadTotal(int downloadTotal) { |
|
107 |
this.downloadTotal = downloadTotal; |
|
108 |
} |
|
109 |
|
|
110 |
public String getDownloadObjId() { |
|
111 |
return downloadObjId; |
|
112 |
} |
|
113 |
|
|
114 |
public void setDownloadObjId(String downloadObjId) { |
|
115 |
this.downloadObjId = downloadObjId; |
|
116 |
} |
|
117 |
} |
modules/dnet-modular-repositories-ui/tags/dnet-modular-repositories-ui-3.0.2/src/main/java/eu/dnetlib/functionality/modular/ui/repositories/objects/VocabularyEntry.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.modular.ui.repositories.objects; |
|
2 |
|
|
3 |
public class VocabularyEntry implements Comparable<VocabularyEntry> { |
|
4 |
|
|
5 |
private String id; |
|
6 |
private String name; |
|
7 |
|
|
8 |
public VocabularyEntry() {} |
|
9 |
|
|
10 |
public VocabularyEntry(final String id, final String name) { |
|
11 |
this.id = id; |
|
12 |
this.name = name; |
|
13 |
} |
|
14 |
|
|
15 |
public String getId() { |
|
16 |
return id; |
|
17 |
} |
|
18 |
|
|
19 |
public void setId(final String id) { |
|
20 |
this.id = id; |
|
21 |
} |
|
22 |
|
|
23 |
public String getName() { |
|
24 |
return name; |
|
25 |
} |
|
26 |
|
|
27 |
public void setName(final String name) { |
|
28 |
this.name = name; |
|
29 |
} |
|
30 |
|
|
31 |
@Override |
|
32 |
public int compareTo(final VocabularyEntry o) { |
|
33 |
return getName().compareTo(o.getName()); |
|
34 |
} |
|
35 |
|
|
36 |
} |
modules/dnet-modular-repositories-ui/tags/dnet-modular-repositories-ui-3.0.2/src/main/java/eu/dnetlib/functionality/modular/ui/repositories/objects/RepoMetaWfEntry.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.modular.ui.repositories.objects; |
|
2 |
|
|
3 |
public class RepoMetaWfEntry implements Comparable<RepoMetaWfEntry> { |
|
4 |
|
|
5 |
private String id; |
|
6 |
private String name; |
|
7 |
private String status; |
|
8 |
private String destroyWorkflow; |
|
9 |
private int progress; |
|
10 |
|
|
11 |
public RepoMetaWfEntry(final String id, final String name, final String status, final String destroyWorkflow, final int progress) { |
|
12 |
this.id = id; |
|
13 |
this.name = name; |
|
14 |
this.status = status; |
|
15 |
this.destroyWorkflow = destroyWorkflow; |
|
16 |
this.progress = progress; |
|
17 |
} |
|
18 |
|
|
19 |
@Override |
|
20 |
public int compareTo(final RepoMetaWfEntry o) { |
|
21 |
return getName().compareTo(o.getName()); |
|
22 |
} |
|
23 |
|
|
24 |
public String getId() { |
|
25 |
return id; |
|
26 |
} |
|
27 |
|
|
28 |
public String getName() { |
|
29 |
return name; |
|
30 |
} |
|
31 |
|
|
32 |
public String getStatus() { |
|
33 |
return status; |
|
34 |
} |
|
35 |
|
|
36 |
public String getDestroyWorkflow() { |
|
37 |
return destroyWorkflow; |
|
38 |
} |
|
39 |
|
|
40 |
public int getProgress() { |
|
41 |
return progress; |
|
42 |
} |
|
43 |
|
|
44 |
} |
modules/dnet-modular-repositories-ui/tags/dnet-modular-repositories-ui-3.0.2/src/main/java/eu/dnetlib/functionality/modular/ui/repositories/objects/SimpleParamEntry.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.modular.ui.repositories.objects; |
|
2 |
|
|
3 |
public class SimpleParamEntry implements Comparable<SimpleParamEntry> { |
|
4 |
|
|
5 |
private String id; |
|
6 |
private String name; |
|
7 |
private Object value; |
|
8 |
private Object otherValue; |
|
9 |
|
|
10 |
public SimpleParamEntry(final String name, final Object value) { |
|
11 |
this(name, name, value, null); |
|
12 |
} |
|
13 |
|
|
14 |
public SimpleParamEntry(final String id, final String name, final Object value) { |
|
15 |
this(id, name, value, null); |
|
16 |
} |
|
17 |
|
|
18 |
public SimpleParamEntry(final String id, final String name, final Object value, final Object otherValue) { |
|
19 |
this.id = id; |
|
20 |
this.name = name; |
|
21 |
this.value = value; |
|
22 |
this.setOtherValue(otherValue); |
|
23 |
} |
|
24 |
|
|
25 |
public String getId() { |
|
26 |
return id; |
|
27 |
} |
|
28 |
|
|
29 |
public void setId(final String id) { |
|
30 |
this.id = id; |
|
31 |
} |
|
32 |
|
|
33 |
public Object getValue() { |
|
34 |
return value; |
|
35 |
} |
|
36 |
|
|
37 |
public void setValue(final Object value) { |
|
38 |
this.value = value; |
|
39 |
} |
|
40 |
|
|
41 |
public String getName() { |
|
42 |
return name; |
|
43 |
} |
|
44 |
|
|
45 |
public void setName(final String name) { |
|
46 |
this.name = name; |
|
47 |
} |
|
48 |
|
|
49 |
|
|
50 |
public Object getOtherValue() { |
|
51 |
return otherValue; |
|
52 |
} |
|
53 |
|
|
54 |
public void setOtherValue(Object otherValue) { |
|
55 |
this.otherValue = otherValue; |
|
56 |
} |
|
57 |
|
|
58 |
@Override |
|
59 |
public int compareTo(final SimpleParamEntry o) { |
|
60 |
return getName().compareTo(o.getName()); |
|
61 |
} |
|
62 |
} |
modules/dnet-modular-repositories-ui/tags/dnet-modular-repositories-ui-3.0.2/src/main/java/eu/dnetlib/functionality/modular/ui/repositories/RepoEnablerEntryPointController.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.modular.ui.repositories; |
|
2 |
|
|
3 |
import java.util.Collections; |
|
4 |
import java.util.List; |
|
5 |
|
|
6 |
import javax.annotation.Resource; |
|
7 |
import javax.servlet.http.HttpServletRequest; |
|
8 |
import javax.servlet.http.HttpServletResponse; |
|
9 |
|
|
10 |
import org.springframework.beans.factory.annotation.Required; |
|
11 |
import org.springframework.ui.ModelMap; |
|
12 |
|
|
13 |
import com.google.common.collect.Lists; |
|
14 |
import com.google.gson.Gson; |
|
15 |
|
|
16 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException; |
|
17 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; |
|
18 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
19 |
import eu.dnetlib.functionality.modular.ui.ModuleEntryPoint; |
|
20 |
import eu.dnetlib.functionality.modular.ui.repositories.objects.VocabularyEntry; |
|
21 |
|
|
22 |
public class RepoEnablerEntryPointController extends ModuleEntryPoint { |
|
23 |
|
|
24 |
private String datasourceTypeVocabulary; |
|
25 |
|
|
26 |
@Resource |
|
27 |
private UniqueServiceLocator serviceLocator; |
|
28 |
|
|
29 |
@Override |
|
30 |
protected void initialize(final ModelMap map, final HttpServletRequest request, final HttpServletResponse response) throws Exception { |
|
31 |
map.addAttribute("types", new Gson().toJson(listDatasourceTypes())); |
|
32 |
} |
|
33 |
|
|
34 |
private List<VocabularyEntry> listDatasourceTypes() throws ISLookUpException { |
|
35 |
final String xquery = "for $x in collection('/db/DRIVER/VocabularyDSResources/VocabularyDSResourceType')[.//VOCABULARY_NAME/@code = '" |
|
36 |
+ getDatasourceTypeVocabulary().trim() + "']//TERM return concat($x/@code, ' @@@ ', $x/@english_name)"; |
|
37 |
|
|
38 |
final List<VocabularyEntry> list = Lists.newArrayList(); |
|
39 |
for (String s : serviceLocator.getService(ISLookUpService.class).quickSearchProfile(xquery)) { |
|
40 |
final String[] arr = s.split("@@@"); |
|
41 |
list.add(new VocabularyEntry(arr[0].trim(), arr[1].trim())); |
|
42 |
} |
|
43 |
Collections.sort(list); |
|
44 |
|
|
45 |
return list; |
|
46 |
} |
|
47 |
|
|
48 |
public String getDatasourceTypeVocabulary() { |
|
49 |
return datasourceTypeVocabulary; |
|
50 |
} |
|
51 |
|
|
52 |
@Required |
|
53 |
public void setDatasourceTypeVocabulary(final String datasourceTypeVocabulary) { |
|
54 |
this.datasourceTypeVocabulary = datasourceTypeVocabulary; |
|
55 |
} |
|
56 |
|
|
57 |
} |
Also available in: Unified diff
[maven-release-plugin] copy for tag dnet-modular-repositories-ui-3.0.2