use of au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue in project constellation by constellation-app.
the class FactAnalyticPlugin method onPrerequisiteAttributeChange.
@Override
public void onPrerequisiteAttributeChange(final Graph graph, final PluginParameters parameters) {
final Set<TransactionTypeParameterValue> transactionTypes = new HashSet<>();
if (graph != null) {
final ReadableGraph readableGraph = graph.getReadableGraph();
try {
final int typeAttributeId = AnalyticConcept.TransactionAttribute.TYPE.get(readableGraph);
final int transactionCount = readableGraph.getTransactionCount();
for (int transactionPosition = 0; transactionPosition < transactionCount; transactionPosition++) {
final int transactionId = readableGraph.getTransaction(transactionPosition);
final SchemaTransactionType type = readableGraph.getObjectValue(typeAttributeId, transactionId);
transactionTypes.add(new TransactionTypeParameterValue(type));
}
} finally {
readableGraph.release();
}
}
// TRANSACTION_TYPES_PARAMETER always of type MultiChoiceParameter
@SuppressWarnings("unchecked") final PluginParameter<MultiChoiceParameterValue> transactionTypesParam = (PluginParameter<MultiChoiceParameterValue>) parameters.getParameters().get(TRANSACTION_TYPES_PARAMETER_ID);
MultiChoiceParameterType.setOptionsData(transactionTypesParam, new ArrayList<>(transactionTypes));
MultiChoiceParameterType.setChoicesData(transactionTypesParam, new ArrayList<>(transactionTypes));
}
use of au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue in project constellation by constellation-app.
the class FactAnalyticPlugin method edit.
@Override
protected final void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
try {
// prepare the graph
prepareGraph(graph, parameters);
// ensure the required analytic attributes exists on the graph
getAnalyticAttributes(parameters).forEach(schemaAttribute -> schemaAttribute.ensure(graph));
// TRANSACTION_TYPES_PARAMETER always of type MultiChoiceParameter
@SuppressWarnings("unchecked") final PluginParameter<MultiChoiceParameterValue> transactionTypesParameter = (PluginParameter<MultiChoiceParameterValue>) parameters.getParameters().get(TRANSACTION_TYPES_PARAMETER_ID);
final List<ParameterValue> allTransactionTypes = MultiChoiceParameterType.getOptionsData(transactionTypesParameter);
final List<? extends ParameterValue> chosenTransactionTypes = MultiChoiceParameterType.getChoicesData(transactionTypesParameter);
if (chosenTransactionTypes.equals(allTransactionTypes)) {
// run analytic plugin on the entire graph and compute results
PluginExecution.withPlugin(getAnalyticPlugin().getDeclaredConstructor().newInstance()).withParameters(parameters).executeNow(graph);
computeResultsFromGraph(graph, parameters);
} else {
// create subgraph
final Set<SchemaTransactionType> transactionTypes = new HashSet<>();
chosenTransactionTypes.forEach(parameterValue -> transactionTypes.add((SchemaTransactionType) ((TransactionTypeParameterValue) parameterValue).getObjectValue()));
assert transactionTypes.size() > 0 : "You must select at least one transaction type";
final StoreGraph subgraph = getSubgraph(graph, SchemaFactoryUtilities.getDefaultSchemaFactory(), transactionTypes);
// run analytic plugin on the subgraph and compute results
PluginExecution.withPlugin(getAnalyticPlugin().getDeclaredConstructor().newInstance()).withParameters(parameters).executeNow(subgraph);
copySubgraphToGraph(graph, subgraph);
computeResultsFromGraph(graph, parameters);
}
} catch (final IllegalAccessException | IllegalArgumentException | InstantiationException | NoSuchMethodException | SecurityException | InvocationTargetException ex) {
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
}
}
use of au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue in project constellation by constellation-app.
the class ScoreAnalyticPlugin method edit.
@Override
protected final void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
try {
// prepare the graph
prepareGraph(graph, parameters);
// ensure the required analytic attributes exists on the graph
getAnalyticAttributes(parameters).forEach(analyticAttribute -> analyticAttribute.ensure(graph));
// Transaction types parameter is created as a multiChoiceParameter in this class on line 166.
@SuppressWarnings("unchecked") final PluginParameter<MultiChoiceParameterValue> transactionTypesParameter = (PluginParameter<MultiChoiceParameterValue>) parameters.getParameters().get(TRANSACTION_TYPES_PARAMETER_ID);
final List<? extends ParameterValue> allTransactionTypes = MultiChoiceParameterType.getOptionsData(transactionTypesParameter);
final List<? extends ParameterValue> chosenTransactionTypes = MultiChoiceParameterType.getChoicesData(transactionTypesParameter);
if (chosenTransactionTypes.equals(allTransactionTypes)) {
// run analytic plugin on the entire graph and compute results
PluginExecution.withPlugin(getAnalyticPlugin().getDeclaredConstructor().newInstance()).withParameters(parameters).executeNow(graph);
computeResultsFromGraph(graph, parameters);
} else {
// create subgraph
final Set<SchemaTransactionType> transactionTypes = new HashSet<>();
parameters.getMultiChoiceValue(TRANSACTION_TYPES_PARAMETER_ID).getChoicesData().forEach(parameterValue -> transactionTypes.add((SchemaTransactionType) ((TransactionTypeParameterValue) parameterValue).getObjectValue()));
assert transactionTypes.size() > 0 : "You must select at least one transaction type";
final StoreGraph subgraph = getSubgraph(graph, SchemaFactoryUtilities.getDefaultSchemaFactory(), transactionTypes);
// run analytic plugin and compute results
PluginExecution.withPlugin(getAnalyticPlugin().getDeclaredConstructor().newInstance()).withParameters(parameters).executeNow(subgraph);
copySubgraphToGraph(graph, subgraph);
computeResultsFromGraph(graph, parameters);
}
} catch (final IllegalAccessException | IllegalArgumentException | InstantiationException | NoSuchMethodException | SecurityException | InvocationTargetException ex) {
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
}
}
use of au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue in project constellation by constellation-app.
the class MostLikelyCorrelatedQuestion method initialiseParameters.
@Override
public void initialiseParameters(final AnalyticPlugin<ScoreResult> plugin, final PluginParameters parameters) {
// TRANSACTION_TYPES_PARAMETER always of type MultiChoiceParameter
@SuppressWarnings("unchecked") final PluginParameter<MultiChoiceParameterValue> transactionTypeParameter = (PluginParameter<MultiChoiceParameterValue>) parameters.getParameters().get(ScoreAnalyticPlugin.TRANSACTION_TYPES_PARAMETER_ID);
final List<TransactionTypeParameterValue> newChecked = new ArrayList<>();
final List<ParameterValue> checked = transactionTypeParameter.getMultiChoiceValue().getChoicesData();
checked.forEach(parameterValue -> {
final TransactionTypeParameterValue transactionTypeParameterValue = (TransactionTypeParameterValue) parameterValue;
final SchemaTransactionType transactionType = (SchemaTransactionType) transactionTypeParameterValue.getObjectValue();
if (transactionType == null || !transactionType.isSubTypeOf(AnalyticConcept.TransactionType.SIMILARITY)) {
newChecked.add(transactionTypeParameterValue);
}
});
MultiChoiceParameterType.setChoicesData(transactionTypeParameter, newChecked);
parameters.setBooleanValue(CosineSimilarityPlugin.INCLUDE_CONNECTIONS_IN_PARAMETER_ID, true);
parameters.setBooleanValue(CosineSimilarityPlugin.INCLUDE_CONNECTIONS_OUT_PARAMETER_ID, true);
parameters.setBooleanValue(CosineSimilarityPlugin.TREAT_UNDIRECTED_BIDIRECTIONAL_PARAMETER_ID, true);
}
use of au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue in project constellation by constellation-app.
the class TestParametersPlugin method query.
@Override
protected RecordStore query(final RecordStore query, final PluginInteraction interaction, final PluginParameters parameters) throws PluginException {
final int sleep = parameters.getParameters().get(SLEEP_PARAMETER_ID).getIntegerValue();
for (int i = 0; i < sleep; i++) {
LOGGER.log(Level.INFO, "sleep {0}/{1}", new Object[] { i, sleep });
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
Thread.currentThread().interrupt();
}
}
LOGGER.log(Level.INFO, "slept for {0} seconds", sleep);
LOGGER.log(Level.INFO, "parameters: {0}", parameters);
LOGGER.log(Level.INFO, "GraphElementType: {0}", parameters.getSingleChoice(ELEMENT_TYPE_PARAMETER_ID));
final LocalDate localDate = parameters.getLocalDateValue(LOCAL_DATE_PARAMETER_ID);
LOGGER.log(Level.INFO, "localdate: {0} ", localDate);
if (localDate != null) {
final Calendar cal = LocalDateParameterType.toCalendar(localDate);
LOGGER.log(Level.INFO, String.format("toDate: [%s] [%04d-%02d-%02d]", cal, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH)));
LOGGER.log(Level.INFO, String.format("fields: [%04d-%02d-%02d]", localDate.get(ChronoField.YEAR), localDate.get(ChronoField.MONTH_OF_YEAR), localDate.get(ChronoField.DAY_OF_MONTH)));
}
final MultiChoiceParameterValue planets = parameters.getMultiChoiceValue(PLANETS_PARAMETER_ID);
planets.getChoices().stream().forEach(planet -> LOGGER.log(Level.INFO, "Planet: {0}", planet));
LOGGER.log(Level.INFO, "==== begin string values");
parameters.getParameters().values().stream().forEach(param -> LOGGER.log(Level.INFO, "String {0}: \"{1}\"", new Object[] { param.getName(), param.getStringValue() }));
LOGGER.log(Level.INFO, "==== end string values");
final File outputDir = DataAccessPreferenceUtilities.getDataAccessResultsDir();
if (outputDir != null) {
final String fnam = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss")) + "-testChainer.txt";
final File fout = new File(outputDir, fnam);
try (final PrintWriter writer = new PrintWriter(fout, StandardCharsets.UTF_8.name())) {
parameters.getParameters().values().stream().forEach(param -> writer.printf("%s: '%s'", param.getName(), param.getStringValue()));
} catch (final FileNotFoundException | UnsupportedEncodingException ex) {
Exceptions.printStackTrace(ex);
}
}
final List<String> keys = query.keys();
while (query.next()) {
keys.stream().forEach(key -> LOGGER.log(Level.INFO, String.format("%-20s: %s", key, query.get(key))));
LOGGER.log(Level.INFO, "--");
}
final boolean crash = parameters.getBooleanValue(CRASH_PARAMETER_ID);
if (crash) {
throw new RuntimeException("Simulated plugin failure");
}
try {
interaction.setProgress(1, 0, String.format("Pretended to add %d node(s), modify %d node(s)", r.nextInt(100) + 1, r.nextInt(100) + 1), false);
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
Thread.currentThread().interrupt();
}
final String queryName = parameters.getStringValue(CoreGlobalParameters.QUERY_NAME_PARAMETER_ID);
LOGGER.log(Level.INFO, "query name: {0}", queryName);
final DateTimeRange dtr = parameters.getDateTimeRangeValue(CoreGlobalParameters.DATETIME_RANGE_PARAMETER_ID);
final ZonedDateTime[] dtrStartEnd = dtr.getZonedStartEnd();
LOGGER.log(Level.INFO, "range: (zdt) {0} .. {1}", new Object[] { dtrStartEnd[0], dtrStartEnd[1] });
LOGGER.log(Level.INFO, "range: (zdt) {0} .. {1}", new Object[] { DateTimeFormatter.ISO_INSTANT.format(dtrStartEnd[0]), DateTimeFormatter.ISO_INSTANT.format(dtrStartEnd[1]) });
final String interactionLevel = parameters.getParameters().get(INTERACTION_PARAMETER_ID).getStringValue();
final PluginNotificationLevel pnInteractionLevel;
if (interactionLevel != null) {
switch(interactionLevel) {
case DEBUG:
pnInteractionLevel = PluginNotificationLevel.DEBUG;
break;
case INFO:
pnInteractionLevel = PluginNotificationLevel.INFO;
break;
case WARNING:
pnInteractionLevel = PluginNotificationLevel.WARNING;
break;
case ERROR:
pnInteractionLevel = PluginNotificationLevel.ERROR;
break;
case FATAL:
pnInteractionLevel = PluginNotificationLevel.FATAL;
break;
default:
pnInteractionLevel = null;
break;
}
if (pnInteractionLevel != null) {
interaction.notify(pnInteractionLevel, "Interaction from plugin");
}
}
final String exceptionLevel = parameters.getParameters().get(LEVEL_PARAMETER_ID).getStringValue();
final PluginNotificationLevel pnExceptionLevel;
if (exceptionLevel != null) {
switch(exceptionLevel) {
case DEBUG:
pnExceptionLevel = PluginNotificationLevel.DEBUG;
break;
case INFO:
pnExceptionLevel = PluginNotificationLevel.INFO;
break;
case WARNING:
pnExceptionLevel = PluginNotificationLevel.WARNING;
break;
case ERROR:
pnExceptionLevel = PluginNotificationLevel.ERROR;
break;
case FATAL:
pnExceptionLevel = PluginNotificationLevel.FATAL;
break;
default:
pnExceptionLevel = null;
break;
}
if (pnExceptionLevel != null) {
throw new PluginException(pnExceptionLevel, "Exception thrown from plugin");
}
}
// Add nodes containing global query parameters
final RecordStore results = new GraphRecordStore();
results.add();
results.set(GraphRecordStoreUtilities.SOURCE + AnalyticConcept.VertexAttribute.RAW, "name1@domain1.com");
results.set(GraphRecordStoreUtilities.SOURCE + AnalyticConcept.VertexAttribute.TYPE, "Email");
results.set(GraphRecordStoreUtilities.SOURCE + AnalyticConcept.VertexAttribute.COMMENT, queryName);
results.set(GraphRecordStoreUtilities.SOURCE + TemporalConcept.VertexAttribute.LAST_SEEN, DateTimeFormatter.ISO_INSTANT.format(dtrStartEnd[0]).replace("Z", ".000Z"));
results.set(GraphRecordStoreUtilities.DESTINATION + AnalyticConcept.VertexAttribute.RAW, "name2@domain2.com");
results.set(GraphRecordStoreUtilities.DESTINATION + AnalyticConcept.VertexAttribute.TYPE, "Email");
results.set(GraphRecordStoreUtilities.DESTINATION + AnalyticConcept.VertexAttribute.COMMENT, queryName);
results.set(GraphRecordStoreUtilities.DESTINATION + TemporalConcept.VertexAttribute.LAST_SEEN, DateTimeFormatter.ISO_INSTANT.format(dtrStartEnd[1]).replace("Z", ".000Z"));
results.set(GraphRecordStoreUtilities.TRANSACTION + AnalyticConcept.TransactionAttribute.COMMENT, parameters.toString());
return results;
}
Aggregations