use of com.att.ajsc.camunda.core.AttCamundaHistoryEvent 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();
}
}
}
}
}
}
Aggregations