Revision 57908
Added by Ioannis Diplas over 4 years ago
modules/uoa-repository-manager-service/branches/java_configuration/src/main/java/eu/dnetlib/repo/manager/service/customHystrixCommands/LastYearUsageStatsHystrixCommand.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.customHystrixCommands; |
|
2 |
|
|
3 |
import com.netflix.hystrix.HystrixCommand; |
|
4 |
import com.netflix.hystrix.HystrixCommandGroupKey; |
|
5 |
import org.springframework.http.HttpMethod; |
|
6 |
import org.springframework.http.ResponseEntity; |
|
7 |
import org.springframework.web.client.RestTemplate; |
|
8 |
import org.springframework.web.util.UriComponents; |
|
9 |
import org.springframework.web.util.UriComponentsBuilder; |
|
10 |
|
|
11 |
import java.util.HashMap; |
|
12 |
import java.util.List; |
|
13 |
import java.util.Map; |
|
14 |
|
|
15 |
public class LastYearUsageStatsHystrixCommand extends HystrixCommand<Map> { |
|
16 |
|
|
17 |
RestTemplate restTemplate; |
|
18 |
String usagestatsBaseAddress; |
|
19 |
|
|
20 |
public LastYearUsageStatsHystrixCommand(String usagestatsBaseAddress,RestTemplate restTemplate) { |
|
21 |
super(HystrixCommandGroupKey.Factory.asKey("StatisticsGroup")); |
|
22 |
this.usagestatsBaseAddress = usagestatsBaseAddress; |
|
23 |
this.restTemplate = restTemplate; |
|
24 |
} |
|
25 |
|
|
26 |
@Override |
|
27 |
protected Map run() throws Exception { |
|
28 |
UriComponents uriComponents = UriComponentsBuilder |
|
29 |
.fromHttpUrl(usagestatsBaseAddress + "/totals") |
|
30 |
.build().encode(); |
|
31 |
|
|
32 |
ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET,null,Map.class); |
|
33 |
|
|
34 |
List yearly_stats = (List) ((Map)rs.getBody()).get("yearly_stats"); |
|
35 |
Map lastYear = (Map) yearly_stats.get(yearly_stats.size()-1); |
|
36 |
Integer downloads = (Integer) lastYear.get("downloads"); |
|
37 |
Integer views = (Integer) lastYear.get("views"); |
|
38 |
Integer year = (Integer) lastYear.get("year"); |
|
39 |
|
|
40 |
Map<String,Object> usagestats = new HashMap<>(); |
|
41 |
usagestats.put("number",String.valueOf(downloads+views)); |
|
42 |
usagestats.put("year",year); |
|
43 |
|
|
44 |
return usagestats; |
|
45 |
} |
|
46 |
|
|
47 |
@Override |
|
48 |
protected Map getFallback() { |
|
49 |
return null; |
|
50 |
} |
|
51 |
|
|
52 |
} |
modules/uoa-repository-manager-service/branches/java_configuration/src/main/java/eu/dnetlib/repo/manager/service/customHystrixCommands/SoftwareHystrixCommand.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.customHystrixCommands; |
|
2 |
|
|
3 |
import com.netflix.hystrix.HystrixCommand; |
|
4 |
import com.netflix.hystrix.HystrixCommandGroupKey; |
|
5 |
import org.springframework.http.HttpMethod; |
|
6 |
import org.springframework.http.ResponseEntity; |
|
7 |
import org.springframework.web.client.RestTemplate; |
|
8 |
import org.springframework.web.util.UriComponents; |
|
9 |
import org.springframework.web.util.UriComponentsBuilder; |
|
10 |
|
|
11 |
import java.util.Map; |
|
12 |
|
|
13 |
public class SoftwareHystrixCommand extends HystrixCommand<String> { |
|
14 |
|
|
15 |
String baseAddress; |
|
16 |
RestTemplate restTemplate; |
|
17 |
|
|
18 |
public SoftwareHystrixCommand(String baseAddress, RestTemplate restTemplate) { |
|
19 |
super(HystrixCommandGroupKey.Factory.asKey("StatisticsGroup")); |
|
20 |
this.baseAddress = baseAddress; |
|
21 |
this.restTemplate = restTemplate; |
|
22 |
} |
|
23 |
|
|
24 |
@Override |
|
25 |
protected String run() { |
|
26 |
String url = baseAddress + "/software/count"; |
|
27 |
|
|
28 |
UriComponents uriComponents = UriComponentsBuilder |
|
29 |
.fromHttpUrl(url) |
|
30 |
.queryParam("page", 0) |
|
31 |
.queryParam("size", 0) |
|
32 |
.queryParam("format", "json") |
|
33 |
.build().encode(); |
|
34 |
|
|
35 |
ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class); |
|
36 |
Map metadata = (Map) (rs.getBody()); |
|
37 |
return String.valueOf(metadata.get("total")); |
|
38 |
} |
|
39 |
|
|
40 |
@Override |
|
41 |
protected String getFallback() { |
|
42 |
return null; |
|
43 |
} |
|
44 |
} |
modules/uoa-repository-manager-service/branches/java_configuration/src/main/java/eu/dnetlib/repo/manager/utils/OaiTools.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.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 |
|
|
8 |
import javax.net.ssl.*; |
|
9 |
import javax.xml.namespace.NamespaceContext; |
|
10 |
import javax.xml.xpath.XPath; |
|
11 |
import javax.xml.xpath.XPathExpressionException; |
|
12 |
import javax.xml.xpath.XPathFactory; |
|
13 |
import java.security.KeyManagementException; |
|
14 |
import java.security.NoSuchAlgorithmException; |
|
15 |
import java.security.cert.X509Certificate; |
|
16 |
import java.util.ArrayList; |
|
17 |
import java.util.Collections; |
|
18 |
import java.util.Iterator; |
|
19 |
import java.util.List; |
|
20 |
|
|
21 |
public class OaiTools { |
|
22 |
|
|
23 |
{ |
|
24 |
disableSslVerification(); |
|
25 |
} |
|
26 |
|
|
27 |
private static Logger LOGGER = Logger.getLogger(OaiTools.class); |
|
28 |
|
|
29 |
public static List<String> getSetsOfRepo(String baseUrl) throws Exception { |
|
30 |
try { |
|
31 |
LOGGER.debug("Getting sets of repository " + baseUrl); |
|
32 |
OaiPmhServer harvester = new OaiPmhServer(baseUrl); |
|
33 |
SetsList setList = harvester.listSets(); |
|
34 |
ResumptionToken token = setList.getResumptionToken(); |
|
35 |
List<Set> sets = new ArrayList<Set>(); |
|
36 |
sets.addAll(setList.asList()); |
|
37 |
while (token != null) { |
|
38 |
setList = harvester.listSets(token); |
|
39 |
token = setList.getResumptionToken(); |
|
40 |
sets.addAll(setList.asList()); |
|
41 |
} |
|
42 |
|
|
43 |
List<String> ret = new ArrayList<String>(); |
|
44 |
for (Set set : sets) { |
|
45 |
ret.add(set.getSpec().trim()); |
|
46 |
} |
|
47 |
if (ret.size() > 0 ) |
|
48 |
Collections.sort(ret); |
|
49 |
return ret; |
|
50 |
|
|
51 |
} catch (Exception e) { |
|
52 |
LOGGER.error("Error getting sets of repository " + baseUrl, e); |
|
53 |
return new ArrayList<String>(); |
|
54 |
//throw e; |
|
55 |
} |
|
56 |
} |
|
57 |
|
|
58 |
public static boolean identifyRepository(String baseUrl) throws Exception { |
|
59 |
LOGGER.debug("sending identify request to repo " + baseUrl); |
|
60 |
|
|
61 |
OaiPmhServer harvester = new OaiPmhServer(baseUrl); |
|
62 |
|
|
63 |
if (baseUrl.trim().isEmpty()) { |
|
64 |
return false; |
|
65 |
} |
|
66 |
|
|
67 |
try { |
|
68 |
Identification identification = harvester.identify(); |
|
69 |
DOMWriter d4Writer = new DOMWriter(); |
|
70 |
Document d = d4Writer.write(identification.getResponse()); |
|
71 |
|
|
72 |
return verifyIdentify(d); |
|
73 |
} catch (Exception e) { |
|
74 |
LOGGER.debug("Error verifying identify response", e); |
|
75 |
throw e; |
|
76 |
} |
|
77 |
} |
|
78 |
|
|
79 |
private static boolean verifyIdentify(Document doc) throws XPathExpressionException { |
|
80 |
NamespaceContext ctx = new NamespaceContext() { |
|
81 |
public String getNamespaceURI(String prefix) { |
|
82 |
String uri; |
|
83 |
if (prefix.equals("oai")) |
|
84 |
uri = "http://www.openarchives.org/OAI/2.0/"; |
|
85 |
else |
|
86 |
uri = null; |
|
87 |
return uri; |
|
88 |
} |
|
89 |
|
|
90 |
// Dummy implementation - not used! |
|
91 |
public Iterator<String> getPrefixes(String val) { |
|
92 |
return null; |
|
93 |
} |
|
94 |
|
|
95 |
// Dummy implemenation - not used! |
|
96 |
public String getPrefix(String uri) { |
|
97 |
return null; |
|
98 |
} |
|
99 |
}; |
|
100 |
|
|
101 |
// Now the XPath expression |
|
102 |
|
|
103 |
String xpathStr = "//oai:OAI-PMH/oai:Identify"; |
|
104 |
XPathFactory xpathFact = XPathFactory.newInstance(); |
|
105 |
XPath xpath = xpathFact.newXPath(); |
|
106 |
xpath.setNamespaceContext(ctx); |
|
107 |
String result = xpath.evaluate(xpathStr, doc); |
|
108 |
|
|
109 |
return (result != null && !result.equals("")); |
|
110 |
} |
|
111 |
|
|
112 |
private static void disableSslVerification() { |
|
113 |
try |
|
114 |
{ |
|
115 |
LOGGER.debug("disabling ssl verification"); |
|
116 |
// Create a trust manager that does not validate certificate chains |
|
117 |
TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() { |
|
118 |
public X509Certificate[] getAcceptedIssuers() { |
|
119 |
return null; |
|
120 |
} |
|
121 |
public void checkClientTrusted(X509Certificate[] certs, String authType) { |
|
122 |
} |
|
123 |
public void checkServerTrusted(X509Certificate[] certs, String authType) { |
|
124 |
} |
|
125 |
} |
|
126 |
}; |
|
127 |
|
|
128 |
// Install the all-trusting trust manager |
|
129 |
SSLContext sc = SSLContext.getInstance("SSL"); |
|
130 |
sc.init(null, trustAllCerts, new java.security.SecureRandom()); |
|
131 |
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); |
|
132 |
|
|
133 |
// Create all-trusting host name verifier |
|
134 |
HostnameVerifier allHostsValid = new HostnameVerifier() { |
|
135 |
public boolean verify(String hostname, SSLSession session) { |
|
136 |
return true; |
|
137 |
} |
|
138 |
}; |
|
139 |
|
|
140 |
// Install the all-trusting host verifier |
|
141 |
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); |
|
142 |
} catch (NoSuchAlgorithmException e) { |
|
143 |
LOGGER.error("disabling ssl verification", e); |
|
144 |
} catch (KeyManagementException e) { |
|
145 |
LOGGER.error("error while disabling ssl verification", e); |
|
146 |
} |
|
147 |
} |
|
148 |
} |
modules/uoa-repository-manager-service/branches/java_configuration/src/main/java/eu/dnetlib/repo/manager/service/customHystrixCommands/LiteratureHystrixCommand.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.customHystrixCommands; |
|
2 |
|
|
3 |
import com.netflix.hystrix.HystrixCommand; |
|
4 |
import com.netflix.hystrix.HystrixCommandGroupKey; |
|
5 |
import org.springframework.http.HttpMethod; |
|
6 |
import org.springframework.http.ResponseEntity; |
|
7 |
import org.springframework.web.client.RestTemplate; |
|
8 |
import org.springframework.web.util.UriComponents; |
|
9 |
import org.springframework.web.util.UriComponentsBuilder; |
|
10 |
|
|
11 |
import java.util.Map; |
|
12 |
|
|
13 |
public class LiteratureHystrixCommand extends HystrixCommand<String> { |
|
14 |
|
|
15 |
RestTemplate restTemplate; |
|
16 |
private String baseAddress; |
|
17 |
|
|
18 |
public LiteratureHystrixCommand(String baseAddress , RestTemplate restTemplate) { |
|
19 |
super(HystrixCommandGroupKey.Factory.asKey("StatisticsGroup")); |
|
20 |
this.baseAddress = baseAddress; |
|
21 |
this.restTemplate = restTemplate; |
|
22 |
} |
|
23 |
|
|
24 |
@Override |
|
25 |
protected String run() throws Exception { |
|
26 |
String url = baseAddress+"/resources"+ |
|
27 |
"?query= " + |
|
28 |
" oaftype exact datasource and " + |
|
29 |
" ( datasourcetypename exact Institutional Repository " + |
|
30 |
" or datasourcetypename exact Publication Repository )"; |
|
31 |
|
|
32 |
UriComponents uriComponents = UriComponentsBuilder |
|
33 |
.fromHttpUrl(url) |
|
34 |
.queryParam("page", 0) |
|
35 |
.queryParam("size", 0) |
|
36 |
.queryParam("format", "json") |
|
37 |
.build().encode(); |
|
38 |
|
|
39 |
ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class); |
|
40 |
Map metadata = (Map) ((Map) rs.getBody()).get("meta"); |
|
41 |
return String.valueOf(metadata.get("total")); |
|
42 |
} |
|
43 |
|
|
44 |
@Override |
|
45 |
protected String getFallback() { |
|
46 |
return null; |
|
47 |
} |
|
48 |
|
|
49 |
} |
modules/uoa-repository-manager-service/branches/java_configuration/src/main/java/eu/dnetlib/repo/manager/service/UserServiceImpl.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service; |
|
2 |
|
|
3 |
import org.mitre.openid.connect.model.OIDCAuthenticationToken; |
|
4 |
import org.springframework.beans.factory.annotation.Value; |
|
5 |
import org.springframework.http.HttpStatus; |
|
6 |
import org.springframework.http.ResponseEntity; |
|
7 |
import org.springframework.security.core.GrantedAuthority; |
|
8 |
import org.springframework.security.core.context.SecurityContextHolder; |
|
9 |
import org.springframework.stereotype.Service; |
|
10 |
|
|
11 |
import java.util.HashMap; |
|
12 |
import java.util.List; |
|
13 |
import java.util.Map; |
|
14 |
import java.util.stream.Collectors; |
|
15 |
|
|
16 |
@Service("userService") |
|
17 |
public class UserServiceImpl implements UserService { |
|
18 |
|
|
19 |
private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger |
|
20 |
.getLogger(UserServiceImpl.class); |
|
21 |
|
|
22 |
@Value("${oidc.issuer}") |
|
23 |
private String oidc_issuer; |
|
24 |
|
|
25 |
@Override |
|
26 |
public ResponseEntity<Object> login() { |
|
27 |
OIDCAuthenticationToken authentication = (OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); |
|
28 |
LOGGER.debug("User authentication : " + authentication); |
|
29 |
Map<String,Object> body = new HashMap<>(); |
|
30 |
body.put("sub",authentication.getSub()); |
|
31 |
if(authentication.getUserInfo().getName() == null || authentication.getUserInfo().getName().equals("")) |
|
32 |
body.put("name",authentication.getUserInfo().getGivenName() + " " + authentication.getUserInfo().getFamilyName()); |
|
33 |
else |
|
34 |
body.put("name",authentication.getUserInfo().getName()); |
|
35 |
|
|
36 |
body.put("email",authentication.getUserInfo().getEmail()); |
|
37 |
List<String> roles = authentication.getAuthorities().stream().map(GrantedAuthority::getAuthority).collect(Collectors.toList()); |
|
38 |
body.put("role",roles); |
|
39 |
|
|
40 |
return new ResponseEntity<>(body, HttpStatus.OK); |
|
41 |
} |
|
42 |
} |
modules/uoa-repository-manager-service/branches/java_configuration/src/main/java/eu/dnetlib/repo/manager/config/FrontEndLinkURIAuthenticationSuccessHandler.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.config; |
|
2 |
|
|
3 |
import com.google.gson.Gson; |
|
4 |
import com.google.gson.JsonObject; |
|
5 |
import org.apache.log4j.Logger; |
|
6 |
import org.mitre.openid.connect.model.OIDCAuthenticationToken; |
|
7 |
import org.springframework.beans.factory.annotation.Value; |
|
8 |
import org.springframework.security.core.Authentication; |
|
9 |
import org.springframework.security.web.authentication.AuthenticationSuccessHandler; |
|
10 |
|
|
11 |
import javax.servlet.ServletException; |
|
12 |
import javax.servlet.http.Cookie; |
|
13 |
import javax.servlet.http.HttpServletRequest; |
|
14 |
import javax.servlet.http.HttpServletResponse; |
|
15 |
import java.io.IOException; |
|
16 |
import java.net.URLEncoder; |
|
17 |
|
|
18 |
public class FrontEndLinkURIAuthenticationSuccessHandler implements AuthenticationSuccessHandler { |
|
19 |
|
|
20 |
private String frontEndURI; |
|
21 |
|
|
22 |
private static final Logger LOGGER = Logger |
|
23 |
.getLogger(FrontEndLinkURIAuthenticationSuccessHandler.class); |
|
24 |
|
|
25 |
public void init(){ |
|
26 |
LOGGER.debug("Front end uri : " + frontEndURI); |
|
27 |
} |
|
28 |
|
|
29 |
|
|
30 |
@Value("${aai.mode}") |
|
31 |
private String aai_mode; |
|
32 |
|
|
33 |
@Override |
|
34 |
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { |
|
35 |
|
|
36 |
OIDCAuthenticationToken authOIDC = (OIDCAuthenticationToken) authentication; |
|
37 |
JsonObject userInfo = new JsonObject(); |
|
38 |
|
|
39 |
if (authOIDC.getUserInfo().getSub() == null) |
|
40 |
userInfo.addProperty("sub", ""); |
|
41 |
else |
|
42 |
userInfo.addProperty("sub", URLEncoder.encode(authOIDC.getUserInfo().getSub(), "UTF-8")); |
|
43 |
|
|
44 |
|
|
45 |
if(authOIDC.getUserInfo().getName() != null) |
|
46 |
userInfo.addProperty("fullname", URLEncoder.encode(authOIDC.getUserInfo().getName(), "UTF-8")); |
|
47 |
|
|
48 |
if (authOIDC.getUserInfo().getGivenName() == null) |
|
49 |
userInfo.addProperty("firstname", ""); |
|
50 |
else |
|
51 |
userInfo.addProperty("firstname", URLEncoder.encode(authOIDC.getUserInfo().getGivenName(), "UTF-8") + ""); |
|
52 |
|
|
53 |
if (authOIDC.getUserInfo().getFamilyName() == null) |
|
54 |
userInfo.addProperty("lastname", ""); |
|
55 |
else |
|
56 |
userInfo.addProperty("lastname", URLEncoder.encode(authOIDC.getUserInfo().getFamilyName(), "UTF-8") + ""); |
|
57 |
|
|
58 |
userInfo.addProperty("email", authOIDC.getUserInfo().getEmail() + ""); |
|
59 |
if (authOIDC.getUserInfo().getSource().getAsJsonArray("edu_person_entitlements") == null) |
|
60 |
userInfo.addProperty("role", ""); |
|
61 |
else |
|
62 |
userInfo.addProperty("role", URLEncoder.encode(authOIDC.getUserInfo() |
|
63 |
.getSource().getAsJsonArray("edu_person_entitlements").toString(), "UTF-8") + ""); |
|
64 |
|
|
65 |
|
|
66 |
Cookie openAIREUser = new Cookie("openAIREUser", new Gson().toJson(userInfo) ); |
|
67 |
openAIREUser.setMaxAge(14400); |
|
68 |
openAIREUser.setPath("/"); |
|
69 |
if(aai_mode.equalsIgnoreCase("production") || aai_mode.equalsIgnoreCase("beta")) |
|
70 |
openAIREUser .setDomain(".openaire.eu"); |
|
71 |
// openAIREUser.setDomain(".athenarc.gr"); |
|
72 |
response.addCookie(openAIREUser); |
|
73 |
|
|
74 |
|
|
75 |
Cookie accessToken = new Cookie("AccessToken", authOIDC.getAccessTokenValue()); |
|
76 |
accessToken.setMaxAge(14400); |
|
77 |
if(aai_mode.equalsIgnoreCase("production") || aai_mode.equalsIgnoreCase("beta")) |
|
78 |
accessToken.setDomain(".openaire.eu"); |
|
79 |
accessToken.setPath("/"); |
|
80 |
|
|
81 |
// accessToken.setDomain(".athenarc.gr"); |
|
82 |
response.addCookie(accessToken); |
|
83 |
response.sendRedirect(frontEndURI); |
|
84 |
} |
|
85 |
|
|
86 |
public String getFrontEndURI() { |
|
87 |
return frontEndURI; |
|
88 |
} |
|
89 |
|
|
90 |
public void setFrontEndURI(String frontEndURI) { |
|
91 |
this.frontEndURI = frontEndURI; |
|
92 |
} |
|
93 |
} |
|
94 |
|
modules/uoa-repository-manager-service/branches/java_configuration/src/test/resources/application-context.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<beans xmlns="http://www.springframework.org/schema/beans" |
|
3 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|
4 |
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" |
|
5 |
xsi:schemaLocation="http://www.springframework.org/schema/beans |
|
6 |
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> |
|
7 |
|
|
8 |
|
|
9 |
<context:annotation-config/> |
|
10 |
<context:component-scan base-package="eu.dnetlib.repo.manager.service.*"/> |
|
11 |
|
|
12 |
<bean class="eu.dnetlib.repo.manager.config.CascadingPropertyLoader" |
|
13 |
id="propertyLoader"> |
|
14 |
<property name="order" value="2"/> |
|
15 |
<property name="properties"> |
|
16 |
<bean class="eu.dnetlib.conf.WebappContextProperyFactory"> |
|
17 |
<property name="propertyFetcher"> |
|
18 |
<bean class="eu.dnetlib.conf.PropertyFetcher"/> |
|
19 |
</property> |
|
20 |
</bean> |
|
21 |
</property> |
|
22 |
<property name="ignoreUnresolvablePlaceholders" value="true"/> |
|
23 |
<property name="locations"> |
|
24 |
<list> |
|
25 |
<value>classpath*:/gr/**/springContext-*.properties</value> |
|
26 |
<value>classpath*:/eu/**/springContext-*.properties</value> |
|
27 |
|
|
28 |
<value>classpath*:/application.properties</value> |
|
29 |
<value>classpath*:/email-texts.properties</value> |
|
30 |
|
|
31 |
<!-- <value>classpath*:dnet-site-wizard.properties</value>--> |
|
32 |
<!-- <value>classpath*:dnet-site-override.properties</value>--> |
|
33 |
<!-- <value>classpath*:dnet-wizard.properties</value>--> |
|
34 |
<!-- <value>classpath*:dnet-override-new.properties</value>--> |
|
35 |
<!-- <value>classpath*:dnet-validator-wizard.properties</value>--> |
|
36 |
<!-- <value>classpath*:dnet-validator-override.properties</value>--> |
|
37 |
<!-- <value>classpath*:dnet-site-force-override.properties</value>--> |
|
38 |
<!-- <value>classpath*:dnet-force-override.properties</value>--> |
|
39 |
</list> |
|
40 |
</property> |
|
41 |
</bean> |
|
42 |
</beans> |
modules/uoa-repository-manager-service/branches/java_configuration/src/main/java/eu/dnetlib/repo/manager/controllers/StatsController.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.controllers; |
|
2 |
|
|
3 |
import eu.dnetlib.repo.manager.service.StatsServiceImpl; |
|
4 |
import io.swagger.annotations.Api; |
|
5 |
import org.springframework.beans.factory.annotation.Autowired; |
|
6 |
import org.springframework.http.MediaType; |
|
7 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
8 |
import org.springframework.web.bind.annotation.RequestMethod; |
|
9 |
import org.springframework.web.bind.annotation.ResponseBody; |
|
10 |
import org.springframework.web.bind.annotation.RestController; |
|
11 |
|
|
12 |
import java.util.Map; |
|
13 |
|
|
14 |
@RestController |
|
15 |
@RequestMapping(value = "/stats") |
|
16 |
@Api(description = "Stats API", tags = {"statistics"}) |
|
17 |
public class StatsController { |
|
18 |
|
|
19 |
@Autowired |
|
20 |
private StatsServiceImpl statsService; |
|
21 |
|
|
22 |
@RequestMapping(value = "/getStatistics" , method = RequestMethod.GET, |
|
23 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
24 |
@ResponseBody |
|
25 |
public Map getStatistics(){ |
|
26 |
return statsService.getStatistics(); |
|
27 |
} |
|
28 |
} |
modules/uoa-repository-manager-service/branches/java_configuration/src/test/resources/applicationContext.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<beans xmlns="http://www.springframework.org/schema/beans" |
|
3 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|
4 |
xmlns:tx="http://www.springframework.org/schema/tx" |
|
5 |
xmlns:mvc="http://www.springframework.org/schema/mvc" |
|
6 |
xsi:schemaLocation="http://www.springframework.org/schema/beans |
|
7 |
|
|
8 |
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd |
|
9 |
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd |
|
10 |
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd"> |
|
11 |
|
|
12 |
<import resource="classpath*:/application-context.xml"/> |
|
13 |
|
|
14 |
<import resource="classpath*:/eu/dnetlib/soap/cxf/applicationContext-eprbuilders.xml"/> |
|
15 |
<import resource="classpath*:/eu/dnetlib/clients/ws/springContext-locatorFactory.xml"/> |
|
16 |
<import resource="classpath*:/gr/uoa/di/driver/util/springContext-locators.xml"/> |
|
17 |
<import resource="classpath*:/gr/uoa/di/driver/app/springContext-lookupFactory.xml"/> |
|
18 |
<import resource="classpath*:/gr/uoa/di/driver/app/springContext-lookupClients.xml"/> |
|
19 |
<import resource="classpath*:/eu/dnetlib/enabling/hcm/springContext-hcmService.xml"/> |
|
20 |
<import resource="classpath*:/gr/uoa/di/driver/app/springContext-commons.xml"/> |
|
21 |
|
|
22 |
<!--<import resource="classpath*:/gr/uoa/di/driver/app/springContext-registrator.xml"/>--> |
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
<bean id="maillib" class="eu.dnetlib.utils.MailLibrary" init-method="init"> |
|
28 |
<property name="mailhost" value="${services.validator.mail.host}"/> |
|
29 |
<property name="smtpPort" value="${services.validator.mail.port}"/> |
|
30 |
<property name="authenticate" value="${services.validator.mail.authenticate}"/> |
|
31 |
<property name="username" value="${services.validator.mail.username}"/> |
|
32 |
<property name="password" value="${services.validator.mail.password}"/> |
|
33 |
<property name="from" value="${services.validator.mail.fromAddress}"/> |
|
34 |
<property name="replyTo" value="${services.validator.mail.replyToAddress}"/> |
|
35 |
<property name="mode" value="${services.validator.mail.mode}"/> |
|
36 |
<property name="debug" value="${services.validator.mail.debug}"/> |
|
37 |
</bean> |
|
38 |
|
|
39 |
<bean class="eu.dnetlib.repo.manager.config.CascadingPropertyLoader" |
|
40 |
id="propertyLoader"> |
|
41 |
<property name="order" value="2"/> |
|
42 |
<property name="properties"> |
|
43 |
<bean class="eu.dnetlib.conf.WebappContextProperyFactory"> |
|
44 |
<property name="propertyFetcher"> |
|
45 |
<bean class="eu.dnetlib.conf.PropertyFetcher"/> |
|
46 |
</property> |
|
47 |
</bean> |
|
48 |
</property> |
|
49 |
<property name="ignoreUnresolvablePlaceholders" value="true"/> |
|
50 |
<property name="locations"> |
|
51 |
<list> |
|
52 |
<value>classpath*:/gr/**/springContext-*.properties</value> |
|
53 |
<value>classpath*:/eu/**/springContext-*.properties</value> |
|
54 |
|
|
55 |
<value>classpath*:/application.properties</value> |
|
56 |
<value>classpath*:/email-texts.properties</value> |
|
57 |
|
|
58 |
<!-- <value>classpath*:dnet-site-wizard.properties</value>--> |
|
59 |
<!-- <value>classpath*:dnet-site-override.properties</value>--> |
|
60 |
<!-- <value>classpath*:dnet-wizard.properties</value>--> |
|
61 |
<!-- <value>classpath*:dnet-override-new.properties</value>--> |
|
62 |
<!-- <value>classpath*:dnet-validator-wizard.properties</value>--> |
|
63 |
<!-- <value>classpath*:dnet-validator-override.properties</value>--> |
|
64 |
<!-- <value>classpath*:dnet-site-force-override.properties</value>--> |
|
65 |
<!-- <value>classpath*:dnet-force-override.properties</value>--> |
|
66 |
</list> |
|
67 |
</property> |
|
68 |
</bean> |
|
69 |
|
|
70 |
<bean id="repomanager.dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> |
|
71 |
<property name="driverClassName" value="${repomanager.db.driverClassName}" /> |
|
72 |
<property name="url" value="${repomanager.db.url}" /> |
|
73 |
<property name="username" value="${repomanager.db.username}" /> |
|
74 |
<property name="password" value="${repomanager.db.password}" /> |
|
75 |
<property name="maxIdle" value="10" /> |
|
76 |
<property name="maxActive" value="100" /> |
|
77 |
<property name="maxWait" value="10000" /> |
|
78 |
<property name="validationQuery" value="SELECT 1;" /> |
|
79 |
<property name="testOnBorrow" value="true" /> |
|
80 |
<property name="testOnReturn" value="true" /> |
|
81 |
<property name="testWhileIdle" value="true" /> |
|
82 |
<property name="timeBetweenEvictionRunsMillis" value="1200000" /> |
|
83 |
<property name="minEvictableIdleTimeMillis" value="1800000" /> |
|
84 |
<property name="numTestsPerEvictionRun" value="5" /> |
|
85 |
<property name="poolPreparedStatements" value="true" /> |
|
86 |
<property name="defaultAutoCommit" value="true" /> |
|
87 |
</bean> |
|
88 |
|
|
89 |
<tx:annotation-driven transaction-manager="txManager"/> |
|
90 |
|
|
91 |
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> |
|
92 |
<property name="dataSource" ref="repomanager.dataSource"/> |
|
93 |
</bean> |
|
94 |
|
|
95 |
<mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/"/> |
|
96 |
<mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/> |
|
97 |
<bean class="eu.dnetlib.repo.manager.config.SwaggerConfig"/> |
|
98 |
|
|
99 |
</beans> |
modules/uoa-repository-manager-service/branches/java_configuration/src/main/java/eu/dnetlib/repo/manager/config/AaiSecurityConfiguration.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.config; |
|
2 |
|
|
3 |
import org.mitre.oauth2.model.ClientDetailsEntity.AuthMethod; |
|
4 |
import org.mitre.oauth2.model.RegisteredClient; |
|
5 |
import org.mitre.openid.connect.client.OIDCAuthenticationFilter; |
|
6 |
import org.mitre.openid.connect.client.OIDCAuthenticationProvider; |
|
7 |
import org.mitre.openid.connect.client.service.impl.*; |
|
8 |
import org.mitre.openid.connect.config.ServerConfiguration; |
|
9 |
import org.springframework.beans.factory.annotation.Value; |
|
10 |
import org.springframework.context.annotation.Bean; |
|
11 |
import org.springframework.context.annotation.Configuration; |
|
12 |
import org.springframework.security.authentication.AuthenticationManager; |
|
13 |
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; |
|
14 |
import org.springframework.security.config.annotation.web.builders.HttpSecurity; |
|
15 |
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; |
|
16 |
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; |
|
17 |
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint; |
|
18 |
import org.springframework.security.web.authentication.preauth.AbstractPreAuthenticatedProcessingFilter; |
|
19 |
|
|
20 |
import java.util.Collections; |
|
21 |
import java.util.HashMap; |
|
22 |
import java.util.HashSet; |
|
23 |
import java.util.Map; |
|
24 |
|
|
25 |
@Configuration |
|
26 |
@EnableWebSecurity |
|
27 |
public class AaiSecurityConfiguration extends WebSecurityConfigurerAdapter { |
|
28 |
|
|
29 |
@Value("${webapp.dev.front}") |
|
30 |
private String logoutSuccessUrl; |
|
31 |
|
|
32 |
@Value("${oidc.issuer}") |
|
33 |
private String oidcIssuer; |
|
34 |
|
|
35 |
@Value("${oidc.id}") |
|
36 |
private String oidcId; |
|
37 |
|
|
38 |
@Value("${oidc.secret}") |
|
39 |
private String oidcSecret; |
|
40 |
|
|
41 |
@Value("${oidc.dev.home}") |
|
42 |
private String oidcDevHome; |
|
43 |
|
|
44 |
@Value("${webapp.dev.front}") |
|
45 |
private String webAppFrontEnd; |
|
46 |
|
|
47 |
private Map<String, String> userRoles = new HashMap<String, String>(){{ |
|
48 |
put("urn:geant:openaire.eu:group:Super+Administrator#aai.openaire.eu", "ROLE_ADMIN"); |
|
49 |
put("urn:geant:openaire.eu:group:Content+Provider+Dashboard+Administrator#aai.openaire.eu","ROLE_PROVIDE_ADMIN"); |
|
50 |
}}; |
|
51 |
|
|
52 |
@Bean |
|
53 |
@Override |
|
54 |
public AuthenticationManager authenticationManagerBean() throws Exception { |
|
55 |
return authenticationManager(); |
|
56 |
} |
|
57 |
|
|
58 |
@Override |
|
59 |
protected void configure(AuthenticationManagerBuilder auth) throws Exception { |
|
60 |
auth.authenticationProvider(openIdConnectAuthenticationProvider()); |
|
61 |
} |
|
62 |
|
|
63 |
@Override |
|
64 |
protected void configure(HttpSecurity http) throws Exception { |
|
65 |
http.csrf().disable() |
|
66 |
.anonymous().disable() |
|
67 |
.authorizeRequests() |
|
68 |
.anyRequest().authenticated() |
|
69 |
.and() |
|
70 |
.httpBasic() |
|
71 |
.authenticationEntryPoint(authenticationEntryPoint()) |
|
72 |
.and() |
|
73 |
.logout().logoutUrl("/openid_logout") |
|
74 |
.invalidateHttpSession(true) |
|
75 |
.deleteCookies("openAIRESession") |
|
76 |
.logoutSuccessUrl(logoutSuccessUrl) |
|
77 |
.and() |
|
78 |
.addFilterBefore(openIdConnectAuthenticationFilter(), AbstractPreAuthenticatedProcessingFilter.class) |
|
79 |
; |
|
80 |
} |
|
81 |
|
|
82 |
@Bean |
|
83 |
public OIDCAuthenticationProvider openIdConnectAuthenticationProvider(){ |
|
84 |
OIDCAuthenticationProvider oidcProvider = new OIDCAuthenticationProvider(); |
|
85 |
oidcProvider.setAuthoritiesMapper(authoritiesMapper()); |
|
86 |
return oidcProvider; |
|
87 |
} |
|
88 |
|
|
89 |
@Bean |
|
90 |
public OpenAireProviderAuthoritiesMapper authoritiesMapper(){ |
|
91 |
OpenAireProviderAuthoritiesMapper authoritiesMapper = new OpenAireProviderAuthoritiesMapper(userRoles); |
|
92 |
return authoritiesMapper; |
|
93 |
} |
|
94 |
|
|
95 |
@Bean |
|
96 |
public StaticServerConfigurationService staticServerConfigurationService(){ |
|
97 |
StaticServerConfigurationService staticServerConfigurationService = new StaticServerConfigurationService(); |
|
98 |
Map<String, ServerConfiguration> servers = new HashMap<>(); |
|
99 |
servers.put(oidcIssuer, serverConfiguration()); |
|
100 |
staticServerConfigurationService.setServers(servers); |
|
101 |
return staticServerConfigurationService; |
|
102 |
} |
|
103 |
|
|
104 |
@Bean |
|
105 |
public StaticClientConfigurationService staticClientConfigurationService(){ |
|
106 |
StaticClientConfigurationService staticClientConfigurationService = new StaticClientConfigurationService(); |
|
107 |
Map<String, RegisteredClient> clients = new HashMap<>(); |
|
108 |
clients.put(oidcIssuer,registeredClient()); |
|
109 |
staticClientConfigurationService.setClients(clients); |
|
110 |
return staticClientConfigurationService; |
|
111 |
} |
|
112 |
|
|
113 |
@Bean |
|
114 |
public RegisteredClient registeredClient(){ |
|
115 |
RegisteredClient registeredClient = new RegisteredClient(); |
|
116 |
registeredClient.setClientId(oidcId); |
|
117 |
registeredClient.setClientSecret(oidcSecret); |
|
118 |
registeredClient.setScope(new HashSet<>(Collections.singletonList("openid"))); |
|
119 |
registeredClient.setTokenEndpointAuthMethod(AuthMethod.SECRET_BASIC); |
|
120 |
registeredClient.setRedirectUris(new HashSet<>(Collections.singletonList(oidcDevHome))); |
|
121 |
return registeredClient; |
|
122 |
} |
|
123 |
|
|
124 |
@Bean |
|
125 |
public StaticAuthRequestOptionsService staticAuthRequestOptionsService(){ |
|
126 |
return new StaticAuthRequestOptionsService(); |
|
127 |
} |
|
128 |
|
|
129 |
@Bean |
|
130 |
public PlainAuthRequestUrlBuilder plainAuthRequestUrlBuilder(){ |
|
131 |
return new PlainAuthRequestUrlBuilder(); |
|
132 |
} |
|
133 |
|
|
134 |
@Bean |
|
135 |
public ServerConfiguration serverConfiguration(){ |
|
136 |
ServerConfiguration serverConfiguration = new ServerConfiguration(); |
|
137 |
serverConfiguration.setIssuer(oidcIssuer); |
|
138 |
serverConfiguration.setAuthorizationEndpointUri(oidcIssuer+"authorize"); |
|
139 |
serverConfiguration.setTokenEndpointUri(oidcIssuer+"token"); |
|
140 |
serverConfiguration.setUserInfoUri(oidcIssuer+"userinfo"); |
|
141 |
serverConfiguration.setJwksUri(oidcIssuer+"jwk"); |
|
142 |
serverConfiguration.setRevocationEndpointUri(oidcIssuer+"revoke"); |
|
143 |
return serverConfiguration; |
|
144 |
} |
|
145 |
|
|
146 |
@Bean |
|
147 |
public LoginUrlAuthenticationEntryPoint authenticationEntryPoint(){ |
|
148 |
return new LoginUrlAuthenticationEntryPoint("/openid_connect_login"); |
|
149 |
} |
|
150 |
|
|
151 |
|
|
152 |
@Bean |
|
153 |
public OIDCAuthenticationFilter openIdConnectAuthenticationFilter() throws Exception { |
|
154 |
OIDCAuthenticationFilter oidc = new OIDCAuthenticationFilter(); |
|
155 |
oidc.setAuthenticationManager(authenticationManagerBean()); |
|
156 |
oidc.setIssuerService(staticSingleIssuerService()); |
|
157 |
oidc.setServerConfigurationService(staticServerConfigurationService()); |
|
158 |
oidc.setClientConfigurationService(staticClientConfigurationService()); |
|
159 |
oidc.setAuthRequestOptionsService(staticAuthRequestOptionsService()); |
|
160 |
oidc.setAuthRequestUrlBuilder(plainAuthRequestUrlBuilder()); |
|
161 |
oidc.setAuthenticationSuccessHandler(frontEndRedirect()); |
|
162 |
return oidc; |
|
163 |
} |
|
164 |
|
|
165 |
@Bean |
|
166 |
public StaticSingleIssuerService staticSingleIssuerService(){ |
|
167 |
StaticSingleIssuerService staticSingleIssuerService = new StaticSingleIssuerService(); |
|
168 |
staticSingleIssuerService.setIssuer(oidcIssuer); |
|
169 |
return staticSingleIssuerService; |
|
170 |
} |
|
171 |
|
|
172 |
@Bean(initMethod = "init") |
|
173 |
public FrontEndLinkURIAuthenticationSuccessHandler frontEndRedirect(){ |
|
174 |
FrontEndLinkURIAuthenticationSuccessHandler frontEnd = new FrontEndLinkURIAuthenticationSuccessHandler(); |
|
175 |
frontEnd.setFrontEndURI(webAppFrontEnd); |
|
176 |
return frontEnd; |
|
177 |
} |
|
178 |
|
|
179 |
} |
modules/uoa-repository-manager-service/branches/java_configuration/src/test/java/unitest/ValidatorTest.java | ||
---|---|---|
1 |
//package unitest; |
|
2 |
// |
|
3 |
//import eu.dnetlib.repo.manager.config.RepoManagerContextLoaderListener; |
|
4 |
//import eu.dnetlib.repo.manager.utils.OaiTools; |
|
5 |
//import org.junit.Test; |
|
6 |
//import org.junit.runner.RunWith; |
|
7 |
//import org.springframework.test.context.ContextConfiguration; |
|
8 |
//import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
|
9 |
// |
|
10 |
//@RunWith(SpringJUnit4ClassRunner.class) |
|
11 |
//@ContextConfiguration(classes = RepoManagerContextLoaderListener.class) |
|
12 |
////@WebAppConfiguration |
|
13 |
//public class ValidatorTest { |
|
14 |
// |
|
15 |
// |
|
16 |
// @Test |
|
17 |
// public void identiFy(){ |
|
18 |
// |
|
19 |
// String url = "https://repozitorij.srce.unizg.hr/oai"; |
|
20 |
// |
|
21 |
// |
|
22 |
// System.out.println("Identify repository with url : " + url); |
|
23 |
// try { |
|
24 |
// System.out.println(OaiTools.identifyRepository(url)); |
|
25 |
// } catch (Exception e) { |
|
26 |
// System.out.println(e); |
|
27 |
// } |
|
28 |
// } |
|
29 |
// |
|
30 |
// |
|
31 |
//} |
modules/uoa-repository-manager-service/branches/java_configuration/src/main/java/eu/dnetlib/repo/manager/config/OpenAireProviderAuthoritiesMapper.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.config; |
|
2 |
|
|
3 |
import com.nimbusds.jwt.JWT; |
|
4 |
import org.mitre.openid.connect.client.OIDCAuthoritiesMapper; |
|
5 |
import org.mitre.openid.connect.model.UserInfo; |
|
6 |
import org.slf4j.Logger; |
|
7 |
import org.slf4j.LoggerFactory; |
|
8 |
import org.springframework.security.core.GrantedAuthority; |
|
9 |
import org.springframework.security.core.authority.SimpleGrantedAuthority; |
|
10 |
|
|
11 |
import java.util.*; |
|
12 |
|
|
13 |
public class OpenAireProviderAuthoritiesMapper implements OIDCAuthoritiesMapper { |
|
14 |
|
|
15 |
private static Logger logger = LoggerFactory.getLogger(OpenAireProviderAuthoritiesMapper.class); |
|
16 |
|
|
17 |
final private static String ROLE_CLAIMS = "edu_person_entitlements"; |
|
18 |
|
|
19 |
private Map<String,SimpleGrantedAuthority> userRolesMap; |
|
20 |
|
|
21 |
OpenAireProviderAuthoritiesMapper(Map<String,String> userRoles) { |
|
22 |
userRolesMap = new HashMap<>(); |
|
23 |
userRoles.forEach((openaireRole, appRole) -> userRolesMap.put(openaireRole, new SimpleGrantedAuthority(appRole))); |
|
24 |
} |
|
25 |
|
|
26 |
@Override |
|
27 |
public Collection<? extends GrantedAuthority> mapAuthorities(JWT idToken, UserInfo userInfo) { |
|
28 |
Set<GrantedAuthority> out = new HashSet<>(); |
|
29 |
out.add(new SimpleGrantedAuthority("ROLE_USER")); |
|
30 |
|
|
31 |
if(userInfo.getSource().getAsJsonArray(ROLE_CLAIMS) != null) { |
|
32 |
userInfo.getSource().getAsJsonArray(ROLE_CLAIMS).forEach(role -> { |
|
33 |
SimpleGrantedAuthority authority = userRolesMap.get(role.getAsString()); |
|
34 |
if (authority != null) { |
|
35 |
logger.debug("Role mapped " + role); |
|
36 |
out.add(authority); |
|
37 |
} |
|
38 |
}); |
|
39 |
} |
|
40 |
return out; |
|
41 |
} |
|
42 |
} |
modules/uoa-repository-manager-service/branches/java_configuration/src/test/java/unitest/PiwikTest.java | ||
---|---|---|
1 |
/* |
|
2 |
package unitest; |
|
3 |
|
|
4 |
import com.fasterxml.jackson.databind.ObjectMapper; |
|
5 |
import eu.dnetlib.repo.manager.config.RepoManagerContextLoaderListener; |
|
6 |
import org.apache.commons.lang.StringEscapeUtils; |
|
7 |
import org.junit.Test; |
|
8 |
import org.junit.runner.RunWith; |
|
9 |
import org.springframework.context.annotation.ComponentScan; |
|
10 |
import org.springframework.test.context.ContextConfiguration; |
|
11 |
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
|
12 |
|
|
13 |
import java.io.IOException; |
|
14 |
import java.io.UnsupportedEncodingException; |
|
15 |
import java.net.URL; |
|
16 |
import java.net.URLEncoder; |
|
17 |
import java.util.Map; |
|
18 |
|
|
19 |
@RunWith(SpringJUnit4ClassRunner.class) |
|
20 |
@ContextConfiguration(classes = RepoManagerContextLoaderListener.class) |
|
21 |
public class PiwikTest { |
|
22 |
|
|
23 |
String analyticsURL = "https://analytics.openaire.eu/addsite.php?"; |
|
24 |
|
|
25 |
@Test |
|
26 |
public void enableMetricsRepo1(){ |
|
27 |
|
|
28 |
String officialName = "BỘ SƯU TẬP SỐ"; |
|
29 |
String repoWebsite = "http://www.vnulib.edu.vn:8000/dspace/"; |
|
30 |
|
|
31 |
enableMetrics(officialName, repoWebsite, analyticsURL); |
|
32 |
|
|
33 |
} |
|
34 |
|
|
35 |
@Test |
|
36 |
public void enableMetricsRepo2(){ |
|
37 |
|
|
38 |
String officialName = "ILC4CLARIN repository of language resources and tools"; |
|
39 |
String repoWebsite = "https://dspace-clarin-it.ilc.cnr.it/repository/xmlui"; |
|
40 |
|
|
41 |
enableMetrics(officialName, repoWebsite, analyticsURL); |
|
42 |
} |
|
43 |
|
|
44 |
@Test |
|
45 |
public void enableMetricsRepo3(){ |
|
46 |
|
|
47 |
String officialName = "ANSTO Publications Online"; |
|
48 |
String repoWebsite = "http://apo.ansto.gov.au/dspace/"; |
|
49 |
|
|
50 |
enableMetrics(officialName, repoWebsite, analyticsURL); |
|
51 |
} |
|
52 |
|
|
53 |
private void enableMetrics(String officialName, String repoWebsite, String analyticsURL) { |
|
54 |
String url; |
|
55 |
try { |
|
56 |
url = analyticsURL + "siteName=" + URLEncoder.encode(officialName, "UTF-8") + "&url=" |
|
57 |
+ URLEncoder.encode(repoWebsite, "UTF-8"); |
|
58 |
url = StringEscapeUtils.escapeJava(url); |
|
59 |
|
|
60 |
Map map = null; |
|
61 |
String siteId = null; |
|
62 |
|
|
63 |
URL u = new URL(url); |
|
64 |
map = new ObjectMapper().readValue(u, Map.class); |
|
65 |
if(map.get("value")!=null) { |
|
66 |
siteId = map.get("value").toString(); |
|
67 |
} |
|
68 |
} catch (Exception e) { |
|
69 |
e.printStackTrace(); |
|
70 |
} |
|
71 |
} |
|
72 |
}*/ |
modules/uoa-repository-manager-service/branches/java_configuration/src/main/java/eu/dnetlib/repo/manager/service/RepositoryService.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service; |
|
2 |
|
|
3 |
import eu.dnetlib.api.functionality.ValidatorServiceException; |
|
4 |
import eu.dnetlib.domain.data.Repository; |
|
5 |
import eu.dnetlib.domain.data.RepositoryInterface; |
|
6 |
import eu.dnetlib.repo.manager.domain.*; |
|
7 |
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException; |
|
8 |
import org.json.JSONException; |
|
9 |
import org.springframework.security.core.Authentication; |
|
10 |
|
|
11 |
import java.io.IOException; |
|
12 |
import java.util.List; |
|
13 |
import java.util.Map; |
|
14 |
|
|
15 |
public interface RepositoryService { |
|
16 |
|
|
17 |
|
|
18 |
Country[] getCountries() ; |
|
19 |
|
|
20 |
List<RepositorySnippet> getRepositoriesByCountry(String country, String mode, Boolean managed) throws JSONException, IOException; |
|
21 |
|
|
22 |
List<Repository> getRepositoriesOfUser(String userEmail, |
|
23 |
String page, |
|
24 |
String size) throws JSONException, IOException; |
|
25 |
|
|
26 |
List<RepositorySnippet> getRepositoriesSnippetOfUser(String userEmail, String page, String size) throws IOException, JSONException; |
|
27 |
|
|
28 |
Repository getRepositoryById(String id) throws JSONException, ResourceNotFoundException; |
|
29 |
|
|
30 |
List<AggregationDetails> getRepositoryAggregations(String id, int from, int size) throws JSONException; |
|
31 |
|
|
32 |
Map<String,List<AggregationDetails>> getRepositoryAggregationsByYear(String id) throws JSONException; |
|
33 |
|
|
34 |
List<Repository> getRepositoriesByName(String name, |
|
35 |
String page, |
|
36 |
String size) throws JSONException; |
|
37 |
|
|
38 |
List<RepositorySnippet> searchRegisteredRepositories(String country, String typology, String englishName, |
|
39 |
String officialName, String requestSortBy, String order, |
|
40 |
int page, int pageSize) throws Exception; |
|
41 |
|
|
42 |
List<RepositoryInterface> getRepositoryInterface(String id) throws JSONException; |
|
43 |
|
|
44 |
Repository addRepository(String datatype, Repository repository) throws Exception; |
|
45 |
|
|
46 |
void deleteRepositoryInterface(String id, String registeredBy); |
|
47 |
|
|
48 |
RepositoryInterface addRepositoryInterface(String datatype, |
|
49 |
String repoId, |
|
50 |
String registeredBy, |
|
51 |
RepositoryInterface iFace) throws JSONException, ResourceNotFoundException, ValidatorServiceException; |
|
52 |
|
|
53 |
List<String> getDnetCountries(); |
|
54 |
|
|
55 |
List<String> getTypologies(); |
|
56 |
|
|
57 |
List<Timezone> getTimezones(); |
|
58 |
|
|
59 |
Repository updateRepository(Repository repository, Authentication authentication) throws Exception; |
|
60 |
|
|
61 |
List<String> getUrlsOfUserRepos(String user_email, |
|
62 |
String page, |
|
63 |
String size) throws JSONException; |
|
64 |
|
|
65 |
List<String> getDatasourceVocabularies(String mode); |
|
66 |
|
|
67 |
Map<String, String> getCompatibilityClasses(String mode); |
|
68 |
|
|
69 |
Map<String, String> getDatasourceClasses(String mode); |
|
70 |
|
|
71 |
String getCountryName(String countryCode); |
|
72 |
|
|
73 |
MetricsInfo getMetricsInfoForRepository(String repoId) throws RepositoryServiceException; |
|
74 |
|
|
75 |
Map<String, String> getListLatestUpdate(String mode) throws RepositoryServiceException, JSONException; |
|
76 |
|
|
77 |
RepositoryInterface updateRepositoryInterface(String repositoryId, String registeredBy, RepositoryInterface repositoryInterface) throws Exception; |
|
78 |
|
|
79 |
} |
modules/uoa-repository-manager-service/branches/java_configuration/src/main/java/eu/dnetlib/repo/manager/controllers/ValidatorController.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.controllers; |
|
2 |
|
|
3 |
import eu.dnetlib.api.functionality.ValidatorServiceException; |
|
4 |
import eu.dnetlib.domain.functionality.validator.JobForValidation; |
|
5 |
import eu.dnetlib.domain.functionality.validator.RuleSet; |
|
6 |
import eu.dnetlib.domain.functionality.validator.StoredJob; |
|
7 |
import eu.dnetlib.repo.manager.domain.InterfaceInformation; |
|
8 |
import eu.dnetlib.repo.manager.domain.ValidationServiceException; |
|
9 |
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException; |
|
10 |
import eu.dnetlib.repo.manager.service.EmailUtils; |
|
11 |
import eu.dnetlib.repo.manager.service.ValidatorServiceImpl; |
|
12 |
import io.swagger.annotations.Api; |
|
13 |
import io.swagger.annotations.ApiParam; |
|
14 |
import org.json.JSONException; |
|
15 |
import org.springframework.beans.factory.annotation.Autowired; |
|
16 |
import org.springframework.http.MediaType; |
|
17 |
import org.springframework.http.ResponseEntity; |
|
18 |
import org.springframework.security.access.prepost.PreAuthorize; |
|
19 |
import org.springframework.web.bind.annotation.*; |
|
20 |
|
|
21 |
import java.util.List; |
|
22 |
|
|
23 |
|
|
24 |
@RestController |
|
25 |
@RequestMapping(value = "/validator") |
|
26 |
@Api(description = "Validator API", tags = {"validator"}) |
|
27 |
public class ValidatorController { |
|
28 |
|
|
29 |
@Autowired |
|
30 |
private ValidatorServiceImpl validatorService; |
|
31 |
|
|
32 |
@Autowired |
|
33 |
private EmailUtils emailUtils; |
|
34 |
|
|
35 |
@RequestMapping(value = "/submitJobForValidation",method = RequestMethod.POST, |
|
36 |
consumes = MediaType.APPLICATION_JSON_VALUE, |
|
37 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
38 |
@ResponseBody |
|
39 |
@PreAuthorize("hasRole('ROLE_USER') and #jobForValidation.userEmail == authentication.userInfo.email") |
|
40 |
public JobForValidation submitJobForValidation(@RequestBody JobForValidation jobForValidation) throws ValidatorServiceException { |
|
41 |
return validatorService.submitJobForValidation(jobForValidation); |
|
42 |
} |
|
43 |
|
|
44 |
@RequestMapping(value = "/reSubmitJobForValidation/{email}/{jobId}",method = RequestMethod.POST, |
|
45 |
consumes = MediaType.APPLICATION_JSON_VALUE, |
|
46 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
47 |
@ResponseBody |
|
48 |
@PreAuthorize("hasRole('ROLE_USER') and #email == authentication.userInfo.email") |
|
49 |
public ResponseEntity<Object> reSubmitJobForValidation(@PathVariable("email") String email, |
|
50 |
@PathVariable("jobId") String jobId) throws JSONException, ValidatorServiceException { |
|
51 |
return validatorService.reSubmitJobForValidation(email, jobId); |
|
52 |
} |
|
53 |
|
|
54 |
@RequestMapping(value = "/getRuleSets/{mode}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) |
|
55 |
@ResponseBody |
|
56 |
public List<RuleSet> getRuleSets(@PathVariable("mode") String mode) { |
|
57 |
return validatorService.getRuleSets(mode); |
|
58 |
} |
|
59 |
|
|
60 |
@RequestMapping(value = "/getSetsOfRepository" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) |
|
61 |
@ResponseBody |
|
62 |
public List<String> getSetsOfRepository(@RequestParam(value = "url", required = true) String url) { |
|
63 |
return validatorService.getSetsOfRepository(url); |
|
64 |
} |
|
65 |
|
|
66 |
@RequestMapping(value = "/identifyRepository" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) |
|
67 |
@ResponseBody |
|
68 |
public boolean identifyRepo(@RequestParam(value = "url", required = true) String url) { |
|
69 |
return validatorService.identifyRepo(url); |
|
70 |
} |
|
71 |
|
|
72 |
@RequestMapping(value = "/getRuleSet/{acronym}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) |
|
73 |
@ResponseBody |
|
74 |
public RuleSet getRuleSet(@PathVariable("acronym") String acronym) { |
|
75 |
return validatorService.getRuleSet(acronym); |
|
76 |
} |
|
77 |
|
|
78 |
@RequestMapping(value = "/getStoredJobsNew" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) |
|
79 |
@ResponseBody |
|
80 |
@PreAuthorize("hasRole('ROLE_USER')") |
|
81 |
public List<StoredJob> getStoredJobsNew(@RequestParam("user") @ApiParam(value = "User email", required = true) String user, |
|
82 |
@RequestParam(value = "jobType", required = false) |
|
83 |
@ApiParam(value = "Equals to filter job type on validation history page") String jobType, |
|
84 |
@RequestParam("offset") @ApiParam(value = "Page number", required = true) String offset, |
|
85 |
@RequestParam(value = "limit", required = false,defaultValue = "10") @ApiParam(value = "Null value") String limit, |
|
86 |
@RequestParam(value = "dateFrom", required = false) @ApiParam(value = "Null value") String dateFrom, |
|
87 |
@RequestParam(value = "dateTo", required = false) @ApiParam(value = "Null value") String dateTo, |
|
88 |
@RequestParam("validationStatus") @ApiParam(value = "Equals to filter validation jobs", required = true) String validationStatus |
|
89 |
) throws ValidatorServiceException { |
|
90 |
return validatorService.getStoredJobsNew(user, jobType, offset, limit, dateFrom, dateTo, validationStatus); |
|
91 |
} |
|
92 |
|
|
93 |
@RequestMapping(value = "/getStoredJobsTotalNumberNew" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) |
|
94 |
@ResponseBody |
|
95 |
public int getStoredJobsTotalNumberNew(String user, String jobType, String validationStatus) throws ValidatorServiceException { |
|
96 |
return validatorService.getStoredJobsTotalNumberNew(user, jobType, validationStatus); |
|
97 |
} |
|
98 |
|
|
99 |
@RequestMapping(value = "/getInterfaceInformation" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) |
|
100 |
@ResponseBody |
|
101 |
public InterfaceInformation getInterfaceInformation(@RequestParam(value = "baseUrl") String baseUrl) throws ValidationServiceException { |
|
102 |
return validatorService.getInterfaceInformation(baseUrl); |
|
103 |
} |
|
104 |
|
|
105 |
@RequestMapping(value = "/validationSummary/{repoId}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) |
|
106 |
@ResponseBody |
|
107 |
public List<StoredJob> getInterfaceInformation(@PathVariable(value = "repoId") String repoId, @RequestParam(name = "size", defaultValue = "20") int size ) throws ValidatorServiceException, ResourceNotFoundException, JSONException { |
|
108 |
return validatorService.getJobsSummary(repoId,size); |
|
109 |
} |
|
110 |
|
|
111 |
|
|
112 |
@RequestMapping(value = "/complete" , method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) |
|
113 |
@ResponseBody |
|
114 |
public void validationCompleted( |
|
115 |
@RequestParam(value = "interfaceId") String interfaceId, |
|
116 |
@RequestParam(value = "repoId") String repoId, |
|
117 |
@RequestParam(value = "jobId") String jobId, |
|
118 |
@RequestParam(value = "issuerEmail") String issuerEmail, |
|
119 |
@RequestParam(value = "isUpdate") boolean isUpdate, |
|
120 |
@RequestParam(value = "isSuccess") boolean isSuccess, |
|
121 |
@RequestParam(value = "scoreUsage") int scoreUsage, |
|
122 |
@RequestParam(value = "scoreContent") int scoreContent) throws Exception { |
|
123 |
|
|
124 |
emailUtils.sendUponJobCompletion(repoId,interfaceId,scoreUsage,scoreContent,isSuccess,isUpdate,issuerEmail, jobId); |
|
125 |
} |
|
126 |
|
|
127 |
|
|
128 |
} |
modules/uoa-repository-manager-service/branches/java_configuration/src/main/java/eu/dnetlib/repo/manager/utils/Converter.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.utils; |
|
2 |
|
|
3 |
import com.fasterxml.jackson.core.JsonProcessingException; |
|
4 |
import com.fasterxml.jackson.databind.ObjectMapper; |
|
5 |
import eu.dnetlib.domain.data.Repository; |
|
6 |
import eu.dnetlib.domain.data.RepositoryInterface; |
|
7 |
import eu.dnetlib.repo.manager.domain.AggregationDetails; |
|
8 |
import eu.dnetlib.repo.manager.domain.RepositorySnippet; |
|
9 |
import eu.dnetlib.repo.manager.domain.Timezone; |
|
10 |
import org.apache.commons.codec.digest.DigestUtils; |
|
11 |
import org.apache.log4j.Logger; |
|
12 |
import org.json.JSONArray; |
|
13 |
import org.json.JSONException; |
|
14 |
import org.json.JSONObject; |
|
15 |
|
|
16 |
import java.io.BufferedReader; |
|
17 |
import java.io.IOException; |
|
18 |
import java.io.InputStream; |
|
19 |
import java.io.InputStreamReader; |
|
20 |
import java.text.ParseException; |
|
21 |
import java.text.SimpleDateFormat; |
|
22 |
import java.util.*; |
|
23 |
|
|
24 |
public class Converter { |
|
25 |
|
|
26 |
private static final Logger LOGGER = Logger.getLogger(Converter.class); |
|
27 |
|
|
28 |
public static Repository jsonToRepositoryObject(JSONObject repositoryObject) throws JSONException { |
|
29 |
|
|
30 |
Repository repository = new Repository(); |
|
31 |
|
|
32 |
JSONObject datasource = repositoryObject.getJSONObject("datasource"); |
|
33 |
|
|
34 |
//if( datasource.equals(null)) |
|
35 |
// return null; |
|
36 |
|
|
37 |
repository.setId(datasource.get("id").toString()); |
|
38 |
repository.setOfficialName(datasource.get("officialname").toString()); |
|
39 |
|
|
40 |
repository.setEnglishName( datasource.get("englishname").toString()); |
|
41 |
if(repository.getEnglishName().equals("null")) |
|
42 |
repository.setEnglishName(""); |
|
43 |
|
|
44 |
repository.setWebsiteUrl(datasource.get("websiteurl").toString()); |
|
45 |
if(repository.getWebsiteUrl().equals("null")) |
|
46 |
repository.setWebsiteUrl(""); |
|
47 |
|
|
48 |
repository.setLogoUrl(datasource.get("logourl").toString()); |
|
49 |
if(repository.getLogoUrl().equals("null")) |
|
50 |
repository.setLogoUrl(""); |
|
51 |
|
|
52 |
repository.setContactEmail(datasource.get("contactemail").toString()); |
|
53 |
if(repository.getContactEmail().equals("null")) |
|
54 |
repository.setContactEmail(""); |
|
55 |
|
|
56 |
|
|
57 |
repository.setLatitude( toDouble(datasource.get("latitude").toString())); |
|
58 |
repository.setLongitude(toDouble(datasource.get("longitude").toString())); |
|
59 |
Double timezone = toDouble(datasource.get("timezone").toString()); |
|
60 |
repository.setTimezone(timezone!=null?timezone:0.0); |
|
61 |
repository.setNamespacePrefix(datasource.get("namespaceprefix").toString()); |
|
62 |
repository.setOdLanguages(datasource.get("languages").toString()); |
|
63 |
repository.setDateOfValidation(convertStringToDate( datasource.get("dateofvalidation").toString())); |
|
64 |
|
|
65 |
/* typology -> platform |
|
66 |
* datasource class -> typology */ |
|
67 |
repository.setTypology(datasource.get("platform").toString()); |
|
68 |
if(repository.getTypology().equals("null")) |
|
69 |
repository.setTypology(""); |
|
70 |
repository.setDatasourceClass(datasource.get("typology").toString()); |
|
71 |
|
|
72 |
repository.setDateOfCollection(convertStringToDate( datasource.get("dateofcollection").toString())); |
|
73 |
repository.setActivationId(datasource.get("activationId").toString()); |
|
74 |
|
|
75 |
repository.setDescription(datasource.get("description").toString()); |
|
76 |
if(repository.getDescription().equals("null")) |
|
77 |
repository.setDescription(""); |
|
78 |
|
|
79 |
repository.setIssn(datasource.get("issn").toString()); |
|
80 |
repository.setLissn(datasource.get("lissn").toString()); |
|
81 |
if(repository.getLissn().equals("null")) |
|
82 |
repository.setLissn(""); |
|
83 |
repository.setEissn(datasource.get("eissn").toString()); |
|
84 |
if(repository.getEissn().equals("null")) |
|
85 |
repository.setEissn(""); |
|
86 |
repository.setRegisteredBy(datasource.get("registeredby").toString()); |
|
87 |
|
|
88 |
/* managed field */ |
|
89 |
repository.setRegistered(Boolean.parseBoolean(datasource.get("managed").toString())); |
|
90 |
|
|
91 |
//subjects |
|
92 |
|
|
93 |
repository.setAggregator(datasource.get("aggregator").toString()); |
|
94 |
repository.setCollectedFrom(datasource.get("collectedfrom").toString()); |
|
95 |
|
|
96 |
//TODO change organization to list |
|
97 |
JSONArray organizations = ((JSONArray)datasource.get("organizations")); |
|
98 |
if(organizations.length() != 0) { |
|
99 |
repository.setOrganization(((JSONArray) datasource.get("organizations")).getJSONObject(0).get("legalname").toString()); |
|
100 |
String countryCode = ((JSONArray) datasource.get("organizations")).getJSONObject(0).get("country").toString(); |
|
101 |
repository.setCountryCode(countryCode); |
|
102 |
} |
|
103 |
|
|
104 |
/* identities field */ |
|
105 |
|
|
106 |
return repository; |
|
107 |
} |
|
108 |
|
|
109 |
public static Date convertStringToDate(String date){ |
|
110 |
|
|
111 |
if(Objects.equals(date, "null")) |
|
112 |
return null; |
|
113 |
|
|
114 |
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); |
|
115 |
try { |
|
116 |
return formatter.parse(date); |
|
117 |
} catch (ParseException e) { |
|
118 |
LOGGER.error(e); |
|
119 |
} |
|
120 |
return null; |
|
121 |
} |
|
122 |
|
|
123 |
public static String convertDateToString(Date date){ |
|
124 |
|
|
125 |
if(Objects.equals(date, null)) |
|
126 |
return null; |
|
127 |
|
|
128 |
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); |
|
129 |
return formatter.format(date); |
|
130 |
} |
|
131 |
|
|
132 |
public static Double toDouble(String number){ |
|
133 |
if(Objects.equals(number, "null")) |
|
134 |
return 0.0; |
|
135 |
else |
|
136 |
return Double.valueOf(number); |
|
137 |
} |
|
138 |
|
|
139 |
public static List<RepositorySnippet> jsonToRepositorySnippetList(JSONObject json) throws JSONException { |
|
140 |
|
|
141 |
List<RepositorySnippet> resultSet = new ArrayList<>(); |
|
142 |
JSONArray rs = json.getJSONArray("datasourceInfo"); |
|
143 |
for(int i=0;i<rs.length();i++) |
|
144 |
resultSet.add(jsonToRepositorySnippetObject( rs.getJSONObject(i)) ); |
|
145 |
return resultSet; |
|
146 |
} |
|
147 |
|
|
148 |
private static RepositorySnippet jsonToRepositorySnippetObject(JSONObject repositorySnippetObject) throws JSONException { |
|
149 |
|
|
150 |
|
|
151 |
RepositorySnippet repositorySnippet = new RepositorySnippet(); |
|
152 |
|
|
153 |
// JSONObject datasource = repositorySnippetObject.getJSONObject("datasource"); |
|
154 |
|
|
155 |
|
|
156 |
repositorySnippet.setId(repositorySnippetObject.get("id").toString()); |
|
157 |
repositorySnippet.setOfficialname(repositorySnippetObject.get("officialname").toString()); |
|
158 |
|
|
159 |
repositorySnippet.setEnglishname( repositorySnippetObject.get("englishname").toString()); |
|
160 |
if(repositorySnippet.getEnglishname().equals("null")) |
|
161 |
repositorySnippet.setEnglishname(""); |
|
162 |
|
|
163 |
repositorySnippet.setWebsiteurl(repositorySnippetObject.get("websiteurl").toString()); |
|
164 |
if(repositorySnippet.getWebsiteurl().equals("null")) |
|
165 |
repositorySnippet.setWebsiteurl(""); |
|
166 |
|
|
167 |
repositorySnippet.setRegisteredby(repositorySnippetObject.get("registeredby").toString()); |
|
168 |
if(repositorySnippet.getRegisteredby().equals("null")) |
|
169 |
repositorySnippet.setRegisteredby(""); |
|
170 |
return repositorySnippet; |
|
171 |
|
|
172 |
} |
|
173 |
|
|
174 |
public static List<Repository> jsonToRepositoryList(JSONObject json) throws JSONException { |
|
175 |
|
|
176 |
List<Repository> resultSet = new ArrayList<>(); |
|
177 |
JSONArray rs = json.getJSONArray("datasourceInfo"); |
|
178 |
for(int i=0;i<rs.length();i++) |
|
179 |
resultSet.add(jsonToRepositoryObject( rs.getJSONObject(i)) ); |
|
180 |
return resultSet; |
|
181 |
} |
|
182 |
|
|
183 |
public static List<RepositoryInterface> jsonToRepositoryInterfaceList(JSONObject json) throws JSONException { |
|
184 |
|
|
185 |
List<RepositoryInterface> resultSet = new ArrayList<>(); |
|
186 |
JSONArray rs = json.getJSONArray("api"); |
|
187 |
for(int i=0;i<rs.length();i++) |
|
188 |
resultSet.add(jsonToRepositoryInterfaceObject( rs.getJSONObject(i)) ); |
|
189 |
return resultSet; |
|
190 |
} |
|
191 |
|
|
192 |
public static RepositoryInterface jsonToRepositoryInterfaceObject(JSONObject repositoryInterfaceObject) throws JSONException { |
|
193 |
|
|
194 |
RepositoryInterface repositoryInterface = new RepositoryInterface(); |
|
195 |
|
|
196 |
repositoryInterface.setId(repositoryInterfaceObject.get("id").toString()); |
|
197 |
repositoryInterface.setAccessProtocol(repositoryInterfaceObject.get("protocol").toString()); |
|
198 |
repositoryInterface.setContentDescription(repositoryInterfaceObject.get("contentdescription").toString()); |
|
199 |
repositoryInterface.setTypology(repositoryInterfaceObject.get("typology").toString()); |
|
200 |
repositoryInterface.setCompliance(repositoryInterfaceObject.get("compatibility").toString()); |
|
201 |
repositoryInterface.setLastCollectionDate(repositoryInterfaceObject.get("lastCollectionDate").toString()); |
|
202 |
|
|
203 |
repositoryInterface.setBaseUrl(repositoryInterfaceObject.get("baseurl").toString()); |
|
204 |
repositoryInterface.setRemovable(Boolean.parseBoolean(repositoryInterfaceObject.get("removable").toString())); |
|
205 |
|
|
206 |
|
|
207 |
// repositoryInterface.setMetadataIdentifierPath(repositoryInterfaceObject.get("metadataIdentifierPath").toString()); |
|
208 |
repositoryInterface.setDesiredCompatibilityLevel(repositoryInterfaceObject.get("compatibility").toString()); |
|
209 |
//repositoryInterface.setActive(Boolean.parseBoolean(repositoryInterfaceObject.get("active").toString())); |
|
210 |
|
|
211 |
|
|
212 |
Map<String, String> accessParams = new HashMap<>(); |
|
213 |
Map<String, String> extraFields = new HashMap<>(); |
|
214 |
|
|
215 |
ObjectMapper mapper = new ObjectMapper(); |
|
216 |
JSONArray apiparams = repositoryInterfaceObject.getJSONArray("apiParams"); |
|
217 |
|
|
218 |
for(int i=0;i<apiparams.length();i++) |
|
219 |
accessParams.put(apiparams.getJSONObject(i).getString("param"),apiparams.getJSONObject(i).getString("value")); |
|
220 |
|
|
221 |
repositoryInterface.setAccessParams(accessParams); |
|
222 |
|
|
223 |
return repositoryInterface; |
|
224 |
} |
|
225 |
|
|
226 |
public static String repositoryObjectToJson(Repository repository) throws JSONException, JsonProcessingException { |
|
227 |
|
|
228 |
HashMap<String,Object> repositoryMap = new HashMap<>(); |
|
229 |
ObjectMapper mapper = new ObjectMapper(); |
|
230 |
|
|
231 |
repositoryMap.put("id",repository.getId()); |
|
232 |
repositoryMap.put("openaireId",getOpenaireId(repository.getId())); |
|
233 |
repositoryMap.put("officialname",repository.getOfficialName()); |
|
234 |
repositoryMap.put("englishname",repository.getEnglishName()); |
|
235 |
repositoryMap.put("websiteurl",repository.getWebsiteUrl()); |
|
236 |
repositoryMap.put("logourl",repository.getLogoUrl()); |
|
237 |
repositoryMap.put("contactemail",repository.getContactEmail()); |
|
238 |
repositoryMap.put("longitude",repository.getLongitude().toString()); |
|
239 |
repositoryMap.put("latitude",repository.getLatitude().toString()); |
|
240 |
repositoryMap.put("timezone",repository.getTimezone()); |
|
241 |
|
|
242 |
repositoryMap.put("namespaceprefix",repository.getNamespacePrefix()!=null?repository.getNamespacePrefix():""); |
|
243 |
repositoryMap.put("languages",repository.getOdLanguages()!=null?repository.getOdLanguages():""); |
|
244 |
|
|
245 |
repositoryMap.put("dateofcollection",repository.getDateOfCollection()!=null?convertDateToString(repository.getDateOfCollection()):""); |
|
246 |
|
|
247 |
/* |
|
248 |
* typology -> platform |
|
249 |
* datasource class -> typology |
|
250 |
* */ |
|
251 |
repositoryMap.put("typology",repository.getDatasourceClass()); |
|
252 |
repositoryMap.put("platform",repository.getTypology()); |
|
253 |
|
|
254 |
repositoryMap.put("dateofvalidation",repository.getDateOfCollection()!=null?convertDateToString(repository.getDateOfCollection()):""); |
|
255 |
repositoryMap.put("activationId",repository.getActivationId()!=null?repository.getActivationId():""); |
|
256 |
|
|
257 |
repositoryMap.put("description",repository.getDescription()); |
|
258 |
|
|
259 |
repositoryMap.put("eissn",repository.getEissn()!=null?repository.getEissn():""); |
|
260 |
repositoryMap.put("issn",repository.getIssn()!=null?repository.getIssn():""); |
|
261 |
repositoryMap.put("lissn",repository.getLissn()!=null?repository.getLissn():""); |
|
262 |
|
|
263 |
repositoryMap.put("registeredby",repository.getRegisteredBy()); |
|
264 |
|
|
265 |
repositoryMap.put("aggregator",repository.getAggregator()!=null?repository.getAggregator():""); |
|
266 |
repositoryMap.put("collectedfrom",repository.getCollectedFrom()!=null?repository.getCollectedFrom():""); |
|
267 |
|
|
268 |
repositoryMap.put("managed",repository.isRegistered()); |
|
269 |
|
|
270 |
Map<String,String> organization = new HashMap<>(); |
|
271 |
organization.put("legalname",repository.getOrganization()); |
|
272 |
organization.put("country",repository.getCountryCode()); |
|
273 |
organization.put("legalshortname",""); |
|
274 |
organization.put("websiteurl",""); |
|
275 |
organization.put("logourl",""); |
|
276 |
|
|
277 |
List organizations = new ArrayList(); |
|
278 |
organizations.add(organization); |
|
279 |
repositoryMap.put("organizations",organizations); |
|
280 |
|
|
281 |
//TODO check identitites |
|
282 |
//Map<String,String> identity = new HashMap<>(); |
|
283 |
|
|
284 |
if (repository.getPiwikInfo() != null) { |
|
285 |
Map<String, Object> identity = new HashMap<>(); |
|
286 |
HashSet<Map<String, Object>> identities = new HashSet<>(); |
|
287 |
|
|
288 |
identity.put("issuertype", "piwik"); |
|
289 |
identity.put("pid", "piwik:" + repository.getPiwikInfo().getSiteId()); |
|
290 |
|
Also available in: Unified diff
Replacing XML configuration for Provide with Java equivalent