use of org.talend.esb.sam.server.persistence.CustomInfo in project tesb-rt-se by Talend.
the class SAMRestServiceImpl method aggregateFlowDetails.
public FlowDetails aggregateFlowDetails(List<FlowEvent> flowEvents) {
Map<Long, List<CustomInfo>> customInfo = new HashMap<Long, List<CustomInfo>>();
Set<Long> allEvents = new HashSet<Long>();
for (FlowEvent flowEvent : flowEvents) {
long flowEventId = flowEvent.getId();
allEvents.add(flowEventId);
String custKey = flowEvent.getCustomKey();
String custValue = flowEvent.getCustomValue();
if (null != custKey) {
if (!customInfo.containsKey(flowEventId)) {
customInfo.put(flowEventId, new ArrayList<CustomInfo>());
}
CustomInfo custom = new CustomInfo();
custom.setKey(custKey);
custom.setValue(custValue);
customInfo.get(flowEventId).add(custom);
}
}
List<AggregatedFlowEvent> aggregatedFlowEventList = new ArrayList<AggregatedFlowEvent>();
for (FlowEvent flowEvent : flowEvents) {
long flowEventId = flowEvent.getId();
if (allEvents.contains(flowEventId)) {
allEvents.remove(flowEventId);
AggregatedFlowEvent aggregatedFlowEvent = new AggregatedFlowEvent();
aggregatedFlowEvent.setContentCut(flowEvent.isContentCut());
aggregatedFlowEvent.setCustomId(flowEvent.getCustomId());
aggregatedFlowEvent.setDetails(uriInfo.getBaseUriBuilder().path("event").path(String.valueOf(flowEventId)).build());
aggregatedFlowEvent.setType(flowEvent.getType());
aggregatedFlowEvent.setFlowID(flowEvent.getFlowID());
aggregatedFlowEvent.setHost(flowEvent.getHost());
aggregatedFlowEvent.setId(flowEventId);
aggregatedFlowEvent.setIp(flowEvent.getIp());
aggregatedFlowEvent.setMessageID(flowEvent.getMessageID());
aggregatedFlowEvent.setOperation(flowEvent.getOperation());
aggregatedFlowEvent.setPort(flowEvent.getPort());
aggregatedFlowEvent.setPrincipal(flowEvent.getPrincipal());
aggregatedFlowEvent.setProcess(flowEvent.getProcess());
aggregatedFlowEvent.setTimestamp(flowEvent.getTimestamp());
aggregatedFlowEvent.setTransport(flowEvent.getTransport());
if (customInfo.containsKey(flowEventId)) {
aggregatedFlowEvent.setCustomInfo(customInfo.get(flowEventId));
}
aggregatedFlowEventList.add(aggregatedFlowEvent);
}
}
FlowDetails flowDetails = new FlowDetails();
flowDetails.setEvents(aggregatedFlowEventList);
return flowDetails;
}
Aggregations