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);
}
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();
}
}
}
}
}
}
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);
}
Aggregations