From: Vásáry Dániel Date: Fri, 1 Dec 2023 10:08:20 +0000 (+0100) Subject: Added prepare project process initial version X-Git-Url: http://git.useribm.hu/?a=commitdiff_plain;h=dfcd9bff2be78418d92508ccd8ca95f386e31031;p=sly-crm.git Added prepare project process initial version --- diff --git a/lis-app/src/main/resources/application.yaml b/lis-app/src/main/resources/application-test.yaml similarity index 100% rename from lis-app/src/main/resources/application.yaml rename to lis-app/src/main/resources/application-test.yaml diff --git a/lis-app/src/test/java/hu/user/lis/AssociatesDataModelIT.java b/lis-app/src/test/java/hu/user/lis/AssociatesDataModelIT.java index 7617378..c665368 100644 --- a/lis-app/src/test/java/hu/user/lis/AssociatesDataModelIT.java +++ b/lis-app/src/test/java/hu/user/lis/AssociatesDataModelIT.java @@ -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 index 0000000..3ee88b3 --- /dev/null +++ b/lis-app/src/test/java/hu/user/lis/workflow/BpmnTest.java @@ -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 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 index 0000000..fafcdd4 --- /dev/null +++ b/lis-app/src/test/java/hu/user/lis/workflow/PrepareProjectIT.java @@ -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 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 index 0000000..358c957 --- /dev/null +++ b/lis-app/src/test/resources/application-test.yaml @@ -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 index 0000000..665ba2b --- /dev/null +++ b/lis-workflow/src/main/java/hu/user/lis/workflow/project/CreateProjectFolders.java @@ -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); + } +} diff --git a/lis-workflow/src/main/java/hu/user/lis/workflow/properties/WorkflowProperties.java b/lis-workflow/src/main/java/hu/user/lis/workflow/properties/WorkflowProperties.java index c62fcb7..05a46a4 100644 --- a/lis-workflow/src/main/java/hu/user/lis/workflow/properties/WorkflowProperties.java +++ b/lis-workflow/src/main/java/hu/user/lis/workflow/properties/WorkflowProperties.java @@ -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 index 0000000..b4ca0a4 --- /dev/null +++ b/lis-workflow/src/main/resources/prepare-project.bpmn @@ -0,0 +1,38 @@ + + + + + Flow_1w8ohiv + + + + Flow_1w8ohiv + Flow_0fihphr + + + Flow_0fihphr + + + + + + + + + + + + + + + + + + + + + + + + +