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 c016a74..fd9a6c7 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 @@ -9,6 +9,7 @@ import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; import org.junit.jupiter.api.BeforeEach; @@ -24,6 +25,7 @@ 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.process.model.element.value.Mappings; import ch.ivyteam.ivy.scripting.dataclass.IDataClass; import ch.ivyteam.ivy.scripting.dataclass.IDataClassField; import ch.ivyteam.ivy.scripting.dataclass.IEntityClass; @@ -53,6 +55,8 @@ void createEntityDialog(@TempDir Path dir) throws IOException, CoreException { assertData(dialog.getDataClass(null)); assertProcess(customer, dialog.getProcess(null).getModel()); assertView(read(dialog.getViewFile())); + var udRoot = (IFolder) dialog.getResource(); + assertDetailView(read(udRoot.getFile("EntityDetail.xhtml"))); } finally { customer.getResource().delete(true, new NullProgressMonitor()); @@ -70,10 +74,16 @@ private void assertData(IDataClass dataClass) { 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(); + + var delete = process.search().type(HtmlDialogMethodStart.class).name("delete(customer)").findOne(); String removal = delete.getOutput().getCode(); assertThat(removal) .contains("testing.remove("); + + var edit = process.search().type(HtmlDialogMethodStart.class).name("edit(customer)").findOne(); + Mappings mappings = edit.getOutput().getMappings(); + assertThat(mappings.asList()) + .hasSize(1); } private void assertView(String view) { @@ -84,6 +94,13 @@ private void assertView(String view) { .doesNotContain(""); } + private void assertDetailView(String view) { + 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 380406a..8f78763 100644 --- a/excel-importer/src/com/axonivy/util/excel/importer/DialogCreator.java +++ b/excel-importer/src/com/axonivy/util/excel/importer/DialogCreator.java @@ -6,9 +6,11 @@ import java.io.InputStream; import java.util.List; import java.util.Optional; +import java.util.function.Function; import java.util.stream.Collectors; import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; import ch.ivyteam.ivy.IvyConstants; @@ -57,10 +59,19 @@ public IUserDialog createDialog(IEntityClass entity, String unit) { processRdm.save(); extendView(userDialog.getViewFile(), entity); + detailView(userDialog, entity); return userDialog; } + private void detailView(IUserDialog userDialog, IEntityClass entity) { + String template = readTemplate("EntityDetail.xhtml"); + String rendered = renderFields(entity, template, this::renderDetail); + var dir = (IFolder) userDialog.getResource(); + var detailView = dir.getFile("EntityDetail.xhtml"); + write(detailView, rendered); + } + private void prepareTemplate(IProject project, String template) { try { var view = ch.ivyteam.ivy.dialog.ui.ViewTechnologyDesignerUiRegistry.getInstance().getViewTechnology(IvyConstants.VIEW_TECHONOLOGY_JSF); @@ -74,24 +85,34 @@ private void prepareTemplate(IProject project, String template) { } private void extendView(IFile viewFile, IEntityClass entity) { - try(InputStream is = DialogCreator.class.getResourceAsStream("/com/axonivy/util/excel/importer/EntityManager/EntityManager.xhtml")) { + String template = readTemplate("EntityManager.xhtml"); + String rendered = renderFields(entity, template, this::renderColumn); + write(viewFile, rendered); + } + + private static String readTemplate(String resource) { + try(InputStream is = DialogCreator.class.getResourceAsStream("/com/axonivy/util/excel/importer/EntityManager/"+resource)) { var bos = new ByteArrayOutputStream(); is.transferTo(bos); var template = new String(bos.toByteArray()); + return template; + } catch (Exception ex) { + throw new RuntimeException("Failed to read template "+resource); + } + } - String rendered = renderFields(entity, template); - - var bis = new ByteArrayInputStream(rendered.getBytes()); - viewFile.setContents(bis, 0, null); + private static void write(IFile view, String content) { + try(var bis = new ByteArrayInputStream(content.getBytes())){ + view.setContents(bis, 0, null); } catch (Exception ex) { - throw new RuntimeException("Failed to extend view for "+viewFile, ex); + throw new RuntimeException("Failed to extend view for "+view, ex); } } - private String renderFields(IEntityClass entity, String template) { + private String renderFields(IEntityClass entity, String template, Function renderer) { String fieldXhtml = entity.getFields().stream() .filter(fld -> !fld.getName().equals("id")) - .map(this::renderColumn) + .map(renderer) .collect(Collectors.joining("\n")); return template.replace("", fieldXhtml); } @@ -105,6 +126,14 @@ private String renderColumn(IEntityClassField field) { return fieldXhtml; } + private String renderDetail(IEntityClassField field) { + String fieldXhtml = """ + + + """.replaceAll("FIELD", field.getName()); + return fieldXhtml; + } + public static UserDialogStart dialogStartFor(IEntityClass entity) { var dialogId = UserDialogId.create(entity.getName()+"Manager"); var target = new UserDialogStart(dialogId, new CallSignature("start")); diff --git a/excel-importer/src/com/axonivy/util/excel/importer/DialogProcess.java b/excel-importer/src/com/axonivy/util/excel/importer/DialogProcess.java index 1680b17..e437dab 100644 --- a/excel-importer/src/com/axonivy/util/excel/importer/DialogProcess.java +++ b/excel-importer/src/com/axonivy/util/excel/importer/DialogProcess.java @@ -10,6 +10,7 @@ import ch.ivyteam.ivy.process.model.element.event.start.dialog.html.HtmlDialogMethodStart; import ch.ivyteam.ivy.process.model.element.event.start.dialog.html.HtmlDialogStart; import ch.ivyteam.ivy.process.model.element.event.start.value.CallSignature; +import ch.ivyteam.ivy.process.model.element.value.Mappings; import ch.ivyteam.ivy.process.model.value.MappingCode; import ch.ivyteam.ivy.process.model.value.scripting.QualifiedType; import ch.ivyteam.ivy.process.model.value.scripting.VariableDesc; @@ -22,6 +23,9 @@ public class DialogProcess { private final IEntityClass entity; private final String unit; + private final int x = 96; + private int y = 248; + public DialogProcess(Process process, IEntityClass entity, String unit) { this.process = process; this.entity = entity; @@ -31,6 +35,7 @@ public DialogProcess(Process process, IEntityClass entity, String unit) { public void extendProcess() { addDbLoaderScript(); addDeleteAction(); + addEditAction(); } private void addDbLoaderScript() { @@ -53,10 +58,7 @@ private void addDbLoaderScript() { } private void addDeleteAction() { - int x = 96; - int y = 248; - var delete = process.add().element(HtmlDialogMethodStart.class); - delete.getShape().moveTo(new Position(x, y)); + var delete = addMethod(); delete.setName("delete(" + entity.getSimpleName() + ")"); var param = new VariableDesc("entity", new QualifiedType(entity.getName())); delete.setSignature(new CallSignature("delete").setInputParameters(List.of(param))); @@ -75,4 +77,20 @@ private void addDeleteAction() { delete.setOutput(new MappingCode(code)); } + private void addEditAction() { + var edit = addMethod(); + edit.setName("edit(" + entity.getSimpleName() + ")"); + var param = new VariableDesc("entity", new QualifiedType(entity.getName())); + edit.setSignature(new CallSignature("edit").setInputParameters(List.of(param))); + + edit.setOutput(new MappingCode(Mappings.single("out.edit", "param.entity"))); + } + + private HtmlDialogMethodStart addMethod() { + var delete = process.add().element(HtmlDialogMethodStart.class); + delete.getShape().moveTo(new Position(x, y)); + y += 120; + return delete; + } + } \ No newline at end of file diff --git a/excel-importer/src_hd/com/axonivy/util/excel/importer/EntityManager/EntityDetail.xhtml b/excel-importer/src_hd/com/axonivy/util/excel/importer/EntityManager/EntityDetail.xhtml index 9db2846..7f1f792 100644 --- a/excel-importer/src_hd/com/axonivy/util/excel/importer/EntityManager/EntityDetail.xhtml +++ b/excel-importer/src_hd/com/axonivy/util/excel/importer/EntityManager/EntityDetail.xhtml @@ -17,7 +17,7 @@ columnClasses="ui-g-12 ui-md-3 ui-lg-2, ui-g-12 ui-md-9 ui-lg-4, ui-g-12 ui-md-3 ui-lg-2, ui-g-12 ui-md-9 ui-lg-4"> - +