Search in sources :

Example 56 with PluginParameter

use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameter in project constellation by constellation-app.

the class ExtractWordsFromTextPlugin method edit.

@Override
public void edit(final GraphWriteMethods wg, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
    interaction.setProgress(0, 0, "Extracting...", true);
    /*
         Retrieving attributes
         */
    final Map<String, PluginParameter<?>> extractEntityParameters = parameters.getParameters();
    final String contentAttribute = extractEntityParameters.get(ATTRIBUTE_PARAMETER_ID).getStringValue();
    final String words = extractEntityParameters.get(WORDS_PARAMETER_ID).getStringValue() == null ? null : extractEntityParameters.get(WORDS_PARAMETER_ID).getStringValue().trim();
    final boolean useRegex = extractEntityParameters.get(USE_REGEX_PARAMETER_ID).getBooleanValue();
    final boolean wholeWordOnly = extractEntityParameters.get(WHOLE_WORDS_ONLY_PARAMETER_ID).getBooleanValue();
    final int wordLength = parameters.getParameters().get(MIN_WORD_LENGTH_PARAMETER_ID).getIntegerValue();
    final boolean removeSpecialChars = extractEntityParameters.get(REMOVE_SPECIAL_CHARS_PARAMETER_ID).getBooleanValue();
    final boolean toLowerCase = extractEntityParameters.get(LOWER_CASE_PARAMETER_ID).getBooleanValue();
    final boolean types = extractEntityParameters.get(SCHEMA_TYPES_PARAMETER_ID).getBooleanValue();
    final String inOrOut = extractEntityParameters.get(IN_OR_OUT_PARAMETER_ID).getStringValue();
    final boolean selectedOnly = extractEntityParameters.get(SELECTED_ONLY_PARAMETER_ID).getBooleanValue();
    final boolean regexOnly = extractEntityParameters.get(REGEX_ONLY_PARAMETER_ID).getBooleanValue();
    if (!OUTGOING.equals(inOrOut) && !INCOMING.equals(inOrOut)) {
        var msg = String.format("Parameter %s must be '%s' or '%s'", REGEX_ONLY_PARAMETER_ID, OUTGOING, INCOMING);
        throw new PluginException(PluginNotificationLevel.ERROR, msg);
    }
    final boolean outgoing = OUTGOING.equals(inOrOut);
    /*
         Retrieving attribute IDs
         */
    final int vertexIdentifierAttributeId = VisualConcept.VertexAttribute.IDENTIFIER.ensure(wg);
    final int vertexTypeAttributeId = AnalyticConcept.VertexAttribute.TYPE.ensure(wg);
    final int transactionTypeAttributeId = AnalyticConcept.TransactionAttribute.TYPE.ensure(wg);
    final int transactionDatetimeAttributeId = TemporalConcept.TransactionAttribute.DATETIME.ensure(wg);
    final int transactionContentAttributeId = wg.getAttribute(GraphElementType.TRANSACTION, contentAttribute);
    final int transactionSelectedAttributeId = VisualConcept.TransactionAttribute.SELECTED.ensure(wg);
    // 
    if (transactionContentAttributeId == Graph.NOT_FOUND) {
        final NotifyDescriptor nd = new NotifyDescriptor.Message(String.format("The specified attribute %s does not exist.", contentAttribute), NotifyDescriptor.WARNING_MESSAGE);
        DialogDisplayer.getDefault().notify(nd);
        return;
    }
    final int transactionCount = wg.getTransactionCount();
    if (regexOnly) {
        // This choice ignores several other parameters, so is a bit simpler
        // even if there code commonalities, but combining the if/else
        // code would make things even more complex.
        // 
        // The input words are treated as trusted regular expressions,
        // so the caller has to know what they're doing.
        // This is power-use mode.
        // 
        // Each line of the input words is a regex.
        // Use them as-is for the power users.
        // 
        final List<Pattern> patterns = new ArrayList<>();
        if (StringUtils.isNotBlank(words)) {
            for (String word : words.split(SeparatorConstants.NEWLINE)) {
                word = word.strip();
                if (!word.isEmpty()) {
                    final Pattern pattern = Pattern.compile(word);
                    patterns.add(pattern);
                }
            }
        }
        if (!patterns.isEmpty()) {
            // Use a set to hold the words.
            // If a word is found multiple times, there's no point adding multiple nodes.
            // 
            final Set<String> matched = new HashSet<>();
            // 
            for (int transactionPosition = 0; transactionPosition < transactionCount; transactionPosition++) {
                final int transactionId = wg.getTransaction(transactionPosition);
                final boolean selectedTx = wg.getBooleanValue(transactionSelectedAttributeId, transactionId);
                if (selectedOnly && !selectedTx) {
                    continue;
                }
                final String content = wg.getStringValue(transactionContentAttributeId, transactionId);
                /*
                     Does the transaction have content?
                     */
                if (StringUtils.isBlank(content)) {
                    continue;
                }
                /*
                     Ignore other "referenced" transactions because that's not useful
                     */
                if (wg.getObjectValue(transactionTypeAttributeId, transactionId) != null && wg.getObjectValue(transactionTypeAttributeId, transactionId).equals(AnalyticConcept.TransactionType.REFERENCED)) {
                    continue;
                }
                patterns.stream().map(pattern -> pattern.matcher(content)).forEach(matcher -> {
                    while (matcher.find()) {
                        if (matcher.groupCount() == 0) {
                            // The regex doesn't have an explicit capture group, so capture the lot.
                            // 
                            final String g = matcher.group();
                            matched.add(toLowerCase ? g.toLowerCase() : g);
                        } else {
                            // 
                            for (int i = 1; i <= matcher.groupCount(); i++) {
                                final String g = matcher.group(i);
                                matched.add(toLowerCase ? g.toLowerCase() : g);
                            }
                        }
                    }
                });
                // 
                if (!matched.isEmpty()) {
                    /*
                         Retrieving information needed to create new transactions
                         */
                    final int sourceVertexId = wg.getTransactionSourceVertex(transactionId);
                    final int destinationVertexId = wg.getTransactionDestinationVertex(transactionId);
                    final ZonedDateTime datetime = wg.getObjectValue(transactionDatetimeAttributeId, transactionId);
                    matched.forEach(word -> {
                        final int newVertexId = wg.addVertex();
                        wg.setStringValue(vertexIdentifierAttributeId, newVertexId, word);
                        wg.setObjectValue(vertexTypeAttributeId, newVertexId, AnalyticConcept.VertexType.WORD);
                        final int newTransactionId = outgoing ? wg.addTransaction(sourceVertexId, newVertexId, true) : wg.addTransaction(newVertexId, destinationVertexId, true);
                        wg.setObjectValue(transactionDatetimeAttributeId, newTransactionId, datetime);
                        wg.setObjectValue(transactionTypeAttributeId, newTransactionId, AnalyticConcept.TransactionType.REFERENCED);
                        wg.setStringValue(transactionContentAttributeId, newTransactionId, content);
                    });
                }
            }
        }
    // End of regexOnly.
    } else {
        // The original logic.
        final List<Pattern> patterns = patternsFromWords(words, useRegex, wholeWordOnly);
        /*
             Iterating over all the transactions in the graph
             */
        final List<String> foundWords = new ArrayList<>();
        for (int transactionPosition = 0; transactionPosition < transactionCount; transactionPosition++) {
            foundWords.clear();
            final int transactionId = wg.getTransaction(transactionPosition);
            final boolean selectedTx = wg.getBooleanValue(transactionSelectedAttributeId, transactionId);
            if (selectedOnly && !selectedTx) {
                continue;
            }
            String content = wg.getStringValue(transactionContentAttributeId, transactionId);
            /*
                 Does the transaction have content?
                 */
            if (StringUtils.isBlank(content)) {
                continue;
            }
            /*
                 Ignore other "referenced" transactions because that's not useful
                 */
            if (wg.getObjectValue(transactionTypeAttributeId, transactionId) != null && wg.getObjectValue(transactionTypeAttributeId, transactionId).equals(AnalyticConcept.TransactionType.REFERENCED)) {
                continue;
            }
            /*
                 Retrieving information needed to create new transactions
                 */
            final int sourceVertexId = wg.getTransactionSourceVertex(transactionId);
            final int destinationVertexId = wg.getTransactionDestinationVertex(transactionId);
            final ZonedDateTime datetime = wg.getObjectValue(transactionDatetimeAttributeId, transactionId);
            final HashSet<String> typesExtracted = new HashSet<>();
            /*
                 Extracting Schema Types
                 */
            if (types) {
                final List<ExtractedVertexType> extractedTypes = SchemaVertexTypeUtilities.extractVertexTypes(content);
                final Map<String, SchemaVertexType> identifiers = new HashMap<>();
                extractedTypes.forEach(extractedType -> identifiers.put(extractedType.getIdentifier(), extractedType.getType()));
                for (String identifier : identifiers.keySet()) {
                    final int newVertexId = wg.addVertex();
                    wg.setStringValue(vertexIdentifierAttributeId, newVertexId, identifier);
                    wg.setObjectValue(vertexTypeAttributeId, newVertexId, identifiers.get(identifier));
                    final int newTransactionId = outgoing ? wg.addTransaction(sourceVertexId, newVertexId, true) : wg.addTransaction(newVertexId, destinationVertexId, true);
                    wg.setObjectValue(transactionDatetimeAttributeId, newTransactionId, datetime);
                    wg.setObjectValue(transactionTypeAttributeId, newTransactionId, AnalyticConcept.TransactionType.REFERENCED);
                    wg.setStringValue(transactionContentAttributeId, newTransactionId, content);
                    typesExtracted.add(identifier.toLowerCase());
                }
            }
            if (StringUtils.isBlank(words)) {
                /*
                     Extracting all words of the specified length if no word list has been provided
                     */
                for (String word : content.split(" ")) {
                    if (toLowerCase) {
                        word = word.toLowerCase();
                    }
                    if (removeSpecialChars) {
                        word = word.replaceAll("\\W", "");
                    }
                    if (word.length() < wordLength) {
                        continue;
                    }
                    foundWords.add(word);
                }
            } else {
                patterns.stream().map(pattern -> pattern.matcher(content)).forEach(matcher -> {
                    while (matcher.find()) {
                        final String g = matcher.group();
                        foundWords.add(toLowerCase ? g.toLowerCase() : g);
                    }
                });
            }
            /*
                 Add words to graph
                 */
            for (String word : foundWords) {
                if (types && typesExtracted.contains(word.toLowerCase())) {
                    continue;
                }
                final int newVertexId = wg.addVertex();
                wg.setStringValue(vertexIdentifierAttributeId, newVertexId, word);
                wg.setObjectValue(vertexTypeAttributeId, newVertexId, AnalyticConcept.VertexType.WORD);
                final int newTransactionId = outgoing ? wg.addTransaction(sourceVertexId, newVertexId, true) : wg.addTransaction(newVertexId, destinationVertexId, true);
                wg.setObjectValue(transactionDatetimeAttributeId, newTransactionId, datetime);
                wg.setObjectValue(transactionTypeAttributeId, newTransactionId, AnalyticConcept.TransactionType.REFERENCED);
                wg.setStringValue(transactionContentAttributeId, newTransactionId, content);
            }
        }
    }
    PluginExecutor.startWith(VisualSchemaPluginRegistry.COMPLETE_SCHEMA).followedBy(InteractiveGraphPluginRegistry.RESET_VIEW).executeNow(wg);
    interaction.setProgress(1, 0, "Completed successfully", true);
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) StringParameterType(au.gov.asd.tac.constellation.plugins.parameters.types.StringParameterType) SingleChoiceParameterType(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType) ZonedDateTime(java.time.ZonedDateTime) StringAttributeDescription(au.gov.asd.tac.constellation.graph.attribute.StringAttributeDescription) PluginType(au.gov.asd.tac.constellation.plugins.PluginType) StringUtils(org.apache.commons.lang3.StringUtils) DataAccessPlugin(au.gov.asd.tac.constellation.views.dataaccess.plugins.DataAccessPlugin) Map(java.util.Map) PluginExecutor(au.gov.asd.tac.constellation.plugins.PluginExecutor) StringParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.StringParameterValue) InteractiveGraphPluginRegistry(au.gov.asd.tac.constellation.graph.interaction.InteractiveGraphPluginRegistry) SeparatorConstants(au.gov.asd.tac.constellation.utilities.text.SeparatorConstants) BooleanParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType.BooleanParameterValue) Set(java.util.Set) PluginNotificationLevel(au.gov.asd.tac.constellation.plugins.PluginNotificationLevel) PluginInfo(au.gov.asd.tac.constellation.plugins.PluginInfo) List(java.util.List) NotifyDescriptor(org.openide.NotifyDescriptor) IntegerParameterType(au.gov.asd.tac.constellation.plugins.parameters.types.IntegerParameterType) VisualSchemaPluginRegistry(au.gov.asd.tac.constellation.graph.schema.visual.VisualSchemaPluginRegistry) Pattern(java.util.regex.Pattern) Messages(org.openide.util.NbBundle.Messages) GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods) SchemaVertexTypeUtilities(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexTypeUtilities) IntegerParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.IntegerParameterType.IntegerParameterValue) ParameterChange(au.gov.asd.tac.constellation.plugins.parameters.ParameterChange) 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) 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) ServiceProvider(org.openide.util.lookup.ServiceProvider) PluginTags(au.gov.asd.tac.constellation.plugins.templates.PluginTags) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) ContentConcept(au.gov.asd.tac.constellation.graph.schema.analytic.concept.ContentConcept) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) DialogDisplayer(org.openide.DialogDisplayer) ExtractedVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexTypeUtilities.ExtractedVertexType) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) BooleanParameterType(au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType) SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) AnalyticConcept(au.gov.asd.tac.constellation.graph.schema.analytic.concept.AnalyticConcept) TemporalConcept(au.gov.asd.tac.constellation.graph.schema.analytic.concept.TemporalConcept) SimpleQueryPlugin(au.gov.asd.tac.constellation.plugins.templates.SimpleQueryPlugin) DataAccessPluginCoreType(au.gov.asd.tac.constellation.views.dataaccess.plugins.DataAccessPluginCoreType) SingleChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue) Pattern(java.util.regex.Pattern) SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) HashMap(java.util.HashMap) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) ArrayList(java.util.ArrayList) ExtractedVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexTypeUtilities.ExtractedVertexType) NotifyDescriptor(org.openide.NotifyDescriptor) ZonedDateTime(java.time.ZonedDateTime) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) HashSet(java.util.HashSet)

Example 57 with PluginParameter

use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameter in project constellation by constellation-app.

the class ExtractWordsFromTextPlugin method updateParameters.

/**
 * Updating parameters to retrieve the transaction attributes
 *
 * @param graph
 * @param parameters
 */
@Override
public void updateParameters(final Graph graph, final PluginParameters parameters) {
    final List<String> attributes = new ArrayList<>();
    if (graph != null) {
        final ReadableGraph readableGraph = graph.getReadableGraph();
        try {
            final int attributeCount = readableGraph.getAttributeCount(GraphElementType.TRANSACTION);
            for (int attributePosition = 0; attributePosition < attributeCount; attributePosition++) {
                final int attributeId = readableGraph.getAttribute(GraphElementType.TRANSACTION, attributePosition);
                final String attributeType = readableGraph.getAttributeType(attributeId);
                if (attributeType.equals(StringAttributeDescription.ATTRIBUTE_NAME)) {
                    attributes.add(readableGraph.getAttributeName(attributeId));
                }
            }
        } finally {
            readableGraph.release();
        }
    }
    attributes.sort(String::compareTo);
    if (parameters != null && parameters.getParameters() != null) {
        // ATTRIBUTE_PARAMETER will always be of type SingleChoiceParameter
        @SuppressWarnings("unchecked") final PluginParameter<SingleChoiceParameterValue> contentAttribute = (PluginParameter<SingleChoiceParameterValue>) parameters.getParameters().get(ATTRIBUTE_PARAMETER_ID);
        SingleChoiceParameterType.setOptions(contentAttribute, attributes);
        contentAttribute.suppressEvent(true, new ArrayList<>());
        if (contentAttribute.getSingleChoice() == null && attributes.contains(ContentConcept.TransactionAttribute.CONTENT.getName())) {
            SingleChoiceParameterType.setChoice(contentAttribute, ContentConcept.TransactionAttribute.CONTENT.getName());
        }
        contentAttribute.suppressEvent(false, new ArrayList<>());
        contentAttribute.setObjectValue(parameters.getObjectValue(ATTRIBUTE_PARAMETER_ID));
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) ArrayList(java.util.ArrayList) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) SingleChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue)

Example 58 with PluginParameter

use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameter in project constellation by constellation-app.

the class MergeTransactionsPlugin method createParameters.

@Override
public PluginParameters createParameters() {
    PluginParameters params = new PluginParameters();
    final PluginParameter<SingleChoiceParameterValue> mergeType = SingleChoiceParameterType.build(MERGE_TYPE_PARAMETER_ID);
    mergeType.setName("Merge By");
    mergeType.setDescription("Transactions will be merged based on this");
    List<String> mergeTypes = new ArrayList<>(MERGE_TYPES.keySet());
    SingleChoiceParameterType.setOptions(mergeType, mergeTypes);
    params.addParameter(mergeType);
    final PluginParameter<IntegerParameterValue> threshold = IntegerParameterType.build(THRESHOLD_PARAMETER_ID);
    threshold.setName("Threshold");
    threshold.setIntegerValue(0);
    IntegerParameterType.setMinimum(threshold, 0);
    threshold.setEnabled(false);
    params.addParameter(threshold);
    final PluginParameter<SingleChoiceParameterValue> mergingRule = SingleChoiceParameterType.build(MERGER_PARAMETER_ID);
    mergingRule.setName("Merging Rule");
    mergingRule.setDescription("The rule deciding how attributes are merged");
    List<String> mergerNames = new ArrayList<>(MERGERS.keySet());
    SingleChoiceParameterType.setOptions(mergingRule, mergerNames);
    SingleChoiceParameterType.setChoice(mergingRule, mergerNames.get(0));
    mergingRule.setEnabled(false);
    params.addParameter(mergingRule);
    final PluginParameter<SingleChoiceParameterValue> leadParam = SingleChoiceParameterType.build(LEAD_PARAMETER_ID);
    leadParam.setName("Lead Transaction");
    leadParam.setDescription("The rule deciding how to choose the lead transaction");
    List<String> leadTransactionChooserNames = new ArrayList<>(LEAD_TRANSACTION_CHOOSERS.keySet());
    SingleChoiceParameterType.setOptions(leadParam, leadTransactionChooserNames);
    SingleChoiceParameterType.setChoice(leadParam, leadTransactionChooserNames.get(0));
    leadParam.setEnabled(false);
    params.addParameter(leadParam);
    final PluginParameter<BooleanParameterValue> selectedParam = BooleanParameterType.build(SELECTED_PARAMETER_ID);
    selectedParam.setName("Selected Only");
    selectedParam.setDescription("Merge Only Selected Transactions");
    selectedParam.setBooleanValue(false);
    selectedParam.setEnabled(false);
    params.addParameter(selectedParam);
    params.addController(MERGE_TYPE_PARAMETER_ID, (final PluginParameter<?> master, final Map<String, PluginParameter<?>> parameters, final ParameterChange change) -> {
        if (change == ParameterChange.VALUE) {
            final String selectedMergeType = parameters.get(MERGE_TYPE_PARAMETER_ID).getStringValue();
            if (MERGE_TYPES.containsKey(selectedMergeType)) {
                final MergeTransactionType mergeTransactionTypeSelected = MERGE_TYPES.get(selectedMergeType);
                mergeTransactionTypeSelected.updateParameters(parameters);
            }
        }
    });
    return params;
}
Also used : ParameterChange(au.gov.asd.tac.constellation.plugins.parameters.ParameterChange) ArrayList(java.util.ArrayList) BooleanParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType.BooleanParameterValue) 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) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) SingleChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue)

Example 59 with PluginParameter

use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameter in project constellation by constellation-app.

the class SplitNodesPlugin method edit.

@Override
public void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
    final Map<String, PluginParameter<?>> splitParameters = parameters.getParameters();
    final String character = splitParameters.get(SPLIT_PARAMETER_ID) != null && splitParameters.get(SPLIT_PARAMETER_ID).getStringValue() != null ? splitParameters.get(SPLIT_PARAMETER_ID).getStringValue() : "";
    final ParameterValue transactionTypeChoice = splitParameters.get(TRANSACTION_TYPE_PARAMETER_ID).getSingleChoice();
    final String linkType = transactionTypeChoice != null ? transactionTypeChoice.toString() : AnalyticConcept.TransactionType.CORRELATION.getName();
    final boolean allOccurrences = splitParameters.get(ALL_OCCURRENCES_PARAMETER_ID).getBooleanValue();
    final boolean splitIntoSameLevel = splitParameters.get(DUPLICATE_TRANSACTIONS_PARAMETER_ID).getBooleanValue();
    final int vertexSelectedAttributeId = VisualConcept.VertexAttribute.SELECTED.ensure(graph);
    final int vertexIdentifierAttributeId = VisualConcept.VertexAttribute.IDENTIFIER.ensure(graph);
    final List<Integer> newVertices = new ArrayList<>();
    final int graphVertexCount = graph.getVertexCount();
    for (int position = 0; position < graphVertexCount; position++) {
        final int currentVertexId = graph.getVertex(position);
        if (graph.getBooleanValue(vertexSelectedAttributeId, currentVertexId)) {
            final String identifier = graph.getStringValue(vertexIdentifierAttributeId, currentVertexId);
            if (identifier != null && identifier.contains(character) && identifier.indexOf(character) < identifier.length() - character.length()) {
                String leftNodeIdentifier = "";
                if (allOccurrences) {
                    final String[] substrings = Arrays.stream(identifier.split(character)).filter(value -> value != null && value.length() > 0).toArray(size -> new String[size]);
                    if (substrings.length <= 0) {
                        continue;
                    }
                    leftNodeIdentifier = substrings[0];
                    for (int i = 1; i < substrings.length; i++) {
                        newVertices.add(createNewNode(graph, position, substrings[i], linkType, splitIntoSameLevel));
                    }
                } else {
                    final int i = identifier.indexOf(character);
                    leftNodeIdentifier = identifier.substring(0, i);
                    if (StringUtils.isNotBlank(leftNodeIdentifier)) {
                        newVertices.add(createNewNode(graph, position, identifier.substring(i + 1), linkType, splitIntoSameLevel));
                    } else {
                        leftNodeIdentifier = identifier.substring(i + 1);
                    }
                }
                // Rename the selected node
                if (StringUtils.isNotBlank(leftNodeIdentifier)) {
                    graph.setStringValue(vertexIdentifierAttributeId, currentVertexId, leftNodeIdentifier);
                    newVertices.add(currentVertexId);
                }
            }
        }
    }
    if (!newVertices.isEmpty()) {
        // Reset the view
        graph.validateKey(GraphElementType.VERTEX, true);
        graph.validateKey(GraphElementType.TRANSACTION, true);
        final PluginExecutor arrangement = completionArrangement();
        if (arrangement != null) {
            // run the arrangement
            final VertexListInclusionGraph vlGraph = new VertexListInclusionGraph(graph, AbstractInclusionGraph.Connections.NONE, newVertices);
            arrangement.executeNow(vlGraph.getInclusionGraph());
            vlGraph.retrieveCoords();
        }
        if (splitParameters.get(COMPLETE_WITH_SCHEMA_OPTION_ID).getBooleanValue()) {
            PluginExecution.withPlugin(VisualSchemaPluginRegistry.COMPLETE_SCHEMA).executeNow(graph);
        }
        PluginExecutor.startWith(InteractiveGraphPluginRegistry.RESET_VIEW).executeNow(graph);
    }
}
Also used : GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods) SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) Arrays(java.util.Arrays) StringParameterType(au.gov.asd.tac.constellation.plugins.parameters.types.StringParameterType) 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) SimpleEditPlugin(au.gov.asd.tac.constellation.plugins.templates.SimpleEditPlugin) PluginType(au.gov.asd.tac.constellation.plugins.PluginType) VisualConcept(au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) Graph(au.gov.asd.tac.constellation.graph.Graph) ArrangementPluginRegistry(au.gov.asd.tac.constellation.plugins.arrangements.ArrangementPluginRegistry) 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) PluginExecutor(au.gov.asd.tac.constellation.plugins.PluginExecutor) PluginTags(au.gov.asd.tac.constellation.plugins.templates.PluginTags) StringParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.StringParameterValue) PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) AbstractInclusionGraph(au.gov.asd.tac.constellation.plugins.arrangements.AbstractInclusionGraph) VertexListInclusionGraph(au.gov.asd.tac.constellation.plugins.arrangements.VertexListInclusionGraph) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) InteractiveGraphPluginRegistry(au.gov.asd.tac.constellation.graph.interaction.InteractiveGraphPluginRegistry) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) BooleanParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType.BooleanParameterValue) ParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.ParameterValue) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) BooleanParameterType(au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType) PluginInfo(au.gov.asd.tac.constellation.plugins.PluginInfo) List(java.util.List) AnalyticConcept(au.gov.asd.tac.constellation.graph.schema.analytic.concept.AnalyticConcept) VisualSchemaPluginRegistry(au.gov.asd.tac.constellation.graph.schema.visual.VisualSchemaPluginRegistry) DataAccessPluginCoreType(au.gov.asd.tac.constellation.views.dataaccess.plugins.DataAccessPluginCoreType) NbBundle(org.openide.util.NbBundle) SingleChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue) StringParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.StringParameterValue) BooleanParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType.BooleanParameterValue) ParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.ParameterValue) SingleChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue) ArrayList(java.util.ArrayList) PluginExecutor(au.gov.asd.tac.constellation.plugins.PluginExecutor) VertexListInclusionGraph(au.gov.asd.tac.constellation.plugins.arrangements.VertexListInclusionGraph) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)

Example 60 with PluginParameter

use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameter in project constellation by constellation-app.

the class DataAccessParametersIoProviderNGTest method loadParameters.

@Test
public void loadParameters() throws IOException {
    final DataAccessPane dataAccessPane = mock(DataAccessPane.class);
    final DataAccessTabPane dataAccessTabPane = mock(DataAccessTabPane.class);
    when(dataAccessPane.getDataAccessTabPane()).thenReturn(dataAccessTabPane);
    final QueryPhasePane tab1 = mock(QueryPhasePane.class);
    final QueryPhasePane tab2 = mock(QueryPhasePane.class);
    when(dataAccessTabPane.newTab(anyString())).thenReturn(tab1).thenReturn(tab2);
    final GlobalParametersPane globalParametersPane1 = mock(GlobalParametersPane.class);
    final GlobalParametersPane globalParametersPane2 = mock(GlobalParametersPane.class);
    when(tab1.getGlobalParametersPane()).thenReturn(globalParametersPane1);
    when(tab2.getGlobalParametersPane()).thenReturn(globalParametersPane2);
    // By adding the settings bit here, it forces mockito to generate two different
    // classes. Otherwise they would be two different objects but have the same class name
    final Plugin plugin1 = mock(Plugin.class, withSettings().extraInterfaces(Comparable.class));
    final Plugin plugin2 = mock(Plugin.class, withSettings().extraInterfaces(Serializable.class));
    final DataSourceTitledPane dataSourceTitledPane1 = mock(DataSourceTitledPane.class);
    when(dataSourceTitledPane1.getPlugin()).thenReturn(plugin1);
    final DataSourceTitledPane dataSourceTitledPane2 = mock(DataSourceTitledPane.class);
    when(dataSourceTitledPane2.getPlugin()).thenReturn(plugin2);
    when(tab1.getDataAccessPanes()).thenReturn(List.of(dataSourceTitledPane1, dataSourceTitledPane2));
    when(tab2.getDataAccessPanes()).thenReturn(List.of());
    final PluginParameter pluginParameter1 = mock(PluginParameter.class);
    when(pluginParameter1.getId()).thenReturn("param1");
    final PluginParameter pluginParameter2 = mock(PluginParameter.class);
    when(pluginParameter2.getId()).thenReturn("param2");
    final PluginParameter pluginParameter3 = mock(PluginParameter.class);
    when(pluginParameter3.getId()).thenReturn("param3");
    final PluginParameter pluginParameter4 = mock(PluginParameter.class);
    when(pluginParameter4.getId()).thenReturn("param4");
    final PluginParameters globalPluginParameters1 = new PluginParameters();
    globalPluginParameters1.addParameter(pluginParameter1);
    globalPluginParameters1.addParameter(pluginParameter2);
    globalPluginParameters1.addParameter(pluginParameter3);
    final PluginParameters globalPluginParameters2 = new PluginParameters();
    globalPluginParameters2.addParameter(pluginParameter3);
    globalPluginParameters2.addParameter(pluginParameter4);
    when(globalParametersPane1.getParams()).thenReturn(globalPluginParameters1);
    when(globalParametersPane2.getParams()).thenReturn(globalPluginParameters2);
    try (final MockedStatic<JsonIO> jsonIOStaticMock = Mockito.mockStatic(JsonIO.class)) {
        final ObjectMapper objectMapper = new ObjectMapper();
        final String json = IOUtils.toString(new FileInputStream(getClass().getResource("resources/preferences.json").getPath()), StandardCharsets.UTF_8);
        // We do not know the mockito plugin names ahead of time so substitute them in now
        final StringSubstitutor substitutor = new StringSubstitutor(Map.of("INSERT_PLUGIN1_NAME", plugin1.getClass().getSimpleName(), "INSERT_PLUGIN2_NAME", plugin2.getClass().getSimpleName()));
        final List<DataAccessUserPreferences> preferences = objectMapper.readValue(substitutor.replace(json), new TypeReference<List<DataAccessUserPreferences>>() {
        });
        jsonIOStaticMock.when(() -> JsonIO.loadJsonPreferences(eq(Optional.of("DataAccessView")), any(TypeReference.class))).thenReturn(preferences);
        DataAccessParametersIoProvider.loadParameters(dataAccessPane);
    }
    verify(dataAccessTabPane, times(2)).newTab(anyString());
    // tab1 global parameters
    verify(pluginParameter1).setStringValue("tab1_param1_value");
    verify(pluginParameter3).setStringValue(null);
    // tab1 plugin parameters - only plugin1 because plugin2 is disabled
    verify(dataSourceTitledPane1).setParameterValues(Map.of(plugin1.getClass().getSimpleName() + "." + "__is_enabled__", "true", plugin1.getClass().getSimpleName() + "." + "param1", "plugin1_param1_value"));
    // tab2 global parameters
    verify(pluginParameter4).setStringValue("tab2_param4_value");
    // tab2 plugin parameters
    verify(dataSourceTitledPane2, times(0)).setParameterValues(anyMap());
}
Also used : JsonIO(au.gov.asd.tac.constellation.utilities.genericjsonio.JsonIO) Serializable(java.io.Serializable) DataAccessPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane) QueryPhasePane(au.gov.asd.tac.constellation.views.dataaccess.panes.QueryPhasePane) GlobalParametersPane(au.gov.asd.tac.constellation.views.dataaccess.panes.GlobalParametersPane) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FileInputStream(java.io.FileInputStream) DataAccessUserPreferences(au.gov.asd.tac.constellation.views.dataaccess.api.DataAccessUserPreferences) DataSourceTitledPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataSourceTitledPane) DataAccessTabPane(au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane) StringSubstitutor(org.apache.commons.text.StringSubstitutor) List(java.util.List) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) TypeReference(com.fasterxml.jackson.core.type.TypeReference) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) Test(org.testng.annotations.Test)

Aggregations

PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)93 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)53 Test (org.testng.annotations.Test)52 ArrayList (java.util.ArrayList)36 MultiChoiceParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue)25 SingleChoiceParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue)21 Map (java.util.Map)16 PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)15 IntegerParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.IntegerParameterType.IntegerParameterValue)13 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)12 SchemaTransactionType (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType)11 ParameterChange (au.gov.asd.tac.constellation.plugins.parameters.ParameterChange)11 Graph (au.gov.asd.tac.constellation.graph.Graph)10 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)10 BooleanParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType.BooleanParameterValue)10 HashMap (java.util.HashMap)10 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)9 List (java.util.List)9 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)8 StringParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.StringParameterValue)8