Search in sources :

Example 11 with StandaloneJtaStrategy

use of org.jbpm.process.audit.strategy.StandaloneJtaStrategy in project jbpm by kiegroup.

the class AuditQueryDataUtil method createTestVariableInstanceLogData.

static VariableInstanceLog[] createTestVariableInstanceLogData(EntityManagerFactory emf) {
    StandaloneJtaStrategy jtaHelper = new StandaloneJtaStrategy(emf);
    EntityManager em = jtaHelper.getEntityManager();
    int numEntities = 8;
    VariableInstanceLog[] testData = new VariableInstanceLog[numEntities];
    Calendar cal = randomCal();
    for (int i = 0; i < numEntities; ++i) {
        VariableInstanceLog vil = new VariableInstanceLog();
        vil.setProcessInstanceId(randomLong());
        vil.setProcessId(randomString());
        cal.add(Calendar.MINUTE, 1);
        vil.setDate(cal.getTime());
        vil.setVariableInstanceId(randomString());
        vil.setVariableId(randomString());
        vil.setValue(randomString());
        vil.setOldValue(randomString());
        vil.setExternalId(randomString());
        testData[i] = vil;
    }
    for (int i = 0; i < numEntities; ++i) {
        switch(i) {
            case 1:
                testData[i - 1].setDate(testData[i].getDate());
                break;
            case 2:
                testData[i - 1].setOldValue(testData[i].getOldValue());
                break;
            case 3:
                testData[i - 1].setProcessId(testData[i].getProcessId());
                break;
            case 4:
                testData[i - 1].setProcessInstanceId(testData[i].getProcessInstanceId());
                break;
            case 5:
                testData[i - 1].setValue(testData[i].getValue());
                break;
            case 6:
                testData[i - 1].setVariableId(testData[i].getVariableId());
                break;
            case 7:
                testData[i - 1].setVariableInstanceId(testData[i].getVariableInstanceId());
                break;
        }
    }
    Object tx = jtaHelper.joinTransaction(em);
    for (int i = 0; i < numEntities; ++i) {
        em.persist(testData[i]);
    }
    jtaHelper.leaveTransaction(em, tx);
    createdEntities.addAll(Arrays.asList(testData));
    return testData;
}
Also used : VariableInstanceLog(org.jbpm.process.audit.VariableInstanceLog) StandaloneJtaStrategy(org.jbpm.process.audit.strategy.StandaloneJtaStrategy) EntityManager(javax.persistence.EntityManager) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar)

Example 12 with StandaloneJtaStrategy

use of org.jbpm.process.audit.strategy.StandaloneJtaStrategy in project jbpm by kiegroup.

the class AuditQueryDataUtil method cleanDB.

static void cleanDB(EntityManagerFactory emf) {
    StandaloneJtaStrategy jtaHelper = new StandaloneJtaStrategy(emf);
    EntityManager em = jtaHelper.getEntityManager();
    Object tx = jtaHelper.joinTransaction(em);
    for (Object entity : createdEntities) {
        Object mergedEntity = em.merge(entity);
        em.remove(mergedEntity);
    }
    jtaHelper.leaveTransaction(em, tx);
}
Also used : StandaloneJtaStrategy(org.jbpm.process.audit.strategy.StandaloneJtaStrategy) EntityManager(javax.persistence.EntityManager)

Example 13 with StandaloneJtaStrategy

use of org.jbpm.process.audit.strategy.StandaloneJtaStrategy in project jbpm by kiegroup.

the class AuditQueryDataUtil method createTestNodeInstanceLogData.

static NodeInstanceLog[] createTestNodeInstanceLogData(EntityManagerFactory emf) {
    StandaloneJtaStrategy jtaHelper = new StandaloneJtaStrategy(emf);
    EntityManager em = jtaHelper.getEntityManager();
    int numEntities = 9;
    NodeInstanceLog[] testData = new NodeInstanceLog[numEntities];
    Calendar cal = randomCal();
    for (int i = 0; i < numEntities; ++i) {
        NodeInstanceLog nil = new NodeInstanceLog();
        nil.setProcessInstanceId(randomLong());
        nil.setProcessId(randomString());
        cal.add(Calendar.SECOND, 1);
        nil.setDate(cal.getTime());
        nil.setType(Math.abs(random.nextInt()));
        nil.setNodeInstanceId(randomString());
        nil.setNodeId(randomString());
        nil.setNodeName(randomString());
        nil.setNodeType(randomString());
        nil.setWorkItemId(randomLong());
        nil.setConnection(randomString());
        nil.setExternalId(randomString());
        testData[i] = nil;
    }
    for (int i = 0; i < numEntities; ++i) {
        switch(i) {
            case 1:
                testData[i - 1].setDate(testData[i].getDate());
                break;
            case 2:
                testData[i - 1].setNodeId(testData[i].getNodeId());
                break;
            case 3:
                testData[i - 1].setNodeInstanceId(testData[i].getNodeInstanceId());
                break;
            case 4:
                testData[i - 1].setNodeName(testData[i].getNodeName());
                break;
            case 5:
                testData[i - 1].setNodeType(testData[i].getNodeType());
                break;
            case 6:
                testData[i - 1].setProcessId(testData[i].getProcessId());
                break;
            case 7:
                testData[i - 1].setProcessInstanceId(testData[i].getProcessInstanceId());
                break;
            case 8:
                testData[i - 1].setWorkItemId(testData[i].getWorkItemId());
                break;
        }
    }
    Object tx = jtaHelper.joinTransaction(em);
    for (int i = 0; i < numEntities; ++i) {
        em.persist(testData[i]);
    }
    jtaHelper.leaveTransaction(em, tx);
    createdEntities.addAll(Arrays.asList(testData));
    return testData;
}
Also used : StandaloneJtaStrategy(org.jbpm.process.audit.strategy.StandaloneJtaStrategy) EntityManager(javax.persistence.EntityManager) NodeInstanceLog(org.jbpm.process.audit.NodeInstanceLog) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar)

Example 14 with StandaloneJtaStrategy

use of org.jbpm.process.audit.strategy.StandaloneJtaStrategy in project jbpm by kiegroup.

the class AuditQueryTest method removeEntities.

private void removeEntities(VariableInstanceLog[] testData) {
    StandaloneJtaStrategy jtaHelper = new StandaloneJtaStrategy(emf);
    EntityManager em = jtaHelper.getEntityManager();
    int numLogs = testData.length;
    Object tx = jtaHelper.joinTransaction(em);
    for (int i = 0; i < numLogs; ++i) {
        VariableInstanceLog mergedEntity = em.merge(testData[i]);
        em.remove(mergedEntity);
    }
    jtaHelper.leaveTransaction(em, tx);
}
Also used : VariableInstanceLog(org.jbpm.process.audit.VariableInstanceLog) StandaloneJtaStrategy(org.jbpm.process.audit.strategy.StandaloneJtaStrategy) EntityManager(javax.persistence.EntityManager)

Example 15 with StandaloneJtaStrategy

use of org.jbpm.process.audit.strategy.StandaloneJtaStrategy in project jbpm by kiegroup.

the class JPAService method setPersistenceUnitName.

public void setPersistenceUnitName(String persistenceUnitName) {
    persistenceStrategy = new StandaloneJtaStrategy(Persistence.createEntityManagerFactory(persistenceUnitName));
    this.persistenceUnitName = persistenceUnitName;
}
Also used : StandaloneJtaStrategy(org.jbpm.process.audit.strategy.StandaloneJtaStrategy)

Aggregations

StandaloneJtaStrategy (org.jbpm.process.audit.strategy.StandaloneJtaStrategy)15 EntityManager (javax.persistence.EntityManager)10 Calendar (java.util.Calendar)7 GregorianCalendar (java.util.GregorianCalendar)7 ProcessInstanceLog (org.jbpm.process.audit.ProcessInstanceLog)5 Before (org.junit.Before)4 VariableInstanceLog (org.jbpm.process.audit.VariableInstanceLog)3 NodeInstanceLog (org.jbpm.process.audit.NodeInstanceLog)2 ArrayList (java.util.ArrayList)1 JPATaskLifeCycleEventListener (org.jbpm.services.task.audit.JPATaskLifeCycleEventListener)1 BAMTaskEventListener (org.jbpm.services.task.lifecycle.listeners.BAMTaskEventListener)1 TaskFluent (org.jbpm.services.task.utils.TaskFluent)1 Task (org.kie.api.task.model.Task)1 AuditTask (org.kie.internal.task.api.AuditTask)1 InternalTaskService (org.kie.internal.task.api.InternalTaskService)1