Skip to content

Commit

Permalink
Improve DO import error message
Browse files Browse the repository at this point in the history
- frontend error message display
- error when DO parent does not exist
  • Loading branch information
mauvaisetroupe committed Dec 25, 2023
1 parent 14c79ae commit fbd97f9
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,36 +121,40 @@ public DataObjectDTO importExcel(InputStream excel) throws IOException {

// Create Data Object from fullpath
if (StringUtils.hasText(dto.getDataobject())) {
String[] dos = dto.getDataobject().split("\\w*>\\w*");
DataObject dataObject = null;
DataObject dataObjectParent = null;
for (int i = 0; i < dos.length; i++) {
String doName = dos[i].trim();
// application in excel file is for DO but also for DO parents
dataObject = findOrCreateDO(doName, dataObjectParent, application);
dataObjectParent = dataObject;
}
dataObject.setBusinessObject(bo);
dataObject.setType(dto.getType());
dataObjectRepository.save(dataObject);

// Create link to Application
if (application != null) {
dataObject.setApplication(application);
dataObjectRepository.save(dataObject);
}
try {
if (application == null) {
dto.setErrorMessage("Application should not be null");
dto.setImportStatus(ImportStatus.ERROR);
throw new IllegalStateException();
}

// create link to landascape
if (dto.getLandscapes() != null && dto.getLandscapes().size() > 0) {
for (String landscapename : dto.getLandscapes()) {
LandscapeView landscape = landscapeViewRepository.findByDiagramNameIgnoreCase(landscapename);
if (landscape == null) {
throw new IllegalStateException("Cannot find landscape " + landscapename);
String[] dos = dto.getDataobject().split("\\w*>\\w*");
DataObject dataObjectParent = null;
if (dos.length > 1) {
dataObjectParent = checkParentExist(dos, application);
if (dataObjectParent == null) {
dto.setErrorMessage("All DataObject parents should be exist and be declared in a previous line");
dto.setImportStatus(ImportStatus.ERROR);
throw new IllegalStateException();
}
}
String dataObjectName = dos[dos.length - 1].trim();
DataObject dataObject = findOrCreateDO(dataObjectName, dataObjectParent, application);

// create link to landascape
if (dto.getLandscapes() != null && dto.getLandscapes().size() > 0) {
for (String landscapename : dto.getLandscapes()) {
LandscapeView landscape = landscapeViewRepository.findByDiagramNameIgnoreCase(landscapename);
if (landscape == null) {
throw new IllegalStateException("Cannot find landscape " + landscapename);
}
dataObject.addLandscapes(landscape);
landscapeViewRepository.save(landscape);
}
dataObject.addLandscapes(landscape);
landscapeViewRepository.save(landscape);
dataObjectRepository.save(dataObject);
}
dataObjectRepository.save(dataObject);
} catch (IllegalStateException e) {
log.error("Error with line " + map);
}
}
result.add(dto);
Expand All @@ -162,6 +166,20 @@ public DataObjectDTO importExcel(InputStream excel) throws IOException {
return dataObjectDTO;
}

private DataObject checkParentExist(String[] dos, Application application) {
DataObject dataObjectParent = null;
DataObject dataObject = null;
for (int i = 0; i < dos.length - 1; i++) {
String doName = dos[i].trim();
dataObject =
dataObjectRepository.findByNameIgnoreCaseAndParentAndApplication(doName, dataObjectParent, application).orElse(null);

if (dataObject == null) return null;
dataObjectParent = dataObject;
}
return dataObject;
}

private BusinessObject findOrCreateBO(BusinessObject parent, String boName) {
BusinessObject bo;
bo =
Expand All @@ -187,6 +205,7 @@ private DataObject findOrCreateDO(String dataObjectName, DataObject parent, Appl
if (dataObj.getId() == null) {
dataObj.setName(dataObjectName);
dataObj.setParent(parent);
dataObj.setApplication(application);
dataObjectRepository.save(dataObj);
}
return dataObj;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class DataObjectImport implements Serializable {
private String dataobject;
private String application;
private DataObjectType type;
private ImportStatus importStatus;
private String errorMessage;

public DataObjectType getType() {
return type;
Expand Down Expand Up @@ -59,9 +61,6 @@ public void setLandscapes(List<String> landscapes) {
this.landscapes = landscapes;
}

private ImportStatus importStatus;
private String errorMessage;

public ImportStatus getImportStatus() {
return importStatus;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,27 @@
<table class="table table-striped">
<thead>
<tr>
<th scope="row"><span>Status</span></th>
<th scope="row"><span>Error Message</span></th>
<th scope="row"><span>Business Object</span></th>
<th scope="row"><span>Data Object</span></th>
<th scope="row"><span>Business Object abstract</span></th>
<th scope="row"><span>Generalization</span></th>
<th scope="row"><span>Application</span></th>
<th scope="row"><span>Landscapes</span></th>
</tr>
</thead>
<tbody>
<tr v-for="(dto, i) in dataObjectDTO.dtos" :key="i" data-cy="entityTable">
<td>
<span :class="[dto.importStatus === 'ERROR' ? 'rederror' : '']">{{ dto.importStatus }}</span>
</td>
<td>{{ dto.errorMessage }}</td>
<td>{{ dto.businessobject }}</td>
<td>{{ dto.dataobject }}</td>
<td>{{ dto.abstractValue }}</td>
<td>{{ dto.generalization }}</td>
<td>{{ dto.application }}</td>
<td>
<span v-for="(landscape, i) in dto.landscapes" :key="i"><span v-if="i > 0">, </span>{{ landscape }}</span>
</td>
Expand All @@ -55,3 +63,9 @@
</template>

<script lang="ts" src="./data-object-import-upload-file.component"></script>
<style>
.rederror {
background-color: red;
color: white;
}
</style>
4 changes: 4 additions & 0 deletions src/main/webapp/app/shared/model/data-objects-import.model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export interface IDataObjectImport {
errorMessage?: string;
importStatus?: string;
businessobject?: string;
generalization?: string;
abstractValue?: boolean;
Expand All @@ -9,6 +11,8 @@ export interface IDataObjectImport {

export class DataObjectImport implements IDataObjectImport {
constructor(
public errorMessage?: string,
public importStatus?: string,
public businessobject?: string,
public generalization?: string,
public abstractValue?: boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ImportDataObjects extends ImportFlowTest {

@Test
@Transactional
void testImportDataObjects() throws EncryptedDocumentException, IOException {
void testImportDataObjectsWithIncorrectLine() throws EncryptedDocumentException, IOException {
String filename = "/junit/05-import-multi-flows-with-capas-and-dataobjects.xlsx";

// Party yes
Expand Down Expand Up @@ -62,6 +62,8 @@ void testImportDataObjects() throws EncryptedDocumentException, IOException {
file = this.getClass().getResourceAsStream(filename);
dataObjectImportService.importExcel(file);

assertEquals(11, dataObjectRepository.findAll().size());

List<DataObject> allCustomerDO = dataObjectRepository.findByNameIgnoreCase("Customer");
assertEquals(4, allCustomerDO.size());

Expand Down Expand Up @@ -95,5 +97,85 @@ void testImportDataObjects() throws EncryptedDocumentException, IOException {
application_0005
);
assertTrue(RiskDOOptional.isPresent());

// Prospect GOLDEN_SOURCE APPLICATION-0001 Payment Landscape
// Prospect READ_ONLY_REPLICA APPLICATION-0002 Payment Landscape
// Prospect > External Assets READ_ONLY_REPLICA APPLICATION-0001 Payment Landscape
// Prospect > External Assets GOLDEN_SOURCE APPLICATION-0002 Payment Landscape
// Prospect > External Assets > Cash GOLDEN_SOURCE APPLICATION-0003 Payment Landscape // INCORRECT
assertEquals(2, dataObjectRepository.findByNameIgnoreCase("Prospect").size());
assertEquals(2, dataObjectRepository.findByNameIgnoreCase("External Assets").size());

for (String appName : new String[] { "APPLICATION-0001", "APPLICATION-0002" }) {
Application app = applicationRepository.findByNameIgnoreCase(appName);
assertThat(
dataObjectRepository
.findByNameIgnoreCaseAndParentAndApplication(
"External Assets",
dataObjectRepository.findByNameIgnoreCaseAndParentAndApplication("Prospect", null, app).orElseThrow(),
app
)
.isPresent()
);
}
}

@Test
@Transactional
void testImportDataObjectsWithCorrectLine() throws EncryptedDocumentException, IOException {
String filename = "/junit/05-import-multi-flows-with-capas-and-dataobjects-corrected.xlsx";

assertEquals(0, applicationRepository.findAll().size());
assertEquals(0, landscapeViewRepository.findAll().size());
assertEquals(0, functionalFlowRepository.findAll().size());

/////////////////////
// Import APPLICATION
/////////////////////
InputStream file = this.getClass().getResourceAsStream(filename);
applicationImportService.importExcel(file, "WE.DONT.CARE.NOT.USED");

///////////////////////////
// Import FLW.01, ... FLW.04
///////////////////////////

file = this.getClass().getResourceAsStream(filename);
flowImportService.importExcelWithMultiFLWSheets(file, "FLW.01");
file = this.getClass().getResourceAsStream(filename);
flowImportService.importExcelWithMultiFLWSheets(file, "FLW.02");
file = this.getClass().getResourceAsStream(filename);
flowImportService.importExcelWithMultiFLWSheets(file, "FLW.03");
file = this.getClass().getResourceAsStream(filename);
flowImportService.importExcelWithMultiFLWSheets(file, "FLW.04");
checkNbLandscapes(4);

file = this.getClass().getResourceAsStream(filename);
dataObjectImportService.importExcel(file);

assertEquals(14, dataObjectRepository.findAll().size());

// Prospect GOLDEN_SOURCE APPLICATION-0001 Payment Landscape
// Prospect READ_ONLY_REPLICA APPLICATION-0002 Payment Landscape
// Prospect > External Assets READ_ONLY_REPLICA APPLICATION-0001 Payment Landscape
// Prospect > External Assets GOLDEN_SOURCE APPLICATION-0002 Payment Landscape
// Prospect GOLDEN_SOURCE APPLICATION-0003 Payment Landscape
// Prospect > External Assets GOLDEN_SOURCE APPLICATION-0003 Payment Landscape
// Prospect > External Assets > Cash GOLDEN_SOURCE APPLICATION-0003 Payment Landscape

assertEquals(3, dataObjectRepository.findByNameIgnoreCase("Prospect").size());
assertEquals(3, dataObjectRepository.findByNameIgnoreCase("External Assets").size());

for (String appName : new String[] { "APPLICATION-0001", "APPLICATION-0002", "APPLICATION-0003" }) {
Application app = applicationRepository.findByNameIgnoreCase(appName);
assertThat(
dataObjectRepository
.findByNameIgnoreCaseAndParentAndApplication(
"External Assets",
dataObjectRepository.findByNameIgnoreCaseAndParentAndApplication("Prospect", null, app).orElseThrow(),
app
)
.isPresent()
);
}
}
}
Binary file not shown.

0 comments on commit fbd97f9

Please sign in to comment.