Search in sources :

Example 21 with SchemaVertexType

use of au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType in project constellation by constellation-app.

the class SelectTopNPlugin method createParameters.

@Override
public PluginParameters createParameters() {
    final PluginParameters params = new PluginParameters();
    final List<String> modes = new ArrayList<>();
    modes.add(NODE);
    modes.add(TRANSACTION);
    final PluginParameter<SingleChoiceParameterValue> modeParameter = SingleChoiceParameterType.build(MODE_PARAMETER_ID);
    modeParameter.setName("Mode");
    modeParameter.setDescription("Select either the Node or Transaction mode");
    SingleChoiceParameterType.setOptions(modeParameter, modes);
    params.addParameter(modeParameter);
    final PluginParameter<SingleChoiceParameterValue> typeCategoryParameter = SingleChoiceParameterType.build(TYPE_CATEGORY_PARAMETER_ID);
    typeCategoryParameter.setName("Type Category");
    typeCategoryParameter.setDescription("The high level type category");
    params.addParameter(typeCategoryParameter);
    final PluginParameter<MultiChoiceParameterValue> typeParameter = MultiChoiceParameterType.build(TYPE_PARAMETER_ID);
    typeParameter.setName("Specific Types");
    typeParameter.setDescription("The specific types to include when calculating the top N");
    params.addParameter(typeParameter);
    final PluginParameter<IntegerParameterValue> limitParameter = IntegerParameterType.build(LIMIT_PARAMETER_ID);
    limitParameter.setName("Limit");
    limitParameter.setDescription("The limit, default being 10");
    limitParameter.setIntegerValue(10);
    params.addParameter(limitParameter);
    params.addController(MODE_PARAMETER_ID, (PluginParameter<?> master, Map<String, PluginParameter<?>> parameters, ParameterChange change) -> {
        if (change == ParameterChange.VALUE) {
            final String mode = parameters.get(MODE_PARAMETER_ID).getStringValue();
            if (mode != null) {
                final List<String> types = new ArrayList<>();
                switch(mode) {
                    case NODE:
                        for (final SchemaVertexType type : SchemaVertexTypeUtilities.getTypes()) {
                            if (type.isTopLevelType()) {
                                types.add(type.getName());
                            }
                        }
                        break;
                    case TRANSACTION:
                        for (final SchemaTransactionType type : SchemaTransactionTypeUtilities.getTypes()) {
                            if (type.isTopLevelType()) {
                                types.add(type.getName());
                            }
                        }
                        break;
                    default:
                        LOGGER.severe("Invalid mode provided. Mode values accepted are " + NODE + " or " + TRANSACTION);
                }
                // TYPE_CATEGORY_PARAMETER will always be of type SingleChoiceParameter
                @SuppressWarnings("unchecked") final PluginParameter<SingleChoiceParameterValue> typeCategoryParamter = (PluginParameter<SingleChoiceParameterValue>) parameters.get(TYPE_CATEGORY_PARAMETER_ID);
                types.sort(String::compareTo);
                SingleChoiceParameterType.setOptions(typeCategoryParamter, types);
            }
        }
    });
    params.addController(TYPE_CATEGORY_PARAMETER_ID, (PluginParameter<?> master, Map<String, PluginParameter<?>> parameters, ParameterChange change) -> {
        if (change == ParameterChange.VALUE) {
            final String mode = parameters.get(MODE_PARAMETER_ID).getStringValue();
            final String typeCategory = parameters.get(TYPE_CATEGORY_PARAMETER_ID).getStringValue();
            if (mode != null && typeCategory != null) {
                final List<String> types = new ArrayList<>();
                switch(mode) {
                    case NODE:
                        final SchemaVertexType typeCategoryVertexType = SchemaVertexTypeUtilities.getType(typeCategory);
                        for (final SchemaVertexType type : SchemaVertexTypeUtilities.getTypes()) {
                            if (type.getSuperType().equals(typeCategoryVertexType)) {
                                types.add(type.getName());
                            }
                        }
                        break;
                    case TRANSACTION:
                        final SchemaTransactionType typeCategoryTransactionType = SchemaTransactionTypeUtilities.getType(typeCategory);
                        for (final SchemaTransactionType type : SchemaTransactionTypeUtilities.getTypes()) {
                            if (type.getSuperType().equals(typeCategoryTransactionType)) {
                                types.add(type.getName());
                            }
                        }
                        break;
                    default:
                        break;
                }
                // update the sub level types
                // TYPE_PARAMETER will always be of type MultiChoiceParameter
                @SuppressWarnings("unchecked") final PluginParameter<MultiChoiceParameterValue> typeParamter = (PluginParameter<MultiChoiceParameterValue>) parameters.get(TYPE_PARAMETER_ID);
                types.sort(String::compareTo);
                MultiChoiceParameterType.setOptions(typeParamter, types);
                MultiChoiceParameterType.setChoices(typeParamter, types);
            }
        }
    });
    return params;
}
Also used : ParameterChange(au.gov.asd.tac.constellation.plugins.parameters.ParameterChange) SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) MultiChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue) ArrayList(java.util.ArrayList) SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) IntegerParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.IntegerParameterType.IntegerParameterValue) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) SingleChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue)

Example 22 with SchemaVertexType

use of au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType in project constellation by constellation-app.

the class SelectTopNPlugin method edit.

@Override
protected void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
    final String mode = parameters.getParameters().get(MODE_PARAMETER_ID).getStringValue();
    final String typeCategory = parameters.getParameters().get(TYPE_CATEGORY_PARAMETER_ID).getStringValue();
    final List<String> subTypes = parameters.getParameters().get(TYPE_PARAMETER_ID).getMultiChoiceValue().getChoices();
    final int limit = parameters.getParameters().get(LIMIT_PARAMETER_ID).getIntegerValue();
    if (mode == null || (!mode.equals(NODE) && !mode.equals(TRANSACTION))) {
        throw new PluginException(PluginNotificationLevel.ERROR, "Invalid mode value provided");
    }
    if (typeCategory == null) {
        throw new PluginException(PluginNotificationLevel.ERROR, "Select a type category");
    }
    if (subTypes.isEmpty()) {
        throw new PluginException(PluginNotificationLevel.ERROR, "Select some types to perform the calculation");
    }
    final int vertexLabelAttribute = VisualConcept.VertexAttribute.LABEL.get(graph);
    if (vertexLabelAttribute == Graph.NOT_FOUND) {
        throw new PluginException(PluginNotificationLevel.ERROR, String.format(MISSING_PROPERTY_FORMAT, VisualConcept.VertexAttribute.LABEL.getName()));
    }
    final int vertexSelectedAttribute = VisualConcept.VertexAttribute.SELECTED.get(graph);
    if (vertexSelectedAttribute == Graph.NOT_FOUND) {
        throw new PluginException(PluginNotificationLevel.ERROR, String.format(MISSING_PROPERTY_FORMAT, VisualConcept.VertexAttribute.SELECTED.getName()));
    }
    final int vertexTypeAttribute = AnalyticConcept.VertexAttribute.TYPE.get(graph);
    if (vertexTypeAttribute == Graph.NOT_FOUND) {
        throw new PluginException(PluginNotificationLevel.ERROR, String.format(MISSING_PROPERTY_FORMAT, AnalyticConcept.VertexAttribute.TYPE.getName()));
    }
    final int transactionTypeAttribute = AnalyticConcept.TransactionAttribute.TYPE.get(graph);
    if (transactionTypeAttribute == Graph.NOT_FOUND) {
        throw new PluginException(PluginNotificationLevel.ERROR, String.format(MISSING_PROPERTY_FORMAT, AnalyticConcept.TransactionAttribute.TYPE.getName()));
    }
    // make a set of the highlighted nodes
    final Set<Integer> selectedNodes = new HashSet<>();
    final int vertexCount = graph.getVertexCount();
    for (int position = 0; position < vertexCount; position++) {
        final int vxId = graph.getVertex(position);
        if (graph.getBooleanValue(vertexSelectedAttribute, vxId)) {
            selectedNodes.add(vxId);
        }
    }
    if (selectedNodes.isEmpty()) {
        throw new PluginException(PluginNotificationLevel.ERROR, "Select at least 1 node");
    }
    // calculate the occurrences of destination vertices
    int txId;
    int sourceVxId;
    int destinationVxId;
    int targetVxId;
    int step = 0;
    SchemaVertexType destinationVertexType;
    SchemaTransactionType transactionType;
    final Map<Integer, Integer> occurrences = new HashMap<>();
    for (final Integer vxId : selectedNodes) {
        final String label = graph.getStringValue(vertexLabelAttribute, vxId);
        interaction.setProgress(++step, selectedNodes.size(), String.format("Calculating top %s for %s", limit, label), true);
        final int transactionCount = graph.getVertexTransactionCount(vxId);
        for (int position = 0; position < transactionCount; position++) {
            txId = graph.getVertexTransaction(vxId, position);
            sourceVxId = graph.getTransactionSourceVertex(txId);
            destinationVxId = graph.getTransactionDestinationVertex(txId);
            targetVxId = vxId == sourceVxId ? destinationVxId : sourceVxId;
            switch(mode) {
                case NODE:
                    destinationVertexType = graph.getObjectValue(vertexTypeAttribute, targetVxId);
                    if (destinationVertexType != null && subTypes.contains(destinationVertexType.getName())) {
                        if (!occurrences.containsKey(targetVxId)) {
                            occurrences.put(targetVxId, 0);
                        }
                        occurrences.put(targetVxId, occurrences.get(targetVxId) + 1);
                    }
                    break;
                case TRANSACTION:
                    transactionType = graph.getObjectValue(transactionTypeAttribute, txId);
                    if (transactionType != null && subTypes.contains(transactionType.getName())) {
                        if (!occurrences.containsKey(targetVxId)) {
                            occurrences.put(targetVxId, 0);
                        }
                        occurrences.put(targetVxId, occurrences.get(targetVxId) + 1);
                    }
                    break;
                default:
                    break;
            }
        }
        // make a map sorted by the count in descending order
        final LinkedHashMap<Integer, Integer> sortedMap = occurrences.entrySet().stream().sorted(Map.Entry.comparingByValue(Collections.reverseOrder())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
        sortedMap.keySet().stream().limit(limit).forEach(id -> graph.setBooleanValue(vertexSelectedAttribute, id, true));
        interaction.setProgress(1, 0, "Selected " + sortedMap.size() + " nodes.", true);
    }
    interaction.setProgress(1, 0, "Completed successfully", true);
}
Also used : GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods) SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) SchemaVertexTypeUtilities(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexTypeUtilities) IntegerParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.IntegerParameterType.IntegerParameterValue) SchemaTransactionTypeUtilities(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionTypeUtilities) ParameterChange(au.gov.asd.tac.constellation.plugins.parameters.ParameterChange) SingleChoiceParameterType(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType) MultiChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue) PluginType(au.gov.asd.tac.constellation.plugins.PluginType) HashMap(java.util.HashMap) VisualConcept(au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept) ArrayList(java.util.ArrayList) Graph(au.gov.asd.tac.constellation.graph.Graph) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) DataAccessPlugin(au.gov.asd.tac.constellation.views.dataaccess.plugins.DataAccessPlugin) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) ServiceProviders(org.openide.util.lookup.ServiceProviders) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) Map(java.util.Map) ServiceProvider(org.openide.util.lookup.ServiceProvider) PluginTags(au.gov.asd.tac.constellation.plugins.templates.PluginTags) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) MultiChoiceParameterType(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType) Set(java.util.Set) Logger(java.util.logging.Logger) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) Collectors(java.util.stream.Collectors) PluginNotificationLevel(au.gov.asd.tac.constellation.plugins.PluginNotificationLevel) SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) PluginInfo(au.gov.asd.tac.constellation.plugins.PluginInfo) List(java.util.List) AnalyticConcept(au.gov.asd.tac.constellation.graph.schema.analytic.concept.AnalyticConcept) IntegerParameterType(au.gov.asd.tac.constellation.plugins.parameters.types.IntegerParameterType) SimpleQueryPlugin(au.gov.asd.tac.constellation.plugins.templates.SimpleQueryPlugin) DataAccessPluginCoreType(au.gov.asd.tac.constellation.views.dataaccess.plugins.DataAccessPluginCoreType) Messages(org.openide.util.NbBundle.Messages) SingleChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue) Collections(java.util.Collections) SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 23 with SchemaVertexType

use of au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType in project constellation by constellation-app.

the class MergeNodesByType method getNodesToMerge.

@Override
public final Map<Integer, Set<Integer>> getNodesToMerge(final GraphWriteMethods graph, final Comparator<String> leadVertexChooser, final int threshold, final boolean selectedOnly) {
    final Map<String, Map<Integer, SchemaVertexType>> typeMap = new HashMap<>();
    final Map<Integer, Set<Integer>> nodesToMerge = new HashMap<>();
    final int identifierAttribute = VisualConcept.VertexAttribute.IDENTIFIER.get(graph);
    if (identifierAttribute == Graph.NOT_FOUND) {
        return nodesToMerge;
    }
    final int typeAttribute = AnalyticConcept.VertexAttribute.TYPE.get(graph);
    if (typeAttribute == Graph.NOT_FOUND) {
        return nodesToMerge;
    }
    final int selectedAttribute = VisualConcept.VertexAttribute.SELECTED.get(graph);
    final int vertexCount = graph.getVertexCount();
    for (int vertexPosition = 0; vertexPosition < vertexCount; vertexPosition++) {
        final int vxId = graph.getVertex(vertexPosition);
        final String identifier = graph.getStringValue(identifierAttribute, vxId);
        final SchemaVertexType type = graph.getObjectValue(typeAttribute, vxId);
        if (!selectedOnly || graph.getBooleanValue(selectedAttribute, vxId)) {
            Map<Integer, SchemaVertexType> matchingVertices = typeMap.get(identifier);
            if (matchingVertices == null) {
                matchingVertices = new LinkedHashMap<>();
                typeMap.put(identifier, matchingVertices);
            }
            matchingVertices.put(vxId, type);
        }
    }
    // get a list type names for a quick lookup
    final Collection<? extends SchemaVertexType> supportedTypes = SchemaVertexTypeUtilities.getTypes();
    for (final Map<Integer, SchemaVertexType> matchingVertices : typeMap.values()) {
        if (matchingVertices.size() > 1) {
            int leadVertex = Graph.NOT_FOUND;
            for (Map.Entry<Integer, SchemaVertexType> entry : matchingVertices.entrySet()) {
                if (supportedTypes.contains(entry.getValue())) {
                    leadVertex = entry.getKey();
                    break;
                }
            }
            if (leadVertex != Graph.NOT_FOUND) {
                nodesToMerge.put(leadVertex, matchingVertices.keySet());
            }
        }
    }
    return nodesToMerge;
}
Also used : Set(java.util.Set) SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 24 with SchemaVertexType

use of au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType 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 25 with SchemaVertexType

use of au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType in project constellation by constellation-app.

the class IdentifierInconsistentWithTypeRule method executeRule.

@Override
protected boolean executeRule(final GraphReadMethods graph, final int vertexId) {
    final int identifierAttribute = VisualConcept.VertexAttribute.IDENTIFIER.get(graph);
    final int typeAttribute = AnalyticConcept.VertexAttribute.TYPE.get(graph);
    if (identifierAttribute != Graph.NOT_FOUND && typeAttribute != Graph.NOT_FOUND) {
        final String identifier = graph.getStringValue(identifierAttribute, vertexId);
        final SchemaVertexType type = graph.getObjectValue(typeAttribute, vertexId);
        if (identifier != null && type != null && !SchemaVertexTypeUtilities.getDefaultType().equals(type)) {
            final Pattern validationRegex = type.getValidationRegex();
            return validationRegex != null && !validationRegex.matcher(identifier).matches();
        }
    }
    return false;
}
Also used : Pattern(java.util.regex.Pattern) SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType)

Aggregations

SchemaVertexType (au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType)30 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)9 SchemaTransactionType (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType)8 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)6 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)6 Map (java.util.Map)6 SchemaConcept (au.gov.asd.tac.constellation.graph.schema.concept.SchemaConcept)5 SchemaVertexTypeUtilities (au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexTypeUtilities)5 List (java.util.List)5 Test (org.testng.annotations.Test)5 Graph (au.gov.asd.tac.constellation.graph.Graph)4 AnalyticConcept (au.gov.asd.tac.constellation.graph.schema.analytic.concept.AnalyticConcept)4 VisualConcept (au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept)4 MultiChoiceParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue)4 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)3 SchemaTransactionTypeUtilities (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionTypeUtilities)3 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)3 ParameterChange (au.gov.asd.tac.constellation.plugins.parameters.ParameterChange)3 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)3