From 60ff3dce6e6c67d439a59ddf2fc7c4eb6e940b35 Mon Sep 17 00:00:00 2001 From: Konstantinos Spyrou Date: Tue, 17 Jan 2023 18:20:41 +0200 Subject: [PATCH 01/29] changes for new aai registry --- .../controllers/UserRoleController.java | 3 +- .../service/RepositoryServiceImpl.java | 29 +------------- .../aai/registry/AaiRegistryService.java | 3 +- .../service/aai/registry/RegistryCalls.java | 25 +++--------- .../aai/registry/utils/RegistryUtils.java | 9 ++++- .../security/AuthorizationService.java | 10 ++++- .../security/AuthorizationServiceImpl.java | 34 ++++++++++++++++- .../dnetlib/repo/manager/utils/HttpUtils.java | 38 +++++++++++++------ 8 files changed, 83 insertions(+), 68 deletions(-) diff --git a/src/main/java/eu/dnetlib/repo/manager/controllers/UserRoleController.java b/src/main/java/eu/dnetlib/repo/manager/controllers/UserRoleController.java index 255bac7..bc4dcf2 100644 --- a/src/main/java/eu/dnetlib/repo/manager/controllers/UserRoleController.java +++ b/src/main/java/eu/dnetlib/repo/manager/controllers/UserRoleController.java @@ -71,8 +71,7 @@ public class UserRoleController { } Integer couId = aaiRegistryService.getCouId(type, id); if (couId != null) { - Integer role = aaiRegistryService.getRoleId(coPersonId, couId); - aaiRegistryService.assignMemberRole(coPersonId, couId, role); + aaiRegistryService.assignMemberRole(coPersonId, couId); // Add role to current authorities authoritiesUpdater.addRole(roleMappingService.convertRepoIdToAuthority(id)); diff --git a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java index 06e67f3..b89746a 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java @@ -8,7 +8,6 @@ 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.BrokerException; import eu.dnetlib.repo.manager.exception.RepositoryServiceException; @@ -36,7 +35,6 @@ 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; @@ -499,32 +497,7 @@ public class RepositoryServiceImpl implements RepositoryService { this.latentUpdate(repository, SecurityContextHolder.getContext().getAuthentication()); } - // 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())); - } + authorizationService.createAndAssignRoleToAuthenticatedUser(repository.getId(), repository.getOfficialname()); return repository; } diff --git a/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/AaiRegistryService.java b/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/AaiRegistryService.java index 6fe4888..e54aebb 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/AaiRegistryService.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/AaiRegistryService.java @@ -188,9 +188,8 @@ public interface AaiRegistryService { * * @param coPersonId * @param couId - * @param id */ - void assignMemberRole(Integer coPersonId, Integer couId, Integer id); + void assignMemberRole(Integer coPersonId, Integer couId); /** * 16. Remove a member role from a User diff --git a/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/RegistryCalls.java b/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/RegistryCalls.java index 050b20a..8d93ac9 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/RegistryCalls.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/RegistryCalls.java @@ -11,7 +11,6 @@ import org.mitre.openid.connect.model.OIDCAuthenticationToken; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; @@ -26,14 +25,11 @@ 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; @Autowired - RegistryCalls(@Value("${services.provide.aai.registry.coid:2}") String coid, - HttpUtils httpUtils, RegistryUtils registryUtils) { - this.coid = coid; + RegistryCalls(HttpUtils httpUtils, RegistryUtils registryUtils) { this.httpUtils = httpUtils; this.jsonUtils = registryUtils; } @@ -53,7 +49,6 @@ public class RegistryCalls implements AaiRegistryService { OIDCAuthenticationToken authentication = (OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); String email = authentication.getUserInfo().getEmail(); Map 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; @@ -66,7 +61,6 @@ public class RegistryCalls implements AaiRegistryService { @Override public Integer getCoPersonIdByEmail(String email) { Map params = new HashMap<>(); - params.put("coid", coid); params.put("mail", email); JsonElement response = httpUtils.get("co_people.json", params); if (response != null) { @@ -82,7 +76,6 @@ public class RegistryCalls implements AaiRegistryService { public List getCoPersonIdsByEmail(String email) { List coPersonIds = new ArrayList<>(); Map params = new HashMap<>(); - params.put("coid", coid); params.put("mail", email); JsonElement response = httpUtils.get("co_people.json", params); if (response != null) { @@ -108,7 +101,6 @@ public class RegistryCalls implements AaiRegistryService { public Integer getCoPersonIdByIdentifier(String sub) { Map params = new HashMap<>(); - 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; @@ -117,7 +109,6 @@ public class RegistryCalls implements AaiRegistryService { @Override public JsonArray getCous(String name) { Map params = new HashMap<>(); - params.put("coid", coid); if (name != null) { params.put("name", URLEncoder.encode(name).toLowerCase()); } @@ -214,7 +205,6 @@ public class RegistryCalls implements AaiRegistryService { @Override public JsonArray getCouGroups(Integer couId) { Map 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(); @@ -345,18 +335,15 @@ public class RegistryCalls implements AaiRegistryService { } @Override - 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")); - } + public void assignMemberRole(Integer coPersonId, Integer couId) { + 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.toString() + ".json", jsonUtils.coPersonRoles(coPersonId, couId, "Deleted")); + httpUtils.put("co_person_roles/" + id + ".json", jsonUtils.coPersonRoles(coPersonId, couId, "Deleted")); } } @@ -416,7 +403,7 @@ public class RegistryCalls implements AaiRegistryService { } } if (id != null) { - httpUtils.delete("co_group_members/" + id.toString() + ".json"); + httpUtils.delete("co_group_members/" + id + ".json"); } } diff --git a/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/utils/RegistryUtils.java b/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/utils/RegistryUtils.java index 7fe74f1..24576b0 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/utils/RegistryUtils.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/utils/RegistryUtils.java @@ -6,6 +6,8 @@ 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 { @@ -29,8 +31,11 @@ public class RegistryUtils { coPersonRole.addProperty("Title", ""); coPersonRole.addProperty("O", "Openaire"); coPersonRole.addProperty("Status", status); - coPersonRole.addProperty("ValidFrom", ""); - coPersonRole.addProperty("ValidThrough", ""); + if(status.equals("Active")) { + coPersonRole.addProperty("ValidFrom", new Date().toString()); + } else { + coPersonRole.addProperty("ValidThrough", new Date().toString()); + } coPersonRoles.add(coPersonRole); role.addProperty("RequestType", "CoPersonRoles"); role.addProperty("Version", version); diff --git a/src/main/java/eu/dnetlib/repo/manager/service/security/AuthorizationService.java b/src/main/java/eu/dnetlib/repo/manager/service/security/AuthorizationService.java index 3696321..88abcd7 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/security/AuthorizationService.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/security/AuthorizationService.java @@ -55,10 +55,18 @@ public interface AuthorizationService { */ boolean 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); + /** * Returns the roles of the authenticated user. - * + * * @return */ Collection getUserRoles(); diff --git a/src/main/java/eu/dnetlib/repo/manager/service/security/AuthorizationServiceImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/security/AuthorizationServiceImpl.java index cd6812e..ad4dcfc 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/security/AuthorizationServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/security/AuthorizationServiceImpl.java @@ -1,6 +1,7 @@ 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; @@ -11,6 +12,7 @@ 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; @@ -85,8 +87,7 @@ public class AuthorizationServiceImpl implements AuthorizationService { String role = roleMappingService.getRoleIdByRepoId(resourceId); Integer couId = aaiRegistryService.getCouId(role); if (couId != null) { - Integer roleId = aaiRegistryService.getRoleId(coPersonId, couId); - aaiRegistryService.assignMemberRole(coPersonId, couId, roleId); + aaiRegistryService.assignMemberRole(coPersonId, couId); // Add role to user current authorities authoritiesUpdater.addRole(email, roleMappingService.convertRepoIdToAuthority(resourceId)); @@ -125,6 +126,35 @@ public class AuthorizationServiceImpl implements AuthorizationService { } } + @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)); + } + } + @Override public Collection getUserRoles() { Collection roles; diff --git a/src/main/java/eu/dnetlib/repo/manager/utils/HttpUtils.java b/src/main/java/eu/dnetlib/repo/manager/utils/HttpUtils.java index 957da55..65bed60 100644 --- a/src/main/java/eu/dnetlib/repo/manager/utils/HttpUtils.java +++ b/src/main/java/eu/dnetlib/repo/manager/utils/HttpUtils.java @@ -9,9 +9,14 @@ 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.HashMap; import java.util.Map; @Component @@ -28,6 +33,9 @@ public class HttpUtils { @Value("${services.provide.aai.registry.password}") private String password; + @Value("2") + private String coid; + public JsonElement post(String path, JsonObject body) { RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = createHeaders(user, password); @@ -48,7 +56,7 @@ public class HttpUtils { public JsonElement get(String path, Map params) { RestTemplate restTemplate = new RestTemplate(); - String url = registryUrl + path + ((params != null) ? createParams(params) : null); + String url = createUrl(registryUrl + path, params); ResponseEntity responseEntity = restTemplate.exchange (url, HttpMethod.GET, new HttpEntity<>(createHeaders(user, password)), String.class); return getResponseEntityAsJsonElement(responseEntity); @@ -62,18 +70,24 @@ public class HttpUtils { return getResponseEntityAsJsonElement(responseEntity); } - - private String createParams(Map params) { - StringBuilder ret = new StringBuilder("?"); - int count = 0; - for (Map.Entry param : params.entrySet()) { - ret.append(param.getKey()).append("=").append(param.getValue()); - count++; - if (count != params.entrySet().size()) { - ret.append("&"); - } + private Map addCoId(Map params) { + if(params == null) { + params = new HashMap<>(); } - return ret.toString(); + params.put("coid", coid); + return params; + } + + + private String createUrl(String baseAddress, Map params) { + params = addCoId(params); + LinkedMultiValueMap 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 HttpHeaders createHeaders(String username, String password) { From 139fb420d4bd544aa42f9d4d9526c9d7cced3e89 Mon Sep 17 00:00:00 2001 From: Konstantinos Spyrou Date: Tue, 17 Jan 2023 18:21:20 +0200 Subject: [PATCH 02/29] removed empty class --- .../dnetlib/repo/manager/utils/DatasourceManagerClient.java | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 src/main/java/eu/dnetlib/repo/manager/utils/DatasourceManagerClient.java diff --git a/src/main/java/eu/dnetlib/repo/manager/utils/DatasourceManagerClient.java b/src/main/java/eu/dnetlib/repo/manager/utils/DatasourceManagerClient.java deleted file mode 100644 index 118dd05..0000000 --- a/src/main/java/eu/dnetlib/repo/manager/utils/DatasourceManagerClient.java +++ /dev/null @@ -1,5 +0,0 @@ -package eu.dnetlib.repo.manager.utils; - -public class DatasourceManagerClient { - // -} From e4d52c23230acc00dd8e098346d6e4a89a5fdd96 Mon Sep 17 00:00:00 2001 From: Konstantinos Spyrou Date: Tue, 17 Jan 2023 18:23:59 +0200 Subject: [PATCH 03/29] refactoring project structure --- .../repo/manager/service/aai/registry/RegistryCalls.java | 2 +- .../manager/{ => service/aai/registry}/utils/HttpUtils.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/main/java/eu/dnetlib/repo/manager/{ => service/aai/registry}/utils/HttpUtils.java (98%) diff --git a/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/RegistryCalls.java b/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/RegistryCalls.java index 8d93ac9..ceeb05b 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/RegistryCalls.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/RegistryCalls.java @@ -6,7 +6,7 @@ import com.google.gson.JsonObject; 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.RegistryUtils; -import eu.dnetlib.repo.manager.utils.HttpUtils; +import eu.dnetlib.repo.manager.service.aai.registry.utils.HttpUtils; import org.mitre.openid.connect.model.OIDCAuthenticationToken; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/eu/dnetlib/repo/manager/utils/HttpUtils.java b/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/utils/HttpUtils.java similarity index 98% rename from src/main/java/eu/dnetlib/repo/manager/utils/HttpUtils.java rename to src/main/java/eu/dnetlib/repo/manager/service/aai/registry/utils/HttpUtils.java index 65bed60..44ff24c 100644 --- a/src/main/java/eu/dnetlib/repo/manager/utils/HttpUtils.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/utils/HttpUtils.java @@ -1,4 +1,4 @@ -package eu.dnetlib.repo.manager.utils; +package eu.dnetlib.repo.manager.service.aai.registry.utils; import com.google.gson.JsonElement; import com.google.gson.JsonObject; From 7c5020c2059942c85cc99213aded495a0a021706 Mon Sep 17 00:00:00 2001 From: Konstantinos Spyrou Date: Wed, 18 Jan 2023 16:54:18 +0200 Subject: [PATCH 04/29] update user roles using identifier instead of email --- .../aai/registry/AaiRegistryService.java | 10 +++++- .../service/aai/registry/RegistryCalls.java | 31 +++++++++++++++++-- .../service/aai/registry/utils/HttpUtils.java | 18 ++--------- .../security/AuthorizationServiceImpl.java | 8 +++-- 4 files changed, 45 insertions(+), 22 deletions(-) diff --git a/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/AaiRegistryService.java b/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/AaiRegistryService.java index e54aebb..ac6a69b 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/AaiRegistryService.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/AaiRegistryService.java @@ -26,7 +26,15 @@ public interface AaiRegistryService { Integer getCoPersonIdByEmail(String email); /** - * 1. Get CoPersonId List by Email + * 1.3 Get a list of User Identifiers by Email + * + * @param email + * @return + */ + List getUserIdentifiersByEmail(String email); + + /** + * 1.4 Get CoPersonId List by Email * * @param email * @return diff --git a/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/RegistryCalls.java b/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/RegistryCalls.java index ceeb05b..ce46c5b 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/RegistryCalls.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/RegistryCalls.java @@ -5,12 +5,13 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; 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.RegistryUtils; import eu.dnetlib.repo.manager.service.aai.registry.utils.HttpUtils; +import eu.dnetlib.repo.manager.service.aai.registry.utils.RegistryUtils; import org.mitre.openid.connect.model.OIDCAuthenticationToken; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; @@ -27,11 +28,13 @@ public class RegistryCalls implements AaiRegistryService { public final HttpUtils httpUtils; public final RegistryUtils jsonUtils; + private final String coid; @Autowired - RegistryCalls(HttpUtils httpUtils, RegistryUtils registryUtils) { + RegistryCalls(HttpUtils httpUtils, RegistryUtils registryUtils, @Value("${services.provide.aai.registry.coid}") String coid) { this.httpUtils = httpUtils; this.jsonUtils = registryUtils; + this.coid = coid; } private String mapType(String type, boolean communityMap) { @@ -62,6 +65,7 @@ public class RegistryCalls implements AaiRegistryService { public Integer getCoPersonIdByEmail(String email) { Map params = new HashMap<>(); params.put("mail", email); + params.put("coid", coid); JsonElement response = httpUtils.get("co_people.json", params); if (response != null) { JsonArray coPeople = response.getAsJsonObject().get("CoPeople").getAsJsonArray(); @@ -72,11 +76,31 @@ public class RegistryCalls implements AaiRegistryService { return null; } + @Override + public List getUserIdentifiersByEmail(String email) { + List ids = new ArrayList<>(); + Map params = new HashMap<>(); + params.put("copersonid", getCoPersonIdByEmail(email).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 getCoPersonIdsByEmail(String email) { List coPersonIds = new ArrayList<>(); Map params = new HashMap<>(); params.put("mail", email); + params.put("coid", coid); JsonElement response = httpUtils.get("co_people.json", params); if (response != null) { JsonArray coPeople = response.getAsJsonObject().get("CoPeople").getAsJsonArray(); @@ -102,6 +126,7 @@ public class RegistryCalls implements AaiRegistryService { public Integer getCoPersonIdByIdentifier(String sub) { Map params = new HashMap<>(); params.put("search.identifier", sub); + params.put("coid", coid); JsonElement response = httpUtils.get("co_people.json", params); return (response != null) ? response.getAsJsonObject().get("CoPeople").getAsJsonArray().get(0).getAsJsonObject().get("Id").getAsInt() : null; } @@ -368,7 +393,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 diff --git a/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/utils/HttpUtils.java b/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/utils/HttpUtils.java index 44ff24c..c88c5b4 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/utils/HttpUtils.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/utils/HttpUtils.java @@ -16,7 +16,6 @@ import org.springframework.web.util.UriComponentsBuilder; import java.nio.charset.StandardCharsets; import java.util.Collections; -import java.util.HashMap; import java.util.Map; @Component @@ -33,9 +32,6 @@ public class HttpUtils { @Value("${services.provide.aai.registry.password}") private String password; - @Value("2") - private String coid; - public JsonElement post(String path, JsonObject body) { RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = createHeaders(user, password); @@ -70,17 +66,7 @@ public class HttpUtils { return getResponseEntityAsJsonElement(responseEntity); } - private Map addCoId(Map params) { - if(params == null) { - params = new HashMap<>(); - } - params.put("coid", coid); - return params; - } - - private String createUrl(String baseAddress, Map params) { - params = addCoId(params); LinkedMultiValueMap multiValueMap = new LinkedMultiValueMap<>(); params.forEach((k, v) -> multiValueMap.put(k, Collections.singletonList(v))); UriComponents uriComponents = UriComponentsBuilder @@ -101,11 +87,11 @@ public class HttpUtils { private JsonElement getResponseEntityAsJsonElement(ResponseEntity responseEntity) { - if ( responseEntity == null ) + if (responseEntity == null) return null; String responseBody = responseEntity.getBody(); - if ( responseBody != null ) { + if (responseBody != null) { logger.debug(responseBody); try { return new JsonParser().parse(responseBody); diff --git a/src/main/java/eu/dnetlib/repo/manager/service/security/AuthorizationServiceImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/security/AuthorizationServiceImpl.java index ad4dcfc..56a71c2 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/security/AuthorizationServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/security/AuthorizationServiceImpl.java @@ -90,7 +90,9 @@ public class AuthorizationServiceImpl implements AuthorizationService { aaiRegistryService.assignMemberRole(coPersonId, couId); // Add role to user current authorities - authoritiesUpdater.addRole(email, roleMappingService.convertRepoIdToAuthority(resourceId)); + for (String userId : aaiRegistryService.getUserIdentifiersByEmail(email)) { + authoritiesUpdater.addRole(userId, roleMappingService.convertRepoIdToAuthority(resourceId)); + } return true; } else { @@ -115,7 +117,9 @@ public class AuthorizationServiceImpl implements AuthorizationService { aaiRegistryService.removeMemberRole(coPersonId, couId, roleId); // Remove role from user current authorities - authoritiesUpdater.removeRole(email, roleMappingService.convertRepoIdToAuthority(resourceId)); + for (String userId : aaiRegistryService.getUserIdentifiersByEmail(email)) { + authoritiesUpdater.removeRole(userId, roleMappingService.convertRepoIdToAuthority(resourceId)); + } return true; } else { From 0674a3c031657cfaba7c232c8346ffc7ebe0b36d Mon Sep 17 00:00:00 2001 From: Konstantinos Spyrou Date: Thu, 19 Jan 2023 12:15:30 +0200 Subject: [PATCH 05/29] fixed null pointer exception --- .../dnetlib/repo/manager/service/RepositoryServiceImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java index b89746a..898bbb1 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java @@ -614,7 +614,7 @@ public class RepositoryServiceImpl implements RepositoryService { emailUtils.sendAdminRegisterInterfaceEmail(e, comment, repositoryInterface, authentication); emailUtils.sendUserRegisterInterfaceEmail(e, comment, repositoryInterface, authentication); - if (desiredCompatibilityLevel != null && !repositoryInterface.getCompatibility().equals(desiredCompatibilityLevel)) { + if (desiredCompatibilityLevel != null && (repositoryInterface.getCompatibility() == null || !repositoryInterface.getCompatibility().equals(desiredCompatibilityLevel))) { InterfaceComplianceRequest request = new InterfaceComplianceRequest(repoId, repositoryInterface.getId(), desiredCompatibilityLevel); interfaceComplianceService.create(request); } @@ -637,7 +637,7 @@ public class RepositoryServiceImpl implements RepositoryService { emailUtils.sendAdminUpdateInterfaceEmail(repository, comment, repositoryInterface, authentication); emailUtils.sendUserUpdateInterfaceEmail(repository, comment, repositoryInterface, authentication); - if (desiredCompatibilityLevel != null && !repositoryInterface.getCompatibility().equals(desiredCompatibilityLevel)) { + if (desiredCompatibilityLevel != null && (repositoryInterface.getCompatibility() == null || !repositoryInterface.getCompatibility().equals(desiredCompatibilityLevel))) { InterfaceComplianceRequest request = new InterfaceComplianceRequest(repoId, repositoryInterface.getId(), desiredCompatibilityLevel); interfaceComplianceService.create(request); } From f88d9b838101af18bf6efbdd1ba5d06b468a576b Mon Sep 17 00:00:00 2001 From: Konstantinos Spyrou Date: Thu, 19 Jan 2023 12:28:31 +0200 Subject: [PATCH 06/29] fixed deserialization issue caused from json to String --- .../repo/manager/service/RepositoryServiceImpl.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java index 898bbb1..ed8f062 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java @@ -287,16 +287,14 @@ public class RepositoryServiceImpl implements RepositoryService { requestFilter.setEnglishname(englishName); try { - String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class); + Map rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, Map.class); if (rs == null) { logger.error("DSM response is null : [url={}]", uriComponents.toUri()); } else { - JSONObject response = new JSONObject(rs); - JSONArray jsonArray = (JSONArray) response.get("datasourceInfo"); - Header header = mapper.readValue(response.get("header").toString(), Header.class); + Header header = mapper.readValue(mapper.writeValueAsString(rs.get("header")), Header.class); snippets = Paging.of(header, mapper.readValue( - String.valueOf(jsonArray), + mapper.writeValueAsString(rs.get("datasourceInfo")), mapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class))); } From 415bb1e1974810cbed6a230256c25c5e64eacad4 Mon Sep 17 00:00:00 2001 From: Konstantinos Spyrou Date: Thu, 19 Jan 2023 13:08:03 +0200 Subject: [PATCH 07/29] fixed conflict --- .../manager/service/aai/registry/RegistryCalls.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/RegistryCalls.java b/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/RegistryCalls.java index ce46c5b..2485137 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/RegistryCalls.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/RegistryCalls.java @@ -178,15 +178,18 @@ public class RegistryCalls implements AaiRegistryService { @Override public JsonArray getRolesWithStatus(Integer coPersonId, RoleStatus status) { JsonArray roles = getRoles(coPersonId); - if (status == null) { - return roles; + if (roles == null) { + roles = new JsonArray(); } JsonArray activeRoles = new JsonArray(); - for (JsonElement role : roles) { - if (role.getAsJsonObject().get("Status").getAsString().equalsIgnoreCase(status.toString())) { - activeRoles.add(role); + if (status != null) { + for (JsonElement role : roles) { + if (role.getAsJsonObject().get("Status").getAsString().equalsIgnoreCase(status.toString())) { + activeRoles.add(role); + } } } + assert activeRoles != null; return activeRoles; } From 125b64ec3bea2f6a554e895414db98d67f5c9f7e Mon Sep 17 00:00:00 2001 From: Konstantinos Spyrou Date: Thu, 19 Jan 2023 13:41:11 +0200 Subject: [PATCH 08/29] check if CouId is null --- .../manager/service/security/AuthorizationServiceImpl.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/eu/dnetlib/repo/manager/service/security/AuthorizationServiceImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/security/AuthorizationServiceImpl.java index 56a71c2..0f05eaa 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/security/AuthorizationServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/security/AuthorizationServiceImpl.java @@ -176,7 +176,9 @@ public class AuthorizationServiceImpl implements AuthorizationService { int coPersonId = aaiRegistryService.getCoPersonIdByEmail(email); List list = new ArrayList<>(); for (JsonElement element : aaiRegistryService.getRolesWithStatus(coPersonId, AaiRegistryService.RoleStatus.ACTIVE)) { - list.add(element.getAsJsonObject().get("CouId").getAsInt()); + if (element.getAsJsonObject().get("CouId") != null) { + list.add(element.getAsJsonObject().get("CouId").getAsInt()); + } } return aaiRegistryService.getCouNames(list).values(); } From 607c417e3f6fb06fe21f77419004ba4b4a0dbfc0 Mon Sep 17 00:00:00 2001 From: Konstantinos Spyrou Date: Fri, 20 Jan 2023 19:15:59 +0200 Subject: [PATCH 09/29] get all ids of user using email in registry --- .../controllers/UserRoleController.java | 216 +++++++++--------- .../service/RepositoryServiceImpl.java | 10 +- .../aai/registry/AaiRegistryService.java | 22 +- .../service/aai/registry/RegistryCalls.java | 67 +++--- .../security/AuthorizationService.java | 4 +- .../security/AuthorizationServiceImpl.java | 61 +++-- 6 files changed, 191 insertions(+), 189 deletions(-) diff --git a/src/main/java/eu/dnetlib/repo/manager/controllers/UserRoleController.java b/src/main/java/eu/dnetlib/repo/manager/controllers/UserRoleController.java index bc4dcf2..9f4d8b7 100644 --- a/src/main/java/eu/dnetlib/repo/manager/controllers/UserRoleController.java +++ b/src/main/java/eu/dnetlib/repo/manager/controllers/UserRoleController.java @@ -1,108 +1,108 @@ -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) { - 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 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> 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> 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.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 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> 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> getRoleNames() { +// return ResponseEntity.ok(authorizationService.getUserRoles()); +// } +// +//} diff --git a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java index ed8f062..cd29d19 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java @@ -434,7 +434,7 @@ public class RepositoryServiceImpl implements RepositoryService { } @Override - public List getRepositoryInterface(String id) throws JSONException { + public List getRepositoryInterface(String id) { UriComponents uriComponents = UriComponentsBuilder .fromHttpUrl(baseAddress + "/ds/api/") @@ -629,6 +629,12 @@ public class RepositoryServiceImpl implements RepositoryService { String desiredCompatibilityLevel) throws Exception { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); Repository repository = this.getRepositoryById(repoId); + if (repositoryInterface.getId() != null) { + RepositoryInterface existing = getRepositoryInterface(repoId).stream().filter(iFace -> iFace.getId().equals(repositoryInterface.getId())).findFirst().orElse(null); + if (existing != null && (existing.getBaseurl() == null || "".equals(existing.getBaseurl()))) { + this.updateBaseUrl(repoId, repositoryInterface.getId(), repositoryInterface.getBaseurl()); + } + } this.updateValidationSet(repoId, repositoryInterface.getId(), repositoryInterface.getAccessSet()); @@ -988,7 +994,7 @@ public class RepositoryServiceImpl implements RepositoryService { } private List getRoleIdsFromUserRoles(String userEmail) { - Integer coPersonId = registryCalls.getCoPersonIdByEmail(userEmail); + List coPersonId = registryCalls.getCoPersonIdsByEmail(userEmail); JsonArray roles; ArrayList roleIds = new ArrayList<>(); ArrayList couIds = new ArrayList<>(); diff --git a/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/AaiRegistryService.java b/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/AaiRegistryService.java index ac6a69b..6cb453f 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/AaiRegistryService.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/AaiRegistryService.java @@ -11,19 +11,19 @@ import java.util.Map; public interface AaiRegistryService { /** - * 1.1 Get CoPersonId by authenticated user's Email + * 1.1 Get CoPersonId List by authenticated user's Email * * @return */ - Integer getCoPersonIdByEmail(); + List getCoPersonIdsByEmail(); /** - * 1.2 Get CoPersonId by Email + * 1.2 Get CoPersonId List by Email * * @param email * @return */ - Integer getCoPersonIdByEmail(String email); + List getCoPersonIdsByEmail(String email); /** * 1.3 Get a list of User Identifiers by Email @@ -34,12 +34,12 @@ public interface AaiRegistryService { List getUserIdentifiersByEmail(String email); /** - * 1.4 Get CoPersonId List by Email + * 1.3 Get a list of User Identifiers by Email * - * @param email + * @param coPersonId * @return */ - List getCoPersonIdsByEmail(String email); + List getUserIdentifiersByCoPersonId(Integer coPersonId); /** * 2. Get CoPersonId by AAI identifier @@ -105,6 +105,14 @@ public interface AaiRegistryService { */ JsonArray getRolesWithStatus(Integer coPersonId, RoleStatus status); + /** + * 5.3 Get User non admin active roles + * + * @param coPersonIds + * @return + */ + JsonArray getRolesWithStatus(List coPersonIds, RoleStatus status); + /** * 6. Get Role id of User base on couId. * diff --git a/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/RegistryCalls.java b/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/RegistryCalls.java index 2485137..db0573e 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/RegistryCalls.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/RegistryCalls.java @@ -16,10 +16,7 @@ import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; import java.net.URLEncoder; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; @Service public class RegistryCalls implements AaiRegistryService { @@ -46,41 +43,20 @@ public class RegistryCalls implements AaiRegistryService { return type; } - @Override - public Integer getCoPersonIdByEmail() { - try { - OIDCAuthenticationToken authentication = (OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); - String email = authentication.getUserInfo().getEmail(); - Map params = new HashMap<>(); - 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 params = new HashMap<>(); - params.put("mail", email); - params.put("coid", coid); - 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 getUserIdentifiersByEmail(String email) { + List ids = new ArrayList<>(); + for (Integer coPersonId : getCoPersonIdsByEmail(email)) { + ids.addAll(getUserIdentifiersByCoPersonId(coPersonId)); + } + return ids; + } + + @Override + public List getUserIdentifiersByCoPersonId(Integer coPersonId) { List ids = new ArrayList<>(); Map params = new HashMap<>(); - params.put("copersonid", getCoPersonIdByEmail(email).toString()); + params.put("copersonid", coPersonId.toString()); JsonElement response = httpUtils.get("identifiers.json", params); if (response != null) { @@ -95,6 +71,18 @@ public class RegistryCalls implements AaiRegistryService { return ids; } + @Override + public List getCoPersonIdsByEmail() { + try { + OIDCAuthenticationToken authentication = (OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); + String email = authentication.getUserInfo().getEmail(); + return getCoPersonIdsByEmail(email); + } catch (Exception e) { + logger.error("Get User info: An error occurred ", e); + return null; + } + } + @Override public List getCoPersonIdsByEmail(String email) { List coPersonIds = new ArrayList<>(); @@ -177,7 +165,14 @@ public class RegistryCalls implements AaiRegistryService { @Override public JsonArray getRolesWithStatus(Integer coPersonId, RoleStatus status) { - JsonArray roles = getRoles(coPersonId); + return getRolesWithStatus(Collections.singletonList(coPersonId), status); + } + + @Override + public JsonArray getRolesWithStatus(List coPersonIds, RoleStatus status) { + JsonArray roles = new JsonArray(); + JsonArray finalRoles = roles; + coPersonIds.parallelStream().forEach(coPersonId -> finalRoles.addAll(getRoles(coPersonId))); if (roles == null) { roles = new JsonArray(); } diff --git a/src/main/java/eu/dnetlib/repo/manager/service/security/AuthorizationService.java b/src/main/java/eu/dnetlib/repo/manager/service/security/AuthorizationService.java index 88abcd7..8c8a665 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/security/AuthorizationService.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/security/AuthorizationService.java @@ -43,7 +43,7 @@ public interface AuthorizationService { * @return * @throws ResourceNotFoundException */ - boolean addAdmin(String resourceId, String email) throws ResourceNotFoundException; + void addAdmin(String resourceId, String email) throws ResourceNotFoundException; /** * Remove user from resource admins. @@ -53,7 +53,7 @@ public interface AuthorizationService { * @return * @throws ResourceNotFoundException */ - boolean removeAdmin(String resourceId, String email) throws ResourceNotFoundException; + void removeAdmin(String resourceId, String email) throws ResourceNotFoundException; /** * Creates a role based on the resourceId and assigns it to the current user. diff --git a/src/main/java/eu/dnetlib/repo/manager/service/security/AuthorizationServiceImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/security/AuthorizationServiceImpl.java index 0f05eaa..7583c6f 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/security/AuthorizationServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/security/AuthorizationServiceImpl.java @@ -81,52 +81,45 @@ public class AuthorizationServiceImpl implements AuthorizationService { @Override - 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) { - aaiRegistryService.assignMemberRole(coPersonId, couId); + 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 coPersonIds = aaiRegistryService.getCoPersonIdsByEmail(email); + for (Integer coPersonId : coPersonIds) { + assert coPersonId != null; + aaiRegistryService.assignMemberRole(coPersonId, couId); - // Add role to user current authorities - for (String userId : aaiRegistryService.getUserIdentifiersByEmail(email)) { - authoritiesUpdater.addRole(userId, roleMappingService.convertRepoIdToAuthority(resourceId)); - } - - return true; - } else { - throw new ResourceNotFoundException("Cannot find CouId for role: " + role); + // Add role to user current authorities + for (String userId : aaiRegistryService.getUserIdentifiersByEmail(email)) { + authoritiesUpdater.addRole(userId, roleMappingService.convertRepoIdToAuthority(resourceId)); } - } else { - throw new ResourceNotFoundException("Cannot find coPersonId for user with email: " + email); } } @Override - 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) { + 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 coPersonIds = aaiRegistryService.getCoPersonIdsByEmail(email); + for (Integer coPersonId : coPersonIds) { + assert coPersonId != null; + Integer roleId = aaiRegistryService.getRoleId(coPersonId, couId); + if (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)); } - - return true; } else { - throw new ResourceNotFoundException("Cannot find CouId for role: " + role); + logger.error("Cannot find RoleId for role: {}", role); } - } else { - throw new ResourceNotFoundException("Cannot find coPersonId for user with email: " + email); } } @@ -173,9 +166,9 @@ public class AuthorizationServiceImpl implements AuthorizationService { @Override public Collection getUserRolesByEmail(String email) { - int coPersonId = aaiRegistryService.getCoPersonIdByEmail(email); + List coPersonIds = aaiRegistryService.getCoPersonIdsByEmail(email); List list = new ArrayList<>(); - for (JsonElement element : aaiRegistryService.getRolesWithStatus(coPersonId, AaiRegistryService.RoleStatus.ACTIVE)) { + for (JsonElement element : aaiRegistryService.getRolesWithStatus(coPersonIds, AaiRegistryService.RoleStatus.ACTIVE)) { if (element.getAsJsonObject().get("CouId") != null) { list.add(element.getAsJsonObject().get("CouId").getAsInt()); } From 0aa604a192b6d3cd3114803fef9acb3df2cb5f34 Mon Sep 17 00:00:00 2001 From: Konstantinos Spyrou Date: Mon, 23 Jan 2023 17:54:51 +0200 Subject: [PATCH 10/29] refactoring --- .../manager/service/RepositoryService.java | 5 +- .../service/RepositoryServiceImpl.java | 251 ++++++++---------- .../dnetlib/repo/manager/utils/Converter.java | 67 +---- 3 files changed, 122 insertions(+), 201 deletions(-) diff --git a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryService.java b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryService.java index ff760f9..2de462f 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryService.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryService.java @@ -1,5 +1,6 @@ package eu.dnetlib.repo.manager.service; +import com.fasterxml.jackson.core.JsonProcessingException; import eu.dnetlib.repo.manager.domain.*; import eu.dnetlib.repo.manager.exception.RepositoryServiceException; import eu.dnetlib.repo.manager.exception.ResourceNotFoundException; @@ -50,7 +51,7 @@ public interface RepositoryService { String officialName, String requestSortBy, String order, int page, int pageSize) throws Exception; - int getTotalRegisteredRepositories(); + Integer getTotalRegisteredRepositories(); List getRepositoryInterface(String id) throws JSONException; @@ -84,7 +85,7 @@ public interface RepositoryService { MetricsInfo getMetricsInfoForRepository(String repoId) throws RepositoryServiceException; - Map getListLatestUpdate(String mode) throws JSONException; + Map getListLatestUpdate(String mode); RepositoryInterface updateRepositoryInterface(String repoId, String comment, RepositoryInterface repositoryInterface, String desiredCompatibilityLevel) throws Exception; diff --git a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java index cd29d19..7e582c6 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java @@ -1,5 +1,6 @@ package eu.dnetlib.repo.manager.service; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gson.JsonArray; import com.google.gson.JsonElement; @@ -9,7 +10,6 @@ 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.User; -import eu.dnetlib.repo.manager.exception.BrokerException; import eu.dnetlib.repo.manager.exception.RepositoryServiceException; import eu.dnetlib.repo.manager.exception.ResourceNotFoundException; import eu.dnetlib.repo.manager.service.aai.registry.AaiRegistryService; @@ -20,9 +20,7 @@ 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.JSONArray; import org.json.JSONException; -import org.json.JSONObject; import org.mitre.openid.connect.model.OIDCAuthenticationToken; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -74,8 +72,6 @@ public class RepositoryServiceImpl implements RepositoryService { @Value("${services.provide.usageStatisticsNumbersBaseURL}") private String usageStatisticsNumbersBaseURL; - private final Converter converter; - private static final Map> dataSourceClass = new HashMap<>(); private static final Map invertedDataSourceClass = new HashMap<>(); @@ -94,7 +90,7 @@ public class RepositoryServiceImpl implements RepositoryService { VocabularyLoader vocabularyLoader, RestTemplate restTemplate, ObjectMapper objectMapper, - Converter converter, +// Converter converter, @Lazy EmailUtils emailUtils, @Lazy ValidatorService validatorService, @Lazy PiWikService piWikService, @@ -105,7 +101,6 @@ public class RepositoryServiceImpl implements RepositoryService { this.authoritiesUpdater = authoritiesUpdater; this.vocabularyLoader = vocabularyLoader; this.piWikService = piWikService; - this.converter = converter; this.emailUtils = emailUtils; this.validatorService = validatorService; this.restTemplate = restTemplate; @@ -172,21 +167,18 @@ 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 getRepositories(List ids, int page, int size) throws JSONException { - List repos = new ArrayList<>(); + public List getRepositories(List ids, int page, int size) { logger.debug("Retrieving repositories with ids : {}", String.join(", ", ids)); - UriComponents uriComponents = searchDatasource(Integer.toString(Math.abs(page)), Integer.toString(Math.abs(size))); + UriComponents uriComponents = searchDatasourceUri(Integer.toString(Math.abs(page)), Integer.toString(Math.abs(size))); RequestFilter requestFilter = new RequestFilter(); + List repos = new ArrayList<>(); + for (String repoId : ids) { requestFilter.setId(repoId); - List rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, List.class); - -// repos.addAll(converter.toRepositoryList(new JSONObject(rs))); + repos.addAll(searchDatasource(uriComponents, requestFilter, Repository.class).getResults()); } - // TODO - "repos" is EMPTY!! - for (Repository r : repos) r.setPiwikInfo(piWikService.getPiwikSiteForRepo(r.getId())); return repos; @@ -205,31 +197,30 @@ public class RepositoryServiceImpl implements RepositoryService { // another way for paging must be implemented. @Override public List getRepositoriesSnippets(List ids, int page, int size) throws Exception { - List resultSet = new ArrayList<>(); + List resultSet; + List datasourceDetailsList = new ArrayList<>(); // here page should be 0 - UriComponents uriComponents = searchSnippetDatasource(Integer.toString(Math.abs(page)), Integer.toString(Math.abs(size))); + UriComponents uriComponents = searchDatasourceSnippetUri(Integer.toString(Math.abs(page)), Integer.toString(Math.abs(size))); RequestFilter requestFilter = new RequestFilter(); - try { - for (String repoId : ids) { - requestFilter.setId(repoId); + 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!"); - return null; - } - - resultSet.addAll(objectMapper.readValue(objectMapper.writeValueAsString(rs.getDatasourceInfo()), - objectMapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class))); + DatasourceResponse rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, DatasourceResponse.class); + if (rs == null) { + logger.error("The \"DatasourceResponse\" is null!"); + } else { + datasourceDetailsList.addAll(rs.getDatasourceInfo()); } - } catch (Exception e) { - logger.debug("Exception on getRepositoriesSnippetOfUser", e); - throw e; } - logger.debug("resultSet: {}", resultSet); + 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())); }); @@ -240,13 +231,10 @@ public class RepositoryServiceImpl implements RepositoryService { @Override public List getRepositoriesByCountry(String country, String mode, - Boolean managed) throws JSONException, IOException { - + Boolean managed) throws IOException { logger.debug("Getting repositories by country!"); int page = 0; int size = 100; - List resultSet = new ArrayList<>(); - ObjectMapper mapper = new ObjectMapper(); String filterKey = "UNKNOWN"; if (mode.equalsIgnoreCase("repository")) @@ -257,17 +245,12 @@ public class RepositoryServiceImpl implements RepositoryService { logger.debug("Country code equals : {} | Filter mode equals : {}", country, filterKey); - UriComponents uriComponents = searchSnippetDatasource(String.valueOf(page), String.valueOf(size)); + UriComponents uriComponents = searchDatasourceSnippetUri(String.valueOf(page), String.valueOf(size)); RequestFilter requestFilter = new RequestFilter(); requestFilter.setCountry(country); requestFilter.setEoscDatasourceType(filterKey); - Map rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, Map.class); - if (rs != null) { - resultSet.addAll(mapper.readValue(mapper.writeValueAsString(rs.get("datasourceInfo")), - mapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class))); - } - return resultSet; + return searchDatasource(uriComponents, requestFilter, RepositorySnippet.class).getResults(); } public List searchRegisteredRepositories(String country, String typology, String englishName, @@ -275,10 +258,7 @@ public class RepositoryServiceImpl implements RepositoryService { logger.debug("Searching registered repositories"); - Paging snippets = null; - ObjectMapper mapper = new ObjectMapper(); - - UriComponents uriComponents = searchRegisteredDatasource(requestSortBy, order, Integer.toString(page), Integer.toString(pageSize)); + UriComponents uriComponents = searchRegisteredDatasourceUri(requestSortBy, order, Integer.toString(page), Integer.toString(pageSize)); RequestFilter requestFilter = new RequestFilter(); requestFilter.setCountry(country); @@ -286,27 +266,12 @@ public class RepositoryServiceImpl implements RepositoryService { requestFilter.setOfficialname(officialName); requestFilter.setEnglishname(englishName); - try { - Map rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, Map.class); - if (rs == null) { - logger.error("DSM response is null : [url={}]", uriComponents.toUri()); - } else { - Header header = mapper.readValue(mapper.writeValueAsString(rs.get("header")), Header.class); - snippets = Paging.of(header, - mapper.readValue( - mapper.writeValueAsString(rs.get("datasourceInfo")), - mapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class))); - } - - } catch (Exception e) { - logger.error("Error searching registered datasources", e); - throw e; - } + Paging snippets = searchDatasource(uriComponents, requestFilter, RepositorySnippet.class); return snippets != null ? snippets.getResults() : null; // TODO: return paging when ui is compatible } @Override - public int getTotalRegisteredRepositories() throws NullPointerException { + public Integer getTotalRegisteredRepositories() throws NullPointerException { UriComponents uriComponents = UriComponentsBuilder .fromHttpUrl(baseAddress + "/ds/countregistered") .queryParam("fromDate", "1900-01-01") @@ -315,7 +280,7 @@ public class RepositoryServiceImpl implements RepositoryService { return restTemplate.getForObject(uriComponents.toUri(), Integer.class); } - private Repository updateRepositoryInfo(Repository r) throws JSONException { + private Repository updateRepositoryInfo(Repository r) { r.setInterfaces(this.getRepositoryInterface(r.getId())); r.setPiwikInfo(piWikService.getPiwikSiteForRepo(r.getId())); return r; @@ -361,57 +326,35 @@ public class RepositoryServiceImpl implements RepositoryService { } @Override - public RepositorySnippet getRepositorySnippetById(String id) throws JSONException, ResourceNotFoundException { + public RepositorySnippet getRepositorySnippetById(String id) throws ResourceNotFoundException { logger.debug("Retrieving repositories with id : {}", id); - RepositorySnippet repo; - UriComponents uriComponents = searchSnippetDatasource("0", "100"); + UriComponents uriComponents = searchDatasourceSnippetUri("0", "100"); RequestFilter requestFilter = new RequestFilter(); requestFilter.setId(id); - String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class); - if (rs == null) { - logger.error("The result is null!"); - return null; - } + List repositories = searchDatasource(uriComponents, requestFilter, RepositorySnippet.class).getResults(); - JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo"); - - if (jsonArray.length() == 0) + if (repositories.isEmpty()) throw new ResourceNotFoundException(); - repo = converter.toRepositorySnippet(jsonArray.getJSONObject(0)); - return repo; + return repositories.get(0); } @Override - public Repository getRepositoryById(String id) throws JSONException, ResourceNotFoundException { + public Repository getRepositoryById(String id) throws ResourceNotFoundException { logger.debug("Retrieving repositories with id : {}", id); - Repository repo; - UriComponents uriComponents = searchDatasource("0", "100"); + + UriComponents uriComponents = searchDatasourceUri("0", "100"); RequestFilter requestFilter = new RequestFilter(); requestFilter.setId(id); -// String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class); -// JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo"); - - DatasourceResponse response; - response = restTemplate.postForObject(uriComponents.toUri(), requestFilter, DatasourceResponse.class); - if (response == null) { - logger.error("The response is null!"); - return null; - } - - List datasources = response.getDatasourceInfo(); - if (datasources.size() == 0) + List datasources = searchDatasource(uriComponents, requestFilter, Repository.class).getResults(); + if (datasources.isEmpty()) throw new ResourceNotFoundException(); -// repo = converter.toRepository(jsonArray.getJSONObject(0)); -// return updateRepositoryInfo(repo); - - return updateRepositoryInfo(converter.toRepository(datasources.get(0))); - + return updateRepositoryInfo(datasources.get(0)); } @@ -421,12 +364,11 @@ public class RepositoryServiceImpl implements RepositoryService { String size) throws JSONException { logger.debug("Retrieving repositories with official name : {}", name); - UriComponents uriComponents = searchDatasource("0", "100"); + UriComponents uriComponents = searchDatasourceUri("0", "100"); RequestFilter requestFilter = new RequestFilter(); requestFilter.setOfficialname(name); - String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class); - List repos = converter.toRepositoryList(new JSONObject(rs)); + List repos = searchDatasource(uriComponents, requestFilter, Repository.class).getResults(); for (Repository r : repos) updateRepositoryInfo(r); return repos; @@ -441,26 +383,20 @@ public class RepositoryServiceImpl implements RepositoryService { .path("/{id}") .build().expand(id).encode(); -// String rs = restTemplate.getForObject(uriComponents.toUri(), String.class); - ApiDetailsResponse rs = restTemplate.getForObject(uriComponents.toUri(), ApiDetailsResponse.class); - if (rs == null) { - logger.error("The ApiDetailsResponse was null!"); - return null; - } + List rs = searchApi(uriComponents, null, RepositoryInterface.class).getResults(); // TODO STOP FILTERING OUT "sword", "rest" AND FIX UI! - List res = new ArrayList<>(); - - for (ApiDetails det : rs.getApi()) { + List repositoryInterfaces = new ArrayList<>(); + for (RepositoryInterface det : rs) { String protocol = det.getProtocol(); if (!protocol.equals("sword") && !protocol.equals("rest") && !protocol.equals("ftp")) { - res.add(det); + repositoryInterfaces.add(det); } } - return converter.toRepositoryInterfaceList(res); + return repositoryInterfaces; } @Override @@ -501,17 +437,13 @@ public class RepositoryServiceImpl implements RepositoryService { } /* update method acting as add -> send email with registration topic/body*/ - private Repository latentUpdate(Repository repository, Authentication authentication) throws Exception { + private Repository latentUpdate(Repository repository, Authentication authentication) { UriComponents uriComponents = UriComponentsBuilder .fromHttpUrl(baseAddress + "/ds/update/") .build() .encode(); - // FIXME: problematic -// String json_repository = converter.toJson(repository); -// logger.debug("JSON to add(update) -> " + json_repository); - - HttpEntity httpEntity = new HttpEntity<>(repository, httpHeaders); // TODO: check if it works (Repository contains extra fields) + HttpEntity httpEntity = new HttpEntity<>(repository, httpHeaders); ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class); if (responseEntity.getStatusCode().equals(HttpStatus.OK)) { @@ -533,10 +465,6 @@ public class RepositoryServiceImpl implements RepositoryService { .build() .encode(); - // FIXME: problematic -// String json_repository = converter.toJson(repository); -// logger.debug("JSON to update -> " + json_repository); - HttpEntity httpEntity = new HttpEntity<>(repository, httpHeaders); ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class); @@ -564,7 +492,6 @@ public class RepositoryServiceImpl implements RepositoryService { .fromHttpUrl(baseAddress + "/ds/add/") .build() .encode(); -// String json_repository = converter.toJson(repository); HttpEntity httpEntity = new HttpEntity<>(repository, httpHeaders); ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class); @@ -597,8 +524,7 @@ public class RepositoryServiceImpl implements RepositoryService { String desiredCompatibilityLevel) throws Exception { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); Repository e = this.getRepositoryById(repoId); - repositoryInterface = createRepositoryInterface(e, repositoryInterface, datatype); -// String json_interface = converter.toJson(e, repositoryInterface); + repositoryInterface = fillInterfaceFields(e, repositoryInterface, datatype); UriComponents uriComponents = UriComponentsBuilder .fromHttpUrl(baseAddress + "/ds/api/add/") @@ -606,9 +532,11 @@ public class RepositoryServiceImpl implements RepositoryService { .encode(); HttpEntity httpEntity = new HttpEntity<>(repositoryInterface, httpHeaders); - restTemplate.postForObject(uriComponents.toUri(), httpEntity, String.class); + // Explicitly update validation set (updating the interface does not allow updating the set value) + this.updateValidationSet(repoId, repositoryInterface.getId(), repositoryInterface.getAccessSet()); + emailUtils.sendAdminRegisterInterfaceEmail(e, comment, repositoryInterface, authentication); emailUtils.sendUserRegisterInterfaceEmail(e, comment, repositoryInterface, authentication); @@ -682,12 +610,11 @@ public class RepositoryServiceImpl implements RepositoryService { this.validatorService.submitJobForValidation(job); } - private RepositoryInterface createRepositoryInterface(Repository repo, RepositoryInterface iFace, String datatype) { + private RepositoryInterface fillInterfaceFields(Repository repo, RepositoryInterface iFace, String datatype) { iFace.setDatasource(repo.getId()); iFace.setContentdescription("metadata"); - // TODO: double check me logger.warn("Compatibility level: {}", iFace.getCompatibility()); if (iFace.getCompatibility() == null || iFace.getCompatibility().equals("")) { iFace.setCompatibility("UNKNOWN"); @@ -699,7 +626,7 @@ public class RepositoryServiceImpl implements RepositoryService { iFace.setAccessFormat("oai_dc"); - // FIXME: this will probably not work + // TODO: is this the correct functionality? if (repo.getEoscDatasourceType() != null && !repo.getEoscDatasourceType().isEmpty()) iFace.setTypology(repo.getEoscDatasourceType()); else if (datatype.equalsIgnoreCase("journal")) @@ -725,18 +652,18 @@ public class RepositoryServiceImpl implements RepositoryService { @Override public List getDnetCountries() { logger.debug("Getting dnet-countries!"); - return converter.readFile("countries.txt"); + return Converter.readFile("countries.txt"); } @Override public List getTypologies() { - return converter.readFile("typologies.txt"); + return Converter.readFile("typologies.txt"); } @Override public List getTimezones() { - List timezones = converter.readFile("timezones.txt"); - return converter.toTimezones(timezones); + List timezones = Converter.readFile("timezones.txt"); + return Converter.toTimezones(timezones); } @Override @@ -867,13 +794,13 @@ public class RepositoryServiceImpl implements RepositoryService { } @Override - public Map getListLatestUpdate(String mode) throws JSONException { + public Map getListLatestUpdate(String mode) { Map dates = new HashMap<>(); if (mode.equals("repository")) { dates.put("opendoar", DateUtils.toString(getRepositoryInterface("openaire____::opendoar").get(0).getLastCollectionDate())); dates.put("fairsharing", DateUtils.toString(getRepositoryInterface("openaire____::fairsharing").get(0).getLastCollectionDate())); // create re3data last collection date -// dates.put("re3data", converter.toString(getRepositoryInterface("openaire____::re3data").get(1).getLastCollectionDate())); +// dates.put("re3data", Converter.toString(getRepositoryInterface("openaire____::re3data").get(1).getLastCollectionDate())); List re3interfaces = getRepositoryInterface("openaire____::re3data"); String re3Date = null; for (RepositoryInterface interf : re3interfaces) { @@ -928,7 +855,7 @@ public class RepositoryServiceImpl implements RepositoryService { restTemplate.postForObject(uriComponents.toUri(), null, String.class); } - private MetricsNumbers getMetricsNumbers(String openAIREID) throws BrokerException { + private MetricsNumbers getMetricsNumbers(String openAIREID) { //build the uri params UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(this.usageStatisticsNumbersBaseURL + openAIREID + "/clicks"); @@ -959,7 +886,7 @@ public class RepositoryServiceImpl implements RepositoryService { } - private UriComponents searchDatasource(String page, String size) { + private UriComponents searchDatasourceUri(String page, String size) { return UriComponentsBuilder .fromHttpUrl(baseAddress + "/ds/searchdetails/") @@ -969,7 +896,7 @@ public class RepositoryServiceImpl implements RepositoryService { .build().expand(page, size).encode(); } - private UriComponents searchSnippetDatasource(String page, String size) { + private UriComponents searchDatasourceSnippetUri(String page, String size) { return UriComponentsBuilder .fromHttpUrl(baseAddress + "/ds/searchsnippet/") @@ -979,7 +906,7 @@ public class RepositoryServiceImpl implements RepositoryService { .build().expand(page, size).encode(); } - private UriComponents searchRegisteredDatasource(String requestSortBy, String order, String page, String size) { + private UriComponents searchRegisteredDatasourceUri(String requestSortBy, String order, String page, String size) { return UriComponentsBuilder .fromHttpUrl(baseAddress + "/ds/searchregistered/") @@ -989,6 +916,52 @@ public class RepositoryServiceImpl implements RepositoryService { .build().expand(page, size).encode(); } + private Paging searchDatasource(UriComponents uriComponents, RequestFilter requestFilter, Class clazz) { + Paging repositories = new Paging<>(); + ResponseEntity rs; + rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, new HttpEntity<>(requestFilter), Map.class); + if (!rs.getStatusCode().is2xxSuccessful()) { + logger.error("Api call not successful. Code: {} | Body: {}", rs.getStatusCode(), rs.getBody()); + } + if (rs.getBody() == null) { + logger.error("DSM response is null : [url={}]", uriComponents.toUri()); + } else { + try { + Header header = objectMapper.readValue(objectMapper.writeValueAsString(rs.getBody().get("header")), Header.class); + repositories = Paging.of(header, + objectMapper.readValue( + objectMapper.writeValueAsString(rs.getBody().get("datasourceInfo")), + objectMapper.getTypeFactory().constructCollectionType(List.class, clazz))); + } catch (JsonProcessingException e) { + logger.error("Error in objectMapper", e); + } + } + return repositories; + } + + private Paging searchApi(UriComponents uriComponents, RequestFilter requestFilter, Class clazz) { + Paging repositories = new Paging<>(); + ResponseEntity rs; + rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, new HttpEntity<>(requestFilter), Map.class); + if (!rs.getStatusCode().is2xxSuccessful()) { + logger.error("Api call not successful. Code: {} | Body: {}", rs.getStatusCode(), rs.getBody()); + } + if (rs.getBody() == null) { + logger.error("DSM response is null : [url={}]", uriComponents.toUri()); + } else { + try { + Header header = objectMapper.readValue(objectMapper.writeValueAsString(rs.getBody().get("header")), Header.class); + repositories = Paging.of(header, + objectMapper.readValue( + objectMapper.writeValueAsString(rs.getBody().get("api")), + objectMapper.getTypeFactory().constructCollectionType(List.class, clazz))); + } catch (JsonProcessingException e) { + logger.error("Error in objectMapper", e); + } + } + return repositories; + } + private String getRepositoryType(String typology) { return invertedDataSourceClass.get(typology); } diff --git a/src/main/java/eu/dnetlib/repo/manager/utils/Converter.java b/src/main/java/eu/dnetlib/repo/manager/utils/Converter.java index 38f5e2e..3dccc4e 100644 --- a/src/main/java/eu/dnetlib/repo/manager/utils/Converter.java +++ b/src/main/java/eu/dnetlib/repo/manager/utils/Converter.java @@ -1,15 +1,9 @@ package eu.dnetlib.repo.manager.utils; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import eu.dnetlib.repo.manager.domain.*; +import eu.dnetlib.repo.manager.domain.Timezone; import org.apache.commons.codec.digest.DigestUtils; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; import java.io.BufferedReader; import java.io.InputStream; @@ -18,61 +12,14 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; -@Component public class Converter { private static final Logger logger = LoggerFactory.getLogger(Converter.class); - private final ObjectMapper objectMapper; - - public Converter() { - objectMapper = new ObjectMapper()/*.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)*/; - } - public Repository toRepository(Object repositoryObject) { - - Repository repository = objectMapper.convertValue(repositoryObject, Repository.class); - - return repository; + private Converter() { } - public RepositorySnippet toRepositorySnippet(JSONObject repositorySnippetObject) { - - RepositorySnippet snippet = objectMapper.convertValue(repositorySnippetObject, RepositorySnippet.class); - - return snippet; - } - - public List toRepositoryList(JSONObject json) throws JSONException { - - List resultSet = new ArrayList<>(); - JSONArray rs = json.getJSONArray("datasourceInfo"); - for (int i = 0; i < rs.length(); i++) - resultSet.add(toRepository(rs.getJSONObject(i))); - return resultSet; - } - - public List toRepositoryInterfaceList(List apiDetailsList) { - - List resultSet = new ArrayList<>(); - - for (ApiDetails entry : apiDetailsList) - resultSet.add(toRepositoryInterface(entry)); - return resultSet; - } - - public RepositoryInterface toRepositoryInterface(Object repositoryInterfaceObject) { - - RepositoryInterface repoInterface = objectMapper.convertValue(repositoryInterfaceObject, RepositoryInterface.class); - - return repoInterface; - } - - public String toJson(Repository repository) throws JsonProcessingException { - - return objectMapper.writeValueAsString(repository); - } - - public List readFile(String filename) { + public static List readFile(String filename) { String line; List list = new ArrayList<>(); try { @@ -88,7 +35,7 @@ public class Converter { return list; // It may be empty. } - public List toTimezones(List timezones) { + public static List toTimezones(List timezones) { List tmz = new ArrayList<>(); for (String t : timezones) { @@ -98,17 +45,17 @@ public class Converter { return tmz; } - private String getOpenaireId(String repositoryId) { + public static String getOpenaireId(String repositoryId) { if (repositoryId != null && repositoryId.contains("::")) return repositoryId.split("::")[0] + "::" + DigestUtils.md5Hex(repositoryId.split("::")[1]); return null; } - private Boolean convertStringToBoolean(String value) { + public static Boolean convertStringToBoolean(String value) { return value.equals("null") ? null : Boolean.valueOf(value); } - private Double toDouble(String number) { + public static Double toDouble(String number) { if (Objects.equals(number, "null")) return 0.0; else From 4231480cbce247b7e99fae23f9b269976146d3a9 Mon Sep 17 00:00:00 2001 From: Konstantinos Spyrou Date: Mon, 23 Jan 2023 17:57:18 +0200 Subject: [PATCH 11/29] disabled delete on interfaces --- .../dnetlib/repo/manager/controllers/RepositoryController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/eu/dnetlib/repo/manager/controllers/RepositoryController.java b/src/main/java/eu/dnetlib/repo/manager/controllers/RepositoryController.java index 807d0af..9112339 100644 --- a/src/main/java/eu/dnetlib/repo/manager/controllers/RepositoryController.java +++ b/src/main/java/eu/dnetlib/repo/manager/controllers/RepositoryController.java @@ -201,7 +201,8 @@ public class RepositoryController { @PreAuthorize("hasAuthority('SUPER_ADMINISTRATOR') or hasAuthority('CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR') or @authorizationService.isMemberOfInterface(#id)") public void deleteRepositoryInterface(@RequestParam("id") String id, @RequestParam("registeredBy") String registeredBy) { - repositoryService.deleteRepositoryInterface(id, registeredBy); +// repositoryService.deleteRepositoryInterface(id, registeredBy); + logger.warn("User attempted delete on Interface with ID: {}", id); } @RequestMapping(value = "/addInterface", method = RequestMethod.POST, From 9e4817f2bd7718dd9a8f5a24429ba82093d5ee9a Mon Sep 17 00:00:00 2001 From: Konstantinos Spyrou Date: Mon, 23 Jan 2023 18:26:19 +0200 Subject: [PATCH 12/29] refactoring --- .../manager/service/RepositoryService.java | 27 ++++---- .../service/RepositoryServiceImpl.java | 65 +++++++++---------- 2 files changed, 42 insertions(+), 50 deletions(-) diff --git a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryService.java b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryService.java index 2de462f..b3bf3e3 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryService.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryService.java @@ -1,13 +1,12 @@ package eu.dnetlib.repo.manager.service; -import com.fasterxml.jackson.core.JsonProcessingException; +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; @@ -17,27 +16,25 @@ public interface RepositoryService { // TODO: move this elsewhere Country[] getCountries(); - List getRepositories(List ids) throws JSONException; + List getRepositories(List ids); - List getRepositories(List ids, int page, int size) throws JSONException; + List getRepositories(List ids, int page, int size); List getRepositoriesSnippets(List ids) throws Exception; List getRepositoriesSnippets(List ids, int page, int size) throws Exception; - List getRepositoriesByCountry(String country, String mode, Boolean managed) throws JSONException, IOException; + List getRepositoriesByCountry(String country, String mode, Boolean managed); // TODO: remove? - List getRepositoriesOfUser(String page, String size) throws JSONException, IOException; + List getRepositoriesOfUser(String page, String size); // TODO: remove? - List getRepositoriesOfUser(String userEmail, - String page, - String size) throws JSONException, IOException; + List getRepositoriesOfUser(String userEmail, String page, String size); - List getRepositoriesSnippetsOfUser(String page, String size) throws Exception; + List getRepositoriesSnippetsOfUser(String page, String size); - List getRepositoriesSnippetsOfUser(String userEmail, String page, String size) throws Exception; + List getRepositoriesSnippetsOfUser(String userEmail, String page, String size); RepositorySnippet getRepositorySnippetById(String id) throws JSONException, ResourceNotFoundException; @@ -71,11 +68,9 @@ public interface RepositoryService { List getTimezones(); - Repository updateRepository(Repository repository, Authentication authentication) throws Exception; + Repository updateRepository(Repository repository, Authentication authentication); - List getUrlsOfUserRepos(String user_email, - String page, - String size); + List getUrlsOfUserRepos(String userEmail, String page, String size); Map getCompatibilityClasses(String mode); @@ -87,7 +82,7 @@ public interface RepositoryService { Map getListLatestUpdate(String mode); - RepositoryInterface updateRepositoryInterface(String repoId, String comment, RepositoryInterface repositoryInterface, String desiredCompatibilityLevel) throws Exception; + RepositoryInterface updateRepositoryInterface(String repoId, String comment, RepositoryInterface repositoryInterface, String desiredCompatibilityLevel) throws ResourceNotFoundException, ValidatorServiceException; void updateInterfaceCompliance(String repositoryId, String repositoryInterfaceId, String compliance); } diff --git a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java index 7e582c6..b0b828d 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java @@ -13,14 +13,12 @@ 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; @@ -38,7 +36,6 @@ 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; @@ -51,7 +48,6 @@ 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; @@ -86,11 +82,9 @@ 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, @@ -98,7 +92,6 @@ 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; @@ -134,7 +127,7 @@ public class RepositoryServiceImpl implements RepositoryService { } httpHeaders = new HttpHeaders(); - httpHeaders.setContentType(MediaType.APPLICATION_JSON_UTF8); + httpHeaders.setContentType(MediaType.APPLICATION_JSON); for (String vocName : vocabularyNames) { vocabularyMap.put(vocName, vocabularyLoader.getVocabulary(vocName, Locale.ENGLISH, Locale.ROOT)); @@ -159,7 +152,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 getRepositories(List ids) throws JSONException { + public List getRepositories(List ids) { return getRepositories(ids, 0, 10); } @@ -188,7 +181,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 getRepositoriesSnippets(List ids) throws Exception { + public List getRepositoriesSnippets(List ids) { return getRepositoriesSnippets(ids, 0, 10); } @@ -196,8 +189,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 getRepositoriesSnippets(List ids, int page, int size) throws Exception { - List resultSet; + public List getRepositoriesSnippets(List ids, int page, int size) { + List resultSet = null; List datasourceDetailsList = new ArrayList<>(); // here page should be 0 @@ -215,15 +208,19 @@ public class RepositoryServiceImpl implements RepositoryService { } } - resultSet = objectMapper.readValue(objectMapper.writeValueAsString(datasourceDetailsList), - objectMapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class)); - - if (logger.isDebugEnabled()) { - logger.debug("resultSet: {}", objectMapper.writeValueAsString(resultSet)); + 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.parallelStream().forEach(repositorySnippet -> { - repositorySnippet.setPiwikInfo(piWikService.getPiwikSiteForRepo(repositorySnippet.getId())); - }); + return resultSet; } @@ -231,7 +228,7 @@ public class RepositoryServiceImpl implements RepositoryService { @Override public List getRepositoriesByCountry(String country, String mode, - Boolean managed) throws IOException { + Boolean managed) { logger.debug("Getting repositories by country!"); int page = 0; int size = 100; @@ -254,7 +251,7 @@ public class RepositoryServiceImpl implements RepositoryService { } public List searchRegisteredRepositories(String country, String typology, String englishName, - String officialName, String requestSortBy, String order, int page, int pageSize) throws Exception { + String officialName, String requestSortBy, String order, int page, int pageSize) { logger.debug("Searching registered repositories"); @@ -287,7 +284,7 @@ public class RepositoryServiceImpl implements RepositoryService { } @Override - public List getRepositoriesOfUser(String page, String size) throws JSONException { + public List getRepositoriesOfUser(String page, String size) { logger.debug("Retrieving repositories of authenticated user : {}", ((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail()); Collection repoIds = roleMappingService.getRepoIdsByRoleIds(authorizationService.getUserRoles()); @@ -295,19 +292,19 @@ public class RepositoryServiceImpl implements RepositoryService { } @Override - public List getRepositoriesOfUser(String userEmail, String page, String size) throws JSONException { + public List getRepositoriesOfUser(String userEmail, String page, String size) { logger.debug("Retrieving repositories of authenticated user : {}", userEmail); Collection repoIds = roleMappingService.getRepoIdsByRoleIds(authorizationService.getUserRolesByEmail(userEmail)); return getRepositories(new ArrayList<>(repoIds)); } @Override - public List getRepositoriesSnippetsOfUser(String page, String size) throws Exception { + public List getRepositoriesSnippetsOfUser(String page, String size) { return getRepositoriesSnippetsOfUser(null, page, size); } @Override - public List getRepositoriesSnippetsOfUser(String userEmail, String page, String size) throws Exception { + public List getRepositoriesSnippetsOfUser(String userEmail, String page, String size) { int from = Integer.parseInt(page) * Integer.parseInt(size); int to = from + Integer.parseInt(size); List repoIds = new ArrayList<>(); @@ -361,7 +358,7 @@ public class RepositoryServiceImpl implements RepositoryService { @Override public List getRepositoriesByName(String name, String page, - String size) throws JSONException { + String size) { logger.debug("Retrieving repositories with official name : {}", name); UriComponents uriComponents = searchDatasourceUri("0", "100"); @@ -400,7 +397,7 @@ public class RepositoryServiceImpl implements RepositoryService { } @Override - public Repository addRepository(String datatype, Repository repository) throws Exception { + public Repository addRepository(String datatype, Repository repository) { logger.debug("storing '{}' repository with id: {}", datatype, repository.getId()); @@ -459,7 +456,7 @@ public class RepositoryServiceImpl implements RepositoryService { } @Override - public Repository updateRepository(Repository repository, Authentication authentication) throws Exception { + public Repository updateRepository(Repository repository, Authentication authentication) { UriComponents uriComponents = UriComponentsBuilder .fromHttpUrl(baseAddress + "/ds/update/") .build() @@ -480,7 +477,7 @@ public class RepositoryServiceImpl implements RepositoryService { return repository; } - private void storeRepository(Repository repository, Authentication authentication) throws Exception { + private void storeRepository(Repository repository, Authentication authentication) { Date utilDate = new Date(); Timestamp date = new Timestamp(utilDate.getTime()); @@ -554,7 +551,7 @@ public class RepositoryServiceImpl implements RepositoryService { public RepositoryInterface updateRepositoryInterface(String repoId, String comment, RepositoryInterface repositoryInterface, - String desiredCompatibilityLevel) throws Exception { + String desiredCompatibilityLevel) throws ResourceNotFoundException, ValidatorServiceException { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); Repository repository = this.getRepositoryById(repoId); if (repositoryInterface.getId() != null) { @@ -694,7 +691,7 @@ public class RepositoryServiceImpl implements RepositoryService { public Map getCompatibilityClasses(String mode) { logger.debug("Getting compatibility classes for mode: {}", mode); - Map retMap = new HashMap(); + Map retMap = new HashMap<>(); Map compatibilityClasses = this.getVocabulary("dnet:compatibilityLevel").getAsMap(); boolean foundData = false; @@ -729,7 +726,7 @@ public class RepositoryServiceImpl implements RepositoryService { logger.debug("Getting datasource classes for mode: {}", mode); - Map retMap = new HashMap(); + Map retMap = new HashMap<>(); // TODO: refactor (remove?) for (Map.Entry entry : this.getVocabulary("dnet:datasource_typologies").getAsMap().entrySet()) { @@ -823,7 +820,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) throws Exception { + private void updateValidationSet(String repositoryId, String repositoryInterfaceId, String validationSet) { UriComponents uriComponents = UriComponentsBuilder .fromHttpUrl(baseAddress + "/ds/api/oaiset") .queryParam("dsId", repositoryId) From 40aae5d750622b65b358ce45d2723d24d1d97525 Mon Sep 17 00:00:00 2001 From: LSmyrnaios Date: Wed, 25 Jan 2023 14:05:30 +0200 Subject: [PATCH 13/29] Adjust logging-levels. --- src/main/resources/log4j2.xml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml index a98fd99..2e6c355 100644 --- a/src/main/resources/log4j2.xml +++ b/src/main/resources/log4j2.xml @@ -9,7 +9,13 @@ - + + + + + + + From b9cde0f1a9ba3eb5ac41282d9df1a6cc3e8e8dbc Mon Sep 17 00:00:00 2001 From: LSmyrnaios Date: Mon, 30 Jan 2023 13:44:15 +0200 Subject: [PATCH 14/29] Fix "SolrServerException: Server refused connection", during startup. --- pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pom.xml b/pom.xml index 5b76779..5b4727b 100644 --- a/pom.xml +++ b/pom.xml @@ -64,6 +64,11 @@ h2 + + org.apache.solr + solr-solrj + 9.1.1 + eu.dnetlib.dhp From 97d81ce4787cddbb991b1469e72eb6a70ed95b5f Mon Sep 17 00:00:00 2001 From: LSmyrnaios Date: Mon, 30 Jan 2023 15:31:06 +0200 Subject: [PATCH 15/29] - Add missing repositories in pom.xml. - Update README.md --- README.md | 2 +- pom.xml | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5ca50b9..41091f1 100644 --- a/README.md +++ b/README.md @@ -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 -s ` +- Build the app with: `mvn clean install` - Run the app with: `java -jar ./target/uoa-repository-manager-service.jar` diff --git a/pom.xml b/pom.xml index 5b4727b..6e4c908 100644 --- a/pom.xml +++ b/pom.xml @@ -367,6 +367,30 @@ + + dnet45-bootstrap-snapshot + D-Net 45 Bootstrap Snapshot + https://maven.research-infrastructures.eu/nexus/content/repositories/dnet45-bootstrap-snapshot + + false + + + true + + default + + + dnet45-bootstrap-release + D-Net 45 Bootstrap Release + https://maven.research-infrastructures.eu/nexus/content/repositories/dnet45-bootstrap-release + + true + + + false + + default + dnet-deps dnet-dependencies From de2ac5631fad38f35eda72d37b206c1161b51e1e Mon Sep 17 00:00:00 2001 From: LSmyrnaios Date: Mon, 30 Jan 2023 16:25:21 +0200 Subject: [PATCH 16/29] Fix return object of "getUrlsOfUserRepos" endpoint. --- .../dnetlib/repo/manager/service/RepositoryServiceImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java index 4ce000e..666536b 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java @@ -704,8 +704,8 @@ public class RepositoryServiceImpl implements RepositoryService { RequestFilter requestFilter = new RequestFilter(); requestFilter.setRegisteredby(userEmail); - Object result = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String[].class); - return (result != null) ? Collections.singletonList(result.toString()) : null; + String[] result = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String[].class); + return (result != null) ? Arrays.asList(result) : null; } private Vocabulary getVocabulary(String vocName) { From d3bcea79c03ad4133d8b57390aab8f7fc203810a Mon Sep 17 00:00:00 2001 From: Konstantinos Spyrou Date: Mon, 30 Jan 2023 18:56:34 +0200 Subject: [PATCH 17/29] Changes: 1. refactored method signatures 2. used desired compatibility level for 'Guidelines' field in emails 3. enabled async error logs --- .../manager/config/AsyncConfiguration.java | 2 +- .../controllers/RepositoryController.java | 23 +++--- .../repo/manager/service/EmailUtils.java | 25 +++--- .../repo/manager/service/EmailUtilsImpl.java | 77 ++++++++++--------- .../service/InterfaceComplianceService.java | 3 +- .../manager/service/RepositoryService.java | 20 ++--- .../service/RepositoryServiceImpl.java | 29 ++++--- .../manager/service/ValidatorServiceImpl.java | 4 +- 8 files changed, 94 insertions(+), 89 deletions(-) diff --git a/src/main/java/eu/dnetlib/repo/manager/config/AsyncConfiguration.java b/src/main/java/eu/dnetlib/repo/manager/config/AsyncConfiguration.java index e2689eb..5cd225b 100644 --- a/src/main/java/eu/dnetlib/repo/manager/config/AsyncConfiguration.java +++ b/src/main/java/eu/dnetlib/repo/manager/config/AsyncConfiguration.java @@ -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); } }; } diff --git a/src/main/java/eu/dnetlib/repo/manager/controllers/RepositoryController.java b/src/main/java/eu/dnetlib/repo/manager/controllers/RepositoryController.java index 9112339..7712547 100644 --- a/src/main/java/eu/dnetlib/repo/manager/controllers/RepositoryController.java +++ b/src/main/java/eu/dnetlib/repo/manager/controllers/RepositoryController.java @@ -26,7 +26,6 @@ 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; @@ -63,7 +62,7 @@ public class RepositoryController { @ResponseBody public List getRepositoriesByCountry(@PathVariable("country") String country, @PathVariable("mode") String mode, - @RequestParam(value = "managed", required = false) Boolean managed) throws JSONException, IOException { + @RequestParam(value = "managed", required = false) Boolean managed) { return repositoryService.getRepositoriesByCountry(country, mode, managed); } @@ -83,7 +82,7 @@ public class RepositoryController { public void updateRepositoriesTerms(@RequestBody List 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()); @@ -104,7 +103,7 @@ public class RepositoryController { @RequestParam("requestSortBy") String requestSortBy, @RequestParam("order") String order, @PathVariable("page") int page, - @PathVariable("size") int pageSize) throws Exception { + @PathVariable("size") int pageSize) { return repositoryService.searchRegisteredRepositories(country, typology, englishName, officialName, requestSortBy, order, page, pageSize); } @@ -113,13 +112,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 JSONException, ResourceNotFoundException { + public Repository getRepositoryById(@PathVariable("id") String id) throws ResourceNotFoundException { Repository repo = repositoryService.getRepositoryById(id); if (repo != null) - logger.info("Returning repository " + repo.getId() + " registered by " + repo.getRegisteredby()); + logger.info("Returning repository {} registered by {}", repo.getId(), repo.getRegisteredby()); else - logger.info("Requested repository " + id + " not found"); + logger.info("Requested repository {} not found", id); return repo; } @@ -142,7 +141,7 @@ public class RepositoryController { @ResponseBody public List getRepositoriesByName(@PathVariable("name") String name, @PathVariable("page") String page, - @PathVariable("size") String size) throws JSONException { + @PathVariable("size") String size) { return repositoryService.getRepositoriesByName(name, page, size); } @@ -150,7 +149,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 getRepositoryInterface(@PathVariable("id") String id) throws JSONException { + public List getRepositoryInterface(@PathVariable("id") String id) { return repositoryService.getRepositoryInterface(id); } @@ -160,7 +159,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) throws Exception { + @RequestBody Repository repository) { return repositoryService.addRepository(datatype, repository); } @@ -193,7 +192,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) throws Exception { + public Repository updateRepository(@RequestBody Repository repository, Authentication authentication) { return repositoryService.updateRepository(repository, authentication); } @@ -261,7 +260,7 @@ public class RepositoryController { @RequestMapping(value = "/getListLatestUpdate/{mode}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody - public Map getListLatestUpdate(@PathVariable("mode") String mode) throws JSONException { + public Map getListLatestUpdate(@PathVariable("mode") String mode) { return repositoryService.getListLatestUpdate(mode); } diff --git a/src/main/java/eu/dnetlib/repo/manager/service/EmailUtils.java b/src/main/java/eu/dnetlib/repo/manager/service/EmailUtils.java index fed2c64..ddfdb9d 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/EmailUtils.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/EmailUtils.java @@ -32,38 +32,38 @@ public interface EmailUtils { void sendUserRegistrationEmail(Repository repository, Authentication authentication); @Async - void sendAdminRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication); + void sendAdminRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, String desiredCompatibility, Authentication authentication); @Async - void sendUserRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication); + void sendUserRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, String desiredCompatibility, Authentication authentication); /****SUCCESSFUL REGISTRATION RESULTS EMAILS****/ @Async - void sendUserRegistrationResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication); + void sendUserRegistrationResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication); @Async - void sendAdminRegistrationResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication); + void sendAdminRegistrationResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication); /****FAILURE REGISTRATION RESULTS EMAILS****/ @Async - void sendUserRegistrationResultsFailureEmail(String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication); + void sendUserRegistrationResultsFailureEmail(String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication); @Async - void sendAdminRegistrationResultsFailureEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication); + void sendAdminRegistrationResultsFailureEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication); /****SUCCESSFUL UPDATE RESULTS EMAILS****/ @Async - void sendUserUpdateResultsSuccessEmail(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication); + void sendUserUpdateResultsSuccessEmail(String issuer, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication); @Async - void sendAdminUpdateResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication); + void sendAdminUpdateResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication); /****FAILURE UPDATE RESULTS EMAILS****/ @Async - void sendUserUpdateResultsFailureEmail(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication); + void sendUserUpdateResultsFailureEmail(String issuer, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication); @Async - void sendAdminUpdateResultsFailureEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication); + void sendAdminUpdateResultsFailureEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, 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, Authentication authentication); + void sendAdminUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, String desiredCompatibility, Authentication authentication); @Async - void sendUserUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication); + void sendUserUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, String desiredCompatibility, Authentication authentication); @Async void sendSubmitJobForValidationEmail(Authentication authentication, JobForValidation jobForValidation); @@ -102,6 +102,7 @@ public interface EmailUtils { @Async void sendUponJobCompletion(String repoId, String repoInterfaceId, + String compatibility, int scoreUsage, int scoreContent, boolean isSuccess, diff --git a/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java index 6fc7ce8..137ca74 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java @@ -12,6 +12,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.scheduling.annotation.Async; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Component; @@ -21,6 +22,7 @@ import java.util.List; import java.util.stream.Collectors; @Component("emailUtils") +@Async public class EmailUtilsImpl implements EmailUtils { private final static Logger logger = LoggerFactory.getLogger(EmailUtilsImpl.class); @@ -203,7 +205,7 @@ public class EmailUtilsImpl implements EmailUtils { } @Override - public void sendAdminRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) { + public void sendAdminRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, String desiredCompatibility, Authentication authentication) { try { String subject = "OpenAIRE new interface registration request started for " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; @@ -212,7 +214,7 @@ public class EmailUtilsImpl implements EmailUtils { "We received a request to add the following interface: \n\n" + "Base URL: " + repositoryInterface.getBaseurl() + "\n" + "Set: " + repositoryInterface.getAccessSet() + "\n" + - "Guidelines: " + repositoryInterface.getCompatibilityOverride() + "\n\n" + + "Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibility() + "\n\n" + "to " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n"; if (comment != null) @@ -235,7 +237,7 @@ public class EmailUtilsImpl implements EmailUtils { } @Override - public void sendUserRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) { + public void sendUserRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, String desiredCompatibility, Authentication authentication) { try { String subject = "OpenAIRE new interface registration request started for " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; @@ -243,7 +245,7 @@ public class EmailUtilsImpl implements EmailUtils { "We received a request to add the following interface: \n\n" + "Base URL: " + repositoryInterface.getBaseurl() + "\n" + "Set: " + repositoryInterface.getAccessSet() + "\n" + - "Guidelines: " + repositoryInterface.getCompatibilityOverride() + "\n\n" + + "Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibility() + "\n\n" + "to " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n"; if (comment != null) { @@ -265,7 +267,7 @@ public class EmailUtilsImpl implements EmailUtils { } @Override - public void sendUserRegistrationResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) { + public void sendUserRegistrationResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication) { try { String subject = "OpenAIRE new interface registration request - results (success) for " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; @@ -279,7 +281,7 @@ public class EmailUtilsImpl implements EmailUtils { "\nOfficial Name:" + repository.getOfficialname() + "\n\nBase URL: " + repositoryInterface.getBaseurl() + "\n\nValidation Set: " + repositoryInterface.getAccessSet() + - "\n\nGuidelines: " + repositoryInterface.getCompatibilityOverride() + + "\n\nGuidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibility() + "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + "\n\n\nPlease do not reply to this email\n" + "This message has been generated manually\n\n" + @@ -294,7 +296,7 @@ public class EmailUtilsImpl implements EmailUtils { } @Override - public void sendAdminRegistrationResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) { + public void sendAdminRegistrationResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication) { try { String subject = "OpenAIRE new interface registration request - results (success) for " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; @@ -308,7 +310,7 @@ public class EmailUtilsImpl implements EmailUtils { "\nOfficial Name:" + repository.getOfficialname() + "\n\nBase URL: " + repositoryInterface.getBaseurl() + "\n\nValidation Set: " + repositoryInterface.getAccessSet() + - "\n\nGuidelines: " + repositoryInterface.getCompatibilityOverride() + + "\n\nDesired Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibility() + "\n\nUser Contact:" + issuerEmail + "" + "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + "\n\n\nPlease do not reply to this email\n" + @@ -324,7 +326,7 @@ public class EmailUtilsImpl implements EmailUtils { } @Override - public void sendUserRegistrationResultsFailureEmail(String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) { + public void sendUserRegistrationResultsFailureEmail(String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication) { try { String subject = "OpenAIRE new interface registration request - results (failure) for " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; @@ -337,7 +339,7 @@ public class EmailUtilsImpl implements EmailUtils { "\nOfficial Name:" + repository.getOfficialname() + "\n\nBase URL: " + repositoryInterface.getBaseurl() + "\n\nValidation Set: " + repositoryInterface.getAccessSet() + - "\n\nGuidelines: " + repositoryInterface.getCompatibilityOverride() + + "\n\nGuidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibility() + "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + "\n\n\nPlease do not reply to this email\n" + "This message has been generated manually\n\n" + @@ -352,7 +354,7 @@ public class EmailUtilsImpl implements EmailUtils { } @Override - public void sendAdminRegistrationResultsFailureEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) { + public void sendAdminRegistrationResultsFailureEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication) { try { String subject = "OpenAIRE new interface registration request - results (failure) for " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; @@ -366,7 +368,7 @@ public class EmailUtilsImpl implements EmailUtils { "\nOfficial Name:" + repository.getOfficialname() + "\n\nBase URL: " + repositoryInterface.getBaseurl() + "\n\nValidation Set: " + repositoryInterface.getAccessSet() + - "\n\nGuidelines: " + repositoryInterface.getCompatibilityOverride() + + "\n\nGuidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibility() + "\n\nUser Contact:" + issuerEmail + "" + "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + "\n\n\nPlease do not reply to this email\n" + @@ -382,7 +384,7 @@ public class EmailUtilsImpl implements EmailUtils { } @Override - public void sendUserUpdateResultsSuccessEmail(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) { + public void sendUserUpdateResultsSuccessEmail(String issuer, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication) { try { String subject = "OpenAIRE interface update request - results (success) for " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; @@ -394,7 +396,7 @@ public class EmailUtilsImpl implements EmailUtils { "\nOfficial Name:" + repository.getOfficialname() + "\n\nBase URL: " + repositoryInterface.getBaseurl() + "\n\nValidation Set: " + repositoryInterface.getAccessSet() + - "\n\nGuidelines: " + repositoryInterface.getCompatibilityOverride() + + "\n\nGuidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibility() + "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + "\n\n\nPlease do not reply to this email\n" + "This message has been generated manually\n\n" + @@ -409,7 +411,7 @@ public class EmailUtilsImpl implements EmailUtils { } @Override - public void sendAdminUpdateResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) { + public void sendAdminUpdateResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication) { try { String subject = "OpenAIRE interface update request - results (success) for " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; @@ -421,7 +423,7 @@ public class EmailUtilsImpl implements EmailUtils { "\nOfficial Name:" + repository.getOfficialname() + "\n\nBase URL: " + repositoryInterface.getBaseurl() + "\n\nValidation Set: " + repositoryInterface.getAccessSet() + - "\n\nGuidelines: " + repositoryInterface.getCompatibilityOverride() + + "\n\nGuidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibility() + "\n\nUser Contact:" + issuerEmail + "" + "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + "\n\n\nPlease do not reply to this email\n" + @@ -437,7 +439,7 @@ public class EmailUtilsImpl implements EmailUtils { } @Override - public void sendUserUpdateResultsFailureEmail(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) { + public void sendUserUpdateResultsFailureEmail(String issuer, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication) { try { String subject = "OpenAIRE interface update request - results (failure) for " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; @@ -451,7 +453,7 @@ public class EmailUtilsImpl implements EmailUtils { "\nOfficial Name:" + repository.getOfficialname() + "\n\nBase URL: " + repositoryInterface.getBaseurl() + "\n\nValidation Set: " + repositoryInterface.getAccessSet() + - "\n\nGuidelines: " + repositoryInterface.getCompatibilityOverride() + + "\n\nGuidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibility() + "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + "\n\n\nPlease do not reply to this email\n" + "This message has been generated manually\n\n" + @@ -466,7 +468,7 @@ public class EmailUtilsImpl implements EmailUtils { } @Override - public void sendAdminUpdateResultsFailureEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) { + public void sendAdminUpdateResultsFailureEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication) { try { String subject = "OpenAIRE interface update request - results (failure) for " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; @@ -480,7 +482,7 @@ public class EmailUtilsImpl implements EmailUtils { "\nOfficial Name:" + repository.getOfficialname() + "\n\nBase URL: " + repositoryInterface.getBaseurl() + "\n\nValidation Set: " + repositoryInterface.getAccessSet() + - "\n\nGuidelines: " + repositoryInterface.getCompatibilityOverride() + + "\n\nGuidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibility() + "\n\nUser Contact:" + issuerEmail + "" + "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + "\n\n\nPlease do not reply to this email\n" + @@ -596,8 +598,11 @@ public class EmailUtilsImpl implements EmailUtils { String subject = "OpenAIRE validator - job failure"; String message = - "the validation job that was automatically submitted for the update/registration of the interface " + repositoryInterface.getId() + " (" + repositoryInterface.getBaseurl() + ", " + repositoryInterface.getAccessSet() + ") of the repository " + repository.getId() + " (" + repository.getOfficialname() + ") failed to complete." + - "This message has been generated automatically."; + "the validation job that was automatically submitted for the update/registration of the interface " + + repositoryInterface.getId() + " (" + repositoryInterface.getBaseurl() + ", " + + repositoryInterface.getAccessSet() + ") of the repository " + repository.getId() + + " (" + repository.getOfficialname() + ") failed to complete." + + "This message has been generated automatically."; message = createAdminMail(message); this.sendMail(this.provideAdminEmail, subject, message); @@ -614,7 +619,8 @@ public class EmailUtilsImpl implements EmailUtils { repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; String message = - "We received a request to update the basic information for " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n\n" + + "We received a request to update the basic information for " + repository.getEoscDatasourceType() + + "[" + repository.getOfficialname() + "].\n\n" + "Please do not reply to this message\n" + "This message has been generated automatically."; message = createAdminMail(message); @@ -647,7 +653,7 @@ public class EmailUtilsImpl implements EmailUtils { } @Override - public void sendAdminUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) { + public void sendAdminUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, String desiredCompatibility, Authentication authentication) { try { String subject = "OpenAIRE interface update request started for " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; @@ -656,7 +662,7 @@ public class EmailUtilsImpl implements EmailUtils { "We received a request to update the following interface: \n\n" + "Base URL: " + repositoryInterface.getBaseurl() + "\n" + "Set: " + repositoryInterface.getAccessSet() + "\n" + - "Guidelines: " + repositoryInterface.getCompatibilityOverride() + "\n\n" + + "Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibility() + "\n\n" + "for " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n"; if (comment != null) @@ -677,7 +683,7 @@ public class EmailUtilsImpl implements EmailUtils { } @Override - public void sendUserUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) { + public void sendUserUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, String desiredCompatibility, Authentication authentication) { try { String subject = "OpenAIRE interface update request started for " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; @@ -686,7 +692,7 @@ public class EmailUtilsImpl implements EmailUtils { "We received a request to update the following interface: \n\n" + "Base URL: " + repositoryInterface.getBaseurl() + "\n" + "Set: " + repositoryInterface.getAccessSet() + "\n" + - "Guidelines: " + repositoryInterface.getCompatibilityOverride() + "\n\n" + + "Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibility() + "\n\n" + "for " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n"; if (comment != null) { @@ -729,6 +735,7 @@ public class EmailUtilsImpl implements EmailUtils { public void sendUponJobCompletion( String repoId, String repoInterfaceId, + String compatibility, int scoreUsage, int scoreContent, boolean isSuccess, @@ -745,11 +752,11 @@ public class EmailUtilsImpl implements EmailUtils { if (!isUpdate) { if (isSuccess) { if (scoreContent >= 50 && scoreUsage >= 50) { - this.sendUserRegistrationResultsSuccessEmail(issuerEmail, jobId, repositoryInterface, repository, SecurityContextHolder.getContext().getAuthentication()); - this.sendAdminRegistrationResultsSuccessEmail(issuerEmail, jobId, repositoryInterface, repository, SecurityContextHolder.getContext().getAuthentication()); + this.sendUserRegistrationResultsSuccessEmail(issuerEmail, jobId, repositoryInterface, compatibility, repository, SecurityContextHolder.getContext().getAuthentication()); + this.sendAdminRegistrationResultsSuccessEmail(issuerEmail, jobId, repositoryInterface, compatibility, repository, SecurityContextHolder.getContext().getAuthentication()); } else { - this.sendUserRegistrationResultsFailureEmail(jobId, repositoryInterface, repository, SecurityContextHolder.getContext().getAuthentication()); - this.sendAdminRegistrationResultsFailureEmail(issuerEmail, jobId, repositoryInterface, repository, SecurityContextHolder.getContext().getAuthentication()); + this.sendUserRegistrationResultsFailureEmail(jobId, repositoryInterface, compatibility, repository, SecurityContextHolder.getContext().getAuthentication()); + this.sendAdminRegistrationResultsFailureEmail(issuerEmail, jobId, repositoryInterface, compatibility, repository, SecurityContextHolder.getContext().getAuthentication()); } } else { this.sendAdminGeneralFailure(issuerEmail, jobId, repositoryInterface, repository, SecurityContextHolder.getContext().getAuthentication()); @@ -757,11 +764,11 @@ public class EmailUtilsImpl implements EmailUtils { } else { if (isSuccess) { if (scoreContent >= 50 && scoreUsage >= 50) { - this.sendUserUpdateResultsSuccessEmail(issuerEmail, jobId, repositoryInterface, repository, SecurityContextHolder.getContext().getAuthentication()); - this.sendAdminUpdateResultsSuccessEmail(issuerEmail, jobId, repositoryInterface, repository, SecurityContextHolder.getContext().getAuthentication()); + this.sendUserUpdateResultsSuccessEmail(issuerEmail, jobId, repositoryInterface, compatibility, repository, SecurityContextHolder.getContext().getAuthentication()); + this.sendAdminUpdateResultsSuccessEmail(issuerEmail, jobId, repositoryInterface, compatibility, repository, SecurityContextHolder.getContext().getAuthentication()); } else { - this.sendUserUpdateResultsFailureEmail(issuerEmail, jobId, repositoryInterface, repository, SecurityContextHolder.getContext().getAuthentication()); - this.sendAdminUpdateResultsFailureEmail(issuerEmail, jobId, repositoryInterface, repository, SecurityContextHolder.getContext().getAuthentication()); + this.sendUserUpdateResultsFailureEmail(issuerEmail, jobId, repositoryInterface, compatibility, repository, SecurityContextHolder.getContext().getAuthentication()); + this.sendAdminUpdateResultsFailureEmail(issuerEmail, jobId, repositoryInterface, compatibility, repository, SecurityContextHolder.getContext().getAuthentication()); } } else { this.sendAdminGeneralFailure(issuerEmail, jobId, repositoryInterface, repository, SecurityContextHolder.getContext().getAuthentication()); diff --git a/src/main/java/eu/dnetlib/repo/manager/service/InterfaceComplianceService.java b/src/main/java/eu/dnetlib/repo/manager/service/InterfaceComplianceService.java index db72fea..df414b2 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/InterfaceComplianceService.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/InterfaceComplianceService.java @@ -6,7 +6,6 @@ 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; @@ -50,7 +49,7 @@ public class InterfaceComplianceService { List repositoryAdmins = authorizationService.getAdminsOfRepo(request.getRepositoryId()); emailUtils.sendUserUpdateInterfaceComplianceFailure(repositoryAdmins.stream().map(User::getEmail).collect(Collectors.toList()), repo, iFace, request); emailUtils.sendAdminUpdateInterfaceComplianceFailure(repo, iFace, request); - } catch (JSONException | ResourceNotFoundException e) { + } catch (ResourceNotFoundException e) { logger.error("Error", e); } } diff --git a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryService.java b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryService.java index 4235064..0cd4288 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryService.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryService.java @@ -16,15 +16,15 @@ public interface RepositoryService { // TODO: move this elsewhere Country[] getCountries(); - List getRepositories(List ids) throws JSONException; + List getRepositories(List ids); - List getRepositories(List ids, int page, int size) throws JSONException; + List getRepositories(List ids, int page, int size); List getRepositoriesSnippets(List ids) throws Exception; List getRepositoriesSnippets(List ids, int page, int size) throws Exception; - List getRepositoriesByCountry(String country, String mode, Boolean managed) throws JSONException, IOException; + List getRepositoriesByCountry(String country, String mode, Boolean managed); // TODO: remove? List getRepositoriesOfUser(String page, String size) throws JSONException, IOException; @@ -38,23 +38,23 @@ public interface RepositoryService { List getRepositoriesSnippetsOfUser(String userEmail, String page, String size) throws Exception; - RepositorySnippet getRepositorySnippetById(String id) throws JSONException, ResourceNotFoundException; + RepositorySnippet getRepositorySnippetById(String id) throws ResourceNotFoundException; - Repository getRepositoryById(String id) throws JSONException, ResourceNotFoundException; + Repository getRepositoryById(String id) throws ResourceNotFoundException; List getRepositoriesByName(String name, String page, - String size) throws JSONException; + String size); List searchRegisteredRepositories(String country, String typology, String englishName, String officialName, String requestSortBy, String order, - int page, int pageSize) throws Exception; + int page, int pageSize); Integer getTotalRegisteredRepositories(); - List getRepositoryInterface(String id) throws JSONException; + List getRepositoryInterface(String id); - Repository addRepository(String datatype, Repository repository) throws Exception; + Repository addRepository(String datatype, Repository repository); void deleteRepositoryInterface(String id, String registeredBy); @@ -70,7 +70,7 @@ public interface RepositoryService { List getTimezones(); - Repository updateRepository(Repository repository, Authentication authentication) throws Exception; + Repository updateRepository(Repository repository, Authentication authentication); List getUrlsOfUserRepos(String user_email, String page, diff --git a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java index 666536b..63bef35 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java @@ -21,7 +21,6 @@ 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; @@ -40,7 +39,6 @@ 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; @@ -92,7 +90,6 @@ public class RepositoryServiceImpl implements RepositoryService { VocabularyLoader vocabularyLoader, RestTemplate restTemplate, ObjectMapper objectMapper, -// Converter converter, @Lazy EmailUtils emailUtils, @Lazy ValidatorService validatorService, @Lazy PiWikService piWikService, @@ -161,7 +158,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 getRepositories(List ids) throws JSONException { + public List getRepositories(List ids) { return getRepositories(ids, 0, 10); } @@ -233,7 +230,7 @@ public class RepositoryServiceImpl implements RepositoryService { @Override public List getRepositoriesByCountry(String country, String mode, - Boolean managed) throws IOException { + Boolean managed) { logger.debug("Getting repositories by country!"); int page = 0; int size = 100; @@ -256,7 +253,7 @@ public class RepositoryServiceImpl implements RepositoryService { } public List searchRegisteredRepositories(String country, String typology, String englishName, - String officialName, String requestSortBy, String order, int page, int pageSize) throws Exception { + String officialName, String requestSortBy, String order, int page, int pageSize) { logger.debug("Searching registered repositories"); @@ -289,7 +286,7 @@ public class RepositoryServiceImpl implements RepositoryService { } @Override - public List getRepositoriesOfUser(String page, String size) throws JSONException { + public List getRepositoriesOfUser(String page, String size) { logger.debug("Retrieving repositories of authenticated user : {}", ((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail()); Collection repoIds = roleMappingService.getRepoIdsByRoleIds(authorizationService.getUserRoles()); @@ -297,7 +294,7 @@ public class RepositoryServiceImpl implements RepositoryService { } @Override - public List getRepositoriesOfUser(String userEmail, String page, String size) throws JSONException { + public List getRepositoriesOfUser(String userEmail, String page, String size) { logger.debug("Retrieving repositories of authenticated user : {}", userEmail); Collection repoIds = roleMappingService.getRepoIdsByRoleIds(authorizationService.getUserRolesByEmail(userEmail)); return getRepositories(new ArrayList<>(repoIds)); @@ -363,7 +360,7 @@ public class RepositoryServiceImpl implements RepositoryService { @Override public List getRepositoriesByName(String name, String page, - String size) throws JSONException { + String size) { logger.debug("Retrieving repositories with official name : {}", name); UriComponents uriComponents = searchDatasourceUri("0", "100"); @@ -402,7 +399,7 @@ public class RepositoryServiceImpl implements RepositoryService { } @Override - public Repository addRepository(String datatype, Repository repository) throws Exception { + public Repository addRepository(String datatype, Repository repository) { logger.debug("storing '{}' repository with id: {}", datatype, repository.getId()); @@ -486,7 +483,7 @@ public class RepositoryServiceImpl implements RepositoryService { } @Override - public Repository updateRepository(Repository repository, Authentication authentication) throws Exception { + public Repository updateRepository(Repository repository, Authentication authentication) { UriComponents uriComponents = UriComponentsBuilder .fromHttpUrl(baseAddress + "/ds/update/") .build() @@ -507,7 +504,7 @@ public class RepositoryServiceImpl implements RepositoryService { return repository; } - private void storeRepository(Repository repository, Authentication authentication) throws Exception { + private void storeRepository(Repository repository, Authentication authentication) { Date utilDate = new Date(); Timestamp date = new Timestamp(utilDate.getTime()); @@ -564,8 +561,8 @@ 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(e, comment, repositoryInterface, authentication); - emailUtils.sendUserRegisterInterfaceEmail(e, comment, repositoryInterface, authentication); + emailUtils.sendAdminRegisterInterfaceEmail(e, comment, repositoryInterface, desiredCompatibilityLevel, authentication); + emailUtils.sendUserRegisterInterfaceEmail(e, comment, repositoryInterface, desiredCompatibilityLevel, authentication); if (desiredCompatibilityLevel != null && (repositoryInterface.getCompatibility() == null || !repositoryInterface.getCompatibility().equals(desiredCompatibilityLevel))) { InterfaceComplianceRequest request = new InterfaceComplianceRequest(repoId, repositoryInterface.getId(), desiredCompatibilityLevel); @@ -593,8 +590,8 @@ public class RepositoryServiceImpl implements RepositoryService { this.updateValidationSet(repoId, repositoryInterface.getId(), repositoryInterface.getAccessSet()); - emailUtils.sendAdminUpdateInterfaceEmail(repository, comment, repositoryInterface, authentication); - emailUtils.sendUserUpdateInterfaceEmail(repository, comment, repositoryInterface, authentication); + emailUtils.sendAdminUpdateInterfaceEmail(repository, comment, repositoryInterface, desiredCompatibilityLevel, authentication); + emailUtils.sendUserUpdateInterfaceEmail(repository, comment, repositoryInterface, desiredCompatibilityLevel, authentication); if (desiredCompatibilityLevel != null && (repositoryInterface.getCompatibility() == null || !repositoryInterface.getCompatibility().equals(desiredCompatibilityLevel))) { InterfaceComplianceRequest request = new InterfaceComplianceRequest(repoId, repositoryInterface.getId(), desiredCompatibilityLevel); diff --git a/src/main/java/eu/dnetlib/repo/manager/service/ValidatorServiceImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/ValidatorServiceImpl.java index 908090c..34805c0 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/ValidatorServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/ValidatorServiceImpl.java @@ -310,10 +310,11 @@ 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 request = interfaceComplianceService.getById(requestId); + String compatibility = null; if (request.isPresent()) { + compatibility = request.get().getDesiredCompatibilityLevel(); logger.info("Changing compatibility level. Request: {}", request); if (scoreContent > 50) { @@ -321,6 +322,7 @@ public class ValidatorServiceImpl implements ValidatorService { } interfaceComplianceService.delete(requestId); } + emailUtils.sendUponJobCompletion(repoId,interfaceId,compatibility,scoreUsage,scoreContent,isSuccess,isUpdate,issuerEmail, jobId); } } From 287f476bd2c96b5fb91983ed89cdfbca0c6f61fc Mon Sep 17 00:00:00 2001 From: Konstantinos Spyrou Date: Mon, 30 Jan 2023 19:49:33 +0200 Subject: [PATCH 18/29] messages sent to 'registeredBy' email are now sent to the currently authenticated user as well --- .../repo/manager/service/EmailUtilsImpl.java | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java index 137ca74..a4db326 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java @@ -5,6 +5,7 @@ import eu.dnetlib.domain.functionality.validator.JobForValidation; import eu.dnetlib.repo.manager.domain.InterfaceComplianceRequest; import eu.dnetlib.repo.manager.domain.Repository; import eu.dnetlib.repo.manager.domain.RepositoryInterface; +import eu.dnetlib.repo.manager.domain.dto.User; import eu.dnetlib.repo.manager.exception.ValidationServiceException; import eu.dnetlib.utils.MailLibrary; import org.mitre.openid.connect.model.OIDCAuthenticationToken; @@ -17,8 +18,7 @@ import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Component; -import java.util.Collections; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; @Component("emailUtils") @@ -259,7 +259,12 @@ public class EmailUtilsImpl implements EmailUtils { "This message has been generated automatically."; message = createUserMail(message, authentication); - this.sendMail(repository.getRegisteredby(), subject, message); + Collection emailTo = new HashSet<>(); + if (repository.getRegisteredby() != null) { + emailTo.add(repository.getRegisteredby()); + } + emailTo.add(User.from(((OIDCAuthenticationToken) authentication).getUserInfo()).getEmail()); + this.sendMail(emailTo, subject, message); } catch (Exception e) { logger.error("Error while sending registration of interface notification email to user: " + repository.getRegisteredby(), e); @@ -288,7 +293,12 @@ public class EmailUtilsImpl implements EmailUtils { "If you have any questions, write to 'helpdesk@openaire.eu'."; message = createUserMail(message, authentication); - this.sendMail(repository.getRegisteredby(), subject, message); + Collection emailTo = new HashSet<>(); + if (repository.getRegisteredby() != null) { + emailTo.add(repository.getRegisteredby()); + } + emailTo.add(User.from(((OIDCAuthenticationToken) authentication).getUserInfo()).getEmail()); + this.sendMail(emailTo, subject, message); } catch (Exception e) { logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e); @@ -346,7 +356,12 @@ public class EmailUtilsImpl implements EmailUtils { "If you have any questions, write to 'helpdesk@openaire.eu'."; message = createUserMail(message, authentication); - this.sendMail(repository.getRegisteredby(), subject, message); + Collection emailTo = new HashSet<>(); + if (repository.getRegisteredby() != null) { + emailTo.add(repository.getRegisteredby()); + } + emailTo.add(User.from(((OIDCAuthenticationToken) authentication).getUserInfo()).getEmail()); + this.sendMail(emailTo, subject, message); } catch (Exception e) { logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e); @@ -781,7 +796,7 @@ public class EmailUtilsImpl implements EmailUtils { this.sendMail(Collections.singletonList(email), subject, message); } - public void sendMail(List recipients, String subject, String message) { + public void sendMail(Collection recipients, String subject, String message) { try { logger.debug("Sending e-mail\nRecipients: {}\nSubject: {}\nMessage: {}", recipients, subject, message); mailLibrary.sendEmail(recipients.toArray(new String[]{}), subject, message); From 699b45d62fae497f4a5c5e4d16e7850524a32b6a Mon Sep 17 00:00:00 2001 From: Konstantinos Spyrou Date: Mon, 30 Jan 2023 20:04:11 +0200 Subject: [PATCH 19/29] Missed 3 methods in previous commit. Needs heavy refactoring.. --- .../repo/manager/service/EmailUtilsImpl.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java index a4db326..30d7301 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java @@ -580,7 +580,12 @@ public class EmailUtilsImpl implements EmailUtils { "If you have any questions, write to 'helpdesk@openaire.eu'."; message = createUserMail(message, authentication); - this.sendMail(issuer, subject, message); + Collection emailTo = new HashSet<>(); + if (repository.getRegisteredby() != null) { + emailTo.add(repository.getRegisteredby()); + } + emailTo.add(User.from(((OIDCAuthenticationToken) authentication).getUserInfo()).getEmail()); + this.sendMail(emailTo, subject, message); } catch (Exception e) { logger.error("Error while sending validation submission notification email to user: " + issuer, e); @@ -660,7 +665,12 @@ public class EmailUtilsImpl implements EmailUtils { "If you have any questions, write to 'helpdesk@openaire.eu'."; message = createUserMail(message, authentication); - this.sendMail(repository.getRegisteredby(), subject, message); + Collection emailTo = new HashSet<>(); + if (repository.getRegisteredby() != null) { + emailTo.add(repository.getRegisteredby()); + } + emailTo.add(User.from(((OIDCAuthenticationToken) authentication).getUserInfo()).getEmail()); + this.sendMail(emailTo, subject, message); } catch (Exception e) { logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e); @@ -720,7 +730,12 @@ public class EmailUtilsImpl implements EmailUtils { "If you have any questions, write to 'helpdesk@openaire.eu'."; message = createUserMail(message, authentication); - this.sendMail(repository.getRegisteredby(), subject, message); + Collection emailTo = new HashSet<>(); + if (repository.getRegisteredby() != null) { + emailTo.add(repository.getRegisteredby()); + } + emailTo.add(User.from(((OIDCAuthenticationToken) authentication).getUserInfo()).getEmail()); + this.sendMail(emailTo, subject, message); } catch (Exception e) { logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e); From 60f8c8cb82765ae465bbcaa4680019e19ed4a410 Mon Sep 17 00:00:00 2001 From: Konstantinos Spyrou Date: Tue, 31 Jan 2023 12:11:41 +0200 Subject: [PATCH 20/29] use Compatibility Override field --- .../repo/manager/service/EmailUtilsImpl.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java index 30d7301..ac47442 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java @@ -214,7 +214,7 @@ public class EmailUtilsImpl implements EmailUtils { "We received a request to add the following interface: \n\n" + "Base URL: " + repositoryInterface.getBaseurl() + "\n" + "Set: " + repositoryInterface.getAccessSet() + "\n" + - "Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibility() + "\n\n" + + "Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + "\n\n" + "to " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n"; if (comment != null) @@ -245,7 +245,7 @@ public class EmailUtilsImpl implements EmailUtils { "We received a request to add the following interface: \n\n" + "Base URL: " + repositoryInterface.getBaseurl() + "\n" + "Set: " + repositoryInterface.getAccessSet() + "\n" + - "Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibility() + "\n\n" + + "Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + "\n\n" + "to " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n"; if (comment != null) { @@ -286,7 +286,7 @@ public class EmailUtilsImpl implements EmailUtils { "\nOfficial Name:" + repository.getOfficialname() + "\n\nBase URL: " + repositoryInterface.getBaseurl() + "\n\nValidation Set: " + repositoryInterface.getAccessSet() + - "\n\nGuidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibility() + + "\n\nGuidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + "\n\n\nPlease do not reply to this email\n" + "This message has been generated manually\n\n" + @@ -320,7 +320,7 @@ public class EmailUtilsImpl implements EmailUtils { "\nOfficial Name:" + repository.getOfficialname() + "\n\nBase URL: " + repositoryInterface.getBaseurl() + "\n\nValidation Set: " + repositoryInterface.getAccessSet() + - "\n\nDesired Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibility() + + "\n\nDesired Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + "\n\nUser Contact:" + issuerEmail + "" + "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + "\n\n\nPlease do not reply to this email\n" + @@ -349,7 +349,7 @@ public class EmailUtilsImpl implements EmailUtils { "\nOfficial Name:" + repository.getOfficialname() + "\n\nBase URL: " + repositoryInterface.getBaseurl() + "\n\nValidation Set: " + repositoryInterface.getAccessSet() + - "\n\nGuidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibility() + + "\n\nGuidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + "\n\n\nPlease do not reply to this email\n" + "This message has been generated manually\n\n" + @@ -375,7 +375,7 @@ public class EmailUtilsImpl implements EmailUtils { repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; String message = - "the compatibility test on " + "[" + repository.getOfficialname() + "]" + + "the compatibility test on [" + repository.getOfficialname() + "]" + " was not successful and the registration process was interrupted." + "\n\n" + "We will check what caused the problem and get back to you within a couple of days.\n\n" + @@ -383,7 +383,7 @@ public class EmailUtilsImpl implements EmailUtils { "\nOfficial Name:" + repository.getOfficialname() + "\n\nBase URL: " + repositoryInterface.getBaseurl() + "\n\nValidation Set: " + repositoryInterface.getAccessSet() + - "\n\nGuidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibility() + + "\n\nGuidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + "\n\nUser Contact:" + issuerEmail + "" + "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + "\n\n\nPlease do not reply to this email\n" + @@ -411,7 +411,7 @@ public class EmailUtilsImpl implements EmailUtils { "\nOfficial Name:" + repository.getOfficialname() + "\n\nBase URL: " + repositoryInterface.getBaseurl() + "\n\nValidation Set: " + repositoryInterface.getAccessSet() + - "\n\nGuidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibility() + + "\n\nGuidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + "\n\n\nPlease do not reply to this email\n" + "This message has been generated manually\n\n" + @@ -438,7 +438,7 @@ public class EmailUtilsImpl implements EmailUtils { "\nOfficial Name:" + repository.getOfficialname() + "\n\nBase URL: " + repositoryInterface.getBaseurl() + "\n\nValidation Set: " + repositoryInterface.getAccessSet() + - "\n\nGuidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibility() + + "\n\nGuidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + "\n\nUser Contact:" + issuerEmail + "" + "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + "\n\n\nPlease do not reply to this email\n" + @@ -468,7 +468,7 @@ public class EmailUtilsImpl implements EmailUtils { "\nOfficial Name:" + repository.getOfficialname() + "\n\nBase URL: " + repositoryInterface.getBaseurl() + "\n\nValidation Set: " + repositoryInterface.getAccessSet() + - "\n\nGuidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibility() + + "\n\nGuidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + "\n\n\nPlease do not reply to this email\n" + "This message has been generated manually\n\n" + @@ -497,7 +497,7 @@ public class EmailUtilsImpl implements EmailUtils { "\nOfficial Name:" + repository.getOfficialname() + "\n\nBase URL: " + repositoryInterface.getBaseurl() + "\n\nValidation Set: " + repositoryInterface.getAccessSet() + - "\n\nGuidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibility() + + "\n\nGuidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + "\n\nUser Contact:" + issuerEmail + "" + "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + "\n\n\nPlease do not reply to this email\n" + @@ -687,7 +687,7 @@ public class EmailUtilsImpl implements EmailUtils { "We received a request to update the following interface: \n\n" + "Base URL: " + repositoryInterface.getBaseurl() + "\n" + "Set: " + repositoryInterface.getAccessSet() + "\n" + - "Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibility() + "\n\n" + + "Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + "\n\n" + "for " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n"; if (comment != null) @@ -717,7 +717,7 @@ public class EmailUtilsImpl implements EmailUtils { "We received a request to update the following interface: \n\n" + "Base URL: " + repositoryInterface.getBaseurl() + "\n" + "Set: " + repositoryInterface.getAccessSet() + "\n" + - "Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibility() + "\n\n" + + "Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + "\n\n" + "for " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n"; if (comment != null) { From fdd597cf022e01923499bd034fe33f3745bebceb Mon Sep 17 00:00:00 2001 From: Konstantinos Spyrou Date: Tue, 31 Jan 2023 12:25:41 +0200 Subject: [PATCH 21/29] changed 'validation set' to 'set' and 'guidelines' to 'selected guidelines' in message bodies --- .../repo/manager/service/EmailUtilsImpl.java | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java index ac47442..b67231f 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java @@ -214,7 +214,7 @@ public class EmailUtilsImpl implements EmailUtils { "We received a request to add the following interface: \n\n" + "Base URL: " + repositoryInterface.getBaseurl() + "\n" + "Set: " + repositoryInterface.getAccessSet() + "\n" + - "Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + "\n\n" + + "Selected Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + "\n\n" + "to " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n"; if (comment != null) @@ -245,7 +245,7 @@ public class EmailUtilsImpl implements EmailUtils { "We received a request to add the following interface: \n\n" + "Base URL: " + repositoryInterface.getBaseurl() + "\n" + "Set: " + repositoryInterface.getAccessSet() + "\n" + - "Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + "\n\n" + + "Selected Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + "\n\n" + "to " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n"; if (comment != null) { @@ -285,8 +285,8 @@ public class EmailUtilsImpl implements EmailUtils { "Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() + "\nOfficial Name:" + repository.getOfficialname() + "\n\nBase URL: " + repositoryInterface.getBaseurl() + - "\n\nValidation Set: " + repositoryInterface.getAccessSet() + - "\n\nGuidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + + "\n\nSet: " + repositoryInterface.getAccessSet() + + "\n\nSelected Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + "\n\n\nPlease do not reply to this email\n" + "This message has been generated manually\n\n" + @@ -319,8 +319,8 @@ public class EmailUtilsImpl implements EmailUtils { "Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() + "\nOfficial Name:" + repository.getOfficialname() + "\n\nBase URL: " + repositoryInterface.getBaseurl() + - "\n\nValidation Set: " + repositoryInterface.getAccessSet() + - "\n\nDesired Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + + "\n\nSet: " + repositoryInterface.getAccessSet() + + "\n\nDesired Selected Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + "\n\nUser Contact:" + issuerEmail + "" + "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + "\n\n\nPlease do not reply to this email\n" + @@ -348,8 +348,8 @@ public class EmailUtilsImpl implements EmailUtils { "Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() + "\nOfficial Name:" + repository.getOfficialname() + "\n\nBase URL: " + repositoryInterface.getBaseurl() + - "\n\nValidation Set: " + repositoryInterface.getAccessSet() + - "\n\nGuidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + + "\n\nSet: " + repositoryInterface.getAccessSet() + + "\n\nSelected Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + "\n\n\nPlease do not reply to this email\n" + "This message has been generated manually\n\n" + @@ -382,8 +382,8 @@ public class EmailUtilsImpl implements EmailUtils { "Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() + "\nOfficial Name:" + repository.getOfficialname() + "\n\nBase URL: " + repositoryInterface.getBaseurl() + - "\n\nValidation Set: " + repositoryInterface.getAccessSet() + - "\n\nGuidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + + "\n\nSet: " + repositoryInterface.getAccessSet() + + "\n\nSelected Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + "\n\nUser Contact:" + issuerEmail + "" + "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + "\n\n\nPlease do not reply to this email\n" + @@ -410,8 +410,8 @@ public class EmailUtilsImpl implements EmailUtils { "Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() + "\nOfficial Name:" + repository.getOfficialname() + "\n\nBase URL: " + repositoryInterface.getBaseurl() + - "\n\nValidation Set: " + repositoryInterface.getAccessSet() + - "\n\nGuidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + + "\n\nSet: " + repositoryInterface.getAccessSet() + + "\n\nSelected Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + "\n\n\nPlease do not reply to this email\n" + "This message has been generated manually\n\n" + @@ -437,8 +437,8 @@ public class EmailUtilsImpl implements EmailUtils { "Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() + "\nOfficial Name:" + repository.getOfficialname() + "\n\nBase URL: " + repositoryInterface.getBaseurl() + - "\n\nValidation Set: " + repositoryInterface.getAccessSet() + - "\n\nGuidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + + "\n\nSet: " + repositoryInterface.getAccessSet() + + "\n\nSelected Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + "\n\nUser Contact:" + issuerEmail + "" + "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + "\n\n\nPlease do not reply to this email\n" + @@ -467,8 +467,8 @@ public class EmailUtilsImpl implements EmailUtils { "Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() + "\nOfficial Name:" + repository.getOfficialname() + "\n\nBase URL: " + repositoryInterface.getBaseurl() + - "\n\nValidation Set: " + repositoryInterface.getAccessSet() + - "\n\nGuidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + + "\n\nSet: " + repositoryInterface.getAccessSet() + + "\n\nSelected Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + "\n\n\nPlease do not reply to this email\n" + "This message has been generated manually\n\n" + @@ -496,8 +496,8 @@ public class EmailUtilsImpl implements EmailUtils { "Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() + "\nOfficial Name:" + repository.getOfficialname() + "\n\nBase URL: " + repositoryInterface.getBaseurl() + - "\n\nValidation Set: " + repositoryInterface.getAccessSet() + - "\n\nGuidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + + "\n\nSet: " + repositoryInterface.getAccessSet() + + "\n\nSelected Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + "\n\nUser Contact:" + issuerEmail + "" + "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + "\n\n\nPlease do not reply to this email\n" + @@ -526,8 +526,8 @@ public class EmailUtilsImpl implements EmailUtils { "Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() + "\nOfficial Name:" + repository.getOfficialname() + "\n\nBase URL: " + repositoryInterface.getBaseurl() + - "\n\nValidation Set: " + repositoryInterface.getAccessSet() + - "\n\nGuidelines: " + request.getDesiredCompatibilityLevel() + + "\n\nSet: " + repositoryInterface.getAccessSet() + + "\n\nSelected Guidelines: " + request.getDesiredCompatibilityLevel() + "\n\n\nPlease do not reply to this email\n" + "This message has been generated automatically\n\n" + "If you have any questions, write to 'helpdesk@openaire.eu'."; @@ -554,8 +554,8 @@ public class EmailUtilsImpl implements EmailUtils { "Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() + "\nOfficial Name:" + repository.getOfficialname() + "\n\nBase URL: " + repositoryInterface.getBaseurl() + - "\n\nValidation Set: " + repositoryInterface.getAccessSet() + - "\n\nGuidelines: " + request.getDesiredCompatibilityLevel() + + "\n\nSet: " + repositoryInterface.getAccessSet() + + "\n\nSelected Guidelines: " + request.getDesiredCompatibilityLevel() + "\n\n\nPlease do not reply to this email\n" + "This message has been generated automatically\n\n" + "If you have any questions, write to 'helpdesk@openaire.eu'."; @@ -687,7 +687,7 @@ public class EmailUtilsImpl implements EmailUtils { "We received a request to update the following interface: \n\n" + "Base URL: " + repositoryInterface.getBaseurl() + "\n" + "Set: " + repositoryInterface.getAccessSet() + "\n" + - "Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + "\n\n" + + "Selected Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + "\n\n" + "for " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n"; if (comment != null) @@ -717,7 +717,7 @@ public class EmailUtilsImpl implements EmailUtils { "We received a request to update the following interface: \n\n" + "Base URL: " + repositoryInterface.getBaseurl() + "\n" + "Set: " + repositoryInterface.getAccessSet() + "\n" + - "Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + "\n\n" + + "Selected Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + "\n\n" + "for " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n"; if (comment != null) { From 1a3399f7d7483591781717f28fd62cbef1b40f43 Mon Sep 17 00:00:00 2001 From: Konstantinos Spyrou Date: Tue, 31 Jan 2023 14:35:48 +0200 Subject: [PATCH 22/29] changed level in verbose logs --- .../dnetlib/repo/manager/service/RepositoryServiceImpl.java | 4 ++-- .../manager/service/security/AuthorizationServiceImpl.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java index 63bef35..8aee836 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java @@ -217,8 +217,8 @@ public class RepositoryServiceImpl implements RepositoryService { resultSet = objectMapper.readValue(objectMapper.writeValueAsString(datasourceDetailsList), objectMapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class)); - if (logger.isDebugEnabled()) { - logger.debug("resultSet: {}", objectMapper.writeValueAsString(resultSet)); + if (logger.isTraceEnabled()) { + logger.trace("resultSet: {}", objectMapper.writeValueAsString(resultSet)); } resultSet.parallelStream().forEach(repositorySnippet -> { repositorySnippet.setPiwikInfo(piWikService.getPiwikSiteForRepo(repositorySnippet.getId())); diff --git a/src/main/java/eu/dnetlib/repo/manager/service/security/AuthorizationServiceImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/security/AuthorizationServiceImpl.java index 4ce5e70..af8647e 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/security/AuthorizationServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/security/AuthorizationServiceImpl.java @@ -131,8 +131,8 @@ public class AuthorizationServiceImpl implements AuthorizationService { UserInfo userInfo = ((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo(); roles = getUserRolesByEmail(userInfo.getEmail()); - if (logger.isDebugEnabled()) { - logger.debug("User Roles: {}", String.join(",", roles)); + if (logger.isTraceEnabled()) { + logger.trace("User Roles: {}", String.join(",", roles)); } return roles; } From 19923c19fc3283e6d966631705865c8cd869e420 Mon Sep 17 00:00:00 2001 From: Konstantinos Spyrou Date: Tue, 31 Jan 2023 14:51:34 +0200 Subject: [PATCH 23/29] refactoring --- .../repo/manager/service/EmailUtilsImpl.java | 972 ++++++++---------- 1 file changed, 425 insertions(+), 547 deletions(-) diff --git a/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java index b67231f..89f4e87 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java @@ -18,7 +18,10 @@ import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Component; -import java.util.*; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; import java.util.stream.Collectors; @Component("emailUtils") @@ -50,715 +53,586 @@ public class EmailUtilsImpl implements EmailUtils { @Override public void sendAdministratorRequestToEnableMetrics(PiwikInfo piwikInfo) { + String subject = "[OpenAIRE-Usage Statistics] New request to enable usage statistics"; - try { - String subject = "[OpenAIRE-Usage Statistics] New request to enable usage statistics"; + String message = + "we have received a request to enable the OpenAIRE usage statistics for the following repository \n" + + "\n" + + "Repository - " + piwikInfo.getRepositoryName() + ", " + piwikInfo.getCountry() + " (" + piwikInfo.getRepositoryId() + ")\n" + + "Requestor - " + piwikInfo.getRequestorName() + ", " + piwikInfo.getRequestorEmail() + "\n" + + "Matomo ID - " + piwikInfo.getSiteId() + "\n" + + "Authentication token - " + piwikInfo.getAuthenticationToken() + "\n" + + "\n" + + "For more information about this request, go here: \n" + + this.baseUrl + "/admin/metrics"; + message = createAdminMail(message); - String message = - "we have received a request to enable the OpenAIRE usage statistics for the following repository \n" + - "\n" + - "Repository - " + piwikInfo.getRepositoryName() + ", " + piwikInfo.getCountry() + " (" + piwikInfo.getRepositoryId() + ")\n" + - "Requestor - " + piwikInfo.getRequestorName() + ", " + piwikInfo.getRequestorEmail() + "\n" + - "Matomo ID - " + piwikInfo.getSiteId() + "\n" + - "Authentication token - " + piwikInfo.getAuthenticationToken() + "\n" + - "\n" + - "For more information about this request, go here: \n" + - this.baseUrl + "/admin/metrics"; - message = createAdminMail(message); - - this.sendMail(this.usageStatsAdminEmail, subject, message); - - } catch (Exception e) { - logger.error("Error while sending request to enable metrics email to administrator: " + this.usageStatsAdminEmail, e); - } + this.sendMail(this.usageStatsAdminEmail, subject, message); } @Override public void sendUserRequestToEnableMetrics(PiwikInfo piwikInfo) { + String subject = "[OpenAIRE-Usage Statistics] Your request to enable usage statistics"; - try { - String subject = "[OpenAIRE-Usage Statistics] Your request to enable usage statistics"; + String message = "Dear " + piwikInfo.getRequestorName() + ",\n" + + "\n" + + "we have received your request to enable the OpenAIRE usage statistics for your repository\n" + + "\n" + + "Repository - " + piwikInfo.getRepositoryName() + ", " + piwikInfo.getCountry() + " (" + piwikInfo.getRepositoryId() + ")\n" + + "Matomo ID - " + piwikInfo.getSiteId() + "\n" + + "Authentication token - " + piwikInfo.getAuthenticationToken() + "\n" + + "\n" + + "In order to enable the usage statistics, you must install the OpenAIRE's tracking code in your repository software. " + + "OpenAIRE's usage statistics service tracking code is maintained on Github as a patch for various versions of DSpace " + + "(https://github.com/openaire/OpenAIRE-Piwik-DSpace) and as an Eprints plugin for version 3 " + + "(https://github.com/openaire/EPrints-OAPiwik). In case the platform is different from DSpace or EPrints please contact " + + "the OpenAIRE team in repositoryusagestats@openaire.eu in order to find a solution.\n" + + "\n" + + "For more information about your request and configuration details, go here: \n" + + this.baseUrl + "/getImpact/instructions/" + piwikInfo.getRepositoryId() + "\n" + + "\n" + + "Once you have finished configuring your repository or if you have any questions, please notify the OpenAIRE team by sending \n" + + "an email to repositoryusagestats@openaire.eu\n" + + "\n" + + "Best,\n" + + "The OpenAIRE team"; - String message = "Dear " + piwikInfo.getRequestorName() + ",\n" + - "\n" + - "we have received your request to enable the OpenAIRE usage statistics for your repository\n" + - "\n" + - "Repository - " + piwikInfo.getRepositoryName() + ", " + piwikInfo.getCountry() + " (" + piwikInfo.getRepositoryId() + ")\n" + - "Matomo ID - " + piwikInfo.getSiteId() + "\n" + - "Authentication token - " + piwikInfo.getAuthenticationToken() + "\n" + - "\n" + - "In order to enable the usage statistics, you must install the OpenAIRE's tracking code in your repository software. " + - "OpenAIRE's usage statistics service tracking code is maintained on Github as a patch for various versions of DSpace " + - "(https://github.com/openaire/OpenAIRE-Piwik-DSpace) and as an Eprints plugin for version 3 " + - "(https://github.com/openaire/EPrints-OAPiwik). In case the platform is different from DSpace or EPrints please contact " + - "the OpenAIRE team in repositoryusagestats@openaire.eu in order to find a solution.\n" + - "\n" + - "For more information about your request and configuration details, go here: \n" + - this.baseUrl + "/getImpact/instructions/" + piwikInfo.getRepositoryId() + "\n" + - "\n" + - "Once you have finished configuring your repository or if you have any questions, please notify the OpenAIRE team by sending \n" + - "an email to repositoryusagestats@openaire.eu\n" + - "\n" + - "Best,\n" + - "The OpenAIRE team"; - - this.sendMail(piwikInfo.getRequestorEmail(), subject, message); - - } catch (Exception e) { - logger.error("Error while sending request to enable metrics email to user: " + piwikInfo.getRequestorEmail(), e); - } + this.sendMail(piwikInfo.getRequestorEmail(), subject, message); } @Override public void sendAdministratorMetricsEnabled(PiwikInfo piwikInfo) { + String subject = "[OpenAIRE-Usage Statistics] Usage statistics have been enabled"; - try { - String subject = "[OpenAIRE-Usage Statistics] Usage statistics have been enabled"; + String message = + "The installation and configuration of OpenAIRE's tracking code for the following repository " + + "has been completed and validated and the usage statistics have been enabled in OpenAIRE.\n" + + "\n" + + "Repository - " + piwikInfo.getRepositoryName() + ", " + piwikInfo.getCountry() + " (" + piwikInfo.getRepositoryId() + ")\n" + + "Requestor - " + piwikInfo.getRequestorName() + ", " + piwikInfo.getRequestorEmail() + "\n" + + "Piwik ID - " + piwikInfo.getSiteId() + "\n" + + "Authentication token - " + piwikInfo.getAuthenticationToken(); + message = createAdminMail(message); - String message = - "The installation and configuration of OpenAIRE's tracking code for the following repository " + - "has been completed and validated and the usage statistics have been enabled in OpenAIRE.\n" + - "\n" + - "Repository - " + piwikInfo.getRepositoryName() + ", " + piwikInfo.getCountry() + " (" + piwikInfo.getRepositoryId() + ")\n" + - "Requestor - " + piwikInfo.getRequestorName() + ", " + piwikInfo.getRequestorEmail() + "\n" + - "Piwik ID - " + piwikInfo.getSiteId() + "\n" + - "Authentication token - " + piwikInfo.getAuthenticationToken(); - message = createAdminMail(message); - - this.sendMail(this.usageStatsAdminEmail, subject, message); - - } catch (Exception e) { - logger.error("Error while sending metrics enabled notification email to administator: " + this.usageStatsAdminEmail, e); - } + this.sendMail(this.usageStatsAdminEmail, subject, message); } @Override public void sendUserMetricsEnabled(PiwikInfo piwikInfo) { + String subject = "[OpenAIRE-Usage Statistics] Usage statistics have been enabled"; - try { - String subject = "[OpenAIRE-Usage Statistics] Usage statistics have been enabled"; + String message = "Dear " + piwikInfo.getRequestorName() + ",\n" + + "\n" + + "The installation and configuration of OpenAIRE's tracking code for your repository \"" + piwikInfo.getRepositoryName() + + "\" has been completed and validated and the usage statistics have been enabled in OpenAIRE.\n" + + "\n" + + "You can preview the statistics in your repository's dashboard: \n" + + this.baseUrl + "/getImpact/" + piwikInfo.getRepositoryId() + "\n" + + "\n" + + " For more information and questions, you can contact the openaire support team by sending an email to " + + "repositoryusagestats@openaire.eu\n" + + "\n" + + "Best Regards,\n" + + "The OpenAIRE team"; - String message = "Dear " + piwikInfo.getRequestorName() + ",\n" + - "\n" + - "The installation and configuration of OpenAIRE's tracking code for your repository \"" + piwikInfo.getRepositoryName() + - "\" has been completed and validated and the usage statistics have been enabled in OpenAIRE.\n" + - "\n" + - "You can preview the statistics in your repository's dashboard: \n" + - this.baseUrl + "/getImpact/" + piwikInfo.getRepositoryId() + "\n" + - "\n" + - " For more information and questions, you can contact the openaire support team by sending an email to " + - "repositoryusagestats@openaire.eu\n" + - "\n" + - "Best Regards,\n" + - "The OpenAIRE team"; - - this.sendMail(piwikInfo.getRequestorEmail(), subject, message); - - } catch (Exception e) { - logger.error("Error while sending metrics enabled notification email to user: " + piwikInfo.getRequestorEmail(), e); - } + this.sendMail(piwikInfo.getRequestorEmail(), subject, message); } @Override public void sendAdminRegistrationEmail(Repository repository, Authentication authentication) { - try { - String subject = "OpenAIRE content provider registration for " + - repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; + String subject = "OpenAIRE content provider registration for " + + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; - String message = - "We received a request to register the " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]" + - " to the OpenAIRE compliant list of content providers. " + - "\n\n" + - "User Contact: " + authentication.getName() + " (" + ((OIDCAuthenticationToken) authentication).getUserInfo().getEmail() + ")" + - "\n\n" + - "Please do not reply to this message\n" + - "This message has been generated automatically."; - message = createAdminMail(message); + String message = + "We received a request to register the " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]" + + " to the OpenAIRE compliant list of content providers. " + + "\n\n" + + "User Contact: " + authentication.getName() + " (" + ((OIDCAuthenticationToken) authentication).getUserInfo().getEmail() + ")" + + "\n\n" + + "Please do not reply to this message\n" + + "This message has been generated automatically."; + message = createAdminMail(message); - this.sendMail(this.provideAdminEmail, subject, message); - - } catch (Exception e) { - logger.error("Error while sending registration notification email to the administrator", e); - } + this.sendMail(this.provideAdminEmail, subject, message); } @Override public void sendUserRegistrationEmail(Repository repository, Authentication authentication) { - try { - String subject = "OpenAIRE content provider registration for " + - repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; + String subject = "OpenAIRE content provider registration for " + + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; - String message = - "We received a request to register the " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]" + - " to the OpenAIRE compliant list of content providers. " + - "\n\n" + - "Please do not reply to this message\n" + - "This message has been generated automatically.\n\n" + - "If you have any questions, write to 'helpdesk@openaire.eu'."; - message = createUserMail(message, authentication); + String message = + "We received a request to register the " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]" + + " to the OpenAIRE compliant list of content providers. " + + "\n\n" + + "Please do not reply to this message\n" + + "This message has been generated automatically.\n\n" + + "If you have any questions, write to 'helpdesk@openaire.eu'."; + message = createUserMail(message, authentication); - this.sendMail(repository.getRegisteredby(), subject, message); - - } catch (Exception e) { - logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e); + Collection emailTo = new HashSet<>(); + if (repository.getRegisteredby() != null) { + emailTo.add(repository.getRegisteredby()); } + emailTo.add(User.from(((OIDCAuthenticationToken) authentication).getUserInfo()).getEmail()); + this.sendMail(emailTo, subject, message); } @Override public void sendAdminRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, String desiredCompatibility, Authentication authentication) { - try { - String subject = "OpenAIRE new interface registration request started for " + - repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; + String subject = "OpenAIRE new interface registration request started for " + + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; - String message = - "We received a request to add the following interface: \n\n" + - "Base URL: " + repositoryInterface.getBaseurl() + "\n" + - "Set: " + repositoryInterface.getAccessSet() + "\n" + - "Selected Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + "\n\n" + - "to " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n"; + String message = + "We received a request to add the following interface: \n\n" + + "Base URL: " + repositoryInterface.getBaseurl() + "\n" + + "Set: " + repositoryInterface.getAccessSet() + "\n" + + "Selected Guidelines: " + getSelectedGuidelines(desiredCompatibility, repositoryInterface) + "\n\n" + + "to " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n"; - if (comment != null) - message += "\nThe users comment was '" + comment + "'\n"; + if (comment != null) + message += "\nThe users comment was '" + comment + "'\n"; - message += "A validation process for this interface against the OpenAIRE guidelines compatibility " + - "has been started. You will be informed in another message once the process is finished." + - "\n\n" + - "User Contact: " + authentication.getName() + " (" + ((OIDCAuthenticationToken) authentication).getUserInfo().getEmail() + ")" + - "\n\n" + - "Please do not reply to this message\n" + - "This message has been generated automatically."; - message = createAdminMail(message); + message += "A validation process for this interface against the OpenAIRE guidelines compatibility " + + "has been started. You will be informed in another message once the process is finished." + + "\n\n" + + "User Contact: " + authentication.getName() + " (" + ((OIDCAuthenticationToken) authentication).getUserInfo().getEmail() + ")" + + "\n\n" + + "Please do not reply to this message\n" + + "This message has been generated automatically."; + message = createAdminMail(message); - this.sendMail(this.provideAdminEmail, subject, message); - - } catch (Exception e) { - logger.error("Error while sending registration of interface notification email to the administrator", e); - } + this.sendMail(this.provideAdminEmail, subject, message); } @Override public void sendUserRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, String desiredCompatibility, Authentication authentication) { - try { - String subject = "OpenAIRE new interface registration request started for " + - repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; - String message = - "We received a request to add the following interface: \n\n" + - "Base URL: " + repositoryInterface.getBaseurl() + "\n" + - "Set: " + repositoryInterface.getAccessSet() + "\n" + - "Selected Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + "\n\n" + - "to " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n"; + String subject = "OpenAIRE new interface registration request started for " + + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; + String message = + "We received a request to add the following interface: \n\n" + + "Base URL: " + repositoryInterface.getBaseurl() + "\n" + + "Set: " + repositoryInterface.getAccessSet() + "\n" + + "Selected Guidelines: " + getSelectedGuidelines(desiredCompatibility, repositoryInterface) + "\n\n" + + "to " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n"; - if (comment != null) { - message += "\n Your comment was '" + comment + "'\n"; - } - - message += "A validation process for this interface against the OpenAIRE guidelines compatibility " + - "has been started. You will be informed in another message once the process is finished." + - "\n\n" + - "Please do not reply to this message\n" + - "This message has been generated automatically."; - message = createUserMail(message, authentication); - - Collection emailTo = new HashSet<>(); - if (repository.getRegisteredby() != null) { - emailTo.add(repository.getRegisteredby()); - } - emailTo.add(User.from(((OIDCAuthenticationToken) authentication).getUserInfo()).getEmail()); - this.sendMail(emailTo, subject, message); - - } catch (Exception e) { - logger.error("Error while sending registration of interface notification email to user: " + repository.getRegisteredby(), e); + if (comment != null) { + message += "\n Your comment was '" + comment + "'\n"; } + + message += "A validation process for this interface against the OpenAIRE guidelines compatibility " + + "has been started. You will be informed in another message once the process is finished." + + "\n\n" + + "Please do not reply to this message\n" + + "This message has been generated automatically."; + message = createUserMail(message, authentication); + + Collection emailTo = new HashSet<>(); + if (repository.getRegisteredby() != null) { + emailTo.add(repository.getRegisteredby()); + } + emailTo.add(User.from(((OIDCAuthenticationToken) authentication).getUserInfo()).getEmail()); + this.sendMail(emailTo, subject, message); } @Override public void sendUserRegistrationResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication) { - try { - String subject = "OpenAIRE new interface registration request - results (success) for " + - repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; + String subject = "OpenAIRE new interface registration request - results (success) for " + + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; - String message = - "the compatibility test on " + "[" + repository.getOfficialname() + "]" + - " was successful and the datasource type \"" + repository.getEoscDatasourceType() + "\" will be prepared for aggregation in OpenAIRE." + - "\n\n" + - "Please note that it usually takes about 3-4 weeks until a data source is indexed and it's metadata visible on openaire.eu.\n\n" + - "Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() + - "\nOfficial Name:" + repository.getOfficialname() + - "\n\nBase URL: " + repositoryInterface.getBaseurl() + - "\n\nSet: " + repositoryInterface.getAccessSet() + - "\n\nSelected Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + - "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + - "\n\n\nPlease do not reply to this email\n" + - "This message has been generated manually\n\n" + - "If you have any questions, write to 'helpdesk@openaire.eu'."; - message = createUserMail(message, authentication); + String message = + "the compatibility test on " + "[" + repository.getOfficialname() + "]" + + " was successful and the datasource type \"" + repository.getEoscDatasourceType() + "\" will be prepared for aggregation in OpenAIRE." + + "\n\n" + + "Please note that it usually takes about 3-4 weeks until a data source is indexed and it's metadata visible on openaire.eu.\n\n" + + "Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() + + "\nOfficial Name:" + repository.getOfficialname() + + "\n\nBase URL: " + repositoryInterface.getBaseurl() + + "\n\nSet: " + repositoryInterface.getAccessSet() + + "\n\nSelected Guidelines: " + getSelectedGuidelines(desiredCompatibility, repositoryInterface) + + "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + + "\n\n\nPlease do not reply to this email\n" + + "This message has been generated manually\n\n" + + "If you have any questions, write to 'helpdesk@openaire.eu'."; + message = createUserMail(message, authentication); - Collection emailTo = new HashSet<>(); - if (repository.getRegisteredby() != null) { - emailTo.add(repository.getRegisteredby()); - } - emailTo.add(User.from(((OIDCAuthenticationToken) authentication).getUserInfo()).getEmail()); - this.sendMail(emailTo, subject, message); - - } catch (Exception e) { - logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e); + Collection emailTo = new HashSet<>(); + if (repository.getRegisteredby() != null) { + emailTo.add(repository.getRegisteredby()); } + emailTo.add(User.from(((OIDCAuthenticationToken) authentication).getUserInfo()).getEmail()); + this.sendMail(emailTo, subject, message); } @Override public void sendAdminRegistrationResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication) { - try { - String subject = "OpenAIRE new interface registration request - results (success) for " + - repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; + String subject = "OpenAIRE new interface registration request - results (success) for " + + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; - String message = - "the compatibility test on " + "[" + repository.getOfficialname() + "]" + - " was successful and the datasource type \"" + repository.getEoscDatasourceType() + "\" will be prepared for aggregation in OpenAIRE." + - "\n\n" + - "Please note that it usually takes about 3-4 weeks until a data source is indexed and it's metadata visible on openaire.eu.\n\n" + - "Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() + - "\nOfficial Name:" + repository.getOfficialname() + - "\n\nBase URL: " + repositoryInterface.getBaseurl() + - "\n\nSet: " + repositoryInterface.getAccessSet() + - "\n\nDesired Selected Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + - "\n\nUser Contact:" + issuerEmail + "" + - "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + - "\n\n\nPlease do not reply to this email\n" + - "This message has been generated manually\n\n" + - "If you have any questions, write to 'helpdesk@openaire.eu'."; - message = createAdminMail(message); + String message = + "the compatibility test on " + "[" + repository.getOfficialname() + "]" + + " was successful and the datasource type \"" + repository.getEoscDatasourceType() + "\" will be prepared for aggregation in OpenAIRE." + + "\n\n" + + "Please note that it usually takes about 3-4 weeks until a data source is indexed and it's metadata visible on openaire.eu.\n\n" + + "Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() + + "\nOfficial Name:" + repository.getOfficialname() + + "\n\nBase URL: " + repositoryInterface.getBaseurl() + + "\n\nSet: " + repositoryInterface.getAccessSet() + + "\n\nDesired Selected Guidelines: " + getSelectedGuidelines(desiredCompatibility, repositoryInterface) + + "\n\nUser Contact:" + issuerEmail + "" + + "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + + "\n\n\nPlease do not reply to this email\n" + + "This message has been generated manually\n\n" + + "If you have any questions, write to 'helpdesk@openaire.eu'."; + message = createAdminMail(message); - this.sendMail(this.provideAdminEmail, subject, message); - - } catch (Exception e) { - logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e); - } + this.sendMail(this.provideAdminEmail, subject, message); } @Override public void sendUserRegistrationResultsFailureEmail(String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication) { - try { - String subject = "OpenAIRE new interface registration request - results (failure) for " + - repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; - String message = - "the compatibility test on " + "[" + repository.getOfficialname() + "]" + - " was not successful and the registration process was interrupted." + - "\n\n" + - "We will check what caused the problem and get back to you within a couple of days.\n\n" + - "Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() + - "\nOfficial Name:" + repository.getOfficialname() + - "\n\nBase URL: " + repositoryInterface.getBaseurl() + - "\n\nSet: " + repositoryInterface.getAccessSet() + - "\n\nSelected Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + - "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + - "\n\n\nPlease do not reply to this email\n" + - "This message has been generated manually\n\n" + - "If you have any questions, write to 'helpdesk@openaire.eu'."; - message = createUserMail(message, authentication); + String subject = "OpenAIRE new interface registration request - results (failure) for " + + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; + String message = + "the compatibility test on " + "[" + repository.getOfficialname() + "]" + + " was not successful and the registration process was interrupted." + + "\n\n" + + "We will check what caused the problem and get back to you within a couple of days.\n\n" + + "Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() + + "\nOfficial Name:" + repository.getOfficialname() + + "\n\nBase URL: " + repositoryInterface.getBaseurl() + + "\n\nSet: " + repositoryInterface.getAccessSet() + + "\n\nSelected Guidelines: " + getSelectedGuidelines(desiredCompatibility, repositoryInterface) + + "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + + "\n\n\nPlease do not reply to this email\n" + + "This message has been generated manually\n\n" + + "If you have any questions, write to 'helpdesk@openaire.eu'."; + message = createUserMail(message, authentication); - Collection emailTo = new HashSet<>(); - if (repository.getRegisteredby() != null) { - emailTo.add(repository.getRegisteredby()); - } - emailTo.add(User.from(((OIDCAuthenticationToken) authentication).getUserInfo()).getEmail()); - this.sendMail(emailTo, subject, message); - - } catch (Exception e) { - logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e); + Collection emailTo = new HashSet<>(); + if (repository.getRegisteredby() != null) { + emailTo.add(repository.getRegisteredby()); } + emailTo.add(User.from(((OIDCAuthenticationToken) authentication).getUserInfo()).getEmail()); + this.sendMail(emailTo, subject, message); } @Override public void sendAdminRegistrationResultsFailureEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication) { - try { - String subject = "OpenAIRE new interface registration request - results (failure) for " + - repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; + String subject = "OpenAIRE new interface registration request - results (failure) for " + + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; - String message = - "the compatibility test on [" + repository.getOfficialname() + "]" + - " was not successful and the registration process was interrupted." + - "\n\n" + - "We will check what caused the problem and get back to you within a couple of days.\n\n" + - "Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() + - "\nOfficial Name:" + repository.getOfficialname() + - "\n\nBase URL: " + repositoryInterface.getBaseurl() + - "\n\nSet: " + repositoryInterface.getAccessSet() + - "\n\nSelected Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + - "\n\nUser Contact:" + issuerEmail + "" + - "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + - "\n\n\nPlease do not reply to this email\n" + - "This message has been generated manually\n\n" + - "If you have any questions, write to 'helpdesk@openaire.eu'."; - message = createAdminMail(message); + String message = + "the compatibility test on [" + repository.getOfficialname() + "]" + + " was not successful and the registration process was interrupted." + + "\n\n" + + "We will check what caused the problem and get back to you within a couple of days.\n\n" + + "Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() + + "\nOfficial Name:" + repository.getOfficialname() + + "\n\nBase URL: " + repositoryInterface.getBaseurl() + + "\n\nSet: " + repositoryInterface.getAccessSet() + + "\n\nSelected Guidelines: " + getSelectedGuidelines(desiredCompatibility, repositoryInterface) + + "\n\nUser Contact:" + issuerEmail + "" + + "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + + "\n\n\nPlease do not reply to this email\n" + + "This message has been generated manually\n\n" + + "If you have any questions, write to 'helpdesk@openaire.eu'."; + message = createAdminMail(message); - this.sendMail(this.provideAdminEmail, subject, message); - - } catch (Exception e) { - logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e); - } + this.sendMail(this.provideAdminEmail, subject, message); } @Override public void sendUserUpdateResultsSuccessEmail(String issuer, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication) { - try { - String subject = "OpenAIRE interface update request - results (success) for " + - repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; + String subject = "OpenAIRE interface update request - results (success) for " + + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; - String message = - "the compatibility test on [" + repository.getOfficialname() + "] has been successful\n\n" + - "We will check your transmitted information and adjust the aggregation settings accordingly. Please note that it usually takes about 3-4 weeks until the changes are visible on openaire.eu." + "\n\n" + - "Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() + - "\nOfficial Name:" + repository.getOfficialname() + - "\n\nBase URL: " + repositoryInterface.getBaseurl() + - "\n\nSet: " + repositoryInterface.getAccessSet() + - "\n\nSelected Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + - "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + - "\n\n\nPlease do not reply to this email\n" + - "This message has been generated manually\n\n" + - "If you have any questions, write to 'helpdesk@openaire.eu'."; - message = createUserMail(message, authentication); + String message = + "the compatibility test on [" + repository.getOfficialname() + "] has been successful\n\n" + + "We will check your transmitted information and adjust the aggregation settings accordingly. Please note that it usually takes about 3-4 weeks until the changes are visible on openaire.eu." + "\n\n" + + "Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() + + "\nOfficial Name:" + repository.getOfficialname() + + "\n\nBase URL: " + repositoryInterface.getBaseurl() + + "\n\nSet: " + repositoryInterface.getAccessSet() + + "\n\nSelected Guidelines: " + getSelectedGuidelines(desiredCompatibility, repositoryInterface) + + "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + + "\n\n\nPlease do not reply to this email\n" + + "This message has been generated manually\n\n" + + "If you have any questions, write to 'helpdesk@openaire.eu'."; + message = createUserMail(message, authentication); - this.sendMail(issuer, subject, message); - - } catch (Exception e) { - logger.error("Error while sending registration notification email to the administrator", e); - } + this.sendMail(issuer, subject, message); } @Override public void sendAdminUpdateResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication) { - try { - String subject = "OpenAIRE interface update request - results (success) for " + - repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; + String subject = "OpenAIRE interface update request - results (success) for " + + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; - String message = - "the compatibility test on [" + repository.getOfficialname() + "] has been successful\n\n" + - "We will check your transmitted information and adjust the aggregation settings accordingly. Please note that it usually takes about 3-4 weeks until the changes are visible on openaire.eu." + "\n\n" + - "Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() + - "\nOfficial Name:" + repository.getOfficialname() + - "\n\nBase URL: " + repositoryInterface.getBaseurl() + - "\n\nSet: " + repositoryInterface.getAccessSet() + - "\n\nSelected Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + - "\n\nUser Contact:" + issuerEmail + "" + - "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + - "\n\n\nPlease do not reply to this email\n" + - "This message has been generated manually\n\n" + - "If you have any questions, write to 'helpdesk@openaire.eu'."; - message = createAdminMail(message); + String message = + "the compatibility test on [" + repository.getOfficialname() + "] has been successful\n\n" + + "We will check your transmitted information and adjust the aggregation settings accordingly. Please note that it usually takes about 3-4 weeks until the changes are visible on openaire.eu." + "\n\n" + + "Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() + + "\nOfficial Name:" + repository.getOfficialname() + + "\n\nBase URL: " + repositoryInterface.getBaseurl() + + "\n\nSet: " + repositoryInterface.getAccessSet() + + "\n\nSelected Guidelines: " + getSelectedGuidelines(desiredCompatibility, repositoryInterface) + + "\n\nUser Contact:" + issuerEmail + "" + + "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + + "\n\n\nPlease do not reply to this email\n" + + "This message has been generated manually\n\n" + + "If you have any questions, write to 'helpdesk@openaire.eu'."; + message = createAdminMail(message); - this.sendMail(this.provideAdminEmail, subject, message); - - } catch (Exception e) { - logger.error("Error while sending registration notification email to the administrator", e); - } + this.sendMail(this.provideAdminEmail, subject, message); } @Override public void sendUserUpdateResultsFailureEmail(String issuer, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication) { - try { - String subject = "OpenAIRE interface update request - results (failure) for " + - repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; + String subject = "OpenAIRE interface update request - results (failure) for " + + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; - String message = - "the compatibility test on " + "[" + repository.getOfficialname() + "]" + - " was not successful." + - "\n\n" + - "WWe will check your transmitted information to see what caused the problem and get back to you within a couple of days.\n\n" + - "Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() + - "\nOfficial Name:" + repository.getOfficialname() + - "\n\nBase URL: " + repositoryInterface.getBaseurl() + - "\n\nSet: " + repositoryInterface.getAccessSet() + - "\n\nSelected Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + - "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + - "\n\n\nPlease do not reply to this email\n" + - "This message has been generated manually\n\n" + - "If you have any questions, write to 'helpdesk@openaire.eu'."; - message = createUserMail(message, authentication); + String message = + "the compatibility test on [" + repository.getOfficialname() + "] was not successful." + + "\n\n" + + "We will check your transmitted information to see what caused the problem and get back to you within a couple of days.\n\n" + + "Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() + + "\nOfficial Name:" + repository.getOfficialname() + + "\n\nBase URL: " + repositoryInterface.getBaseurl() + + "\n\nSet: " + repositoryInterface.getAccessSet() + + "\n\nSelected Guidelines: " + getSelectedGuidelines(desiredCompatibility, repositoryInterface) + + "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + + "\n\n\nPlease do not reply to this email\n" + + "This message has been generated manually\n\n" + + "If you have any questions, write to 'helpdesk@openaire.eu'."; + message = createUserMail(message, authentication); - this.sendMail(issuer, subject, message); - - } catch (Exception e) { - logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e); - } + this.sendMail(issuer, subject, message); } @Override public void sendAdminUpdateResultsFailureEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication) { - try { - String subject = "OpenAIRE interface update request - results (failure) for " + - repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; + String subject = "OpenAIRE interface update request - results (failure) for " + + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; - String message = - "the compatibility test on " + "[" + repository.getOfficialname() + "]" + - " was not successful." + - "\n\n" + - "WWe will check your transmitted information to see what caused the problem and get back to you within a couple of days.\n\n" + - "Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() + - "\nOfficial Name:" + repository.getOfficialname() + - "\n\nBase URL: " + repositoryInterface.getBaseurl() + - "\n\nSet: " + repositoryInterface.getAccessSet() + - "\n\nSelected Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + - "\n\nUser Contact:" + issuerEmail + "" + - "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + - "\n\n\nPlease do not reply to this email\n" + - "This message has been generated manually\n\n" + - "If you have any questions, write to 'helpdesk@openaire.eu'."; - message = createAdminMail(message); + String message = + "the compatibility test on " + "[" + repository.getOfficialname() + "]" + + " was not successful." + + "\n\n" + + "WWe will check your transmitted information to see what caused the problem and get back to you within a couple of days.\n\n" + + "Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() + + "\nOfficial Name:" + repository.getOfficialname() + + "\n\nBase URL: " + repositoryInterface.getBaseurl() + + "\n\nSet: " + repositoryInterface.getAccessSet() + + "\n\nSelected Guidelines: " + getSelectedGuidelines(desiredCompatibility, repositoryInterface) + + "\n\nUser Contact:" + issuerEmail + "" + + "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + + "\n\n\nPlease do not reply to this email\n" + + "This message has been generated manually\n\n" + + "If you have any questions, write to 'helpdesk@openaire.eu'."; + message = createAdminMail(message); - this.sendMail(this.provideAdminEmail, subject, message); - - } catch (Exception e) { - logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e); - } + this.sendMail(this.provideAdminEmail, subject, message); } @Override public void sendUserUpdateInterfaceComplianceFailure(List emails, Repository repository, RepositoryInterface repositoryInterface, InterfaceComplianceRequest request) { - try { - String subject = "OpenAIRE interface update compliance request - results (failure) for " + - repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; + String subject = "OpenAIRE interface update compliance request - results (failure) for " + + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; - String message = - "The request for changing the compatibility of " + "[" + repository.getOfficialname() + "]" + - " was not successful." + - "\n\n" + + String message = + "The request for changing the compatibility of " + "[" + repository.getOfficialname() + "]" + + " was not successful." + + "\n\n" + - "Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() + - "\nOfficial Name:" + repository.getOfficialname() + - "\n\nBase URL: " + repositoryInterface.getBaseurl() + - "\n\nSet: " + repositoryInterface.getAccessSet() + - "\n\nSelected Guidelines: " + request.getDesiredCompatibilityLevel() + - "\n\n\nPlease do not reply to this email\n" + - "This message has been generated automatically\n\n" + - "If you have any questions, write to 'helpdesk@openaire.eu'."; - message = createRepoAdminsMail(message); + "Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() + + "\nOfficial Name:" + repository.getOfficialname() + + "\n\nBase URL: " + repositoryInterface.getBaseurl() + + "\n\nSet: " + repositoryInterface.getAccessSet() + + "\n\nSelected Guidelines: " + request.getDesiredCompatibilityLevel() + + "\n\n\nPlease do not reply to this email\n" + + "This message has been generated automatically\n\n" + + "If you have any questions, write to 'helpdesk@openaire.eu'."; + message = createRepoAdminsMail(message); - this.sendMail(emails, subject, message); - - } catch (Exception e) { - logger.error("Notification email to repository admins failed.\nRepository: {}\nRequest: {}", repository, request, e); - } + this.sendMail(emails, subject, message); } @Override public void sendAdminUpdateInterfaceComplianceFailure(Repository repository, RepositoryInterface repositoryInterface, InterfaceComplianceRequest request) { - try { - String subject = "OpenAIRE interface update compliance request - results (failure) for " + - repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; + String subject = "OpenAIRE interface update compliance request - results (failure) for " + + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; - String message = - "The request for changing the compatibility of " + "[" + repository.getOfficialname() + "]" + - " was not successful." + - "\n\n" + + String message = + "The request for changing the compatibility of " + "[" + repository.getOfficialname() + "]" + + " was not successful." + + "\n\n" + - "Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() + - "\nOfficial Name:" + repository.getOfficialname() + - "\n\nBase URL: " + repositoryInterface.getBaseurl() + - "\n\nSet: " + repositoryInterface.getAccessSet() + - "\n\nSelected Guidelines: " + request.getDesiredCompatibilityLevel() + - "\n\n\nPlease do not reply to this email\n" + - "This message has been generated automatically\n\n" + - "If you have any questions, write to 'helpdesk@openaire.eu'."; - message = createAdminMail(message); + "Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() + + "\nOfficial Name:" + repository.getOfficialname() + + "\n\nBase URL: " + repositoryInterface.getBaseurl() + + "\n\nSet: " + repositoryInterface.getAccessSet() + + "\n\nSelected Guidelines: " + request.getDesiredCompatibilityLevel() + + "\n\n\nPlease do not reply to this email\n" + + "This message has been generated automatically\n\n" + + "If you have any questions, write to 'helpdesk@openaire.eu'."; + message = createAdminMail(message); - this.sendMail(this.provideAdminEmail, subject, message); - - } catch (Exception e) { - logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e); - } + this.sendMail(this.provideAdminEmail, subject, message); } @Override public void sendUserValidationResults(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) { - try { - String subject = "OpenAIRE validator - Test results "; + String subject = "OpenAIRE validator - Test results "; - String message = - "the validation request you have submitted has finished. You can retrieve the results by following this url: " + valBaseUrl + "" + jobId + " .\n\n" + - "Please do not reply to this message.\n" + - "This message has been generated automatically.\n" + - "If you have any questions, write to 'helpdesk@openaire.eu'."; - message = createUserMail(message, authentication); + String message = + "the validation request you have submitted has finished. You can retrieve the results by following this url: " + valBaseUrl + "" + jobId + " .\n\n" + + "Please do not reply to this message.\n" + + "This message has been generated automatically.\n" + + "If you have any questions, write to 'helpdesk@openaire.eu'."; + message = createUserMail(message, authentication); - Collection emailTo = new HashSet<>(); - if (repository.getRegisteredby() != null) { - emailTo.add(repository.getRegisteredby()); - } - emailTo.add(User.from(((OIDCAuthenticationToken) authentication).getUserInfo()).getEmail()); - this.sendMail(emailTo, subject, message); - - } catch (Exception e) { - logger.error("Error while sending validation submission notification email to user: " + issuer, e); + Collection emailTo = new HashSet<>(); + emailTo.add(issuer); + if (repository.getRegisteredby() != null) { + emailTo.add(repository.getRegisteredby()); } + emailTo.add(User.from(((OIDCAuthenticationToken) authentication).getUserInfo()).getEmail()); + this.sendMail(emailTo, subject, message); } @Override public void sendAdminValidationResults(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) { - try { - String subject = "OpenAIRE validator - Test results "; + String subject = "OpenAIRE validator - Test results "; - String message = - "a validation request has finished. You can retrieve the results by following this url: " + valBaseUrl + "" + jobId + " .\n\n" + - "\n\nUser Contact:" + issuer + "" + - "Please do not reply to this message.\n" + - "This message has been generated automatically.\n" + - "If you have any questions, write to 'helpdesk@openaire.eu'."; - message = createAdminMail(message); + String message = + "a validation request has finished. You can retrieve the results by following this url: " + valBaseUrl + "" + jobId + " .\n\n" + + "\n\nUser Contact:" + issuer + "" + + "Please do not reply to this message.\n" + + "This message has been generated automatically.\n" + + "If you have any questions, write to 'helpdesk@openaire.eu'."; + message = createAdminMail(message); - this.sendMail(this.provideAdminEmail, subject, message); - - } catch (Exception e) { - logger.error("Error while sending validation submission notification email to user: " + issuer, e); - } + this.sendMail(this.provideAdminEmail, subject, message); } @Override public void sendAdminGeneralFailure(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) { - try { - String subject = "OpenAIRE validator - job failure"; + String subject = "OpenAIRE validator - job failure"; - String message = - "the validation job that was automatically submitted for the update/registration of the interface " - + repositoryInterface.getId() + " (" + repositoryInterface.getBaseurl() + ", " - + repositoryInterface.getAccessSet() + ") of the repository " + repository.getId() - + " (" + repository.getOfficialname() + ") failed to complete." - + "This message has been generated automatically."; - message = createAdminMail(message); + String message = + "the validation job that was automatically submitted for the update/registration of the interface " + + repositoryInterface.getId() + " (" + repositoryInterface.getBaseurl() + ", " + + repositoryInterface.getAccessSet() + ") of the repository " + repository.getId() + + " (" + repository.getOfficialname() + ") failed to complete." + + "This message has been generated automatically."; + message = createAdminMail(message); - this.sendMail(this.provideAdminEmail, subject, message); - - } catch (Exception e) { - logger.error("Error while sending validation submission notification email to user: " + issuer, e); - } + this.sendMail(this.provideAdminEmail, subject, message); } @Override public void sendAdminUpdateRepositoryInfoEmail(Repository repository, Authentication authentication) { - try { - String subject = "OpenAIRE content provider update information for " + - repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; + String subject = "OpenAIRE content provider update information for " + + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; - String message = - "We received a request to update the basic information for " + repository.getEoscDatasourceType() - + "[" + repository.getOfficialname() + "].\n\n" + - "Please do not reply to this message\n" + - "This message has been generated automatically."; - message = createAdminMail(message); + String message = + "We received a request to update the basic information for " + repository.getEoscDatasourceType() + + "[" + repository.getOfficialname() + "].\n\n" + + "Please do not reply to this message\n" + + "This message has been generated automatically."; + message = createAdminMail(message); - this.sendMail(this.provideAdminEmail, subject, message); - - } catch (Exception e) { - logger.error("Error while sending registration notification email to the administrator", e); - } + this.sendMail(this.provideAdminEmail, subject, message); } @Override public void sendUserUpdateRepositoryInfoEmail(Repository repository, Authentication authentication) { - try { - String subject = "OpenAIRE content provider update information for " + - repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; + String subject = "OpenAIRE content provider update information for " + + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; - String message = - "We received a request to update the basic information for " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n\n" + - "Please do not reply to this message\n" + - "This message has been generated automatically.\n\n" + - "If you have any questions, write to 'helpdesk@openaire.eu'."; - message = createUserMail(message, authentication); + String message = + "We received a request to update the basic information for " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n\n" + + "Please do not reply to this message\n" + + "This message has been generated automatically.\n\n" + + "If you have any questions, write to 'helpdesk@openaire.eu'."; + message = createUserMail(message, authentication); - Collection emailTo = new HashSet<>(); - if (repository.getRegisteredby() != null) { - emailTo.add(repository.getRegisteredby()); - } - emailTo.add(User.from(((OIDCAuthenticationToken) authentication).getUserInfo()).getEmail()); - this.sendMail(emailTo, subject, message); - - } catch (Exception e) { - logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e); + Collection emailTo = new HashSet<>(); + if (repository.getRegisteredby() != null) { + emailTo.add(repository.getRegisteredby()); } + emailTo.add(User.from(((OIDCAuthenticationToken) authentication).getUserInfo()).getEmail()); + this.sendMail(emailTo, subject, message); } @Override public void sendAdminUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, String desiredCompatibility, Authentication authentication) { - try { - String subject = "OpenAIRE interface update request started for " + - repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; + String subject = "OpenAIRE interface update request started for " + + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; - String message = - "We received a request to update the following interface: \n\n" + - "Base URL: " + repositoryInterface.getBaseurl() + "\n" + - "Set: " + repositoryInterface.getAccessSet() + "\n" + - "Selected Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + "\n\n" + - "for " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n"; + String message = + "We received a request to update the following interface: \n\n" + + "Base URL: " + repositoryInterface.getBaseurl() + "\n" + + "Set: " + repositoryInterface.getAccessSet() + "\n" + + "Selected Guidelines: " + getSelectedGuidelines(desiredCompatibility, repositoryInterface) + "\n\n" + + "for " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n"; - if (comment != null) - message += "\nThe users comment was '" + comment + "'\n"; + if (comment != null) + message += "\nThe users comment was '" + comment + "'\n"; - message += "A new iteration process of the validation against the OpenAIRE guidelines compatibility has been started.\n\n" + - "User Contact: " + authentication.getName() + " (" + ((OIDCAuthenticationToken) authentication).getUserInfo().getEmail() + ")" + - "\n\n" + - "Please do not reply to this message\n" + - "This message has been generated automatically."; - message = createAdminMail(message); + message += "A new iteration process of the validation against the OpenAIRE guidelines compatibility has been started.\n\n" + + "User Contact: " + authentication.getName() + " (" + ((OIDCAuthenticationToken) authentication).getUserInfo().getEmail() + ")" + + "\n\n" + + "Please do not reply to this message\n" + + "This message has been generated automatically."; + message = createAdminMail(message); - this.sendMail(this.provideAdminEmail, subject, message); - - } catch (Exception e) { - logger.error("Error while sending registration notification email to the administrator", e); - } + this.sendMail(this.provideAdminEmail, subject, message); } @Override public void sendUserUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, String desiredCompatibility, Authentication authentication) { - try { - String subject = "OpenAIRE interface update request started for " + - repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; + String subject = "OpenAIRE interface update request started for " + + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]"; - String message = - "We received a request to update the following interface: \n\n" + - "Base URL: " + repositoryInterface.getBaseurl() + "\n" + - "Set: " + repositoryInterface.getAccessSet() + "\n" + - "Selected Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride() + "\n\n" + - "for " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n"; + String message = + "We received a request to update the following interface: \n\n" + + "Base URL: " + repositoryInterface.getBaseurl() + "\n" + + "Set: " + repositoryInterface.getAccessSet() + "\n" + + "Selected Guidelines: " + getSelectedGuidelines(desiredCompatibility, repositoryInterface) + "\n\n" + + "for " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n"; - if (comment != null) { - message += "\n Your comment was '" + comment + "'\n"; - } - - message += "A new iteration process of the validation against the OpenAIRE guidelines compatibility has been started.\n\n" + - "Please do not reply to this message\n" + - "This message has been generated automatically.\n\n" + - "If you have any questions, write to 'helpdesk@openaire.eu'."; - message = createUserMail(message, authentication); - - Collection emailTo = new HashSet<>(); - if (repository.getRegisteredby() != null) { - emailTo.add(repository.getRegisteredby()); - } - emailTo.add(User.from(((OIDCAuthenticationToken) authentication).getUserInfo()).getEmail()); - this.sendMail(emailTo, subject, message); - - } catch (Exception e) { - logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e); + if (comment != null) { + message += "\n Your comment was '" + comment + "'\n"; } + + message += "A new iteration process of the validation against the OpenAIRE guidelines compatibility has been started.\n\n" + + "Please do not reply to this message\n" + + "This message has been generated automatically.\n\n" + + "If you have any questions, write to 'helpdesk@openaire.eu'."; + message = createUserMail(message, authentication); + + Collection emailTo = new HashSet<>(); + if (repository.getRegisteredby() != null) { + emailTo.add(repository.getRegisteredby()); + } + emailTo.add(User.from(((OIDCAuthenticationToken) authentication).getUserInfo()).getEmail()); + this.sendMail(emailTo, subject, message); } @Override public void sendSubmitJobForValidationEmail(Authentication authentication, JobForValidation jobForValidation) { - try { - String subject = "OpenAIRE validator - Test submission "; + String subject = "OpenAIRE validator - Test submission "; - String message = - "The validation request you have submitted has started.\n" + - "Please do not reply to this message.\n" + - "This message has been generated automatically.\n" + - "If you have any questions, write to 'helpdesk@openaire.eu'."; - message = createUserMail(message, authentication); + String message = + "The validation request you have submitted has started.\n" + + "Please do not reply to this message.\n" + + "This message has been generated automatically.\n" + + "If you have any questions, write to 'helpdesk@openaire.eu'."; + message = createUserMail(message, authentication); - this.sendMail(jobForValidation.getUserEmail(), subject, message); - - } catch (Exception e) { - logger.error("Error while sending validation submission notification email to user: " + jobForValidation.getUserEmail(), e); - } + this.sendMail(jobForValidation.getUserEmail(), subject, message); } @Override @@ -848,4 +722,8 @@ public class EmailUtilsImpl implements EmailUtils { } return user; // It may be just "user". TODO - Wouldn't be better if it was null? } + + private String getSelectedGuidelines(String desiredCompatibility, RepositoryInterface repositoryInterface) { + return desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibilityOverride(); + } } From c2e5af87e8c2278c8e7e5780a224f1eb774d48b3 Mon Sep 17 00:00:00 2001 From: Konstantinos Spyrou Date: Tue, 31 Jan 2023 15:26:19 +0200 Subject: [PATCH 24/29] changes in mail content --- .../repo/manager/service/EmailUtilsImpl.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java index 89f4e87..353082b 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java @@ -147,7 +147,8 @@ public class EmailUtilsImpl implements EmailUtils { "We received a request to register the " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]" + " to the OpenAIRE compliant list of content providers. " + "\n\n" + - "User Contact: " + authentication.getName() + " (" + ((OIDCAuthenticationToken) authentication).getUserInfo().getEmail() + ")" + + "User Contact: " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + + " (" + ((OIDCAuthenticationToken) authentication).getUserInfo().getEmail() + ")" + "\n\n" + "Please do not reply to this message\n" + "This message has been generated automatically."; @@ -196,7 +197,8 @@ public class EmailUtilsImpl implements EmailUtils { message += "A validation process for this interface against the OpenAIRE guidelines compatibility " + "has been started. You will be informed in another message once the process is finished." + "\n\n" + - "User Contact: " + authentication.getName() + " (" + ((OIDCAuthenticationToken) authentication).getUserInfo().getEmail() + ")" + + "User Contact: " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + + " (" + ((OIDCAuthenticationToken) authentication).getUserInfo().getEmail() + ")" + "\n\n" + "Please do not reply to this message\n" + "This message has been generated automatically."; @@ -279,7 +281,7 @@ public class EmailUtilsImpl implements EmailUtils { "\n\nBase URL: " + repositoryInterface.getBaseurl() + "\n\nSet: " + repositoryInterface.getAccessSet() + "\n\nDesired Selected Guidelines: " + getSelectedGuidelines(desiredCompatibility, repositoryInterface) + - "\n\nUser Contact:" + issuerEmail + "" + + "\n\nUser Contact: " + issuerEmail + "" + "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + "\n\n\nPlease do not reply to this email\n" + "This message has been generated manually\n\n" + @@ -332,7 +334,7 @@ public class EmailUtilsImpl implements EmailUtils { "\n\nBase URL: " + repositoryInterface.getBaseurl() + "\n\nSet: " + repositoryInterface.getAccessSet() + "\n\nSelected Guidelines: " + getSelectedGuidelines(desiredCompatibility, repositoryInterface) + - "\n\nUser Contact:" + issuerEmail + "" + + "\n\nUser Contact: " + issuerEmail + "" + "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + "\n\n\nPlease do not reply to this email\n" + "This message has been generated manually\n\n" + @@ -377,7 +379,7 @@ public class EmailUtilsImpl implements EmailUtils { "\n\nBase URL: " + repositoryInterface.getBaseurl() + "\n\nSet: " + repositoryInterface.getAccessSet() + "\n\nSelected Guidelines: " + getSelectedGuidelines(desiredCompatibility, repositoryInterface) + - "\n\nUser Contact:" + issuerEmail + "" + + "\n\nUser Contact: " + issuerEmail + "" + "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + "\n\n\nPlease do not reply to this email\n" + "This message has been generated manually\n\n" + @@ -425,7 +427,7 @@ public class EmailUtilsImpl implements EmailUtils { "\n\nBase URL: " + repositoryInterface.getBaseurl() + "\n\nSet: " + repositoryInterface.getAccessSet() + "\n\nSelected Guidelines: " + getSelectedGuidelines(desiredCompatibility, repositoryInterface) + - "\n\nUser Contact:" + issuerEmail + "" + + "\n\nUser Contact: " + issuerEmail + "" + "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId + "\n\n\nPlease do not reply to this email\n" + "This message has been generated manually\n\n" + @@ -507,7 +509,7 @@ public class EmailUtilsImpl implements EmailUtils { String message = "a validation request has finished. You can retrieve the results by following this url: " + valBaseUrl + "" + jobId + " .\n\n" + - "\n\nUser Contact:" + issuer + "" + + "\n\nUser Contact: " + issuer + "" + "Please do not reply to this message.\n" + "This message has been generated automatically.\n" + "If you have any questions, write to 'helpdesk@openaire.eu'."; @@ -582,7 +584,8 @@ public class EmailUtilsImpl implements EmailUtils { message += "\nThe users comment was '" + comment + "'\n"; message += "A new iteration process of the validation against the OpenAIRE guidelines compatibility has been started.\n\n" + - "User Contact: " + authentication.getName() + " (" + ((OIDCAuthenticationToken) authentication).getUserInfo().getEmail() + ")" + + "User Contact: " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + + " (" + ((OIDCAuthenticationToken) authentication).getUserInfo().getEmail() + ")" + "\n\n" + "Please do not reply to this message\n" + "This message has been generated automatically."; From a239164f97bdb8af90b798e990d26db6f2a1cf98 Mon Sep 17 00:00:00 2001 From: LSmyrnaios Date: Tue, 31 Jan 2023 15:40:06 +0200 Subject: [PATCH 25/29] - Ensure the "BufferedReader" and the "InputStream" get always closed in the end, in "Converter.readFile()". - Code polishing. --- .../service/RepositoryServiceImpl.java | 23 +++++++++---------- .../service/aai/registry/RegistryCalls.java | 1 - .../dnetlib/repo/manager/utils/Converter.java | 7 ++---- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java index 8aee836..3cdf396 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java @@ -205,13 +205,11 @@ public class RepositoryServiceImpl implements RepositoryService { for (String repoId : ids) { requestFilter.setId(repoId); - DatasourceResponse rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, DatasourceResponse.class); - if (rs == null) { + if ( rs == null ) logger.error("The \"DatasourceResponse\" is null!"); - } else { + else datasourceDetailsList.addAll(rs.getDatasourceInfo()); - } } resultSet = objectMapper.readValue(objectMapper.writeValueAsString(datasourceDetailsList), @@ -547,13 +545,12 @@ public class RepositoryServiceImpl implements RepositoryService { RepositoryInterface repositoryInterface, String desiredCompatibilityLevel) throws Exception { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); - Repository e = this.getRepositoryById(repoId); - repositoryInterface = fillInterfaceFields(e, repositoryInterface, datatype); + Repository repo = this.getRepositoryById(repoId); + repositoryInterface = fillInterfaceFields(repo, repositoryInterface, datatype); UriComponents uriComponents = UriComponentsBuilder .fromHttpUrl(baseAddress + "/ds/api/add/") - .build() - .encode(); + .build().encode(); HttpEntity httpEntity = new HttpEntity<>(repositoryInterface, httpHeaders); restTemplate.postForObject(uriComponents.toUri(), httpEntity, String.class); @@ -561,15 +558,17 @@ 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(e, comment, repositoryInterface, desiredCompatibilityLevel, authentication); - emailUtils.sendUserRegisterInterfaceEmail(e, comment, repositoryInterface, desiredCompatibilityLevel, authentication); + emailUtils.sendAdminRegisterInterfaceEmail(repo, comment, repositoryInterface, desiredCompatibilityLevel, authentication); + emailUtils.sendUserRegisterInterfaceEmail(repo, comment, repositoryInterface, desiredCompatibilityLevel, authentication); - if (desiredCompatibilityLevel != null && (repositoryInterface.getCompatibility() == null || !repositoryInterface.getCompatibility().equals(desiredCompatibilityLevel))) { + String prevCompatibilityLevel = repositoryInterface.getCompatibility(); + if ( (desiredCompatibilityLevel != null) + && ((prevCompatibilityLevel == null) || ! prevCompatibilityLevel.equals(desiredCompatibilityLevel))) { InterfaceComplianceRequest request = new InterfaceComplianceRequest(repoId, repositoryInterface.getId(), desiredCompatibilityLevel); interfaceComplianceService.create(request); } - submitInterfaceValidation(e, getAuthenticatedUser().getEmail(), repositoryInterface, false, repositoryInterface.getCompatibility()); + submitInterfaceValidation(repo, getAuthenticatedUser().getEmail(), repositoryInterface, false, desiredCompatibilityLevel); return repositoryInterface; } diff --git a/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/RegistryCalls.java b/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/RegistryCalls.java index dc7c5f1..be987bb 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/RegistryCalls.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/RegistryCalls.java @@ -16,7 +16,6 @@ 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.ArrayList; diff --git a/src/main/java/eu/dnetlib/repo/manager/utils/Converter.java b/src/main/java/eu/dnetlib/repo/manager/utils/Converter.java index 3dccc4e..b250602 100644 --- a/src/main/java/eu/dnetlib/repo/manager/utils/Converter.java +++ b/src/main/java/eu/dnetlib/repo/manager/utils/Converter.java @@ -6,7 +6,6 @@ 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; @@ -22,13 +21,11 @@ public class Converter { public static List readFile(String filename) { String line; List list = new ArrayList<>(); - try { - InputStream in = Converter.class.getResourceAsStream("/eu/**/" + filename); - BufferedReader br = new BufferedReader(new InputStreamReader(in)); // It may throw an NPE. + try ( BufferedReader br = new BufferedReader(new InputStreamReader(Objects.requireNonNull(Converter.class.getResourceAsStream("/eu/**/" + filename)))) ) + { while ((line = br.readLine()) != null) { list.add(line.trim()); } - br.close(); } catch (Exception e) { logger.error("Error opening file!", e); } From 8bf0f76ad67b955735f8a7623f13ed63ca0400e0 Mon Sep 17 00:00:00 2001 From: LSmyrnaios Date: Tue, 31 Jan 2023 16:57:37 +0200 Subject: [PATCH 26/29] - Improve performance of "ValidatorController.getRuleSet()" endpoint. - Improve exception-handling. - Replace deprecated method-calls. - Code polishing. --- .../repo/manager/service/MonitorServiceImpl.java | 8 +++----- .../repo/manager/service/PiWikServiceImpl.java | 4 ++-- .../manager/service/SushiliteServiceImpl.java | 10 ++++------ .../manager/service/ValidatorServiceImpl.java | 16 ++++++++-------- .../eu/dnetlib/repo/manager/utils/HttpUtils.java | 6 ++---- .../eu/dnetlib/repo/manager/utils/OaiTools.java | 4 ++-- 6 files changed, 21 insertions(+), 27 deletions(-) diff --git a/src/main/java/eu/dnetlib/repo/manager/service/MonitorServiceImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/MonitorServiceImpl.java index 3f0de75..f4156cd 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/MonitorServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/MonitorServiceImpl.java @@ -95,7 +95,6 @@ public class MonitorServiceImpl implements MonitorService { || (job.getValidationType().equals("U") && job.getContentJobStatus().equals("none") && job.getUsageJobStatus().equals("finished") && job.getUsageJobScore() <= 50)) { job.setValidationStatus("failed"); } - } } @@ -140,7 +139,6 @@ public class MonitorServiceImpl implements MonitorService { ///////////////////////////////////////////////////////////////////////////////////////// return retJobs; - } private int getJobsTotalNumberOfUser(String user, String jobType, String validationStatus) throws ValidatorServiceException { @@ -166,13 +164,12 @@ public class MonitorServiceImpl implements MonitorService { } @Override - public StoredJob getJobSummary(String jobId, - String groupBy) throws JSONException { + public StoredJob getJobSummary(String jobId, String groupBy) { logger.debug("Getting job summary with id : " + jobId); StoredJob job = null; try { job = getValidationService().getStoredJob(Integer.parseInt(jobId), groupBy); - } catch (ValidatorServiceException e) { + } catch (Exception e) { logger.error(e.getMessage(), e); } ///////////////////////////////////////////////////////////////////////////////////////// @@ -189,4 +186,5 @@ public class MonitorServiceImpl implements MonitorService { ///////////////////////////////////////////////////////////////////////////////////////// return job; } + } diff --git a/src/main/java/eu/dnetlib/repo/manager/service/PiWikServiceImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/PiWikServiceImpl.java index f5c9d56..667cf12 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/PiWikServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/PiWikServiceImpl.java @@ -226,12 +226,12 @@ public class PiWikServiceImpl implements PiWikService { @Override public Integer getTotal() { - return new JdbcTemplate(dataSource).queryForObject(GET_PIWIK_SITES_TOTAL, new Object[]{}, Integer.class); + return new JdbcTemplate(dataSource).queryForObject(GET_PIWIK_SITES_TOTAL, Integer.class, new Object[]{}); } @Override public Integer getValidated(boolean validated) { String finalizedQuery = GET_PIWIK_SITES_TOTAL + " where validated = ?"; - return new JdbcTemplate(dataSource).queryForObject(finalizedQuery, new Object[]{validated}, Integer.class); + return new JdbcTemplate(dataSource).queryForObject(finalizedQuery, Integer.class, validated); } } diff --git a/src/main/java/eu/dnetlib/repo/manager/service/SushiliteServiceImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/SushiliteServiceImpl.java index 002c867..ba41dda 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/SushiliteServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/SushiliteServiceImpl.java @@ -95,22 +95,20 @@ public class SushiliteServiceImpl implements SushiliteService { Customer customer = reportResponseWrapper.getReportResponse().getReportWrapper().getReport().getCustomer(); List 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.debug("Exception on getReportResults - trying to cast strings to integers", e); - //emailUtils.reportException(e); + logger.error("Exception on getReportResults - trying to cast strings to integers", e); throw e; } } diff --git a/src/main/java/eu/dnetlib/repo/manager/service/ValidatorServiceImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/ValidatorServiceImpl.java index 34805c0..7619147 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/ValidatorServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/ValidatorServiceImpl.java @@ -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,16 +210,13 @@ public class ValidatorServiceImpl implements ValidatorService { @Override public List getSetsOfRepository(String url) { logger.debug("Getting sets of repository with url : {}", url); - List sets = null; - try { sets = OaiTools.getSetsOfRepo(url); } catch (Exception e) { logger.error("Exception on getSetsOfRepository", e); } - - return sets; + return sets; // It may be null. } @Override @@ -239,13 +236,16 @@ public class ValidatorServiceImpl implements ValidatorService { RuleSet ruleSet = null; try { for (List 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; + return ruleSet; // It may be null. } catch (Exception e) { logger.error("Error getting ruleset", e); return null; diff --git a/src/main/java/eu/dnetlib/repo/manager/utils/HttpUtils.java b/src/main/java/eu/dnetlib/repo/manager/utils/HttpUtils.java index 957da55..7fbb870 100644 --- a/src/main/java/eu/dnetlib/repo/manager/utils/HttpUtils.java +++ b/src/main/java/eu/dnetlib/repo/manager/utils/HttpUtils.java @@ -49,16 +49,14 @@ public class HttpUtils { public JsonElement get(String path, Map params) { RestTemplate restTemplate = new RestTemplate(); String url = registryUrl + path + ((params != null) ? createParams(params) : null); - ResponseEntity responseEntity = restTemplate.exchange - (url, HttpMethod.GET, new HttpEntity<>(createHeaders(user, password)), String.class); + ResponseEntity responseEntity = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(createHeaders(user, password)), String.class); return getResponseEntityAsJsonElement(responseEntity); } public JsonElement delete(String path) { RestTemplate restTemplate = new RestTemplate(); String url = registryUrl + path; - ResponseEntity responseEntity = restTemplate.exchange - (url, HttpMethod.DELETE, new HttpEntity<>(createHeaders(user, password)), String.class); + ResponseEntity responseEntity = restTemplate.exchange(url, HttpMethod.DELETE, new HttpEntity<>(createHeaders(user, password)), String.class); return getResponseEntityAsJsonElement(responseEntity); } diff --git a/src/main/java/eu/dnetlib/repo/manager/utils/OaiTools.java b/src/main/java/eu/dnetlib/repo/manager/utils/OaiTools.java index 1e030e6..d9c7008 100644 --- a/src/main/java/eu/dnetlib/repo/manager/utils/OaiTools.java +++ b/src/main/java/eu/dnetlib/repo/manager/utils/OaiTools.java @@ -25,7 +25,7 @@ public class OaiTools { disableSslVerification(); } - private static Logger logger = LoggerFactory.getLogger(OaiTools.class); + private static final Logger logger = LoggerFactory.getLogger(OaiTools.class); public static List getSetsOfRepo(String baseUrl) throws Exception { try { @@ -36,8 +36,8 @@ public class OaiTools { List sets = new ArrayList<>(setList.asList()); while (token != null) { setList = harvester.listSets(token); - token = setList.getResumptionToken(); sets.addAll(setList.asList()); + token = setList.getResumptionToken(); } List ret = new ArrayList(); From 3845a5103b3aa6243f168a044ccc00cacdf45461 Mon Sep 17 00:00:00 2001 From: LSmyrnaios Date: Thu, 2 Feb 2023 18:47:04 +0200 Subject: [PATCH 27/29] - Fix a performance bug in "DashboardController.getCollectionMonitorSummary()", where the code for the "isIndexedVersion"-check, was re-checking 20 of the already-checked "aggregationInfo"-objects, in each new batch. - Update some properties. - Code polishing. --- .../controllers/DashboardController.java | 25 +++++++++++++------ src/main/resources/application.yml | 10 ++++---- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/main/java/eu/dnetlib/repo/manager/controllers/DashboardController.java b/src/main/java/eu/dnetlib/repo/manager/controllers/DashboardController.java index c04ad14..a0c32cb 100644 --- a/src/main/java/eu/dnetlib/repo/manager/controllers/DashboardController.java +++ b/src/main/java/eu/dnetlib/repo/manager/controllers/DashboardController.java @@ -57,20 +57,29 @@ public class DashboardController { @PathVariable("repoId") String repoId, @RequestParam(name = "size", required = false, defaultValue = "20") int size) throws JSONException { - List aggregationInfo = aggregationService.getRepositoryAggregations(repoId, 0, size); + // Get the "aggregationInfo" for the first requested aggregations. + List aggregationInfoList = aggregationService.getRepositoryAggregations(repoId, 0, size); + CollectionMonitorSummary collectionMonitorSummary = new CollectionMonitorSummary(); - collectionMonitorSummary.setAggregationInfo(aggregationInfo); + collectionMonitorSummary.setAggregationInfo(aggregationInfoList); + + // Search for the last indexed version, from the beginning of the list. + + // TODO - WARNING! This is very slow, since each time it requests the next 50, it re-requests the whole list from the "/ds/aggregationhistory/" DSM-endpoint. + // inside "AggregationServiceImpl.getRepositoryAggregations()". Then it splits the list in a chunk of 50 and then iterate though it here.. + // Since we already request the whole list each time anyway, just take that use it here!! + size = 0; do { - aggregationInfo = aggregationService.getRepositoryAggregations(repoId, size, size + 50); - for (AggregationInfo aggregationDetail : aggregationInfo) { - if (aggregationDetail.isIndexedVersion()) { - collectionMonitorSummary.setLastIndexedVersion(aggregationDetail); + aggregationInfoList = aggregationService.getRepositoryAggregations(repoId, size, size + 50); + for (AggregationInfo aggregationInfo : aggregationInfoList) { + if (aggregationInfo.isIndexedVersion()) { + collectionMonitorSummary.setLastIndexedVersion(aggregationInfo); break; } } - size += 30; - } while (aggregationInfo.size() != 0 && collectionMonitorSummary.getLastIndexedVersion() == null); + size += 50; + } while (aggregationInfoList.size() != 0 && collectionMonitorSummary.getLastIndexedVersion() == null); return collectionMonitorSummary; } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 02c21d1..409f18f 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -15,11 +15,11 @@ spring: services: provide: - dev-machine: 88.197.53.71 + dev-machine: 88.197.53.71 # VM-71 aai: baseURL: https://aai.openaire.eu oidc: - domain: .openaire.eu + domain: .openaire.eu # use empty value for local, otherwise: ".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: 8080 - url: https://broker1-dev-dnet.d4science.org + port: 443 + url: https://beta.broker.openaire.eu 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://services.openaire.eu/usagestats + usagestats: https://beta.services.openaire.eu/usagestats db: driverClassName: org.postgresql.Driver password: dnetPwd From c1abaad3e18e40b942166fc0f71c65b347fc1d9b Mon Sep 17 00:00:00 2001 From: LSmyrnaios Date: Thu, 2 Feb 2023 18:54:46 +0200 Subject: [PATCH 28/29] - Show a warning when the "indexedVersion" was not found in "DashboardServiceImpl.getRepositoriesSummaryInfo()". - Code optimization and polishing. --- .../manager/service/BrokerServiceImpl.java | 38 +++++++++---------- .../manager/service/DashboardServiceImpl.java | 27 ++++++++----- .../service/InterfaceComplianceService.java | 2 +- .../manager/service/MonitorServiceImpl.java | 2 +- .../service/RepositoryServiceImpl.java | 10 ++--- .../dnetlib/repo/manager/utils/HttpUtils.java | 2 +- .../integration/metrics/PrometheusTest.java | 3 +- .../InterfaceComplianceRequestTests.java | 14 +++---- 8 files changed, 50 insertions(+), 48 deletions(-) diff --git a/src/main/java/eu/dnetlib/repo/manager/service/BrokerServiceImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/BrokerServiceImpl.java index 48fb2f8..d4506d2 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/BrokerServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/BrokerServiceImpl.java @@ -8,7 +8,6 @@ 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; @@ -17,8 +16,6 @@ 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; @@ -27,6 +24,7 @@ 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; @@ -52,7 +50,7 @@ public class BrokerServiceImpl implements BrokerService { private HttpHeaders httpHeaders; - private HashMap topics = new HashMap<>(); + private final HashMap topics = new HashMap<>(); @PostConstruct private void initDnetTopicsMap() { @@ -78,7 +76,7 @@ public class BrokerServiceImpl implements BrokerService { @Override - public DatasourcesBroker getDatasourcesOfUser(String user, String includeShared, String includeByOthers) throws JSONException { + public DatasourcesBroker getDatasourcesOfUser(String user, String includeShared, String includeByOthers) { long start = System.currentTimeMillis(); DatasourcesBroker ret = new DatasourcesBroker(); try { @@ -96,7 +94,7 @@ public class BrokerServiceImpl implements BrokerService { logger.error("Exception on getDatasourcesOfUser", e); } long end = System.currentTimeMillis(); - System.out.println("Getting datasources of user in " + (end - start) + "ms"); + logger.debug("Getting datasources of user in " + (end - start) + "ms"); return ret; } @@ -129,14 +127,15 @@ public class BrokerServiceImpl implements BrokerService { final String service = "/events/{page}/{pageSize}"; + long pageNum = Long.parseLong(page); + advQueryObject.setPage(pageNum); + Map uriParams = new HashMap<>(); - uriParams.put("page", Long.parseLong(page)); + uriParams.put("page", pageNum); uriParams.put("pageSize", Long.parseLong(size)); UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service); - MultiValueMap headers = new LinkedMultiValueMap<>(); - advQueryObject.setPage(Long.parseLong(page)); HttpEntity entity = new HttpEntity<>(advQueryObject, httpHeaders); ResponseEntity resp; try { @@ -144,8 +143,7 @@ public class BrokerServiceImpl implements BrokerService { builder.buildAndExpand(uriParams).encode().toUri(), HttpMethod.POST, entity, - new ParameterizedTypeReference() { - } + new ParameterizedTypeReference() {} ); } catch (RestClientException e) { throw new BrokerException(e); @@ -171,8 +169,7 @@ 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(); - System.out.println("getDatasourcesOfUserType returned in " + (stop - start) + "ms "); - + logger.debug("getDatasourcesOfUserType returned in " + (stop - start) + "ms "); return entries; } @@ -180,7 +177,7 @@ public class BrokerServiceImpl implements BrokerService { public EventsPage showEvents(String datasourceName, String topic, String page, - String size) throws BrokerException, JSONException { + String size) throws BrokerException { final String service = "/events"; @@ -209,14 +206,14 @@ public class BrokerServiceImpl implements BrokerService { final String service = "/subscriptions"; - UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service) - .queryParam("email", userEmail); + URI uri = UriComponentsBuilder.fromHttpUrl(openairePath + service) + .queryParam("email", userEmail).build().encode().toUri(); - logger.debug("{}", builder.build().encode().toUri()); + logger.debug("{}", uri); ResponseEntity>> resp; try { resp = restTemplate.exchange( - builder.build().encode().toUri(), + uri, HttpMethod.GET, null, new ParameterizedTypeReference>>() { @@ -228,10 +225,9 @@ public class BrokerServiceImpl implements BrokerService { } @Override - public Map> getSimpleSubscriptionsOfUserByRepoId(String userEmail, String repoId) throws BrokerException { - Map> subscriptionsOfUser = getSimpleSubscriptionsOfUser(userEmail); + public Map> getSimpleSubscriptionsOfUserByRepoId(String userEmail, String repoId) { //throws BrokerException { throw new NotImplementedException(); -// return null; + //Map> subscriptionsOfUser = getSimpleSubscriptionsOfUser(userEmail); } @Override diff --git a/src/main/java/eu/dnetlib/repo/manager/service/DashboardServiceImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/DashboardServiceImpl.java index a344fcc..38f15cc 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/DashboardServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/DashboardServiceImpl.java @@ -39,41 +39,50 @@ public class DashboardServiceImpl implements DashboardService { try { List repositoriesOfUser = repositoryService.getRepositoriesSnippetsOfUser(userEmail, page, size); - for (RepositorySnippet repository : repositoriesOfUser) { + for (RepositorySnippet repository : repositoriesOfUser) + { + String repoId = repository.getId(); + String repoOfficialName = repository.getOfficialname(); + RepositorySummaryInfo repositorySummaryInfo = new RepositorySummaryInfo(); - repositorySummaryInfo.setId(repository.getId()); - repositorySummaryInfo.setRepositoryName(repository.getOfficialname()); + repositorySummaryInfo.setId(repoId); + repositorySummaryInfo.setRepositoryName(repoOfficialName); 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 aggregationInfoList = aggregationService.getRepositoryAggregations(repository.getId(), 0, 20); + List aggregationInfoList = aggregationService.getRepositoryAggregations(repoId, 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(); - System.out.println("Got repo aggregations in " + (end - start) + "ms"); + if ( isIndexedVersionFound ) + logger.debug("Got repo aggregations in " + (end - start) + "ms"); + else + logger.warn("Could not find repo aggregations, after " + (end - start) + "ms!"); try { - MetricsInfo metricsInfo = repositoryService.getMetricsInfoForRepository(repository.getId()); + MetricsInfo metricsInfo = repositoryService.getMetricsInfoForRepository(repoId); repositorySummaryInfo.setTotalDownloads(metricsInfo.getMetricsNumbers().getTotalDownloads()); repositorySummaryInfo.setTotalViews(metricsInfo.getMetricsNumbers().getTotalViews()); } catch (RepositoryServiceException e) { - logger.error("Exception getting metrics info for repository: " + repository.getId(), e); + logger.error("Exception getting metrics info for repository: {}, {} ", repoId, repoOfficialName, e); } try { - List events = brokerService.getTopicsForDatasource(repository.getOfficialname()); + List events = brokerService.getTopicsForDatasource(repoOfficialName); Long totalEvents = 0L; for (BrowseEntry browseEntry : events) totalEvents += browseEntry.getSize(); repositorySummaryInfo.setEnrichmentEvents(totalEvents); } catch (BrokerException e) { - logger.error("Exception getting broker events for repository: " + repository.getId(), e); + logger.error("Exception getting broker events for repository: {}, {} ", repoId, repoOfficialName, e); } repositorySummaryInfoList.add(repositorySummaryInfo); diff --git a/src/main/java/eu/dnetlib/repo/manager/service/InterfaceComplianceService.java b/src/main/java/eu/dnetlib/repo/manager/service/InterfaceComplianceService.java index df414b2..2a59c31 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/InterfaceComplianceService.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/InterfaceComplianceService.java @@ -58,7 +58,7 @@ public class InterfaceComplianceService { private Set getOutdated() { Calendar calendar = Calendar.getInstance(); - calendar.add(Calendar.DATE, -7); + calendar.add(Calendar.DATE, -7); // 7-days-old return this.repository.findAllBySubmissionDateBefore(calendar.getTime()); } diff --git a/src/main/java/eu/dnetlib/repo/manager/service/MonitorServiceImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/MonitorServiceImpl.java index f4156cd..e5e9339 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/MonitorServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/MonitorServiceImpl.java @@ -52,7 +52,7 @@ public class MonitorServiceImpl implements MonitorService { String dateFrom, String dateTo, String validationStatus, - String includeJobsTotal) throws JSONException, ValidatorServiceException { + String includeJobsTotal) throws ValidatorServiceException, NumberFormatException { ///////////////////////////////////////////////////////////////////////////////////////// // FIXME: this is a hack for CRIS Jan Dvorak Validator, should be implemented properly // diff --git a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java index 3cdf396..05faa63 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java @@ -4,7 +4,6 @@ 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; @@ -997,15 +996,12 @@ public class RepositoryServiceImpl implements RepositoryService { if (coPersonId != null) { roles = registryCalls.getRolesWithStatus(coPersonId, AaiRegistryService.RoleStatus.ACTIVE); for (JsonElement role : roles) { - JsonObject object = role.getAsJsonObject(); - if (object.get("CouId") == null) { - continue; - } - couIds.add(object.get("CouId").getAsInt()); + JsonElement couId = role.getAsJsonObject().get("CouId"); + if (couId != null) + couIds.add(couId.getAsInt()); } roleIds.addAll(registryCalls.getCouNames(couIds).values()); - } return roleIds; } diff --git a/src/main/java/eu/dnetlib/repo/manager/utils/HttpUtils.java b/src/main/java/eu/dnetlib/repo/manager/utils/HttpUtils.java index 7fbb870..245fc58 100644 --- a/src/main/java/eu/dnetlib/repo/manager/utils/HttpUtils.java +++ b/src/main/java/eu/dnetlib/repo/manager/utils/HttpUtils.java @@ -90,7 +90,7 @@ public class HttpUtils { String responseBody = responseEntity.getBody(); if ( responseBody != null ) { - logger.debug(responseBody); + logger.trace(responseBody); try { return new JsonParser().parse(responseBody); } catch (Exception e) { diff --git a/src/test/java/eu/dnetlib/repo/manager/integration/metrics/PrometheusTest.java b/src/test/java/eu/dnetlib/repo/manager/integration/metrics/PrometheusTest.java index 897aaea..381558d 100644 --- a/src/test/java/eu/dnetlib/repo/manager/integration/metrics/PrometheusTest.java +++ b/src/test/java/eu/dnetlib/repo/manager/integration/metrics/PrometheusTest.java @@ -11,6 +11,7 @@ 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; @@ -51,7 +52,7 @@ public class PrometheusTest { @Test public void testPiwikMetrics() { - assertTrue(piWikService.getValidated(false).equals(TOTAL - VALIDATED)); + assertEquals((long) piWikService.getValidated(false), (TOTAL - VALIDATED)); String report = prometheusController.getPiwikMetrics(); assertTrue(report.contains("provide_repositories_registered_total " + TOTAL)); assertTrue(report.contains("provide_usagecounts_repositories_registered_total " + TOTAL)); diff --git a/src/test/java/eu/dnetlib/repo/manager/integration/service/InterfaceComplianceRequestTests.java b/src/test/java/eu/dnetlib/repo/manager/integration/service/InterfaceComplianceRequestTests.java index 8a19e7d..a84ccb6 100644 --- a/src/test/java/eu/dnetlib/repo/manager/integration/service/InterfaceComplianceRequestTests.java +++ b/src/test/java/eu/dnetlib/repo/manager/integration/service/InterfaceComplianceRequestTests.java @@ -40,17 +40,17 @@ class InterfaceComplianceRequestTests { } private InterfaceComplianceRequestId createRequestId() { - InterfaceComplianceRequestId id = new InterfaceComplianceRequestId(); - id.setRepositoryId("repository"); - id.setInterfaceId("interface"); - return id; + InterfaceComplianceRequestId requestId = new InterfaceComplianceRequestId(); + requestId.setRepositoryId("repository"); + requestId.setInterfaceId("interface"); + return requestId; } private InterfaceComplianceRequest createRequest(String compatibilityLevel) { InterfaceComplianceRequest request = new InterfaceComplianceRequest(); - InterfaceComplianceRequestId id = createRequestId(); - request.setRepositoryId(id.getRepositoryId()); - request.setInterfaceId(id.getInterfaceId()); + InterfaceComplianceRequestId requestId = createRequestId(); + request.setRepositoryId(requestId.getRepositoryId()); + request.setInterfaceId(requestId.getInterfaceId()); request.setDesiredCompatibilityLevel(compatibilityLevel); request.setSubmissionDate(new Date()); return request; From 06cea537bfd0514e8fd8e5bbc96edb46535da9fc Mon Sep 17 00:00:00 2001 From: LSmyrnaios Date: Fri, 3 Feb 2023 14:19:43 +0200 Subject: [PATCH 29/29] Improve performance of "DashboardController.getCollectionMonitorSummary()"-endpoint. Now, a single "getRepositoryAggregations"-call is made, which results in just one "DSM-aggregationhistory"-api-call. Previously, multiple api-calls where made, each requesting the whole "aggregationhistory"-data and then trimming it down to only a few results. --- .../controllers/DashboardController.java | 30 +++++++------------ 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/src/main/java/eu/dnetlib/repo/manager/controllers/DashboardController.java b/src/main/java/eu/dnetlib/repo/manager/controllers/DashboardController.java index a0c32cb..3fd6650 100644 --- a/src/main/java/eu/dnetlib/repo/manager/controllers/DashboardController.java +++ b/src/main/java/eu/dnetlib/repo/manager/controllers/DashboardController.java @@ -55,31 +55,21 @@ public class DashboardController { @PreAuthorize("hasAuthority('REGISTERED_USER')") public CollectionMonitorSummary getCollectionMonitorSummary( @PathVariable("repoId") String repoId, - @RequestParam(name = "size", required = false, defaultValue = "20") int size) throws JSONException { + @RequestParam(name = "size", required = false, defaultValue = "20") int summarySize) throws JSONException { - // Get the "aggregationInfo" for the first requested aggregations. - List aggregationInfoList = aggregationService.getRepositoryAggregations(repoId, 0, size); + List aggregationInfoList = aggregationService.getRepositoryAggregations(repoId); CollectionMonitorSummary collectionMonitorSummary = new CollectionMonitorSummary(); - collectionMonitorSummary.setAggregationInfo(aggregationInfoList); + // Set the "aggregationInfo" for the first requested aggregations, in order to create a "summary". + collectionMonitorSummary.setAggregationInfo(aggregationInfoList.subList(0, Math.min(summarySize, aggregationInfoList.size()))); - // Search for the last indexed version, from the beginning of the list. - - // TODO - WARNING! This is very slow, since each time it requests the next 50, it re-requests the whole list from the "/ds/aggregationhistory/" DSM-endpoint. - // inside "AggregationServiceImpl.getRepositoryAggregations()". Then it splits the list in a chunk of 50 and then iterate though it here.. - // Since we already request the whole list each time anyway, just take that use it here!! - - size = 0; - do { - aggregationInfoList = aggregationService.getRepositoryAggregations(repoId, size, size + 50); - for (AggregationInfo aggregationInfo : aggregationInfoList) { - if (aggregationInfo.isIndexedVersion()) { - collectionMonitorSummary.setLastIndexedVersion(aggregationInfo); - break; - } + // Search for the last indexed version and set the "collectionMonitorSummary". + for ( AggregationInfo aggregationInfo : aggregationInfoList ) { + if ( aggregationInfo.isIndexedVersion() ) { + collectionMonitorSummary.setLastIndexedVersion(aggregationInfo); + break; } - size += 50; - } while (aggregationInfoList.size() != 0 && collectionMonitorSummary.getLastIndexedVersion() == null); + } return collectionMonitorSummary; }