use of au.gov.asd.tac.constellation.graph.Attribute 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.Attribute 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.Attribute in project constellation by constellation-app.
the class ResetStatePluginNGTest method setupGraph.
private void setupGraph() {
graph = new DualGraph(SchemaFactoryUtilities.getSchemaFactory(VisualSchemaFactory.VISUAL_SCHEMA_ID).createSchema());
try {
WritableGraph wg = graph.getWritableGraph("", true);
final int stateId = FindViewConcept.MetaAttribute.FINDVIEW_STATE.ensure(wg);
ArrayList<Attribute> attributeList = new ArrayList<>();
BasicFindReplaceParameters parameters = new BasicFindReplaceParameters("label name", "", GraphElementType.GRAPH.VERTEX, attributeList, true, false, false, false, false, false, false, false, false);
FindResultsList foundResult = new FindResultsList(2, parameters, graph.getId());
wg.setObjectValue(stateId, 0, foundResult);
wg.commit();
} catch (final InterruptedException ex) {
Exceptions.printStackTrace(ex);
Thread.currentThread().interrupt();
}
}
use of au.gov.asd.tac.constellation.graph.Attribute in project constellation by constellation-app.
the class FindViewControllerNGTest method testUpdateBasicReplaceParameters.
/**
* Test of updateBasicReplaceParameters method, of class FindViewController.
*/
@Test
public void testUpdateBasicReplaceParameters() {
System.out.println("updateBasicReplaceParameters");
FindViewController instance = FindViewController.getDefault();
List<Attribute> attributeList = new ArrayList<>();
instance.updateBasicReplaceParameters(parameters);
BasicFindReplaceParameters result = instance.getCurrentBasicReplaceParameters();
// The object is copied in the updateBasicFindParameters function
// This will cause a direct comparison of the object to be false
assertEquals(result, parameters);
assertNotEquals(result, parameters2);
}
use of au.gov.asd.tac.constellation.graph.Attribute in project constellation by constellation-app.
the class GraphJsonWriter method writeElements.
/**
* Write elements of a Graph to JSON.
*
* @param jg The JsonGenerator to use for writing.
* @param graph The graph.
* @param elementType The GraphElementType being written.
* @param writeData If false, write out the attributes but not the data for
* the given element type.
*
* @throws IOException
*/
private void writeElements(final JsonGenerator jg, final GraphReadMethods graph, final GraphElementType elementType, final boolean verbose, final boolean writeData) throws Exception {
final String elementTypeLabel = IoUtilities.getGraphElementTypeString(elementType);
if (progress != null) {
progress.progress("Writing " + elementTypeLabel + " elements...");
}
final AbstractGraphIOProvider[] ioProviders = new AbstractGraphIOProvider[graph.getAttributeCapacity()];
final ArrayList<Attribute> attrs = new ArrayList<>();
for (int position = 0; position < graph.getAttributeCount(elementType); position++) {
final int attrId = graph.getAttribute(elementType, position);
final Attribute attr = new GraphAttribute(graph, attrId);
ioProviders[attrId] = graphIoProviders.get(attr.getAttributeType());
// Don't write non-META object types; we don't know what they are.
if (!"object".equals(attr.getAttributeType()) || elementType == GraphElementType.META) {
attrs.add(attr);
}
}
// Here we go.
jg.writeStartObject();
jg.writeArrayFieldStart(elementTypeLabel);
jg.writeStartObject();
jg.writeArrayFieldStart("attrs");
// Write the attributes.
for (final Attribute attr : attrs) {
jg.writeStartObject();
jg.writeStringField("label", attr.getName());
jg.writeStringField("type", attr.getAttributeType());
if (attr.getDescription() != null) {
jg.writeStringField("descr", attr.getDescription());
}
// actual attribute values inside the attribute descriptions.
if (attr.getDefaultValue() != null && isNumeric(attr)) {
jg.writeNumberField(DEFAULT_FIELD, ((Number) attr.getDefaultValue()).doubleValue());
} else if (attr.getDefaultValue() != null && "boolean".equals(attr.getAttributeType())) {
jg.writeBooleanField(DEFAULT_FIELD, (Boolean) attr.getDefaultValue());
} else if (attr.getDefaultValue() != null) {
jg.writeStringField(DEFAULT_FIELD, attr.getDefaultValue().toString());
} else {
// Do nothing
}
if (attr.getAttributeMerger() != null) {
jg.writeStringField("merger", attr.getAttributeMerger().getId());
}
jg.writeNumberField("mod_count", graph.getValueModificationCounter(attr.getId()));
jg.writeEndObject();
}
jg.writeEndArray();
// Check for optional key.
if (elementType == GraphElementType.VERTEX || elementType == GraphElementType.TRANSACTION) {
final int[] key = graph.getPrimaryKey(elementType);
if (key.length > 0) {
// Write the labels of the key attributes.
jg.writeArrayFieldStart("key");
for (int i = 0; i < key.length; i++) {
final Attribute attr = new GraphAttribute(graph, key[i]);
jg.writeString(attr.getName());
}
jg.writeEndArray();
}
}
jg.writeEndObject();
// Write the main graph data (graph, vertex, transaction).
jg.writeStartObject();
jg.writeArrayFieldStart("data");
if (!writeData) {
// Do nothing
} else if (elementType == GraphElementType.GRAPH || elementType == GraphElementType.META) {
jg.writeStartObject();
for (final Attribute attr : attrs) {
final AbstractGraphIOProvider ioProvider = ioProviders[attr.getId()];
if (ioProvider != null) {
// Get the provider to write its data into an ObjectNode.
// If they didn't write anything, don't write the data to the JSON.
ioProvider.writeObject(attr, 0, jg, graph, byteWriter, verbose);
} else {
final Object value = graph.getObjectValue(attr.getId(), 0);
final String className = value != null ? value.getClass().getName() : "<null>";
final String msg = String.format("No I/O provider found for object type %s, attribute %s", className, attr);
throw new Exception(msg);
}
}
jg.writeEndObject();
} else if (elementType == GraphElementType.VERTEX) {
for (int position = 0; position < graph.getVertexCount(); position++) {
final int vxId = graph.getVertex(position);
jg.writeStartObject();
jg.writeNumberField(GraphFileConstants.VX_ID, vxId);
for (final Attribute attr : attrs) {
final AbstractGraphIOProvider ioProvider = ioProviders[attr.getId()];
if (ioProvider != null) {
// Get the provider to write its data into an ObjectNode.
// If they didn't write anything, don't write the data to the JSON.
ioProvider.writeObject(attr, vxId, jg, graph, byteWriter, verbose);
} else {
throw new Exception("No IO provider found for attribute type: " + attr.getAttributeType());
}
}
jg.writeEndObject();
counter++;
if (counter % REPORT_INTERVAL == 0 && isCancelled) {
return;
} else if (counter % REPORT_INTERVAL == 0 && progress != null) {
progress.progress(counter);
} else {
// Do nothing
}
}
} else if (elementType == GraphElementType.TRANSACTION) {
for (int position = 0; position < graph.getTransactionCount(); position++) {
final int txId = graph.getTransaction(position);
jg.writeStartObject();
jg.writeNumberField(GraphFileConstants.TX_ID, txId);
jg.writeNumberField(GraphFileConstants.SRC, graph.getTransactionSourceVertex(txId));
jg.writeNumberField(GraphFileConstants.DST, graph.getTransactionDestinationVertex(txId));
jg.writeBooleanField(GraphFileConstants.DIR, graph.getTransactionDirection(txId) != Graph.UNDIRECTED);
for (final Attribute attr : attrs) {
final AbstractGraphIOProvider ioProvider = ioProviders[attr.getId()];
if (ioProvider != null) {
// Get the provider to write its data into an ObjectNode.
// If they didn't write anything, don't write the data to the JSON.
ioProvider.writeObject(attr, txId, jg, graph, byteWriter, verbose);
} else {
throw new Exception("No IO provider found for attribute type: " + attr.getAttributeType());
}
}
jg.writeEndObject();
counter++;
if (counter % REPORT_INTERVAL == 0 && isCancelled) {
return;
} else if (counter % REPORT_INTERVAL == 0 && progress != null) {
progress.progress(counter);
}
}
} else {
// Do nothing
}
jg.writeEndArray();
jg.writeEndObject();
jg.writeEndArray();
jg.writeEndObject();
}
Aggregations