From 608c601bd50890ba3c9170cb1b12fe5f9e40820a Mon Sep 17 00:00:00 2001 From: Reguel Wermelinger Date: Tue, 24 Oct 2023 16:24:12 +0200 Subject: [PATCH] introduce an 'edit' field --- .../util/excel/test/TestDialogCreator.java | 41 ++++++++++++------- .../util/excel/importer/DialogCreator.java | 7 ++-- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/excel-importer-test/src_test/com/axonivy/util/excel/test/TestDialogCreator.java b/excel-importer-test/src_test/com/axonivy/util/excel/test/TestDialogCreator.java index ce224dc..c016a74 100644 --- a/excel-importer-test/src_test/com/axonivy/util/excel/test/TestDialogCreator.java +++ b/excel-importer-test/src_test/com/axonivy/util/excel/test/TestDialogCreator.java @@ -24,6 +24,8 @@ import ch.ivyteam.ivy.process.model.Process; import ch.ivyteam.ivy.process.model.element.activity.Script; import ch.ivyteam.ivy.process.model.element.event.start.dialog.html.HtmlDialogMethodStart; +import ch.ivyteam.ivy.scripting.dataclass.IDataClass; +import ch.ivyteam.ivy.scripting.dataclass.IDataClassField; import ch.ivyteam.ivy.scripting.dataclass.IEntityClass; @IvyTest @@ -48,20 +50,9 @@ void createEntityDialog(@TempDir Path dir) throws IOException, CoreException { String unit = "testing"; dialog = new DialogCreator().createDialog(customer, unit); - Process process = dialog.getProcess(null).getModel(); - Script loader = process.search().type(Script.class).findOne(); - assertThat(loader.getCode()).contains(customer.getName()); - var delete = process.search().type(HtmlDialogMethodStart.class).findOne(); - String removal = delete.getOutput().getCode(); - assertThat(removal) - .contains("testing.remove("); - - var view = read(dialog.getViewFile()); - assertThat(view).contains("p:dataTable"); - assertThat(view) - .as("visualizes properties of the entity") - .contains("firstname") - .doesNotContain(""); + assertData(dialog.getDataClass(null)); + assertProcess(customer, dialog.getProcess(null).getModel()); + assertView(read(dialog.getViewFile())); } finally { customer.getResource().delete(true, new NullProgressMonitor()); @@ -71,6 +62,28 @@ void createEntityDialog(@TempDir Path dir) throws IOException, CoreException { } } + private void assertData(IDataClass dataClass) { + assertThat(dataClass.getFields()).extracting(IDataClassField::getName) + .containsOnly("entries", "edit"); + } + + private void assertProcess(IEntityClass customer, Process process) { + Script loader = process.search().type(Script.class).findOne(); + assertThat(loader.getCode()).contains(customer.getName()); + var delete = process.search().type(HtmlDialogMethodStart.class).findOne(); + String removal = delete.getOutput().getCode(); + assertThat(removal) + .contains("testing.remove("); + } + + private void assertView(String view) { + assertThat(view).contains("p:dataTable"); + assertThat(view) + .as("visualizes properties of the entity") + .contains("firstname") + .doesNotContain(""); + } + private static String read(IFile viewFile) throws IOException, CoreException { try(InputStream in = viewFile.getContents()) { var bos = new java.io.ByteArrayOutputStream(); diff --git a/excel-importer/src/com/axonivy/util/excel/importer/DialogCreator.java b/excel-importer/src/com/axonivy/util/excel/importer/DialogCreator.java index 2c072bf..380406a 100644 --- a/excel-importer/src/com/axonivy/util/excel/importer/DialogCreator.java +++ b/excel-importer/src/com/axonivy/util/excel/importer/DialogCreator.java @@ -41,13 +41,14 @@ public IUserDialog createDialog(IEntityClass entity, String unit) { var target = dialogStartFor(entity); VariableDesc entries = new VariableDesc("entries", new QualifiedType(List.class.getName(), List.of(new QualifiedType(entity.getName())))); + VariableDesc edit = new VariableDesc("edit", new QualifiedType(entity.getName())); prepareTemplate(project, "frame-10"); String dialogId = target.getId().getRawId(); var params = new DialogCreationParameters.Builder(project, dialogId) .viewTechId(IvyConstants.VIEW_TECHONOLOGY_JSF) .signature(target.getStartMethod()) - .dataClassFields(List.of(entries)) + .dataClassFields(List.of(entries, edit)) .toCreationParams(); var userDialog = local.createProjectUserDialog(params, null); @@ -90,12 +91,12 @@ private void extendView(IFile viewFile, IEntityClass entity) { private String renderFields(IEntityClass entity, String template) { String fieldXhtml = entity.getFields().stream() .filter(fld -> !fld.getName().equals("id")) - .map(this::htmlview) + .map(this::renderColumn) .collect(Collectors.joining("\n")); return template.replace("", fieldXhtml); } - private String htmlview(IEntityClassField field) { + private String renderColumn(IEntityClassField field) { String fieldXhtml = """