use of org.codice.alliance.nsili.common.PackagingSpecFormatType 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;
}
Aggregations