Revision 54843
Added by Panagiotis Kanakakis about 5 years ago
modules/uoa-repository-manager-service/trunk/src/main/java/eu/dnetlib/repo/manager/service/utils/EmailUtilsImpl.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.utils; |
|
2 |
|
|
3 |
import eu.dnetlib.domain.data.PiwikInfo; |
|
4 |
import eu.dnetlib.repo.manager.service.config.CascadingPropertyLoader; |
|
5 |
import eu.dnetlib.utils.MailLibrary; |
|
6 |
import org.apache.log4j.Logger; |
|
7 |
import org.springframework.beans.factory.annotation.Autowired; |
|
8 |
import org.springframework.beans.factory.annotation.Value; |
|
9 |
import org.springframework.stereotype.Component; |
|
10 |
|
|
11 |
import java.io.PrintWriter; |
|
12 |
import java.io.StringWriter; |
|
13 |
import java.io.Writer; |
|
14 |
import java.util.ArrayList; |
|
15 |
import java.util.List; |
|
16 |
|
|
17 |
|
|
18 |
@Component |
|
19 |
public class EmailUtilsImpl implements EmailUtils { |
|
20 |
|
|
21 |
private static Logger LOGGER = Logger.getLogger(EmailUtilsImpl.class); |
|
22 |
|
|
23 |
private List<String> specialRecipients = new ArrayList<String>(); |
|
24 |
private boolean override = false, logonly = false; |
|
25 |
private String overrideEmail = null, from = null; |
|
26 |
|
|
27 |
@Autowired |
|
28 |
private MailLibrary mailLibrary; |
|
29 |
|
|
30 |
@Autowired |
|
31 |
private CascadingPropertyLoader pLoader; |
|
32 |
|
|
33 |
@Value("${services.repo-manager.baseUrl}") |
|
34 |
private String baseUrl; |
|
35 |
|
|
36 |
@Value("${services.repo-manager.adminEmail}") |
|
37 |
private String adminEmail; |
|
38 |
|
|
39 |
@Value("${services.repomanager.usagestats.adminEmail}") |
|
40 |
private String usageStatsAdminEmail; |
|
41 |
|
|
42 |
|
|
43 |
@Override |
|
44 |
public void reportException(Exception exception) { |
|
45 |
Writer writer = new StringWriter(); |
|
46 |
PrintWriter printWriter = new PrintWriter(writer); |
|
47 |
exception.printStackTrace(printWriter); |
|
48 |
|
|
49 |
List<String> recipients = new ArrayList<String>(); |
|
50 |
|
|
51 |
try { |
|
52 |
recipients.add(this.adminEmail); |
|
53 |
String message = "An exception has occurred:\n"+writer.toString(); |
|
54 |
String subject = "Automatic Bug Report"; |
|
55 |
this.sendMail(recipients, subject, message, false, null); |
|
56 |
} catch (Exception e) { |
|
57 |
LOGGER.error("Error sending error report", e); |
|
58 |
} |
|
59 |
} |
|
60 |
|
|
61 |
@Override |
|
62 |
public void sendAdministratorRequestToEnableMetrics(PiwikInfo piwikInfo) throws Exception { |
|
63 |
|
|
64 |
try { |
|
65 |
String subject = "[OpenAIRE-Usage Statistics] New request to enable usage statistics"; |
|
66 |
|
|
67 |
String message = "Dear administrator,\n" + |
|
68 |
"\n" + |
|
69 |
"we have received a request to enable the OpenAIRE usage statistics for the following repository \n" + |
|
70 |
"\n" + |
|
71 |
"Repository - " + piwikInfo.getRepositoryName() + ", " + piwikInfo.getCountry() + " (" + piwikInfo.getRepositoryId() + ")\n" + |
|
72 |
"Requestor - " + piwikInfo.getRequestorName() + ", " + piwikInfo.getRequestorEmail() + "\n" + |
|
73 |
"Piwik ID - " + piwikInfo.getSiteId() + "\n" + |
|
74 |
"Authentication token - " + piwikInfo.getAuthenticationToken() + "\n" + |
|
75 |
"\n" + |
|
76 |
"For more information about this request, go here: \n" + |
|
77 |
this.baseUrl + "/#admin/metrics\n" + |
|
78 |
"\n" + |
|
79 |
"Best,\n" + |
|
80 |
"The OpenAIRE team"; |
|
81 |
|
|
82 |
this.sendMail(this.usageStatsAdminEmail, subject, message, false, null); |
|
83 |
|
|
84 |
} catch (Exception e) { |
|
85 |
LOGGER.error("Error while sending request to enable metrics email to administrator: " + this.usageStatsAdminEmail, e); |
|
86 |
throw e; |
|
87 |
} |
|
88 |
} |
|
89 |
|
|
90 |
@Override |
|
91 |
public void sendUserRequestToEnableMetrics(PiwikInfo piwikInfo) throws Exception { |
|
92 |
|
|
93 |
try { |
|
94 |
String subject = "[OpenAIRE-Usage Statistics] Your request to enable usage statistics"; |
|
95 |
|
|
96 |
String message = "Dear " + piwikInfo.getRequestorName() + ",\n" + |
|
97 |
"\n" + |
|
98 |
"we have received your request to enable the OpenAIRE usage statistics for your repository\n" + |
|
99 |
"\n" + |
|
100 |
"Repository - " + piwikInfo.getRepositoryName() + ", " + piwikInfo.getCountry() + " (" + piwikInfo.getRepositoryId() + ")\n" + |
|
101 |
"Piwik ID - " + piwikInfo.getSiteId() + "\n" + |
|
102 |
"Authentication token - " + piwikInfo.getAuthenticationToken() + "\n" + |
|
103 |
"\n" + |
|
104 |
"In order to enable the usage statistics, you must install the OpenAIRE's tracking code in your repository software. " + |
|
105 |
"OpenAIRE's usage statistics service tracking code is maintained on Github as a patch for various versions of DSpace " + |
|
106 |
"(https://github.com/openaire/OpenAIRE-Piwik-DSpace) and as an Eprints plugin for version 3 " + |
|
107 |
"(https://github.com/openaire/EPrints-OAPiwik). In case the platform is different from DSpace or EPrints please contact " + |
|
108 |
"the OpenAIRE team in repositoryusagestats@openaire.eu in order to find a solution.\n" + |
|
109 |
"\n" + |
|
110 |
"For more information about your request and configuration details, go here: \n" + |
|
111 |
this.baseUrl + "/#getImpact/instructions/" + piwikInfo.getRepositoryId() + "\n" + |
|
112 |
"\n" + |
|
113 |
"Once you have finished configuring your repository or if you have any questions, please notify the OpenAIRE team by sending \n" + |
|
114 |
"an email to repositoryusagestats@openaire.eu\n" + |
|
115 |
"\n" + |
|
116 |
"Best,\n" + |
|
117 |
"The OpenAIRE team"; |
|
118 |
|
|
119 |
this.sendMail(piwikInfo.getRequestorEmail(), subject, message, false, null); |
|
120 |
|
|
121 |
} catch (Exception e) { |
|
122 |
LOGGER.error("Error while sending request to enable metrics email to user: " + piwikInfo.getRequestorEmail(), e); |
|
123 |
throw e; |
|
124 |
} |
|
125 |
} |
|
126 |
|
|
127 |
@Override |
|
128 |
public void sendAdministratorMetricsEnabled(PiwikInfo piwikInfo) throws Exception { |
|
129 |
|
|
130 |
try { |
|
131 |
String subject = "[OpenAIRE-Usage Statistics] Usage statistics have been enabled"; |
|
132 |
|
|
133 |
String message = "Dear administrator,\n" + |
|
134 |
"\n" + |
|
135 |
"The installation and configuration of OpenAIRE's tracking code for the following repository " + |
|
136 |
"has been completed and validated and the usage statistics have been enabled in OpenAIRE.\n" + |
|
137 |
"\n" + |
|
138 |
"Repository - " + piwikInfo.getRepositoryName() + ", " + piwikInfo.getCountry() + " (" + piwikInfo.getRepositoryId() + ")\n" + |
|
139 |
"Requestor - " + piwikInfo.getRequestorName() + ", " + piwikInfo.getRequestorEmail() + "\n" + |
|
140 |
"Piwik ID - " + piwikInfo.getSiteId() + "\n" + |
|
141 |
"Authentication token - " + piwikInfo.getAuthenticationToken() + "\n" + |
|
142 |
"\n" + |
|
143 |
"Best,\n" + |
|
144 |
"The OpenAIRE team"; |
|
145 |
|
|
146 |
this.sendMail(piwikInfo.getRequestorEmail(), subject, message, false, null); |
|
147 |
|
|
148 |
} catch (Exception e) { |
|
149 |
LOGGER.error("Error while sending metrics enabled notification email to administator: " + this.usageStatsAdminEmail, e); |
|
150 |
throw e; |
|
151 |
} |
|
152 |
} |
|
153 |
|
|
154 |
@Override |
|
155 |
public void sendUserMetricsEnabled(PiwikInfo piwikInfo) throws Exception { |
|
156 |
|
|
157 |
try { |
|
158 |
String subject = "[OpenAIRE-Usage Statistics] Usage statistics have been enabled"; |
|
159 |
|
|
160 |
String message = "Dear " + piwikInfo.getRequestorName() + ",\n" + |
|
161 |
"\n" + |
|
162 |
"The installation and configuration of OpenAIRE's tracking code for your repository \"" + piwikInfo.getRepositoryName() + |
|
163 |
"\" has been completed and validated and the usage statistics have been enabled in OpenAIRE.\n" + |
|
164 |
"\n" + |
|
165 |
"You can preview the statistics in your repository's dashboard: \n" + |
|
166 |
this.baseUrl + "/#getImpact/" + piwikInfo.getRepositoryId() + "\n" + |
|
167 |
"\n" + |
|
168 |
" For more information and questions, you can contact the openaire support team by sending an email to " + |
|
169 |
"repositoryusagestats@openaire.eu\n" + |
|
170 |
"\n" + |
|
171 |
"Best,\n" + |
|
172 |
"The OpenAIRE team"; |
|
173 |
|
|
174 |
this.sendMail(piwikInfo.getRequestorEmail(), subject, message, false, null); |
|
175 |
|
|
176 |
} catch (Exception e) { |
|
177 |
LOGGER.error("Error while sending metrics enabled notification email to user: " + piwikInfo.getRequestorEmail(), e); |
|
178 |
throw e; |
|
179 |
} |
|
180 |
} |
|
181 |
|
|
182 |
private void sendMail(String email, String subject, String message, boolean sendToSpecial, List<String> repoAdminMails) throws Exception { |
|
183 |
ArrayList<String> to = new ArrayList<String>(); |
|
184 |
to.add(email); |
|
185 |
this.sendMail(to,subject,message,sendToSpecial,repoAdminMails); |
|
186 |
} |
|
187 |
|
|
188 |
private void sendMail(List<String> recipients, String subject, String message, boolean sendToSpecial, List<String> repoAdminMails) throws Exception { |
|
189 |
|
|
190 |
/* try { |
|
191 |
if (sendToSpecial) { |
|
192 |
recipients.addAll(this.specialRecipients); |
|
193 |
} |
|
194 |
|
|
195 |
if (repoAdminMails != null) |
|
196 |
recipients.addAll(repoAdminMails); |
|
197 |
|
|
198 |
if (this.override) { |
|
199 |
recipients.clear(); |
|
200 |
recipients.add(overrideEmail); |
|
201 |
} |
|
202 |
if (!logonly) |
|
203 |
mailLibrary.sendEmail(recipients.toArray(new String[]{}), subject, message); |
|
204 |
LOGGER.debug("Sending mail to Recipients: " + recipients + " Subject: " + subject + " Message: " + message); |
|
205 |
} catch (Exception e) { |
|
206 |
LOGGER.error("Error sending mail to Recipients: " + recipients + " Subject: " + subject + " Message: " + message, e); |
|
207 |
throw new Exception(e); |
|
208 |
}*/ |
|
209 |
} |
|
210 |
|
|
211 |
private String getEmailProperty(String key) { |
|
212 |
return pLoader.getProperties().getProperty(key); |
|
213 |
} |
|
214 |
|
|
215 |
public void setSpecialRecipients(String specialRecipients) { |
|
216 |
String[] recps = specialRecipients.split(","); |
|
217 |
|
|
218 |
for (String recp : recps) { |
|
219 |
recp = recp.trim(); |
|
220 |
|
|
221 |
this.specialRecipients.add(recp); |
|
222 |
} |
|
223 |
} |
|
224 |
|
|
225 |
|
|
226 |
public void setOverride(boolean override) { |
|
227 |
this.override = override; |
|
228 |
} |
|
229 |
|
|
230 |
public void setOverrideEmail(String overrideEmail) { |
|
231 |
this.overrideEmail = overrideEmail; |
|
232 |
} |
|
233 |
|
|
234 |
public String getFrom() { |
|
235 |
return from; |
|
236 |
} |
|
237 |
|
|
238 |
public void setFrom(String from) { |
|
239 |
this.from = from; |
|
240 |
} |
|
241 |
|
|
242 |
public boolean isLogonly() { |
|
243 |
return logonly; |
|
244 |
} |
|
245 |
|
|
246 |
public void setLogonly(boolean logonly) { |
|
247 |
this.logonly = logonly; |
|
248 |
} |
|
249 |
|
|
250 |
|
|
251 |
} |
modules/uoa-repository-manager-service/trunk/src/main/java/eu/dnetlib/repo/manager/service/utils/RequestFilter.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.utils; |
|
2 |
|
|
3 |
import com.fasterxml.jackson.annotation.JsonInclude; |
|
4 |
|
|
5 |
@JsonInclude(JsonInclude.Include.NON_NULL) |
|
6 |
public class RequestFilter{ |
|
7 |
|
|
8 |
private String registeredby = null; |
|
9 |
private String typology = null; |
|
10 |
private String country = null; |
|
11 |
private String id = null; |
|
12 |
private String officialname = null; |
|
13 |
|
|
14 |
|
|
15 |
public RequestFilter() { |
|
16 |
|
|
17 |
} |
|
18 |
|
|
19 |
public String getTypology() { |
|
20 |
return typology; |
|
21 |
} |
|
22 |
|
|
23 |
public void setTypology(String typology) { |
|
24 |
this.typology = typology; |
|
25 |
} |
|
26 |
|
|
27 |
public String getRegisteredby() { |
|
28 |
return registeredby; |
|
29 |
} |
|
30 |
|
|
31 |
public void setRegisteredby(String registeredby) { |
|
32 |
this.registeredby = registeredby; |
|
33 |
} |
|
34 |
|
|
35 |
public String getCountry() { |
|
36 |
return country; |
|
37 |
} |
|
38 |
|
|
39 |
public void setCountry(String country) { |
|
40 |
this.country = country; |
|
41 |
} |
|
42 |
|
|
43 |
public String getId() { |
|
44 |
return id; |
|
45 |
} |
|
46 |
|
|
47 |
public void setId(String id) { |
|
48 |
this.id = id; |
|
49 |
} |
|
50 |
|
|
51 |
public String getOfficialname() { |
|
52 |
return officialname; |
|
53 |
} |
|
54 |
|
|
55 |
public void setOfficialname(String officialname) { |
|
56 |
this.officialname = officialname; |
|
57 |
} |
|
58 |
} |
modules/uoa-repository-manager-service/trunk/src/main/java/eu/dnetlib/repo/manager/service/utils/FrontEndLinkURIAuthenticationSuccessHandler.java | ||
---|---|---|
1 |
/* |
|
2 |
package eu.dnetlib.repo.manager.service.utils; |
|
3 |
|
|
4 |
import org.mitre.openid.connect.model.OIDCAuthenticationToken; |
|
5 |
import org.springframework.security.core.Authentication; |
|
6 |
import org.springframework.security.web.authentication.AuthenticationSuccessHandler; |
|
7 |
|
|
8 |
import javax.servlet.ServletException; |
|
9 |
import javax.servlet.http.Cookie; |
|
10 |
import javax.servlet.http.HttpServletRequest; |
|
11 |
import javax.servlet.http.HttpServletResponse; |
|
12 |
import java.io.IOException; |
|
13 |
|
|
14 |
public class FrontEndLinkURIAuthenticationSuccessHandler implements AuthenticationSuccessHandler { |
|
15 |
|
|
16 |
private String frontEndURI; |
|
17 |
|
|
18 |
@Override |
|
19 |
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { |
|
20 |
OIDCAuthenticationToken authOIDC = (OIDCAuthenticationToken) authentication; |
|
21 |
Cookie sessionCookie = new Cookie("currentUser", authOIDC.getSub()); |
|
22 |
int expireSec = -1; |
|
23 |
sessionCookie.setMaxAge(expireSec); |
|
24 |
sessionCookie.setPath("/"); |
|
25 |
response.addCookie(sessionCookie); |
|
26 |
response.sendRedirect(frontEndURI); |
|
27 |
} |
|
28 |
|
|
29 |
public String getFrontEndURI() { |
|
30 |
return frontEndURI; |
|
31 |
} |
|
32 |
|
|
33 |
public void setFrontEndURI(String frontEndURI) { |
|
34 |
this.frontEndURI = frontEndURI; |
|
35 |
} |
|
36 |
} |
|
37 |
|
|
38 |
*/ |
modules/uoa-repository-manager-service/trunk/src/main/java/eu/dnetlib/repo/manager/service/utils/Config.java | ||
---|---|---|
1 |
/* |
|
2 |
package eu.dnetlib.repo.manager.service.utils; |
|
3 |
|
|
4 |
import org.springframework.beans.factory.annotation.Value; |
|
5 |
import org.springframework.context.annotation.Bean; |
|
6 |
import org.springframework.context.annotation.ComponentScan; |
|
7 |
import org.springframework.context.annotation.Configuration; |
|
8 |
import org.springframework.context.annotation.PropertySource; |
|
9 |
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; |
|
10 |
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; |
|
11 |
import org.springframework.session.web.http.CookieSerializer; |
|
12 |
import org.springframework.session.web.http.DefaultCookieSerializer; |
|
13 |
|
|
14 |
import javax.annotation.PostConstruct; |
|
15 |
import java.util.logging.Logger; |
|
16 |
|
|
17 |
@Configuration |
|
18 |
@EnableRedisHttpSession |
|
19 |
@PropertySource(value = { "classpath:eu/dnetlib/repo/manager/service/application.properties", "classpath:application.properties"} ) |
|
20 |
@ComponentScan(basePackages = "eu.dnetlib.repo.manager") |
|
21 |
public class Config { |
|
22 |
|
|
23 |
private static Logger LOGGER = Logger.getLogger(String.valueOf(Config.class)); |
|
24 |
|
|
25 |
@Value("${redis.host}") |
|
26 |
private String host; |
|
27 |
|
|
28 |
@Value("${redis.port:6379}") |
|
29 |
private String port; |
|
30 |
|
|
31 |
@Value("${redis.password:#{null}}") |
|
32 |
private String password; |
|
33 |
|
|
34 |
@PostConstruct |
|
35 |
private void init(){ |
|
36 |
LOGGER.info(host); |
|
37 |
} |
|
38 |
|
|
39 |
@Bean |
|
40 |
public LettuceConnectionFactory connectionFactory() { |
|
41 |
LOGGER.info(String.format("Redis connection listens to %s:%s",host,port)); |
|
42 |
LettuceConnectionFactory factory = new LettuceConnectionFactory(host,Integer.parseInt(port)); |
|
43 |
if(password != null) factory.setPassword(password); |
|
44 |
return factory; |
|
45 |
} |
|
46 |
|
|
47 |
@Bean |
|
48 |
public CookieSerializer cookieSerializer() { |
|
49 |
DefaultCookieSerializer serializer = new DefaultCookieSerializer(); |
|
50 |
serializer.setCookieName("SESSION"); // <1> |
|
51 |
serializer.setCookiePath("/"); // <2> |
|
52 |
return serializer; |
|
53 |
} |
|
54 |
|
|
55 |
} |
|
56 |
*/ |
modules/uoa-repository-manager-service/trunk/src/main/java/eu/dnetlib/repo/manager/service/utils/Converter.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.utils; |
|
2 |
|
|
3 |
import com.fasterxml.jackson.databind.ObjectMapper; |
|
4 |
import eu.dnetlib.domain.data.Repository; |
|
5 |
import eu.dnetlib.domain.data.RepositoryInterface; |
|
6 |
import eu.dnetlib.repo.manager.shared.*; |
|
7 |
import org.apache.log4j.Logger; |
|
8 |
import org.json.JSONArray; |
|
9 |
import org.json.JSONException; |
|
10 |
import org.json.JSONObject; |
|
11 |
|
|
12 |
import java.io.*; |
|
13 |
import java.text.ParseException; |
|
14 |
import java.text.SimpleDateFormat; |
|
15 |
import java.util.*; |
|
16 |
|
|
17 |
public class Converter { |
|
18 |
|
|
19 |
private static final Logger LOGGER = Logger.getLogger(Converter.class); |
|
20 |
|
|
21 |
public static Repository jsonToRepositoryObject(JSONObject repositoryObject) throws JSONException { |
|
22 |
|
|
23 |
Repository repository = new Repository(); |
|
24 |
|
|
25 |
|
|
26 |
LOGGER.debug("datasource response -> " + repositoryObject); |
|
27 |
JSONObject datasource = repositoryObject.getJSONObject("datasource"); |
|
28 |
|
|
29 |
if( datasource.equals(null)) |
|
30 |
return null; |
|
31 |
|
|
32 |
repository.setActivationId(datasource.get("activationId").toString()); |
|
33 |
repository.setAggregator(datasource.get("aggregator").toString()); |
|
34 |
repository.setCertificates(datasource.get("certificates").toString()); |
|
35 |
repository.setCitationGuidelineUrl(datasource.get("citationguidelineurl").toString()); |
|
36 |
repository.setCollectedFrom( datasource.get("collectedfrom").toString()); |
|
37 |
|
|
38 |
repository.setContactEmail(datasource.get("contactemail").toString()); |
|
39 |
if(repository.getContactEmail().equals("null")) |
|
40 |
repository.setContactEmail(""); |
|
41 |
|
|
42 |
repository.setDatabaseAccessRestriction(datasource.get("databaseaccessrestriction").toString()); |
|
43 |
repository.setDatabaseAccessType(datasource.get("databaseaccesstype").toString()); |
|
44 |
repository.setDataUploadRestriction(datasource.get("datauploadrestriction").toString()); |
|
45 |
repository.setDataUploadType(datasource.get("datauploadtype").toString()); |
|
46 |
repository.setDateOfCollection(convertStringToDate( datasource.get("dateofcollection").toString())); |
|
47 |
repository.setDateOfValidation(convertStringToDate( datasource.get("dateofvalidation").toString())); |
|
48 |
|
|
49 |
repository.setDescription(datasource.get("description").toString()); |
|
50 |
if(repository.getDescription().equals("null")) |
|
51 |
repository.setDescription(""); |
|
52 |
|
|
53 |
repository.setEissn(datasource.get("eissn").toString()); |
|
54 |
|
|
55 |
repository.setEnglishName( datasource.get("englishname").toString()); |
|
56 |
if(repository.getEnglishName().equals("null")) |
|
57 |
repository.setEnglishName(""); |
|
58 |
|
|
59 |
|
|
60 |
repository.setId(datasource.get("id").toString()); |
|
61 |
repository.setIssn(datasource.get("issn").toString()); |
|
62 |
repository.setOdLanguages(datasource.get("languages").toString()); |
|
63 |
repository.setLatitude( toDouble(datasource.get("latitude").toString())); |
|
64 |
repository.setLissn(datasource.get("lissn").toString()); |
|
65 |
|
|
66 |
repository.setLogoUrl(datasource.get("logourl").toString()); |
|
67 |
if(repository.getLogoUrl().equals("null")) |
|
68 |
repository.setLogoUrl(""); |
|
69 |
|
|
70 |
repository.setLongitude(toDouble(datasource.get("longitude").toString())); |
|
71 |
//datasource.get("managed"); |
|
72 |
repository.setMissionStatementUrl(datasource.get("missionstatementurl").toString()); |
|
73 |
repository.setNamespacePrefix(datasource.get("namespaceprefix").toString()); |
|
74 |
repository.setOdContentTypes(datasource.get("od_contenttypes").toString()); |
|
75 |
repository.setOfficialName(datasource.get("officialname").toString()); |
|
76 |
if(repository.getOfficialName().equals("null")) |
|
77 |
repository.setOfficialName(""); |
|
78 |
|
|
79 |
repository.setPidSystems(datasource.get("pidsystems").toString()); |
|
80 |
//datasource.get("platform"); |
|
81 |
repository.setProvenanceActionClass( datasource.get("provenanceaction").toString()); |
|
82 |
repository.setQualityManagementKind(datasource.get("qualitymanagementkind").toString()); |
|
83 |
repository.setRegisteredBy(datasource.get("registeredby").toString()); |
|
84 |
|
|
85 |
if(Objects.equals(repository.getRegisteredBy(),"null")) |
|
86 |
repository.setRegistered(true); |
|
87 |
|
|
88 |
repository.setReleaseEndDate(convertStringToDate(datasource.get("releaseenddate").toString())); |
|
89 |
repository.setReleaseStartDate(convertStringToDate(datasource.get("releasestartdate").toString())); |
|
90 |
repository.setServiceProvider(Boolean.valueOf(datasource.get("serviceprovider").toString())); |
|
91 |
//datasource.get("subjects"); |
|
92 |
Double timezone = toDouble(datasource.get("timezone").toString()); |
|
93 |
repository.setTimezone(timezone!=null?timezone:0.0); |
|
94 |
repository.setTypology(datasource.get("platform").toString()); |
|
95 |
repository.setVersioning(Boolean.valueOf(datasource.get("versioning").toString())); |
|
96 |
repository.setWebsiteUrl(datasource.get("websiteurl").toString()); |
|
97 |
repository.setDatasourceClass(datasource.get("typology").toString()); |
|
98 |
|
|
99 |
//TODO change organization to list |
|
100 |
repository.setOrganization( ((JSONArray)datasource.get("organizations")).getJSONObject(0).get("legalname").toString()); |
|
101 |
String countryCode = ((JSONArray)datasource.get("organizations")).getJSONObject(0).get("country").toString(); |
|
102 |
repository.setCountryCode(countryCode); |
|
103 |
|
|
104 |
|
|
105 |
String collectedFrom = datasource.get("collectedfrom").toString(); |
|
106 |
//TODO check data consistency |
|
107 |
String type = "UNKNOWN"; |
|
108 |
if (collectedFrom.equalsIgnoreCase("openaire____::opendoar")) { |
|
109 |
type = "opendoar"; |
|
110 |
} else if (collectedFrom.equalsIgnoreCase("openaire____::re3data")) { |
|
111 |
type = "re3data"; |
|
112 |
} else if (collectedFrom.equalsIgnoreCase("infrastruct_::openaire")) { |
|
113 |
type = "journal"; |
|
114 |
} |
|
115 |
|
|
116 |
repository.setDatasourceType(type); |
|
117 |
|
|
118 |
|
|
119 |
return repository; |
|
120 |
} |
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
public static Date convertStringToDate(String date){ |
|
125 |
|
|
126 |
if(Objects.equals(date, "null")) |
|
127 |
return null; |
|
128 |
|
|
129 |
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); |
|
130 |
try { |
|
131 |
return formatter.parse(date); |
|
132 |
} catch (ParseException e) { |
|
133 |
e.printStackTrace(); |
|
134 |
} |
|
135 |
return null; |
|
136 |
} |
|
137 |
|
|
138 |
public static String convertDateToString(Date date){ |
|
139 |
|
|
140 |
if(Objects.equals(date, null)) |
|
141 |
return null; |
|
142 |
|
|
143 |
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); |
|
144 |
return formatter.format(date); |
|
145 |
} |
|
146 |
|
|
147 |
public static Double toDouble(String number){ |
|
148 |
if(Objects.equals(number, "null")) |
|
149 |
return 0.0; |
|
150 |
else |
|
151 |
return Double.valueOf(number); |
|
152 |
} |
|
153 |
|
|
154 |
public static List<Repository> jsonToRepositoryList(JSONObject json) throws JSONException { |
|
155 |
|
|
156 |
List<Repository> resultSet = new ArrayList<>(); |
|
157 |
JSONArray rs = json.getJSONArray("datasourceInfo"); |
|
158 |
for(int i=0;i<rs.length();i++) |
|
159 |
resultSet.add(jsonToRepositoryObject( rs.getJSONObject(i)) ); |
|
160 |
return resultSet; |
|
161 |
} |
|
162 |
|
|
163 |
public static List<RepositoryInterface> jsonToRepositoryInterfaceList(JSONArray rs) throws JSONException { |
|
164 |
|
|
165 |
List<RepositoryInterface> resultSet = new ArrayList<>(); |
|
166 |
for(int i=0;i<rs.length();i++) |
|
167 |
resultSet.add(jsonToRepositoryInterfaceObject( rs.getJSONObject(i)) ); |
|
168 |
return resultSet; |
|
169 |
} |
|
170 |
|
|
171 |
public static RepositoryInterface jsonToRepositoryInterfaceObject(JSONObject repositoryInterfaceObject) throws JSONException { |
|
172 |
|
|
173 |
RepositoryInterface repositoryInterface = new RepositoryInterface(); |
|
174 |
|
|
175 |
repositoryInterface.setBaseUrl(repositoryInterfaceObject.get("baseurl").toString()); |
|
176 |
repositoryInterface.setContentDescription(repositoryInterfaceObject.get("contentdescription").toString()); |
|
177 |
repositoryInterface.setId(repositoryInterfaceObject.get("id").toString()); |
|
178 |
repositoryInterface.setMetadataIdentifierPath(repositoryInterfaceObject.get("metadataIdentifierPath").toString()); |
|
179 |
repositoryInterface.setAccessProtocol(repositoryInterfaceObject.get("protocol").toString()); |
|
180 |
repositoryInterface.setTypology(repositoryInterfaceObject.get("typology").toString()); |
|
181 |
repositoryInterface.setDesiredCompatibilityLevel(repositoryInterfaceObject.get("compatibility").toString()); |
|
182 |
repositoryInterface.setActive(Boolean.parseBoolean(repositoryInterfaceObject.get("active").toString())); |
|
183 |
repositoryInterface.setRemovable(Boolean.parseBoolean(repositoryInterfaceObject.get("removable").toString())); |
|
184 |
repositoryInterface.setCompliance(repositoryInterfaceObject.get("compatibility").toString()); |
|
185 |
|
|
186 |
Map<String, String> accessParams = new HashMap<>(); |
|
187 |
Map<String, String> extraFields = new HashMap<>(); |
|
188 |
|
|
189 |
ObjectMapper mapper = new ObjectMapper(); |
|
190 |
JSONArray apiparams = repositoryInterfaceObject.getJSONArray("apiparam"); |
|
191 |
|
|
192 |
for(int i=0;i<apiparams.length();i++) |
|
193 |
accessParams.put(apiparams.getJSONObject(i).getString("param"),apiparams.getJSONObject(i).getString("value")); |
|
194 |
|
|
195 |
return repositoryInterface; |
|
196 |
} |
|
197 |
|
|
198 |
public static String repositoryObjectToJson(Repository repository) throws JSONException { |
|
199 |
|
|
200 |
JSONObject jsonObject = new JSONObject(); |
|
201 |
jsonObject.put("activationId",repository.getActivationId()); |
|
202 |
jsonObject.put("aggregator",repository.getAggregator()); |
|
203 |
jsonObject.put("certificates",repository.getCertificates()); |
|
204 |
jsonObject.put("citationguidelineurl",repository.getCitationGuidelineUrl()); |
|
205 |
jsonObject.put("collectedfrom",repository.getCollectedFrom()); |
|
206 |
jsonObject.put("contactemail",repository.getContactEmail()); |
|
207 |
jsonObject.put("databaseaccessrestriction",repository.getDatabaseAccessRestriction()); |
|
208 |
jsonObject.put("databaseaccesstype",repository.getDatabaseAccessType()); |
|
209 |
jsonObject.put("datauploadrestriction",repository.getDataUploadRestriction()); |
|
210 |
jsonObject.put("datauploadtype",repository.getDataUploadType()); |
|
211 |
jsonObject.put("dateofcollection",convertDateToString(repository.getDateOfCollection())); |
|
212 |
jsonObject.put("dateofvalidation",convertDateToString(repository.getDateOfValidation())); |
|
213 |
jsonObject.put("description",repository.getDescription()); |
|
214 |
jsonObject.put("eissn",repository.getEissn()); |
|
215 |
jsonObject.put("englishname",repository.getEnglishName()); |
|
216 |
jsonObject.put("id",repository.getId()); |
|
217 |
jsonObject.put("issn",repository.getIssn()); |
|
218 |
jsonObject.put("languages",repository.getOdLanguages()); |
|
219 |
jsonObject.put("latitude",repository.getLatitude().toString()); |
|
220 |
jsonObject.put("lissn",repository.getLissn()); |
|
221 |
jsonObject.put("logourl",repository.getLogoUrl()); |
|
222 |
jsonObject.put("longitude",repository.getLongitude().toString()); |
|
223 |
jsonObject.put("missionstatementurl",repository.getMissionStatementUrl()); |
|
224 |
jsonObject.put("namespaceprefix",repository.getNamespacePrefix()); |
|
225 |
jsonObject.put("od_contenttypes",repository.getOdContentTypes()); |
|
226 |
jsonObject.put("officialname",repository.getOfficialName()); |
|
227 |
jsonObject.put("pidsystems",repository.getPidSystems()); |
|
228 |
jsonObject.put("provenanceaction",repository.getProvenanceActionClass()); |
|
229 |
jsonObject.put("qualitymanagementkind",repository.getQualityManagementKind()); |
|
230 |
jsonObject.put("registeredby",repository.getRegisteredBy()); |
|
231 |
jsonObject.put("releaseenddate",convertDateToString(repository.getReleaseEndDate())); |
|
232 |
jsonObject.put("releasestartdate",convertDateToString(repository.getReleaseStartDate())); |
|
233 |
jsonObject.put("serviceprovider",repository.getServiceProvider()); |
|
234 |
jsonObject.put("timezone",repository.getTimezone()); |
|
235 |
jsonObject.put("typology",repository.getTypology()); |
|
236 |
jsonObject.put("versioning",repository.getVersioning()); |
|
237 |
jsonObject.put("websiteurl",repository.getWebsiteUrl()); |
|
238 |
|
|
239 |
//datasource.get("managed"); |
|
240 |
//datasource.get("platform"); |
|
241 |
//datasource.get("subjects"); |
|
242 |
return jsonObject.toString(); |
|
243 |
} |
|
244 |
|
|
245 |
public static String repositoryInterfaceObjectToJson(Repository repository,RepositoryInterface repositoryInterface) throws JSONException { |
|
246 |
|
|
247 |
JSONObject jsonObject = new JSONObject(); |
|
248 |
|
|
249 |
jsonObject.put("baseurl",repositoryInterface.getBaseUrl()); |
|
250 |
jsonObject.put("contentdescription",repositoryInterface.getContentDescription()); |
|
251 |
jsonObject.put("id",repositoryInterface.getId()); |
|
252 |
jsonObject.put("metadataIdentifierPath",repositoryInterface.getMetadataIdentifierPath()); |
|
253 |
jsonObject.put("protocol",repositoryInterface.getAccessProtocol()); |
|
254 |
jsonObject.put("typology",repositoryInterface.getTypology()); |
|
255 |
jsonObject.put("compatibility",repositoryInterface.getDesiredCompatibilityLevel()); |
|
256 |
jsonObject.put("datasource",repository.getId()); |
|
257 |
jsonObject.put("metadataIdentifierPath",repositoryInterface.getMetadataIdentifierPath()); |
|
258 |
jsonObject.put("protocol",repositoryInterface.getAccessProtocol()); |
|
259 |
jsonObject.put("removable",repositoryInterface.isRemovable()); |
|
260 |
jsonObject.put("active",repositoryInterface.isActive()); |
|
261 |
|
|
262 |
|
|
263 |
JSONArray apiparams = new JSONArray(); |
|
264 |
for(String param: repositoryInterface.getAccessParams().keySet()){ |
|
265 |
JSONObject jo = new JSONObject(); |
|
266 |
jo.put("param",param); |
|
267 |
jo.put("value",repositoryInterface.getAccessParams().get(param)); |
|
268 |
apiparams.put(jo); |
|
269 |
} |
|
270 |
jsonObject.put("apiparam",apiparams); |
|
271 |
|
|
272 |
|
|
273 |
jsonObject.put("lastCollectionDate",repositoryInterface.getLastCollectionDate()); |
|
274 |
//jsonObject.put("lastCollectionMdid",repositoryInterface); |
|
275 |
//jsonObject.put("lastCollectionTotal"); |
|
276 |
//jsonObject.put("lastDownloadDate"); |
|
277 |
// jsonObject.put("lastDownloadMdid"); |
|
278 |
// jsonObject.put("lastDownloadTotal"); |
|
279 |
// jsonObject.put("lastValidationJob"); |
|
280 |
//jsonObject.put("lastAggregationDate"); |
|
281 |
//jsonObject.put("lastAggregationMdid"); |
|
282 |
//jsonObject.put("lastAggregationTotal"); |
|
283 |
|
|
284 |
return jsonObject.toString(); |
|
285 |
} |
|
286 |
|
|
287 |
public static ArrayList<String> readFile(String filename) { |
|
288 |
String line; |
|
289 |
ArrayList<String> list = new ArrayList<String>(); |
|
290 |
try { |
|
291 |
//InputStream in = Converter.class.getResourceAsStream("resources/eu/dnetlib/repo/manager/service/utils/"+filename); |
|
292 |
InputStream in = Converter.class.getClass().getResourceAsStream("/eu/**/" + filename); |
|
293 |
BufferedReader br = new BufferedReader(new InputStreamReader(in)); |
|
294 |
while((line = br.readLine()) != null) { |
|
295 |
list.add(line.trim()); |
|
296 |
} |
|
297 |
br.close(); |
|
298 |
} catch (IOException e) { |
|
299 |
LOGGER.debug("Error opening file!"); |
|
300 |
e.printStackTrace(); |
|
301 |
} |
|
302 |
return list; |
|
303 |
} |
|
304 |
|
|
305 |
public static List<AggregationDetails> getAggregationHistoryFromJson(JSONObject repositoryObject) throws JSONException { |
|
306 |
|
|
307 |
/* if( repositoryObject.get("aggregationHistory").toString().equals("[]") || |
|
308 |
repositoryObject.get("aggregationHistory")!= null) |
|
309 |
return null;*/ |
|
310 |
if(repositoryObject.get("aggregationHistory").toString().equals("[]")) |
|
311 |
return null; |
|
312 |
|
|
313 |
|
|
314 |
JSONArray rs = new JSONArray(repositoryObject.get("aggregationHistory").toString()); |
|
315 |
|
|
316 |
LOGGER.debug(rs.length()); |
|
317 |
|
|
318 |
List<AggregationDetails> aggregationDetailsList = new ArrayList<>(); |
|
319 |
for(int i=0;i<rs.length();i++) |
|
320 |
aggregationDetailsList.add(jsonToAggregationDetails(rs.getJSONObject(i))); |
|
321 |
return aggregationDetailsList; |
|
322 |
} |
|
323 |
|
|
324 |
private static AggregationDetails jsonToAggregationDetails(JSONObject aggregationObject) throws JSONException { |
|
325 |
|
|
326 |
AggregationDetails aggregationDetails = new AggregationDetails(); |
|
327 |
|
|
328 |
aggregationDetails.setAggregationStage(aggregationObject.get("aggregationStage").toString()); |
|
329 |
if(aggregationObject.has("collectionMode")) |
|
330 |
aggregationDetails.setCollectionMode(aggregationObject.get("collectionMode").toString()); |
|
331 |
aggregationDetails.setDate(convertStringToDate(aggregationObject.get("date").toString())); |
|
332 |
aggregationDetails.setNumberOfRecords(Integer.parseInt(aggregationObject.get("numberOfRecords").toString())); |
|
333 |
return aggregationDetails; |
|
334 |
} |
|
335 |
|
|
336 |
public static AggregationDetails getLastCollectionFromJson(JSONObject repositoryObject) throws JSONException { |
|
337 |
|
|
338 |
if( repositoryObject.get("lastCollection").equals(null)) |
|
339 |
return null; |
|
340 |
|
|
341 |
return jsonToAggregationDetails(repositoryObject.getJSONObject("lastCollection")); |
|
342 |
} |
|
343 |
|
|
344 |
public static AggregationDetails getLastTransformationFromJson(JSONObject repositoryObject) throws JSONException { |
|
345 |
|
|
346 |
if( repositoryObject.get("lastTransformation").equals(null)) |
|
347 |
return null; |
|
348 |
|
|
349 |
return jsonToAggregationDetails(repositoryObject.getJSONObject("lastTransformation")); |
|
350 |
} |
|
351 |
|
|
352 |
public static List<Timezone> toTimezones(List<String> timezones) { |
|
353 |
|
|
354 |
List<Timezone> tmz = new ArrayList<>(); |
|
355 |
for(String t : timezones){ |
|
356 |
String[] s = t.split("\t"); |
|
357 |
tmz.add(new Timezone(s[1],Double.parseDouble(s[0]))); |
|
358 |
} |
|
359 |
return tmz; |
|
360 |
} |
|
361 |
} |
modules/uoa-repository-manager-service/trunk/src/main/java/eu/dnetlib/repo/manager/service/utils/EmailUtils.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.utils; |
|
2 |
|
|
3 |
import eu.dnetlib.domain.data.PiwikInfo; |
|
4 |
import eu.dnetlib.domain.functionality.UserProfile; |
|
5 |
|
|
6 |
public interface EmailUtils { |
|
7 |
|
|
8 |
|
|
9 |
void reportException(Exception exception); |
|
10 |
|
|
11 |
void sendAdministratorRequestToEnableMetrics(PiwikInfo piwikInfo) throws Exception; |
|
12 |
|
|
13 |
void sendUserRequestToEnableMetrics(PiwikInfo piwikInfo) throws Exception; |
|
14 |
|
|
15 |
void sendAdministratorMetricsEnabled(PiwikInfo piwikInfo) throws Exception; |
|
16 |
|
|
17 |
void sendUserMetricsEnabled(PiwikInfo piwikInfo) throws Exception; |
|
18 |
} |
modules/uoa-repository-manager-service/trunk/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/trunk/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.shared.JobsOfUser; |
|
7 |
import eu.dnetlib.repo.manager.shared.Constants; |
|
8 |
import gr.uoa.di.driver.util.ServiceLocator; |
|
9 |
import io.swagger.annotations.ApiParam; |
|
10 |
import org.apache.log4j.Logger; |
|
11 |
import org.json.JSONException; |
|
12 |
import org.springframework.stereotype.Component; |
|
13 |
import javax.annotation.Resource; |
|
14 |
|
|
15 |
@Component |
|
16 |
public class MonitorApiImpl implements MonitorApi { |
|
17 |
|
|
18 |
@Resource(name = "validatorServiceLocator") |
|
19 |
private ServiceLocator<ValidatorService> validatorServiceLocator; |
|
20 |
|
|
21 |
private ValidatorService getValidationService() { |
|
22 |
return this.validatorServiceLocator.getService(); |
|
23 |
} |
|
24 |
|
|
25 |
public ServiceLocator<ValidatorService> getValidatorServiceLocator() { |
|
26 |
return validatorServiceLocator; |
|
27 |
} |
|
28 |
|
|
29 |
public void setValidatorServiceLocator(ServiceLocator<ValidatorService> validatorServiceLocator) { |
|
30 |
this.validatorServiceLocator = validatorServiceLocator; |
|
31 |
} |
|
32 |
|
|
33 |
|
|
34 |
private static final Logger LOGGER = Logger |
|
35 |
.getLogger(MonitorApiImpl.class); |
|
36 |
|
|
37 |
@Override |
|
38 |
public JobsOfUser getJobsOfUser(@ApiParam(value = "User email", required = true) String user, |
|
39 |
@ApiParam(value = "Equals to filter job type on validation history page", required = true) String jobType, |
|
40 |
@ApiParam(value = "Page number", required = true) String offset, |
|
41 |
@ApiParam(value = "Null value", required = true) String limit, |
|
42 |
@ApiParam(value = "Null value", required = true) String dateFrom, |
|
43 |
@ApiParam(value = "Null value", required = true) String dateTo, |
|
44 |
@ApiParam(value = "Equals to filter validation jobs", required = true) String validationStatus, |
|
45 |
@ApiParam(value = "Always true", required = true) String includeJobsTotal) throws JSONException, ValidatorServiceException { |
|
46 |
|
|
47 |
LOGGER.debug("Getting jobs of user : " + user); |
|
48 |
LOGGER.debug(user + "/" + jobType + "/" + offset + "/" + dateFrom + "/" + dateTo + "/" + validationStatus + "/" + includeJobsTotal); |
|
49 |
JobsOfUser retJobs = new JobsOfUser(); |
|
50 |
retJobs.setJobs(getValidationService().getStoredJobsNew(user, jobType, Integer.parseInt(offset), |
|
51 |
Integer.parseInt(limit), dateFrom, dateTo, validationStatus)); |
|
52 |
if (Boolean.parseBoolean(includeJobsTotal)) { |
|
53 |
retJobs.setTotalJobs(this.getJobsTotalNumberOfUser(user, jobType, null)); |
|
54 |
retJobs.setTotalJobsSuccessful(this.getJobsTotalNumberOfUser(user, jobType, Constants.VALIDATION_JOB_STATUS_SUCCESSFUL)); |
|
55 |
retJobs.setTotalJobsFailed(this.getJobsTotalNumberOfUser(user, jobType, Constants.VALIDATION_JOB_STATUS_FAILED)); |
|
56 |
retJobs.setTotalJobsOngoing(this.getJobsTotalNumberOfUser(user, jobType,Constants.VALIDATION_JOB_STATUS_ONGOING)); |
|
57 |
} |
|
58 |
return retJobs; |
|
59 |
|
|
60 |
} |
|
61 |
|
|
62 |
private int getJobsTotalNumberOfUser(String user, String jobType, String validationStatus) throws ValidatorServiceException { |
|
63 |
return getValidationService().getStoredJobsTotalNumberNew(user, jobType, validationStatus); |
|
64 |
} |
|
65 |
|
|
66 |
@Override |
|
67 |
public int getJobsOfUserPerValidationStatus(String user, |
|
68 |
String jobType, |
|
69 |
String validationStatus) throws JSONException { |
|
70 |
LOGGER.debug("Getting job with validation status : " + validationStatus); |
|
71 |
try { |
|
72 |
return getValidationService().getStoredJobsTotalNumberNew(user, jobType, validationStatus); |
|
73 |
} catch (ValidatorServiceException e) { |
|
74 |
e.printStackTrace(); |
|
75 |
} |
|
76 |
return 0; |
|
77 |
} |
|
78 |
|
|
79 |
@Override |
|
80 |
public StoredJob getJobSummary(String jobId, |
|
81 |
String groupBy) throws JSONException { |
|
82 |
LOGGER.debug("Getting job summary with id : " + jobId); |
|
83 |
try { |
|
84 |
return getValidationService().getStoredJob(Integer.parseInt(jobId), groupBy); |
|
85 |
} catch (ValidatorServiceException e) { |
|
86 |
e.printStackTrace(); |
|
87 |
} |
|
88 |
return null; |
|
89 |
} |
|
90 |
|
|
91 |
} |
modules/uoa-repository-manager-service/trunk/src/main/java/eu/dnetlib/repo/manager/service/controllers/UserApi.java | ||
---|---|---|
1 |
/* |
|
2 |
package eu.dnetlib.repo.manager.service.controllers; |
|
3 |
|
|
4 |
import io.swagger.annotations.Api; |
|
5 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
6 |
import org.springframework.web.bind.annotation.RequestMethod; |
|
7 |
import org.springframework.web.bind.annotation.RestController; |
|
8 |
|
|
9 |
import javax.servlet.http.HttpServletRequest; |
|
10 |
import javax.servlet.http.HttpServletResponse; |
|
11 |
|
|
12 |
@RestController |
|
13 |
@RequestMapping(value = "/user") |
|
14 |
@Api(description = "User API", tags = {"user"}) |
|
15 |
public interface UserApi { |
|
16 |
|
|
17 |
@RequestMapping(value = "/login" , method = RequestMethod.GET) |
|
18 |
void login(HttpServletRequest req, |
|
19 |
HttpServletResponse resp); |
|
20 |
|
|
21 |
|
|
22 |
} |
|
23 |
*/ |
modules/uoa-repository-manager-service/trunk/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.shared.*; |
|
6 |
import io.swagger.annotations.Api; |
|
7 |
import org.json.JSONException; |
|
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 |
|
|
15 |
@RestController |
|
16 |
@RequestMapping(value = "/repository") |
|
17 |
@Api(description = "Repository API", tags = {"repository"}) |
|
18 |
public interface RepositoryApi { |
|
19 |
|
|
20 |
@RequestMapping(value = "/testAggregations", method = RequestMethod.GET, |
|
21 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
22 |
@ResponseBody |
|
23 |
List<String> testAggregations() throws JSONException; |
|
24 |
|
|
25 |
@RequestMapping(value = "/getCountries", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) |
|
26 |
@ResponseBody |
|
27 |
Country[] getCountries() ; |
|
28 |
|
|
29 |
@RequestMapping(value = "/getRepositoriesByCountry/{country}/{mode}", method = RequestMethod.GET, |
|
30 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
31 |
@ResponseBody |
|
32 |
List<Repository> getRepositoriesByCountry(String country, String mode, Boolean managed) throws JSONException; |
|
33 |
|
|
34 |
@RequestMapping(value = "/getRepositoriesOfUser/{userEmail}/{page}/{size}",method = RequestMethod.GET, |
|
35 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
36 |
@ResponseBody |
|
37 |
List<Repository> getRepositoriesOfUser(String userEmail, |
|
38 |
String page, |
|
39 |
String size) throws JSONException; |
|
40 |
|
|
41 |
@RequestMapping(value = "/getRepositoryById/{id}", method = RequestMethod.GET, |
|
42 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
43 |
@ResponseBody |
|
44 |
Repository getRepositoryById(String id) throws JSONException; |
|
45 |
|
|
46 |
|
|
47 |
@RequestMapping(value = "/getRepositoryAggregations/{id}", method = RequestMethod.GET, |
|
48 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
49 |
@ResponseBody |
|
50 |
Aggregations getRepositoryAggregations(String id) throws JSONException; |
|
51 |
|
|
52 |
|
|
53 |
@RequestMapping(value = "/getRepositoriesByName/{name}/{page}/{size}/", method = RequestMethod.GET, |
|
54 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
55 |
@ResponseBody |
|
56 |
List<Repository> getRepositoriesByName(String name, |
|
57 |
String page, |
|
58 |
String size) throws JSONException; |
|
59 |
|
|
60 |
@RequestMapping(value = "/getRepositoryInterface/{id}", method = RequestMethod.GET, |
|
61 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
62 |
@ResponseBody |
|
63 |
List<RepositoryInterface> getRepositoryInterface(String id) throws JSONException; |
|
64 |
|
|
65 |
@RequestMapping(value = "/addRepository", method = RequestMethod.POST, |
|
66 |
consumes = MediaType.APPLICATION_JSON_VALUE) |
|
67 |
@ResponseBody |
|
68 |
void addRepository(String datatype, Repository repository) throws Exception; |
|
69 |
|
|
70 |
|
|
71 |
@RequestMapping(value = "/deleteInterface", method = RequestMethod.DELETE) |
|
72 |
@ResponseBody |
|
73 |
void deleteRepositoryInterface(String id); |
|
74 |
|
|
75 |
@RequestMapping(value = "/addInterface", method = RequestMethod.POST, |
|
76 |
consumes = MediaType.APPLICATION_JSON_VALUE) |
|
77 |
@ResponseBody |
|
78 |
RepositoryInterface addRepositoryInterface(String datatype, |
|
79 |
String repoId, |
|
80 |
RepositoryInterface iFace) throws JSONException; |
|
81 |
|
|
82 |
@RequestMapping(value = "/getDnetCountries", method = RequestMethod.GET, |
|
83 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
84 |
@ResponseBody |
|
85 |
List<String> getDnetCountries(); |
|
86 |
|
|
87 |
@RequestMapping(value = "/getTypologies", method = RequestMethod.GET, |
|
88 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
89 |
@ResponseBody |
|
90 |
List<String> getTypologies(); |
|
91 |
|
|
92 |
@RequestMapping(value = "/getTimezones", method = RequestMethod.GET, |
|
93 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
94 |
@ResponseBody |
|
95 |
List<Timezone> getTimezones(); |
|
96 |
|
|
97 |
@RequestMapping(value = "/updateManagedStatus", method = RequestMethod.POST, |
|
98 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
99 |
@ResponseBody |
|
100 |
String updateManagedStatus(String id, String managed); |
|
101 |
|
|
102 |
@RequestMapping(value = "/updateEnglishName", method = RequestMethod.POST, |
|
103 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
104 |
@ResponseBody |
|
105 |
String updateEnglishName(String id, String englishName); |
|
106 |
|
|
107 |
@RequestMapping(value = "/updateLatitude", method = RequestMethod.POST, |
|
108 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
109 |
@ResponseBody |
|
110 |
String updateLatitude(String id, String latitude); |
|
111 |
|
|
112 |
@RequestMapping(value = "/updateLongitude", method = RequestMethod.POST, |
|
113 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
114 |
@ResponseBody |
|
115 |
String updateLongitude(String id, String longitude); |
|
116 |
|
|
117 |
@RequestMapping(value = "/updateOfficialName", method = RequestMethod.POST, |
|
118 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
119 |
@ResponseBody |
|
120 |
String updateOfficialName(String id, String officialName); |
|
121 |
|
|
122 |
@RequestMapping(value = "/updateTimezone", method = RequestMethod.POST, |
|
123 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
124 |
@ResponseBody |
|
125 |
String updateTimezone(String id, String timezone); |
|
126 |
|
|
127 |
@RequestMapping(value = "/updateTypology", method = RequestMethod.POST, |
|
128 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
129 |
@ResponseBody |
|
130 |
String updateTypology(String id, String typology); |
|
131 |
|
|
132 |
@RequestMapping(value = "/updateLogoUrl", method = RequestMethod.POST, |
|
133 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
134 |
@ResponseBody |
|
135 |
String updateLogoUrl(String id, String logoUrl); |
|
136 |
|
|
137 |
@RequestMapping(value = "/updatePlatform", method = RequestMethod.POST, |
|
138 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
139 |
@ResponseBody |
|
140 |
String updatePlatform(String id, String platform); |
|
141 |
|
|
142 |
|
|
143 |
@RequestMapping(value = "/getUrlsOfUserRepos/{user_email}/{page}/{size}/",method = RequestMethod.GET, |
|
144 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
145 |
@ResponseBody |
|
146 |
List<String> getUrlsOfUserRepos(String user_email, |
|
147 |
String page, |
|
148 |
String size) throws JSONException; |
|
149 |
|
|
150 |
@RequestMapping(value = "/getDatasourceVocabularies/{mode}",method = RequestMethod.GET, |
|
151 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
152 |
@ResponseBody |
|
153 |
List<String> getDatasourceVocabularies(String mode); |
|
154 |
|
|
155 |
@RequestMapping(value = "/getCompatibilityClasses/{mode}",method = RequestMethod.GET, |
|
156 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
157 |
@ResponseBody |
|
158 |
Map<String, String> getCompatibilityClasses(String mode); |
|
159 |
|
|
160 |
@RequestMapping(value = "/getDatasourceClasses/{mode}",method = RequestMethod.GET, |
|
161 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
162 |
@ResponseBody |
|
163 |
Map<String, String> getDatasourceClasses(String mode); |
|
164 |
|
|
165 |
|
|
166 |
String getCountryName(String countryCode); |
|
167 |
|
|
168 |
@RequestMapping(value = "/getMetricsInfoForRepository/{repoId}",method = RequestMethod.GET, |
|
169 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
170 |
@ResponseBody |
|
171 |
MetricsInfo getMetricsInfoForRepository(String repoId) throws RepositoryServiceException; |
|
172 |
} |
modules/uoa-repository-manager-service/trunk/src/main/java/eu/dnetlib/repo/manager/service/controllers/UserApiImpl.java | ||
---|---|---|
1 |
/* |
|
2 |
package eu.dnetlib.repo.manager.service.controllers; |
|
3 |
|
|
4 |
import org.springframework.beans.factory.annotation.Value; |
|
5 |
import org.springframework.stereotype.Component; |
|
6 |
|
|
7 |
import javax.servlet.http.HttpServletRequest; |
|
8 |
import javax.servlet.http.HttpServletResponse; |
|
9 |
|
|
10 |
@Component |
|
11 |
public class UserApiImpl implements UserApi { |
|
12 |
|
|
13 |
private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger |
|
14 |
.getLogger(UserApiImpl.class); |
|
15 |
|
|
16 |
@Value("${oidc.issuer}") |
|
17 |
private String oidc_issuer; |
|
18 |
|
|
19 |
@Override |
|
20 |
public void login(HttpServletRequest req, |
|
21 |
HttpServletResponse resp) { |
|
22 |
LOGGER.debug(oidc_issuer); |
|
23 |
resp.setStatus(HttpServletResponse.SC_FOUND); |
|
24 |
resp.setHeader("Location", oidc_issuer); |
|
25 |
} |
|
26 |
} |
|
27 |
*/ |
modules/uoa-repository-manager-service/trunk/src/main/java/eu/dnetlib/repo/manager/service/controllers/RepositoryApiImpl.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.controllers; |
|
2 |
|
|
3 |
import com.fasterxml.jackson.databind.DeserializationFeature; |
|
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.domain.enabling.Vocabulary; |
|
8 |
import eu.dnetlib.repo.manager.service.utils.Converter; |
|
9 |
import eu.dnetlib.repo.manager.shared.*; |
|
10 |
import gr.uoa.di.driver.enabling.vocabulary.VocabularyLoader; |
|
11 |
import org.apache.commons.codec.digest.DigestUtils; |
|
12 |
import org.apache.log4j.Logger; |
|
13 |
import org.json.JSONArray; |
|
14 |
import org.json.JSONException; |
|
15 |
import org.json.JSONObject; |
|
16 |
import org.springframework.beans.factory.annotation.Autowired; |
|
17 |
import org.springframework.beans.factory.annotation.Value; |
|
18 |
import org.springframework.core.ParameterizedTypeReference; |
|
19 |
import org.springframework.http.HttpEntity; |
|
20 |
import org.springframework.http.HttpHeaders; |
|
21 |
import org.springframework.http.HttpMethod; |
|
22 |
import org.springframework.http.ResponseEntity; |
|
23 |
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; |
|
24 |
import org.springframework.stereotype.Component; |
|
25 |
import org.springframework.web.bind.annotation.PathVariable; |
|
26 |
import org.springframework.web.bind.annotation.RequestBody; |
|
27 |
import org.springframework.web.bind.annotation.RequestParam; |
|
28 |
import org.springframework.web.client.RestClientException; |
|
29 |
import org.springframework.web.client.RestTemplate; |
|
30 |
import org.springframework.web.util.UriComponents; |
|
31 |
import org.springframework.web.util.UriComponentsBuilder; |
|
32 |
|
|
33 |
import javax.annotation.PostConstruct; |
|
34 |
import javax.ws.rs.QueryParam; |
|
35 |
import java.sql.Timestamp; |
|
36 |
import java.text.Normalizer; |
|
37 |
import java.util.*; |
|
38 |
import java.util.concurrent.ConcurrentHashMap; |
|
39 |
|
|
40 |
@Component |
|
41 |
public class RepositoryApiImpl implements RepositoryApi { |
|
42 |
|
|
43 |
@Value("${api.baseAddress}") |
|
44 |
private String baseAddress; |
|
45 |
|
|
46 |
private RestTemplate restTemplate = null; |
|
47 |
|
|
48 |
private HttpHeaders httpHeaders; |
|
49 |
|
|
50 |
private final String[] vocabularyNames = {"dnet:countries", "dnet:datasource_typologies", "dnet:compatibilityLevel"}; |
|
51 |
|
|
52 |
private static final Logger LOGGER = Logger.getLogger(RepositoryApiImpl.class); |
|
53 |
|
|
54 |
@Value("${services.repomanager.usageStatisticsDiagramsBaseURL}") |
|
55 |
private String usageStatisticsDiagramsBaseURL; |
|
56 |
|
|
57 |
@Value("${services.repomanager.usageStatisticsNumbersBaseURL}") |
|
58 |
private String usageStatisticsNumbersBaseURL; |
|
59 |
|
|
60 |
@Autowired |
|
61 |
private VocabularyLoader vocabularyLoader; |
|
62 |
|
|
63 |
@Autowired |
|
64 |
private PiWikApi piWikApi; |
|
65 |
|
|
66 |
private Map<String, Vocabulary> vocabularyMap = new ConcurrentHashMap<String, Vocabulary>(); |
|
67 |
|
|
68 |
private Map<String, String> countriesMap = new HashMap<>(); |
|
69 |
private Map<String, String> inverseCountriesMap = new HashMap<>(); |
|
70 |
|
|
71 |
|
|
72 |
@PostConstruct |
|
73 |
private void init() { |
|
74 |
LOGGER.debug("Initialization method of repository api!"); |
|
75 |
|
|
76 |
restTemplate = new RestTemplate(); |
|
77 |
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter()); |
|
78 |
|
|
79 |
httpHeaders = new HttpHeaders(); |
|
80 |
httpHeaders.set("Content-Type", "application/json"); |
|
81 |
|
|
82 |
for (String vocName : vocabularyNames) { |
|
83 |
vocabularyMap.put(vocName, vocabularyLoader.getVocabulary(vocName, Locale.ENGLISH, Locale.ROOT)); |
|
84 |
} |
|
85 |
|
|
86 |
Country[] countries = getCountries(); |
|
87 |
for (Country c : countries) { |
|
88 |
countriesMap.put(c.getName(), c.getCode()); |
|
89 |
inverseCountriesMap.put(c.getCode(), c.getName()); |
|
90 |
} |
|
91 |
|
|
92 |
|
|
93 |
} |
|
94 |
|
|
95 |
@Override |
|
96 |
public List<String> testAggregations() throws JSONException { |
|
97 |
|
|
98 |
int page = 0; |
|
99 |
int size = 1000; |
|
100 |
|
|
101 |
UriComponents uriComponents = UriComponentsBuilder |
|
102 |
.fromHttpUrl(baseAddress + "/ds/list/") |
|
103 |
.path("/{page}/{size}/") |
|
104 |
.build().expand(page, size).encode(); |
|
105 |
|
|
106 |
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class); |
|
107 |
List<String> ids = new ArrayList<>(); |
|
108 |
while (!rs.equals("[]")) { |
|
109 |
|
|
110 |
ids.addAll(getIdsWithNonEmptyAggregations(rs)); |
|
111 |
|
|
112 |
LOGGER.debug("Checked " + (page + 1) * size + " records!"); |
|
113 |
|
|
114 |
page += 1; |
|
115 |
uriComponents = UriComponentsBuilder |
|
116 |
.fromHttpUrl(baseAddress + "/ds/list/") |
|
117 |
.path("/{page}/{size}/") |
|
118 |
.build().expand(page, size).encode(); |
|
119 |
rs = restTemplate.getForObject(uriComponents.toUri(), String.class); |
|
120 |
} |
|
121 |
|
|
122 |
return ids; |
|
123 |
} |
|
124 |
|
|
125 |
private List<String> getIdsWithNonEmptyAggregations(String rs) throws JSONException { |
|
126 |
|
|
127 |
JSONArray ids = new JSONArray(rs); |
|
128 |
List<String> agg_ids = new ArrayList<>(); |
|
129 |
for (int i = 0; i < ids.length(); i++) { |
|
130 |
String id = ids.getString(i); |
|
131 |
Aggregations aggregations = getRepositoryAggregations(id); |
|
132 |
if (aggregations.getAggregationHistory() != null) |
|
133 |
agg_ids.add(id); |
|
134 |
} |
|
135 |
return agg_ids; |
|
136 |
} |
|
137 |
|
|
138 |
@Override |
|
139 |
public Country[] getCountries() { |
|
140 |
UriComponents uriComponents = UriComponentsBuilder |
|
141 |
.fromHttpUrl(baseAddress + "/ds/countries") |
|
142 |
.build().encode(); |
|
143 |
return restTemplate.getForObject(uriComponents.toUri(), Country[].class); |
|
144 |
} |
|
145 |
|
|
146 |
|
|
147 |
@Override |
|
148 |
public List<Repository> getRepositoriesByCountry(@PathVariable("country") String country, |
|
149 |
@PathVariable("mode") String mode, |
|
150 |
@RequestParam(value = "managed",required=false) Boolean managed) throws JSONException { |
|
151 |
|
|
152 |
LOGGER.debug("Getting repositories by country!"); |
|
153 |
int page = 0; |
|
154 |
int size = 100; |
|
155 |
|
|
156 |
String countryCode = countriesMap.get(country); |
|
157 |
String filterKey = "UNKNOWN"; |
|
158 |
if (mode.equalsIgnoreCase("opendoar")) { |
|
159 |
filterKey = "openaire____::opendoar"; |
|
160 |
} else if (mode.equalsIgnoreCase("re3data")) { |
|
161 |
filterKey = "openaire____::re3data"; |
|
162 |
} else if (mode.equalsIgnoreCase("jour_aggr")) { |
|
163 |
filterKey = "infrastruct_::openaire"; |
|
164 |
} |
|
165 |
|
|
166 |
LOGGER.debug("Country code equals : " + countryCode); |
|
167 |
LOGGER.debug("Filter mode equals : " + filterKey); |
|
168 |
UriComponents uriComponents = UriComponentsBuilder |
|
169 |
.fromHttpUrl(baseAddress + "/ds/search/country/") |
|
170 |
.path("/{page}/{size}/") |
|
171 |
.queryParam("country", countryCode) |
|
172 |
.queryParam("managed", managed) |
|
173 |
.build().expand(page, size).encode(); |
|
174 |
|
|
175 |
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class); |
|
176 |
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo"); |
|
177 |
|
|
178 |
List<Repository> resultSet = new ArrayList<>(); |
|
179 |
while (jsonArray.length() > 0 ) { |
|
180 |
List<Repository> rep = Converter.jsonToRepositoryList(new JSONObject(rs)); |
|
181 |
|
|
182 |
Collection<Repository> repos = this.getRepositoriesByMode(filterKey, rep); |
|
183 |
resultSet.addAll(repos); |
|
184 |
|
|
185 |
page += 1; |
|
186 |
uriComponents = UriComponentsBuilder |
|
187 |
.fromHttpUrl(baseAddress + "/ds/search/country/") |
|
188 |
.path("/{page}/{size}/") |
|
189 |
.queryParam("country", countryCode) |
|
190 |
.queryParam("managed", managed) |
|
191 |
.build().expand(page, size).encode(); |
|
192 |
rs = restTemplate.getForObject(uriComponents.toUri(), String.class); |
|
193 |
jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo"); |
|
194 |
} |
|
195 |
for (Repository r : resultSet) |
|
196 |
this.getRepositoryInfo(r); |
|
197 |
|
|
198 |
return resultSet; |
|
199 |
} |
Also available in: Unified diff
Delete wrong commited files