Search in sources :

Example 1 with BehaviorModelEdge

use of org.iobserve.service.behavior.analysis.model.BehaviorModelEdge in project iobserve-analysis by research-iobserve.

the class BehaviorModelDeserialization method deserialize.

public BehaviorModelGED deserialize() throws Exception {
    final ObjectMapper mapper = new ObjectMapper();
    final JsonNode tree = mapper.readTree(this.input);
    if (!(tree instanceof ObjectNode)) {
        throw new IOException("Wrong format");
    }
    final ObjectNode jsonModel = (ObjectNode) tree;
    final BehaviorModelGED model = new BehaviorModelGED();
    // Read nodes
    final JsonNode jsonNode = jsonModel.get("nodes");
    final Iterator<String> nodeIterator = jsonNode.fieldNames();
    while (nodeIterator.hasNext()) {
        final String operationSignature = nodeIterator.next();
        model.getNodes().put(operationSignature, new BehaviorModelNode(operationSignature));
    }
    // Read edges
    final JsonNode jsonEdges = jsonModel.get("edges");
    final Iterator<JsonNode> edgeIterator = jsonEdges.elements();
    while (edgeIterator.hasNext()) {
        final JsonNode jsonEdge = edgeIterator.next();
        final String source = jsonEdge.get("source").get("name").asText();
        final String target = jsonEdge.get("target").get("name").asText();
        final BehaviorModelNode sourceMatch = model.getNodes().get(source);
        final BehaviorModelNode targetMatch = model.getNodes().get(target);
        final BehaviorModelEdge newEdge = new BehaviorModelEdge(sourceMatch, targetMatch);
        model.getEdges().add(newEdge);
        sourceMatch.getOutgoingEdges().put(targetMatch, newEdge);
        targetMatch.getIngoingEdges().put(sourceMatch, newEdge);
        // Read event groups
        final JsonNode jsonEventGroups = jsonEdge.get("eventGroups");
        final Iterator<JsonNode> eventGroupIterator = jsonEventGroups.elements();
        while (eventGroupIterator.hasNext()) {
            final JsonNode jsonEventGroup = eventGroupIterator.next();
            final Iterator<JsonNode> eventIterator = jsonEventGroup.get("events").elements();
            final List<PayloadAwareEntryCallEvent> events = new ArrayList<>();
            while (eventIterator.hasNext()) {
                final JsonNode jsonEvent = eventIterator.next();
                final String operationSignature = jsonEvent.get("operationSignature").asText();
                final String[] parameters = mapper.treeToValue(jsonEvent.get("parameters"), String[].class);
                final String[] values = mapper.treeToValue(jsonEvent.get("values"), String[].class);
                final PayloadAwareEntryCallEvent event = new PayloadAwareEntryCallEvent(0, 0, operationSignature, operationSignature, "", "", parameters, values, 0);
                events.add(event);
            }
            final EventGroup group = new EventGroup(events.get(0).getParameters());
            group.getEvents().addAll(events);
            newEdge.getEventGroups().add(group);
        }
    }
    return model;
}
Also used : BehaviorModelNode(org.iobserve.service.behavior.analysis.model.BehaviorModelNode) BehaviorModelEdge(org.iobserve.service.behavior.analysis.model.BehaviorModelEdge) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) EventGroup(org.iobserve.service.behavior.analysis.model.EventGroup) BehaviorModelGED(org.iobserve.service.behavior.analysis.model.BehaviorModelGED) PayloadAwareEntryCallEvent(org.iobserve.stages.general.data.PayloadAwareEntryCallEvent) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with BehaviorModelEdge

use of org.iobserve.service.behavior.analysis.model.BehaviorModelEdge in project iobserve-analysis by research-iobserve.

the class TestHelper method createBehaviorModelC.

// only difference to A: different parameterNames
public static BehaviorModelGED createBehaviorModelC() {
    final BehaviorModelGED model = new BehaviorModelGED();
    TestHelper.addNode(model, "Init");
    TestHelper.addNode(model, "A");
    TestHelper.addNode(model, "B");
    TestHelper.addNode(model, "C");
    final String[] parameters = { "different parameters" };
    final String[] values = {};
    final BehaviorModelEdge edge1 = TestHelper.addEdge(model, "Init", "A");
    edge1.addEvent(TestHelper.createEvent(0, "A", parameters, values));
    final BehaviorModelEdge edge2 = TestHelper.addEdge(model, "A", "B");
    edge2.addEvent(TestHelper.createEvent(1, "A", parameters, values));
    final BehaviorModelEdge edge3 = TestHelper.addEdge(model, "B", "C");
    edge3.addEvent(TestHelper.createEvent(2, "C", parameters, values));
    return model;
}
Also used : BehaviorModelEdge(org.iobserve.service.behavior.analysis.model.BehaviorModelEdge) BehaviorModelGED(org.iobserve.service.behavior.analysis.model.BehaviorModelGED)

Example 3 with BehaviorModelEdge

use of org.iobserve.service.behavior.analysis.model.BehaviorModelEdge in project iobserve-analysis by research-iobserve.

the class TestHelper method addEdge.

public static BehaviorModelEdge addEdge(final BehaviorModelGED model, final String sourceName, final String targetName) {
    final BehaviorModelNode source = model.getNodes().get(sourceName);
    final BehaviorModelNode target = model.getNodes().get(targetName);
    final BehaviorModelEdge edge = new BehaviorModelEdge(source, target);
    source.getOutgoingEdges().put(target, edge);
    source.getIngoingEdges().put(source, edge);
    model.getEdges().add(edge);
    return edge;
}
Also used : BehaviorModelNode(org.iobserve.service.behavior.analysis.model.BehaviorModelNode) BehaviorModelEdge(org.iobserve.service.behavior.analysis.model.BehaviorModelEdge)

Example 4 with BehaviorModelEdge

use of org.iobserve.service.behavior.analysis.model.BehaviorModelEdge in project iobserve-analysis by research-iobserve.

the class UserSessionToModelGeneratorTest method test.

@Test
public void test() {
    final BehaviorModelGED model = this.startAndGetSolutions(this.session);
    // 3 nodes: A, B, Init
    MatcherAssert.assertThat(model.getNodes().size(), Matchers.is(3));
    // 3 edges (Init -> A, A -> B, B -> B)
    MatcherAssert.assertThat(model.getEdges().size(), Matchers.is(3));
    final BehaviorModelNode nodeB = model.getNodes().get("B");
    // only 1 edge: (B -> B)
    MatcherAssert.assertThat(nodeB.getOutgoingEdges().size(), Matchers.is(1));
    // get edge to itself
    final BehaviorModelEdge edgeBtoB = nodeB.getOutgoingEdges().get(nodeB);
    // two event groups
    MatcherAssert.assertThat(edgeBtoB.getEventGroups().size(), Matchers.is(2));
}
Also used : BehaviorModelNode(org.iobserve.service.behavior.analysis.model.BehaviorModelNode) BehaviorModelEdge(org.iobserve.service.behavior.analysis.model.BehaviorModelEdge) BehaviorModelGED(org.iobserve.service.behavior.analysis.model.BehaviorModelGED) Test(org.junit.Test)

Example 5 with BehaviorModelEdge

use of org.iobserve.service.behavior.analysis.model.BehaviorModelEdge in project iobserve-analysis by research-iobserve.

the class TestHelper method createBehaviorModelD.

// only difference to A: additional edge
public static BehaviorModelGED createBehaviorModelD() {
    final BehaviorModelGED model = new BehaviorModelGED();
    TestHelper.addNode(model, "Init");
    TestHelper.addNode(model, "A");
    TestHelper.addNode(model, "B");
    TestHelper.addNode(model, "C");
    final String[] parameters = {};
    final String[] values = {};
    final BehaviorModelEdge edge1 = TestHelper.addEdge(model, "Init", "A");
    edge1.addEvent(TestHelper.createEvent(0, "A", parameters, values));
    final BehaviorModelEdge edge2 = TestHelper.addEdge(model, "A", "B");
    edge2.addEvent(TestHelper.createEvent(1, "A", parameters, values));
    final BehaviorModelEdge edge3 = TestHelper.addEdge(model, "B", "C");
    edge3.addEvent(TestHelper.createEvent(2, "C", parameters, values));
    final BehaviorModelEdge edge4 = TestHelper.addEdge(model, "C", "B");
    edge3.addEvent(TestHelper.createEvent(3, "B", parameters, values));
    return model;
}
Also used : BehaviorModelEdge(org.iobserve.service.behavior.analysis.model.BehaviorModelEdge) BehaviorModelGED(org.iobserve.service.behavior.analysis.model.BehaviorModelGED)

Aggregations

BehaviorModelEdge (org.iobserve.service.behavior.analysis.model.BehaviorModelEdge)10 BehaviorModelGED (org.iobserve.service.behavior.analysis.model.BehaviorModelGED)7 BehaviorModelNode (org.iobserve.service.behavior.analysis.model.BehaviorModelNode)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 EventGroup (org.iobserve.service.behavior.analysis.model.EventGroup)1 PayloadAwareEntryCallEvent (org.iobserve.stages.general.data.PayloadAwareEntryCallEvent)1 Test (org.junit.Test)1