Search in sources :

Example 11 with Product

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

the class ProductMgrImplTest method testGetParameters.

@Test
public void testGetParameters() 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);
    GetParametersRequest parametersRequest = productMgr.get_parameters(product, new String[] { "ALL" }, null);
    assertThat(parametersRequest, notNullValue());
    DAGHolder dagHolder = new DAGHolder();
    parametersRequest.complete(dagHolder);
    assertThat(dagHolder, notNullValue());
}
Also used : DAGHolder(org.codice.alliance.nsili.common.UCO.DAGHolder) 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) GetParametersRequest(org.codice.alliance.nsili.common.GIAS.GetParametersRequest) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 12 with Product

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

the class ProductMgrImplTest method testGetRelatedFiles.

@Test
public void testGetRelatedFiles() 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);
    Product[] products = new Product[] { product };
    String userName = "";
    String password = "";
    String hostName = "localhost";
    String pathName = "/nsili/file";
    FileLocation location = new FileLocation(userName, password, hostName, pathName, null);
    NameValue[] props = new NameValue[0];
    GetRelatedFilesRequest request = productMgr.get_related_files(products, location, NsiliConstants.THUMBNAIL_TYPE, props);
    assertThat(request, notNullValue());
}
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) NameValue(org.codice.alliance.nsili.common.UCO.NameValue) FileLocation(org.codice.alliance.nsili.common.UCO.FileLocation) GetRelatedFilesRequest(org.codice.alliance.nsili.common.GIAS.GetRelatedFilesRequest) Test(org.junit.Test)

Example 13 with Product

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

the class ProductMgrImplTest method testGetRelatedFilesWithPort.

@Test
public void testGetRelatedFilesWithPort() 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);
    Product[] products = new Product[] { product };
    String userName = "";
    String password = "";
    String hostName = "localhost";
    String pathName = "/nsili/file";
    FileLocation location = new FileLocation(userName, password, hostName, pathName, null);
    NameValue[] props = new NameValue[1];
    Any portAny = orb.create_any();
    portAny.insert_string("2000");
    NameValue prop = new NameValue("PORT", portAny);
    props[0] = prop;
    GetRelatedFilesRequest request = productMgr.get_related_files(products, location, NsiliConstants.THUMBNAIL_TYPE, props);
    assertThat(request, notNullValue());
}
Also used : Product(org.codice.alliance.nsili.common.UID.Product) ResultImpl(ddf.catalog.data.impl.ResultImpl) DAG(org.codice.alliance.nsili.common.UCO.DAG) Any(org.omg.CORBA.Any) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) NameValue(org.codice.alliance.nsili.common.UCO.NameValue) FileLocation(org.codice.alliance.nsili.common.UCO.FileLocation) GetRelatedFilesRequest(org.codice.alliance.nsili.common.GIAS.GetRelatedFilesRequest) Test(org.junit.Test)

Example 14 with Product

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

the class SampleNsiliClient method order.

public PackageElement[] order(DAG dag) throws Exception {
    if (orderMgr == null) {
        LOGGER.warn("OrderMgr is not initialized, unable to submit order");
        return null;
    }
    LOGGER.info("--------------------------");
    LOGGER.info("OrderMgr getting package specifications");
    String[] supportedPackageSpecs = orderMgr.get_package_specifications();
    if (supportedPackageSpecs != null && supportedPackageSpecs.length > 0) {
        for (String supportedPackageSpec : supportedPackageSpecs) {
            LOGGER.info(TAB_LOG_MSG, supportedPackageSpec);
        }
    } else {
        LOGGER.warn("Server returned no packaging specifications");
        supportedPackageSpecs = new String[0];
    }
    LOGGER.info("Getting OrderMgr Use Modes");
    String[] useModes = orderMgr.get_use_modes();
    for (String useMode : useModes) {
        LOGGER.info(TAB_LOG_MSG, useMode);
    }
    LOGGER.info("Order Mgr num of priorities: {} ", orderMgr.get_number_of_priorities());
    Product product = getProductFromDag(dag);
    String filename = getAttributeFromDag(dag, NsiliConstants.FILENAME) + ".dat";
    // Product available
    boolean productAvail = orderMgr.is_available(product, useModes[0]);
    LOGGER.info("Product available: {}", productAvail);
    LOGGER.info("Creating order request...");
    Any portAny = orb.create_any();
    Any protocolAny = orb.create_any();
    protocolAny.insert_string("http");
    portAny.insert_long(listenPort);
    NameValue portProp = new NameValue("PORT", portAny);
    NameValue protocolProp = new NameValue("PROTOCOL", protocolAny);
    NameValue[] properties = new NameValue[] { portProp, protocolProp };
    OrderContents order = createFileOrder(product, supportedPackageSpecs, filename);
    // Validating Order
    LOGGER.info("Validating Order...");
    ValidationResults validationResults = orderMgr.validate_order(order, properties);
    LOGGER.info("Validation Results: ");
    LOGGER.info("\tValid : {} \n" + "\tWarning : {} \n" + "\tDetails : {}", validationResults.valid, validationResults.warning, validationResults.details);
    OrderRequest orderRequest = orderMgr.order(order, properties);
    LOGGER.info("Completing OrderRequest...");
    DeliveryManifestHolder deliveryManifestHolder = new DeliveryManifestHolder();
    orderRequest.set_user_info(ALLIANCE);
    PackageElement[] elements;
    try {
        orderRequest.complete(deliveryManifestHolder);
        if (emailAddress != null) {
            order = createEmailOrder(orb, product, supportedPackageSpecs);
            // Validating Order
            LOGGER.info("Validating Email Order...");
            validationResults = orderMgr.validate_order(order, properties);
            LOGGER.info("Email Validation Results: ");
            LOGGER.info("\tValid : {}\n\tWarning : {}\n\tDetails : {}\n", validationResults.valid, validationResults.warning, validationResults.details);
            orderRequest = orderMgr.order(order, properties);
            orderRequest.set_user_info(ALLIANCE);
            orderRequest.complete(deliveryManifestHolder);
        }
        DeliveryManifest deliveryManifest = deliveryManifestHolder.value;
        LOGGER.info("Completed Order : {}", deliveryManifest.package_name);
        elements = deliveryManifest.elements;
        if (deliveryManifest.elements != null) {
            for (PackageElement element : elements) {
                for (String file : element.files) {
                    LOGGER.info(TAB_LOG_MSG, file);
                }
            }
        }
        return elements;
    } catch (Exception e) {
        LOGGER.error("Error completing order request", NsilCorbaExceptionUtil.getExceptionDetails(e));
        return null;
    }
}
Also used : OrderRequest(org.codice.alliance.nsili.common.GIAS.OrderRequest) DeliveryManifest(org.codice.alliance.nsili.common.GIAS.DeliveryManifest) Product(org.codice.alliance.nsili.common.UID.Product) Any(org.omg.CORBA.Any) KeyManagementException(java.security.KeyManagementException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) CertificateException(java.security.cert.CertificateException) NameValue(org.codice.alliance.nsili.common.UCO.NameValue) ValidationResults(org.codice.alliance.nsili.common.GIAS.ValidationResults) OrderContents(org.codice.alliance.nsili.common.GIAS.OrderContents) DeliveryManifestHolder(org.codice.alliance.nsili.common.GIAS.DeliveryManifestHolder) PackageElement(org.codice.alliance.nsili.common.GIAS.PackageElement)

Example 15 with Product

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

the class SampleNsiliClient method getRelatedFiles.

public String[] getRelatedFiles(Product product) throws Exception {
    if (productMgr != null) {
        LOGGER.info("Sending Get Related Files Request...");
        final FileLocation fileLocation = new FileLocation("user", "pass", "localhost", "/nsili/file", "");
        Any portAny = orb.create_any();
        portAny.insert_string(String.valueOf(listenPort));
        NameValue portProp = new NameValue("PORT", portAny);
        NameValue[] properties = new NameValue[] { portProp };
        Product[] products = { product };
        GetRelatedFilesRequest relatedFilesRequest = productMgr.get_related_files(products, fileLocation, NsiliConstants.THUMBNAIL_TYPE, properties);
        relatedFilesRequest.set_user_info(ALLIANCE);
        NameListHolder locations = new NameListHolder();
        relatedFilesRequest.complete(locations);
        String[] locationList = locations.value;
        if (locationList.length > 0) {
            LOGGER.info("Location List : ");
            for (String location : locationList) {
                LOGGER.info("\t Stored File: {}", location);
            }
        } else {
            LOGGER.info("No locations returned from Get Related Files Request");
        }
        return locationList;
    } else {
        LOGGER.warn("ProductMgr is not initialized, unable to get related files");
        return null;
    }
}
Also used : NameValue(org.codice.alliance.nsili.common.UCO.NameValue) FileLocation(org.codice.alliance.nsili.common.UCO.FileLocation) GetRelatedFilesRequest(org.codice.alliance.nsili.common.GIAS.GetRelatedFilesRequest) Product(org.codice.alliance.nsili.common.UID.Product) Any(org.omg.CORBA.Any) NameListHolder(org.codice.alliance.nsili.common.UCO.NameListHolder)

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