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); }