Added prepare project process initial version
authorVásáry Dániel <vasary@elgekko.net>
Fri, 1 Dec 2023 10:08:20 +0000 (11:08 +0100)
committerVásáry Dániel <vasary@elgekko.net>
Fri, 1 Dec 2023 10:08:20 +0000 (11:08 +0100)
lis-app/src/main/resources/application-test.yaml [moved from lis-app/src/main/resources/application.yaml with 100% similarity]
lis-app/src/test/java/hu/user/lis/AssociatesDataModelIT.java
lis-app/src/test/java/hu/user/lis/workflow/BpmnTest.java [new file with mode: 0644]
lis-app/src/test/java/hu/user/lis/workflow/PrepareProjectIT.java [new file with mode: 0644]
lis-app/src/test/resources/application-test.yaml [new file with mode: 0644]
lis-workflow/src/main/java/hu/user/lis/workflow/project/CreateProjectFolders.java [new file with mode: 0644]
lis-workflow/src/main/java/hu/user/lis/workflow/properties/WorkflowProperties.java
lis-workflow/src/main/resources/prepare-project.bpmn [new file with mode: 0644]

index 76173781a7a0c7968be9f0b7fc9ace479e0bdcf7..c665368c5c16b56d18a30ae094107c060fb9cfaf 100644 (file)
@@ -19,7 +19,7 @@ import org.springframework.test.context.junit4.SpringRunner;
 @RunWith(SpringRunner.class)
 @ComponentScan("hu.user.lis")
 @SpringBootTest
-//@TestPropertySource("classpath:application.yaml")
+//@TestPropertySource("classpath:application-test.yaml")
 //@AutoConfigureMockMvc
 public class AssociatesDataModelIT {
     @Autowired
diff --git a/lis-app/src/test/java/hu/user/lis/workflow/BpmnTest.java b/lis-app/src/test/java/hu/user/lis/workflow/BpmnTest.java
new file mode 100644 (file)
index 0000000..3ee88b3
--- /dev/null
@@ -0,0 +1,32 @@
+package hu.user.lis.workflow;
+
+import org.camunda.bpm.engine.RuntimeService;
+import org.camunda.bpm.engine.runtime.ProcessInstance;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.util.List;
+
+public class BpmnTest {
+    @Autowired
+    private RuntimeService runtimeService;
+
+    protected void waitForFinish(ProcessInstance processInstance) throws InterruptedException {
+        while (true) {
+            ProcessInstance active = runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getProcessInstanceId()).active().singleResult();
+            if (active == null) {
+                break;
+            }
+            Thread.sleep(1000);
+        }
+    }
+
+    protected void cancelRunningProcesses(String processId) {
+        List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery().processDefinitionKey(processId).list();
+        processInstances.forEach(p -> {
+            try {
+                runtimeService.deleteProcessInstance(p.getProcessInstanceId(), "Canceled");
+            } catch (Exception e) {
+            }
+        });
+    }
+}
\ No newline at end of file
diff --git a/lis-app/src/test/java/hu/user/lis/workflow/PrepareProjectIT.java b/lis-app/src/test/java/hu/user/lis/workflow/PrepareProjectIT.java
new file mode 100644 (file)
index 0000000..fafcdd4
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) $today.year-$today.month-24.
+ * By elGekko
+ */
+
+package hu.user.lis.workflow;
+
+import com.google.common.collect.ImmutableMap;
+import hu.user.lis.db.Project;
+import hu.user.lis.db.repository.PartnerRepository;
+import hu.user.lis.db.repository.ProjectRepository;
+import hu.user.lis.db.repository.ProjectStatusRepository;
+import hu.user.lis.workflow.properties.WorkflowProperties;
+import lombok.extern.log4j.Log4j2;
+import org.camunda.bpm.engine.RuntimeService;
+import org.camunda.bpm.engine.runtime.ProcessInstance;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.util.Objects;
+
+
+@Log4j2
+@SpringBootTest
+@RunWith(SpringRunner.class)
+@ActiveProfiles("test")
+@ComponentScan("hu.user.lis")
+public class PrepareProjectIT extends BpmnTest {
+    private final String PROCESSID = "prepareProject";
+    @Autowired
+    private RuntimeService runtimeService;
+
+    @Autowired
+    private WorkflowProperties workflowProperties;
+
+    @Autowired
+    private ProjectRepository projectRepository;
+
+    @Autowired
+    private PartnerRepository partnerRepository;
+
+    @Autowired
+    private ProjectStatusRepository projectStatusRepository;
+
+    @Test
+    public void testPrepareProject() throws InterruptedException {
+        Project project = Project.builder()
+                .partner(partnerRepository.findAll().get(0))
+                .projectStatus(projectStatusRepository.findAll().get(0))
+                .name("Teszt projekt")
+                .active(true)
+                .build();
+        try {
+            projectRepository.saveAndFlush(project);
+//            log.info("Template source: {}", workflowProperties.getPrepareProject().getTemplateSourceFolder());
+            cancelRunningProcesses(PROCESSID);
+            ImmutableMap<String, Object> params = ImmutableMap.of("projectId", project.getId());
+            ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(PROCESSID, params);
+            waitForFinish(processInstance);
+        } catch (Exception e) {
+            log.error(e);
+            throw e;
+        } finally {
+            if (Objects.nonNull(project.getId())) {
+                projectRepository.delete(project);
+            }
+        }
+
+    }
+
+}
\ No newline at end of file
diff --git a/lis-app/src/test/resources/application-test.yaml b/lis-app/src/test/resources/application-test.yaml
new file mode 100644 (file)
index 0000000..358c957
--- /dev/null
@@ -0,0 +1,80 @@
+server:
+  port: 8080
+  servlet:
+    context-path: /
+zk:
+  homepage: index
+  zul-view-resolver-enabled: true
+spring:
+  jpa:
+    #    hibernate:
+    #      use-new-id-generator-mappings: false
+    show-sql: false
+    properties:
+      hibernate:
+        format_sql: true
+  main:
+    banner-mode: off
+  output:
+    ansi:
+      enabled: always
+  datasource:
+    type: com.zaxxer.hikari.HikariDataSource
+    url: jdbc:db2://dvdev.in.useribm.hu:50000/lis
+    username: db2admin
+    password: password
+camunda.bpm:
+  generic-properties.properties:
+    telemetry-reporter-activate: false
+  job-executor-acquire-by-priority: true
+  job-execution:
+    core-pool-size: 10
+    #lock-time-in-millis: 600000
+  database:
+    type: db2
+    schema-update: false
+    table-prefix: CAMUNDA.
+    schema-name: CAMUNDA
+  webapp:
+    enabled: true
+    index-redirect-enabled: false
+  admin-user:
+    id: kermit
+    password: password
+    firstName: Kermit
+  filter:
+    create: All tasks
+  job-execution.enabled: true
+logging:
+  config: classpath:logback-dev.xml
+  level:
+    org.hibernate.engine.jdbc.spi.SqlExceptionHelper: ERROR
+    org.springframework.web.clientRestTemplate: DEBUG
+    logging.level.org.apache.http: TRACE
+    logging.level.httpclient.wire: TRACE
+application:
+  ui:
+    user-name: user
+    password: password
+  workflow:
+    import-invoice:
+      input-path: /temp/invoice-import
+      project-id-pattern: \d{4}-\d{4}
+    prepare-project:
+      template-source-folder: "valami"
+service:
+  nav:
+    trust:
+      store: classpath:keystore/lis-keystore.jks
+      store.password: password
+    api:
+      url: https://api-test.onlineszamla.nav.gov.hu/invoiceService/v3
+      user: vkvyibj5xgqpbp0
+      password: Salabakt3r
+      sign-key: fe-9d8b-971c878376204BQEWTHH2HI6
+      exchange-key: 3af24BQEWTHH4TSX
+      sender-tax-number: 13364937
+      sender-company: User Rendszerház Kft.
+      sender-country: HU
+      sender-contact: Kovács Géza
+      days-range: 34
\ No newline at end of file
diff --git a/lis-workflow/src/main/java/hu/user/lis/workflow/project/CreateProjectFolders.java b/lis-workflow/src/main/java/hu/user/lis/workflow/project/CreateProjectFolders.java
new file mode 100644 (file)
index 0000000..665ba2b
--- /dev/null
@@ -0,0 +1,30 @@
+package hu.user.lis.workflow.project;
+
+import hu.user.lis.db.Project;
+import hu.user.lis.db.repository.ProjectRepository;
+import hu.user.lis.workflow.properties.WorkflowProperties;
+import lombok.extern.log4j.Log4j2;
+import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.camunda.bpm.engine.delegate.JavaDelegate;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import javax.persistence.EntityNotFoundException;
+
+@Log4j2
+@Component
+public class CreateProjectFolders implements JavaDelegate {
+    @Autowired
+    private ProjectRepository projectRepository;
+
+    @Autowired
+    private WorkflowProperties workflowProperties;
+
+    @Override
+    public void execute(DelegateExecution delegateExecution) throws Exception {
+        Long projectId = (Long) delegateExecution.getVariable("projectId");
+        Project project = projectRepository.findById(projectId).orElseThrow(EntityNotFoundException::new);
+        log.info("Executing on project ID {}", projectId);
+//        delegateExecution.setVariableLocal("invoices", invoices);
+    }
+}
index c62fcb7d9d1c1135fa2fbcba5c4d5fe144cffade..05a46a489af102c355520b6075ecc803d52b91c1 100644 (file)
@@ -13,6 +13,8 @@ public class WorkflowProperties {
 
     private ImportInvoice importInvoice;
 
+    private PrepareProject prepareProject;
+
     @Getter
     @Setter
     public static class ImportInvoice {
@@ -21,4 +23,10 @@ public class WorkflowProperties {
         private String projectIdPattern;
     }
 
+    @Getter
+    @Setter
+    public static class PrepareProject {
+        private String templateSourceFolder;
+    }
+
 }
diff --git a/lis-workflow/src/main/resources/prepare-project.bpmn b/lis-workflow/src/main/resources/prepare-project.bpmn
new file mode 100644 (file)
index 0000000..b4ca0a4
--- /dev/null
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_08cp8iu" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.14.0" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.19.0">
+  <bpmn:process id="prepareProject" name="Prepare Project" isExecutable="true" camunda:historyTimeToLive="180">
+    <bpmn:startEvent id="StartEvent_1">
+      <bpmn:outgoing>Flow_1w8ohiv</bpmn:outgoing>
+    </bpmn:startEvent>
+    <bpmn:sequenceFlow id="Flow_1w8ohiv" sourceRef="StartEvent_1" targetRef="createProjectFolders" />
+    <bpmn:serviceTask id="createProjectFolders" name="Create project folders" camunda:delegateExpression="${createProjectFolders}">
+      <bpmn:incoming>Flow_1w8ohiv</bpmn:incoming>
+      <bpmn:outgoing>Flow_0fihphr</bpmn:outgoing>
+    </bpmn:serviceTask>
+    <bpmn:endEvent id="Event_0h9gy35">
+      <bpmn:incoming>Flow_0fihphr</bpmn:incoming>
+    </bpmn:endEvent>
+    <bpmn:sequenceFlow id="Flow_0fihphr" sourceRef="createProjectFolders" targetRef="Event_0h9gy35" />
+  </bpmn:process>
+  <bpmndi:BPMNDiagram id="BPMNDiagram_1">
+    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="prepareProject">
+      <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
+        <dc:Bounds x="179" y="79" width="36" height="36" />
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNShape id="Activity_06cl6md_di" bpmnElement="createProjectFolders">
+        <dc:Bounds x="270" y="57" width="100" height="80" />
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNShape id="Event_0h9gy35_di" bpmnElement="Event_0h9gy35">
+        <dc:Bounds x="432" y="79" width="36" height="36" />
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNEdge id="Flow_1w8ohiv_di" bpmnElement="Flow_1w8ohiv">
+        <di:waypoint x="215" y="97" />
+        <di:waypoint x="270" y="97" />
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNEdge id="Flow_0fihphr_di" bpmnElement="Flow_0fihphr">
+        <di:waypoint x="370" y="97" />
+        <di:waypoint x="432" y="97" />
+      </bpmndi:BPMNEdge>
+    </bpmndi:BPMNPlane>
+  </bpmndi:BPMNDiagram>
+</bpmn:definitions>