Search in sources :

Example 1 with FactResult

use of au.gov.asd.tac.constellation.views.analyticview.results.FactResult in project constellation by constellation-app.

the class FactAnalyticPlugin method computeResultsFromGraph.

protected final void computeResultsFromGraph(final GraphReadMethods graph, final PluginParameters parameters) {
    result = new FactResult();
    result.setIgnoreNullResults(ignoreDefaultValues());
    getAnalyticAttributes(parameters).forEach(schemaAttribute -> {
        int graphElementCount = 0;
        int identifierAttributeId = Graph.NOT_FOUND;
        final int factAttributeId = schemaAttribute.get(graph);
        if (factAttributeId == Graph.NOT_FOUND) {
            throw new RuntimeException("Expected attribute not found on graph: " + schemaAttribute.getName());
        }
        final GraphElementType graphElementType = schemaAttribute.getElementType();
        switch(graphElementType) {
            case VERTEX:
                graphElementCount = graph.getVertexCount();
                identifierAttributeId = VisualConcept.VertexAttribute.IDENTIFIER.get(graph);
                break;
            case TRANSACTION:
                graphElementCount = graph.getTransactionCount();
                identifierAttributeId = VisualConcept.TransactionAttribute.IDENTIFIER.get(graph);
                break;
            default:
                break;
        }
        for (int graphElementPosition = 0; graphElementPosition < graphElementCount; graphElementPosition++) {
            final int graphElementId;
            if (graphElementType == GraphElementType.VERTEX) {
                graphElementId = graph.getVertex(graphElementPosition);
            } else {
                graphElementId = graphElementType == GraphElementType.TRANSACTION ? graph.getTransaction(graphElementPosition) : Graph.NOT_FOUND;
            }
            final String identifier = graph.getStringValue(identifierAttributeId, graphElementId);
            final boolean fact = graph.getBooleanValue(factAttributeId, graphElementId);
            final boolean defaultFact = (boolean) graph.getAttributeDefaultValue(factAttributeId);
            final boolean isNull = ignoreDefaultValues() && fact == defaultFact;
            result.add(new ElementFact(graphElementType, graphElementId, identifier, isNull, schemaAttribute.getName(), fact));
        }
    });
}
Also used : FactResult(au.gov.asd.tac.constellation.views.analyticview.results.FactResult) ElementFact(au.gov.asd.tac.constellation.views.analyticview.results.FactResult.ElementFact) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType)

Aggregations

GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)1 FactResult (au.gov.asd.tac.constellation.views.analyticview.results.FactResult)1 ElementFact (au.gov.asd.tac.constellation.views.analyticview.results.FactResult.ElementFact)1