- Ensure the "BufferedReader" and the "InputStream" get always closed in the end, in "Converter.readFile()".
- Code polishing.
This commit is contained in:
parent
c2e5af87e8
commit
a239164f97
|
@ -205,13 +205,11 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
|
|
||||||
for (String repoId : ids) {
|
for (String repoId : ids) {
|
||||||
requestFilter.setId(repoId);
|
requestFilter.setId(repoId);
|
||||||
|
|
||||||
DatasourceResponse rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, DatasourceResponse.class);
|
DatasourceResponse rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, DatasourceResponse.class);
|
||||||
if (rs == null) {
|
if ( rs == null )
|
||||||
logger.error("The \"DatasourceResponse\" is null!");
|
logger.error("The \"DatasourceResponse\" is null!");
|
||||||
} else {
|
else
|
||||||
datasourceDetailsList.addAll(rs.getDatasourceInfo());
|
datasourceDetailsList.addAll(rs.getDatasourceInfo());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resultSet = objectMapper.readValue(objectMapper.writeValueAsString(datasourceDetailsList),
|
resultSet = objectMapper.readValue(objectMapper.writeValueAsString(datasourceDetailsList),
|
||||||
|
@ -547,13 +545,12 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
RepositoryInterface repositoryInterface,
|
RepositoryInterface repositoryInterface,
|
||||||
String desiredCompatibilityLevel) throws Exception {
|
String desiredCompatibilityLevel) throws Exception {
|
||||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||||
Repository e = this.getRepositoryById(repoId);
|
Repository repo = this.getRepositoryById(repoId);
|
||||||
repositoryInterface = fillInterfaceFields(e, repositoryInterface, datatype);
|
repositoryInterface = fillInterfaceFields(repo, repositoryInterface, datatype);
|
||||||
|
|
||||||
UriComponents uriComponents = UriComponentsBuilder
|
UriComponents uriComponents = UriComponentsBuilder
|
||||||
.fromHttpUrl(baseAddress + "/ds/api/add/")
|
.fromHttpUrl(baseAddress + "/ds/api/add/")
|
||||||
.build()
|
.build().encode();
|
||||||
.encode();
|
|
||||||
|
|
||||||
HttpEntity<RepositoryInterface> httpEntity = new HttpEntity<>(repositoryInterface, httpHeaders);
|
HttpEntity<RepositoryInterface> httpEntity = new HttpEntity<>(repositoryInterface, httpHeaders);
|
||||||
restTemplate.postForObject(uriComponents.toUri(), httpEntity, String.class);
|
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)
|
// Explicitly update validation set (updating the interface does not allow updating the set value)
|
||||||
this.updateValidationSet(repoId, repositoryInterface.getId(), repositoryInterface.getAccessSet());
|
this.updateValidationSet(repoId, repositoryInterface.getId(), repositoryInterface.getAccessSet());
|
||||||
|
|
||||||
emailUtils.sendAdminRegisterInterfaceEmail(e, comment, repositoryInterface, desiredCompatibilityLevel, authentication);
|
emailUtils.sendAdminRegisterInterfaceEmail(repo, comment, repositoryInterface, desiredCompatibilityLevel, authentication);
|
||||||
emailUtils.sendUserRegisterInterfaceEmail(e, 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);
|
InterfaceComplianceRequest request = new InterfaceComplianceRequest(repoId, repositoryInterface.getId(), desiredCompatibilityLevel);
|
||||||
interfaceComplianceService.create(request);
|
interfaceComplianceService.create(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
submitInterfaceValidation(e, getAuthenticatedUser().getEmail(), repositoryInterface, false, repositoryInterface.getCompatibility());
|
submitInterfaceValidation(repo, getAuthenticatedUser().getEmail(), repositoryInterface, false, desiredCompatibilityLevel);
|
||||||
|
|
||||||
return repositoryInterface;
|
return repositoryInterface;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@ import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
|
@ -6,7 +6,6 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -22,13 +21,11 @@ public class Converter {
|
||||||
public static List<String> readFile(String filename) {
|
public static List<String> readFile(String filename) {
|
||||||
String line;
|
String line;
|
||||||
List<String> list = new ArrayList<>();
|
List<String> list = new ArrayList<>();
|
||||||
try {
|
try ( BufferedReader br = new BufferedReader(new InputStreamReader(Objects.requireNonNull(Converter.class.getResourceAsStream("/eu/**/" + filename)))) )
|
||||||
InputStream in = Converter.class.getResourceAsStream("/eu/**/" + filename);
|
{
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(in)); // It may throw an NPE.
|
|
||||||
while ((line = br.readLine()) != null) {
|
while ((line = br.readLine()) != null) {
|
||||||
list.add(line.trim());
|
list.add(line.trim());
|
||||||
}
|
}
|
||||||
br.close();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Error opening file!", e);
|
logger.error("Error opening file!", e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue