Compare commits

..

No commits in common. "401de371b293868ebb0b20a18fadc5a264e2f8b9" and "8c07950459c83d0600c089ec8f2f4a10358576b8" have entirely different histories.

30 changed files with 992 additions and 955 deletions

View File

@ -5,5 +5,5 @@
## Install and run:
- Run **git clone** and then **cd uoa-repository-manager-service**.
- Provide all not-set or redacted configurations, inside the **src/main/resources/application.properties** file.
- Build the app with: `mvn clean install`
- Build the app with: `mvn clean install -s <settings-file>`
- Run the app with: `java -jar ./target/uoa-repository-manager-service.jar`

29
pom.xml
View File

@ -64,11 +64,6 @@
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>9.1.1</version>
</dependency>
<dependency>
<groupId>eu.dnetlib.dhp</groupId>
@ -367,30 +362,6 @@
</build>
<repositories>
<repository>
<id>dnet45-bootstrap-snapshot</id>
<name>D-Net 45 Bootstrap Snapshot</name>
<url>https://maven.research-infrastructures.eu/nexus/content/repositories/dnet45-bootstrap-snapshot</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
<layout>default</layout>
</repository>
<repository>
<id>dnet45-bootstrap-release</id>
<name>D-Net 45 Bootstrap Release</name>
<url>https://maven.research-infrastructures.eu/nexus/content/repositories/dnet45-bootstrap-release</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<layout>default</layout>
</repository>
<repository>
<id>dnet-deps</id>
<name>dnet-dependencies</name>

View File

@ -20,7 +20,7 @@ public class AsyncConfiguration implements AsyncConfigurer {
@Override
public void handleUncaughtException(Throwable throwable, Method method, Object... objects) {
logger.error("Async error", throwable);
//logger.error("Async error", throwable);
}
};
}

View File

@ -55,21 +55,22 @@ public class DashboardController {
@PreAuthorize("hasAuthority('REGISTERED_USER')")
public CollectionMonitorSummary getCollectionMonitorSummary(
@PathVariable("repoId") String repoId,
@RequestParam(name = "size", required = false, defaultValue = "20") int summarySize) throws JSONException {
List<AggregationInfo> aggregationInfoList = aggregationService.getRepositoryAggregations(repoId);
@RequestParam(name = "size", required = false, defaultValue = "20") int size) throws JSONException {
List<AggregationInfo> aggregationInfo = aggregationService.getRepositoryAggregations(repoId, 0, size);
CollectionMonitorSummary collectionMonitorSummary = new CollectionMonitorSummary();
// Set the "aggregationInfo" for the first <number of> requested aggregations, in order to create a "summary".
collectionMonitorSummary.setAggregationInfo(aggregationInfoList.subList(0, Math.min(summarySize, aggregationInfoList.size())));
// Search for the last indexed version and set the "collectionMonitorSummary".
for ( AggregationInfo aggregationInfo : aggregationInfoList ) {
if ( aggregationInfo.isIndexedVersion() ) {
collectionMonitorSummary.setLastIndexedVersion(aggregationInfo);
break;
collectionMonitorSummary.setAggregationInfo(aggregationInfo);
size = 0;
do {
aggregationInfo = aggregationService.getRepositoryAggregations(repoId, size, size + 50);
for (AggregationInfo aggregationDetail : aggregationInfo) {
if (aggregationDetail.isIndexedVersion()) {
collectionMonitorSummary.setLastIndexedVersion(aggregationDetail);
break;
}
}
}
size += 30;
} while (aggregationInfo.size() != 0 && collectionMonitorSummary.getLastIndexedVersion() == null);
return collectionMonitorSummary;
}

View File

@ -26,6 +26,7 @@ import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Map;
@ -62,7 +63,7 @@ public class RepositoryController {
@ResponseBody
public List<RepositorySnippet> getRepositoriesByCountry(@PathVariable("country") String country,
@PathVariable("mode") String mode,
@RequestParam(value = "managed", required = false) Boolean managed) {
@RequestParam(value = "managed", required = false) Boolean managed) throws JSONException, IOException {
return repositoryService.getRepositoriesByCountry(country, mode, managed);
}
@ -82,7 +83,7 @@ public class RepositoryController {
public void updateRepositoriesTerms(@RequestBody List<RepositoryTerms> repositoriesTerms) throws Exception {
Date date = new Date();
if (repositoriesTerms != null) {
for (RepositoryTerms terms : repositoriesTerms) {
for (RepositoryTerms terms : repositoriesTerms) {
Repository repository = repositoryService.getRepositoryById(terms.getId());
repository.setConsentTermsOfUse(terms.getConsentTermsOfUse());
repository.setFullTextDownload(terms.getFullTextDownload());
@ -103,7 +104,7 @@ public class RepositoryController {
@RequestParam("requestSortBy") String requestSortBy,
@RequestParam("order") String order,
@PathVariable("page") int page,
@PathVariable("size") int pageSize) {
@PathVariable("size") int pageSize) throws Exception {
return repositoryService.searchRegisteredRepositories(country, typology, englishName, officialName, requestSortBy, order, page, pageSize);
}
@ -112,13 +113,13 @@ public class RepositoryController {
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PostAuthorize("hasAnyAuthority('SUPER_ADMINISTRATOR', 'CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR') or @authorizationService.isMemberOf(#id) or (returnObject.registeredby==null and hasAuthority('REGISTERED_USER'))")
public Repository getRepositoryById(@PathVariable("id") String id) throws ResourceNotFoundException {
public Repository getRepositoryById(@PathVariable("id") String id) throws JSONException, ResourceNotFoundException {
Repository repo = repositoryService.getRepositoryById(id);
if (repo != null)
logger.info("Returning repository {} registered by {}", repo.getId(), repo.getRegisteredby());
logger.info("Returning repository " + repo.getId() + " registered by " + repo.getRegisteredby());
else
logger.info("Requested repository {} not found", id);
logger.info("Requested repository " + id + " not found");
return repo;
}
@ -141,7 +142,7 @@ public class RepositoryController {
@ResponseBody
public List<Repository> getRepositoriesByName(@PathVariable("name") String name,
@PathVariable("page") String page,
@PathVariable("size") String size) {
@PathVariable("size") String size) throws JSONException {
return repositoryService.getRepositoriesByName(name, page, size);
}
@ -149,7 +150,7 @@ public class RepositoryController {
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PostAuthorize("hasAuthority('SUPER_ADMINISTRATOR') or hasAuthority('CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR') or @authorizationService.isMemberOf(#id) or (@repositoryService.getRepositoryById(#id).registeredby==null and hasAuthority('REGISTERED_USER'))")
public List<RepositoryInterface> getRepositoryInterface(@PathVariable("id") String id) {
public List<RepositoryInterface> getRepositoryInterface(@PathVariable("id") String id) throws JSONException {
return repositoryService.getRepositoryInterface(id);
}
@ -159,7 +160,7 @@ public class RepositoryController {
// @PreAuthorize("hasAuthority('SUPER_ADMINISTRATOR') or hasAuthority('CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR') or (hasAuthority(@authorizationService.convertRepoIdToRoleId(#repository.id)) or hasAuthority(@authorizationService.convertRepoIdToRoleId(returnObject.id)))")
@PreAuthorize("hasAuthority('SUPER_ADMINISTRATOR') or hasAuthority('CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR') or hasAuthority('REGISTERED_USER')")
public Repository addRepository(@RequestParam("datatype") String datatype,
@RequestBody Repository repository) {
@RequestBody Repository repository) throws Exception {
return repositoryService.addRepository(datatype, repository);
}
@ -192,7 +193,7 @@ public class RepositoryController {
consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasAuthority('SUPER_ADMINISTRATOR') or hasAuthority('CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR') or @authorizationService.isMemberOf(#repository.id)")
public Repository updateRepository(@RequestBody Repository repository, Authentication authentication) {
public Repository updateRepository(@RequestBody Repository repository, Authentication authentication) throws Exception {
return repositoryService.updateRepository(repository, authentication);
}
@ -260,7 +261,7 @@ public class RepositoryController {
@RequestMapping(value = "/getListLatestUpdate/{mode}", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Map<String, String> getListLatestUpdate(@PathVariable("mode") String mode) {
public Map<String, String> getListLatestUpdate(@PathVariable("mode") String mode) throws JSONException {
return repositoryService.getListLatestUpdate(mode);
}

View File

@ -1,108 +1,109 @@
//package eu.dnetlib.repo.manager.controllers;
//
//import eu.dnetlib.repo.manager.domain.dto.Role;
//import eu.dnetlib.repo.manager.service.aai.registry.AaiRegistryService;
//import eu.dnetlib.repo.manager.service.security.AuthoritiesUpdater;
//import eu.dnetlib.repo.manager.service.security.AuthorizationService;
//import eu.dnetlib.repo.manager.service.security.RoleMappingService;
//import eu.dnetlib.repo.manager.utils.JsonUtils;
//import io.swagger.annotations.ApiOperation;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.ResponseEntity;
//import org.springframework.security.access.prepost.PreAuthorize;
//import org.springframework.web.bind.annotation.*;
//
//import javax.ws.rs.core.MediaType;
//import javax.ws.rs.core.Response;
//import java.util.Collection;
//
////@RestController
////@RequestMapping(value = "/role-management")
////@Api(description = "Role Management", value = "role-management")
//public class UserRoleController {
//
// private final AaiRegistryService aaiRegistryService;
// private final AuthoritiesUpdater authoritiesUpdater;
// private final RoleMappingService roleMappingService;
// private final AuthorizationService authorizationService;
//
// @Autowired
// UserRoleController(AaiRegistryService aaiRegistryService,
// AuthoritiesUpdater authoritiesUpdater,
// RoleMappingService roleMappingService,
// AuthorizationService authorizationService) {
// this.aaiRegistryService = aaiRegistryService;
// this.authoritiesUpdater = authoritiesUpdater;
// this.roleMappingService = roleMappingService;
// this.authorizationService = authorizationService;
// }
//
// /**
// * Get the role with the given id.
// **/
// @RequestMapping(method = RequestMethod.GET, path = "/role/{id}")
//// @PreAuthorize("hasAnyAuthority('REGISTERED_USER', 'SUPER_ADMINISTRATOR', 'CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR')")
// public Response getRole(@RequestParam(value = "type", defaultValue = "datasource") String type, @PathVariable("id") String id) {
// int roleId = aaiRegistryService.getCouId(type, id);
// return Response.status(HttpStatus.OK.value()).entity(JsonUtils.createResponse("Role id is: " + roleId).toString()).type(MediaType.APPLICATION_JSON).build();
// }
//
// /**
// * Create a new role with the given name and description.
// **/
// @RequestMapping(method = RequestMethod.POST, path = "/role")
// @PreAuthorize("hasAnyAuthority('SUPER_ADMINISTRATOR')")
// public Response createRole(@RequestBody Role role) {
// aaiRegistryService.createRole(role);
// return Response.status(HttpStatus.OK.value()).entity(JsonUtils.createResponse("Role has been created").toString()).type(MediaType.APPLICATION_JSON).build();
// }
//
// /**
// * Subscribe to a type(Community, etc.) with id(ee, egi, etc.)
// */
// @ApiOperation(value = "subscribe")
// @RequestMapping(method = RequestMethod.POST, path = "/subscribe/{type}/{id}")
// @PreAuthorize("hasAnyAuthority('SUPER_ADMINISTRATOR', 'CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR')")
// public Response subscribe(@PathVariable("type") String type, @PathVariable("id") String id) {
// Integer coPersonId = aaiRegistryService.getCoPersonIdByIdentifier();
// if (coPersonId == null) {
// coPersonId = aaiRegistryService.getCoPersonIdsByEmail();
// }
// Integer couId = aaiRegistryService.getCouId(type, id);
// if (couId != null) {
// aaiRegistryService.assignMemberRole(coPersonId, couId);
//
// // Add role to current authorities
// authoritiesUpdater.addRole(roleMappingService.convertRepoIdToAuthority(id));
//
// return Response.status(HttpStatus.OK.value()).entity(JsonUtils.createResponse("Role has been assigned").toString()).type(MediaType.APPLICATION_JSON).build();
// } else {
// return Response.status(HttpStatus.NOT_FOUND.value()).entity(JsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
// }
// }
// /////////////////////////////////////////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////////////////////////
//
// @RequestMapping(method = RequestMethod.GET, path = "/users/couid/{id}")
// @PreAuthorize("hasAnyAuthority('SUPER_ADMINISTRATOR', 'CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR')")
// public ResponseEntity<String> getUsersByCouId(@PathVariable("id") Integer id) {
//// calls.getUserByCoId()
// return ResponseEntity.ok(aaiRegistryService.getUsersByCouId(id).toString());
// }
//
//
// @RequestMapping(method = RequestMethod.GET, path = "/users/{email}/roles")
// @PreAuthorize("hasAnyAuthority('SUPER_ADMINISTRATOR', 'CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR') or hasAuthority('REGISTERED_USER') and authentication.userInfo.email==#email")
// public ResponseEntity<Collection<String>> getRolesByEmail(@PathVariable("email") String email) {
// return ResponseEntity.ok(authorizationService.getUserRolesByEmail(email));
// }
//
//
// @RequestMapping(method = RequestMethod.GET, path = "/user/roles/my")
// @PreAuthorize("hasAuthority('REGISTERED_USER')")
// public ResponseEntity<Collection<String>> getRoleNames() {
// return ResponseEntity.ok(authorizationService.getUserRoles());
// }
//
//}
package eu.dnetlib.repo.manager.controllers;
import eu.dnetlib.repo.manager.domain.dto.Role;
import eu.dnetlib.repo.manager.service.aai.registry.AaiRegistryService;
import eu.dnetlib.repo.manager.service.security.AuthoritiesUpdater;
import eu.dnetlib.repo.manager.service.security.AuthorizationService;
import eu.dnetlib.repo.manager.service.security.RoleMappingService;
import eu.dnetlib.repo.manager.utils.JsonUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.Collection;
//@RestController
//@RequestMapping(value = "/role-management")
//@Api(description = "Role Management", value = "role-management")
public class UserRoleController {
private final AaiRegistryService aaiRegistryService;
private final AuthoritiesUpdater authoritiesUpdater;
private final RoleMappingService roleMappingService;
private final AuthorizationService authorizationService;
@Autowired
UserRoleController(AaiRegistryService aaiRegistryService,
AuthoritiesUpdater authoritiesUpdater,
RoleMappingService roleMappingService,
AuthorizationService authorizationService) {
this.aaiRegistryService = aaiRegistryService;
this.authoritiesUpdater = authoritiesUpdater;
this.roleMappingService = roleMappingService;
this.authorizationService = authorizationService;
}
/**
* Get the role with the given id.
**/
@RequestMapping(method = RequestMethod.GET, path = "/role/{id}")
// @PreAuthorize("hasAnyAuthority('REGISTERED_USER', 'SUPER_ADMINISTRATOR', 'CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR')")
public Response getRole(@RequestParam(value = "type", defaultValue = "datasource") String type, @PathVariable("id") String id) {
int roleId = aaiRegistryService.getCouId(type, id);
return Response.status(HttpStatus.OK.value()).entity(JsonUtils.createResponse("Role id is: " + roleId).toString()).type(MediaType.APPLICATION_JSON).build();
}
/**
* Create a new role with the given name and description.
**/
@RequestMapping(method = RequestMethod.POST, path = "/role")
@PreAuthorize("hasAnyAuthority('SUPER_ADMINISTRATOR')")
public Response createRole(@RequestBody Role role) {
aaiRegistryService.createRole(role);
return Response.status(HttpStatus.OK.value()).entity(JsonUtils.createResponse("Role has been created").toString()).type(MediaType.APPLICATION_JSON).build();
}
/**
* Subscribe to a type(Community, etc.) with id(ee, egi, etc.)
*/
@ApiOperation(value = "subscribe")
@RequestMapping(method = RequestMethod.POST, path = "/subscribe/{type}/{id}")
@PreAuthorize("hasAnyAuthority('SUPER_ADMINISTRATOR', 'CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR')")
public Response subscribe(@PathVariable("type") String type, @PathVariable("id") String id) {
Integer coPersonId = aaiRegistryService.getCoPersonIdByIdentifier();
if (coPersonId == null) {
coPersonId = aaiRegistryService.getCoPersonIdByEmail();
}
Integer couId = aaiRegistryService.getCouId(type, id);
if (couId != null) {
Integer role = aaiRegistryService.getRoleId(coPersonId, couId);
aaiRegistryService.assignMemberRole(coPersonId, couId, role);
// Add role to current authorities
authoritiesUpdater.addRole(roleMappingService.convertRepoIdToAuthority(id));
return Response.status(HttpStatus.OK.value()).entity(JsonUtils.createResponse("Role has been assigned").toString()).type(MediaType.APPLICATION_JSON).build();
} else {
return Response.status(HttpStatus.NOT_FOUND.value()).entity(JsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
}
}
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
@RequestMapping(method = RequestMethod.GET, path = "/users/couid/{id}")
@PreAuthorize("hasAnyAuthority('SUPER_ADMINISTRATOR', 'CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR')")
public ResponseEntity<String> getUsersByCouId(@PathVariable("id") Integer id) {
// calls.getUserByCoId()
return ResponseEntity.ok(aaiRegistryService.getUsersByCouId(id).toString());
}
@RequestMapping(method = RequestMethod.GET, path = "/users/{email}/roles")
@PreAuthorize("hasAnyAuthority('SUPER_ADMINISTRATOR', 'CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR') or hasAuthority('REGISTERED_USER') and authentication.userInfo.email==#email")
public ResponseEntity<Collection<String>> getRolesByEmail(@PathVariable("email") String email) {
return ResponseEntity.ok(authorizationService.getUserRolesByEmail(email));
}
@RequestMapping(method = RequestMethod.GET, path = "/user/roles/my")
@PreAuthorize("hasAuthority('REGISTERED_USER')")
public ResponseEntity<Collection<String>> getRoleNames() {
return ResponseEntity.ok(authorizationService.getUserRoles());
}
}

View File

@ -8,6 +8,7 @@ import eu.dnetlib.repo.manager.domain.Tuple;
import eu.dnetlib.repo.manager.domain.broker.*;
import eu.dnetlib.repo.manager.exception.BrokerException;
import org.apache.commons.lang.NotImplementedException;
import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -16,6 +17,8 @@ import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.*;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponents;
@ -24,7 +27,6 @@ import org.springframework.web.util.UriComponentsBuilder;
import javax.annotation.PostConstruct;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
@ -50,7 +52,7 @@ public class BrokerServiceImpl implements BrokerService {
private HttpHeaders httpHeaders;
private final HashMap<String, Term> topics = new HashMap<>();
private HashMap<String, Term> topics = new HashMap<>();
@PostConstruct
private void initDnetTopicsMap() {
@ -76,7 +78,7 @@ public class BrokerServiceImpl implements BrokerService {
@Override
public DatasourcesBroker getDatasourcesOfUser(String user, String includeShared, String includeByOthers) {
public DatasourcesBroker getDatasourcesOfUser(String user, String includeShared, String includeByOthers) throws JSONException {
long start = System.currentTimeMillis();
DatasourcesBroker ret = new DatasourcesBroker();
try {
@ -94,7 +96,7 @@ public class BrokerServiceImpl implements BrokerService {
logger.error("Exception on getDatasourcesOfUser", e);
}
long end = System.currentTimeMillis();
logger.debug("Getting datasources of user in " + (end - start) + "ms");
System.out.println("Getting datasources of user in " + (end - start) + "ms");
return ret;
}
@ -127,15 +129,14 @@ public class BrokerServiceImpl implements BrokerService {
final String service = "/events/{page}/{pageSize}";
long pageNum = Long.parseLong(page);
advQueryObject.setPage(pageNum);
Map<String, Long> uriParams = new HashMap<>();
uriParams.put("page", pageNum);
uriParams.put("page", Long.parseLong(page));
uriParams.put("pageSize", Long.parseLong(size));
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service);
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
advQueryObject.setPage(Long.parseLong(page));
HttpEntity<AdvQueryObject> entity = new HttpEntity<>(advQueryObject, httpHeaders);
ResponseEntity<EventsPage> resp;
try {
@ -143,7 +144,8 @@ public class BrokerServiceImpl implements BrokerService {
builder.buildAndExpand(uriParams).encode().toUri(),
HttpMethod.POST,
entity,
new ParameterizedTypeReference<EventsPage>() {}
new ParameterizedTypeReference<EventsPage>() {
}
);
} catch (RestClientException e) {
throw new BrokerException(e);
@ -169,7 +171,8 @@ public class BrokerServiceImpl implements BrokerService {
// sort the collection by the second field of the tuple which is size
entries.sort((e1, e2) -> (int) (e2.getFirst().getSize() - e1.getFirst().getSize()));
long stop = System.currentTimeMillis();
logger.debug("getDatasourcesOfUserType returned in " + (stop - start) + "ms ");
System.out.println("getDatasourcesOfUserType returned in " + (stop - start) + "ms ");
return entries;
}
@ -177,7 +180,7 @@ public class BrokerServiceImpl implements BrokerService {
public EventsPage showEvents(String datasourceName,
String topic,
String page,
String size) throws BrokerException {
String size) throws BrokerException, JSONException {
final String service = "/events";
@ -206,14 +209,14 @@ public class BrokerServiceImpl implements BrokerService {
final String service = "/subscriptions";
URI uri = UriComponentsBuilder.fromHttpUrl(openairePath + service)
.queryParam("email", userEmail).build().encode().toUri();
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service)
.queryParam("email", userEmail);
logger.debug("{}", uri);
logger.debug("{}", builder.build().encode().toUri());
ResponseEntity<Map<String, List<SimpleSubscriptionDesc>>> resp;
try {
resp = restTemplate.exchange(
uri,
builder.build().encode().toUri(),
HttpMethod.GET,
null,
new ParameterizedTypeReference<Map<String, List<SimpleSubscriptionDesc>>>() {
@ -225,9 +228,10 @@ public class BrokerServiceImpl implements BrokerService {
}
@Override
public Map<String, List<SimpleSubscriptionDesc>> getSimpleSubscriptionsOfUserByRepoId(String userEmail, String repoId) { //throws BrokerException {
public Map<String, List<SimpleSubscriptionDesc>> getSimpleSubscriptionsOfUserByRepoId(String userEmail, String repoId) throws BrokerException {
Map<String, List<SimpleSubscriptionDesc>> subscriptionsOfUser = getSimpleSubscriptionsOfUser(userEmail);
throw new NotImplementedException();
//Map<String, List<SimpleSubscriptionDesc>> subscriptionsOfUser = getSimpleSubscriptionsOfUser(userEmail);
// return null;
}
@Override

View File

@ -39,50 +39,41 @@ public class DashboardServiceImpl implements DashboardService {
try {
List<RepositorySnippet> repositoriesOfUser = repositoryService.getRepositoriesSnippetsOfUser(userEmail, page, size);
for (RepositorySnippet repository : repositoriesOfUser)
{
String repoId = repository.getId();
String repoOfficialName = repository.getOfficialname();
for (RepositorySnippet repository : repositoriesOfUser) {
RepositorySummaryInfo repositorySummaryInfo = new RepositorySummaryInfo();
repositorySummaryInfo.setId(repoId);
repositorySummaryInfo.setRepositoryName(repoOfficialName);
repositorySummaryInfo.setId(repository.getId());
repositorySummaryInfo.setRepositoryName(repository.getOfficialname());
repositorySummaryInfo.setLogoURL(repository.getLogoUrl());
//TODO getRepositoryAggregations returns only the 20 more recent items. Is it positive that we will find an indexed version there?
boolean isIndexedVersionFound = false;
long start = System.currentTimeMillis();
List<AggregationInfo> aggregationInfoList = aggregationService.getRepositoryAggregations(repoId, 0, 20);
List<AggregationInfo> aggregationInfoList = aggregationService.getRepositoryAggregations(repository.getId(), 0, 20);
for (AggregationInfo aggregationInfo : aggregationInfoList) {
if (aggregationInfo.isIndexedVersion()) {
repositorySummaryInfo.setRecordsCollected(aggregationInfo.getNumberOfRecords());
repositorySummaryInfo.setLastIndexedVersion(DateUtils.toDate(aggregationInfo.getDate()));
isIndexedVersionFound = true;
break;
}
}
long end = System.currentTimeMillis();
if ( isIndexedVersionFound )
logger.debug("Got repo aggregations in " + (end - start) + "ms");
else
logger.warn("Could not find repo aggregations, after " + (end - start) + "ms!");
System.out.println("Got repo aggregations in " + (end - start) + "ms");
try {
MetricsInfo metricsInfo = repositoryService.getMetricsInfoForRepository(repoId);
MetricsInfo metricsInfo = repositoryService.getMetricsInfoForRepository(repository.getId());
repositorySummaryInfo.setTotalDownloads(metricsInfo.getMetricsNumbers().getTotalDownloads());
repositorySummaryInfo.setTotalViews(metricsInfo.getMetricsNumbers().getTotalViews());
} catch (RepositoryServiceException e) {
logger.error("Exception getting metrics info for repository: {}, {} ", repoId, repoOfficialName, e);
logger.error("Exception getting metrics info for repository: " + repository.getId(), e);
}
try {
List<BrowseEntry> events = brokerService.getTopicsForDatasource(repoOfficialName);
List<BrowseEntry> events = brokerService.getTopicsForDatasource(repository.getOfficialname());
Long totalEvents = 0L;
for (BrowseEntry browseEntry : events)
totalEvents += browseEntry.getSize();
repositorySummaryInfo.setEnrichmentEvents(totalEvents);
} catch (BrokerException e) {
logger.error("Exception getting broker events for repository: {}, {} ", repoId, repoOfficialName, e);
logger.error("Exception getting broker events for repository: " + repository.getId(), e);
}
repositorySummaryInfoList.add(repositorySummaryInfo);

View File

@ -32,38 +32,38 @@ public interface EmailUtils {
void sendUserRegistrationEmail(Repository repository, Authentication authentication);
@Async
void sendAdminRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, String desiredCompatibility, Authentication authentication);
void sendAdminRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication);
@Async
void sendUserRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, String desiredCompatibility, Authentication authentication);
void sendUserRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication);
/****SUCCESSFUL REGISTRATION RESULTS EMAILS****/
@Async
void sendUserRegistrationResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication);
void sendUserRegistrationResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
@Async
void sendAdminRegistrationResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication);
void sendAdminRegistrationResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
/****FAILURE REGISTRATION RESULTS EMAILS****/
@Async
void sendUserRegistrationResultsFailureEmail(String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication);
void sendUserRegistrationResultsFailureEmail(String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
@Async
void sendAdminRegistrationResultsFailureEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication);
void sendAdminRegistrationResultsFailureEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
/****SUCCESSFUL UPDATE RESULTS EMAILS****/
@Async
void sendUserUpdateResultsSuccessEmail(String issuer, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication);
void sendUserUpdateResultsSuccessEmail(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
@Async
void sendAdminUpdateResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication);
void sendAdminUpdateResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
/****FAILURE UPDATE RESULTS EMAILS****/
@Async
void sendUserUpdateResultsFailureEmail(String issuer, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication);
void sendUserUpdateResultsFailureEmail(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
@Async
void sendAdminUpdateResultsFailureEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication);
void sendAdminUpdateResultsFailureEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
/****FAILURE UPDATE INTERFACE COMPLIANCE****/
@Async
@ -91,10 +91,10 @@ public interface EmailUtils {
void sendUserUpdateRepositoryInfoEmail(Repository repository, Authentication authentication);
@Async
void sendAdminUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, String desiredCompatibility, Authentication authentication);
void sendAdminUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication);
@Async
void sendUserUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, String desiredCompatibility, Authentication authentication);
void sendUserUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication);
@Async
void sendSubmitJobForValidationEmail(Authentication authentication, JobForValidation jobForValidation);
@ -102,7 +102,6 @@ public interface EmailUtils {
@Async
void sendUponJobCompletion(String repoId,
String repoInterfaceId,
String compatibility,
int scoreUsage,
int scoreContent,
boolean isSuccess,

View File

@ -6,6 +6,7 @@ import eu.dnetlib.repo.manager.exception.ResourceConflictException;
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
import eu.dnetlib.repo.manager.repository.InterfaceComplianceRequestsRepository;
import eu.dnetlib.repo.manager.service.security.AuthorizationService;
import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
@ -49,7 +50,7 @@ public class InterfaceComplianceService {
List<User> repositoryAdmins = authorizationService.getAdminsOfRepo(request.getRepositoryId());
emailUtils.sendUserUpdateInterfaceComplianceFailure(repositoryAdmins.stream().map(User::getEmail).collect(Collectors.toList()), repo, iFace, request);
emailUtils.sendAdminUpdateInterfaceComplianceFailure(repo, iFace, request);
} catch (ResourceNotFoundException e) {
} catch (JSONException | ResourceNotFoundException e) {
logger.error("Error", e);
}
}
@ -58,7 +59,7 @@ public class InterfaceComplianceService {
private Set<InterfaceComplianceRequest> getOutdated() {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE, -7); // 7-days-old
calendar.add(Calendar.DATE, -7);
return this.repository.findAllBySubmissionDateBefore(calendar.getTime());
}

View File

@ -52,7 +52,7 @@ public class MonitorServiceImpl implements MonitorService {
String dateFrom,
String dateTo,
String validationStatus,
String includeJobsTotal) throws ValidatorServiceException, NumberFormatException {
String includeJobsTotal) throws JSONException, ValidatorServiceException {
/////////////////////////////////////////////////////////////////////////////////////////
// FIXME: this is a hack for CRIS Jan Dvorak Validator, should be implemented properly //
@ -95,6 +95,7 @@ public class MonitorServiceImpl implements MonitorService {
|| (job.getValidationType().equals("U") && job.getContentJobStatus().equals("none") && job.getUsageJobStatus().equals("finished") && job.getUsageJobScore() <= 50)) {
job.setValidationStatus("failed");
}
}
}
@ -139,6 +140,7 @@ public class MonitorServiceImpl implements MonitorService {
/////////////////////////////////////////////////////////////////////////////////////////
return retJobs;
}
private int getJobsTotalNumberOfUser(String user, String jobType, String validationStatus) throws ValidatorServiceException {
@ -164,12 +166,13 @@ public class MonitorServiceImpl implements MonitorService {
}
@Override
public StoredJob getJobSummary(String jobId, String groupBy) {
public StoredJob getJobSummary(String jobId,
String groupBy) throws JSONException {
logger.debug("Getting job summary with id : " + jobId);
StoredJob job = null;
try {
job = getValidationService().getStoredJob(Integer.parseInt(jobId), groupBy);
} catch (Exception e) {
} catch (ValidatorServiceException e) {
logger.error(e.getMessage(), e);
}
/////////////////////////////////////////////////////////////////////////////////////////
@ -186,5 +189,4 @@ public class MonitorServiceImpl implements MonitorService {
/////////////////////////////////////////////////////////////////////////////////////////
return job;
}
}

View File

@ -226,12 +226,12 @@ public class PiWikServiceImpl implements PiWikService {
@Override
public Integer getTotal() {
return new JdbcTemplate(dataSource).queryForObject(GET_PIWIK_SITES_TOTAL, Integer.class, new Object[]{});
return new JdbcTemplate(dataSource).queryForObject(GET_PIWIK_SITES_TOTAL, new Object[]{}, Integer.class);
}
@Override
public Integer getValidated(boolean validated) {
String finalizedQuery = GET_PIWIK_SITES_TOTAL + " where validated = ?";
return new JdbcTemplate(dataSource).queryForObject(finalizedQuery, Integer.class, validated);
return new JdbcTemplate(dataSource).queryForObject(finalizedQuery, new Object[]{validated}, Integer.class);
}
}

View File

@ -1,12 +1,12 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.api.functionality.ValidatorServiceException;
import eu.dnetlib.repo.manager.domain.*;
import eu.dnetlib.repo.manager.exception.RepositoryServiceException;
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
import org.json.JSONException;
import org.springframework.security.core.Authentication;
import java.io.IOException;
import java.util.List;
import java.util.Map;
@ -16,43 +16,45 @@ public interface RepositoryService {
// TODO: move this elsewhere
Country[] getCountries();
List<Repository> getRepositories(List<String> ids);
List<Repository> getRepositories(List<String> ids) throws JSONException;
List<Repository> getRepositories(List<String> ids, int page, int size);
List<Repository> getRepositories(List<String> ids, int page, int size) throws JSONException;
List<RepositorySnippet> getRepositoriesSnippets(List<String> ids) throws Exception;
List<RepositorySnippet> getRepositoriesSnippets(List<String> ids, int page, int size) throws Exception;
List<RepositorySnippet> getRepositoriesByCountry(String country, String mode, Boolean managed);
List<RepositorySnippet> getRepositoriesByCountry(String country, String mode, Boolean managed) throws JSONException, IOException;
// TODO: remove?
List<Repository> getRepositoriesOfUser(String page, String size);
List<Repository> getRepositoriesOfUser(String page, String size) throws JSONException, IOException;
// TODO: remove?
List<Repository> getRepositoriesOfUser(String userEmail, String page, String size);
List<Repository> getRepositoriesOfUser(String userEmail,
String page,
String size) throws JSONException, IOException;
List<RepositorySnippet> getRepositoriesSnippetsOfUser(String page, String size);
List<RepositorySnippet> getRepositoriesSnippetsOfUser(String page, String size) throws Exception;
List<RepositorySnippet> getRepositoriesSnippetsOfUser(String userEmail, String page, String size);
List<RepositorySnippet> getRepositoriesSnippetsOfUser(String userEmail, String page, String size) throws Exception;
RepositorySnippet getRepositorySnippetById(String id) throws ResourceNotFoundException;
RepositorySnippet getRepositorySnippetById(String id) throws JSONException, ResourceNotFoundException;
Repository getRepositoryById(String id) throws ResourceNotFoundException;
Repository getRepositoryById(String id) throws JSONException, ResourceNotFoundException;
List<Repository> getRepositoriesByName(String name,
String page,
String size);
String size) throws JSONException;
List<RepositorySnippet> searchRegisteredRepositories(String country, String typology, String englishName,
String officialName, String requestSortBy, String order,
int page, int pageSize);
int page, int pageSize) throws Exception;
Integer getTotalRegisteredRepositories();
List<RepositoryInterface> getRepositoryInterface(String id);
List<RepositoryInterface> getRepositoryInterface(String id) throws JSONException;
Repository addRepository(String datatype, Repository repository);
Repository addRepository(String datatype, Repository repository) throws Exception;
void deleteRepositoryInterface(String id, String registeredBy);
@ -68,9 +70,11 @@ public interface RepositoryService {
List<Timezone> getTimezones();
Repository updateRepository(Repository repository, Authentication authentication);
Repository updateRepository(Repository repository, Authentication authentication) throws Exception;
List<String> getUrlsOfUserRepos(String userEmail, String page, String size);
List<String> getUrlsOfUserRepos(String user_email,
String page,
String size);
Map<String, String> getCompatibilityClasses(String mode);
@ -82,7 +86,7 @@ public interface RepositoryService {
Map<String, String> getListLatestUpdate(String mode);
RepositoryInterface updateRepositoryInterface(String repoId, String comment, RepositoryInterface repositoryInterface, String desiredCompatibilityLevel) throws ResourceNotFoundException, ValidatorServiceException;
RepositoryInterface updateRepositoryInterface(String repoId, String comment, RepositoryInterface repositoryInterface, String desiredCompatibilityLevel) throws Exception;
void updateInterfaceCompliance(String repositoryId, String repositoryInterfaceId, String compliance);
}

View File

@ -4,20 +4,24 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import eu.dnetlib.api.functionality.ValidatorServiceException;
import eu.dnetlib.domain.enabling.Vocabulary;
import eu.dnetlib.domain.functionality.validator.JobForValidation;
import eu.dnetlib.repo.manager.domain.*;
import eu.dnetlib.repo.manager.domain.dto.Role;
import eu.dnetlib.repo.manager.domain.dto.User;
import eu.dnetlib.repo.manager.exception.RepositoryServiceException;
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
import eu.dnetlib.repo.manager.service.aai.registry.AaiRegistryService;
import eu.dnetlib.repo.manager.service.security.AuthoritiesUpdater;
import eu.dnetlib.repo.manager.service.security.AuthorizationService;
import eu.dnetlib.repo.manager.service.security.RoleMappingService;
import eu.dnetlib.repo.manager.utils.Converter;
import eu.dnetlib.repo.manager.utils.DateUtils;
import gr.uoa.di.driver.enabling.vocabulary.VocabularyLoader;
import org.apache.commons.codec.digest.DigestUtils;
import org.json.JSONException;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -30,11 +34,13 @@ import org.springframework.http.converter.json.MappingJackson2HttpMessageConvert
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import javax.annotation.PostConstruct;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
@ -47,6 +53,7 @@ public class RepositoryServiceImpl implements RepositoryService {
private final AuthorizationService authorizationService;
private final RoleMappingService roleMappingService;
private final AaiRegistryService registryCalls;
private final AuthoritiesUpdater authoritiesUpdater;
private final RestTemplate restTemplate;
private final ObjectMapper objectMapper;
private final VocabularyLoader vocabularyLoader;
@ -81,9 +88,11 @@ public class RepositoryServiceImpl implements RepositoryService {
public RepositoryServiceImpl(AuthorizationService authorizationService,
RoleMappingService roleMappingService,
AaiRegistryService registryCalls,
AuthoritiesUpdater authoritiesUpdater,
VocabularyLoader vocabularyLoader,
RestTemplate restTemplate,
ObjectMapper objectMapper,
// Converter converter,
@Lazy EmailUtils emailUtils,
@Lazy ValidatorService validatorService,
@Lazy PiWikService piWikService,
@ -91,6 +100,7 @@ public class RepositoryServiceImpl implements RepositoryService {
this.authorizationService = authorizationService;
this.roleMappingService = roleMappingService;
this.registryCalls = registryCalls;
this.authoritiesUpdater = authoritiesUpdater;
this.vocabularyLoader = vocabularyLoader;
this.piWikService = piWikService;
this.emailUtils = emailUtils;
@ -126,7 +136,7 @@ public class RepositoryServiceImpl implements RepositoryService {
}
httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
httpHeaders.setContentType(MediaType.valueOf(MediaType.APPLICATION_JSON_VALUE));
for (String vocName : vocabularyNames) {
vocabularyMap.put(vocName, vocabularyLoader.getVocabulary(vocName, Locale.ENGLISH, Locale.ROOT));
@ -151,7 +161,7 @@ public class RepositoryServiceImpl implements RepositoryService {
// and the "requestFilter.setId(repoId)" should return only one result at a time, thus,
// another way for paging must be implemented.
@Override
public List<Repository> getRepositories(List<String> ids) {
public List<Repository> getRepositories(List<String> ids) throws JSONException {
return getRepositories(ids, 0, 10);
}
@ -180,7 +190,7 @@ public class RepositoryServiceImpl implements RepositoryService {
// and the "requestFilter.setId(repoId)" should return only one result at a time, thus,
// another way for paging must be implemented.
@Override
public List<RepositorySnippet> getRepositoriesSnippets(List<String> ids) {
public List<RepositorySnippet> getRepositoriesSnippets(List<String> ids) throws Exception {
return getRepositoriesSnippets(ids, 0, 10);
}
@ -188,8 +198,8 @@ public class RepositoryServiceImpl implements RepositoryService {
// and the "requestFilter.setId(repoId)" should return only one result at a time, thus,
// another way for paging must be implemented.
@Override
public List<RepositorySnippet> getRepositoriesSnippets(List<String> ids, int page, int size) {
List<RepositorySnippet> resultSet = null;
public List<RepositorySnippet> getRepositoriesSnippets(List<String> ids, int page, int size) throws Exception {
List<RepositorySnippet> resultSet;
List<DatasourceDetails> datasourceDetailsList = new ArrayList<>();
// here page should be 0
@ -198,6 +208,7 @@ public class RepositoryServiceImpl implements RepositoryService {
for (String repoId : ids) {
requestFilter.setId(repoId);
DatasourceResponse rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, DatasourceResponse.class);
if (rs == null) {
logger.error("The \"DatasourceResponse\" is null!");
@ -206,18 +217,15 @@ public class RepositoryServiceImpl implements RepositoryService {
}
}
try {
resultSet = objectMapper.readValue(objectMapper.writeValueAsString(datasourceDetailsList),
objectMapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class));
if (logger.isDebugEnabled()) {
logger.debug("resultSet: {}", objectMapper.writeValueAsString(resultSet));
}
resultSet.parallelStream().forEach(repositorySnippet -> {
repositorySnippet.setPiwikInfo(piWikService.getPiwikSiteForRepo(repositorySnippet.getId()));
});
} catch (JsonProcessingException e) {
logger.error("Error deserializing.", e);
resultSet = objectMapper.readValue(objectMapper.writeValueAsString(datasourceDetailsList),
objectMapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class));
if (logger.isDebugEnabled()) {
logger.debug("resultSet: {}", objectMapper.writeValueAsString(resultSet));
}
resultSet.parallelStream().forEach(repositorySnippet -> {
repositorySnippet.setPiwikInfo(piWikService.getPiwikSiteForRepo(repositorySnippet.getId()));
});
return resultSet;
}
@ -225,7 +233,7 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override
public List<RepositorySnippet> getRepositoriesByCountry(String country,
String mode,
Boolean managed) {
Boolean managed) throws IOException {
logger.debug("Getting repositories by country!");
int page = 0;
int size = 100;
@ -248,7 +256,7 @@ public class RepositoryServiceImpl implements RepositoryService {
}
public List<RepositorySnippet> searchRegisteredRepositories(String country, String typology, String englishName,
String officialName, String requestSortBy, String order, int page, int pageSize) {
String officialName, String requestSortBy, String order, int page, int pageSize) throws Exception {
logger.debug("Searching registered repositories");
@ -281,7 +289,7 @@ public class RepositoryServiceImpl implements RepositoryService {
}
@Override
public List<Repository> getRepositoriesOfUser(String page, String size) {
public List<Repository> getRepositoriesOfUser(String page, String size) throws JSONException {
logger.debug("Retrieving repositories of authenticated user : {}",
((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail());
Collection<String> repoIds = roleMappingService.getRepoIdsByRoleIds(authorizationService.getUserRoles());
@ -289,19 +297,19 @@ public class RepositoryServiceImpl implements RepositoryService {
}
@Override
public List<Repository> getRepositoriesOfUser(String userEmail, String page, String size) {
public List<Repository> getRepositoriesOfUser(String userEmail, String page, String size) throws JSONException {
logger.debug("Retrieving repositories of authenticated user : {}", userEmail);
Collection<String> repoIds = roleMappingService.getRepoIdsByRoleIds(authorizationService.getUserRolesByEmail(userEmail));
return getRepositories(new ArrayList<>(repoIds));
}
@Override
public List<RepositorySnippet> getRepositoriesSnippetsOfUser(String page, String size) {
public List<RepositorySnippet> getRepositoriesSnippetsOfUser(String page, String size) throws Exception {
return getRepositoriesSnippetsOfUser(null, page, size);
}
@Override
public List<RepositorySnippet> getRepositoriesSnippetsOfUser(String userEmail, String page, String size) {
public List<RepositorySnippet> getRepositoriesSnippetsOfUser(String userEmail, String page, String size) throws Exception {
int from = Integer.parseInt(page) * Integer.parseInt(size);
int to = from + Integer.parseInt(size);
List<String> repoIds = new ArrayList<>();
@ -355,7 +363,7 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override
public List<Repository> getRepositoriesByName(String name,
String page,
String size) {
String size) throws JSONException {
logger.debug("Retrieving repositories with official name : {}", name);
UriComponents uriComponents = searchDatasourceUri("0", "100");
@ -394,7 +402,7 @@ public class RepositoryServiceImpl implements RepositoryService {
}
@Override
public Repository addRepository(String datatype, Repository repository) {
public Repository addRepository(String datatype, Repository repository) throws Exception {
logger.debug("storing '{}' repository with id: {}", datatype, repository.getId());
@ -425,7 +433,32 @@ public class RepositoryServiceImpl implements RepositoryService {
this.latentUpdate(repository, SecurityContextHolder.getContext().getAuthentication());
}
authorizationService.createAndAssignRoleToAuthenticatedUser(repository.getId(), repository.getOfficialname());
// TODO: move the following code elsewhere (creation and assignment of role to user) ??
// Create new role
String newRoleName = roleMappingService.getRoleIdByRepoId(repository.getId());
Role newRole = new Role(newRoleName, repository.getOfficialname());
Integer couId = null;
try {
couId = registryCalls.createRole(newRole);
} catch (HttpClientErrorException e) {
couId = registryCalls.getCouId(newRoleName);
if (couId == null) {
logger.error(String.format("Could not create role '%s'", newRoleName), e);
}
} catch (Exception e) {
logger.error(String.format("Could not create role '%s'", newRoleName), e);
throw e;
}
// Assign new role to the user that created it
Integer coPersonId = registryCalls.getCoPersonIdByIdentifier();
if (couId != null) {
Integer role = registryCalls.getRoleId(coPersonId, couId);
registryCalls.assignMemberRole(coPersonId, couId, role);
// Add role to current user authorities
authoritiesUpdater.addRole(roleMappingService.convertRepoIdToAuthority(repository.getId()));
}
return repository;
}
@ -453,7 +486,7 @@ public class RepositoryServiceImpl implements RepositoryService {
}
@Override
public Repository updateRepository(Repository repository, Authentication authentication) {
public Repository updateRepository(Repository repository, Authentication authentication) throws Exception {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/update/")
.build()
@ -474,7 +507,7 @@ public class RepositoryServiceImpl implements RepositoryService {
return repository;
}
private void storeRepository(Repository repository, Authentication authentication) {
private void storeRepository(Repository repository, Authentication authentication) throws Exception {
Date utilDate = new Date();
Timestamp date = new Timestamp(utilDate.getTime());
@ -517,12 +550,13 @@ public class RepositoryServiceImpl implements RepositoryService {
RepositoryInterface repositoryInterface,
String desiredCompatibilityLevel) throws Exception {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
Repository repo = this.getRepositoryById(repoId);
repositoryInterface = fillInterfaceFields(repo, repositoryInterface, datatype);
Repository e = this.getRepositoryById(repoId);
repositoryInterface = fillInterfaceFields(e, repositoryInterface, datatype);
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/api/add/")
.build().encode();
.build()
.encode();
HttpEntity<RepositoryInterface> httpEntity = new HttpEntity<>(repositoryInterface, httpHeaders);
restTemplate.postForObject(uriComponents.toUri(), httpEntity, String.class);
@ -530,17 +564,15 @@ public class RepositoryServiceImpl implements RepositoryService {
// Explicitly update validation set (updating the interface does not allow updating the set value)
this.updateValidationSet(repoId, repositoryInterface.getId(), repositoryInterface.getAccessSet());
emailUtils.sendAdminRegisterInterfaceEmail(repo, comment, repositoryInterface, desiredCompatibilityLevel, authentication);
emailUtils.sendUserRegisterInterfaceEmail(repo, comment, repositoryInterface, desiredCompatibilityLevel, authentication);
emailUtils.sendAdminRegisterInterfaceEmail(e, comment, repositoryInterface, authentication);
emailUtils.sendUserRegisterInterfaceEmail(e, comment, repositoryInterface, authentication);
String prevCompatibilityLevel = repositoryInterface.getCompatibility();
if ( (desiredCompatibilityLevel != null)
&& ((prevCompatibilityLevel == null) || ! prevCompatibilityLevel.equals(desiredCompatibilityLevel))) {
if (desiredCompatibilityLevel != null && (repositoryInterface.getCompatibility() == null || !repositoryInterface.getCompatibility().equals(desiredCompatibilityLevel))) {
InterfaceComplianceRequest request = new InterfaceComplianceRequest(repoId, repositoryInterface.getId(), desiredCompatibilityLevel);
interfaceComplianceService.create(request);
}
submitInterfaceValidation(repo, getAuthenticatedUser().getEmail(), repositoryInterface, false, desiredCompatibilityLevel);
submitInterfaceValidation(e, getAuthenticatedUser().getEmail(), repositoryInterface, false, repositoryInterface.getCompatibility());
return repositoryInterface;
}
@ -549,7 +581,7 @@ public class RepositoryServiceImpl implements RepositoryService {
public RepositoryInterface updateRepositoryInterface(String repoId,
String comment,
RepositoryInterface repositoryInterface,
String desiredCompatibilityLevel) throws ResourceNotFoundException, ValidatorServiceException {
String desiredCompatibilityLevel) throws Exception {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
Repository repository = this.getRepositoryById(repoId);
if (repositoryInterface.getId() != null) {
@ -561,8 +593,8 @@ public class RepositoryServiceImpl implements RepositoryService {
this.updateValidationSet(repoId, repositoryInterface.getId(), repositoryInterface.getAccessSet());
emailUtils.sendAdminUpdateInterfaceEmail(repository, comment, repositoryInterface, desiredCompatibilityLevel, authentication);
emailUtils.sendUserUpdateInterfaceEmail(repository, comment, repositoryInterface, desiredCompatibilityLevel, authentication);
emailUtils.sendAdminUpdateInterfaceEmail(repository, comment, repositoryInterface, authentication);
emailUtils.sendUserUpdateInterfaceEmail(repository, comment, repositoryInterface, authentication);
if (desiredCompatibilityLevel != null && (repositoryInterface.getCompatibility() == null || !repositoryInterface.getCompatibility().equals(desiredCompatibilityLevel))) {
InterfaceComplianceRequest request = new InterfaceComplianceRequest(repoId, repositoryInterface.getId(), desiredCompatibilityLevel);
@ -672,8 +704,8 @@ public class RepositoryServiceImpl implements RepositoryService {
RequestFilter requestFilter = new RequestFilter();
requestFilter.setRegisteredby(userEmail);
String[] result = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String[].class);
return (result != null) ? Arrays.asList(result) : null;
Object result = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String[].class);
return (result != null) ? Collections.singletonList(result.toString()) : null;
}
private Vocabulary getVocabulary(String vocName) {
@ -689,7 +721,7 @@ public class RepositoryServiceImpl implements RepositoryService {
public Map<String, String> getCompatibilityClasses(String mode) {
logger.debug("Getting compatibility classes for mode: {}", mode);
Map<String, String> retMap = new HashMap<>();
Map<String, String> retMap = new HashMap<String, String>();
Map<String, String> compatibilityClasses = this.getVocabulary("dnet:compatibilityLevel").getAsMap();
boolean foundData = false;
@ -724,7 +756,7 @@ public class RepositoryServiceImpl implements RepositoryService {
logger.debug("Getting datasource classes for mode: {}", mode);
Map<String, String> retMap = new HashMap<>();
Map<String, String> retMap = new HashMap<String, String>();
// TODO: refactor (remove?)
for (Map.Entry<String, String> entry : this.getVocabulary("dnet:datasource_typologies").getAsMap().entrySet()) {
@ -818,7 +850,7 @@ public class RepositoryServiceImpl implements RepositoryService {
return Collections.singletonMap("lastCollectionDate", DateUtils.toString(getRepositoryInterface("openaire____::" + mode).get(0).getLastCollectionDate()));
}
private void updateValidationSet(String repositoryId, String repositoryInterfaceId, String validationSet) {
private void updateValidationSet(String repositoryId, String repositoryInterfaceId, String validationSet) throws Exception {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/api/oaiset")
.queryParam("dsId", repositoryId)
@ -962,19 +994,22 @@ public class RepositoryServiceImpl implements RepositoryService {
}
private List<String> getRoleIdsFromUserRoles(String userEmail) {
List<Integer> coPersonId = registryCalls.getCoPersonIdsByEmail(userEmail);
Integer coPersonId = registryCalls.getCoPersonIdByEmail(userEmail);
JsonArray roles;
ArrayList<String> roleIds = new ArrayList<>();
ArrayList<Integer> couIds = new ArrayList<>();
if (coPersonId != null) {
roles = registryCalls.getRolesWithStatus(coPersonId, AaiRegistryService.RoleStatus.ACTIVE);
for (JsonElement role : roles) {
JsonElement couId = role.getAsJsonObject().get("CouId");
if (couId != null)
couIds.add(couId.getAsInt());
JsonObject object = role.getAsJsonObject();
if (object.get("CouId") == null) {
continue;
}
couIds.add(object.get("CouId").getAsInt());
}
roleIds.addAll(registryCalls.getCouNames(couIds).values());
}
return roleIds;
}

View File

@ -95,20 +95,22 @@ public class SushiliteServiceImpl implements SushiliteService {
Customer customer = reportResponseWrapper.getReportResponse().getReportWrapper().getReport().getCustomer();
List<ReportItem> allReportItems = customer.getReportItems();
if ( allReportItems != null ) {
if ( allReportItems != null) {
try {
int totalItems = allReportItems.size();
int size = Integer.parseInt(pageSize);
int offset = (Integer.parseInt(page) * size);
if ( offset < totalItems ) {
if (offset < totalItems ) {
int upperIndex = (offset + size);
if ( upperIndex > totalItems ) {
if (upperIndex > totalItems) {
upperIndex = totalItems;
}
requestedItemList = allReportItems.subList(offset, upperIndex);
}
} catch (NumberFormatException e) {
logger.error("Exception on getReportResults - trying to cast strings to integers", e);
logger.debug("Exception on getReportResults - trying to cast strings to integers", e);
//emailUtils.reportException(e);
throw e;
}
}

View File

@ -185,7 +185,7 @@ public class ValidatorServiceImpl implements ValidatorService {
}
}
}
if (ruleSet != null) {
if (ruleSet != null){
for (int ruleId : job.getRules()) {
if (ruleSet.getContentRulesIds().contains(ruleId))
contentRules.add(ruleId);
@ -210,13 +210,16 @@ public class ValidatorServiceImpl implements ValidatorService {
@Override
public List<String> getSetsOfRepository(String url) {
logger.debug("Getting sets of repository with url : {}", url);
List<String> sets = null;
try {
sets = OaiTools.getSetsOfRepo(url);
} catch (Exception e) {
logger.error("Exception on getSetsOfRepository", e);
}
return sets; // It may be null.
return sets;
}
@Override
@ -236,16 +239,13 @@ public class ValidatorServiceImpl implements ValidatorService {
RuleSet ruleSet = null;
try {
for (List<RuleSet> ruleSets : this.rulesetMap.values()) {
for ( RuleSet rSet : ruleSets ) {
if ( rSet.getGuidelinesAcronym().equals(acronym) ) {
for (RuleSet rSet : ruleSets)
if (rSet.getGuidelinesAcronym().equals(acronym)) {
ruleSet = rSet;
break;
}
}
if ( ruleSet != null )
break;
}
return ruleSet; // It may be null.
return ruleSet;
} catch (Exception e) {
logger.error("Error getting ruleset", e);
return null;
@ -310,11 +310,10 @@ public class ValidatorServiceImpl implements ValidatorService {
@Override
public void onComplete(String repoId, String interfaceId, String jobId, String issuerEmail, boolean isUpdate, boolean isSuccess, int scoreUsage, int scoreContent) throws Exception {
emailUtils.sendUponJobCompletion(repoId,interfaceId,scoreUsage,scoreContent,isSuccess,isUpdate,issuerEmail, jobId);
InterfaceComplianceRequestId requestId = InterfaceComplianceRequestId.of(repoId, interfaceId);
Optional<InterfaceComplianceRequest> request = interfaceComplianceService.getById(requestId);
String compatibility = null;
if (request.isPresent()) {
compatibility = request.get().getDesiredCompatibilityLevel();
logger.info("Changing compatibility level. Request: {}", request);
if (scoreContent > 50) {
@ -322,7 +321,6 @@ public class ValidatorServiceImpl implements ValidatorService {
}
interfaceComplianceService.delete(requestId);
}
emailUtils.sendUponJobCompletion(repoId,interfaceId,compatibility,scoreUsage,scoreContent,isSuccess,isUpdate,issuerEmail, jobId);
}
}

View File

@ -11,36 +11,28 @@ import java.util.Map;
public interface AaiRegistryService {
/**
* 1.1 Get CoPersonId List by authenticated user's Email
* 1.1 Get CoPersonId by authenticated user's Email
*
* @return
*/
List<Integer> getCoPersonIdsByEmail();
Integer getCoPersonIdByEmail();
/**
* 1.2 Get CoPersonId List by Email
* 1.2 Get CoPersonId by Email
*
* @param email
* @return
*/
Integer getCoPersonIdByEmail(String email);
/**
* 1. Get CoPersonId List by Email
*
* @param email
* @return
*/
List<Integer> getCoPersonIdsByEmail(String email);
/**
* 1.3 Get a list of User Identifiers by Email
*
* @param email
* @return
*/
List<String> getUserIdentifiersByEmail(String email);
/**
* 1.3 Get a list of User Identifiers by Email
*
* @param coPersonId
* @return
*/
List<String> getUserIdentifiersByCoPersonId(Integer coPersonId);
/**
* 2. Get CoPersonId by AAI identifier
*
@ -105,14 +97,6 @@ public interface AaiRegistryService {
*/
JsonArray getRolesWithStatus(Integer coPersonId, RoleStatus status);
/**
* 5.3 Get User non admin active roles
*
* @param coPersonIds
* @return
*/
JsonArray getRolesWithStatus(List<Integer> coPersonIds, RoleStatus status);
/**
* 6. Get Role id of User base on couId.
*
@ -204,8 +188,9 @@ public interface AaiRegistryService {
*
* @param coPersonId
* @param couId
* @param id
*/
void assignMemberRole(Integer coPersonId, Integer couId);
void assignMemberRole(Integer coPersonId, Integer couId, Integer id);
/**
* 16. Remove a member role from a User

View File

@ -6,8 +6,8 @@ import com.google.gson.JsonObject;
import com.nimbusds.jose.util.StandardCharset;
import eu.dnetlib.repo.manager.domain.dto.Role;
import eu.dnetlib.repo.manager.domain.dto.User;
import eu.dnetlib.repo.manager.service.aai.registry.utils.HttpUtils;
import eu.dnetlib.repo.manager.service.aai.registry.utils.RegistryUtils;
import eu.dnetlib.repo.manager.utils.HttpUtils;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -16,24 +16,29 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import javax.validation.constraints.NotNull;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class RegistryCalls implements AaiRegistryService {
private static final Logger logger = LoggerFactory.getLogger(RegistryCalls.class);
private final String coid;
public final HttpUtils httpUtils;
public final RegistryUtils jsonUtils;
private final String coid;
@Autowired
RegistryCalls(HttpUtils httpUtils, RegistryUtils registryUtils, @Value("${services.provide.aai.registry.coid}") String coid) {
RegistryCalls(@Value("${services.provide.aai.registry.coid:2}") String coid,
HttpUtils httpUtils, RegistryUtils registryUtils) {
this.coid = coid;
this.httpUtils = httpUtils;
this.jsonUtils = registryUtils;
this.coid = coid;
}
private String mapType(String type, boolean communityMap) {
@ -46,51 +51,42 @@ public class RegistryCalls implements AaiRegistryService {
}
@Override
public List<String> getUserIdentifiersByEmail(String email) {
List<String> ids = new ArrayList<>();
for (Integer coPersonId : getCoPersonIdsByEmail(email)) {
ids.addAll(getUserIdentifiersByCoPersonId(coPersonId));
}
return ids;
}
@Override
public List<String> getUserIdentifiersByCoPersonId(Integer coPersonId) {
List<String> ids = new ArrayList<>();
Map<String, String> params = new HashMap<>();
params.put("copersonid", coPersonId.toString());
JsonElement response = httpUtils.get("identifiers.json", params);
if (response != null) {
JsonArray infos = response.getAsJsonObject().get("Identifiers").getAsJsonArray();
infos.forEach(info -> {
JsonObject jsonInfo = info.getAsJsonObject();
if (!jsonInfo.get("Deleted").getAsBoolean()) {
ids.add(jsonInfo.get("Identifier").getAsString());
}
});
}
return ids;
}
@Override
public List<Integer> getCoPersonIdsByEmail() {
public Integer getCoPersonIdByEmail() {
try {
OIDCAuthenticationToken authentication = (OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
String email = authentication.getUserInfo().getEmail();
return getCoPersonIdsByEmail(email);
Map<String, String> params = new HashMap<>();
params.put("coid", coid);
params.put("mail", email);
JsonElement response = httpUtils.get("co_people.json", params);
return (response != null) ? response.getAsJsonObject().get("CoPeople").getAsJsonArray().get(0).getAsJsonObject().get("Id").getAsInt() : null;
} catch (Exception e) {
logger.error("Get User info: An error occurred ", e);
return null;
}
}
@Override
public Integer getCoPersonIdByEmail(String email) {
Map<String, String> params = new HashMap<>();
params.put("coid", coid);
params.put("mail", email);
JsonElement response = httpUtils.get("co_people.json", params);
if (response != null) {
JsonArray coPeople = response.getAsJsonObject().get("CoPeople").getAsJsonArray();
if (coPeople.size() > 0) {
return coPeople.get(0).getAsJsonObject().get("Id").getAsInt();
}
}
return null;
}
@Override
public List<Integer> getCoPersonIdsByEmail(String email) {
List<Integer> coPersonIds = new ArrayList<>();
Map<String, String> params = new HashMap<>();
params.put("mail", email);
params.put("coid", coid);
params.put("mail", email);
JsonElement response = httpUtils.get("co_people.json", params);
if (response != null) {
JsonArray coPeople = response.getAsJsonObject().get("CoPeople").getAsJsonArray();
@ -115,8 +111,8 @@ public class RegistryCalls implements AaiRegistryService {
public Integer getCoPersonIdByIdentifier(String sub) {
Map<String, String> params = new HashMap<>();
params.put("search.identifier", sub);
params.put("coid", coid);
params.put("search.identifier", sub);
JsonElement response = httpUtils.get("co_people.json", params);
return (response != null) ? response.getAsJsonObject().get("CoPeople").getAsJsonArray().get(0).getAsJsonObject().get("Id").getAsInt() : null;
}
@ -124,6 +120,7 @@ public class RegistryCalls implements AaiRegistryService {
@Override
public JsonArray getCous(String name) {
Map<String, String> params = new HashMap<>();
params.put("coid", coid);
if (name != null) {
try {
params.put("name", URLEncoder.encode(name, StandardCharset.UTF_8.name()).toLowerCase());
@ -172,13 +169,10 @@ public class RegistryCalls implements AaiRegistryService {
@Override
public JsonArray getRolesWithStatus(Integer coPersonId, RoleStatus status) {
return getRolesWithStatus(Collections.singletonList(coPersonId), status);
}
@Override
public JsonArray getRolesWithStatus(List<Integer> coPersonIds, RoleStatus status) {
JsonArray roles = new JsonArray();
coPersonIds.parallelStream().forEach(coPersonId -> roles.addAll(getRoles(coPersonId)));
JsonArray roles = getRoles(coPersonId);
if (roles == null) {
roles = new JsonArray();
}
JsonArray activeRoles = new JsonArray();
if (status != null) {
for (JsonElement role : roles) {
@ -187,6 +181,7 @@ public class RegistryCalls implements AaiRegistryService {
}
}
}
assert activeRoles != null;
return activeRoles;
}
@ -230,6 +225,7 @@ public class RegistryCalls implements AaiRegistryService {
@Override
public JsonArray getCouGroups(Integer couId) {
Map<String, String> params = new HashMap<>();
params.put("coid", coid);
params.put("couid", couId.toString());
JsonElement response = httpUtils.get("co_groups.json", params);
return (response != null) ? response.getAsJsonObject().get("CoGroups").getAsJsonArray() : new JsonArray();
@ -360,15 +356,18 @@ public class RegistryCalls implements AaiRegistryService {
}
@Override
public void assignMemberRole(Integer coPersonId, Integer couId) {
httpUtils.post("co_person_roles.json", jsonUtils.coPersonRoles(coPersonId, couId, "Active"));
public void assignMemberRole(Integer coPersonId, Integer couId, Integer id) {
if (id != null) {
httpUtils.put("co_person_roles/" + id.toString() + ".json", jsonUtils.coPersonRoles(coPersonId, couId, "Active"));
} else {
httpUtils.post("co_person_roles.json", jsonUtils.coPersonRoles(coPersonId, couId, "Active"));
}
}
@Override
public void removeMemberRole(Integer coPersonId, Integer couId, Integer id) {
if (id != null) {
httpUtils.put("co_person_roles/" + id + ".json", jsonUtils.coPersonRoles(coPersonId, couId, "Deleted"));
httpUtils.put("co_person_roles/" + id.toString() + ".json", jsonUtils.coPersonRoles(coPersonId, couId, "Deleted"));
}
}
@ -393,7 +392,7 @@ public class RegistryCalls implements AaiRegistryService {
params.put("copersonid", coPersonId.toString());
JsonElement response = httpUtils.get("names.json", params);
JsonObject info = (response != null) ? response.getAsJsonObject().get("Names").getAsJsonArray().get(0).getAsJsonObject() : null;
if (info != null) {
if ( info != null ) {
JsonObject jsonInfo = info.getAsJsonObject();
return jsonInfo.get("Given").getAsString() + " " + jsonInfo.get("Family").getAsString();
} else
@ -428,7 +427,7 @@ public class RegistryCalls implements AaiRegistryService {
}
}
if (id != null) {
httpUtils.delete("co_group_members/" + id + ".json");
httpUtils.delete("co_group_members/" + id.toString() + ".json");
}
}

View File

@ -6,8 +6,6 @@ import eu.dnetlib.repo.manager.domain.dto.Role;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.Date;
@Component
public class RegistryUtils {
@ -31,11 +29,8 @@ public class RegistryUtils {
coPersonRole.addProperty("Title", "");
coPersonRole.addProperty("O", "Openaire");
coPersonRole.addProperty("Status", status);
if(status.equals("Active")) {
coPersonRole.addProperty("ValidFrom", new Date().toString());
} else {
coPersonRole.addProperty("ValidThrough", new Date().toString());
}
coPersonRole.addProperty("ValidFrom", "");
coPersonRole.addProperty("ValidThrough", "");
coPersonRoles.add(coPersonRole);
role.addProperty("RequestType", "CoPersonRoles");
role.addProperty("Version", version);

View File

@ -43,7 +43,7 @@ public interface AuthorizationService {
* @return
* @throws ResourceNotFoundException
*/
void addAdmin(String resourceId, String email) throws ResourceNotFoundException;
boolean addAdmin(String resourceId, String email) throws ResourceNotFoundException;
/**
* Remove user from resource admins.
@ -53,20 +53,12 @@ public interface AuthorizationService {
* @return
* @throws ResourceNotFoundException
*/
void removeAdmin(String resourceId, String email) throws ResourceNotFoundException;
/**
* Creates a role based on the resourceId and assigns it to the current user.
*
* @param resourceId usually the repository Id.
* @param roleDescription usually the repository official name.
*/
void createAndAssignRoleToAuthenticatedUser(String resourceId, String roleDescription);
boolean removeAdmin(String resourceId, String email) throws ResourceNotFoundException;
/**
* Returns the roles of the authenticated user.
*
*
* @return
*/
Collection<String> getUserRoles();

View File

@ -1,7 +1,6 @@
package eu.dnetlib.repo.manager.service.security;
import com.google.gson.JsonElement;
import eu.dnetlib.repo.manager.domain.dto.Role;
import eu.dnetlib.repo.manager.domain.dto.User;
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
import eu.dnetlib.repo.manager.service.aai.registry.AaiRegistryService;
@ -12,7 +11,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpClientErrorException;
import java.util.ArrayList;
import java.util.Collection;
@ -81,74 +79,49 @@ public class AuthorizationServiceImpl implements AuthorizationService {
@Override
public void addAdmin(String resourceId, String email) throws ResourceNotFoundException {
String role = roleMappingService.getRoleIdByRepoId(resourceId);
Integer couId = aaiRegistryService.getCouId(role);
if (couId == null) {
throw new ResourceNotFoundException("Cannot find CouId for role: " + role);
}
List<Integer> coPersonIds = aaiRegistryService.getCoPersonIdsByEmail(email);
for (Integer coPersonId : coPersonIds) {
assert coPersonId != null;
aaiRegistryService.assignMemberRole(coPersonId, couId);
public boolean addAdmin(String resourceId, String email) throws ResourceNotFoundException {
Integer coPersonId = aaiRegistryService.getCoPersonIdByEmail(email);
if (coPersonId != null) {
String role = roleMappingService.getRoleIdByRepoId(resourceId);
Integer couId = aaiRegistryService.getCouId(role);
if (couId != null) {
Integer roleId = aaiRegistryService.getRoleId(coPersonId, couId);
aaiRegistryService.assignMemberRole(coPersonId, couId, roleId);
// Add role to user current authorities
for (String userId : aaiRegistryService.getUserIdentifiersByEmail(email)) {
authoritiesUpdater.addRole(userId, roleMappingService.convertRepoIdToAuthority(resourceId));
// Add role to user current authorities
authoritiesUpdater.addRole(email, roleMappingService.convertRepoIdToAuthority(resourceId));
return true;
} else {
throw new ResourceNotFoundException("Cannot find CouId for role: " + role);
}
} else {
throw new ResourceNotFoundException("Cannot find coPersonId for user with email: " + email);
}
}
@Override
public void removeAdmin(String resourceId, String email) throws ResourceNotFoundException {
String role = roleMappingService.getRoleIdByRepoId(resourceId);
Integer couId = aaiRegistryService.getCouId(role);
if (couId == null) {
throw new ResourceNotFoundException("Cannot find CouId for role: " + role);
}
List<Integer> coPersonIds = aaiRegistryService.getCoPersonIdsByEmail(email);
for (Integer coPersonId : coPersonIds) {
assert coPersonId != null;
Integer roleId = aaiRegistryService.getRoleId(coPersonId, couId);
if (roleId != null) {
public boolean removeAdmin(String resourceId, String email) throws ResourceNotFoundException {
Integer coPersonId = aaiRegistryService.getCoPersonIdByEmail(email);
if (coPersonId != null) {
String role = roleMappingService.getRoleIdByRepoId(resourceId);
Integer couId = aaiRegistryService.getCouId(role);
Integer roleId = null;
if (couId != null) {
roleId = aaiRegistryService.getRoleId(coPersonId, couId);
}
if (couId != null && roleId != null) {
aaiRegistryService.removeMemberRole(coPersonId, couId, roleId);
// Remove role from user current authorities
for (String userId : aaiRegistryService.getUserIdentifiersByEmail(email)) {
authoritiesUpdater.removeRole(userId, roleMappingService.convertRepoIdToAuthority(resourceId));
}
authoritiesUpdater.removeRole(email, roleMappingService.convertRepoIdToAuthority(resourceId));
return true;
} else {
logger.error("Cannot find RoleId for role: {}", role);
throw new ResourceNotFoundException("Cannot find CouId for role: " + role);
}
}
}
@Override
public void createAndAssignRoleToAuthenticatedUser(String resourceId, String roleDescription) {
// Create new role
String newRoleName = roleMappingService.getRoleIdByRepoId(resourceId);
Role newRole = new Role(newRoleName, roleDescription);
Integer couId;
try {
couId = aaiRegistryService.createRole(newRole);
} catch (HttpClientErrorException e) {
couId = aaiRegistryService.getCouId(newRoleName);
if (couId == null) {
logger.error(String.format("Could not create role '%s'", newRoleName), e);
}
} catch (Exception e) {
logger.error(String.format("Could not create role '%s'", newRoleName), e);
throw e;
}
// Assign new role to the current authenticated user
Integer coPersonId = aaiRegistryService.getCoPersonIdByIdentifier();
if (couId != null) {
aaiRegistryService.assignMemberRole(coPersonId, couId);
// Add role to current user authorities
authoritiesUpdater.addRole(roleMappingService.convertRepoIdToAuthority(resourceId));
} else {
throw new ResourceNotFoundException("Cannot find coPersonId for user with email: " + email);
}
}
@ -158,17 +131,17 @@ public class AuthorizationServiceImpl implements AuthorizationService {
UserInfo userInfo = ((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo();
roles = getUserRolesByEmail(userInfo.getEmail());
if (logger.isTraceEnabled()) {
logger.trace("User Roles: {}", String.join(",", roles));
if (logger.isDebugEnabled()) {
logger.debug("User Roles: {}", String.join(",", roles));
}
return roles;
}
@Override
public Collection<String> getUserRolesByEmail(String email) {
List<Integer> coPersonIds = aaiRegistryService.getCoPersonIdsByEmail(email);
int coPersonId = aaiRegistryService.getCoPersonIdByEmail(email);
List<Integer> list = new ArrayList<>();
for (JsonElement element : aaiRegistryService.getRolesWithStatus(coPersonIds, AaiRegistryService.RoleStatus.ACTIVE)) {
for (JsonElement element : aaiRegistryService.getRolesWithStatus(coPersonId, AaiRegistryService.RoleStatus.ACTIVE)) {
if (element.getAsJsonObject().get("CouId") != null) {
list.add(element.getAsJsonObject().get("CouId").getAsInt());
}

View File

@ -6,6 +6,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
@ -21,11 +22,13 @@ public class Converter {
public static List<String> readFile(String filename) {
String line;
List<String> list = new ArrayList<>();
try ( BufferedReader br = new BufferedReader(new InputStreamReader(Objects.requireNonNull(Converter.class.getResourceAsStream("/eu/**/" + filename)))) )
{
try {
InputStream in = Converter.class.getResourceAsStream("/eu/**/" + filename);
BufferedReader br = new BufferedReader(new InputStreamReader(in)); // It may throw an NPE.
while ((line = br.readLine()) != null) {
list.add(line.trim());
}
br.close();
} catch (Exception e) {
logger.error("Error opening file!", e);
}

View File

@ -0,0 +1,5 @@
package eu.dnetlib.repo.manager.utils;
public class DatasourceManagerClient {
//
}

View File

@ -1,4 +1,4 @@
package eu.dnetlib.repo.manager.service.aai.registry.utils;
package eu.dnetlib.repo.manager.utils;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
@ -9,13 +9,9 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.*;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.Map;
@Component
@ -52,7 +48,7 @@ public class HttpUtils {
public JsonElement get(String path, Map<String, String> params) {
RestTemplate restTemplate = new RestTemplate();
String url = createUrl(registryUrl + path, params);
String url = registryUrl + path + ((params != null) ? createParams(params) : null);
ResponseEntity<String> responseEntity = restTemplate.exchange
(url, HttpMethod.GET, new HttpEntity<>(createHeaders(user, password)), String.class);
return getResponseEntityAsJsonElement(responseEntity);
@ -61,18 +57,23 @@ public class HttpUtils {
public JsonElement delete(String path) {
RestTemplate restTemplate = new RestTemplate();
String url = registryUrl + path;
ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.DELETE, new HttpEntity<>(createHeaders(user, password)), String.class);
ResponseEntity<String> responseEntity = restTemplate.exchange
(url, HttpMethod.DELETE, new HttpEntity<>(createHeaders(user, password)), String.class);
return getResponseEntityAsJsonElement(responseEntity);
}
private String createUrl(String baseAddress, Map<String, String> params) {
LinkedMultiValueMap<String, String> multiValueMap = new LinkedMultiValueMap<>();
params.forEach((k, v) -> multiValueMap.put(k, Collections.singletonList(v)));
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress)
.queryParams(multiValueMap)
.build().encode();
return uriComponents.toString();
private String createParams(Map<String, String> params) {
StringBuilder ret = new StringBuilder("?");
int count = 0;
for (Map.Entry<String, String> param : params.entrySet()) {
ret.append(param.getKey()).append("=").append(param.getValue());
count++;
if (count != params.entrySet().size()) {
ret.append("&");
}
}
return ret.toString();
}
private HttpHeaders createHeaders(String username, String password) {
@ -86,13 +87,12 @@ public class HttpUtils {
private JsonElement getResponseEntityAsJsonElement(ResponseEntity<String> responseEntity) {
if (responseEntity == null)
if ( responseEntity == null )
return null;
String responseBody = responseEntity.getBody();
if (responseBody != null) {
logger.trace(responseBody);
if ( responseBody != null ) {
logger.debug(responseBody);
try {
return new JsonParser().parse(responseBody);
} catch (Exception e) {

View File

@ -25,7 +25,7 @@ public class OaiTools {
disableSslVerification();
}
private static final Logger logger = LoggerFactory.getLogger(OaiTools.class);
private static Logger logger = LoggerFactory.getLogger(OaiTools.class);
public static List<String> getSetsOfRepo(String baseUrl) throws Exception {
try {
@ -36,8 +36,8 @@ public class OaiTools {
List<Set> sets = new ArrayList<>(setList.asList());
while (token != null) {
setList = harvester.listSets(token);
sets.addAll(setList.asList());
token = setList.getResumptionToken();
sets.addAll(setList.asList());
}
List<String> ret = new ArrayList<String>();

View File

@ -15,11 +15,11 @@ spring:
services:
provide:
dev-machine: 88.197.53.71 # VM-71
dev-machine: 88.197.53.71
aai:
baseURL: https://aai.openaire.eu
oidc:
domain: .openaire.eu # use empty value for local, otherwise: ".openaire.eu"
domain: .openaire.eu
id: XX
issuer: ${services.provide.aai.baseURL}/oidc/
redirectURL: http://localhost:${server.port}${server.servlet.context-path}/openid_connect_login
@ -37,13 +37,13 @@ services:
broker:
api: api/
openaire: openaireBroker
port: 443
url: https://beta.broker.openaire.eu
port: 8080
url: https://broker1-dev-dnet.d4science.org
clients:
dsm: https://dev-openaire.d4science.org/openaire
search: https://beta.services.openaire.eu/search/v2/api
usageEvents: http://beta.lbs.openaire.eu:8080/ajax/summary
usagestats: https://beta.services.openaire.eu/usagestats
usagestats: https://services.openaire.eu/usagestats
db:
driverClassName: org.postgresql.Driver
password: dnetPwd

View File

@ -9,13 +9,7 @@
<Root level="info">
<AppenderRef ref="LogToConsole"/>
</Root>
<Logger name="eu.dnetlib.repo.manager" level="info" additivity="false"> <!-- Make this "debug", to see debug-logs during development. -->
<AppenderRef ref="LogToConsole"/>
</Logger>
<Logger name="org.springframework.boot" level="warn" additivity="false">
<AppenderRef ref="LogToConsole"/>
</Logger>
<Logger name="springfox.documentation" level="warn" additivity="false">
<Logger name="org.springframework.boot" level="error" additivity="false">
<AppenderRef ref="LogToConsole"/>
</Logger>
</Loggers>

View File

@ -11,7 +11,6 @@ import org.mockito.MockitoAnnotations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
@ -52,7 +51,7 @@ public class PrometheusTest {
@Test
public void testPiwikMetrics() {
assertEquals((long) piWikService.getValidated(false), (TOTAL - VALIDATED));
assertTrue(piWikService.getValidated(false).equals(TOTAL - VALIDATED));
String report = prometheusController.getPiwikMetrics();
assertTrue(report.contains("provide_repositories_registered_total " + TOTAL));
assertTrue(report.contains("provide_usagecounts_repositories_registered_total " + TOTAL));

View File

@ -40,17 +40,17 @@ class InterfaceComplianceRequestTests {
}
private InterfaceComplianceRequestId createRequestId() {
InterfaceComplianceRequestId requestId = new InterfaceComplianceRequestId();
requestId.setRepositoryId("repository");
requestId.setInterfaceId("interface");
return requestId;
InterfaceComplianceRequestId id = new InterfaceComplianceRequestId();
id.setRepositoryId("repository");
id.setInterfaceId("interface");
return id;
}
private InterfaceComplianceRequest createRequest(String compatibilityLevel) {
InterfaceComplianceRequest request = new InterfaceComplianceRequest();
InterfaceComplianceRequestId requestId = createRequestId();
request.setRepositoryId(requestId.getRepositoryId());
request.setInterfaceId(requestId.getInterfaceId());
InterfaceComplianceRequestId id = createRequestId();
request.setRepositoryId(id.getRepositoryId());
request.setInterfaceId(id.getInterfaceId());
request.setDesiredCompatibilityLevel(compatibilityLevel);
request.setSubmissionDate(new Date());
return request;