Search in sources :

Example 1 with Product

use of org.codice.alliance.nsili.common.UID.Product 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 2 with Product

use of org.codice.alliance.nsili.common.UID.Product in project alliance by codice.

the class Client method evaluateResult.

private void evaluateResult(SampleNsiliClient sampleNsiliClient, DAG[] results, int index) throws Exception {
    LOGGER.info("\t RESULT : {} of {} ", (index + 1), results.length);
    String obsoleteName = NsiliCardStatus.OBSOLETE.name();
    if (getAttributeFromDag(results[index], NsiliConstants.STATUS).equalsIgnoreCase(obsoleteName)) {
        LOGGER.info("Record is {}. Not testing result", obsoleteName);
    } else {
        sampleNsiliClient.printDagAttributes(results[index]);
        if (SHOULD_DOWNLOAD_PRODUCT) {
            sampleNsiliClient.downloadProductFromDAG(results[index]);
        }
        // ProductMgr
        LOGGER.info("-----------------------");
        try {
            sampleNsiliClient.testProductMgr(results[index]);
        } catch (Exception e) {
            LOGGER.info("Unable to test ProductMgr: {}", NsilCorbaExceptionUtil.getExceptionDetails(e));
        }
        LOGGER.info("-----------------------");
        // OrderMgr
        PackageElement[] packageElements = sampleNsiliClient.order(results[index]);
        // ProductMgr
        if (SHOULD_PROCESS_PKG_ELEMENTS) {
            for (PackageElement packageElement : packageElements) {
                Product product = packageElement.prod;
                sampleNsiliClient.getParameters(product);
                sampleNsiliClient.getRelatedFileTypes(product);
                sampleNsiliClient.getRelatedFiles(product);
            }
        }
    }
}
Also used : Product(org.codice.alliance.nsili.common.UID.Product) PackageElement(org.codice.alliance.nsili.common.GIAS.PackageElement)

Example 3 with Product

use of org.codice.alliance.nsili.common.UID.Product in project alliance by codice.

the class SampleNsiliClient method testProductMgr.

public void testProductMgr(DAG dag) throws Exception {
    if (productMgr != null) {
        LOGGER.info("--------------------------");
        LOGGER.info("Getting ProductMgr Use Modes");
        final String[] useModes = productMgr.get_use_modes();
        for (String useMode : useModes) {
            LOGGER.info(TAB_LOG_MSG, useMode);
        }
        final short numPriorities = productMgr.get_number_of_priorities();
        LOGGER.info("Product Mgr num of priorities: {}", numPriorities);
        final Product product = getProductFromDag(dag);
        LOGGER.info("Product is available tests ");
        final boolean avail = productMgr.is_available(product, useModes[0]);
        LOGGER.info("\t {} : {}", useModes[0], avail);
        final String productID = getProductIdFromDag(dag);
        LOGGER.info("Getting CORE, ALL, and ORDER parameters for : {}", productID);
        getParameters(product);
        LOGGER.info("Getting related file types for : {}", productID);
        getRelatedFileTypes(product);
        LOGGER.info("Getting thumbnail for : {}", productID);
        getRelatedFiles(product);
    } else {
        LOGGER.warn("ProductMgr is not initialized, unable to test");
    }
}
Also used : Product(org.codice.alliance.nsili.common.UID.Product)

Example 4 with Product

use of org.codice.alliance.nsili.common.UID.Product in project alliance by codice.

the class AccessManagerImplTest method testIsAvailableWithBadURL.

@Test
public void testIsAvailableWithBadURL() throws Exception {
    MetacardImpl testMetacard = new MetacardImpl();
    testMetacard.setId(testMetacardId);
    testMetacard.setTitle("JUnit Test Card");
    testMetacard.setAttribute(new AttributeImpl(Metacard.RESOURCE_DOWNLOAD_URL, "http://localhost:20999/not/present"));
    Result testResult = new ResultImpl(testMetacard);
    List<Result> results = new ArrayList<>();
    results.add(testResult);
    QueryResponse testResponse = new QueryResponseImpl(null, results, results.size());
    when(mockCatalogFramework.query(any(QueryRequest.class))).thenReturn(testResponse);
    DAG dag = ResultDAGConverter.convertResult(testResult, orb, rootPOA, new ArrayList<>(), new HashMap<>());
    Product product = ProductHelper.extract(dag.nodes[0].value);
    boolean avail = accessManager.is_available(product, null);
    assertThat(avail, is(false));
    avail = accessManager.is_available(null, null);
    assertThat(avail, is(false));
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) Product(org.codice.alliance.nsili.common.UID.Product) ResultImpl(ddf.catalog.data.impl.ResultImpl) DAG(org.codice.alliance.nsili.common.UCO.DAG) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) QueryResponse(ddf.catalog.operation.QueryResponse) Test(org.junit.Test)

Example 5 with Product

use of org.codice.alliance.nsili.common.UID.Product in project alliance by codice.

the class AccessManagerImplTest method testIsAvailableNoURL.

@Test
public void testIsAvailableNoURL() throws Exception {
    MetacardImpl testMetacard = new MetacardImpl();
    testMetacard.setId(testMetacardId);
    testMetacard.setTitle("JUnit Test Card");
    Result testResult = new ResultImpl(testMetacard);
    DAG dag = ResultDAGConverter.convertResult(testResult, orb, rootPOA, new ArrayList<>(), new HashMap<>());
    Product product = ProductHelper.extract(dag.nodes[0].value);
    boolean avail = accessManager.is_available(product, null);
    assertThat(avail, is(false));
    avail = accessManager.is_available(null, null);
    assertThat(avail, is(false));
}
Also used : Product(org.codice.alliance.nsili.common.UID.Product) ResultImpl(ddf.catalog.data.impl.ResultImpl) DAG(org.codice.alliance.nsili.common.UCO.DAG) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Aggregations

Product (org.codice.alliance.nsili.common.UID.Product)16 DAG (org.codice.alliance.nsili.common.UCO.DAG)10 Result (ddf.catalog.data.Result)9 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)9 ResultImpl (ddf.catalog.data.impl.ResultImpl)9 Test (org.junit.Test)9 GetRelatedFilesRequest (org.codice.alliance.nsili.common.GIAS.GetRelatedFilesRequest)5 NameValue (org.codice.alliance.nsili.common.UCO.NameValue)5 Any (org.omg.CORBA.Any)5 FileLocation (org.codice.alliance.nsili.common.UCO.FileLocation)4 ArrayList (java.util.ArrayList)3 Metacard (ddf.catalog.data.Metacard)2 GetParametersRequest (org.codice.alliance.nsili.common.GIAS.GetParametersRequest)2 PackageElement (org.codice.alliance.nsili.common.GIAS.PackageElement)2 DAGHolder (org.codice.alliance.nsili.common.UCO.DAGHolder)2 ObjectAlreadyActive (org.omg.PortableServer.POAPackage.ObjectAlreadyActive)2 ServantAlreadyActive (org.omg.PortableServer.POAPackage.ServantAlreadyActive)2 WrongPolicy (org.omg.PortableServer.POAPackage.WrongPolicy)2 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)1 QueryRequest (ddf.catalog.operation.QueryRequest)1