Search in sources :

Example 1 with CustomInfo

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;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FlowEvent(org.talend.esb.sam.server.persistence.FlowEvent) AggregatedFlowEvent(org.talend.esb.sam.server.persistence.AggregatedFlowEvent) CustomInfo(org.talend.esb.sam.server.persistence.CustomInfo) ArrayList(java.util.ArrayList) List(java.util.List) FlowDetails(org.talend.esb.sam.server.persistence.FlowDetails) AggregatedFlowEvent(org.talend.esb.sam.server.persistence.AggregatedFlowEvent) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 AggregatedFlowEvent (org.talend.esb.sam.server.persistence.AggregatedFlowEvent)1 CustomInfo (org.talend.esb.sam.server.persistence.CustomInfo)1 FlowDetails (org.talend.esb.sam.server.persistence.FlowDetails)1 FlowEvent (org.talend.esb.sam.server.persistence.FlowEvent)1