generated from axonivy-market/market-product
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create a simple process to launch the entity dialog
- Loading branch information
Showing
3 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
excel-importer-test/src_test/com/axonivy/util/excel/test/TestProcessDrawer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.axonivy.util.excel.test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
|
||
import org.apache.poi.ss.usermodel.Sheet; | ||
import org.apache.poi.ss.usermodel.Workbook; | ||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.core.runtime.NullProgressMonitor; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
|
||
import com.axonivy.util.excel.importer.EntityClassReader; | ||
import com.axonivy.util.excel.importer.ExcelLoader; | ||
import com.axonivy.util.excel.importer.ProcessDrawer; | ||
|
||
import ch.ivyteam.ivy.environment.IvyTest; | ||
import ch.ivyteam.ivy.process.IProcess; | ||
import ch.ivyteam.ivy.process.model.Process; | ||
import ch.ivyteam.ivy.process.model.element.activity.DialogCall; | ||
import ch.ivyteam.ivy.process.model.element.activity.value.dialog.UserDialogId; | ||
import ch.ivyteam.ivy.scripting.dataclass.IEntityClass; | ||
|
||
@IvyTest | ||
@SuppressWarnings("restriction") | ||
public class TestProcessDrawer { | ||
|
||
private EntityClassReader reader; | ||
|
||
@Test | ||
void drawRunnerProcess(@TempDir Path dir) throws IOException, CoreException { | ||
Path path = dir.resolve("customers.xlsx"); | ||
TstRes.loadTo(path, "sample.xlsx"); | ||
|
||
Workbook wb = ExcelLoader.load(path); | ||
Sheet customerSheet = wb.getSheetAt(0); | ||
|
||
IEntityClass customer = reader.toEntity(customerSheet, "customer"); | ||
IProcess processRdm = null; | ||
try { | ||
customer.save(new NullProgressMonitor()); | ||
|
||
var drawer = new ProcessDrawer(reader.manager.getProject()); | ||
processRdm = drawer.drawManager(customer); | ||
Process process = processRdm.getModel(); | ||
assertThat(process.getProcessElements()).hasSize(3); | ||
DialogCall callHd = process.search().type(DialogCall.class).findOne(); | ||
assertThat(callHd.getName()).contains("customer"); | ||
assertThat(callHd.getTargetDialog().getId()) | ||
.isNotEqualTo(UserDialogId.EMPTY); | ||
|
||
} finally { | ||
customer.getResource().delete(true, new NullProgressMonitor()); | ||
if (processRdm != null) { | ||
processRdm.getResource().delete(true, new NullProgressMonitor()); | ||
} | ||
} | ||
} | ||
|
||
@BeforeEach | ||
void setup() { | ||
this.reader = new EntityClassReader(); | ||
} | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
excel-importer/src/com/axonivy/util/excel/importer/ProcessDrawer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.axonivy.util.excel.importer; | ||
|
||
import org.eclipse.core.resources.IProject; | ||
import org.eclipse.core.runtime.NullProgressMonitor; | ||
|
||
import ch.ivyteam.ivy.process.IProcess; | ||
import ch.ivyteam.ivy.process.model.Process; | ||
import ch.ivyteam.ivy.process.model.diagram.Diagram; | ||
import ch.ivyteam.ivy.process.model.element.activity.DialogCall; | ||
import ch.ivyteam.ivy.process.model.element.activity.value.dialog.UserDialogId; | ||
import ch.ivyteam.ivy.process.model.element.activity.value.dialog.UserDialogStart; | ||
import ch.ivyteam.ivy.process.model.element.event.end.TaskEnd; | ||
import ch.ivyteam.ivy.process.model.element.event.start.RequestStart; | ||
import ch.ivyteam.ivy.process.model.element.event.start.value.CallSignature; | ||
import ch.ivyteam.ivy.process.resource.ProcessCreator; | ||
import ch.ivyteam.ivy.scripting.dataclass.IEntityClass; | ||
|
||
@SuppressWarnings("restriction") | ||
public class ProcessDrawer { | ||
|
||
private IProject project; | ||
|
||
public ProcessDrawer(IProject project) { | ||
this.project = project; | ||
} | ||
|
||
public IProcess drawManager(IEntityClass entity) { | ||
String name = entity.getSimpleName(); | ||
|
||
var rdm = ProcessCreator.create(project, "Manage"+name) | ||
.createDefaultContent(false) | ||
.toCreator() | ||
.createDataModel(new NullProgressMonitor()); | ||
|
||
Process process = rdm.getModel(); | ||
drawProcess(process); | ||
|
||
DialogCall call = process.search().type(DialogCall.class).findOne(); | ||
call.setName(name+" UI"); | ||
var dialogId = UserDialogId.create(entity.getName()+"Manager"); | ||
var target = new UserDialogStart(dialogId, new CallSignature("start")); | ||
call.setTargetDialog(target); | ||
|
||
rdm.save(); | ||
|
||
return rdm; | ||
} | ||
|
||
private void drawProcess(Process process) { | ||
Diagram diagram = process.getDiagram(); | ||
var start = diagram.add().shape(RequestStart.class).at(50, 50); | ||
RequestStart starter = start.getElement(); | ||
starter.setSignature(new CallSignature("manage")); | ||
starter.setName("manage"); | ||
|
||
var dialog = diagram.add().shape(DialogCall.class).at(150, 50); | ||
start.edges().connectTo(dialog); | ||
|
||
var end = diagram.add().shape(TaskEnd.class).at(300, 50); | ||
dialog.edges().connectTo(end); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters