use of org.codice.alliance.nsili.common.UCO.Edge in project alliance by codice.
the class ResultDAGConverter method getNodeEdgeDirectedAcyclicGraph.
private static DirectedAcyclicGraph<Node, Edge> getNodeEdgeDirectedAcyclicGraph(DAG dag, Map<Integer, Node> nodeMap) {
DirectedAcyclicGraph<Node, Edge> graph = new DirectedAcyclicGraph<>(Edge.class);
for (Node node : dag.nodes) {
graph.addVertex(node);
}
for (Edge edge : dag.edges) {
Node node1 = nodeMap.get(edge.start_node);
Node node2 = nodeMap.get(edge.end_node);
if (node1 != null && node2 != null) {
graph.addEdge(node1, node2);
}
}
return graph;
}
use of org.codice.alliance.nsili.common.UCO.Edge in project alliance by codice.
the class ResultDAGConverter method convertResult.
public static DAG convertResult(Result result, ORB orb, POA poa, List<String> resultAttributes, Map<String, List<String>> mandatoryAttributes) throws DagParsingException {
Metacard metacard = result.getMetacard();
DAG dag = new DAG();
DirectedAcyclicGraph<Node, Edge> graph = new DirectedAcyclicGraph<>(Edge.class);
ProductImpl productImpl = new ProductImpl();
String id = result.getMetacard().getId();
if (!CorbaUtils.isIdActive(poa, id.getBytes(Charset.forName(ENCODING)))) {
try {
poa.activate_object_with_id(id.getBytes(Charset.forName(ENCODING)), productImpl);
} catch (ServantAlreadyActive | ObjectAlreadyActive | WrongPolicy e) {
LOGGER.debug("Convert DAG : Unable to activate product impl object ({}): {}", result.getMetacard().getId(), e.getLocalizedMessage());
}
}
org.omg.CORBA.Object obj = poa.create_reference_with_id(id.getBytes(Charset.forName(ENCODING)), ProductHelper.id());
Product product = ProductHelper.narrow(obj);
Node productNode = createRootNode(orb);
String attributeName = NsiliConstants.NSIL_PRODUCT;
Any productAny = orb.create_any();
ProductHelper.insert(productAny, product);
productNode.value = productAny;
graph.addVertex(productNode);
List<String> addedAttributes = new ArrayList<>();
addedAttributes.addAll(addCardNodeWithAttributes(graph, productNode, metacard, orb, attributeName + ":", resultAttributes));
addedAttributes.addAll(addFileNodeWithAttributes(graph, productNode, metacard, orb, attributeName + ":", resultAttributes));
addedAttributes.addAll(addSecurityNodeWithAttributes(graph, productNode, metacard, orb, attributeName + ":", resultAttributes));
addedAttributes.addAll(addMetadataSecurityNodeWithAttributes(graph, productNode, metacard, orb, attributeName + ":", resultAttributes));
addedAttributes.addAll(addParts(graph, productNode, metacard, orb, attributeName + ":", resultAttributes));
if (metacard.getThumbnail() != null && metacard.getThumbnail().length > 0) {
addedAttributes.addAll(addThumbnailRelatedFile(graph, productNode, metacard, orb, attributeName + ":", resultAttributes));
}
if (mandatoryAttributes != null && !mandatoryAttributes.isEmpty()) {
final ThreadLocal<Boolean> dataIsValid = new ThreadLocal<>();
dataIsValid.set(true);
Map<String, List<String>> addedAttrMap = getAttrMap(addedAttributes);
addedAttrMap.entrySet().forEach(entry -> dataIsValid.set(dataIsValid.get() && processEntry(entry.getKey(), mandatoryAttributes.get(entry.getKey()), entry.getValue())));
if (!dataIsValid.get()) {
throw new DagParsingException("One or more mandatory attributes is missing on outgoing data");
}
}
graph.addVertex(productNode);
NsiliCommonUtils.setUCOEdgeIds(graph);
NsiliCommonUtils.setUCOEdges(productNode, graph);
dag.edges = NsiliCommonUtils.getEdgeArrayFromGraph(graph);
dag.nodes = NsiliCommonUtils.getNodeArrayFromGraph(graph);
return dag;
}
use of org.codice.alliance.nsili.common.UCO.Edge in project alliance by codice.
the class NsiliCommonUtils method setUCOEdgeIds.
/**
* Set the UCO.Node IDs in DFS order to conform to the NSILI spec. The root of the node will be 0.
*
* @param graph - the graph representation of the DAG
*/
public static void setUCOEdgeIds(Graph<Node, Edge> graph) {
if (graph != null) {
int id = 0;
DepthFirstIterator<Node, Edge> depthFirstIterator = new DepthFirstIterator<>(graph);
while (depthFirstIterator.hasNext()) {
Node node = depthFirstIterator.next();
node.id = id;
id++;
}
}
}
use of org.codice.alliance.nsili.common.UCO.Edge in project alliance by codice.
the class DAGGenerator method generateNSILDAG.
private static DAG generateNSILDAG(ORB orb, String partType, String commonType, String title) {
DAG metacard = new DAG();
Graph<Node, Edge> graph = new DirectedAcyclicGraph<>(Edge.class);
Node[] nodeRefs = constructNSILProduct(orb, graph, 1, commonType);
constructNSILPart(nodeRefs[0], nodeRefs[1], nodeRefs[3], orb, graph, partType, title);
constructNSILPart(nodeRefs[0], nodeRefs[1], nodeRefs[3], orb, graph, NsiliConstants.NSIL_COVERAGE, title);
constructNSILPart(nodeRefs[0], nodeRefs[1], nodeRefs[3], orb, graph, NsiliConstants.NSIL_EXPLOITATION_INFO, title);
constructNSILAssociation(nodeRefs[0], nodeRefs[2], orb, graph, 1);
NsiliCommonUtils.setUCOEdgeIds(graph);
NsiliCommonUtils.setUCOEdges(nodeRefs[0], graph);
metacard.nodes = NsiliCommonUtils.getNodeArrayFromGraph(graph);
metacard.edges = NsiliCommonUtils.getEdgeArrayFromGraph(graph);
return metacard;
}
use of org.codice.alliance.nsili.common.UCO.Edge in project alliance by codice.
the class DAGConverter method parseGraph.
private MetacardImpl parseGraph(DirectedAcyclicGraph<Node, Edge> graph, boolean swapCoordinates) {
MetacardImpl metacard = new MetacardImpl(nsiliMetacardType);
List<Serializable> associatedCards = new ArrayList<>();
// Traverse the graph
DepthFirstIterator<Node, Edge> depthFirstIterator = new DepthFirstIterator<>(graph);
Node parentEntity = null;
Node assocNode = null;
while (depthFirstIterator.hasNext()) {
Node node = depthFirstIterator.next();
if (node.node_type == NodeType.ROOT_NODE && node.attribute_name.equals(NsiliConstants.NSIL_PRODUCT)) {
// Nothing to process from root node
} else if (node.node_type == NodeType.ENTITY_NODE) {
parentEntity = node;
assocNode = getAssocNode(graph, assocNode, node);
} else if (node.node_type == NodeType.RECORD_NODE) {
// Nothing to process from record node
} else if (parentEntity != null && node.node_type == NodeType.ATTRIBUTE_NODE && node.value != null) {
addNsiliAttribute(swapCoordinates, metacard, associatedCards, parentEntity, assocNode, node);
}
}
// Add associated data
if (!associatedCards.isEmpty()) {
boolean firstAssoc = true;
AttributeImpl attribute = null;
for (Serializable association : associatedCards) {
if (firstAssoc) {
attribute = new AttributeImpl(Associations.RELATED, association);
metacard.setAttribute(attribute);
firstAssoc = false;
} else {
attribute.addValue(association);
}
}
}
return metacard;
}
Aggregations