From 3f94d393ca1207664351c065e01538b26bb98637 Mon Sep 17 00:00:00 2001 From: mauvaisetroupe Date: Sun, 5 Nov 2023 21:03:47 +0100 Subject: [PATCH] 2 DO can exist if on 2 different applications --- .../repository/DataObjectRepository.java | 8 ++++++-- .../importfile/DataObjectImportService.java | 14 ++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/mauvaisetroupe/eadesignit/repository/DataObjectRepository.java b/src/main/java/com/mauvaisetroupe/eadesignit/repository/DataObjectRepository.java index 37de257b..43318476 100644 --- a/src/main/java/com/mauvaisetroupe/eadesignit/repository/DataObjectRepository.java +++ b/src/main/java/com/mauvaisetroupe/eadesignit/repository/DataObjectRepository.java @@ -45,7 +45,11 @@ default Page findAllWithEagerRelationships(Pageable pageable) { ) Optional findOneWithToOneRelationships(@Param("id") Long id); - Optional findByNameIgnoreCase(String boName); + Optional findByNameIgnoreCaseAndApplicationNameIgnoreCase(String boName, String appliName); - Optional findByNameIgnoreCaseAndParentNameIgnoreCase(String boName, String name); + Optional findByNameIgnoreCaseAndParentNameIgnoreCaseAndApplicationNameIgnoreCase( + String boName, + String parentName, + String appliName + ); } diff --git a/src/main/java/com/mauvaisetroupe/eadesignit/service/importfile/DataObjectImportService.java b/src/main/java/com/mauvaisetroupe/eadesignit/service/importfile/DataObjectImportService.java index a31d89c0..47b05564 100644 --- a/src/main/java/com/mauvaisetroupe/eadesignit/service/importfile/DataObjectImportService.java +++ b/src/main/java/com/mauvaisetroupe/eadesignit/service/importfile/DataObjectImportService.java @@ -116,7 +116,7 @@ public DataObjectDTO importExcel(InputStream excel) throws IOException { DataObject dataObjectParent = null; for (int i = 0; i < dos.length; i++) { String doName = dos[i].trim(); - dataObject = findOrCreateDO(dataObjectParent, doName); + dataObject = findOrCreateDO(dataObjectParent, doName, dto.getApplication()); dataObjectParent = dataObject; } dataObject.setBusinessObject(bo); @@ -172,14 +172,16 @@ private BusinessObject findOrCreateBO(BusinessObject parent, String boName) { return bo; } - private DataObject findOrCreateDO(DataObject parent, String dataObjectName) { + private DataObject findOrCreateDO(DataObject parent, String dataObjectName, String applicationName) { DataObject dataObj; dataObj = ((parent == null) - ? dataObjectRepository.findByNameIgnoreCase(dataObjectName) - : dataObjectRepository.findByNameIgnoreCaseAndParentNameIgnoreCase(dataObjectName, parent.getName())).orElseGet( - DataObject::new - ); + ? dataObjectRepository.findByNameIgnoreCaseAndApplicationNameIgnoreCase(dataObjectName, applicationName) + : dataObjectRepository.findByNameIgnoreCaseAndParentNameIgnoreCaseAndApplicationNameIgnoreCase( + dataObjectName, + parent.getName(), + applicationName + )).orElseGet(DataObject::new); if (dataObj.getId() == null) { dataObj.setName(dataObjectName); dataObj.setParent(parent);