Skip to content

Commit

Permalink
2 DO can exist if on 2 different applications
Browse files Browse the repository at this point in the history
  • Loading branch information
mauvaisetroupe committed Nov 5, 2023
1 parent 24ba44f commit 3f94d39
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ default Page<DataObject> findAllWithEagerRelationships(Pageable pageable) {
)
Optional<DataObject> findOneWithToOneRelationships(@Param("id") Long id);

Optional<DataObject> findByNameIgnoreCase(String boName);
Optional<DataObject> findByNameIgnoreCaseAndApplicationNameIgnoreCase(String boName, String appliName);

Optional<DataObject> findByNameIgnoreCaseAndParentNameIgnoreCase(String boName, String name);
Optional<DataObject> findByNameIgnoreCaseAndParentNameIgnoreCaseAndApplicationNameIgnoreCase(
String boName,
String parentName,
String appliName
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3f94d39

Please sign in to comment.