use of au.gov.asd.tac.constellation.graph.utilities.CompositeTransactionId in project constellation by constellation-app.
the class GraphRecordStoreUtilities method copyTransactionsToComposite.
/**
* Takes transactions connected to the constituent of an expanded composite
* and adds to a {@link RecordStore} copies of the corresponding
* transactions connected instead to the composite itself. This is used when
* a composite node is contracted.
*
* @param graph A {@link GraphReadMethods} from which the
* {@link RecordStore} will be created.
* @param recordStore The {@link RecordStore} to add the transactions to.
* @param expandedVxId The vertex id of the composite constituent to copy
* transactions from.
* @param expandedId The id of the composite constituent to be used in the
* {@link RecordStore}.
* @param expandedIds The set of expandedIds.
* @param toId The id of the composite node to be used in the
* {@link RecordStore}.
* @param uniqueIdAttr The id of uniqueId attribute for transactions. This
* is required as the uniqueId attribute is used to hold information about
* the original source and destination vertices of transactions connected to
* composite nodes.
*/
public static void copyTransactionsToComposite(final GraphReadMethods graph, final RecordStore recordStore, final int expandedVxId, final String expandedId, final Set<Integer> expandedIds, final String toId, final Attribute uniqueIdAttr) {
final int transactionAttributeCount = graph.getAttributeCount(GraphElementType.TRANSACTION);
final Attribute[] transactionAttributes = new Attribute[transactionAttributeCount];
for (int a = 0; a < transactionAttributeCount; a++) {
final int attributeId = graph.getAttribute(GraphElementType.TRANSACTION, a);
transactionAttributes[a] = new GraphAttribute(graph, attributeId);
}
final int transactionCount = graph.getVertexTransactionCount(expandedVxId);
for (int t = 0; t < transactionCount; t++) {
final int transaction = graph.getVertexTransaction(expandedVxId, t);
final int source = graph.getTransactionSourceVertex(transaction);
final int destination = graph.getTransactionDestinationVertex(transaction);
// Don't add to a composite those transactions which are between two constituents of the composite!
if (expandedIds.contains(source) && expandedIds.contains(destination)) {
continue;
}
final CompositeTransactionId compositeTransactionId = CompositeTransactionId.fromString(graph.getStringValue(uniqueIdAttr.getId(), transaction));
String sourceId = null;
String destId = null;
String uniqueId;
if (expandedVxId == source) {
destId = String.valueOf(destination);
if (!compositeTransactionId.isSourceContracted() && compositeTransactionId.getOriginalSourceNode() != null) {
sourceId = compositeTransactionId.getOriginalSourceNode();
compositeTransactionId.setOriginalSourceNode(null);
uniqueId = compositeTransactionId.toString();
} else {
sourceId = toId;
compositeTransactionId.setSourceContracted(true);
compositeTransactionId.setOriginalSourceNode(expandedId);
uniqueId = compositeTransactionId.toString();
}
} else {
sourceId = String.valueOf(source);
if (!compositeTransactionId.isDestContracted() && compositeTransactionId.getOriginalDestinationNode() != null) {
destId = compositeTransactionId.getOriginalDestinationNode();
compositeTransactionId.setOriginalDestinationNode(null);
uniqueId = compositeTransactionId.toString();
} else {
destId = toId;
compositeTransactionId.setDestContracted(true);
compositeTransactionId.setOriginalDestinationNode(expandedId);
uniqueId = compositeTransactionId.toString();
}
}
recordStore.add();
for (Attribute transactionAttribute : transactionAttributes) {
final String value = transactionAttribute.getName().equals(uniqueIdAttr.getName()) ? uniqueId : graph.getStringValue(transactionAttribute.getId(), transaction);
recordStore.set(TRANSACTION + transactionAttribute.getName() + "<" + transactionAttribute.getAttributeType() + ">", value);
}
if (graph.getTransactionDirection(transaction) == Graph.UNDIRECTED) {
recordStore.set(TRANSACTION + DIRECTED_KEY, FALSE);
}
recordStore.set(TRANSACTION + ID, COPY + String.format(NUMBER_STRING_STRING_FORMAT, transaction, sourceId, destId));
recordStore.set(SOURCE + ID, sourceId);
recordStore.set(DESTINATION + ID, destId);
}
}
use of au.gov.asd.tac.constellation.graph.utilities.CompositeTransactionId in project constellation by constellation-app.
the class CompositeUtilities method simplifyCompositeTransactions.
private static void simplifyCompositeTransactions(final GraphWriteMethods graph, final int uniqueIdAttr, final int vxId) {
for (int t = 0; t < graph.getVertexTransactionCount(vxId); t++) {
final int txId = graph.getVertexTransaction(vxId, t);
final int source = graph.getTransactionSourceVertex(txId);
final int dest = graph.getTransactionDestinationVertex(txId);
final CompositeTransactionId uniqueId = CompositeTransactionId.fromString(graph.getStringValue(uniqueIdAttr, txId));
if (source == vxId && uniqueId.getOriginalSourceNode() != null) {
uniqueId.setOriginalSourceNode(null);
}
if (dest == vxId && uniqueId.getOriginalDestinationNode() != null) {
uniqueId.setOriginalDestinationNode(null);
}
graph.setStringValue(uniqueIdAttr, txId, uniqueId.toString());
}
}
use of au.gov.asd.tac.constellation.graph.utilities.CompositeTransactionId in project constellation by constellation-app.
the class GraphRecordStoreUtilities method copyTransactionsFromComposite.
/**
* Takes transactions connected to a composite and adds to a
* {@link RecordStore} copies of the corresponding transactions connected
* instead to the composite's constituents. This is used when a composite
* node is expanded.
*
* @param graph A {@link GraphReadMethods} from which the
* {@link RecordStore} will be created.
* @param recordStore The {@link RecordStore} to add the transactions to.
* @param compositeVxId The vertex id of the composite node to copy
* transactions from.
* @param compositeStoredId The id of the composite node to be used in the
* {@link RecordStore}.
* @param toIds A list of the ids of the composite constituents to be used
* in the {@link RecordStore}.
* @param uniqueIdAttr The id of uniqueId attribute for transactions. This
* is required as the uniqueId attribute is used to hold information about
* the original source and destination vertices of transactions connected to
* composite nodes.
*/
public static void copyTransactionsFromComposite(final GraphReadMethods graph, final RecordStore recordStore, final int compositeVxId, final String compositeStoredId, final List<String> toIds, final Attribute uniqueIdAttr) {
final int transactionAttributeCount = graph.getAttributeCount(GraphElementType.TRANSACTION);
final Attribute[] transactionAttributes = new Attribute[transactionAttributeCount];
for (int a = 0; a < transactionAttributeCount; a++) {
final int attributeId = graph.getAttribute(GraphElementType.TRANSACTION, a);
transactionAttributes[a] = new GraphAttribute(graph, attributeId);
}
final int transactionCount = graph.getVertexTransactionCount(compositeVxId);
for (int t = 0; t < transactionCount; t++) {
final int transaction = graph.getVertexTransaction(compositeVxId, t);
final int source = graph.getTransactionSourceVertex(transaction);
final int destination = graph.getTransactionDestinationVertex(transaction);
final CompositeTransactionId compositeTransactionId = CompositeTransactionId.fromString(graph.getStringValue(uniqueIdAttr.getId(), transaction));
String sourceId = null;
String destId = null;
String uniqueId;
if (compositeVxId == source) {
destId = String.valueOf(destination);
if (compositeTransactionId.isSourceContracted() && compositeTransactionId.getOriginalSourceNode() != null) {
sourceId = compositeTransactionId.getOriginalSourceNode();
compositeTransactionId.setOriginalSourceNode(null);
uniqueId = compositeTransactionId.toString();
} else {
compositeTransactionId.setSourceContracted(false);
compositeTransactionId.setOriginalSourceNode(compositeStoredId);
uniqueId = compositeTransactionId.toString();
}
} else {
sourceId = String.valueOf(source);
if (compositeTransactionId.isDestContracted() && compositeTransactionId.getOriginalDestinationNode() != null) {
destId = compositeTransactionId.getOriginalDestinationNode();
compositeTransactionId.setOriginalDestinationNode(null);
uniqueId = compositeTransactionId.toString();
} else {
compositeTransactionId.setDestContracted(false);
compositeTransactionId.setOriginalDestinationNode(compositeStoredId);
uniqueId = compositeTransactionId.toString();
}
}
final List<String> sourceIds = sourceId == null ? toIds : Arrays.asList(sourceId);
final List<String> destIds = destId == null ? toIds : Arrays.asList(destId);
for (String srcId : sourceIds) {
for (String dstId : destIds) {
recordStore.add();
for (Attribute transactionAttribute : transactionAttributes) {
final String value = transactionAttribute.getName().equals(uniqueIdAttr.getName()) ? uniqueId : graph.getStringValue(transactionAttribute.getId(), transaction);
recordStore.set(TRANSACTION + transactionAttribute.getName() + "<" + transactionAttribute.getAttributeType() + ">", value);
}
if (graph.getTransactionDirection(transaction) == Graph.UNDIRECTED) {
recordStore.set(TRANSACTION + DIRECTED_KEY, FALSE);
}
recordStore.set(TRANSACTION + ID, COPY + String.format(NUMBER_STRING_STRING_FORMAT, transaction, srcId, dstId));
recordStore.set(SOURCE + ID, srcId);
recordStore.set(DESTINATION + ID, dstId);
}
}
}
}
Aggregations