Search in sources :

Example 1 with DeliveryManifest

use of org.codice.alliance.nsili.common.GIAS.DeliveryManifest in project alliance by codice.

the class DeliveryManifestGenerator method getManifest.

public static DeliveryManifest getManifest() {
    String package_name = "myPackage";
    String[] files = {};
    PackageElement packageElement = new PackageElement(new _ProductStub(), files);
    PackageElement[] elements = { packageElement };
    DeliveryManifest deliveryManifest = new DeliveryManifest(package_name, elements);
    return deliveryManifest;
}
Also used : UID._ProductStub(org.codice.alliance.nsili.common.UID._ProductStub) DeliveryManifest(org.codice.alliance.nsili.common.GIAS.DeliveryManifest) PackageElement(org.codice.alliance.nsili.common.GIAS.PackageElement)

Example 2 with DeliveryManifest

use of org.codice.alliance.nsili.common.GIAS.DeliveryManifest in project alliance by codice.

the class OrderRequestImpl method complete.

@Override
public State complete(DeliveryManifestHolder deliveryManifestHolder) throws ProcessingFault, SystemFault {
    DeliveryManifest deliveryManifest = new DeliveryManifest();
    List<PackageElement> packageElements = new ArrayList<>();
    if (!orderContainsSupportedDelivery()) {
        throw new NO_IMPLEMENT("Only HTTP(s) is supported");
    }
    try {
        String filename = null;
        PackagingSpecFormatType packageFormatType = PackagingSpecFormatType.FILESUNC;
        List<ResourceContainer> files = new ArrayList<>();
        if (order.prod_list == null) {
            throw new BAD_OPERATION("No products specified for the order");
        }
        for (ProductDetails productDetails : order.prod_list) {
            requestProductResource(files, productDetails);
        }
        if (order.pSpec != null) {
            PackagingSpec packagingSpec = order.pSpec;
            filename = packagingSpec.package_identifier;
            packageFormatType = PackagingSpecFormatType.valueOf(packagingSpec.packaging_format_and_compression);
        }
        if (order.del_list != null) {
            for (DeliveryDetails deliveryDetails : order.del_list) {
                Destination destination = deliveryDetails.dests;
                Optional<DestinationSink> destinationSink = destinationSinkFactory.apply(destination);
                if (destinationSink.isPresent()) {
                    List<String> filesSent = writeData(destinationSink.get(), packageFormatType, files, filename);
                    PackageElement packageElement = new PackageElement();
                    packageElement.files = filesSent.toArray(new String[filesSent.size()]);
                    packageElements.add(packageElement);
                }
            }
        }
    } catch (UnsupportedEncodingException | WrongAdapter | WrongPolicy e) {
        LOGGER.debug("Unable to get Metacard for product:", e);
    } catch (IOException | ExecutionException | SecurityServiceException e) {
        LOGGER.debug("Unable to retrieve resource:", e);
    }
    if (order.pSpec != null) {
        deliveryManifest.package_name = order.pSpec.package_identifier;
    }
    deliveryManifest.elements = packageElements.toArray(new PackageElement[packageElements.size()]);
    deliveryManifestHolder.value = deliveryManifest;
    return State.COMPLETED;
}
Also used : NO_IMPLEMENT(org.omg.CORBA.NO_IMPLEMENT) Destination(org.codice.alliance.nsili.common.GIAS.Destination) SecurityServiceException(ddf.security.service.SecurityServiceException) DeliveryDetails(org.codice.alliance.nsili.common.GIAS.DeliveryDetails) DeliveryManifest(org.codice.alliance.nsili.common.GIAS.DeliveryManifest) ArrayList(java.util.ArrayList) WrongPolicy(org.omg.PortableServer.POAPackage.WrongPolicy) PackagingSpecFormatType(org.codice.alliance.nsili.common.PackagingSpecFormatType) ProductDetails(org.codice.alliance.nsili.common.GIAS.ProductDetails) PackagingSpec(org.codice.alliance.nsili.common.GIAS.PackagingSpec) ExecutionException(org.apache.shiro.subject.ExecutionException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) WrongAdapter(org.omg.PortableServer.POAPackage.WrongAdapter) PackageElement(org.codice.alliance.nsili.common.GIAS.PackageElement) BAD_OPERATION(org.omg.CORBA.BAD_OPERATION)

Example 3 with DeliveryManifest

use of org.codice.alliance.nsili.common.GIAS.DeliveryManifest 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)

Aggregations

DeliveryManifest (org.codice.alliance.nsili.common.GIAS.DeliveryManifest)3 PackageElement (org.codice.alliance.nsili.common.GIAS.PackageElement)3 IOException (java.io.IOException)2 SecurityServiceException (ddf.security.service.SecurityServiceException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 KeyManagementException (java.security.KeyManagementException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 CertificateException (java.security.cert.CertificateException)1 ArrayList (java.util.ArrayList)1 ExecutionException (org.apache.shiro.subject.ExecutionException)1 DeliveryDetails (org.codice.alliance.nsili.common.GIAS.DeliveryDetails)1 DeliveryManifestHolder (org.codice.alliance.nsili.common.GIAS.DeliveryManifestHolder)1 Destination (org.codice.alliance.nsili.common.GIAS.Destination)1 OrderContents (org.codice.alliance.nsili.common.GIAS.OrderContents)1 OrderRequest (org.codice.alliance.nsili.common.GIAS.OrderRequest)1 PackagingSpec (org.codice.alliance.nsili.common.GIAS.PackagingSpec)1 ProductDetails (org.codice.alliance.nsili.common.GIAS.ProductDetails)1 ValidationResults (org.codice.alliance.nsili.common.GIAS.ValidationResults)1