Improve performance and error-handling in "InterfaceComplianceService.cleanUp()".
This commit is contained in:
parent
64fdff095d
commit
842468a175
|
@ -39,19 +39,26 @@ public class InterfaceComplianceService {
|
||||||
@Scheduled(cron = "0 0 0 * * *") // every day at 00:00
|
@Scheduled(cron = "0 0 0 * * *") // every day at 00:00
|
||||||
public void cleanUp() {
|
public void cleanUp() {
|
||||||
Set<InterfaceComplianceRequest> requests = getOutdated();
|
Set<InterfaceComplianceRequest> requests = getOutdated();
|
||||||
for (InterfaceComplianceRequest request : requests) {
|
for ( InterfaceComplianceRequest request : requests )
|
||||||
|
{
|
||||||
|
String repoId = request.getRepositoryId();
|
||||||
|
String interfaceId = request.getInterfaceId();
|
||||||
try {
|
try {
|
||||||
Map<String, RepositoryInterface> repositoryInterfaceMap = repositoryService.getRepositoryInterface(request.getRepositoryId())
|
Map<String, RepositoryInterface> repositoryInterfaceMap = repositoryService.getRepositoryInterface(repoId)
|
||||||
.stream()
|
.stream()
|
||||||
.collect(Collectors.toMap(ApiDetails::getId, i -> i));
|
.collect(Collectors.toMap(ApiDetails::getId, i -> i));
|
||||||
Repository repo = repositoryService.getRepositoryById(request.getRepositoryId());
|
RepositoryInterface iFace = repositoryInterfaceMap.get(interfaceId);
|
||||||
RepositoryInterface iFace = repositoryInterfaceMap.get(request.getInterfaceId());
|
if ( iFace == null ) {
|
||||||
List<User> repositoryAdmins = authorizationService.getAdminsOfRepo(request.getRepositoryId());
|
logger.error("The repository-interface \"" + interfaceId + "\" does not exist! | the request had the \"repoId\": \"" + repoId + "\"");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Repository repo = repositoryService.getRepositoryById(repoId);
|
||||||
|
List<User> repositoryAdmins = authorizationService.getAdminsOfRepo(repoId);
|
||||||
emailUtils.sendUserUpdateInterfaceComplianceFailure(repositoryAdmins.stream().map(User::getEmail).collect(Collectors.toList()), repo, iFace, request);
|
emailUtils.sendUserUpdateInterfaceComplianceFailure(repositoryAdmins.stream().map(User::getEmail).collect(Collectors.toList()), repo, iFace, request);
|
||||||
emailUtils.sendAdminUpdateInterfaceComplianceFailure(repo, iFace, request);
|
emailUtils.sendAdminUpdateInterfaceComplianceFailure(repo, iFace, request);
|
||||||
} catch (ResourceNotFoundException e) {
|
} catch (ResourceNotFoundException e) {
|
||||||
logger.error("Error", e);
|
logger.error("Error for request with \"repoId\": \"" + repoId + "\" and \"interfaceId\": \"" + interfaceId + "\"", e);
|
||||||
}
|
} // Continue to the next request.
|
||||||
}
|
}
|
||||||
repository.deleteAll(requests);
|
repository.deleteAll(requests);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue