RED-2171: Fixex sonar bugs findings in 3.0 migration

This commit is contained in:
deiflaender 2021-11-25 14:38:38 +01:00
parent 9c8f0c87b3
commit 6fdcb4e655
2 changed files with 35 additions and 11 deletions

View File

@ -0,0 +1,16 @@
package com.iqser.red.service.peristence.v1.server.exception;
public class MigrationException extends RuntimeException {
public MigrationException(String message, Throwable t) {
super(message, t);
}
public MigrationException(String message) {
super(message);
}
}

View File

@ -21,6 +21,7 @@ import org.springframework.transaction.annotation.Transactional;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.iqser.red.service.peristence.v1.server.exception.MigrationException;
import com.iqser.red.service.peristence.v1.server.migration.model.CommentRow; import com.iqser.red.service.peristence.v1.server.migration.model.CommentRow;
import com.iqser.red.service.peristence.v1.server.migration.model.ConfigurationRow; import com.iqser.red.service.peristence.v1.server.migration.model.ConfigurationRow;
import com.iqser.red.service.peristence.v1.server.migration.model.DossierAttributeRow; import com.iqser.red.service.peristence.v1.server.migration.model.DossierAttributeRow;
@ -123,6 +124,8 @@ import lombok.extern.slf4j.Slf4j;
@RequiredArgsConstructor @RequiredArgsConstructor
public class MigrationService { public class MigrationService {
private static final String GLOBAL = "global";
private final FileManagementStorageService fileManagementStorageService; private final FileManagementStorageService fileManagementStorageService;
private final ObjectMapper objectMapper; private final ObjectMapper objectMapper;
@ -430,10 +433,15 @@ public class MigrationService {
private void migrateRules(String dossierTemplateId, List<VersionRow> versions) { private void migrateRules(String dossierTemplateId, List<VersionRow> versions) {
var version = versions.stream() var versionOptional = versions.stream()
.filter(versionRow -> versionRow.getDossierTemplateId() .filter(versionRow -> versionRow.getDossierTemplateId()
.equals(dossierTemplateId) && versionRow.getVersionType() == VersionType.RULE.ordinal()) .equals(dossierTemplateId) && versionRow.getVersionType() == VersionType.RULE.ordinal())
.findFirst() .findFirst();
if(!versionOptional.isPresent()){
throw new MigrationException("Unable to find version");
}
var version = versionOptional
.get() .get()
.getVersion(); .getVersion();
@ -477,7 +485,7 @@ public class MigrationService {
}); });
notifications.forEach(notification -> { notifications.forEach(notification -> {
var converted = new NotificationEntity().builder() var converted = NotificationEntity.builder()
.userId(notification.getUserId()) .userId(notification.getUserId())
.notificationType(notification.getNotificationType()) .notificationType(notification.getNotificationType())
.issuerId(notification.getIssuerId()) .issuerId(notification.getIssuerId())
@ -933,10 +941,10 @@ public class MigrationService {
types.stream().forEach(typeEntity -> { types.stream().forEach(typeEntity -> {
if (typeEntity.getDossierId().equals("global")) { if (typeEntity.getDossierId().equals(GLOBAL)) {
var version = versions.stream() var version = versions.stream()
.filter(versionRow -> versionRow.getDossierId() .filter(versionRow -> versionRow.getDossierId()
.equals("global") && versionRow.getDossierTemplateId() .equals(GLOBAL) && versionRow.getDossierTemplateId()
.equals(typeEntity.getDossierTemplateId()) && versionRow.getVersionType() == VersionType.DICTIONARY .equals(typeEntity.getDossierTemplateId()) && versionRow.getVersionType() == VersionType.DICTIONARY
.ordinal()) .ordinal())
.findFirst() .findFirst()
@ -980,7 +988,7 @@ public class MigrationService {
var converted = entries.stream().map(entry -> { var converted = entries.stream().map(entry -> {
String typeId = toTypeId(entry.getType(), entry.getDossierTemplateId(), entry.getDossierId() String typeId = toTypeId(entry.getType(), entry.getDossierTemplateId(), entry.getDossierId()
.equals("global") ? null : entry.getDossierId()); .equals(GLOBAL) ? null : entry.getDossierId());
if (!typeForTypeId.containsKey(typeId)) { if (!typeForTypeId.containsKey(typeId)) {
typeForTypeId.put(typeId, typeRepository.getOne(typeId)); typeForTypeId.put(typeId, typeRepository.getOne(typeId));
} }
@ -1030,7 +1038,7 @@ public class MigrationService {
colorsRepository.save(colors); colorsRepository.save(colors);
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
throw new RuntimeException("Could not migrate dossier attributes config"); throw new MigrationException("Could not migrate default colors");
} }
}); });
} }
@ -1048,7 +1056,7 @@ public class MigrationService {
watermarkRepository.save(watermark); watermarkRepository.save(watermark);
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
throw new RuntimeException("Could not migrate dossier attributes config"); throw new MigrationException("Could not migrate watermark");
} }
}); });
} }
@ -1079,7 +1087,7 @@ public class MigrationService {
legalBasisMappingRepository.save(legalBasisMappingEntity); legalBasisMappingRepository.save(legalBasisMappingEntity);
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
throw new RuntimeException("Could not migrate dossier attributes config"); throw new MigrationException("Could not migrate dossier attributes config");
} }
}); });
} }
@ -1110,7 +1118,7 @@ public class MigrationService {
}); });
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
throw new RuntimeException("Could not migrate dossier attributes config"); throw new MigrationException("Could not migrate dossier attributes config");
} }
}); });
return oldIdToNewId; return oldIdToNewId;
@ -1151,7 +1159,7 @@ public class MigrationService {
dossierTemplateRepository.save(dossierTemplate); dossierTemplateRepository.save(dossierTemplate);
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
throw new RuntimeException("Could not migrate dossier attributes config"); throw new MigrationException("Could not migrate file attributes config");
} }
}); });