Revision 61318
Added by Konstantinos Spyrou almost 3 years ago
RepositoryServiceImpl.java | ||
---|---|---|
12 | 12 |
import eu.dnetlib.repo.manager.domain.*; |
13 | 13 |
import eu.dnetlib.repo.manager.domain.dto.Role; |
14 | 14 |
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException; |
15 |
import eu.dnetlib.repo.manager.utils.AuthorizationService; |
|
15 |
import eu.dnetlib.repo.manager.service.aai.registry.AaiRegistryService; |
|
16 |
import eu.dnetlib.repo.manager.service.security.AuthorizationService; |
|
16 | 17 |
import eu.dnetlib.repo.manager.utils.Converter; |
17 | 18 |
import gr.uoa.di.driver.enabling.vocabulary.VocabularyLoader; |
18 | 19 |
import org.apache.commons.codec.digest.DigestUtils; |
... | ... | |
27 | 28 |
import org.springframework.http.*; |
28 | 29 |
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; |
29 | 30 |
import org.springframework.security.core.Authentication; |
30 |
import org.springframework.security.core.authority.SimpleGrantedAuthority; |
|
31 | 31 |
import org.springframework.security.core.context.SecurityContextHolder; |
32 | 32 |
import org.springframework.stereotype.Service; |
33 | 33 |
import org.springframework.web.client.RestClientException; |
... | ... | |
36 | 36 |
import org.springframework.web.util.UriComponentsBuilder; |
37 | 37 |
|
38 | 38 |
import javax.annotation.PostConstruct; |
39 |
import javax.ws.rs.core.Response; |
|
40 | 39 |
import java.io.IOException; |
41 | 40 |
import java.sql.Timestamp; |
42 | 41 |
import java.util.*; |
... | ... | |
80 | 79 |
ValidatorService validatorService; |
81 | 80 |
|
82 | 81 |
@Autowired |
83 |
private AaiUserRoleService calls;
|
|
82 |
private AaiRegistryService registryCalls;
|
|
84 | 83 |
|
85 | 84 |
// TODO: Antonis K. This should be uncommented |
86 | 85 |
// @Autowired |
... | ... | |
95 | 94 |
private Map<String, String> countriesMap = new HashMap<>(); |
96 | 95 |
private Map<String, String> inverseCountriesMap = new HashMap<>(); |
97 | 96 |
|
98 |
private static Map<String,List<String>> dataSourceClass = new HashMap<>(); |
|
97 |
private static Map<String, List<String>> dataSourceClass = new HashMap<>();
|
|
99 | 98 |
|
100 |
private static Map<String,String> invertedDataSourceClass = new HashMap<>(); |
|
99 |
private static Map<String, String> invertedDataSourceClass = new HashMap<>();
|
|
101 | 100 |
|
102 | 101 |
private String sendEmail() { |
103 | 102 |
OIDCAuthenticationToken authenticationToken = (OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); |
... | ... | |
105 | 104 |
} |
106 | 105 |
|
107 | 106 |
|
108 |
|
|
109 | 107 |
@PostConstruct |
110 | 108 |
private void init() { |
111 | 109 |
LOGGER.debug("Initialization method of repository api!"); |
112 | 110 |
LOGGER.debug("Updated version!"); |
113 | 111 |
|
114 |
dataSourceClass.put("opendoar",Arrays.asList("pubsrepository::institutional","pubsrepository::thematic","pubsrepository::unknown","pubsrepository::mock"));
|
|
112 |
dataSourceClass.put("opendoar", Arrays.asList("pubsrepository::institutional", "pubsrepository::thematic", "pubsrepository::unknown", "pubsrepository::mock"));
|
|
115 | 113 |
dataSourceClass.put("re3data", Collections.singletonList("datarepository::unknown")); |
116 | 114 |
dataSourceClass.put("journal", Collections.singletonList("pubsrepository::journal")); |
117 |
dataSourceClass.put("aggregator",Arrays.asList("aggregator::pubsrepository::institutional","aggregator::pubsrepository::journals","aggregator::datarepository", "aggregator::pubsrepository::unknown"));
|
|
115 |
dataSourceClass.put("aggregator", Arrays.asList("aggregator::pubsrepository::institutional", "aggregator::pubsrepository::journals", "aggregator::datarepository", "aggregator::pubsrepository::unknown"));
|
|
118 | 116 |
|
119 |
invertedDataSourceClass.put("pubsrepository::institutional","opendoar"); |
|
120 |
invertedDataSourceClass.put("pubsrepository::thematic","opendoar"); |
|
121 |
invertedDataSourceClass.put("pubsrepository::unknown","opendoar"); |
|
122 |
invertedDataSourceClass.put("pubsrepository::mock","opendoar"); |
|
123 |
invertedDataSourceClass.put("datarepository::unknown","re3data"); |
|
124 |
invertedDataSourceClass.put("pubsrepository::journal","journal"); |
|
125 |
invertedDataSourceClass.put("aggregator::pubsrepository::institutional","aggregator"); |
|
126 |
invertedDataSourceClass.put("aggregator::pubsrepository::journals","aggregator"); |
|
127 |
invertedDataSourceClass.put("aggregator::datarepository","aggregator"); |
|
128 |
invertedDataSourceClass.put("aggregator::pubsrepository::unknown","aggregator"); |
|
117 |
invertedDataSourceClass.put("pubsrepository::institutional", "opendoar");
|
|
118 |
invertedDataSourceClass.put("pubsrepository::thematic", "opendoar");
|
|
119 |
invertedDataSourceClass.put("pubsrepository::unknown", "opendoar");
|
|
120 |
invertedDataSourceClass.put("pubsrepository::mock", "opendoar");
|
|
121 |
invertedDataSourceClass.put("datarepository::unknown", "re3data");
|
|
122 |
invertedDataSourceClass.put("pubsrepository::journal", "journal");
|
|
123 |
invertedDataSourceClass.put("aggregator::pubsrepository::institutional", "aggregator");
|
|
124 |
invertedDataSourceClass.put("aggregator::pubsrepository::journals", "aggregator");
|
|
125 |
invertedDataSourceClass.put("aggregator::datarepository", "aggregator");
|
|
126 |
invertedDataSourceClass.put("aggregator::pubsrepository::unknown", "aggregator");
|
|
129 | 127 |
|
130 | 128 |
|
131 | 129 |
httpHeaders = new HttpHeaders(); |
... | ... | |
174 | 172 |
LOGGER.debug("Country code equals : " + country); |
175 | 173 |
LOGGER.debug("Filter mode equals : " + filterKey); |
176 | 174 |
|
177 |
UriComponents uriComponents = searchSnipperDatasource(String.valueOf(page),String.valueOf(size)); |
|
175 |
UriComponents uriComponents = searchSnipperDatasource(String.valueOf(page), String.valueOf(size));
|
|
178 | 176 |
RequestFilter requestFilter = new RequestFilter(); |
179 | 177 |
requestFilter.setCountry(country); |
180 | 178 |
requestFilter.setCollectedfrom(filterKey); |
181 | 179 |
|
182 |
try{ |
|
183 |
String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class); |
|
180 |
try {
|
|
181 |
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
|
184 | 182 |
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo"); |
185 |
while (jsonArray.length() > 0 ) {
|
|
183 |
while (jsonArray.length() > 0) { |
|
186 | 184 |
resultSet.addAll(mapper.readValue(String.valueOf(jsonArray), |
187 | 185 |
mapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class))); |
188 | 186 |
page += 1; |
189 |
uriComponents = searchSnipperDatasource(String.valueOf(page),String.valueOf(size)); |
|
190 |
rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class); |
|
187 |
uriComponents = searchSnipperDatasource(String.valueOf(page), String.valueOf(size));
|
|
188 |
rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
|
191 | 189 |
jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo"); |
192 | 190 |
} |
193 | 191 |
return resultSet; |
194 |
}catch (Exception e){
|
|
195 |
LOGGER.debug("Exception on getRepositoriesByCountry" , e);
|
|
192 |
} catch (Exception e) {
|
|
193 |
LOGGER.debug("Exception on getRepositoriesByCountry", e); |
|
196 | 194 |
// emailUtils.reportException(e); |
197 | 195 |
throw e; |
198 | 196 |
} |
199 | 197 |
} |
200 | 198 |
|
201 | 199 |
public List<RepositorySnippet> searchRegisteredRepositories(String country, String typology, String englishName, |
202 |
String officialName, String requestSortBy, String order, int page, int pageSize) throws Exception { |
|
200 |
String officialName, String requestSortBy, String order, int page, int pageSize) throws Exception {
|
|
203 | 201 |
|
204 | 202 |
LOGGER.debug("Searching registered repositories"); |
205 | 203 |
|
... | ... | |
215 | 213 |
requestFilter.setEnglishname(englishName); |
216 | 214 |
|
217 | 215 |
try { |
218 |
String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class); |
|
216 |
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
|
219 | 217 |
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo"); |
220 | 218 |
|
221 |
resultSet.addAll(mapper.readValue(String.valueOf(jsonArray), mapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class)));
|
|
219 |
resultSet.addAll(mapper.readValue(String.valueOf(jsonArray), mapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class))); |
|
222 | 220 |
|
223 |
return resultSet;
|
|
224 |
}catch (Exception e){
|
|
225 |
LOGGER.error("Error searching registered datasources" , e);
|
|
221 |
return resultSet; |
|
222 |
} catch (Exception e) {
|
|
223 |
LOGGER.error("Error searching registered datasources", e); |
|
226 | 224 |
throw e; |
227 | 225 |
} |
228 | 226 |
} |
... | ... | |
230 | 228 |
private Repository updateRepositoryInfo(Repository r) throws JSONException { |
231 | 229 |
|
232 | 230 |
/* |
233 |
* from datasource class |
|
234 |
* we get the datasource type form the inverted map |
|
235 |
* */ |
|
231 |
* from datasource class
|
|
232 |
* we get the datasource type form the inverted map
|
|
233 |
* */
|
|
236 | 234 |
r.setDatasourceType(getRepositoryType(r.getDatasourceClass())); |
237 | 235 |
r.setInterfaces(this.getRepositoryInterface(r.getId())); |
238 | 236 |
r.setPiwikInfo(piWikService.getPiwikSiteForRepo(r.getId())); |
... | ... | |
257 | 255 |
String page, |
258 | 256 |
String size) throws JSONException { |
259 | 257 |
|
260 |
LOGGER.debug("Retreiving repositories of user : " + userEmail );
|
|
261 |
UriComponents uriComponents = searchDatasource(page,size); |
|
258 |
LOGGER.debug("Retreiving repositories of user : " + userEmail); |
|
259 |
UriComponents uriComponents = searchDatasource(page, size);
|
|
262 | 260 |
RequestFilter requestFilter = new RequestFilter(); |
263 |
requestFilter.setRegisteredby(userEmail); |
|
261 |
// requestFilter.setRegisteredby(userEmail);
|
|
264 | 262 |
|
265 |
try{
|
|
266 |
String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class);
|
|
263 |
List<String> repoIds = getRepoIdsFromUserRoles(userEmail);
|
|
264 |
List<Repository> repos = new ArrayList<>();
|
|
267 | 265 |
|
268 |
List<Repository> repos = Converter.jsonToRepositoryList(new JSONObject(rs)); |
|
269 |
for (Repository r : repos) |
|
270 |
r.setPiwikInfo(piWikService.getPiwikSiteForRepo(r.getId())); |
|
271 |
return repos; |
|
272 |
}catch (Exception e){ |
|
273 |
LOGGER.debug("Exception on getRepositoriesOfUser" , e); |
|
266 |
try { |
|
267 |
for (String repoId : repoIds) { |
|
268 |
requestFilter.setId(repoId); |
|
269 |
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class); |
|
270 |
|
|
271 |
repos.addAll(Converter.jsonToRepositoryList(new JSONObject(rs))); |
|
272 |
} |
|
273 |
} catch (Exception e) { |
|
274 |
LOGGER.debug("Exception on getRepositoriesOfUser", e); |
|
274 | 275 |
emailUtils.reportException(e); |
275 | 276 |
throw e; |
276 | 277 |
} |
278 |
|
|
279 |
for (Repository r : repos) |
|
280 |
r.setPiwikInfo(piWikService.getPiwikSiteForRepo(r.getId())); |
|
281 |
return repos; |
|
277 | 282 |
} |
278 | 283 |
|
279 | 284 |
@Override |
280 | 285 |
public List<RepositorySnippet> getRepositoriesSnippetOfUser(String userEmail, String page, String size) throws IOException, JSONException { |
281 | 286 |
|
282 |
// TODO: Antonis K. - Change the below content. get repos of User by his roles |
|
283 |
// TODO: Step 1 - Get all roles (cous) of the user |
|
284 |
// TODO: From the result replace $$ with :: |
|
285 |
// TODO: Step 2 - For each role call getRepositoryById to get the repositoryId |
|
286 | 287 |
// TODO: Step 3 - For each repo from the previous step call findByRepositoryId piwik_site to get the full info of repo |
287 |
Integer coPersonId = calls.getCoPersonIdByEmail(userEmail); |
|
288 |
JsonArray roles; |
|
289 |
ArrayList<String> rolesId = new ArrayList<>(); |
|
290 |
if (coPersonId != null ) { |
|
291 |
roles = calls.getRoles(coPersonId); |
|
292 |
for (JsonElement role : roles) { |
|
293 |
JsonObject object = role.getAsJsonObject(); |
|
294 |
String roleStr = object.get("Name").getAsString().replaceAll(":", "$"); |
|
295 |
String repoBareId = calls.getRepoNameWithoutType(roleStr, "datasource."); |
|
296 |
rolesId.add(roleStr); |
|
297 |
} |
|
298 |
} |
|
288 |
List<String> repoIds = getRepoIdsFromUserRoles(userEmail); |
|
299 | 289 |
|
300 | 290 |
List<RepositorySnippet> resultSet = new ArrayList<>(); |
301 | 291 |
ObjectMapper mapper = new ObjectMapper(); |
302 | 292 |
|
303 | 293 |
// here page should be 0 |
304 |
UriComponents uriComponents = searchSnipperDatasource(page,size); |
|
294 |
UriComponents uriComponents = searchSnipperDatasource(page, size);
|
|
305 | 295 |
RequestFilter requestFilter = new RequestFilter(); |
306 | 296 |
|
307 |
for ( int i = 0; i < rolesId.size(); i++ ) {
|
|
308 |
if ( rolesId.get(i) != "ROLE_ADMIN" && rolesId.get(i) != "ROLE_PROVIDE_ADMIN" && rolesId.get(i) != "ROLE_USER" )
|
|
309 |
requestFilter.setId(rolesId.get(i));
|
|
297 |
try {
|
|
298 |
for (String repoId : repoIds) {
|
|
299 |
requestFilter.setId(repoId);
|
|
310 | 300 |
|
311 |
try{ |
|
312 |
String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class); |
|
301 |
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class); |
|
313 | 302 |
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo"); |
314 | 303 |
resultSet.addAll(mapper.readValue(String.valueOf(jsonArray), |
315 | 304 |
mapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class))); |
316 |
}catch (Exception e){ |
|
317 |
LOGGER.debug("Exception on getRepositoriesByCountry" , e); |
|
318 |
throw e; |
|
319 | 305 |
} |
306 |
} catch (Exception e) { |
|
307 |
LOGGER.debug("Exception on getRepositoriesSnippetOfUser", e); |
|
308 |
throw e; |
|
320 | 309 |
} |
321 |
System.out.println("resultSet:" + resultSet); |
|
310 |
|
|
311 |
LOGGER.debug("resultSet:" + resultSet); |
|
322 | 312 |
resultSet.parallelStream().forEach(repositorySnippet -> { |
323 | 313 |
repositorySnippet.setPiwikInfo(piWikService.getPiwikSiteForRepo(repositorySnippet.getId())); |
324 | 314 |
}); |
... | ... | |
326 | 316 |
} |
327 | 317 |
|
328 | 318 |
@Override |
329 |
public RepositorySnippet getRepositorySnippetById(String id) throws JSONException,ResourceNotFoundException { |
|
319 |
public RepositorySnippet getRepositorySnippetById(String id) throws JSONException, ResourceNotFoundException {
|
|
330 | 320 |
|
331 |
LOGGER.debug("Retreiving repositories with id : " + id );
|
|
321 |
LOGGER.debug("Retreiving repositories with id : " + id); |
|
332 | 322 |
RepositorySnippet repo = null; |
333 |
UriComponents uriComponents = searchSnipperDatasource("0","100"); |
|
323 |
UriComponents uriComponents = searchSnipperDatasource("0", "100");
|
|
334 | 324 |
RequestFilter requestFilter = new RequestFilter(); |
335 | 325 |
requestFilter.setId(id); |
336 | 326 |
|
337 |
try{ |
|
338 |
String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class); |
|
327 |
try {
|
|
328 |
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
|
339 | 329 |
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo"); |
340 | 330 |
|
341 |
if(jsonArray.length() == 0) |
|
331 |
if (jsonArray.length() == 0)
|
|
342 | 332 |
throw new ResourceNotFoundException(); |
343 | 333 |
|
344 | 334 |
repo = Converter.jsonToRepositorySnippetObject(jsonArray.getJSONObject(0)); |
345 | 335 |
return repo; |
346 |
}catch (JSONException e){
|
|
347 |
LOGGER.debug("Exception on getRepositoryById" , e);
|
|
336 |
} catch (JSONException e) {
|
|
337 |
LOGGER.debug("Exception on getRepositoryById", e); |
|
348 | 338 |
emailUtils.reportException(e); |
349 | 339 |
throw e; |
350 | 340 |
} |
... | ... | |
352 | 342 |
} |
353 | 343 |
|
354 | 344 |
@Override |
355 |
public Repository getRepositoryById(String id) throws JSONException,ResourceNotFoundException { |
|
345 |
public Repository getRepositoryById(String id) throws JSONException, ResourceNotFoundException {
|
|
356 | 346 |
|
357 |
LOGGER.debug("Retreiving repositories with id : " + id );
|
|
347 |
LOGGER.debug("Retreiving repositories with id : " + id); |
|
358 | 348 |
Repository repo = null; |
359 |
UriComponents uriComponents = searchDatasource("0","100"); |
|
349 |
UriComponents uriComponents = searchDatasource("0", "100");
|
|
360 | 350 |
RequestFilter requestFilter = new RequestFilter(); |
361 | 351 |
requestFilter.setId(id); |
362 | 352 |
|
363 |
try{ |
|
364 |
String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class); |
|
353 |
try {
|
|
354 |
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
|
365 | 355 |
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo"); |
366 | 356 |
|
367 |
if(jsonArray.length() == 0) |
|
357 |
if (jsonArray.length() == 0)
|
|
368 | 358 |
throw new ResourceNotFoundException(); |
369 | 359 |
|
370 | 360 |
repo = Converter.jsonToRepositoryObject(jsonArray.getJSONObject(0)); |
371 | 361 |
return updateRepositoryInfo(repo); |
372 |
}catch (JSONException e){
|
|
373 |
LOGGER.debug("Exception on getRepositoryById" , e);
|
|
362 |
} catch (JSONException e) {
|
|
363 |
LOGGER.debug("Exception on getRepositoryById", e); |
|
374 | 364 |
emailUtils.reportException(e); |
375 | 365 |
throw e; |
376 | 366 |
} |
... | ... | |
381 | 371 |
@Override |
382 | 372 |
public List<AggregationDetails> getRepositoryAggregations(String id, int from, int size) throws JSONException { |
383 | 373 |
|
384 |
LOGGER.debug("Retreiving aggregations for repository with id : " + id );
|
|
385 |
UriComponents uriComponents = searchDatasource(from+"",size+"");
|
|
374 |
LOGGER.debug("Retreiving aggregations for repository with id : " + id); |
|
375 |
UriComponents uriComponents = searchDatasource(from + "", size + "");
|
|
386 | 376 |
RequestFilter requestFilter = new RequestFilter(); |
387 | 377 |
requestFilter.setId(id); |
388 | 378 |
|
... | ... | |
390 | 380 |
|
391 | 381 |
try { |
392 | 382 |
long start = System.currentTimeMillis(); |
393 |
String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class); |
|
383 |
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
|
394 | 384 |
long end = System.currentTimeMillis(); |
395 | 385 |
|
396 |
System.out.println("Aggregations request through rest template took " + (end-start)+"ms");
|
|
386 |
System.out.println("Aggregations request through rest template took " + (end - start) + "ms");
|
|
397 | 387 |
JSONObject repository = new JSONObject(rs); |
398 | 388 |
|
399 |
if(repository.getJSONArray("datasourceInfo").length() == 0) |
|
389 |
if (repository.getJSONArray("datasourceInfo").length() == 0)
|
|
400 | 390 |
return aggregationHistory; |
401 | 391 |
|
402 | 392 |
start = System.currentTimeMillis(); |
403 | 393 |
aggregationHistory.addAll(Converter.getAggregationHistoryFromJson(repository.getJSONArray("datasourceInfo").getJSONObject(0))); |
404 | 394 |
end = System.currentTimeMillis(); |
405 | 395 |
|
406 |
System.out.println("Getting aggregations history from json " + (end-start)+"ms");
|
|
407 |
return aggregationHistory.size() == 0? aggregationHistory : aggregationHistory.stream() |
|
408 |
.sorted(Comparator.comparing(AggregationDetails::getDate).reversed())
|
|
409 |
.limit(size)
|
|
410 |
.collect(Collectors.toList());
|
|
396 |
System.out.println("Getting aggregations history from json " + (end - start) + "ms");
|
|
397 |
return aggregationHistory.size() == 0 ? aggregationHistory : aggregationHistory.stream()
|
|
398 |
.sorted(Comparator.comparing(AggregationDetails::getDate).reversed()) |
|
399 |
.limit(size) |
|
400 |
.collect(Collectors.toList()); |
|
411 | 401 |
} catch (JSONException e) { |
412 |
LOGGER.debug("Exception on getRepositoryAggregations" , e);
|
|
402 |
LOGGER.debug("Exception on getRepositoryAggregations", e); |
|
413 | 403 |
emailUtils.reportException(e); |
414 | 404 |
throw e; |
415 | 405 |
} |
... | ... | |
418 | 408 |
|
419 | 409 |
@Override |
420 | 410 |
public Map<String, List<AggregationDetails>> getRepositoryAggregationsByYear(String id) throws JSONException { |
421 |
LOGGER.debug("Retreiving aggregations (by year) for repository with id : " + id );
|
|
422 |
UriComponents uriComponents = searchDatasource("0","100"); |
|
411 |
LOGGER.debug("Retreiving aggregations (by year) for repository with id : " + id); |
|
412 |
UriComponents uriComponents = searchDatasource("0", "100");
|
|
423 | 413 |
RequestFilter requestFilter = new RequestFilter(); |
424 | 414 |
requestFilter.setId(id); |
425 | 415 |
|
426 | 416 |
List<AggregationDetails> aggregationHistory = new ArrayList<>(); |
427 | 417 |
Map<String, List<AggregationDetails>> aggregationByYear = new HashMap<>(); |
428 | 418 |
try { |
429 |
String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class); |
|
419 |
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
|
430 | 420 |
JSONObject repository = new JSONObject(rs); |
431 | 421 |
|
432 |
if(repository.getJSONArray("datasourceInfo").length() == 0) |
|
422 |
if (repository.getJSONArray("datasourceInfo").length() == 0)
|
|
433 | 423 |
return aggregationByYear; |
434 | 424 |
|
435 | 425 |
aggregationHistory.addAll(Converter.getAggregationHistoryFromJson(repository.getJSONArray("datasourceInfo").getJSONObject(0))); |
436 |
return aggregationHistory.size() == 0? aggregationByYear:createYearMap(aggregationHistory);
|
|
426 |
return aggregationHistory.size() == 0 ? aggregationByYear : createYearMap(aggregationHistory);
|
|
437 | 427 |
|
438 | 428 |
} catch (JSONException e) { |
439 |
LOGGER.debug("Exception on getRepositoryAggregations" , e);
|
|
429 |
LOGGER.debug("Exception on getRepositoryAggregations", e); |
|
440 | 430 |
emailUtils.reportException(e); |
441 | 431 |
throw e; |
442 | 432 |
} |
443 | 433 |
} |
444 | 434 |
|
445 |
private Map<String,List<AggregationDetails>> createYearMap(List<AggregationDetails> aggregationHistory) { |
|
435 |
private Map<String, List<AggregationDetails>> createYearMap(List<AggregationDetails> aggregationHistory) {
|
|
446 | 436 |
Map<String, List<AggregationDetails>> aggregationByYear; |
447 | 437 |
aggregationHistory = aggregationHistory.stream() |
448 |
.sorted(Comparator.comparing(AggregationDetails::getDate).reversed())
|
|
449 |
.collect(Collectors.toList());
|
|
438 |
.sorted(Comparator.comparing(AggregationDetails::getDate).reversed()) |
|
439 |
.collect(Collectors.toList()); |
|
450 | 440 |
|
451 |
return aggregationHistory.stream() |
|
452 |
.collect(Collectors.groupingBy(AggregationDetails::getYear));
|
|
441 |
return aggregationHistory.stream()
|
|
442 |
.collect(Collectors.groupingBy(AggregationDetails::getYear)); |
|
453 | 443 |
} |
454 | 444 |
|
455 | 445 |
|
... | ... | |
458 | 448 |
String page, |
459 | 449 |
String size) throws JSONException { |
460 | 450 |
|
461 |
LOGGER.debug("Retreiving repositories with official name : " + name );
|
|
462 |
UriComponents uriComponents = searchDatasource("0","100"); |
|
451 |
LOGGER.debug("Retreiving repositories with official name : " + name); |
|
452 |
UriComponents uriComponents = searchDatasource("0", "100");
|
|
463 | 453 |
RequestFilter requestFilter = new RequestFilter(); |
464 | 454 |
requestFilter.setOfficialname(name); |
465 | 455 |
|
466 |
try{ |
|
467 |
String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class); |
|
456 |
try {
|
|
457 |
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
|
468 | 458 |
List<Repository> repos = Converter.jsonToRepositoryList(new JSONObject(rs)); |
469 | 459 |
for (Repository r : repos) |
470 | 460 |
updateRepositoryInfo(r); |
471 | 461 |
return repos; |
472 |
}catch (Exception e){
|
|
473 |
LOGGER.debug("Exception on getRepositoriesByName" , e);
|
|
462 |
} catch (Exception e) {
|
|
463 |
LOGGER.debug("Exception on getRepositoriesByName", e); |
|
474 | 464 |
emailUtils.reportException(e); |
475 | 465 |
throw e; |
476 | 466 |
} |
... | ... | |
485 | 475 |
.path("/{id}") |
486 | 476 |
.build().expand(id).encode(); |
487 | 477 |
|
488 |
try{ |
|
478 |
try {
|
|
489 | 479 |
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class); |
490 | 480 |
return Converter.jsonToRepositoryInterfaceList(new JSONObject(rs)); |
491 |
}catch (Exception e ){
|
|
492 |
LOGGER.debug("Exception on getRepositoryInterface" , e);
|
|
481 |
} catch (Exception e) {
|
|
482 |
LOGGER.debug("Exception on getRepositoryInterface", e); |
|
493 | 483 |
emailUtils.reportException(e); |
494 | 484 |
throw e; |
495 | 485 |
} |
... | ... | |
510 | 500 |
repository.setId("openaire____::issn" + repository.getIssn()); |
511 | 501 |
repository.setNamespacePrefix("issn" + repository.getIssn()); |
512 | 502 |
this.storeRepository(repository, SecurityContextHolder.getContext().getAuthentication()); |
513 |
}else if (datatype.equals("aggregator")) { |
|
503 |
} else if (datatype.equals("aggregator")) {
|
|
514 | 504 |
repository.setId("openaire____::" + com.unboundid.util.Base64.encode(repository.getOfficialName())); |
515 |
repository.setNamespacePrefix(DigestUtils.md5Hex(repository.getOfficialName()).substring(0,12)); |
|
505 |
repository.setNamespacePrefix(DigestUtils.md5Hex(repository.getOfficialName()).substring(0, 12));
|
|
516 | 506 |
this.storeRepository(repository, SecurityContextHolder.getContext().getAuthentication()); |
517 |
}else { |
|
507 |
} else {
|
|
518 | 508 |
this.latentUpdate(repository, SecurityContextHolder.getContext().getAuthentication()); |
519 | 509 |
} |
520 | 510 |
|
... | ... | |
524 | 514 |
String newRoleDescr = repository.getId().replaceAll(":", "\\$"); |
525 | 515 |
Role newRole = new Role(newRoleName, newRoleDescr); |
526 | 516 |
try { |
527 |
calls.createRole(newRole);
|
|
517 |
registryCalls.createRole(newRole);
|
|
528 | 518 |
} catch (Exception e) { |
529 |
LOGGER.debug("Exception on create role during add repository" , e);
|
|
519 |
LOGGER.debug("Exception on create role during add repository", e); |
|
530 | 520 |
throw e; |
531 | 521 |
} |
532 | 522 |
|
533 | 523 |
// Assign new role to the user that created it |
534 |
Integer coPersonId = calls.getCoPersonIdByIdentifier();
|
|
535 |
Integer couId = calls.getCouId("datasource", newRoleName);
|
|
524 |
Integer coPersonId = registryCalls.getCoPersonIdByIdentifier();
|
|
525 |
Integer couId = registryCalls.getCouId("datasource", newRoleName);
|
|
536 | 526 |
if (couId != null) { |
537 |
Integer role = calls.getRoleId(coPersonId, couId);
|
|
538 |
try{ |
|
539 |
calls.assignMemberRole(coPersonId, couId, role);
|
|
527 |
Integer role = registryCalls.getRoleId(coPersonId, couId);
|
|
528 |
try {
|
|
529 |
registryCalls.assignMemberRole(coPersonId, couId, role);
|
|
540 | 530 |
// TODO: Antonis K. This should be uncommented to make a role DATASOURCE.OP... for every new repo |
541 | 531 |
// authoritiesUpdater.update(sendEmail(), old -> { |
542 | 532 |
// HashSet<SimpleGrantedAuthority> authorities = new HashSet<>((Collection<? extends SimpleGrantedAuthority>) old); |
... | ... | |
544 | 534 |
// return authorities; |
545 | 535 |
// }); |
546 | 536 |
} catch (Exception e) { |
547 |
LOGGER.debug("Exception on assign role to user during add repository" , e);
|
|
537 |
LOGGER.debug("Exception on assign role to user during add repository", e); |
|
548 | 538 |
throw e; |
549 | 539 |
} |
550 | 540 |
|
... | ... | |
566 | 556 |
LOGGER.debug("JSON to add(update) -> " + json_repository); |
567 | 557 |
|
568 | 558 |
HttpEntity<String> httpEntity = new HttpEntity<String>(json_repository, httpHeaders); |
569 |
ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(),HttpMethod.POST, httpEntity, ResponseEntity.class); |
|
559 |
ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class);
|
|
570 | 560 |
|
571 | 561 |
if (responseEntity.getStatusCode().equals(HttpStatus.OK)) { |
572 | 562 |
// emailUtils.sendUserRegistrationEmail(repository, authentication); |
... | ... | |
576 | 566 |
|
577 | 567 |
return repository; |
578 | 568 |
} catch (Exception e) { |
579 |
LOGGER.debug("Exception on updateRepository" , e);
|
|
569 |
LOGGER.debug("Exception on updateRepository", e); |
|
580 | 570 |
emailUtils.reportException(e); |
581 | 571 |
throw e; |
582 | 572 |
} |
... | ... | |
585 | 575 |
} |
586 | 576 |
|
587 | 577 |
@Override |
588 |
public Repository updateRepository(Repository repository,Authentication authentication) throws Exception { |
|
578 |
public Repository updateRepository(Repository repository, Authentication authentication) throws Exception {
|
|
589 | 579 |
UriComponents uriComponents = UriComponentsBuilder |
590 | 580 |
.fromHttpUrl(baseAddress + "/ds/update/") |
591 | 581 |
.build() |
... | ... | |
597 | 587 |
LOGGER.debug("JSON to update -> " + json_repository); |
598 | 588 |
|
599 | 589 |
HttpEntity<String> httpEntity = new HttpEntity<String>(json_repository, httpHeaders); |
600 |
ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(),HttpMethod.POST, httpEntity |
|
590 |
ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity
|
|
601 | 591 |
, ResponseEntity.class); |
602 | 592 |
|
603 | 593 |
if (responseEntity.getStatusCode().equals(HttpStatus.OK)) { |
... | ... | |
608 | 598 |
|
609 | 599 |
return repository; |
610 | 600 |
} catch (Exception e) { |
611 |
LOGGER.debug("Exception on updateRepository" , e);
|
|
601 |
LOGGER.debug("Exception on updateRepository", e); |
|
612 | 602 |
emailUtils.reportException(e); |
613 | 603 |
throw e; |
614 | 604 |
} |
... | ... | |
627 | 617 |
.build() |
628 | 618 |
.encode(); |
629 | 619 |
String json_repository = Converter.repositoryObjectToJson(repository); |
630 |
HttpEntity<String> httpEntity = new HttpEntity <String> (json_repository,httpHeaders);
|
|
631 |
ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(),HttpMethod.POST, httpEntity, ResponseEntity.class); |
|
620 |
HttpEntity<String> httpEntity = new HttpEntity<String>(json_repository, httpHeaders);
|
|
621 |
ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class);
|
|
632 | 622 |
|
633 |
if(responseEntity.getStatusCode().equals(HttpStatus.OK)) { |
|
623 |
if (responseEntity.getStatusCode().equals(HttpStatus.OK)) {
|
|
634 | 624 |
emailUtils.sendUserRegistrationEmail(repository, authentication); |
635 | 625 |
emailUtils.sendAdminRegistrationEmail(repository, authentication); |
636 | 626 |
} else { |
... | ... | |
639 | 629 |
} |
640 | 630 |
|
641 | 631 |
@Override |
642 |
public void deleteRepositoryInterface(String id ,
|
|
643 |
String registeredBy){ |
|
632 |
public void deleteRepositoryInterface(String id, |
|
633 |
String registeredBy) {
|
|
644 | 634 |
UriComponents uriComponents = UriComponentsBuilder |
645 | 635 |
.fromHttpUrl(baseAddress + "/ds/api/") |
646 | 636 |
.path("/{id}") |
... | ... | |
656 | 646 |
String comment, RepositoryInterface repositoryInterface) throws Exception { |
657 | 647 |
try { |
658 | 648 |
Repository e = this.getRepositoryById(repoId); |
659 |
repositoryInterface = createRepositoryInterface(e,repositoryInterface,datatype);
|
|
660 |
String json_interface = Converter.repositoryInterfaceObjectToJson(e,repositoryInterface); |
|
649 |
repositoryInterface = createRepositoryInterface(e, repositoryInterface, datatype);
|
|
650 |
String json_interface = Converter.repositoryInterfaceObjectToJson(e, repositoryInterface);
|
|
661 | 651 |
|
662 | 652 |
UriComponents uriComponents = UriComponentsBuilder |
663 | 653 |
.fromHttpUrl(baseAddress + "/ds/api/add/") |
664 | 654 |
.build() |
665 | 655 |
.encode(); |
666 | 656 |
|
667 |
HttpEntity<String> httpEntity = new HttpEntity <> (json_interface,httpHeaders);
|
|
657 |
HttpEntity<String> httpEntity = new HttpEntity<>(json_interface, httpHeaders);
|
|
668 | 658 |
|
669 |
restTemplate.postForObject(uriComponents.toUri(),httpEntity, String.class); |
|
659 |
restTemplate.postForObject(uriComponents.toUri(), httpEntity, String.class);
|
|
670 | 660 |
|
671 | 661 |
emailUtils.sendAdminRegisterInterfaceEmail(e, comment, repositoryInterface, SecurityContextHolder.getContext().getAuthentication()); |
672 | 662 |
emailUtils.sendUserRegisterInterfaceEmail(e, comment, repositoryInterface, SecurityContextHolder.getContext().getAuthentication()); |
... | ... | |
676 | 666 |
return repositoryInterface; |
677 | 667 |
|
678 | 668 |
} catch (Exception e) { |
679 |
LOGGER.error("Exception on addRepositoryInterface" , e);
|
|
669 |
LOGGER.error("Exception on addRepositoryInterface", e); |
|
680 | 670 |
emailUtils.reportException(e); |
681 | 671 |
throw e; |
682 | 672 |
} |
... | ... | |
687 | 677 |
String registeredBy, |
688 | 678 |
String comment, RepositoryInterface repositoryInterface) throws Exception { |
689 | 679 |
|
690 |
this.updateBaseUrl(repoId,repositoryInterface.getId(),repositoryInterface.getBaseUrl());
|
|
691 |
this.updateCompliance(repoId,repositoryInterface.getId(),repositoryInterface.getCompliance());
|
|
692 |
this.updateValidationSet(repoId,repositoryInterface.getId(),repositoryInterface.getAccessSet());
|
|
680 |
this.updateBaseUrl(repoId, repositoryInterface.getId(), repositoryInterface.getBaseUrl());
|
|
681 |
this.updateCompliance(repoId, repositoryInterface.getId(), repositoryInterface.getCompliance());
|
|
682 |
this.updateValidationSet(repoId, repositoryInterface.getId(), repositoryInterface.getAccessSet());
|
|
693 | 683 |
|
694 | 684 |
Repository e = this.getRepositoryById(repoId); |
695 | 685 |
emailUtils.sendAdminUpdateInterfaceEmail(e, comment, repositoryInterface, SecurityContextHolder.getContext().getAuthentication()); |
696 | 686 |
emailUtils.sendUserUpdateInterfaceEmail(e, comment, repositoryInterface, SecurityContextHolder.getContext().getAuthentication()); |
697 |
submitInterfaceValidation(getRepositoryById(repoId),registeredBy,repositoryInterface,true);
|
|
687 |
submitInterfaceValidation(getRepositoryById(repoId), registeredBy, repositoryInterface, true);
|
|
698 | 688 |
|
699 | 689 |
return repositoryInterface; |
700 | 690 |
} |
... | ... | |
766 | 756 |
|
767 | 757 |
@Override |
768 | 758 |
public List<Timezone> getTimezones() { |
769 |
List<String> timezones = Converter.readFile("timezones.txt");
|
|
759 |
List<String> timezones = Converter.readFile("timezones.txt"); |
|
770 | 760 |
return Converter.toTimezones(timezones); |
771 | 761 |
} |
772 | 762 |
|
773 | 763 |
@Override |
774 | 764 |
public List<String> getUrlsOfUserRepos(String userEmail, |
775 | 765 |
String page, |
776 |
String size){ |
|
766 |
String size) {
|
|
777 | 767 |
UriComponents uriComponents = UriComponentsBuilder |
778 | 768 |
.fromHttpUrl(baseAddress + "/api/baseurl/") |
779 | 769 |
.path("/{page}/{size}") |
780 |
.build().expand(page,size).encode(); |
|
770 |
.build().expand(page, size).encode();
|
|
781 | 771 |
|
782 |
try{ |
|
772 |
try {
|
|
783 | 773 |
RequestFilter requestFilter = new RequestFilter(); |
784 | 774 |
requestFilter.setRegisteredby(userEmail); |
785 |
return Arrays.asList(restTemplate.postForObject(uriComponents.toUri(),requestFilter, String[].class)); |
|
786 |
}catch (Exception e){
|
|
787 |
LOGGER.debug("Exception on addRepositoryInterface" , e);
|
|
775 |
return Arrays.asList(restTemplate.postForObject(uriComponents.toUri(), requestFilter, String[].class));
|
|
776 |
} catch (Exception e) {
|
|
777 |
LOGGER.debug("Exception on addRepositoryInterface", e); |
|
788 | 778 |
emailUtils.reportException(e); |
789 | 779 |
throw e; |
790 | 780 |
} |
... | ... | |
824 | 814 |
|
825 | 815 |
|
826 | 816 |
@Override |
827 |
public Map<String, String> getCompatibilityClasses(String mode) {
|
|
817 |
public Map<String, String> getCompatibilityClasses(String mode) { |
|
828 | 818 |
|
829 | 819 |
LOGGER.debug("Getting compatibility classes for mode: " + mode); |
830 | 820 |
Map<String, String> retMap = new HashMap<String, String>(); |
... | ... | |
853 | 843 |
} |
854 | 844 |
|
855 | 845 |
@Override |
856 |
public Map<String, String> getDatasourceClasses(String mode) {
|
|
846 |
public Map<String, String> getDatasourceClasses(String mode) { |
|
857 | 847 |
|
858 | 848 |
LOGGER.debug("Getting datasource classes for mode: " + mode); |
859 | 849 |
|
... | ... | |
874 | 864 |
retMap.put(entry.getKey(), entry.getValue()); |
875 | 865 |
} |
876 | 866 |
} |
877 |
return filterResults(retMap,mode); |
|
867 |
return filterResults(retMap, mode);
|
|
878 | 868 |
|
879 | 869 |
} |
880 | 870 |
|
881 |
private Map<String,String> filterResults(Map<String, String> map,String mode) {
|
|
871 |
private Map<String, String> filterResults(Map<String, String> map, String mode) {
|
|
882 | 872 |
|
883 |
HashMap<String,String> filteredMap = new HashMap<>(); |
|
884 |
for(String key:map.keySet())
|
|
885 |
if(dataSourceClass.get(mode).contains(key)) |
|
886 |
filteredMap.put(key,map.get(key)); |
|
873 |
HashMap<String, String> filteredMap = new HashMap<>();
|
|
874 |
for (String key : map.keySet())
|
|
875 |
if (dataSourceClass.get(mode).contains(key))
|
|
876 |
filteredMap.put(key, map.get(key));
|
|
887 | 877 |
|
888 | 878 |
return filteredMap; |
889 | 879 |
} |
... | ... | |
911 | 901 |
|
912 | 902 |
@Override |
913 | 903 |
public Map<String, String> getListLatestUpdate(String mode) throws JSONException { |
914 |
if(mode.equals("opendoar")) |
|
915 |
return Collections.singletonMap("lastCollectionDate", getRepositoryInterface("openaire____::"+mode).get(0).getLastCollectionDate());
|
|
904 |
if (mode.equals("opendoar"))
|
|
905 |
return Collections.singletonMap("lastCollectionDate", getRepositoryInterface("openaire____::" + mode).get(0).getLastCollectionDate());
|
|
916 | 906 |
else |
917 | 907 |
/* |
918 |
* first api of re3data has null value on collection date |
|
919 |
* */ |
|
920 |
return Collections.singletonMap("lastCollectionDate", getRepositoryInterface("openaire____::"+mode).get(1).getLastCollectionDate());
|
|
908 |
* first api of re3data has null value on collection date
|
|
909 |
* */
|
|
910 |
return Collections.singletonMap("lastCollectionDate", getRepositoryInterface("openaire____::" + mode).get(1).getLastCollectionDate());
|
|
921 | 911 |
} |
922 | 912 |
|
923 | 913 |
private void updateValidationSet(String repositoryId, String repositoryInterfaceId, String validationSet) throws Exception { |
924 | 914 |
UriComponents uriComponents = UriComponentsBuilder |
925 | 915 |
.fromHttpUrl(baseAddress + "/ds/api/oaiset") |
926 |
.queryParam("dsId",repositoryId) |
|
927 |
.queryParam("apiId",repositoryInterfaceId) |
|
928 |
.queryParam("oaiSet",validationSet) |
|
916 |
.queryParam("dsId", repositoryId)
|
|
917 |
.queryParam("apiId", repositoryInterfaceId)
|
|
918 |
.queryParam("oaiSet", validationSet)
|
|
929 | 919 |
.build().encode(); |
930 |
restTemplate.exchange(uriComponents.toUri(),HttpMethod.POST, null, ResponseEntity.class);
|
|
920 |
restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, null, ResponseEntity.class);
|
|
931 | 921 |
|
932 | 922 |
} |
933 | 923 |
|
... | ... | |
935 | 925 |
private void updateBaseUrl(String repositoryId, String repositoryInterfaceId, String baseUrl) { |
936 | 926 |
UriComponents uriComponents = UriComponentsBuilder |
937 | 927 |
.fromHttpUrl(baseAddress + "/ds/api/baseurl") |
938 |
.queryParam("dsId",repositoryId) |
|
939 |
.queryParam("apiId",repositoryInterfaceId) |
|
940 |
.queryParam("baseUrl",baseUrl) |
|
928 |
.queryParam("dsId", repositoryId)
|
|
929 |
.queryParam("apiId", repositoryInterfaceId)
|
|
930 |
.queryParam("baseUrl", baseUrl)
|
|
941 | 931 |
.build().encode(); |
942 |
restTemplate.postForObject(uriComponents.toUri(),null,String.class);
|
|
932 |
restTemplate.postForObject(uriComponents.toUri(), null, String.class);
|
|
943 | 933 |
} |
944 | 934 |
|
945 |
private void updateCompliance(String repositoryId, String repositoryInterfaceId,String compliance) { |
|
935 |
private void updateCompliance(String repositoryId, String repositoryInterfaceId, String compliance) {
|
|
946 | 936 |
UriComponents uriComponents = UriComponentsBuilder |
947 | 937 |
.fromHttpUrl(baseAddress + "/ds/api/compliance") |
948 |
.queryParam("dsId",repositoryId) |
|
949 |
.queryParam("apiId",repositoryInterfaceId) |
|
950 |
.queryParam("compliance",compliance) |
|
938 |
.queryParam("dsId", repositoryId)
|
|
939 |
.queryParam("apiId", repositoryInterfaceId)
|
|
940 |
.queryParam("compliance", compliance)
|
|
951 | 941 |
.build().encode(); |
952 |
restTemplate.postForObject(uriComponents.toUri(),null,String.class);
|
|
942 |
restTemplate.postForObject(uriComponents.toUri(), null, String.class);
|
|
953 | 943 |
} |
954 | 944 |
|
955 | 945 |
private MetricsNumbers getMetricsNumbers(String openAIREID) throws BrokerException { |
... | ... | |
970 | 960 |
new ParameterizedTypeReference<MetricsNumbers>() { |
971 | 961 |
}); |
972 | 962 |
} catch (RestClientException e) { |
973 |
LOGGER.debug("Exception on getMetricsNumbers" , e);
|
|
963 |
LOGGER.debug("Exception on getMetricsNumbers", e); |
|
974 | 964 |
emailUtils.reportException(e); |
975 | 965 |
throw e; |
976 | 966 |
} |
... | ... | |
987 | 977 |
return null; |
988 | 978 |
} |
989 | 979 |
|
990 |
private UriComponents searchDatasource(String page,String size){
|
|
980 |
private UriComponents searchDatasource(String page, String size) {
|
|
991 | 981 |
|
992 | 982 |
return UriComponentsBuilder |
993 | 983 |
.fromHttpUrl(baseAddress + "/ds/search/") |
994 | 984 |
.path("/{page}/{size}/") |
995 |
.queryParam("requestSortBy","officialname") |
|
996 |
.queryParam("order","ASCENDING") |
|
985 |
.queryParam("requestSortBy", "officialname")
|
|
986 |
.queryParam("order", "ASCENDING")
|
|
997 | 987 |
.build().expand(page, size).encode(); |
998 | 988 |
} |
999 | 989 |
|
1000 |
private UriComponents searchSnipperDatasource(String page,String size){
|
|
990 |
private UriComponents searchSnipperDatasource(String page, String size) {
|
|
1001 | 991 |
|
1002 | 992 |
return UriComponentsBuilder |
1003 | 993 |
.fromHttpUrl(baseAddress + "/ds/searchsnippet/") |
1004 | 994 |
.path("/{page}/{size}/") |
1005 |
.queryParam("requestSortBy","officialname") |
|
1006 |
.queryParam("order","ASCENDING") |
|
995 |
.queryParam("requestSortBy", "officialname")
|
|
996 |
.queryParam("order", "ASCENDING")
|
|
1007 | 997 |
.build().expand(page, size).encode(); |
1008 | 998 |
} |
1009 | 999 |
|
1010 |
private UriComponents searchRegisteredDatasource(String requestSortBy, String order, String page,String size){
|
|
1000 |
private UriComponents searchRegisteredDatasource(String requestSortBy, String order, String page, String size) {
|
|
1011 | 1001 |
|
1012 | 1002 |
return UriComponentsBuilder |
1013 | 1003 |
.fromHttpUrl(baseAddress + "/ds/searchregistered/") |
1014 | 1004 |
.path("/{page}/{size}/") |
1015 |
.queryParam("requestSortBy",requestSortBy) |
|
1016 |
.queryParam("order",order) |
|
1005 |
.queryParam("requestSortBy", requestSortBy)
|
|
1006 |
.queryParam("order", order)
|
|
1017 | 1007 |
.build().expand(page, size).encode(); |
1018 | 1008 |
} |
1019 | 1009 |
|
1020 |
private String getRepositoryType(String typology){ |
|
1010 |
private String getRepositoryType(String typology) {
|
|
1021 | 1011 |
return invertedDataSourceClass.get(typology); |
1022 | 1012 |
} |
1023 | 1013 |
|
1014 |
private List<String> getRoleIdsFromUserRoles(String userEmail) { |
|
1015 |
Integer coPersonId = registryCalls.getCoPersonIdByEmail(userEmail); |
|
1016 |
JsonArray roles; |
|
1017 |
ArrayList<String> roleIds = new ArrayList<>(); |
|
1018 |
ArrayList<Integer> couIds = new ArrayList<>(); |
|
1019 |
if (coPersonId != null) { |
|
1020 |
roles = registryCalls.getRoles(coPersonId); |
|
1021 |
for (JsonElement role : roles) { |
|
1022 |
JsonObject object = role.getAsJsonObject(); |
|
1023 |
if (object.get("CouId") == null) { |
|
1024 |
continue; |
|
1025 |
} |
|
1026 |
couIds.add(object.get("CouId").getAsInt()); |
|
1027 |
} |
|
1024 | 1028 |
|
1029 |
roleIds.addAll(registryCalls.getCouNames(couIds).values()); |
|
1030 |
|
|
1031 |
} |
|
1032 |
return roleIds; |
|
1033 |
} |
|
1034 |
|
|
1035 |
private List<String> getRepoIdsFromUserRoles(String userEmail) { |
|
1036 |
List<String> roleIds = getRoleIdsFromUserRoles(userEmail); |
|
1037 |
List<String> repoIds = new ArrayList<>(); |
|
1038 |
for (String role : roleIds) { |
|
1039 |
if (role.contains("datasource")) { |
|
1040 |
// TODO: ask if checking for BETA prefix is required |
|
1041 |
repoIds.add(role.replaceFirst(".*datasource\\.", "").replace("$", ":")); |
|
1042 |
} |
|
1043 |
} |
|
1044 |
return repoIds; |
|
1045 |
} |
|
1025 | 1046 |
} |
Also available in: Unified diff
1. fixed authorization in RepositoryController
2. created new methods and classes
3. made authorities mapping the same as with other openaire projects
4. refactoring