Search in sources :

Example 1 with QualityControlRule

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

the class QualityControlViewPane method showPriorityDialog.

/**
 * Shows a dialog to allow the user to select priorities of each rule.
 */
private static void showPriorityDialog() {
    final ScrollPane rulesScrollPane = new ScrollPane();
    rulesScrollPane.setPrefHeight(240);
    rulesScrollPane.setPrefWidth(700);
    rulesScrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS);
    rulesScrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
    final GridPane buttonGrid = new GridPane();
    buttonGrid.prefWidthProperty().bind(rulesScrollPane.widthProperty());
    buttonGrid.setPadding(new Insets(5, 0, 5, 0));
    // Setting headings
    int rowCount = 0;
    final Label ruleLabel = new Label("Rule");
    ruleLabel.setPadding(new Insets(0, 100, 10, 5));
    buttonGrid.add(ruleLabel, 0, rowCount);
    final Label minorLabel = new Label("MINOR");
    minorLabel.setPadding(new Insets(0, 10, 10, 10));
    buttonGrid.add(minorLabel, 1, rowCount);
    final Label mediumLabel = new Label("MEDIUM");
    mediumLabel.setPadding(new Insets(0, 10, 10, 10));
    buttonGrid.add(mediumLabel, 2, rowCount);
    final Label majorLabel = new Label("MAJOR");
    majorLabel.setPadding(new Insets(0, 10, 10, 10));
    buttonGrid.add(majorLabel, 3, rowCount);
    final Label severeLabel = new Label("SEVERE");
    severeLabel.setPadding(new Insets(0, 10, 10, 10));
    buttonGrid.add(severeLabel, 4, rowCount);
    final Label criticalLabel = new Label("CRITICAL");
    criticalLabel.setPadding(new Insets(0, 10, 10, 10));
    buttonGrid.add(criticalLabel, 5, rowCount);
    rowCount++;
    // Setting rule names and buttons
    for (final QualityControlRule rule : Lookup.getDefault().lookupAll(QualityControlRule.class)) {
        final ToggleGroup ruleGroup = new ToggleGroup();
        final Label ruleName = new Label(rule.getName());
        final RadioButton minorButton = new RadioButton();
        final RadioButton mediumButton = new RadioButton();
        final RadioButton majorButton = new RadioButton();
        final RadioButton severeButton = new RadioButton();
        final RadioButton criticalButton = new RadioButton();
        final String resetText = rule.getCategory(0) == getPriorities().get(rule) ? "Reset" : "Reset to " + rule.getCategory(0).name();
        final Button resetButton = new Button(resetText);
        resetButton.setOnAction(event -> {
            switch(rule.getCategory(0)) {
                case MINOR:
                    minorButton.setSelected(true);
                    break;
                case MEDIUM:
                    mediumButton.setSelected(true);
                    break;
                case MAJOR:
                    majorButton.setSelected(true);
                    break;
                case SEVERE:
                    severeButton.setSelected(true);
                    break;
                case CRITICAL:
                    criticalButton.setSelected(true);
                    break;
                default:
                    break;
            }
            resetButton.setText("Reset");
        });
        getPriorities().putIfAbsent(rule, rule.getCategory(0));
        // setting the selection based on the current priority
        switch(getPriorities().get(rule)) {
            case MINOR:
                minorButton.setSelected(true);
                break;
            case MEDIUM:
                mediumButton.setSelected(true);
                break;
            case MAJOR:
                majorButton.setSelected(true);
                break;
            case SEVERE:
                severeButton.setSelected(true);
                break;
            case CRITICAL:
                criticalButton.setSelected(true);
                break;
            default:
                break;
        }
        toggleGroups.add(ruleGroup);
        GridPane.setHalignment(ruleName, HPos.LEFT);
        GridPane.setHalignment(minorButton, HPos.CENTER);
        GridPane.setHalignment(mediumButton, HPos.CENTER);
        GridPane.setHalignment(majorButton, HPos.CENTER);
        GridPane.setHalignment(severeButton, HPos.CENTER);
        GridPane.setHalignment(criticalButton, HPos.CENTER);
        GridPane.setHalignment(resetButton, HPos.CENTER);
        ruleName.setPadding(new Insets(0, 0, 5, 5));
        minorButton.setPadding(new Insets(0, 10, 5, 10));
        mediumButton.setPadding(new Insets(0, 10, 5, 10));
        majorButton.setPadding(new Insets(0, 10, 5, 10));
        severeButton.setPadding(new Insets(0, 10, 5, 10));
        criticalButton.setPadding(new Insets(0, 10, 5, 10));
        resetButton.setPadding(new Insets(5, 10, 5, 10));
        minorButton.setUserData(QualityCategory.MINOR);
        mediumButton.setUserData(QualityCategory.MEDIUM);
        majorButton.setUserData(QualityCategory.MAJOR);
        severeButton.setUserData(QualityCategory.SEVERE);
        criticalButton.setUserData(QualityCategory.CRITICAL);
        minorButton.setToggleGroup(ruleGroup);
        mediumButton.setToggleGroup(ruleGroup);
        majorButton.setToggleGroup(ruleGroup);
        severeButton.setToggleGroup(ruleGroup);
        criticalButton.setToggleGroup(ruleGroup);
        ruleGroup.setUserData(rule);
        buttonGrid.add(ruleName, 0, rowCount);
        buttonGrid.add(minorButton, 1, rowCount);
        buttonGrid.add(mediumButton, 2, rowCount);
        buttonGrid.add(majorButton, 3, rowCount);
        buttonGrid.add(severeButton, 4, rowCount);
        buttonGrid.add(criticalButton, 5, rowCount);
        buttonGrid.add(resetButton, 6, rowCount);
        rowCount++;
    }
    rulesScrollPane.setContent(buttonGrid);
    final Alert alert = new Alert(Alert.AlertType.INFORMATION, "Select Rule Priorities", ButtonType.OK, ButtonType.CANCEL);
    alert.setTitle("Select Rule Priorities");
    alert.setHeaderText("Customise the priority of rules");
    alert.getDialogPane().setContent(rulesScrollPane);
    alert.setResizable(true);
    if (alert.showAndWait().get() == ButtonType.OK) {
        for (final ToggleGroup tg : toggleGroups) {
            getPriorities().put((QualityControlRule) tg.getUserData(), (QualityCategory) tg.getSelectedToggle().getUserData());
        }
        QualityControlAutoVetter.getInstance().updateQualityEvents();
        writeSerializedRulePriorities();
    }
}
Also used : QualityControlRule(au.gov.asd.tac.constellation.views.qualitycontrol.rules.QualityControlRule) GridPane(javafx.scene.layout.GridPane) Insets(javafx.geometry.Insets) Button(javafx.scene.control.Button) RadioButton(javafx.scene.control.RadioButton) ScrollPane(javafx.scene.control.ScrollPane) ToggleGroup(javafx.scene.control.ToggleGroup) Label(javafx.scene.control.Label) Alert(javafx.scene.control.Alert) RadioButton(javafx.scene.control.RadioButton)

Example 2 with QualityControlRule

use of au.gov.asd.tac.constellation.views.qualitycontrol.rules.QualityControlRule 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 3 with QualityControlRule

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

the class QualityControlViewPaneNGTest method setUpMethod.

@BeforeMethod
public void setUpMethod() throws Exception {
    // create an analytic graph
    final Schema schema = SchemaFactoryUtilities.getSchemaFactory(AnalyticSchemaFactory.ANALYTIC_SCHEMA_ID).createSchema();
    graph = new StoreGraph(schema);
    // add attributes
    vertexIdentifierAttribute = VisualConcept.VertexAttribute.IDENTIFIER.ensure(graph);
    vertexTypeAttribute = AnalyticConcept.VertexAttribute.TYPE.ensure(graph);
    vertexSelectedAttribute = VisualConcept.VertexAttribute.SELECTED.ensure(graph);
    // add vertices
    vxId1 = graph.addVertex();
    vxId2 = graph.addVertex();
    vxId3 = graph.addVertex();
    // set all vertices to be selected
    graph.setBooleanValue(vertexSelectedAttribute, vxId1, true);
    graph.setBooleanValue(vertexSelectedAttribute, vxId2, true);
    graph.setBooleanValue(vertexSelectedAttribute, vxId3, false);
    rules = new ArrayList<>(Lookup.getDefault().lookupAll(QualityControlRule.class));
    vertices = Arrays.asList(vxId1, vxId2);
    for (final QualityControlRule rule : rules) {
        rule.executeRule(graph, vertices);
    }
    events = new ArrayList<>();
    for (final int vertexId : vertices) {
        final String type = graph.getStringValue(vertexTypeAttribute, vertexId);
        events.add(new QualityControlEvent(vertexId, graph.getStringValue(vertexIdentifierAttribute, vertexId), SchemaVertexTypeUtilities.getType(type), rules));
    }
}
Also used : QualityControlRule(au.gov.asd.tac.constellation.views.qualitycontrol.rules.QualityControlRule) Schema(au.gov.asd.tac.constellation.graph.schema.Schema) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 4 with QualityControlRule

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

the class QualityControlViewPane method showRuleDialog.

/**
 * Display a dialog containing all Rule objects registered with the Quality
 * Control View and which matched for a given QualityControlEvent.
 *
 * @param owner
 * @param qcevent
 */
private static void showRuleDialog(final TableCell<QualityControlEvent, QualityControlEvent> qcevent) {
    if (qcevent.getItem() != null) {
        final int vxId = qcevent.getItem().getVertex();
        final String identifier = qcevent.getItem().getIdentifier();
        final List<Pair<QualityCategory, String>> rules = new ArrayList<>();
        for (final QualityControlRule rule : qcevent.getItem().getRules()) {
            // Hack the name and explanation together to obviate the need for another data structure.
            final String ruleName = rule.getName() + "ยง" + rule.getDescription();
            final QualityCategory quality = rule.getResults().contains(vxId) ? getPriorities().get(rule) : null;
            if (quality != null) {
                rules.add(new Pair<>(quality, ruleName));
            }
        }
        Collections.sort(rules, (p1, p2) -> {
            final int compare = QualityControlRule.testPriority(p1.getKey(), p2.getKey());
            return compare == 0 ? p1.getValue().compareTo(p2.getValue()) : compare;
        });
        showRuleDialog(identifier, rules);
    }
}
Also used : QualityControlRule(au.gov.asd.tac.constellation.views.qualitycontrol.rules.QualityControlRule) QualityCategory(au.gov.asd.tac.constellation.views.qualitycontrol.QualityControlEvent.QualityCategory) ArrayList(java.util.ArrayList) Pair(javafx.util.Pair)

Example 5 with QualityControlRule

use of au.gov.asd.tac.constellation.views.qualitycontrol.rules.QualityControlRule 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)

Aggregations

QualityControlRule (au.gov.asd.tac.constellation.views.qualitycontrol.rules.QualityControlRule)8 ArrayList (java.util.ArrayList)5 QualityControlEvent (au.gov.asd.tac.constellation.views.qualitycontrol.QualityControlEvent)4 Test (org.testng.annotations.Test)4 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)3 DualGraph (au.gov.asd.tac.constellation.graph.locking.DualGraph)3 QualityCategory (au.gov.asd.tac.constellation.views.qualitycontrol.QualityControlEvent.QualityCategory)2 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 IdentifierInconsistentWithTypeRule (au.gov.asd.tac.constellation.views.qualitycontrol.rules.IdentifierInconsistentWithTypeRule)1 MissingTypeRule (au.gov.asd.tac.constellation.views.qualitycontrol.rules.MissingTypeRule)1 UnknownTypeRule (au.gov.asd.tac.constellation.views.qualitycontrol.rules.UnknownTypeRule)1 Insets (javafx.geometry.Insets)1 Alert (javafx.scene.control.Alert)1 Button (javafx.scene.control.Button)1 Label (javafx.scene.control.Label)1 RadioButton (javafx.scene.control.RadioButton)1 ScrollPane (javafx.scene.control.ScrollPane)1 ToggleGroup (javafx.scene.control.ToggleGroup)1