use of au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute in project constellation by constellation-app.
the class LayersViewStateIoProvider method readObject.
@Override
public void readObject(final int attributeId, final int elementId, final JsonNode jnode, final GraphWriteMethods graph, final Map<Integer, Integer> vertexMap, final Map<Integer, Integer> transactionMap, final GraphByteReader byteReader, final ImmutableObjectCache cache) throws IOException {
if (!jnode.isNull()) {
final List<BitMaskQuery> vxlayerDescriptions = new ArrayList<>();
final ArrayNode vertexLayersArray = (ArrayNode) jnode.withArray("vertexLayers");
for (int i = 0; i < vertexLayersArray.size(); i++) {
if (vertexLayersArray.get(i).isNull()) {
vxlayerDescriptions.add(null);
} else {
final BitMaskQuery query = new BitMaskQuery(new Query(GraphElementType.VERTEX, StringUtils.equals("null", vertexLayersArray.get(i).get(2).asText()) ? "" : vertexLayersArray.get(i).get(2).asText()), vertexLayersArray.get(i).get(0).asInt(), vertexLayersArray.get(i).get(3).asText());
query.setVisibility(vertexLayersArray.get(i).get(1).asBoolean());
vxlayerDescriptions.add(query);
}
}
final List<BitMaskQuery> txlayerDescriptions = new ArrayList<>();
final ArrayNode transactionLayersArray = (ArrayNode) jnode.withArray("transactionLayers");
for (int i = 0; i < transactionLayersArray.size(); i++) {
if (transactionLayersArray.get(i).isNull()) {
txlayerDescriptions.add(null);
} else {
final BitMaskQuery query = new BitMaskQuery(new Query(GraphElementType.TRANSACTION, StringUtils.equals("null", transactionLayersArray.get(i).get(2).asText()) ? "" : transactionLayersArray.get(i).get(2).asText()), transactionLayersArray.get(i).get(0).asInt(), transactionLayersArray.get(i).get(3).asText());
query.setVisibility(transactionLayersArray.get(i).get(1).asBoolean());
txlayerDescriptions.add(query);
}
}
final List<SchemaAttribute> layerAttributes = new ArrayList<>();
final ArrayNode layerAttributesArray = (ArrayNode) jnode.withArray("layerAttributes");
for (int i = 0; i < layerAttributesArray.size(); i++) {
if (layerAttributesArray.get(i).isNull()) {
layerAttributes.add(null);
} else {
layerAttributes.add(SchemaAttributeUtilities.getAttribute(GraphElementType.getValue(layerAttributesArray.get(i).get(0).asText()), layerAttributesArray.get(i).get(1).asText()));
}
}
BitMaskQueryCollection vxQueries = new BitMaskQueryCollection(GraphElementType.VERTEX);
vxQueries.setQueries(vxlayerDescriptions.toArray(new BitMaskQuery[64]));
BitMaskQueryCollection txQueries = new BitMaskQueryCollection(GraphElementType.TRANSACTION);
txQueries.setQueries(txlayerDescriptions.toArray(new BitMaskQuery[64]));
final LayersViewState state = new LayersViewState(layerAttributes, vxQueries, txQueries);
graph.setObjectValue(attributeId, elementId, state);
}
}
use of au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute in project constellation by constellation-app.
the class LayersViewStateIoProvider method writeObject.
@Override
public void writeObject(final Attribute attribute, final int elementId, final JsonGenerator jsonGenerator, final GraphReadMethods graph, final GraphByteWriter byteWriter, final boolean verbose) throws IOException {
if (verbose || !graph.isDefaultValue(attribute.getId(), elementId)) {
final LayersViewState originalState = graph.getObjectValue(attribute.getId(), elementId);
if (originalState == null) {
jsonGenerator.writeNullField(attribute.getName());
} else {
// make a copy in case the state on the graph is currently being modified.
final LayersViewState state = new LayersViewState(originalState);
jsonGenerator.writeObjectFieldStart(attribute.getName());
jsonGenerator.writeArrayFieldStart("vertexLayers");
for (final BitMaskQuery layer : state.getVxQueriesCollection().getQueries()) {
if (layer == null) {
jsonGenerator.writeNull();
} else {
jsonGenerator.writeStartArray("index", layer.getIndex());
jsonGenerator.writeNumber(layer.getIndex());
jsonGenerator.writeBoolean(layer.isVisible());
jsonGenerator.writeString(layer.getQueryString());
jsonGenerator.writeString(layer.getDescription());
jsonGenerator.writeEndArray();
}
}
jsonGenerator.writeEndArray();
jsonGenerator.writeArrayFieldStart("transactionLayers");
for (final BitMaskQuery layer : state.getTxQueriesCollection().getQueries()) {
if (layer == null) {
jsonGenerator.writeNull();
} else {
jsonGenerator.writeStartArray("index", layer.getIndex());
jsonGenerator.writeNumber(layer.getIndex());
jsonGenerator.writeBoolean(layer.isVisible());
jsonGenerator.writeString(layer.getQueryString());
jsonGenerator.writeString(layer.getDescription());
jsonGenerator.writeEndArray();
}
}
jsonGenerator.writeEndArray();
jsonGenerator.writeArrayFieldStart("layerAttributes");
int count = 0;
for (final SchemaAttribute attr : state.getLayerAttributes()) {
if (attr == null) {
jsonGenerator.writeNull();
} else {
jsonGenerator.writeStartArray("index", count++);
jsonGenerator.writeString(attr.getElementType().toString());
jsonGenerator.writeString(attr.getName());
jsonGenerator.writeEndArray();
}
}
jsonGenerator.writeEndArray();
jsonGenerator.writeEndObject();
}
}
}
use of au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute in project constellation by constellation-app.
the class AttributeNodeProvider method getSchemaInfo.
private List<AttributeEntry> getSchemaInfo(final Graph graph) {
final List<AttributeEntry> attrs = new ArrayList<>();
final Schema schema = graph.getSchema();
final SchemaFactory factory = schema.getFactory();
// Get the keys for each element type.
final Map<GraphElementType, List<String>> elementKeys = new HashMap<>();
for (final GraphElementType et : new GraphElementType[] { GraphElementType.VERTEX, GraphElementType.TRANSACTION }) {
final List<SchemaAttribute> keys = factory.getKeyAttributes(et);
final List<String> keyLabels = keys.stream().map(key -> key.getName()).collect(Collectors.toList());
elementKeys.put(et, keyLabels);
}
for (final GraphElementType et : GraphElementType.values()) {
final Map<String, SchemaAttribute> attrsMap = factory.getRegisteredAttributes(et);
attrsMap.values().stream().forEach(schemaAttribute -> {
final int keyIx = elementKeys.containsKey(schemaAttribute.getElementType()) ? elementKeys.get(schemaAttribute.getElementType()).indexOf(schemaAttribute.getName()) : -1;
final Collection<SchemaConcept> concepts = SchemaConceptUtilities.getAttributeConcepts(schemaAttribute);
final StringBuilder categories = new StringBuilder();
for (SchemaConcept concept : concepts) {
categories.append(concept.getName()).append(",");
}
if (categories.length() > 0) {
categories.deleteCharAt(categories.length() - 1);
}
attrs.add(new AttributeEntry(schemaAttribute, categories.toString(), keyIx));
});
}
return attrs;
}
use of au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute in project constellation by constellation-app.
the class LevenshteinDistancePlugin method updateParameters.
@Override
public void updateParameters(final Graph graph, final PluginParameters parameters) {
final List<String> stringAttributes = new ArrayList<>();
if (graph.getSchema() != null) {
final Map<String, SchemaAttribute> attributes = graph.getSchema().getFactory().getRegisteredAttributes(GraphElementType.VERTEX);
for (final String attr : attributes.keySet()) {
final SchemaAttribute attribute = attributes.get(attr);
final String attributeType = attribute.getAttributeType();
if (attributeType.equals(StringAttributeDescription.ATTRIBUTE_NAME)) {
stringAttributes.add(attr);
}
}
}
stringAttributes.sort(String::compareTo);
if (parameters != null && parameters.getParameters() != null) {
// ATTRIBUTE_PARAMETER_ID is created as a SingleChoiceParmeter in this class on line 71.
@SuppressWarnings("unchecked") final PluginParameter<SingleChoiceParameterValue> compareAttribute = (PluginParameter<SingleChoiceParameterValue>) parameters.getParameters().get(ATTRIBUTE_PARAMETER_ID);
SingleChoiceParameterType.setOptions(compareAttribute, stringAttributes);
if (stringAttributes.contains(VisualConcept.VertexAttribute.IDENTIFIER.getName())) {
SingleChoiceParameterType.setChoice(compareAttribute, VisualConcept.VertexAttribute.IDENTIFIER.getName());
}
}
}
use of au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute in project constellation by constellation-app.
the class AnalyticSchemaV2UpdateProvider method schemaUpdate.
@Override
protected void schemaUpdate(final StoreGraph graph) {
boolean updateVertexKeys = false;
// update vertex raw attribute
final int oldVertexRawAttributeId = AnalyticConcept.VertexAttribute.RAW.get(graph);
final Attribute oldVertexRawAttribute = new GraphAttribute(graph, oldVertexRawAttributeId);
if (!oldVertexRawAttribute.getAttributeType().equals(RawAttributeDescription.ATTRIBUTE_NAME)) {
graph.setPrimaryKey(GraphElementType.VERTEX);
final int newVertexRawAttribute = AnalyticConcept.VertexAttribute.RAW.ensure(graph);
final int vertexIdentifierAttribute = VisualConcept.VertexAttribute.IDENTIFIER.ensure(graph);
for (int vertexPosition = 0; vertexPosition < graph.getVertexCount(); vertexPosition++) {
final int vertexId = graph.getVertex(vertexPosition);
final String rawValue = graph.getStringValue(oldVertexRawAttributeId, vertexId);
graph.setObjectValue(newVertexRawAttribute, vertexId, new RawData(rawValue, null));
if (graph.getStringValue(vertexIdentifierAttribute, vertexId) == null) {
graph.setObjectValue(vertexIdentifierAttribute, vertexId, rawValue);
}
}
graph.removeAttribute(oldVertexRawAttributeId);
updateVertexKeys = true;
}
// update vertex type attribute
if (AnalyticConcept.VertexAttribute.TYPE.get(graph) == Graph.NOT_FOUND) {
updateVertexKeys = true;
}
final int oldVertexTypeAttributeId = graph.getAttribute(GraphElementType.VERTEX, "Type");
final Attribute oldVertexTypeAttribute = new GraphAttribute(graph, oldVertexTypeAttributeId);
if (!oldVertexTypeAttribute.getAttributeType().equals(VertexTypeAttributeDescription.ATTRIBUTE_NAME)) {
graph.setPrimaryKey(GraphElementType.VERTEX);
final int newVertexTypeAttributeId = AnalyticConcept.VertexAttribute.TYPE.ensure(graph);
final int vertexRawAttributeId = AnalyticConcept.VertexAttribute.RAW.ensure(graph);
for (int vertexPosition = 0; vertexPosition < graph.getVertexCount(); vertexPosition++) {
final int vertexId = graph.getVertex(vertexPosition);
final String typeValue = graph.getStringValue(oldVertexTypeAttributeId, vertexId);
final SchemaVertexType type = SchemaVertexTypeUtilities.getType(typeValue);
graph.setObjectValue(newVertexTypeAttributeId, graph.getVertex(vertexPosition), type);
final RawData rawValue = graph.getObjectValue(vertexRawAttributeId, graph.getVertex(vertexPosition));
graph.setObjectValue(vertexRawAttributeId, vertexId, rawValue != null ? new RawData(rawValue.getRawIdentifier(), typeValue) : new RawData(null, null));
}
graph.removeAttribute(oldVertexTypeAttributeId);
updateVertexKeys = true;
}
// update vertex keys and complete vertices
if (updateVertexKeys && graph.getSchema() != null) {
final List<SchemaAttribute> keyAttributes = graph.getSchema().getFactory().getKeyAttributes(GraphElementType.VERTEX);
final int[] keyAttributeIds = keyAttributes.stream().map(keyAttribute -> keyAttribute.ensure(graph)).mapToInt(keyAttributeId -> keyAttributeId).toArray();
graph.setPrimaryKey(GraphElementType.VERTEX, keyAttributeIds);
}
boolean updateTransactionKeys = false;
// update transaction type attribute
if (AnalyticConcept.TransactionAttribute.TYPE.get(graph) == Graph.NOT_FOUND) {
updateTransactionKeys = true;
}
final int oldTransactionTypeAttributeId = graph.getAttribute(GraphElementType.TRANSACTION, "Type");
final Attribute oldTransactionTypeAttribute = new GraphAttribute(graph, oldTransactionTypeAttributeId);
if (!oldTransactionTypeAttribute.getAttributeType().equals(TransactionTypeAttributeDescription.ATTRIBUTE_NAME)) {
graph.setPrimaryKey(GraphElementType.TRANSACTION);
final int newTransactionTypeAttributeId = AnalyticConcept.TransactionAttribute.TYPE.ensure(graph);
for (int transactionPosition = 0; transactionPosition < graph.getTransactionCount(); transactionPosition++) {
final int transactionId = graph.getTransaction(transactionPosition);
final String typeValue = graph.getStringValue(oldTransactionTypeAttributeId, transactionId);
final SchemaTransactionType type = SchemaTransactionTypeUtilities.getType(typeValue);
graph.setObjectValue(newTransactionTypeAttributeId, transactionId, type);
}
graph.removeAttribute(oldTransactionTypeAttributeId);
updateTransactionKeys = true;
}
// update transaction datetime attribute
if (TemporalConcept.TransactionAttribute.DATETIME.get(graph) == Graph.NOT_FOUND) {
updateTransactionKeys = true;
}
// update transaction keys and complete transactions
if (updateTransactionKeys && graph.getSchema() != null) {
final List<SchemaAttribute> keyAttributes = graph.getSchema().getFactory().getKeyAttributes(GraphElementType.TRANSACTION);
final int[] keyAttributeIds = keyAttributes.stream().map(keyAttribute -> keyAttribute.ensure(graph)).mapToInt(keyAttributeId -> keyAttributeId).toArray();
graph.setPrimaryKey(GraphElementType.TRANSACTION, keyAttributeIds);
}
}
Aggregations