From bac028e6aaa7b03de270558b0f51e59d80febeb7 Mon Sep 17 00:00:00 2001 From: mauvaisetroupe Date: Sun, 5 Nov 2023 07:28:58 +0100 Subject: [PATCH] Cappability mapping not imported if Level<3 --- .../service/dto/util/CapabilityUtil.java | 87 ++++---- .../ApplicationCapabilityImportService.java | 14 +- .../importfile/CapabilityImportService.java | 202 +++++++++--------- 3 files changed, 152 insertions(+), 151 deletions(-) diff --git a/src/main/java/com/mauvaisetroupe/eadesignit/service/dto/util/CapabilityUtil.java b/src/main/java/com/mauvaisetroupe/eadesignit/service/dto/util/CapabilityUtil.java index 8aaec075..28da35d9 100644 --- a/src/main/java/com/mauvaisetroupe/eadesignit/service/dto/util/CapabilityUtil.java +++ b/src/main/java/com/mauvaisetroupe/eadesignit/service/dto/util/CapabilityUtil.java @@ -5,21 +5,19 @@ import com.mauvaisetroupe.eadesignit.repository.CapabilityRepository; import com.mauvaisetroupe.eadesignit.service.dto.mapper.CapabilityMapper; import com.mauvaisetroupe.eadesignit.service.importfile.dto.CapabilityImportDTO; - import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; -import java.util.Map; import java.util.List; - +import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.util.Assert; @Component public class CapabilityUtil { - + @Autowired CapabilityRepository capabilityRepository; @@ -33,7 +31,7 @@ public Capability buildCapabilityTree(Collection inputs) { public List buildCapabilityTreeWithoutRoot(Collection inputs) { List listOfRoots = buildCapabilityTree(inputs, false); return listOfRoots; - } + } private List buildCapabilityTree(Collection inputs, boolean includeRoots) { // Merge all capabilities finding common parents @@ -44,9 +42,9 @@ private List buildCapabilityTree(Collection inputs, bool List listOfRoots = new ArrayList<>(); if (inputs == null || inputs.isEmpty()) return listOfRoots; - + CapabilityMapper mapper = new CapabilityMapper(); - // Fullpath is not a solution for key, + // Fullpath is not a solution for key, Map capabilityByFullpath = new HashMap<>(); Map capabilityByFullpathAddedInTree = new HashMap<>(); @@ -80,7 +78,7 @@ private List buildCapabilityTree(Collection inputs, bool } if (!includeRoots) { Assert.isTrue(capabilityByFullpathAddedInTree.size() == inputs.size(), "should have the same size"); - } + } return listOfRoots; } @@ -88,24 +86,22 @@ private void addToRootList(List listOfRoots, Capability dto) { // COMMENT SAVOIR SI CEST UN ROOT LOCAL ? if (dto != null) { if (listOfRoots.isEmpty()) { - listOfRoots.add(dto); - } - else { + listOfRoots.add(dto); + } else { Iterator i = listOfRoots.iterator(); boolean stopProcessing = false; - while (i.hasNext() && !stopProcessing) { - Capability rootCapability = i.next(); + while (i.hasNext() && !stopProcessing) { + Capability rootCapability = i.next(); if (getCapabilityFullPath(rootCapability).equals(getCapabilityFullPath(dto))) { - stopProcessing = true; - } - else if (getCapabilityFullPath(rootCapability).contains(getCapabilityFullPath(dto) + " > ")) { + stopProcessing = true; + } else if (getCapabilityFullPath(rootCapability).contains(getCapabilityFullPath(dto) + " > ")) { // root is a child, replace root by DTO i.remove(); - listOfRoots.add(dto); + listOfRoots.add(dto); stopProcessing = true; - } else if (getCapabilityFullPath(dto).contains(getCapabilityFullPath(rootCapability) + " > " )) { + } else if (getCapabilityFullPath(dto).contains(getCapabilityFullPath(rootCapability) + " > ")) { // dto is a child, we keep root and ignore dto - stopProcessing = true; + stopProcessing = true; } } if (!stopProcessing) { @@ -114,7 +110,7 @@ else if (getCapabilityFullPath(rootCapability).contains(getCapabilityFullPath(dt } } } - + public boolean contains(Collection inputs, Capability tmpCapability) { if (tmpCapability == null) return false; for (Capability capability : inputs) { @@ -132,39 +128,44 @@ public String getCapabilityFullPath(Capability capability) { throw new IllegalStateException("Capability hah itself for parent"); } if (tmCapability.getParent() == null) { - Assert.isTrue(tmCapability.getName().equals("ROOT"), "Cannot compute full path if parents are not pessent until ROOT " + capability); + Assert.isTrue( + tmCapability.getName().equals("ROOT"), + "Cannot compute full path if parents are not pessent until ROOT " + capability + ); } buffer.insert(0, sep).insert(0, tmCapability.getName()); tmCapability = tmCapability.getParent(); sep = " > "; } return buffer.toString(); - } + } - public String getCapabilityFullPath(CapabilityImportDTO importDTO) { + public String getCapabilityFullPath(CapabilityImportDTO importDTO, boolean replaceNullInPath) { StringBuilder buffer = new StringBuilder(); String sep = ""; for (Capability capability : importDTO.getCapabilityList()) { - buffer.append(sep).append(capability != null ? capability.getName() : " --- "); - sep = " > "; + if (replaceNullInPath || capability != null) { + buffer.append(sep).append(capability != null ? capability.getName() : " --- "); + } + sep = " > "; } return buffer.toString(); - } + } - public Map initCapabilitiesByNameFromDB() { - Map capabilitiesByFllPath = new HashMap<>(); + public Map initCapabilitiesByNameFromDB() { + Map capabilitiesByFllPath = new HashMap<>(); List allCapabilities = capabilityRepository.findAllWithSubCapabilities(); for (Capability capability : allCapabilities) { capabilitiesByFllPath.put(getCapabilityFullPath(capability), capability); - } - return capabilitiesByFllPath; - } + } + return capabilitiesByFllPath; + } public CapabilityImportDTO getCapabilityImportDTO(String fullPath) { Capability domain = null, l0Import = null, l1Import = null, l2Import = null, l3Import = null; String[] capabilitiesName = fullPath.split(" > "); Capability root = new Capability("ROOT", -2); - if (capabilitiesName.length > 0) domain = new Capability(capabilitiesName[0], -1); + if (capabilitiesName.length > 0) domain = new Capability(capabilitiesName[0], -1); if (capabilitiesName.length > 1) l0Import = new Capability(capabilitiesName[1], 0); if (capabilitiesName.length > 2) l1Import = new Capability(capabilitiesName[2], 1); if (capabilitiesName.length > 3) l2Import = new Capability(capabilitiesName[3], 2); @@ -174,20 +175,24 @@ public CapabilityImportDTO getCapabilityImportDTO(String fullPath) { } public CapabilityImportDTO buildImportDTO(Capability capability, String error, ImportStatus status) { - Capability[] capabilities = {null, null, null, null, null, null}; - capabilities[0] = new Capability("ROOT",-2); + Capability[] capabilities = { null, null, null, null, null, null }; + capabilities[0] = new Capability("ROOT", -2); Capability tmp = capability; - for (int level = capability.getLevel(); level >= 0 ; level--) { - capabilities[level+2] = tmp; - tmp = capability.getParent(); - } + for (int level = capability.getLevel(); level >= 0; level--) { + capabilities[level + 2] = tmp; + tmp = capability.getParent(); + } CapabilityImportDTO capabilityImportDTO = new CapabilityImportDTO( - capabilities[0], capabilities[1], capabilities[2], capabilities[3], capabilities[4], capabilities[5] + capabilities[0], + capabilities[1], + capabilities[2], + capabilities[3], + capabilities[4], + capabilities[5] ); capabilityImportDTO.setError(error); capabilityImportDTO.setStatus(status); return capabilityImportDTO; - } - + } } diff --git a/src/main/java/com/mauvaisetroupe/eadesignit/service/importfile/ApplicationCapabilityImportService.java b/src/main/java/com/mauvaisetroupe/eadesignit/service/importfile/ApplicationCapabilityImportService.java index 6709c7d3..7ab75578 100644 --- a/src/main/java/com/mauvaisetroupe/eadesignit/service/importfile/ApplicationCapabilityImportService.java +++ b/src/main/java/com/mauvaisetroupe/eadesignit/service/importfile/ApplicationCapabilityImportService.java @@ -62,8 +62,7 @@ public List importExcel(InputStream excel, String // remove mapping from landscape and delete CapabilityMapping if not refernced by another landscape Set capabilityApplicationMappings = new HashSet<>(landscape.getCapabilityApplicationMappings()); - for (CapabilityApplicationMapping cm : capabilityApplicationMappings) { - + for (CapabilityApplicationMapping cm : capabilityApplicationMappings) { // remove capabilityMapping from landscape landscape.removeCapabilityApplicationMapping(cm); @@ -71,10 +70,9 @@ public List importExcel(InputStream excel, String if (cm.getLandscapes() == null || cm.getLandscapes().isEmpty()) { capabilityApplicationMappingRepository.delete(cm); } - } - Map capabilitiesByFullPath = capabilityUtil.initCapabilitiesByNameFromDB(); + Map capabilitiesByFullPath = capabilityUtil.initCapabilitiesByNameFromDB(); List> capabilitiesDF = capabilityFlowExcelReader.getSheet(sheetname); for (Map map : capabilitiesDF) { @@ -86,7 +84,7 @@ public List importExcel(InputStream excel, String itemDTO.setApplicationNames(mapArrayToString(map)); // fullpath from ecel does not inclute ROOT > - Capability capability = capabilitiesByFullPath.get(capabilityUtil.getCapabilityFullPath(capabilityImportDTO)); + Capability capability = capabilitiesByFullPath.get(capabilityUtil.getCapabilityFullPath(capabilityImportDTO, false)); List applications = findApplication(map, itemDTO); if (applications.isEmpty()) { @@ -101,10 +99,8 @@ public List importExcel(InputStream excel, String log.error(error); } else { for (Application application : applications) { - CapabilityApplicationMapping capabilityApplicationMapping = capabilityApplicationMappingRepository.findByApplicationAndCapability( - application, - capability - ); + CapabilityApplicationMapping capabilityApplicationMapping = + capabilityApplicationMappingRepository.findByApplicationAndCapability(application, capability); if (capabilityApplicationMapping == null) { capabilityApplicationMapping = new CapabilityApplicationMapping(); capabilityApplicationMappingRepository.save(capabilityApplicationMapping); diff --git a/src/main/java/com/mauvaisetroupe/eadesignit/service/importfile/CapabilityImportService.java b/src/main/java/com/mauvaisetroupe/eadesignit/service/importfile/CapabilityImportService.java index 157cbcb4..c7d30bed 100644 --- a/src/main/java/com/mauvaisetroupe/eadesignit/service/importfile/CapabilityImportService.java +++ b/src/main/java/com/mauvaisetroupe/eadesignit/service/importfile/CapabilityImportService.java @@ -7,10 +7,9 @@ import com.mauvaisetroupe.eadesignit.repository.CapabilityRepository; import com.mauvaisetroupe.eadesignit.service.dto.util.CapabilityUtil; import com.mauvaisetroupe.eadesignit.service.importfile.dto.CapabilityAction; +import com.mauvaisetroupe.eadesignit.service.importfile.dto.CapabilityAction.Action; import com.mauvaisetroupe.eadesignit.service.importfile.dto.CapabilityImportAnalysisDTO; import com.mauvaisetroupe.eadesignit.service.importfile.dto.CapabilityImportDTO; -import com.mauvaisetroupe.eadesignit.service.importfile.dto.CapabilityAction.Action; - import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; @@ -21,7 +20,6 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; - import org.apache.commons.lang3.StringUtils; import org.apache.poi.EncryptedDocumentException; import org.slf4j.Logger; @@ -40,7 +38,6 @@ public class CapabilityImportService { @Autowired private CapabilityRepository capabilityRepository; - @Autowired private CapabilityApplicationMappingRepository applicationMappingRepository; @@ -56,23 +53,22 @@ public class CapabilityImportService { public static final String L3_NAME = "Capability L3"; public static final String L3_DESCRIPTION = "L3 - Description"; public static final String SUR_DOMAIN = "Sur-domaine"; - public static final String SUR_DOMAIN_DESCRIPTION = "Sur-domaine Description"; + public static final String SUR_DOMAIN_DESCRIPTION = "Sur-domaine Description"; public static final String FULL_PATH = "full.path"; - public CapabilityImportAnalysisDTO analyzeExcel(InputStream excel, String originalFilename) throws EncryptedDocumentException, IOException { - + public CapabilityImportAnalysisDTO analyzeExcel(InputStream excel, String originalFilename) + throws EncryptedDocumentException, IOException { CapabilityImportAnalysisDTO analysisDTO = new CapabilityImportAnalysisDTO(); ExcelReader capabilityFlowExcelReader = new ExcelReader(excel); List> capabilitiesDF = capabilityFlowExcelReader.getSheet(CAPABILITY_SHEET_NAME); - // Capabilities from DB - Map capabilitiesFromDBByFullPath = capabilityUtil.initCapabilitiesByNameFromDB(); - + Map capabilitiesFromDBByFullPath = capabilityUtil.initCapabilitiesByNameFromDB(); + // Capabilities fromExcel - Map capabilitiesFromExcelByFullPath = initCapabilitiesByNameFromExcel(capabilitiesDF); + Map capabilitiesFromExcelByFullPath = initCapabilitiesByNameFromExcel(capabilitiesDF); - // Errors from Excel + // Errors from Excel analysisDTO.setErrorLines(getErrorLines(capabilitiesDF)); List onlyInExcel = new ArrayList<>(capabilitiesFromExcelByFullPath.keySet()); @@ -80,13 +76,19 @@ public CapabilityImportAnalysisDTO analyzeExcel(InputStream excel, String origi List onlyInDatabase = new ArrayList<>(capabilitiesFromDBByFullPath.keySet()); onlyInDatabase.removeAll(capabilitiesFromExcelByFullPath.keySet()); - + List inBothExcelAndDatabase = new ArrayList<>(capabilitiesFromDBByFullPath.keySet()); inBothExcelAndDatabase.removeAll(onlyInDatabase); inBothExcelAndDatabase.removeAll(onlyInExcel); - Assert.isTrue(capabilitiesFromDBByFullPath.size() == inBothExcelAndDatabase.size() + onlyInDatabase.size(), "Should have same size"); - Assert.isTrue(capabilitiesFromExcelByFullPath.size() == inBothExcelAndDatabase.size() + onlyInExcel.size() , "Should have same size"); + Assert.isTrue( + capabilitiesFromDBByFullPath.size() == inBothExcelAndDatabase.size() + onlyInDatabase.size(), + "Should have same size" + ); + Assert.isTrue( + capabilitiesFromExcelByFullPath.size() == inBothExcelAndDatabase.size() + onlyInExcel.size(), + "Should have same size" + ); /////////////// UPDATE DSECRIPTION for (String fullpath : inBothExcelAndDatabase) { @@ -101,32 +103,32 @@ public CapabilityImportAnalysisDTO analyzeExcel(InputStream excel, String origi /////////////// CAPABILITIES TO ADD analysisDTO.setCapabilitiesToAdd( - capabilityUtil.buildCapabilityTreeWithoutRoot( - onlyInExcel.stream() - .map(fullpath -> capabilitiesFromExcelByFullPath.get(fullpath)) - .collect(Collectors.toList())) - .stream() - .sorted(Comparator.comparing(c -> capabilityUtil.getCapabilityFullPath(c))) - .map(c -> new CapabilityAction(c, Action.ADD)) - .collect(Collectors.toList()) + capabilityUtil + .buildCapabilityTreeWithoutRoot( + onlyInExcel.stream().map(fullpath -> capabilitiesFromExcelByFullPath.get(fullpath)).collect(Collectors.toList()) + ) + .stream() + .sorted(Comparator.comparing(c -> capabilityUtil.getCapabilityFullPath(c))) + .map(c -> new CapabilityAction(c, Action.ADD)) + .collect(Collectors.toList()) ); - + // Prepare Capabilities to delete - List capabilitiesToDeleteWithMapping = - onlyInDatabase.stream() + List capabilitiesToDeleteWithMapping = onlyInDatabase + .stream() .map(fullpath -> capabilitiesFromDBByFullPath.get(fullpath)) .filter(capability -> hasMapping(capability)) .collect(Collectors.toList()); - List capabilitiesToDeleteWithChildWithMapping = - onlyInDatabase.stream() + List capabilitiesToDeleteWithChildWithMapping = onlyInDatabase + .stream() .map(fullpath -> capabilitiesFromDBByFullPath.get(fullpath)) .filter(capability -> hasChildToDeleteWithMapping(capability, capabilitiesToDeleteWithMapping)) .collect(Collectors.toList()); - - List capabilitiesToDelete = onlyInDatabase.stream() + List capabilitiesToDelete = onlyInDatabase + .stream() .map(fullpath -> capabilitiesFromDBByFullPath.get(fullpath)) .filter(capability -> !hasMapping(capability)) .filter(capability -> !hasChildToDeleteWithMapping(capability, capabilitiesToDeleteWithMapping)) @@ -135,46 +137,52 @@ public CapabilityImportAnalysisDTO analyzeExcel(InputStream excel, String origi //////////////// CAPABILITIES TO DELETE analysisDTO.setCapabilitiesToDelete( - capabilityUtil.buildCapabilityTreeWithoutRoot(capabilitiesToDelete) - .stream() - .sorted(Comparator.comparing(c -> capabilityUtil.getCapabilityFullPath(c))) - .map(c -> new CapabilityAction(c, Action.DELETE)) - .collect(Collectors.toList()) + capabilityUtil + .buildCapabilityTreeWithoutRoot(capabilitiesToDelete) + .stream() + .sorted(Comparator.comparing(c -> capabilityUtil.getCapabilityFullPath(c))) + .map(c -> new CapabilityAction(c, Action.DELETE)) + .collect(Collectors.toList()) ); //////////////// CAPABILITIES TO DELETE WITH MAPPING analysisDTO.setCapabilitiesToDeleteWithMappings( capabilitiesToDeleteWithMapping - .stream() - .sorted(Comparator.comparing(c -> capabilityUtil.getCapabilityFullPath(c))) - .map(c -> new CapabilityAction(c, Action.FORCE_DELETE)) - .collect(Collectors.toList()) - ); - // do not group in order to move separately + .stream() + .sorted(Comparator.comparing(c -> capabilityUtil.getCapabilityFullPath(c))) + .map(c -> new CapabilityAction(c, Action.FORCE_DELETE)) + .collect(Collectors.toList()) + ); + // do not group in order to move separately ////////////////// ANCESTORS OF CAPABILITIES WITH MAPPPINGS - + analysisDTO.setAncestorsOfCapabilitiesWithMappings( - capabilityUtil.buildCapabilityTreeWithoutRoot(capabilitiesToDeleteWithChildWithMapping) - .stream() - .sorted(Comparator.comparing(c -> capabilityUtil.getCapabilityFullPath(c))) - .map(c -> new CapabilityAction(c, Action.IGNORE)) - .collect(Collectors.toList()) + capabilityUtil + .buildCapabilityTreeWithoutRoot(capabilitiesToDeleteWithChildWithMapping) + .stream() + .sorted(Comparator.comparing(c -> capabilityUtil.getCapabilityFullPath(c))) + .map(c -> new CapabilityAction(c, Action.IGNORE)) + .collect(Collectors.toList()) ); return analysisDTO; } - - private boolean hasChildToDeleteWithMapping(Capability capability, List capabilitiesToDeleteWithMapping) { + + private boolean hasChildToDeleteWithMapping(Capability capability, List capabilitiesToDeleteWithMapping) { return hasChildToDeleteWithMapping(capability, capabilitiesToDeleteWithMapping, true); } - private boolean hasChildToDeleteWithMapping(Capability capability, List capabilitiesToDeleteWithMapping, boolean isFirstCapability) { + private boolean hasChildToDeleteWithMapping( + Capability capability, + List capabilitiesToDeleteWithMapping, + boolean isFirstCapability + ) { if (!isFirstCapability && capabilityUtil.contains(capabilitiesToDeleteWithMapping, capability)) { return true; } if (capability.getSubCapabilities() != null && !capability.getSubCapabilities().isEmpty()) { - for (Capability child : capability.getSubCapabilities()) { + for (Capability child : capability.getSubCapabilities()) { if (hasChildToDeleteWithMapping(child, capabilitiesToDeleteWithMapping, false)) { return true; } @@ -186,28 +194,27 @@ private boolean hasChildToDeleteWithMapping(Capability capability, List getErrorLines(List> capabilitiesDF) { - List errors = new ArrayList<>(); - Capability rootImport = new Capability("ROOT", -2); + Capability rootImport = new Capability("ROOT", -2); for (Map map : capabilitiesDF) { CapabilityImportDTO capabilityImportDTO = getDTOFromExcel(rootImport, map); if (!checkLineIsValid(capabilityImportDTO)) { - errors.add(capabilityUtil.getCapabilityFullPath(capabilityImportDTO)); + errors.add(capabilityUtil.getCapabilityFullPath(capabilityImportDTO, true)); } } return errors; } - private Map initCapabilitiesByNameFromExcel(List> capabilitiesDF) throws EncryptedDocumentException, IOException { - - Map capabilitiesByFullPath = new HashMap<>(); - - Capability rootImport = new Capability("ROOT", -2); + private Map initCapabilitiesByNameFromExcel(List> capabilitiesDF) + throws EncryptedDocumentException, IOException { + Map capabilitiesByFullPath = new HashMap<>(); + + Capability rootImport = new Capability("ROOT", -2); for (Map map : capabilitiesDF) { CapabilityImportDTO capabilityImportDTO = getDTOFromExcel(rootImport, map); if (checkLineIsValid(capabilityImportDTO)) { @@ -215,62 +222,58 @@ private Map initCapabilitiesByNameFromExcel(List confirmImport(CapabilityImportAnalysisDTO analysisDTO) { + public List confirmImport(CapabilityImportAnalysisDTO analysisDTO) { List capabilityImportDTOs = new ArrayList<>(); - + // UPDATE existing - // Add new capabilities + // Add new capabilities for (CapabilityAction capabilityAction : analysisDTO.getCapabilitiesToAdd()) { - if (capabilityAction.getAction() == Action.ADD) { + if (capabilityAction.getAction() == Action.ADD) { // Find a persisted parent capabilityAction.getCapability().setParent(findPersistedParent(capabilityAction.getCapability())); persistCapabilityTree(capabilityAction.getCapability()); capabilityImportDTOs.add(capabilityUtil.buildImportDTO(capabilityAction.getCapability(), "ADDED", ImportStatus.NEW)); - } - else if (capabilityAction.getAction() == Action.IGNORE){ + } else if (capabilityAction.getAction() == Action.IGNORE) { capabilityImportDTOs.add(capabilityUtil.buildImportDTO(capabilityAction.getCapability(), "Ignored", ImportStatus.ERROR)); } } - // Delete capabilities + // Delete capabilities List doDelete = new ArrayList<>(); for (CapabilityAction capabilityAction : analysisDTO.getCapabilitiesToDelete()) { - if (capabilityAction.getAction() == Action.DELETE) { + if (capabilityAction.getAction() == Action.DELETE) { // Find a persisted parent capabilityAction.getCapability().setParent(findPersistedParent(capabilityAction.getCapability())); capabilityImportDTOs.add(capabilityUtil.buildImportDTO(capabilityAction.getCapability(), "DELETED", ImportStatus.UPDATED)); doDelete.add(capabilityAction.getCapability()); - } - else if (capabilityAction.getAction() == Action.IGNORE){ + } else if (capabilityAction.getAction() == Action.IGNORE) { capabilityImportDTOs.add(capabilityUtil.buildImportDTO(capabilityAction.getCapability(), "Ignored", ImportStatus.ERROR)); } } deleteCapabilityTrees(doDelete, false); - // Delete capabilities with mappings + // Delete capabilities with mappings // doDelete = new ArrayList<>(); for (CapabilityAction capabilityAction : analysisDTO.getCapabilitiesToDeleteWithMappings()) { - if (capabilityAction.getAction() == Action.FORCE_DELETE) { + if (capabilityAction.getAction() == Action.FORCE_DELETE) { // Find a persisted parent capabilityAction.getCapability().setParent(findPersistedParent(capabilityAction.getCapability())); capabilityImportDTOs.add(capabilityUtil.buildImportDTO(capabilityAction.getCapability(), "DELETED", ImportStatus.UPDATED)); doDelete.add(capabilityAction.getCapability()); - } - else if (capabilityAction.getAction() == Action.IGNORE){ + } else if (capabilityAction.getAction() == Action.IGNORE) { capabilityImportDTOs.add(capabilityUtil.buildImportDTO(capabilityAction.getCapability(), "Ignored", ImportStatus.ERROR)); } } @@ -285,19 +288,18 @@ private void deleteCapabilityTrees(List doDelete, boolean deleteMapp } } - private void deleteCapabilityTrees(Capability capability, boolean deleteMappings) { - + private void deleteCapabilityTrees(Capability capability, boolean deleteMappings) { //Delete children recursively List children = new ArrayList<>(capability.getSubCapabilities()); - if (children!=null) { + if (children != null) { for (Capability child : children) { deleteCapabilityTrees(child, deleteMappings); } } - - // Detach parent + + // Detach parent Capability parent = capability.getParent(); - if (parent!=null) { + if (parent != null) { parent.removeSubCapabilities(capability); capabilityRepository.save(parent); capabilityRepository.save(capability); @@ -316,61 +318,59 @@ private void deleteCapabilityTrees(Capability capability, boolean deleteMapping } } } - + // Delete capability capabilityRepository.delete(capability); } private void persistCapabilityTree(Capability capability) { capabilityRepository.save(capability); - if (capability!=null && capability.getSubCapabilities()!=null) { + if (capability != null && capability.getSubCapabilities() != null) { for (Capability child : capability.getSubCapabilities()) { - persistCapabilityTree(child); + persistCapabilityTree(child); } } } private Capability findPersistedParent(Capability capability) { - if (capability.getParent()!=null) { + if (capability.getParent() != null) { List potemtials = capabilityRepository.findByNameIgnoreCaseAndLevel( - capability.getParent().getName(), - capability.getParent().getLevel() + capability.getParent().getName(), + capability.getParent().getLevel() ); if (potemtials.size() == 1) { return potemtials.get(0); - } - else if (potemtials.size() > 1) { + } else if (potemtials.size() > 1) { for (Capability potential : potemtials) { - if (potential.getParent().getName().equals(capability.getParent().getParent().getName())) { - return potential; - } + if (potential.getParent().getName().equals(capability.getParent().getParent().getName())) { + return potential; + } } throw new IllegalStateException("Multiple potential parents"); } - } + } return null; } - private CapabilityImportDTO getDTOFromExcel(Capability rootImport, Map map) { // new capability created from excel, without parent assigned Capability domainImport = null, l0Import = null, l1Import = null, l2Import = null, l3Import = null; - if (map.get(SUR_DOMAIN) != null) domainImport = new Capability((String) map.get(SUR_DOMAIN), -1, (String) map.get(SUR_DOMAIN_DESCRIPTION)); + if (map.get(SUR_DOMAIN) != null) domainImport = + new Capability((String) map.get(SUR_DOMAIN), -1, (String) map.get(SUR_DOMAIN_DESCRIPTION)); if (map.get(L0_NAME) != null) l0Import = new Capability((String) map.get(L0_NAME), 0, (String) map.get(L0_DESCRIPTION)); if (map.get(L1_NAME) != null) l1Import = new Capability((String) map.get(L1_NAME), 1, (String) map.get(L1_DESCRIPTION)); if (map.get(L2_NAME) != null) l2Import = new Capability((String) map.get(L2_NAME), 2, (String) map.get(L2_DESCRIPTION)); if (map.get(L3_NAME) != null) l3Import = new Capability((String) map.get(L3_NAME), 3, (String) map.get(L3_DESCRIPTION)); - CapabilityImportDTO capabilityImportDTO = new CapabilityImportDTO(rootImport, domainImport,l0Import, l1Import, l2Import, l3Import); + CapabilityImportDTO capabilityImportDTO = new CapabilityImportDTO(rootImport, domainImport, l0Import, l1Import, l2Import, l3Import); return capabilityImportDTO; } private boolean checkLineIsValid(CapabilityImportDTO capabilityImport) { boolean nullFound = false; for (Capability capability : capabilityImport.getCapabilityList()) { - if (capability!=null && nullFound) return false; + if (capability != null && nullFound) return false; if (capability == null) nullFound = true; } return true; } - }