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;
}
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);
}
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;
}
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));
}
}
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;
}
Aggregations