use of au.gov.asd.tac.constellation.graph.GraphAttribute in project constellation by constellation-app.
the class FindStateIOProvider method getRule.
/**
* Helper method that deserialises an individual rule from a JSON node.
*
* @param graph The graph that is being loaded.
* @param node The node that contains an individual FindRule.
* @return A single FindRule.
*/
private static FindRule getRule(final GraphReadMethods graph, final JsonNode node) {
final FindRule rule = new FindRule();
final int attrID = graph.getAttribute(GraphElementType.getValue(node.get(ELMT).asText()), node.get(ATTR).asText());
if (attrID != Graph.NOT_FOUND) {
final Attribute attr = new GraphAttribute(graph, attrID);
rule.setAttribute(attr);
rule.setOperator(FindTypeOperators.Operator.getTypeEnum(node.get(OPER).textValue()));
rule.setType(FindTypeOperators.Type.getTypeEnum(node.get(TYPE).textValue()));
rule.setHeld(node.get(HOLD).asBoolean());
rule.setArgs(getArguments(node.get(ARGS)));
return rule;
}
return null;
}
use of au.gov.asd.tac.constellation.graph.GraphAttribute in project constellation by constellation-app.
the class GraphAttributePlugin method retrieveAttributes.
/**
* Helper method that performs the attribute query operation.
* <p>
* Sets any found attributes to an internal variable which can be later
* returned through use of the <code>getAttributes()</code> method.
*
* @param graph The graph to retrieve attributes for.
*
* @see Graph
*/
private void retrieveAttributes(final GraphReadMethods graph) {
final long amc = graph.getAttributeModificationCounter();
attributes.clear();
final int attrCount = graph.getAttributeCount(type);
for (int position = 0; position < attrCount; position++) {
final int attr = graph.getAttribute(type, position);
final Attribute candidate = new GraphAttribute(graph, attr);
attributes.add(candidate);
}
attributeModificationCounter = amc;
}
use of au.gov.asd.tac.constellation.graph.GraphAttribute in project constellation by constellation-app.
the class BasicFindPluginNGTest method getAttributes.
/**
* Used to convert the string variant of attributes to the Attribute object
*
* @return the list of Attribute objects
*/
private ArrayList<Attribute> getAttributes() {
final FindViewTopComponent findViewTopComponent = mock(FindViewTopComponent.class);
FindViewController instance = FindViewController.getDefault().init(findViewTopComponent);
final GraphManager gm = Mockito.mock(GraphManager.class);
when(gm.getAllGraphs()).thenReturn(graphMap);
ArrayList<Attribute> attributes = new ArrayList<>();
try (MockedStatic<GraphManager> mockedStatic = Mockito.mockStatic(GraphManager.class)) {
mockedStatic.when(() -> GraphManager.getDefault()).thenReturn(gm);
GraphElementType type = GraphElementType.VERTEX;
List<String> result = instance.populateAttributes(type, attributes, Long.MIN_VALUE);
ReadableGraph rg = graph.getReadableGraph();
for (int i = 0; i < result.size(); i++) {
int attributeInt = rg.getAttribute(type, result.get(i));
GraphAttribute ga = new GraphAttribute(rg, attributeInt);
if (ga.getAttributeType().equals("string")) {
attributes.add(new GraphAttribute(rg, attributeInt));
System.out.println(attributes.get(i).getName() + " = attribute name");
}
}
rg.close();
}
return attributes;
}
use of au.gov.asd.tac.constellation.graph.GraphAttribute in project constellation by constellation-app.
the class ReplacePluginNGTest method getAttributes.
/**
* Used to convert the string variant of attributes to the Attribute object
*
* @return the list of Attribute objects
*/
private ArrayList<Attribute> getAttributes() {
final FindViewTopComponent findViewTopComponent = mock(FindViewTopComponent.class);
FindViewController instance = FindViewController.getDefault().init(findViewTopComponent);
final GraphManager gm = Mockito.mock(GraphManager.class);
when(gm.getAllGraphs()).thenReturn(graphMap);
ArrayList<Attribute> attributes = new ArrayList<>();
try (MockedStatic<GraphManager> mockedStatic = Mockito.mockStatic(GraphManager.class)) {
mockedStatic.when(() -> GraphManager.getDefault()).thenReturn(gm);
GraphElementType type = GraphElementType.VERTEX;
List<String> result = instance.populateAttributes(type, attributes, Long.MIN_VALUE);
ReadableGraph rg = graph.getReadableGraph();
for (int i = 0; i < result.size(); i++) {
int attributeInt = rg.getAttribute(type, result.get(i));
GraphAttribute ga = new GraphAttribute(rg, attributeInt);
if (ga.getAttributeType().equals("string")) {
attributes.add(new GraphAttribute(rg, attributeInt));
}
}
rg.close();
}
return attributes;
}
use of au.gov.asd.tac.constellation.graph.GraphAttribute in project constellation by constellation-app.
the class ReplaceTabNGTest method setupGraph.
private void setupGraph() {
graph = new DualGraph(SchemaFactoryUtilities.getSchemaFactory(VisualSchemaFactory.VISUAL_SCHEMA_ID).createSchema());
graph2 = new DualGraph(SchemaFactoryUtilities.getSchemaFactory(VisualSchemaFactory.VISUAL_SCHEMA_ID).createSchema());
graphMap.put(graph.getId(), graph);
graphMap.put(graph2.getId(), graph2);
try {
WritableGraph wg = graph.getWritableGraph("", true);
// Create Selected Attributes
selectedV = VisualConcept.VertexAttribute.SELECTED.ensure(wg);
labelV = VisualConcept.VertexAttribute.LABEL.ensure(wg);
identifierV = VisualConcept.VertexAttribute.IDENTIFIER.ensure(wg);
xV = VisualConcept.VertexAttribute.X.ensure(wg);
selectedT = VisualConcept.TransactionAttribute.SELECTED.ensure(wg);
labelT = VisualConcept.TransactionAttribute.LABEL.ensure(wg);
identiferT = VisualConcept.TransactionAttribute.IDENTIFIER.ensure(wg);
widthT = VisualConcept.TransactionAttribute.WIDTH.ensure(wg);
vxId1 = wg.addVertex();
wg.setBooleanValue(selectedV, vxId1, false);
wg.setStringValue(labelV, vxId1, "label name");
wg.setStringValue(identifierV, vxId1, "identifer name");
wg.setIntValue(xV, vxId1, 1);
/**
* Get the label and the identifier vertex attributes and add them
* to the attributes list
*/
GraphElementType elementType = GraphElementType.VERTEX;
// The label attribute
int attributeInt = wg.getAttribute(elementType, 1);
labelAttributeV = new GraphAttribute(wg, attributeInt);
replaceTab.attributes.add(labelAttributeV);
// The identifier attribute
attributeInt = wg.getAttribute(elementType, 2);
identifierAttributeV = new GraphAttribute(wg, attributeInt);
replaceTab.attributes.add(identifierAttributeV);
elementType = GraphElementType.TRANSACTION;
attributeInt = wg.getAttribute(elementType, 1);
labelAttributeT = new GraphAttribute(wg, attributeInt);
attributeInt = wg.getAttribute(elementType, 2);
identifierAttributeT = new GraphAttribute(wg, attributeInt);
wg.commit();
} catch (final InterruptedException ex) {
Exceptions.printStackTrace(ex);
Thread.currentThread().interrupt();
}
}
Aggregations