Search in sources :

Example 1 with QualityControlEvent

use of au.gov.asd.tac.constellation.views.qualitycontrol.QualityControlEvent in project constellation by constellation-app.

the class QualityControlStateUpdaterNGTest method testReadSelectedNodesWithRules.

@Test
public void testReadSelectedNodesWithRules() throws Exception {
    System.out.println("read Selected Nodes With Rules");
    graph = new DualGraph(SchemaFactoryUtilities.getSchemaFactory(VisualSchemaFactory.VISUAL_SCHEMA_ID).createSchema());
    WritableGraph wg = graph.getWritableGraph("Add Elements", true);
    try {
        // Add X,Y,Z vertex attributes
        attrX = VisualConcept.VertexAttribute.X.ensure(wg);
        attrY = VisualConcept.VertexAttribute.Y.ensure(wg);
        attrZ = VisualConcept.VertexAttribute.Z.ensure(wg);
        // Add vertex and transaction SELECTED attributes
        vSelectedAttrId = VisualConcept.VertexAttribute.SELECTED.ensure(wg);
        tSelectedAttrId = VisualConcept.TransactionAttribute.SELECTED.ensure(wg);
        // Add two vertices
        vxId1 = wg.addVertex();
        vxId2 = wg.addVertex();
        // Add one transaction between the two vertices
        txId1 = wg.addTransaction(vxId1, vxId2, false);
        wg.setFloatValue(attrX, vxId1, 1.0f);
        wg.setFloatValue(attrY, vxId1, 1.0f);
        wg.setBooleanValue(vSelectedAttrId, vxId1, false);
        wg.setFloatValue(attrX, vxId2, 2.0f);
        wg.setFloatValue(attrY, vxId2, 2.0f);
        wg.setBooleanValue(vSelectedAttrId, vxId1, true);
        // Add vertex IDENTIFIER attribute and label each vertice.
        vxIdentifierAttrId = VisualConcept.VertexAttribute.IDENTIFIER.ensure(wg);
        wg.setStringValue(vxIdentifierAttrId, vxId1, "Vertex1");
        wg.setStringValue(vxIdentifierAttrId, vxId2, "Vertex2");
        // Add vertex TYPE attribute and set each type to unknown
        typeAttrId = AnalyticConcept.VertexAttribute.TYPE.ensure(wg);
        wg.setObjectValue(typeAttrId, vxId1, SchemaVertexType.unknownType());
        wg.setObjectValue(typeAttrId, vxId2, SchemaVertexType.unknownType());
    } finally {
        wg.commit();
    }
    // Expected rules
    final List<QualityControlRule> expectedRegisteredRules = new ArrayList<>(Lookup.getDefault().lookupAll(QualityControlRule.class));
    // generate list of vertex ids
    final List<Integer> vertexIds = new ArrayList<>();
    vertexIds.add(0);
    vertexIds.add(1);
    // Check rules against vertex ids
    for (final QualityControlRule rule : expectedRegisteredRules) {
        rule.executeRule(graph.getReadableGraph(), vertexIds);
    }
    final List<QualityControlEvent> expectedQualityControlEvents = new ArrayList<>();
    expectedQualityControlEvents.add(new QualityControlEvent(0, "Vertex1", SchemaVertexType.unknownType(), expectedRegisteredRules));
    // Call update state to trigger checking of rules
    PluginExecution.withPlugin(new QualityControlStateUpdater()).executeNow(graph);
    // get the state and events
    final QualityControlState state = QualityControlAutoVetter.getInstance().getQualityControlState();
    final List<QualityControlEvent> qualityControlEvents = state.getQualityControlEvents();
    final List<QualityControlRule> registeredRules = state.getRegisteredRules();
    // Loop all events and check equality for each item specifically. Testing equality of the list was taken literally.
    assertEquals(qualityControlEvents.size(), expectedQualityControlEvents.size());
    int i = 0;
    for (QualityControlEvent event : expectedQualityControlEvents) {
        if (qualityControlEvents.size() >= i) {
            assertEquals(qualityControlEvents.get(i).getReasons(), event.getReasons());
            assertEquals(qualityControlEvents.get(i).getQuality(), event.getQuality());
            assertEquals(qualityControlEvents.get(i).getVertex(), event.getVertex());
            assertEquals(qualityControlEvents.get(i).getRules(), event.getRules());
            assertEquals(qualityControlEvents.get(i).getType(), event.getType());
        }
        i++;
    }
    // check equality of the rules
    assertEquals(registeredRules, expectedRegisteredRules);
}
Also used : QualityControlRule(au.gov.asd.tac.constellation.views.qualitycontrol.rules.QualityControlRule) QualityControlEvent(au.gov.asd.tac.constellation.views.qualitycontrol.QualityControlEvent) ArrayList(java.util.ArrayList) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) Test(org.testng.annotations.Test)

Example 2 with QualityControlEvent

use of au.gov.asd.tac.constellation.views.qualitycontrol.QualityControlEvent in project constellation by constellation-app.

the class DefaultQualityControlAutoButtonNGTest method setUpMethod.

@BeforeMethod
public void setUpMethod() throws Exception {
    final Schema schema = SchemaFactoryUtilities.getSchemaFactory(AnalyticSchemaFactory.ANALYTIC_SCHEMA_ID).createSchema();
    graph = new StoreGraph(schema);
    rules = new ArrayList<>();
    events = new ArrayList<>();
    // mock QualityControlEvent
    qualityControlEvent = mock(QualityControlEvent.class);
    when(qualityControlEvent.getCategory()).thenReturn(QualityCategory.CRITICAL);
    when(qualityControlEvent.getReasons()).thenReturn("Reason 1, Reason2");
    events.add(qualityControlEvent);
}
Also used : QualityControlEvent(au.gov.asd.tac.constellation.views.qualitycontrol.QualityControlEvent) Schema(au.gov.asd.tac.constellation.graph.schema.Schema) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 3 with QualityControlEvent

use of au.gov.asd.tac.constellation.views.qualitycontrol.QualityControlEvent in project constellation by constellation-app.

the class QualityControlStateUpdater method read.

@Override
public void read(final GraphReadMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
    final List<QualityControlRule> registeredRules = new ArrayList<>();
    final List<Integer> vertexList = new ArrayList<>();
    final List<String> identifierList = new ArrayList<>();
    final List<SchemaVertexType> typeList = new ArrayList<>();
    if (graph != null) {
        final int selectedAttribute = VisualConcept.VertexAttribute.SELECTED.get(graph);
        final int identifierAttribute = VisualConcept.VertexAttribute.IDENTIFIER.get(graph);
        final int typeAttribute = AnalyticConcept.VertexAttribute.TYPE.get(graph);
        if (selectedAttribute != Graph.NOT_FOUND && identifierAttribute != Graph.NOT_FOUND && typeAttribute != Graph.NOT_FOUND) {
            final int vxCount = graph.getVertexCount();
            for (int position = 0; position < vxCount; position++) {
                final int vertex = graph.getVertex(position);
                final String identifier = graph.getStringValue(identifierAttribute, vertex);
                final SchemaVertexType type = graph.getObjectValue(typeAttribute, vertex);
                final boolean selected = graph.getBooleanValue(selectedAttribute, vertex);
                if (selected) {
                    vertexList.add(vertex);
                    identifierList.add(identifier);
                    typeList.add(type);
                }
            }
        }
        // Set up and run each rule.
        if (!vertexList.isEmpty()) {
            for (final QualityControlRule rule : QualityControlAutoVetter.getRules()) {
                rule.clearResults();
                rule.executeRule(graph, vertexList);
                registeredRules.add(rule);
            }
        }
        final List<QualityControlRule> uRegisteredRules = Collections.unmodifiableList(registeredRules);
        // Build quality control events based on results of rules.
        // Sort by descending risk.
        final List<QualityControlEvent> qualityControlEvents = new ArrayList<>();
        for (int i = 0; i < vertexList.size(); i++) {
            final QualityControlEvent qualityControlEvent = new QualityControlEvent(vertexList.get(i), identifierList.get(i), typeList.get(i), uRegisteredRules);
            qualityControlEvents.add(qualityControlEvent);
        }
        Collections.sort(qualityControlEvents, Collections.reverseOrder());
        QualityControlAutoVetter.getInstance().setQualityControlState(new QualityControlState(graph.getId(), qualityControlEvents, registeredRules));
    }
}
Also used : QualityControlRule(au.gov.asd.tac.constellation.views.qualitycontrol.rules.QualityControlRule) SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) ArrayList(java.util.ArrayList) QualityControlEvent(au.gov.asd.tac.constellation.views.qualitycontrol.QualityControlEvent)

Example 4 with QualityControlEvent

use of au.gov.asd.tac.constellation.views.qualitycontrol.QualityControlEvent in project constellation by constellation-app.

the class DefaultQualityControlAutoButton method update.

@Override
protected void update(final QualityControlState state) {
    QualityControlEvent event = null;
    if (state != null) {
        event = state.getHighestScoringEvent();
    }
    final String riskText;
    final String styleText;
    final String tooltipText;
    if (event != null && event.getCategory() != QualityCategory.OK) {
        riskText = String.format(QUALITY_CONTROL_WIDGET_TEXT, String.valueOf(event.getCategory().name()));
        styleText = QualityControlViewPane.qualityStyle(event.getCategory(), 1);
        tooltipText = event.getReasons();
    } else {
        riskText = String.format(QUALITY_CONTROL_WIDGET_TEXT, String.valueOf(QualityCategory.OK.name()));
        styleText = DEFAULT_TEXT_STYLE;
        tooltipText = null;
    }
    Platform.runLater(() -> {
        setText(riskText);
        setStyle(styleText + BUTTON_STYLE);
        setTooltip(tooltipText != null ? new Tooltip(tooltipText) : null);
    });
}
Also used : QualityControlEvent(au.gov.asd.tac.constellation.views.qualitycontrol.QualityControlEvent) Tooltip(javafx.scene.control.Tooltip)

Example 5 with QualityControlEvent

use of au.gov.asd.tac.constellation.views.qualitycontrol.QualityControlEvent in project constellation by constellation-app.

the class QualityControlStateUpdaterNGTest method testReadNoNodesNoAttributes.

@Test
public void testReadNoNodesNoAttributes() throws Exception {
    System.out.println("read No Nodes");
    graph = new DualGraph(SchemaFactoryUtilities.getSchemaFactory(VisualSchemaFactory.VISUAL_SCHEMA_ID).createSchema());
    WritableGraph wg = graph.getWritableGraph("Add Elements", true);
    try {
        // Add X,Y,Z vertex attributes
        attrX = VisualConcept.VertexAttribute.X.ensure(wg);
        attrY = VisualConcept.VertexAttribute.Y.ensure(wg);
        attrZ = VisualConcept.VertexAttribute.Z.ensure(wg);
    } finally {
        wg.commit();
    }
    // Expected rules and events
    final List<QualityControlEvent> expectedQualityControlEvents = new ArrayList<>();
    final List<QualityControlRule> expectedRegisteredRules = new ArrayList<>();
    final List<QualityControlRule> uExpectedRegisteredRules = Collections.unmodifiableList(expectedRegisteredRules);
    // Call update state to trigger checking of rules
    PluginExecution.withPlugin(new QualityControlStateUpdater()).executeNow(graph);
    // get the state and events
    final QualityControlState state = QualityControlAutoVetter.getInstance().getQualityControlState();
    final List<QualityControlEvent> qualityControlEvents = state.getQualityControlEvents();
    final List<QualityControlRule> registeredRules = state.getRegisteredRules();
    // check equality of the events and rules
    assertEquals(qualityControlEvents, expectedQualityControlEvents);
    assertEquals(registeredRules, uExpectedRegisteredRules);
}
Also used : QualityControlRule(au.gov.asd.tac.constellation.views.qualitycontrol.rules.QualityControlRule) QualityControlEvent(au.gov.asd.tac.constellation.views.qualitycontrol.QualityControlEvent) ArrayList(java.util.ArrayList) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) Test(org.testng.annotations.Test)

Aggregations

QualityControlEvent (au.gov.asd.tac.constellation.views.qualitycontrol.QualityControlEvent)6 QualityControlRule (au.gov.asd.tac.constellation.views.qualitycontrol.rules.QualityControlRule)4 ArrayList (java.util.ArrayList)4 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)3 DualGraph (au.gov.asd.tac.constellation.graph.locking.DualGraph)3 Test (org.testng.annotations.Test)3 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)1 Schema (au.gov.asd.tac.constellation.graph.schema.Schema)1 SchemaVertexType (au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType)1 Tooltip (javafx.scene.control.Tooltip)1 BeforeMethod (org.testng.annotations.BeforeMethod)1