Revision 49469
Added by Panagiotis Kanakakis almost 7 years ago
modules/uoa-repository-manager-service/src/main/java/eu/dnetlib/repo/manager/service/utils/OaiTools.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.utils; |
|
2 |
|
|
3 |
import org.apache.log4j.Logger; |
|
4 |
import org.dom4j.io.DOMWriter; |
|
5 |
import org.w3c.dom.Document; |
|
6 |
import se.kb.oai.pmh.*; |
|
7 |
import se.kb.oai.pmh.Set; |
|
8 |
|
|
9 |
import javax.net.ssl.*; |
|
10 |
import javax.xml.namespace.NamespaceContext; |
|
11 |
import javax.xml.xpath.XPath; |
|
12 |
import javax.xml.xpath.XPathExpressionException; |
|
13 |
import javax.xml.xpath.XPathFactory; |
|
14 |
import java.security.KeyManagementException; |
|
15 |
import java.security.NoSuchAlgorithmException; |
|
16 |
import java.security.cert.X509Certificate; |
|
17 |
import java.util.*; |
|
18 |
|
|
19 |
public class OaiTools { |
|
20 |
|
|
21 |
{ |
|
22 |
disableSslVerification(); |
|
23 |
} |
|
24 |
|
|
25 |
private static Logger LOGGER = Logger.getLogger(OaiTools.class); |
|
26 |
|
|
27 |
public static List<String> getSetsOfRepo(String baseUrl) throws Exception { |
|
28 |
try { |
|
29 |
LOGGER.debug("Getting sets of repository " + baseUrl); |
|
30 |
OaiPmhServer harvester = new OaiPmhServer(baseUrl); |
|
31 |
SetsList setList = harvester.listSets(); |
|
32 |
ResumptionToken token = setList.getResumptionToken(); |
|
33 |
List<Set> sets = new ArrayList<Set>(); |
|
34 |
sets.addAll(setList.asList()); |
|
35 |
while (token != null) { |
|
36 |
setList = harvester.listSets(token); |
|
37 |
token = setList.getResumptionToken(); |
|
38 |
sets.addAll(setList.asList()); |
|
39 |
} |
|
40 |
|
|
41 |
List<String> ret = new ArrayList<String>(); |
|
42 |
for (Set set : sets) { |
|
43 |
ret.add(set.getSpec().trim()); |
|
44 |
} |
|
45 |
if (ret.size() > 0 ) |
|
46 |
Collections.sort(ret); |
|
47 |
return ret; |
|
48 |
|
|
49 |
} catch (Exception e) { |
|
50 |
LOGGER.error("Error getting sets of repository " + baseUrl, e); |
|
51 |
return new ArrayList<String>(); |
|
52 |
//throw e; |
|
53 |
} |
|
54 |
} |
|
55 |
|
|
56 |
public static boolean identifyRepository(String baseUrl) throws Exception { |
|
57 |
LOGGER.debug("sending identify request to repo " + baseUrl); |
|
58 |
|
|
59 |
OaiPmhServer harvester = new OaiPmhServer(baseUrl); |
|
60 |
|
|
61 |
if (baseUrl.trim().isEmpty()) { |
|
62 |
return false; |
|
63 |
} |
|
64 |
|
|
65 |
try { |
|
66 |
Identification identification = harvester.identify(); |
|
67 |
DOMWriter d4Writer = new DOMWriter(); |
|
68 |
Document d = d4Writer.write(identification.getResponse()); |
|
69 |
|
|
70 |
return verifyIdentify(d); |
|
71 |
} catch (Exception e) { |
|
72 |
LOGGER.debug("Error verifying identify response", e); |
|
73 |
throw e; |
|
74 |
} |
|
75 |
} |
|
76 |
|
|
77 |
private static boolean verifyIdentify(Document doc) throws XPathExpressionException { |
|
78 |
NamespaceContext ctx = new NamespaceContext() { |
|
79 |
public String getNamespaceURI(String prefix) { |
|
80 |
String uri; |
|
81 |
if (prefix.equals("oai")) |
|
82 |
uri = "http://www.openarchives.org/OAI/2.0/"; |
|
83 |
else |
|
84 |
uri = null; |
|
85 |
return uri; |
|
86 |
} |
|
87 |
|
|
88 |
// Dummy implementation - not used! |
|
89 |
public Iterator<String> getPrefixes(String val) { |
|
90 |
return null; |
|
91 |
} |
|
92 |
|
|
93 |
// Dummy implemenation - not used! |
|
94 |
public String getPrefix(String uri) { |
|
95 |
return null; |
|
96 |
} |
|
97 |
}; |
|
98 |
|
|
99 |
// Now the XPath expression |
|
100 |
|
|
101 |
String xpathStr = "//oai:OAI-PMH/oai:Identify"; |
|
102 |
XPathFactory xpathFact = XPathFactory.newInstance(); |
|
103 |
XPath xpath = xpathFact.newXPath(); |
|
104 |
xpath.setNamespaceContext(ctx); |
|
105 |
String result = xpath.evaluate(xpathStr, doc); |
|
106 |
|
|
107 |
return (result != null && !result.equals("")); |
|
108 |
} |
|
109 |
|
|
110 |
private static void disableSslVerification() { |
|
111 |
try |
|
112 |
{ |
|
113 |
LOGGER.debug("disabling ssl verification"); |
|
114 |
// Create a trust manager that does not validate certificate chains |
|
115 |
TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() { |
|
116 |
public X509Certificate[] getAcceptedIssuers() { |
|
117 |
return null; |
|
118 |
} |
|
119 |
public void checkClientTrusted(X509Certificate[] certs, String authType) { |
|
120 |
} |
|
121 |
public void checkServerTrusted(X509Certificate[] certs, String authType) { |
|
122 |
} |
|
123 |
} |
|
124 |
}; |
|
125 |
|
|
126 |
// Install the all-trusting trust manager |
|
127 |
SSLContext sc = SSLContext.getInstance("SSL"); |
|
128 |
sc.init(null, trustAllCerts, new java.security.SecureRandom()); |
|
129 |
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); |
|
130 |
|
|
131 |
// Create all-trusting host name verifier |
|
132 |
HostnameVerifier allHostsValid = new HostnameVerifier() { |
|
133 |
public boolean verify(String hostname, SSLSession session) { |
|
134 |
return true; |
|
135 |
} |
|
136 |
}; |
|
137 |
|
|
138 |
// Install the all-trusting host verifier |
|
139 |
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); |
|
140 |
} catch (NoSuchAlgorithmException e) { |
|
141 |
LOGGER.error("disabling ssl verification", e); |
|
142 |
} catch (KeyManagementException e) { |
|
143 |
LOGGER.error("error while disabling ssl verification", e); |
|
144 |
} |
|
145 |
} |
|
146 |
} |
modules/uoa-repository-manager-service/src/main/java/eu/dnetlib/repo/manager/service/utils/Converter.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.utils; |
|
2 |
|
|
3 |
import eu.dnetlib.domain.data.Repository; |
|
4 |
import eu.dnetlib.domain.data.RepositoryInterface; |
|
5 |
import org.json.JSONArray; |
|
6 |
import org.json.JSONException; |
|
7 |
import org.json.JSONObject; |
|
8 |
|
|
9 |
import java.io.BufferedReader; |
|
10 |
import java.io.File; |
|
11 |
import java.io.FileReader; |
|
12 |
import java.io.IOException; |
|
13 |
import java.text.ParseException; |
|
14 |
import java.text.SimpleDateFormat; |
|
15 |
import java.util.*; |
|
16 |
|
|
17 |
public class Converter { |
|
18 |
|
|
19 |
public static Repository jsonToRepositoryObject(JSONObject jsonObject) throws JSONException { |
|
20 |
|
|
21 |
Repository repository = new Repository(); |
|
22 |
|
|
23 |
if( jsonObject.get("datasource").equals(null)) |
|
24 |
return null; |
|
25 |
|
|
26 |
JSONObject datasource = (JSONObject) jsonObject.get("datasource"); |
|
27 |
|
|
28 |
repository.setActivationId(datasource.get("activationId").toString()); |
|
29 |
repository.setAggregator(datasource.get("aggregator").toString()); |
|
30 |
repository.setCertificates(datasource.get("certificates").toString()); |
|
31 |
repository.setCitationGuidelineUrl(datasource.get("citationguidelineurl").toString()); |
|
32 |
repository.setCollectedFrom( datasource.get("collectedfrom").toString()); |
|
33 |
repository.setContactEmail(datasource.get("contactemail").toString()); |
|
34 |
repository.setDatabaseAccessRestriction(datasource.get("databaseaccessrestriction").toString()); |
|
35 |
repository.setDatabaseAccessType(datasource.get("databaseaccesstype").toString()); |
|
36 |
repository.setDataUploadRestriction(datasource.get("datauploadrestriction").toString()); |
|
37 |
repository.setDataUploadType(datasource.get("datauploadtype").toString()); |
|
38 |
repository.setDateOfCollection(convertDate( datasource.get("dateofcollection").toString())); |
|
39 |
repository.setDateOfValidation(convertDate( datasource.get("dateofvalidation").toString())); |
|
40 |
repository.setDescription(datasource.get("description").toString()); |
|
41 |
repository.setEissn(datasource.get("eissn").toString()); |
|
42 |
repository.setEnglishName( datasource.get("englishname").toString()); |
|
43 |
repository.setId(datasource.get("id").toString()); |
|
44 |
repository.setIssn(datasource.get("issn").toString()); |
|
45 |
repository.setOdLanguages(datasource.get("languages").toString()); |
|
46 |
repository.setLatitude( toDouble(datasource.get("latitude").toString())); |
|
47 |
repository.setLissn(datasource.get("lissn").toString()); |
|
48 |
repository.setLogoUrl(datasource.get("logourl").toString()); |
|
49 |
repository.setLongitude(toDouble(datasource.get("longitude").toString())); |
|
50 |
//datasource.get("managed"); |
|
51 |
repository.setMissionStatementUrl(datasource.get("missionstatementurl").toString()); |
|
52 |
repository.setNamespacePrefix(datasource.get("namespaceprefix").toString()); |
|
53 |
repository.setOdContentTypes(datasource.get("od_contenttypes").toString()); |
|
54 |
repository.setOfficialName(datasource.get("officialname").toString()); |
|
55 |
repository.setPidSystems(datasource.get("pidsystems").toString()); |
|
56 |
//datasource.get("platform"); |
|
57 |
repository.setProvenanceActionClass( datasource.get("provenanceaction").toString()); |
|
58 |
repository.setQualityManagementKind(datasource.get("qualitymanagementkind").toString()); |
|
59 |
repository.setRegisteredBy(datasource.get("registeredby").toString()); |
|
60 |
repository.setReleaseEndDate(convertDate(datasource.get("releaseenddate").toString())); |
|
61 |
repository.setReleaseStartDate(convertDate(datasource.get("releasestartdate").toString())); |
|
62 |
repository.setServiceProvider(Boolean.valueOf(datasource.get("serviceprovider").toString())); |
|
63 |
//datasource.get("subjects"); |
|
64 |
Double timezone = toDouble(datasource.get("timezone").toString()); |
|
65 |
repository.setTimezone(timezone!=null?timezone:0.0); |
|
66 |
repository.setTypology(datasource.get("typology").toString()); |
|
67 |
repository.setVersioning(Boolean.valueOf(datasource.get("versioning").toString())); |
|
68 |
repository.setWebsiteUrl(datasource.get("websiteurl").toString()); |
|
69 |
return repository; |
|
70 |
} |
|
71 |
|
|
72 |
public static Date convertDate(String date){ |
|
73 |
|
|
74 |
if(Objects.equals(date, "null")) |
|
75 |
return null; |
|
76 |
|
|
77 |
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); |
|
78 |
try { |
|
79 |
return formatter.parse(date); |
|
80 |
} catch (ParseException e) { |
|
81 |
e.printStackTrace(); |
|
82 |
} |
|
83 |
return null; |
|
84 |
} |
|
85 |
|
|
86 |
public static String convertDateToString(String date){ |
|
87 |
|
|
88 |
if(Objects.equals(date, "null")) |
|
89 |
return null; |
|
90 |
|
|
91 |
SimpleDateFormat formatter = new SimpleDateFormat("E MMM dd HH:mm:ss Z yyyy"); |
|
92 |
|
|
93 |
Date d = null; |
|
94 |
try { |
|
95 |
d = (Date)formatter.parse(date); |
|
96 |
Calendar cal = Calendar.getInstance(); |
|
97 |
cal.setTime(d); |
|
98 |
return cal.get(Calendar.DATE) + "-" + (cal.get(Calendar.MONTH) + 1) + "-" + cal.get(Calendar.YEAR); |
|
99 |
|
|
100 |
} catch (ParseException e) { |
|
101 |
e.printStackTrace(); |
|
102 |
} |
|
103 |
return null; |
|
104 |
} |
|
105 |
|
|
106 |
public static Double toDouble(String number){ |
|
107 |
if(Objects.equals(number, "null")) |
|
108 |
return null; |
|
109 |
else |
|
110 |
return Double.valueOf(number); |
|
111 |
} |
|
112 |
|
|
113 |
public static List<Repository> jsonToRepositoryList(JSONArray rs) throws JSONException { |
|
114 |
|
|
115 |
List<Repository> resultSet = new ArrayList<>(); |
|
116 |
for(int i=0;i<rs.length();i++) |
|
117 |
resultSet.add(jsonToRepositoryObject( rs.getJSONObject(i)) ); |
|
118 |
return resultSet; |
|
119 |
} |
|
120 |
|
|
121 |
public static RepositoryInterface jsonToRepositoryInterfaceObject(JSONObject jsonObject) throws JSONException { |
|
122 |
|
|
123 |
RepositoryInterface repositoryInterface = new RepositoryInterface(); |
|
124 |
|
|
125 |
repositoryInterface.setBaseUrl(jsonObject.get("baseurl").toString()); |
|
126 |
repositoryInterface.setContentDescription(jsonObject.get("contentdescription").toString()); |
|
127 |
repositoryInterface.setId(jsonObject.get("id").toString()); |
|
128 |
repositoryInterface.setMetadataIdentifierPath(jsonObject.get("metadataIdentifierPath").toString()); |
|
129 |
repositoryInterface.setAccessProtocol(jsonObject.get("protocol").toString()); |
|
130 |
repositoryInterface.setTypology(jsonObject.get("typology").toString()); |
|
131 |
repositoryInterface.setDesiredCompatibilityLevel(jsonObject.get("compatibility").toString()); |
|
132 |
repositoryInterface.setActive(Boolean.parseBoolean(jsonObject.get("active").toString())); |
|
133 |
repositoryInterface.setRemovable(Boolean.parseBoolean(jsonObject.get("removable").toString())); |
|
134 |
|
|
135 |
return repositoryInterface; |
|
136 |
} |
|
137 |
|
|
138 |
public static String repositoryObjectToJson(Repository repository) throws JSONException { |
|
139 |
|
|
140 |
JSONObject jsonObject = new JSONObject(); |
|
141 |
jsonObject.put("activationId",repository.getActivationId()); |
|
142 |
jsonObject.put("aggregator",repository.getAggregator()); |
|
143 |
jsonObject.put("certificates",repository.getCertificates()); |
|
144 |
jsonObject.put("citationguidelineurl",repository.getCitationGuidelineUrl()); |
|
145 |
jsonObject.put("collectedfrom",repository.getCollectedFrom()); |
|
146 |
jsonObject.put("contactemail",repository.getContactEmail()); |
|
147 |
jsonObject.put("databaseaccessrestriction",repository.getDatabaseAccessRestriction()); |
|
148 |
jsonObject.put("databaseaccesstype",repository.getDatabaseAccessType()); |
|
149 |
jsonObject.put("datauploadrestriction",repository.getDataUploadRestriction()); |
|
150 |
jsonObject.put("datauploadtype",repository.getDataUploadType()); |
|
151 |
jsonObject.put("dateofcollection",convertDateToString(String.valueOf(repository.getDateOfCollection()))); |
|
152 |
jsonObject.put("dateofvalidation",convertDateToString(String.valueOf(repository.getDateOfValidation()))); |
|
153 |
jsonObject.put("description",repository.getDescription()); |
|
154 |
jsonObject.put("eissn",repository.getEissn()); |
|
155 |
jsonObject.put("englishname",repository.getEnglishName()); |
|
156 |
jsonObject.put("id",repository.getId()); |
|
157 |
jsonObject.put("issn",repository.getIssn()); |
|
158 |
jsonObject.put("languages",repository.getOdLanguages()); |
|
159 |
jsonObject.put("latitude",repository.getLatitude().toString()); |
|
160 |
jsonObject.put("lissn",repository.getLissn()); |
|
161 |
jsonObject.put("logourl",repository.getLogoUrl()); |
|
162 |
jsonObject.put("longitude",repository.getLongitude().toString()); |
|
163 |
jsonObject.put("missionstatementurl",repository.getMissionStatementUrl()); |
|
164 |
jsonObject.put("namespaceprefix",repository.getNamespacePrefix()); |
|
165 |
jsonObject.put("od_contenttypes",repository.getOdContentTypes()); |
|
166 |
jsonObject.put("officialname",repository.getOfficialName()); |
|
167 |
jsonObject.put("pidsystems",repository.getPidSystems()); |
|
168 |
jsonObject.put("provenanceaction",repository.getProvenanceActionClass()); |
|
169 |
jsonObject.put("qualitymanagementkind",repository.getQualityManagementKind()); |
|
170 |
jsonObject.put("registeredby",repository.getRegisteredBy()); |
|
171 |
jsonObject.put("releaseenddate",convertDateToString(String.valueOf(repository.getReleaseEndDate()))); |
|
172 |
jsonObject.put("releasestartdate",convertDateToString(String.valueOf(repository.getReleaseStartDate()))); |
|
173 |
jsonObject.put("serviceprovider",repository.getServiceProvider()); |
|
174 |
jsonObject.put("timezone",repository.getTimezone()); |
|
175 |
jsonObject.put("typology",repository.getTypology()); |
|
176 |
jsonObject.put("versioning",repository.getVersioning()); |
|
177 |
jsonObject.put("websiteurl",repository.getWebsiteUrl()); |
|
178 |
|
|
179 |
//datasource.get("managed"); |
|
180 |
//datasource.get("platform"); |
|
181 |
//datasource.get("subjects"); |
|
182 |
return jsonObject.toString(); |
|
183 |
} |
|
184 |
|
|
185 |
public static String repositoryInterfaceObjectToJson(RepositoryInterface repositoryInterface) throws JSONException { |
|
186 |
|
|
187 |
JSONObject jsonObject = new JSONObject(); |
|
188 |
|
|
189 |
jsonObject.put("baseurl",repositoryInterface.getBaseUrl()); |
|
190 |
jsonObject.put("contentdescription",repositoryInterface.getContentDescription()); |
|
191 |
jsonObject.put("id",repositoryInterface.getId()); |
|
192 |
jsonObject.put("metadataIdentifierPath",repositoryInterface.getMetadataIdentifierPath()); |
|
193 |
jsonObject.put("protocol",repositoryInterface.getAccessProtocol()); |
|
194 |
jsonObject.put("typology",repositoryInterface.getTypology()); |
|
195 |
jsonObject.put("compatibility",repositoryInterface.getDesiredCompatibilityLevel()); |
|
196 |
//jsonObject.put("removable",repositoryInterface.getRemovable()); |
|
197 |
//jsonObject.put("active",repositoryInterface.getActive()); |
|
198 |
return jsonObject.toString(); |
|
199 |
} |
|
200 |
|
|
201 |
public static ArrayList<String> readFile(String filename) { |
|
202 |
String line; |
|
203 |
ArrayList<String> list = new ArrayList<String>(); |
|
204 |
try { |
|
205 |
File file = new File(Converter.class.getResource("/eu/dnetlib/repo/manager/service/utils/"+filename).getFile()); |
|
206 |
BufferedReader br = new BufferedReader(new FileReader(file)); |
|
207 |
while((line = br.readLine()) != null) { |
|
208 |
list.add(line.trim()); |
|
209 |
} |
|
210 |
br.close(); |
|
211 |
} catch (IOException e) { |
|
212 |
e.printStackTrace(); |
|
213 |
} |
|
214 |
return list; |
|
215 |
} |
|
216 |
} |
modules/uoa-repository-manager-service/src/main/java/eu/dnetlib/repo/manager/service/config/RepoManagerContextLoaderListener.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.config; |
|
2 |
|
|
3 |
import org.apache.commons.lang.ArrayUtils; |
|
4 |
import org.apache.log4j.Logger; |
|
5 |
import org.springframework.beans.BeansException; |
|
6 |
import org.springframework.context.support.ClassPathXmlApplicationContext; |
|
7 |
import org.springframework.web.context.ContextLoaderListener; |
|
8 |
import org.springframework.web.context.WebApplicationContext; |
|
9 |
import org.springframework.web.context.support.XmlWebApplicationContext; |
|
10 |
|
|
11 |
import javax.servlet.ServletContext; |
|
12 |
import java.util.Properties; |
|
13 |
|
|
14 |
public class RepoManagerContextLoaderListener extends ContextLoaderListener { |
|
15 |
private static Logger logger = Logger.getLogger(RepoManagerContextLoaderListener.class); |
|
16 |
|
|
17 |
|
|
18 |
public RepoManagerContextLoaderListener() { |
|
19 |
super(); |
|
20 |
} |
|
21 |
|
|
22 |
public RepoManagerContextLoaderListener(WebApplicationContext context) { |
|
23 |
super(context); |
|
24 |
} |
|
25 |
|
|
26 |
@Override |
|
27 |
protected WebApplicationContext createWebApplicationContext( |
|
28 |
ServletContext servletContext) |
|
29 |
throws BeansException { |
|
30 |
logger.debug("Creating web application context"); |
|
31 |
Properties props = this.loadProperties(); |
|
32 |
String repoMode = props.getProperty("services.validator.mode.repo"); |
|
33 |
String userMode = props.getProperty("services.validator.mode.user"); |
|
34 |
Boolean standaloneMode = Boolean.parseBoolean(props.getProperty("services.validator.mode.standalone")); |
|
35 |
|
|
36 |
logger.info("User mode: " + userMode); |
|
37 |
logger.info("Repo mode: " + repoMode); |
|
38 |
logger.info("Standalone mode: " + standaloneMode); |
|
39 |
// logger.info("Dnet workflow enabled: " + repoMode); |
|
40 |
XmlWebApplicationContext ctx = new XmlWebApplicationContext(); |
|
41 |
|
|
42 |
ctx.setServletContext(servletContext); |
|
43 |
|
|
44 |
String userApiContext = null; |
|
45 |
if (userMode.equalsIgnoreCase("local")) |
|
46 |
userApiContext = "eu/dnetlib/validator/web/api/impls/users/springContext-validator-user-local.xml"; |
|
47 |
else if (userMode.equalsIgnoreCase("ldap")) |
|
48 |
userApiContext = "eu/dnetlib/users/springContext-users-ldap.xml"; |
|
49 |
|
|
50 |
String[] springContextCore = new String[] { |
|
51 |
"classpath:META-INF/cxf/cxf.xml", |
|
52 |
"classpath:META-INF/cxf/cxf-extension-soap.xml", |
|
53 |
"classpath:META-INF/cxf/cxf-extension-jaxws.xml", |
|
54 |
"classpath:META-INF/cxf/cxf-servlet.xml", |
|
55 |
"classpath*:/cxf.xml", |
|
56 |
"classpath*:/eu/dnetlib/repos/ehcacher/springContext-repos-ehcacher.xml", |
|
57 |
"classpath*:/eu/dnetlib/clients/ws/springContext-locatorFactory.xml", |
|
58 |
"classpath*:/eu/dnetlib/soap/cxf/applicationContext-eprbuilders.xml", |
|
59 |
// "classpath*:/eu/dnetlib/validator/web/actions/springContext-validator-struts.xml", |
|
60 |
// "classpath*:/eu/dnetlib/validator/web/actions/springContext-validator-emailer.xml", |
|
61 |
// "classpath*:/eu/dnetlib/validator/web/config/springContext-validator.xml", |
|
62 |
"classpath*:/eu/dnetlib/repo/manager/server/config/springContext-repo-manager-config.xml", |
|
63 |
// "classpath*:/eu/dnetlib/validator/commons/dao/springContext-*.xml", |
|
64 |
"classpath*:/eu/dnetlib/repos/springContext-repos-" + repoMode + ".xml", |
|
65 |
"classpath*:/" + userApiContext |
|
66 |
}; |
|
67 |
|
|
68 |
|
|
69 |
String[] springContextForStandalone = new String[] { |
|
70 |
}; |
|
71 |
|
|
72 |
String[] springContextForIS = new String[] { |
|
73 |
"classpath*:/gr/uoa/di/driver/util/springContext-locators.xml", |
|
74 |
"classpath*:/gr/uoa/di/driver/app/springContext-lookupFactory.xml", |
|
75 |
"classpath*:/gr/uoa/di/driver/app/springContext-lookupClients.xml", |
|
76 |
"classpath*:/eu/dnetlib/enabling/hcm/springContext-hcmService.xml", |
|
77 |
"classpath*:/gr/uoa/di/driver/app/springContext-commons.xml", |
|
78 |
"classpath*:/gr/uoa/di/driver/app/springContext-registrator.xml" |
|
79 |
}; |
|
80 |
|
|
81 |
if (standaloneMode) { |
|
82 |
logger.debug("Loading contexts for standalone mode"); |
|
83 |
ctx.setConfigLocations((String[])ArrayUtils.addAll(springContextCore,springContextForStandalone)); |
|
84 |
} else { |
|
85 |
logger.debug("Loading contexts for dnet"); |
|
86 |
ctx.setConfigLocations((String[])ArrayUtils.addAll(springContextCore,springContextForIS)); |
|
87 |
} |
|
88 |
|
|
89 |
ctx.refresh(); |
|
90 |
|
|
91 |
logger.debug("done"); |
|
92 |
|
|
93 |
return ctx; |
|
94 |
} |
|
95 |
|
|
96 |
private Properties loadProperties() { |
|
97 |
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] { |
|
98 |
"classpath*:/eu/dnetlib/repo/manager/server/config/springContext-repo-manager-config.xml" |
|
99 |
}); |
|
100 |
|
|
101 |
CascadingPropertyLoader pLoader = (CascadingPropertyLoader) ctx.getBean("propertyLoader"); |
|
102 |
Properties props = pLoader.getProperties(); |
|
103 |
|
|
104 |
ctx.destroy(); |
|
105 |
ctx.close(); |
|
106 |
return props; |
|
107 |
} |
|
108 |
|
|
109 |
} |
modules/uoa-repository-manager-service/src/main/java/eu/dnetlib/repo/manager/service/config/CascadingPropertyLoader.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.config; |
|
2 |
|
|
3 |
import org.springframework.beans.BeansException; |
|
4 |
import org.springframework.beans.factory.InitializingBean; |
|
5 |
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; |
|
6 |
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; |
|
7 |
|
|
8 |
import java.util.Properties; |
|
9 |
|
|
10 |
/** |
|
11 |
* CascadingPropertyLoader loads a number of property files and mergers them together, so that the last properties |
|
12 |
* override the previous. It also supports property expansion like: |
|
13 |
* |
|
14 |
* <code> |
|
15 |
* something = 1 |
|
16 |
* somethingelse = 2 |
|
17 |
* test = ${something}/${somethingelse} |
|
18 |
* </code> |
|
19 |
* |
|
20 |
* <p> |
|
21 |
* And if you override something to XX, then test will become XX/2 |
|
22 |
* </p> |
|
23 |
* |
|
24 |
* |
|
25 |
* @author marko |
|
26 |
* |
|
27 |
*/ |
|
28 |
public class CascadingPropertyLoader extends PropertyPlaceholderConfigurer implements InitializingBean { |
|
29 |
|
|
30 |
private Properties properties; |
|
31 |
|
|
32 |
public void afterPropertiesSet() throws Exception { |
|
33 |
this.properties = mergeProperties(); |
|
34 |
|
|
35 |
// Convert the merged properties, if necessary. |
|
36 |
convertProperties(this.properties); |
|
37 |
|
|
38 |
logger.debug("Properties: " + properties); |
|
39 |
} |
|
40 |
|
|
41 |
@Override |
|
42 |
protected void processProperties(final ConfigurableListableBeanFactory beanFactoryToProcess, final Properties props) throws BeansException { |
|
43 |
super.processProperties(beanFactoryToProcess, props); |
|
44 |
} |
|
45 |
|
|
46 |
public Properties getProperties() { |
|
47 |
return properties; |
|
48 |
} |
|
49 |
|
|
50 |
public void setProperties(final Properties properties) { |
|
51 |
super.setProperties(properties); |
|
52 |
|
|
53 |
this.properties = properties; |
|
54 |
} |
|
55 |
} |
modules/uoa-repository-manager-service/src/main/java/eu/dnetlib/repo/manager/service/controllers/BrokerApi.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.controllers; |
|
2 |
|
|
3 |
import eu.dnetlib.repo.manager.service.shared.BrokerException; |
|
4 |
import eu.dnetlib.repo.manager.service.shared.broker.BrowseEntry; |
|
5 |
import eu.dnetlib.repo.manager.service.shared.broker.DatasourcesBroker; |
|
6 |
import eu.dnetlib.repo.manager.service.shared.broker.EventsPage; |
|
7 |
import org.json.JSONException; |
|
8 |
import org.springframework.http.MediaType; |
|
9 |
import org.springframework.web.bind.annotation.RequestBody; |
|
10 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
11 |
import org.springframework.web.bind.annotation.RequestMethod; |
|
12 |
import org.springframework.web.bind.annotation.RestController; |
|
13 |
|
|
14 |
import java.util.List; |
|
15 |
|
|
16 |
@RestController |
|
17 |
@RequestMapping(value = "/broker") |
|
18 |
public interface BrokerApi { |
|
19 |
|
|
20 |
@RequestMapping(value = "/getDatasourcesOfUser" , method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE) |
|
21 |
DatasourcesBroker getDatasourcesOfUser(@RequestBody String params) throws BrokerException, JSONException; |
|
22 |
|
|
23 |
@RequestMapping(value = "/getTopicsForDatasource/{datasourceName}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) |
|
24 |
List<BrowseEntry> getTopicsForDatasource(String datasourceName) throws BrokerException; |
|
25 |
|
|
26 |
@RequestMapping(value = "/advancedShowEvents" , method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE) |
|
27 |
EventsPage advancedShowEvents(@RequestBody String params) throws BrokerException, JSONException; |
|
28 |
} |
modules/uoa-repository-manager-service/src/main/java/eu/dnetlib/repo/manager/service/controllers/RestService.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.controllers; |
|
2 |
|
|
3 |
import org.springframework.stereotype.Component; |
|
4 |
import org.springframework.web.client.RestTemplate; |
|
5 |
|
|
6 |
@Component |
|
7 |
public class RestService { |
|
8 |
|
|
9 |
private static RestTemplate restTemplate = new org.springframework.web.client.RestTemplate(); |
|
10 |
|
|
11 |
|
|
12 |
public static String executeGET(String uri){ |
|
13 |
return restTemplate.getForObject(uri,String.class); |
|
14 |
} |
|
15 |
|
|
16 |
public static String executePOST(String uri,String json){ |
|
17 |
return restTemplate.postForObject(uri,json,String.class); |
|
18 |
} |
|
19 |
} |
modules/uoa-repository-manager-service/src/main/java/eu/dnetlib/repo/manager/service/controllers/ValidatorApi.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.controllers; |
|
2 |
|
|
3 |
import eu.dnetlib.domain.functionality.validator.JobForValidation; |
|
4 |
import eu.dnetlib.domain.functionality.validator.RuleSet; |
|
5 |
import org.json.JSONException; |
|
6 |
import org.springframework.http.MediaType; |
|
7 |
import org.springframework.web.bind.annotation.*; |
|
8 |
|
|
9 |
import java.util.List; |
|
10 |
|
|
11 |
|
|
12 |
@RestController |
|
13 |
@RequestMapping(value = "/validator") |
|
14 |
public interface ValidatorApi { |
|
15 |
|
|
16 |
@RequestMapping(value = "/submitJobForValidation",method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE ) |
|
17 |
@ResponseBody |
|
18 |
void submitJobForValidation(@RequestBody JobForValidation jobForValidation); |
|
19 |
|
|
20 |
@RequestMapping(value = "/reSubmitJobForValidation/",method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE ) |
|
21 |
@ResponseBody |
|
22 |
void reSubmitJobForValidation(@RequestBody String jobId) throws JSONException; |
|
23 |
|
|
24 |
@RequestMapping(value = "/getRuleSets/{mode}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) |
|
25 |
@ResponseBody |
|
26 |
List<RuleSet> getRuleSets(String mode); |
|
27 |
|
|
28 |
@RequestMapping(value = "/getSetsOfRepository" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) |
|
29 |
@ResponseBody |
|
30 |
List<String> getSetsOfRepository(@RequestBody String url); |
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
} |
modules/uoa-repository-manager-service/src/main/java/eu/dnetlib/repo/manager/service/controllers/BrokerApiImpl.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.controllers; |
|
2 |
|
|
3 |
|
|
4 |
import com.fasterxml.jackson.databind.ObjectMapper; |
|
5 |
import com.google.gson.Gson; |
|
6 |
import eu.dnetlib.domain.data.Repository; |
|
7 |
import eu.dnetlib.repo.manager.service.shared.BrokerException; |
|
8 |
import eu.dnetlib.repo.manager.service.shared.Tuple; |
|
9 |
import eu.dnetlib.repo.manager.service.shared.broker.AdvQueryObject; |
|
10 |
import eu.dnetlib.repo.manager.service.shared.broker.BrowseEntry; |
|
11 |
import eu.dnetlib.repo.manager.service.shared.broker.DatasourcesBroker; |
|
12 |
import eu.dnetlib.repo.manager.service.shared.broker.EventsPage; |
|
13 |
import org.json.JSONException; |
|
14 |
import org.json.JSONObject; |
|
15 |
import org.springframework.beans.factory.annotation.Autowired; |
|
16 |
import org.springframework.beans.factory.annotation.Value; |
|
17 |
import org.springframework.core.ParameterizedTypeReference; |
|
18 |
import org.springframework.http.HttpEntity; |
|
19 |
import org.springframework.http.HttpMethod; |
|
20 |
import org.springframework.http.ResponseEntity; |
|
21 |
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; |
|
22 |
import org.springframework.stereotype.Component; |
|
23 |
import org.springframework.util.LinkedMultiValueMap; |
|
24 |
import org.springframework.util.MultiValueMap; |
|
25 |
import org.springframework.web.bind.annotation.PathVariable; |
|
26 |
import org.springframework.web.client.RestClientException; |
|
27 |
import org.springframework.web.client.RestTemplate; |
|
28 |
import org.springframework.web.util.UriComponentsBuilder; |
|
29 |
|
|
30 |
import java.util.*; |
|
31 |
|
|
32 |
@Component |
|
33 |
public class BrokerApiImpl implements BrokerApi { |
|
34 |
|
|
35 |
|
|
36 |
@Autowired |
|
37 |
private RepositoryApiImpl repoAPI; |
|
38 |
@Value("${services.broker.url}:${services.broker.port}/${services.broker.api}${services.broker.openaire}") |
|
39 |
private String openairePath; |
|
40 |
|
|
41 |
@Override |
|
42 |
public DatasourcesBroker getDatasourcesOfUser(String params) throws JSONException { |
|
43 |
JSONObject json_params = new JSONObject(params); |
|
44 |
DatasourcesBroker ret = new DatasourcesBroker(); |
|
45 |
|
|
46 |
String userEmail = json_params.getString("userEmail"); |
|
47 |
boolean includeShared = json_params.getBoolean("includeShared"); |
|
48 |
boolean includeByOthers = json_params.getBoolean("includeByOthers"); |
|
49 |
|
|
50 |
try { |
|
51 |
ret.setDatasourcesOfUser(getDatasourcesOfUserType(getRepositoriesOfUser(userEmail))); |
|
52 |
if (includeShared) { |
|
53 |
//TODO whatever nikonas was saying |
|
54 |
List<String> sharedDatasourceIds = new ArrayList<String>(); |
|
55 |
ret.setSharedDatasources(getDatasourcesOfUserType(getRepositoriesByIds(sharedDatasourceIds))); |
|
56 |
} |
|
57 |
|
|
58 |
if (includeByOthers) { |
|
59 |
ret.setDatasourcesOfOthers(getDatasourcesOfUserType(getRepositoriesOfUser(userEmail))); |
|
60 |
} |
|
61 |
} catch (BrokerException e) { |
|
62 |
e.printStackTrace(); |
|
63 |
} |
|
64 |
|
|
65 |
return ret; |
|
66 |
} |
|
67 |
|
|
68 |
@Override |
|
69 |
public List<BrowseEntry> getTopicsForDatasource(@PathVariable("datasourceName") String datasourceName) throws BrokerException { |
|
70 |
final String service = "/topicsForDatasource"; |
|
71 |
|
|
72 |
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service) |
|
73 |
.queryParam("ds", datasourceName); |
|
74 |
|
|
75 |
RestTemplate template = new RestTemplate(); |
|
76 |
template.getMessageConverters().add(new MappingJackson2HttpMessageConverter()); |
|
77 |
ResponseEntity<List<BrowseEntry>> resp; |
|
78 |
try { |
|
79 |
resp = template.exchange( |
|
80 |
builder.build().encode().toUri(), |
|
81 |
HttpMethod.GET, |
|
82 |
null, |
|
83 |
new ParameterizedTypeReference<List<BrowseEntry>>() { |
|
84 |
}); |
|
85 |
} catch (RestClientException e) { |
|
86 |
throw new BrokerException(e); |
|
87 |
} |
|
88 |
|
|
89 |
return resp.getBody(); |
|
90 |
} |
|
91 |
|
|
92 |
@Override |
|
93 |
public EventsPage advancedShowEvents(String params) throws BrokerException, JSONException { |
|
94 |
JSONObject json_params = new JSONObject(params); |
|
95 |
|
|
96 |
long page = json_params.getLong("page"); |
|
97 |
long pagesize = json_params.getLong("pagesize"); |
|
98 |
|
|
99 |
JSONObject json_advQueryObject = json_params.getJSONObject("advQueryObject"); |
|
100 |
ObjectMapper obj = new ObjectMapper(); |
|
101 |
AdvQueryObject advQueryObject = new Gson().fromJson(json_advQueryObject.toString(),AdvQueryObject.class); |
|
102 |
|
|
103 |
|
|
104 |
final String service = "/events/{page}/{pageSize}"; |
|
105 |
|
|
106 |
Map<String, Long> uriParams = new HashMap<>(); |
|
107 |
uriParams.put("page", page); |
|
108 |
uriParams.put("pageSize", pagesize); |
|
109 |
|
|
110 |
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service); |
|
111 |
|
|
112 |
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>(); |
|
113 |
headers.add("Content-Type", "application/json"); |
|
114 |
|
|
115 |
advQueryObject.setPage(page); |
|
116 |
|
|
117 |
HttpEntity<AdvQueryObject> entity = new HttpEntity<>(advQueryObject, headers); |
|
118 |
|
|
119 |
RestTemplate template = new RestTemplate(); |
|
120 |
template.getMessageConverters().add(new MappingJackson2HttpMessageConverter()); |
|
121 |
ResponseEntity<EventsPage> resp; |
|
122 |
try { |
|
123 |
resp = template.exchange( |
|
124 |
builder.buildAndExpand(uriParams).encode().toUri(), |
|
125 |
HttpMethod.POST, |
|
126 |
entity, |
|
127 |
new ParameterizedTypeReference<EventsPage>() { |
|
128 |
} |
|
129 |
); |
|
130 |
} catch (RestClientException e) { |
|
131 |
throw new BrokerException(e); |
|
132 |
} |
|
133 |
return resp.getBody(); |
|
134 |
|
|
135 |
|
|
136 |
} |
|
137 |
|
|
138 |
|
|
139 |
private List<Tuple<BrowseEntry, String>> getDatasourcesOfUserType(List<Repository> repositories) throws BrokerException { |
|
140 |
|
|
141 |
List<Tuple<BrowseEntry, String>> entries = new ArrayList<>(); |
|
142 |
for (Repository repo : repositories) { |
|
143 |
BrowseEntry temp = new BrowseEntry(); |
|
144 |
temp.setValue(repo.getOfficialName()); |
|
145 |
temp.setSize(new Long(0)); |
|
146 |
for (BrowseEntry e : getTopicsForDatasource(repo.getOfficialName())) { |
|
147 |
temp.setSize(temp.getSize() + e.getSize()); |
|
148 |
} |
|
149 |
Tuple<BrowseEntry, String> tup = new Tuple<>(temp, repo.getLogoUrl()); |
|
150 |
entries.add(tup); |
|
151 |
} |
|
152 |
|
|
153 |
// sort the collection by the second field of the tuple which is size |
|
154 |
Collections.sort(entries, new Comparator<Tuple<BrowseEntry, String>>() { |
|
155 |
@Override |
|
156 |
public int compare(Tuple<BrowseEntry, String> e1, Tuple<BrowseEntry, String> e2) { |
|
157 |
return (int) (e2.getFirst().getSize().longValue() - e1.getFirst().getSize().longValue()); |
|
158 |
} |
|
159 |
}); |
|
160 |
|
|
161 |
return entries; |
|
162 |
} |
|
163 |
|
|
164 |
|
|
165 |
|
|
166 |
private List<Repository> getRepositoriesOfUser(String userEmail) throws JSONException { |
|
167 |
|
|
168 |
int page = 1; |
|
169 |
int size = 10; |
|
170 |
List<Repository> rs = null; |
|
171 |
List<Repository> resultSet = new ArrayList<>(); |
|
172 |
|
|
173 |
while (true){ |
|
174 |
rs = repoAPI.getRepositoriesOfUser(userEmail, String.valueOf(page), String.valueOf(size)); |
|
175 |
if(rs.size() == 0) break; |
|
176 |
resultSet.addAll(rs); |
|
177 |
} |
|
178 |
return resultSet; |
|
179 |
} |
|
180 |
|
|
181 |
private List<Repository> getRepositoriesByIds(List<String> sharedDatasourceIds) { |
|
182 |
return null; |
|
183 |
} |
|
184 |
|
|
185 |
} |
modules/uoa-repository-manager-service/src/main/java/eu/dnetlib/repo/manager/service/controllers/MonitorApi.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.controllers; |
|
2 |
|
|
3 |
import eu.dnetlib.api.functionality.ValidatorServiceException; |
|
4 |
import eu.dnetlib.domain.functionality.validator.StoredJob; |
|
5 |
import eu.dnetlib.repo.manager.service.shared.JobsOfUser; |
|
6 |
import org.json.JSONException; |
|
7 |
import org.json.JSONObject; |
|
8 |
import org.springframework.http.MediaType; |
|
9 |
import org.springframework.web.bind.annotation.*; |
|
10 |
|
|
11 |
import java.util.List; |
|
12 |
import java.util.Map; |
|
13 |
|
|
14 |
@RestController |
|
15 |
@RequestMapping(value = "/monitor") |
|
16 |
public interface MonitorApi { |
|
17 |
|
|
18 |
@RequestMapping(value = "/getJobsOfUser" , method = RequestMethod.GET,consumes = MediaType.APPLICATION_JSON_VALUE, |
|
19 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
20 |
@ResponseBody |
|
21 |
JobsOfUser getJobsOfUser(@RequestBody String user, |
|
22 |
@RequestBody String jobType, |
|
23 |
@RequestBody String offset, |
|
24 |
@RequestBody String limit, |
|
25 |
@RequestBody String dateFrom, |
|
26 |
@RequestBody String dateTo, |
|
27 |
@RequestBody String validationStatus, |
|
28 |
@RequestBody String includeJobsTotal) throws JSONException, ValidatorServiceException; |
|
29 |
|
|
30 |
@RequestMapping(value = "/getJobsOfUserPerValidationStatus" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) |
|
31 |
@ResponseBody |
|
32 |
int getJobsOfUserPerValidationStatus(@RequestBody String user, |
|
33 |
@RequestBody String jobType, |
|
34 |
@RequestBody String validationStatus) throws JSONException; |
|
35 |
|
|
36 |
@RequestMapping(value = "/getJobSummary" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) |
|
37 |
@ResponseBody |
|
38 |
StoredJob getJobSummary(@RequestBody String jobId, |
|
39 |
@RequestBody String groupBy) throws JSONException; |
|
40 |
|
|
41 |
} |
modules/uoa-repository-manager-service/src/main/java/eu/dnetlib/repo/manager/service/controllers/ValidatorApiImpl.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.controllers; |
|
2 |
|
|
3 |
import eu.dnetlib.api.functionality.ValidatorServiceException; |
|
4 |
import eu.dnetlib.domain.functionality.validator.StoredJob; |
|
5 |
import eu.dnetlib.repo.manager.service.utils.OaiTools; |
|
6 |
import gr.uoa.di.driver.util.ServiceLocator; |
|
7 |
import eu.dnetlib.domain.functionality.validator.JobForValidation; |
|
8 |
import eu.dnetlib.domain.functionality.validator.RuleSet; |
|
9 |
import eu.dnetlib.repo.manager.service.utils.Constants; |
|
10 |
|
|
11 |
import java.util.*; |
|
12 |
import java.util.concurrent.ConcurrentHashMap; |
|
13 |
import eu.dnetlib.api.functionality.ValidatorService; |
|
14 |
import org.apache.log4j.Logger; |
|
15 |
import org.json.JSONException; |
|
16 |
import org.json.JSONObject; |
|
17 |
import org.springframework.beans.factory.annotation.Autowired; |
|
18 |
import org.springframework.beans.factory.annotation.Qualifier; |
|
19 |
import org.springframework.beans.factory.annotation.Value; |
|
20 |
import org.springframework.stereotype.Component; |
|
21 |
import org.springframework.web.bind.annotation.PathVariable; |
|
22 |
|
|
23 |
import javax.annotation.PostConstruct; |
|
24 |
import javax.annotation.Resource; |
|
25 |
|
|
26 |
|
|
27 |
@Component |
|
28 |
public class ValidatorApiImpl implements ValidatorApi{ |
|
29 |
|
|
30 |
@Autowired |
|
31 |
private MonitorApiImpl monitorApi; |
|
32 |
|
|
33 |
@Resource(name = "validatorServiceLocator") |
|
34 |
private ServiceLocator<ValidatorService> validatorServiceLocator; |
|
35 |
|
|
36 |
private ValidatorService getValidationService() { |
|
37 |
return this.validatorServiceLocator.getService(); |
|
38 |
} |
|
39 |
|
|
40 |
public ServiceLocator<ValidatorService> getValidatorServiceLocator() { |
|
41 |
return validatorServiceLocator; |
|
42 |
} |
|
43 |
|
|
44 |
public void setValidatorServiceLocator(ServiceLocator<ValidatorService> validatorServiceLocator) { |
|
45 |
this.validatorServiceLocator = validatorServiceLocator; |
|
46 |
} |
|
47 |
|
|
48 |
private Map<String, List<RuleSet>> rulesetMap = new ConcurrentHashMap<String, List<RuleSet>>(); |
|
49 |
|
|
50 |
private static final Logger LOGGER = Logger |
|
51 |
.getLogger(ValidatorApiImpl.class); |
|
52 |
|
|
53 |
@PostConstruct |
|
54 |
private void loadRules(){ |
|
55 |
|
|
56 |
try { |
|
57 |
for (RuleSet ruleSet : getValidationService().getRuleSets()) { |
|
58 |
if (ruleSet.getVisibility() != null && ruleSet.getVisibility().contains("development")) { |
|
59 |
String key = ""; |
|
60 |
if (ruleSet.getGuidelinesAcronym().matches("^openaire[1-9].0_data$")) |
|
61 |
key = Constants.VALIDATION_MODE_DATA; |
|
62 |
else if (ruleSet.getGuidelinesAcronym().matches("^openaire[1-9].0$") || ruleSet.getGuidelinesAcronym().equals("driver")) |
|
63 |
key = Constants.VALIDATION_MODE_LITERATURE; |
|
64 |
else if (ruleSet.getGuidelinesAcronym().matches("^openaire[1-9].0_cris$")) |
|
65 |
key = Constants.VALIDATION_MODE_CRIS; |
|
66 |
|
|
67 |
if (rulesetMap.containsKey(key)) |
|
68 |
rulesetMap.get(key).add(ruleSet); |
|
69 |
else { |
|
70 |
List<RuleSet> ruleSets = new ArrayList<RuleSet>(); |
|
71 |
ruleSets.add(ruleSet); |
|
72 |
rulesetMap.put(key, ruleSets); |
|
73 |
} |
|
74 |
} |
|
75 |
} |
|
76 |
} catch (ValidatorServiceException e) { |
|
77 |
e.printStackTrace(); |
|
78 |
} |
|
79 |
|
|
80 |
} |
|
81 |
|
|
82 |
@Override |
|
83 |
public void submitJobForValidation(JobForValidation jobForValidation) { |
|
84 |
try { |
|
85 |
this.getValidationService().submitValidationJob(jobForValidation); |
|
86 |
} catch (ValidatorServiceException e) { |
|
87 |
e.printStackTrace(); |
|
88 |
} |
|
89 |
} |
|
90 |
|
|
91 |
@Override |
|
92 |
public void reSubmitJobForValidation(String jobId) throws JSONException { |
|
93 |
|
|
94 |
StoredJob job = monitorApi.getJobSummary(jobId,"all"); |
|
95 |
Set<Integer> contentRules = new HashSet<Integer>(); |
|
96 |
Set<Integer> usageRules = new HashSet<Integer>(); |
|
97 |
|
|
98 |
RuleSet ruleSet = null; |
|
99 |
for (List<RuleSet> ruleSets : this.rulesetMap.values()) { |
|
100 |
for (RuleSet rSet : ruleSets) |
|
101 |
if (rSet.getGuidelinesAcronym().equals(job.getDesiredCompatibilityLevel())) { |
|
102 |
ruleSet = rSet; |
|
103 |
break; |
|
104 |
} |
|
105 |
} |
|
106 |
|
|
107 |
for (int ruleId : job.getRules()) { |
|
108 |
if (ruleSet.getContentRulesIds().contains(ruleId)) |
|
109 |
contentRules.add(ruleId); |
|
110 |
else if (ruleSet.getUsageRulesIds().contains(ruleId)) |
|
111 |
usageRules.add(ruleId); |
|
112 |
} |
|
113 |
if (!contentRules.isEmpty()) |
|
114 |
job.setSelectedContentRules(contentRules); |
|
115 |
if (!usageRules.isEmpty()) |
|
116 |
job.setSelectedUsageRules(usageRules); |
|
117 |
this.submitJobForValidation(job); |
|
118 |
} |
|
119 |
|
|
120 |
@Override |
|
121 |
public List<RuleSet> getRuleSets(@PathVariable("mode") String mode) { |
|
122 |
return rulesetMap.get(mode); |
|
123 |
} |
|
124 |
|
|
125 |
@Override |
|
126 |
public List<String> getSetsOfRepository(String url) { |
|
127 |
try { |
|
128 |
return OaiTools.getSetsOfRepo(url); |
|
129 |
} catch (Exception e) { |
|
130 |
e.printStackTrace(); |
|
131 |
} |
|
132 |
return null; |
|
133 |
} |
|
134 |
|
|
135 |
} |
modules/uoa-repository-manager-service/src/main/java/eu/dnetlib/repo/manager/service/controllers/MonitorApiImpl.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.controllers; |
|
2 |
|
|
3 |
import eu.dnetlib.api.functionality.ValidatorService; |
|
4 |
import eu.dnetlib.api.functionality.ValidatorServiceException; |
|
5 |
import eu.dnetlib.domain.functionality.validator.StoredJob; |
|
6 |
import eu.dnetlib.repo.manager.service.shared.JobsOfUser; |
|
7 |
import eu.dnetlib.repo.manager.service.utils.Constants; |
|
8 |
import gr.uoa.di.driver.util.ServiceLocator; |
|
9 |
import org.apache.log4j.Logger; |
|
10 |
import org.json.JSONException; |
|
11 |
import org.springframework.stereotype.Component; |
|
12 |
import javax.annotation.Resource; |
|
13 |
|
|
14 |
@Component |
|
15 |
public class MonitorApiImpl implements MonitorApi { |
|
16 |
|
|
17 |
@Resource(name = "validatorServiceLocator") |
|
18 |
private ServiceLocator<ValidatorService> validatorServiceLocator; |
|
19 |
|
|
20 |
private ValidatorService getValidationService() { |
|
21 |
return this.validatorServiceLocator.getService(); |
|
22 |
} |
|
23 |
|
|
24 |
public ServiceLocator<ValidatorService> getValidatorServiceLocator() { |
|
25 |
return validatorServiceLocator; |
|
26 |
} |
|
27 |
|
|
28 |
public void setValidatorServiceLocator(ServiceLocator<ValidatorService> validatorServiceLocator) { |
|
29 |
this.validatorServiceLocator = validatorServiceLocator; |
|
30 |
} |
|
31 |
|
|
32 |
|
|
33 |
private static final Logger LOGGER = Logger |
|
34 |
.getLogger(MonitorApiImpl.class); |
|
35 |
|
|
36 |
@Override |
|
37 |
public JobsOfUser getJobsOfUser(String user, |
|
38 |
String jobType, |
|
39 |
String offset, |
|
40 |
String limit, |
|
41 |
String dateFrom, |
|
42 |
String dateTo, |
|
43 |
String validationStatus, |
|
44 |
String includeJobsTotal) throws JSONException, ValidatorServiceException { |
|
45 |
|
|
46 |
if (jobType.equals("")) |
|
47 |
jobType = null; |
|
48 |
if(dateFrom.equals("")) |
|
49 |
dateFrom = null; |
|
50 |
if(dateTo.equals("")) |
|
51 |
dateTo = null; |
|
52 |
if(validationStatus.equals("")) |
|
53 |
validationStatus = null; |
|
54 |
|
|
55 |
|
|
56 |
JobsOfUser retJobs = new JobsOfUser(); |
|
57 |
retJobs.setJobs(getValidationService().getStoredJobsNew(user, jobType, Integer.parseInt(offset), |
|
58 |
Integer.parseInt(limit), dateFrom, dateTo, validationStatus)); |
|
59 |
if (Boolean.parseBoolean(includeJobsTotal)) { |
|
60 |
retJobs.setTotalJobs(this.getJobsTotalNumberOfUser(user, jobType, null)); |
|
61 |
retJobs.setTotalJobsSuccessful(this.getJobsTotalNumberOfUser(user, jobType, Constants.VALIDATION_JOB_STATUS_SUCCESSFUL)); |
|
62 |
retJobs.setTotalJobsFailed(this.getJobsTotalNumberOfUser(user, jobType, Constants.VALIDATION_JOB_STATUS_FAILED)); |
|
63 |
retJobs.setTotalJobsOngoing(this.getJobsTotalNumberOfUser(user, jobType,Constants.VALIDATION_JOB_STATUS_ONGOING)); |
|
64 |
} |
|
65 |
return retJobs; |
|
66 |
|
|
67 |
} |
|
68 |
|
|
69 |
private int getJobsTotalNumberOfUser(String user, String jobType, String validationStatus) throws ValidatorServiceException { |
|
70 |
return getValidationService().getStoredJobsTotalNumberNew(user, jobType, validationStatus); |
|
71 |
} |
|
72 |
|
|
73 |
@Override |
|
74 |
public int getJobsOfUserPerValidationStatus(String user, |
|
75 |
String jobType, |
|
76 |
String validationStatus) throws JSONException { |
|
77 |
|
|
78 |
try { |
|
79 |
return getValidationService().getStoredJobsTotalNumberNew(user, jobType, validationStatus); |
|
80 |
} catch (ValidatorServiceException e) { |
|
81 |
e.printStackTrace(); |
|
82 |
} |
|
83 |
return 0; |
|
84 |
} |
|
85 |
|
|
86 |
@Override |
|
87 |
public StoredJob getJobSummary(String jobId, |
|
88 |
String groupBy) throws JSONException { |
|
89 |
|
|
90 |
try { |
|
91 |
return getValidationService().getStoredJob(Integer.parseInt(jobId), groupBy); |
|
92 |
} catch (ValidatorServiceException e) { |
|
93 |
e.printStackTrace(); |
|
94 |
} |
|
95 |
return null; |
|
96 |
} |
|
97 |
|
|
98 |
} |
modules/uoa-repository-manager-service/src/main/java/eu/dnetlib/repo/manager/service/controllers/RepositoryApi.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.controllers; |
|
2 |
|
|
3 |
import eu.dnetlib.domain.data.Repository; |
|
4 |
import eu.dnetlib.domain.data.RepositoryInterface; |
|
5 |
import eu.dnetlib.repo.manager.service.shared.Country; |
|
6 |
import org.json.JSONException; |
|
7 |
import org.springframework.http.MediaType; |
|
8 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
9 |
import org.springframework.web.bind.annotation.RequestMethod; |
|
10 |
import org.springframework.web.bind.annotation.ResponseBody; |
|
11 |
import org.springframework.web.bind.annotation.RestController; |
|
12 |
import java.util.List; |
|
13 |
import java.util.Map; |
|
14 |
import java.util.Set; |
|
15 |
|
|
16 |
@RestController |
|
17 |
@RequestMapping(value = "/repository") |
|
18 |
public interface RepositoryApi { |
|
19 |
|
|
20 |
@RequestMapping(value = "/getCountries", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) |
|
21 |
@ResponseBody |
|
22 |
Country[] getCountries() ; |
|
23 |
|
|
24 |
@RequestMapping(value = "/getRepositoriesByCountry/{country}", method = RequestMethod.GET, |
|
25 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
26 |
@ResponseBody |
|
27 |
Set<String> getRepositoriesByCountry(String country) throws JSONException; |
|
28 |
|
|
29 |
@RequestMapping(value = "/getRepositoriesOfUser/{userEmail}/{page}/{size}") |
|
30 |
@ResponseBody |
|
31 |
List<Repository> getRepositoriesOfUser( String userEmail, |
|
32 |
String page, |
|
33 |
String size) throws JSONException; |
|
34 |
|
|
35 |
@RequestMapping(value = "/getRepositoryById/{id}", method = RequestMethod.GET, |
|
36 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
37 |
@ResponseBody |
|
38 |
Repository getRepositoryById(String id) throws JSONException; |
|
39 |
|
|
40 |
@RequestMapping(value = "/getRepositoriesByName/{name}/{page}/{size}/", method = RequestMethod.GET, |
|
41 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
42 |
@ResponseBody |
|
43 |
List<Repository> getRepositoriesByName(String name, |
|
44 |
String page, |
|
45 |
String size) throws JSONException; |
|
46 |
|
|
47 |
@RequestMapping(value = "/getRepositoryInterface/{id}", method = RequestMethod.GET, |
|
48 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
49 |
@ResponseBody |
|
50 |
RepositoryInterface getRepositoyInterface(String id) throws JSONException; |
|
51 |
|
|
52 |
@RequestMapping(value = "/addRepository", method = RequestMethod.POST, |
|
53 |
consumes = MediaType.APPLICATION_JSON_VALUE) |
|
54 |
@ResponseBody |
|
55 |
String addRepository(Repository repository) throws JSONException; |
|
56 |
|
|
57 |
@RequestMapping(value = "/addInterface", method = RequestMethod.POST, |
|
58 |
consumes = MediaType.APPLICATION_JSON_VALUE) |
|
59 |
@ResponseBody |
|
60 |
String addRepositoryInterface(RepositoryInterface repositoryInterface) throws JSONException; |
|
61 |
|
|
62 |
@RequestMapping(value = "/getDnetCountries", method = RequestMethod.GET, |
|
63 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
64 |
@ResponseBody |
|
65 |
List<String> getDnetCountries(); |
|
66 |
|
|
67 |
@RequestMapping(value = "/getTypologies", method = RequestMethod.GET, |
|
68 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
69 |
@ResponseBody |
|
70 |
List<String> getTypologies(); |
|
71 |
|
|
72 |
@RequestMapping(value = "/getTimezones", method = RequestMethod.GET, |
|
73 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
74 |
@ResponseBody |
|
75 |
List<String> getTimezones(); |
|
76 |
|
|
77 |
@RequestMapping(value = "/updateManagedStatus", method = RequestMethod.POST, |
|
78 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
79 |
@ResponseBody |
|
80 |
String updateManagedStatus(String id,String managed); |
|
81 |
|
|
82 |
@RequestMapping(value = "/updateEnglishName", method = RequestMethod.POST, |
|
83 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
84 |
@ResponseBody |
|
85 |
String updateEnglishName(String id,String englishName); |
|
86 |
|
|
87 |
@RequestMapping(value = "/updateLatitude", method = RequestMethod.POST, |
|
88 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
89 |
@ResponseBody |
|
90 |
String updateLatitude(String id,String latitude); |
|
91 |
|
|
92 |
@RequestMapping(value = "/updateLongitude", method = RequestMethod.POST, |
|
93 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
94 |
@ResponseBody |
|
95 |
String updateLongitude(String id,String longitude); |
|
96 |
|
|
97 |
@RequestMapping(value = "/updateOfficialName", method = RequestMethod.POST, |
|
98 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
99 |
@ResponseBody |
|
100 |
String updateOfficialName(String id,String officialName); |
|
101 |
|
|
102 |
@RequestMapping(value = "/getUrlsOfUserRepos/{user_email}",method = RequestMethod.GET, |
|
103 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
104 |
@ResponseBody |
|
105 |
String getUrlsOfUserRepos(String user_email); |
|
106 |
|
|
107 |
@RequestMapping(value = "/getDatasourceVocabularies/{mode}",method = RequestMethod.GET, |
|
108 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
109 |
@ResponseBody |
|
110 |
List<String> getDatasourceVocabularies(String mode); |
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
} |
modules/uoa-repository-manager-service/src/main/java/eu/dnetlib/repo/manager/service/controllers/RepositoryApiImpl.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.controllers; |
|
2 |
|
|
3 |
import eu.dnetlib.domain.enabling.Vocabulary; |
|
4 |
import eu.dnetlib.repo.manager.service.shared.Country; |
|
5 |
import eu.dnetlib.repo.manager.service.utils.Converter; |
|
6 |
import eu.dnetlib.domain.data.Repository; |
|
7 |
import eu.dnetlib.domain.data.RepositoryInterface; |
|
8 |
import gr.uoa.di.driver.enabling.vocabulary.VocabularyLoader; |
|
9 |
import org.json.JSONArray; |
|
10 |
import org.json.JSONException; |
|
11 |
import org.json.JSONObject; |
|
12 |
import org.springframework.beans.factory.annotation.Autowired; |
|
13 |
import org.springframework.beans.factory.annotation.Value; |
|
14 |
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; |
|
15 |
import org.springframework.stereotype.Component; |
|
16 |
import org.springframework.web.bind.annotation.PathVariable; |
|
17 |
import org.springframework.web.bind.annotation.RequestBody; |
|
18 |
import org.springframework.web.bind.annotation.RequestParam; |
|
19 |
import org.springframework.web.client.RestTemplate; |
|
20 |
import org.springframework.web.util.UriComponents; |
|
21 |
import org.springframework.web.util.UriComponentsBuilder; |
|
22 |
|
|
23 |
import javax.annotation.PostConstruct; |
|
24 |
import java.util.*; |
|
25 |
import java.util.concurrent.ConcurrentHashMap; |
|
26 |
|
|
27 |
|
|
28 |
@Component |
|
29 |
public class RepositoryApiImpl implements RepositoryApi { |
|
30 |
|
|
31 |
@Value("${api.baseAddress}") |
|
32 |
private String baseAddress; |
|
33 |
|
|
34 |
private RestTemplate restTemplate = null; |
|
35 |
|
|
36 |
private final String[] vocabularyNames = {"dnet:countries", "dnet:datasource_typologies", "dnet:compatibilityLevel"}; |
|
37 |
|
|
38 |
@Autowired |
|
39 |
private VocabularyLoader vocabularyLoader; |
|
40 |
|
|
41 |
private Map<String, Vocabulary> vocabularyMap = new ConcurrentHashMap<String, Vocabulary>(); |
|
42 |
|
|
43 |
|
|
44 |
@PostConstruct |
|
45 |
private void init(){ |
|
46 |
restTemplate = new RestTemplate(); |
|
47 |
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter()); |
|
48 |
|
|
49 |
for (String vocName : vocabularyNames) { |
|
50 |
vocabularyMap.put(vocName, vocabularyLoader.getVocabulary(vocName, Locale.ENGLISH, Locale.ROOT)); |
|
51 |
} |
|
52 |
|
|
53 |
} |
|
54 |
|
|
55 |
@Override |
|
56 |
public Country[] getCountries() { |
|
57 |
UriComponents uriComponents = UriComponentsBuilder |
|
58 |
.fromHttpUrl(baseAddress + "/ds/countries") |
|
59 |
.build().encode(); |
|
60 |
return restTemplate.getForObject(uriComponents.toUri(),Country[].class); |
|
61 |
} |
|
62 |
|
|
63 |
|
|
64 |
@Override |
|
65 |
public Set<String> getRepositoriesByCountry(@PathVariable("country") String country) throws JSONException { |
|
66 |
|
|
67 |
|
|
68 |
int page = 1; |
|
69 |
int size = 10; |
|
70 |
String mode = "openaire____::opendoar"; |
|
71 |
|
|
72 |
UriComponents uriComponents = UriComponentsBuilder |
|
73 |
.fromHttpUrl(baseAddress + "/ds/search/country/") |
|
74 |
.path("/{page}/{size}/") |
|
75 |
.queryParam("country",country) |
|
76 |
.build().expand(page,size).encode(); |
|
77 |
|
|
78 |
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class); |
|
79 |
Set<String> resultSet = new HashSet<>(); |
|
80 |
while(!rs.equals("[]")){ |
|
81 |
List<Repository> rep = Converter.jsonToRepositoryList(new JSONArray(rs)); |
|
82 |
|
|
83 |
Collection<String> repos = this.getRepositoriesByMode(mode,rep); |
|
84 |
this.addRepos(resultSet,repos); |
|
85 |
|
|
86 |
page+=1; |
|
87 |
uriComponents = UriComponentsBuilder |
|
88 |
.fromHttpUrl(baseAddress + "/ds/search/country/") |
|
89 |
.path("/{page}/{size}/") |
|
90 |
.queryParam("country",country) |
|
91 |
.build().expand(page,size).encode(); |
|
92 |
rs = restTemplate.getForObject(uriComponents.toUri(), String.class); |
|
93 |
} |
|
94 |
|
|
95 |
return resultSet; |
|
96 |
} |
|
97 |
|
|
98 |
private void addRepos(Set<String> resultSet, Collection<String> repos) { |
|
99 |
for(String s : repos) |
|
100 |
if(!resultSet.contains(s)) |
|
101 |
resultSet.add(s); |
|
102 |
} |
|
103 |
|
|
104 |
private Collection<String> getRepositoriesByMode(String mode, List<Repository> rs) { |
|
105 |
|
|
106 |
List<String> reps = new ArrayList<>(); |
|
107 |
|
|
108 |
for(Repository r : rs) |
|
109 |
if(r.getCollectedFrom().equals(mode)) |
|
110 |
reps.add(r.getOfficialName()); |
|
111 |
|
|
112 |
return reps; |
|
113 |
} |
|
114 |
|
|
115 |
@Override |
|
116 |
public List<Repository> getRepositoriesOfUser(@PathVariable("userEmail") String userEmail, |
|
117 |
@PathVariable("page") String page, |
|
118 |
@PathVariable("size") String size) throws JSONException { |
|
119 |
|
|
120 |
UriComponents uriComponents = UriComponentsBuilder |
|
121 |
.fromHttpUrl(baseAddress + "/ds/search/email/") |
|
122 |
.path("/{page}/{size}/") |
|
123 |
.queryParam("contactemail",userEmail) |
|
124 |
.build().expand(page,size).encode(); |
|
125 |
|
|
126 |
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class); |
|
127 |
return Converter.jsonToRepositoryList(new JSONArray(rs)); |
|
128 |
} |
|
129 |
|
|
130 |
@Override |
|
131 |
public Repository getRepositoryById(@PathVariable("id") String id) throws JSONException { |
|
132 |
|
|
133 |
UriComponents uriComponents = UriComponentsBuilder |
|
134 |
.fromHttpUrl(baseAddress + "/ds/get/") |
|
135 |
.path("/{id}/") |
|
136 |
.build().expand(id).encode(); |
|
137 |
|
|
138 |
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class); |
|
139 |
return Converter.jsonToRepositoryObject(new JSONObject(rs)); |
|
140 |
} |
|
141 |
|
|
142 |
@Override |
|
143 |
public List<Repository> getRepositoriesByName(@PathVariable("name") String name, |
|
144 |
@PathVariable("page") String page, |
|
145 |
@PathVariable("size") String size) throws JSONException { |
|
146 |
UriComponents uriComponents = UriComponentsBuilder |
|
147 |
.fromHttpUrl(baseAddress + "/ds/search/name/") |
|
148 |
.path("/{page}/{size}") |
|
149 |
.queryParam("name",name) |
|
150 |
.build().expand(page,size).encode(); |
|
151 |
|
|
152 |
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class); |
|
153 |
return Converter.jsonToRepositoryList(new JSONArray(rs)); |
|
154 |
} |
|
155 |
|
|
156 |
@Override |
|
157 |
public RepositoryInterface getRepositoyInterface(@PathVariable("id") String id) throws JSONException { |
|
158 |
|
|
159 |
UriComponents uriComponents = UriComponentsBuilder |
|
160 |
.fromHttpUrl(baseAddress + "/ds/service/") |
|
161 |
.path("/{id}/") |
|
162 |
.build().expand(id).encode(); |
|
163 |
|
|
164 |
String rs = restTemplate.getForObject(uriComponents.toUri(),String.class); |
|
165 |
return Converter.jsonToRepositoryInterfaceObject(new JSONArray(rs).getJSONObject(0)); |
|
166 |
} |
|
167 |
|
|
168 |
@Override |
|
169 |
public String addRepository(@RequestBody Repository repository) throws JSONException { |
|
170 |
UriComponents uriComponents = UriComponentsBuilder |
|
171 |
.fromHttpUrl(baseAddress + "/ds/add/") |
|
172 |
.build() |
|
173 |
.encode(); |
|
174 |
return restTemplate.postForObject(uriComponents.toUri(),Converter.repositoryObjectToJson(repository),String.class); |
|
175 |
} |
|
176 |
|
|
177 |
@Override |
|
178 |
public String addRepositoryInterface(RepositoryInterface repositoryInterface) throws JSONException { |
|
179 |
UriComponents uriComponents = UriComponentsBuilder |
|
180 |
.fromHttpUrl(baseAddress + "/ds/service/add/") |
|
181 |
.build() |
|
182 |
.encode(); |
|
183 |
return restTemplate.postForObject(uriComponents.toUri(), Converter.repositoryInterfaceObjectToJson(repositoryInterface),String.class); |
|
184 |
} |
|
185 |
|
|
186 |
@Override |
|
187 |
public List<String> getDnetCountries() { |
|
188 |
return Converter.readFile("countries.txt"); |
|
189 |
} |
|
190 |
|
|
191 |
@Override |
|
192 |
public List<String> getTypologies() { |
|
193 |
return Converter.readFile("typologies.txt"); |
|
194 |
} |
|
195 |
|
|
196 |
@Override |
|
197 |
public List<String> getTimezones() { |
|
198 |
return Converter.readFile("timezones.txt"); |
|
199 |
} |
|
200 |
|
|
201 |
@Override |
|
202 |
public String updateManagedStatus(@RequestParam(value = "id") String id, |
|
203 |
@RequestParam(value = "managed") String managed) { |
|
204 |
|
|
205 |
UriComponents uriComponents = UriComponentsBuilder |
|
206 |
.fromHttpUrl(baseAddress + "/ds/manage/") |
|
207 |
.queryParam("id",id) |
|
208 |
.queryParam("managed",managed) |
|
209 |
.build().encode(); |
|
210 |
|
|
211 |
return restTemplate.postForObject(uriComponents.toUri(), null,String.class); |
|
212 |
} |
|
213 |
|
|
214 |
@Override |
|
215 |
public String updateEnglishName(@RequestParam(value = "id") String id, |
|
216 |
@RequestParam(value = "englishname") String englishName) { |
|
217 |
|
|
218 |
UriComponents uriComponents = UriComponentsBuilder |
|
219 |
.fromHttpUrl(baseAddress + "/ds/manage/") |
|
220 |
.queryParam("dsId",id) |
|
221 |
.queryParam("englishname",englishName) |
|
222 |
.build().encode(); |
|
223 |
return restTemplate.postForObject(uriComponents.toUri(), null,String.class); |
|
224 |
|
|
225 |
|
|
226 |
} |
|
227 |
|
|
228 |
@Override |
|
229 |
public String updateLatitude(@RequestParam(value = "id") String id, |
|
230 |
@RequestParam(value = "managed") String latitude) { |
|
231 |
|
|
232 |
UriComponents uriComponents = UriComponentsBuilder |
|
233 |
.fromHttpUrl(baseAddress + "/ds/manage/") |
|
234 |
.queryParam("dsId",id) |
|
235 |
.queryParam("latitude",latitude) |
|
236 |
.build().encode(); |
|
237 |
return restTemplate.postForObject(uriComponents.toUri(), null,String.class); |
|
238 |
} |
|
239 |
|
|
240 |
@Override |
|
241 |
public String updateLongitude(@RequestParam(value = "id") String id, |
|
242 |
@RequestParam(value = "longitude") String longitude) { |
|
243 |
|
|
244 |
UriComponents uriComponents = UriComponentsBuilder |
|
245 |
.fromHttpUrl(baseAddress + "/ds/manage/") |
|
246 |
.queryParam("dsId",id) |
|
247 |
.queryParam("longitude",longitude) |
|
248 |
.build().encode(); |
|
249 |
return restTemplate.postForObject(uriComponents.toUri(), null,String.class); |
|
250 |
} |
|
251 |
|
Also available in: Unified diff