Search in sources :

Example 11 with Node

use of org.codice.alliance.nsili.common.UCO.Node 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;
}
Also used : Node(org.codice.alliance.nsili.common.UCO.Node) ArrayList(java.util.ArrayList) Product(org.codice.alliance.nsili.common.UID.Product) Any(org.omg.CORBA.Any) DirectedAcyclicGraph(org.jgrapht.experimental.dag.DirectedAcyclicGraph) WrongPolicy(org.omg.PortableServer.POAPackage.WrongPolicy) List(java.util.List) ArrayList(java.util.ArrayList) ServantAlreadyActive(org.omg.PortableServer.POAPackage.ServantAlreadyActive) ObjectAlreadyActive(org.omg.PortableServer.POAPackage.ObjectAlreadyActive) DAG(org.codice.alliance.nsili.common.UCO.DAG) Metacard(ddf.catalog.data.Metacard) Edge(org.codice.alliance.nsili.common.UCO.Edge)

Example 12 with Node

use of org.codice.alliance.nsili.common.UCO.Node in project alliance by codice.

the class ResultDAGConverter method addSecurityNodeWithAttributes.

public static List<String> addSecurityNodeWithAttributes(DirectedAcyclicGraph<Node, Edge> graph, Node productNode, Metacard metacard, ORB orb, String parentAttrName, List<String> resultAttributes) {
    List<String> addedAttributes = new ArrayList<>();
    Any any = orb.create_any();
    Node securityNode = new Node(0, NodeType.ENTITY_NODE, NsiliConstants.NSIL_SECURITY, any);
    graph.addVertex(securityNode);
    graph.addEdge(productNode, securityNode);
    String attribute = parentAttrName + NsiliConstants.NSIL_SECURITY;
    boolean classificationAdded = isClassificationAdded(graph, metacard, orb, resultAttributes, addedAttributes, securityNode, attribute);
    addPolicyAttributes(graph, metacard, orb, resultAttributes, addedAttributes, securityNode, attribute);
    addReleasabilityAttributes(graph, metacard, orb, resultAttributes, addedAttributes, securityNode, attribute);
    addClassificationAttributes(graph, orb, addedAttributes, securityNode, attribute, classificationAdded);
    return addedAttributes;
}
Also used : Node(org.codice.alliance.nsili.common.UCO.Node) ArrayList(java.util.ArrayList) Any(org.omg.CORBA.Any)

Example 13 with Node

use of org.codice.alliance.nsili.common.UCO.Node in project alliance by codice.

the class ResultDAGConverter method addThumbnailRelatedFile.

public static List<String> addThumbnailRelatedFile(DirectedAcyclicGraph<Node, Edge> graph, Node productNode, Metacard metacard, ORB orb, String parentAttrName, List<String> resultAttributes) {
    List<String> addedAttributes = new ArrayList<>();
    Any any = orb.create_any();
    Node relatedFileNode = new Node(0, NodeType.ENTITY_NODE, NsiliConstants.NSIL_RELATED_FILE, any);
    graph.addVertex(relatedFileNode);
    graph.addEdge(productNode, relatedFileNode);
    String attribute = parentAttrName + NsiliConstants.NSIL_RELATED_FILE;
    addCreatorAttribute(graph, metacard, orb, resultAttributes, addedAttributes, relatedFileNode, attribute);
    addTimeDeclaredAttribute(graph, metacard, orb, resultAttributes, addedAttributes, relatedFileNode, attribute);
    if (shouldAdd(buildAttr(attribute, NsiliConstants.EXTENT), resultAttributes) && metacard.getThumbnail() != null) {
        try {
            Double resSize = (double) metacard.getThumbnail().length;
            Double resSizeMB = convertToMegabytes(resSize);
            addDoubleAttribute(graph, relatedFileNode, NsiliConstants.EXTENT, resSizeMB, orb);
            addedAttributes.add(buildAttr(attribute, NsiliConstants.EXTENT));
        } catch (NumberFormatException nfe) {
            LOGGER.debug("Couldn't convert the thumbnail size to double: {}", metacard.getResourceSize());
        }
    }
    if (shouldAdd(buildAttr(attribute, NsiliConstants.URL), resultAttributes)) {
        try {
            String thumbnailURL = new URI(SystemBaseUrl.constructUrl(CATALOG_SOURCE_PATH + "/" + metacard.getSourceId() + "/" + metacard.getId() + "?transform=" + THUMBNAIL_TRANSFORMER, true)).toASCIIString();
            addStringAttribute(graph, relatedFileNode, NsiliConstants.URL, thumbnailURL, orb);
            addedAttributes.add(buildAttr(attribute, NsiliConstants.URL));
        } catch (URISyntaxException e) {
            LOGGER.debug("Unable to construct URI: ", e);
        }
    }
    if (shouldAdd(buildAttr(attribute, NsiliConstants.IS_FILE_LOCAL), resultAttributes)) {
        String siteName = SystemInfo.getSiteName();
        boolean fileLocal = true;
        if (siteName != null && metacard.getSourceId() != null && !siteName.equals(metacard.getSourceId())) {
            fileLocal = false;
        }
        addBooleanAttribute(graph, relatedFileNode, NsiliConstants.IS_FILE_LOCAL, fileLocal, orb);
        addedAttributes.add(buildAttr(attribute, NsiliConstants.IS_FILE_LOCAL));
    }
    if (shouldAdd(buildAttr(attribute, NsiliConstants.FILE_TYPE), resultAttributes)) {
        addStringAttribute(graph, relatedFileNode, NsiliConstants.FILE_TYPE, NsiliConstants.THUMBNAIL_TYPE, orb);
        addedAttributes.add(buildAttr(attribute, NsiliConstants.FILE_TYPE));
    }
    return addedAttributes;
}
Also used : Node(org.codice.alliance.nsili.common.UCO.Node) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) Any(org.omg.CORBA.Any) URI(java.net.URI)

Example 14 with Node

use of org.codice.alliance.nsili.common.UCO.Node in project alliance by codice.

the class ResultDAGConverter method addGmtiPart.

public static List<String> addGmtiPart(DirectedAcyclicGraph<Node, Edge> graph, Node partNode, Metacard metacard, ORB orb, String parentAttrName, List<String> resultAttributes) {
    List<String> addedAttributes = new ArrayList<>();
    Any gmtiAny = orb.create_any();
    Node gmtiNode = new Node(0, NodeType.ENTITY_NODE, NsiliConstants.NSIL_GMTI, gmtiAny);
    graph.addVertex(gmtiNode);
    graph.addEdge(partNode, gmtiNode);
    String attribute = parentAttrName + NsiliConstants.NSIL_GMTI;
    addIntAttribute(graph, metacard.getAttribute(Isr.MOVING_TARGET_INDICATOR_JOB_ID), orb, resultAttributes, addedAttributes, gmtiNode, attribute, NsiliConstants.IDENTIFIER_JOB);
    addIntAttribute(graph, metacard.getAttribute(Isr.TARGET_REPORT_COUNT), orb, resultAttributes, addedAttributes, gmtiNode, attribute, NsiliConstants.NUMBER_OF_TARGET_REPORTS);
    return addedAttributes;
}
Also used : Node(org.codice.alliance.nsili.common.UCO.Node) ArrayList(java.util.ArrayList) Any(org.omg.CORBA.Any)

Example 15 with Node

use of org.codice.alliance.nsili.common.UCO.Node in project alliance by codice.

the class ResultDAGConverter method addFileNodeWithAttributes.

public static List<String> addFileNodeWithAttributes(DirectedAcyclicGraph<Node, Edge> graph, Node productNode, Metacard metacard, ORB orb, String parentAttrName, List<String> resultAttributes) {
    List<String> addedAttributes = new ArrayList<>();
    Attribute downloadUrlAttr = metacard.getAttribute(Core.RESOURCE_DOWNLOAD_URL);
    if (downloadUrlAttr == null) {
        return addedAttributes;
    }
    Any any = orb.create_any();
    Node fileNode = new Node(0, NodeType.ENTITY_NODE, NsiliConstants.NSIL_FILE, any);
    graph.addVertex(fileNode);
    graph.addEdge(productNode, fileNode);
    String attribute = parentAttrName + NsiliConstants.NSIL_FILE;
    // Although not required, CSD Alpha requires this field to be populated on synchronization
    if (shouldAdd(buildAttr(attribute, NsiliConstants.ARCHIVED), resultAttributes)) {
        addBooleanAttribute(graph, fileNode, NsiliConstants.ARCHIVED, false, orb);
        addedAttributes.add(buildAttr(attribute, NsiliConstants.ARCHIVED));
    }
    if (shouldAdd(buildAttr(attribute, NsiliConstants.TITLE), resultAttributes) && metacard.getTitle() != null) {
        addStringAttribute(graph, fileNode, NsiliConstants.TITLE, metacard.getTitle(), orb);
        addedAttributes.add(buildAttr(attribute, NsiliConstants.TITLE));
    }
    if (shouldAdd(buildAttr(attribute, NsiliConstants.PRODUCT_URL), resultAttributes)) {
        String downloadUrl = String.valueOf(downloadUrlAttr.getValue());
        if (downloadUrl != null) {
            downloadUrl = modifyUrl(downloadUrl, metacard.getTitle());
            addStringAttribute(graph, fileNode, NsiliConstants.PRODUCT_URL, downloadUrl, orb);
            addedAttributes.add(buildAttr(attribute, NsiliConstants.PRODUCT_URL));
        }
    }
    addExtentResourceSizeAttribute(graph, metacard, orb, resultAttributes, addedAttributes, fileNode, attribute);
    addTimeDeclaredAttribute(graph, metacard, orb, resultAttributes, addedAttributes, fileNode, attribute);
    addStrAttribute(graph, metacard.getAttribute(Media.FORMAT), orb, resultAttributes, addedAttributes, fileNode, attribute, NsiliConstants.FORMAT);
    addStrAttribute(graph, metacard.getAttribute(Media.FORMAT_VERSION), orb, resultAttributes, addedAttributes, fileNode, attribute, NsiliConstants.FORMAT_VERSION);
    addCreatorAttribute(graph, metacard, orb, resultAttributes, addedAttributes, fileNode, attribute);
    if (shouldAdd(buildAttr(attribute, NsiliConstants.IS_PRODUCT_LOCAL), resultAttributes)) {
        String siteName = SystemInfo.getSiteName();
        boolean productLocal = true;
        if (siteName != null && metacard.getSourceId() != null && !siteName.equals(metacard.getSourceId())) {
            productLocal = false;
        }
        addBooleanAttribute(graph, fileNode, NsiliConstants.IS_PRODUCT_LOCAL, productLocal, orb);
        addedAttributes.add(buildAttr(attribute, NsiliConstants.IS_PRODUCT_LOCAL));
    }
    return addedAttributes;
}
Also used : Attribute(ddf.catalog.data.Attribute) Node(org.codice.alliance.nsili.common.UCO.Node) ArrayList(java.util.ArrayList) Any(org.omg.CORBA.Any)

Aggregations

Node (org.codice.alliance.nsili.common.UCO.Node)109 Any (org.omg.CORBA.Any)61 Edge (org.codice.alliance.nsili.common.UCO.Edge)31 ArrayList (java.util.ArrayList)23 DirectedAcyclicGraph (org.jgrapht.experimental.dag.DirectedAcyclicGraph)23 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)21 DAG (org.codice.alliance.nsili.common.UCO.DAG)21 Test (org.junit.Test)20 File (java.io.File)12 IOException (java.io.IOException)12 PrintStream (java.io.PrintStream)11 DepthFirstIterator (org.jgrapht.traverse.DepthFirstIterator)6 Attribute (ddf.catalog.data.Attribute)5 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 Metacard (ddf.catalog.data.Metacard)1 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)1 BufferedInputStream (java.io.BufferedInputStream)1 FileOutputStream (java.io.FileOutputStream)1 Serializable (java.io.Serializable)1