Search in sources :

Example 1 with HistoricActivityInstanceEventEntity

use of org.camunda.bpm.engine.impl.history.event.HistoricActivityInstanceEventEntity in project camunda-bpm-platform by camunda.

the class HistoricActivityInstanceTest method testLongRunningHistoricActivityInstanceReceive.

@Deployment(resources = { "org/camunda/bpm/engine/test/history/HistoricActivityInstanceTest.testHistoricActivityInstanceReceive.bpmn20.xml" })
public void testLongRunningHistoricActivityInstanceReceive() {
    final long ONE_YEAR = 1000 * 60 * 60 * 24 * 365;
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    ClockUtil.setCurrentTime(cal.getTime());
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("receiveProcess");
    HistoricActivityInstance historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityId("receive").singleResult();
    assertEquals("receive", historicActivityInstance.getActivityId());
    assertEquals("receiveTask", historicActivityInstance.getActivityType());
    assertNull(historicActivityInstance.getEndTime());
    assertNull(historicActivityInstance.getDurationInMillis());
    assertNotNull(historicActivityInstance.getProcessDefinitionId());
    assertEquals(processInstance.getId(), historicActivityInstance.getProcessInstanceId());
    assertEquals(processInstance.getId(), historicActivityInstance.getExecutionId());
    assertNotNull(historicActivityInstance.getStartTime());
    // move clock by 1 year
    cal.add(Calendar.YEAR, 1);
    ClockUtil.setCurrentTime(cal.getTime());
    runtimeService.signal(processInstance.getId());
    historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityId("receive").singleResult();
    assertEquals("receive", historicActivityInstance.getActivityId());
    assertEquals("receiveTask", historicActivityInstance.getActivityType());
    assertNotNull(historicActivityInstance.getEndTime());
    assertNotNull(historicActivityInstance.getProcessDefinitionId());
    assertEquals(processInstance.getId(), historicActivityInstance.getProcessInstanceId());
    assertEquals(processInstance.getId(), historicActivityInstance.getExecutionId());
    assertNotNull(historicActivityInstance.getStartTime());
    assertTrue(historicActivityInstance.getDurationInMillis() >= ONE_YEAR);
    assertTrue(((HistoricActivityInstanceEventEntity) historicActivityInstance).getDurationRaw() >= ONE_YEAR);
}
Also used : HistoricActivityInstanceEventEntity(org.camunda.bpm.engine.impl.history.event.HistoricActivityInstanceEventEntity) Calendar(java.util.Calendar) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) HistoricActivityInstance(org.camunda.bpm.engine.history.HistoricActivityInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 2 with HistoricActivityInstanceEventEntity

use of org.camunda.bpm.engine.impl.history.event.HistoricActivityInstanceEventEntity in project AJSC by att.

the class CamundaHistoryEventHandler method handleEvent.

@Override
public void handleEvent(HistoryEvent historyEvent) {
    // create db entry
    super.handleEvent(historyEvent);
    // Create log Entry
    HistoricActivityInstanceEventEntity activityEvent = null;
    Date startDate = null;
    Date endDate = null;
    if (historyEvent != null && historyEvent instanceof HistoricActivityInstanceEventEntity) {
        activityEvent = (HistoricActivityInstanceEventEntity) historyEvent;
        if (activityEvent != null) {
            startDate = activityEvent.getStartTime();
            endDate = activityEvent.getEndTime();
            if (activityEvent.getActivityType() != null && (activityEvent.getActivityType().equalsIgnoreCase("manualTask") || activityEvent.getActivityType().equalsIgnoreCase("userTask"))) {
                historyEventList.clear();
            }
            if (startDate != null && endDate != null) {
                System.out.println(activityEvent + ":" + activityEvent.getProcessInstanceId() + ":" + activityEvent.getActivityType());
                if (activityEvent != null && activityEvent.getProcessInstanceId() != null) {
                    historyEventList.add(activityEvent);
                    if (activityEvent.getActivityType() != null && activityEvent.getActivityType().equalsIgnoreCase("noneEndEvent")) {
                        if (AttCamundaService.getHttpRequest() != null) {
                            for (HistoricActivityInstanceEventEntity actiEvent : historyEventList) {
                                int activityInstanceState = actiEvent.getActivityInstanceState();
                                String activityState = getActivityInstanceState(activityInstanceState);
                                // resolve null pointer exception if actiEvent.getActivityName()
                                String serviceName = actiEvent.getActivityName();
                                if (serviceName == null) {
                                    serviceName = "UNKNOWN";
                                }
                            }
                            System.out.println("Call performacne is success");
                        } else {
                            RestTemplate restTemplate = new RestTemplate();
                            String histEvents = "";
                            for (HistoricActivityInstanceEventEntity actiEvent : historyEventList) {
                                int activityInstanceState = actiEvent.getActivityInstanceState();
                                String activityState = getActivityInstanceState(activityInstanceState);
                                histEvents = histEvents + actiEvent.getActivityName() + ":" + String.valueOf(actiEvent.getStartTime().getTime()) + ":" + String.valueOf(actiEvent.getEndTime().getTime()) + ":" + activityState + ",";
                                System.out.println(actiEvent);
                            }
                            Map<String, String> restValues = new HashMap<String, String>();
                            restValues.put("procInstId", activityEvent.getProcessInstanceId());
                            restValues.put("histEventList", histEvents);
                            try {
                                String port = String.valueOf(context.getEmbeddedServletContainer().getPort());
                                String url = "http://localhost:" + port + "/" + restCallforPerformance + "/log/postLogHist";
                                // create request body
                                AttCamundaHistoryEvent attCamundaHistoryEvent = new AttCamundaHistoryEvent();
                                attCamundaHistoryEvent.setHistoryEventList(historyEventList);
                                attCamundaHistoryEvent.setProcInstId(activityEvent.getProcessInstanceId());
                                Gson gson = new Gson();
                                String json = gson.toJson(attCamundaHistoryEvent, AttCamundaHistoryEvent.class);
                                // set headers
                                HttpHeaders headers = new HttpHeaders();
                                headers.setContentType(MediaType.APPLICATION_JSON);
                                HttpEntity<String> entity = new HttpEntity<String>(json, headers);
                                // send request and parse result
                                ResponseEntity<String> loginResponse = restTemplate.exchange(url, HttpMethod.POST, entity, String.class);
                                System.out.println(loginResponse);
                            } catch (Exception e) {
                                System.out.println("Not able to call restService");
                            }
                        }
                        historyEventList.clear();
                    }
                }
            }
        }
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) HashMap(java.util.HashMap) AttCamundaHistoryEvent(com.att.ajsc.camunda.core.AttCamundaHistoryEvent) Gson(com.google.gson.Gson) Date(java.util.Date) HistoricActivityInstanceEventEntity(org.camunda.bpm.engine.impl.history.event.HistoricActivityInstanceEventEntity) RestTemplate(org.springframework.web.client.RestTemplate)

Example 3 with HistoricActivityInstanceEventEntity

use of org.camunda.bpm.engine.impl.history.event.HistoricActivityInstanceEventEntity in project camunda-bpm-platform by camunda.

the class HistoricActivityInstanceTest method testHistoricActivityInstanceReceive.

@Deployment
public void testHistoricActivityInstanceReceive() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("receiveProcess");
    HistoricActivityInstance historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityId("receive").singleResult();
    assertEquals("receive", historicActivityInstance.getActivityId());
    assertEquals("receiveTask", historicActivityInstance.getActivityType());
    assertNull(historicActivityInstance.getEndTime());
    assertNull(historicActivityInstance.getDurationInMillis());
    assertNotNull(historicActivityInstance.getProcessDefinitionId());
    assertEquals(processInstance.getId(), historicActivityInstance.getProcessInstanceId());
    assertEquals(processInstance.getId(), historicActivityInstance.getExecutionId());
    assertNotNull(historicActivityInstance.getStartTime());
    // move clock by 1 second
    Date now = ClockUtil.getCurrentTime();
    ClockUtil.setCurrentTime(new Date(now.getTime() + 1000));
    runtimeService.signal(processInstance.getId());
    historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityId("receive").singleResult();
    assertEquals("receive", historicActivityInstance.getActivityId());
    assertEquals("receiveTask", historicActivityInstance.getActivityType());
    assertNotNull(historicActivityInstance.getEndTime());
    assertNotNull(historicActivityInstance.getProcessDefinitionId());
    assertEquals(processInstance.getId(), historicActivityInstance.getProcessInstanceId());
    assertEquals(processInstance.getId(), historicActivityInstance.getExecutionId());
    assertNotNull(historicActivityInstance.getStartTime());
    assertTrue(historicActivityInstance.getDurationInMillis() >= 1000);
    assertTrue(((HistoricActivityInstanceEventEntity) historicActivityInstance).getDurationRaw() >= 1000);
}
Also used : HistoricActivityInstanceEventEntity(org.camunda.bpm.engine.impl.history.event.HistoricActivityInstanceEventEntity) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Date(java.util.Date) HistoricActivityInstance(org.camunda.bpm.engine.history.HistoricActivityInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

HistoricActivityInstanceEventEntity (org.camunda.bpm.engine.impl.history.event.HistoricActivityInstanceEventEntity)3 Date (java.util.Date)2 HistoricActivityInstance (org.camunda.bpm.engine.history.HistoricActivityInstance)2 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)2 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)2 Deployment (org.camunda.bpm.engine.test.Deployment)2 AttCamundaHistoryEvent (com.att.ajsc.camunda.core.AttCamundaHistoryEvent)1 Gson (com.google.gson.Gson)1 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 HttpEntity (org.springframework.http.HttpEntity)1 HttpHeaders (org.springframework.http.HttpHeaders)1 RestTemplate (org.springframework.web.client.RestTemplate)1