use of ddf.catalog.operation.impl.ResourceRequestByProductUri in project ddf by codice.
the class ExportCommand method doContentExport.
private List<ExportItem> doContentExport(/*Mutable,IO*/
ZipFile zipFile, List<ExportItem> exportedItems) throws ZipException {
List<ExportItem> contentItemsToExport = exportedItems.stream().filter(ei -> ei.getResourceUri() != null).filter(ei -> ei.getResourceUri().getScheme() != null).filter(ei -> ei.getResourceUri().getScheme().startsWith(ContentItem.CONTENT_SCHEME)).filter(ei -> !ei.getMetacardTag().equals("deleted")).filter(ei -> !ei.getMetacardTag().equals("revision") || ei.getResourceUri().getSchemeSpecificPart().equals(ei.getId())).filter(distinctByKey(ei -> ei.getResourceUri().getSchemeSpecificPart())).collect(Collectors.toList());
List<ExportItem> exportedContentItems = new ArrayList<>();
for (ExportItem contentItem : contentItemsToExport) {
ResourceResponse resource;
try {
resource = catalogFramework.getLocalResource(new ResourceRequestByProductUri(contentItem.getResourceUri()));
} catch (IOException | ResourceNotSupportedException e) {
throw new CatalogCommandRuntimeException("Unable to retrieve resource for " + contentItem.getId(), e);
} catch (ResourceNotFoundException e) {
continue;
}
writeToZip(zipFile, contentItem, resource);
exportedContentItems.add(contentItem);
if (!contentItem.getMetacardTag().equals("revision")) {
for (String derivedUri : contentItem.getDerivedUris()) {
URI uri;
try {
uri = new URI(derivedUri);
} catch (URISyntaxException e) {
LOGGER.debug("Uri [{}] is not a valid URI. Derived content will not be included in export", derivedUri);
continue;
}
ResourceResponse derivedResource;
try {
derivedResource = catalogFramework.getLocalResource(new ResourceRequestByProductUri(uri));
} catch (IOException e) {
throw new CatalogCommandRuntimeException("Unable to retrieve resource for " + contentItem.getId(), e);
} catch (ResourceNotFoundException | ResourceNotSupportedException e) {
LOGGER.warn("Could not retreive resource [{}]", uri, e);
console.printf("%sUnable to retrieve resource for export : %s%s%n", Ansi.ansi().fg(Ansi.Color.RED).toString(), uri, Ansi.ansi().reset().toString());
continue;
}
writeToZip(zipFile, contentItem, derivedResource);
}
}
}
return exportedContentItems;
}
use of ddf.catalog.operation.impl.ResourceRequestByProductUri in project alliance by codice.
the class CatalogInputAdapter method buildReadRequest.
/**
* @param metacard the Metacard containing the relevant information for the ResourceRequest. May
* not be null.
* @return the ResourceRequest object to query the CatalogFramework service.
*/
public ResourceRequest buildReadRequest(Metacard metacard, String qualifier) {
if (metacard == null) {
throw new IllegalArgumentException("method argument 'metacard' may not be null.");
}
if (qualifier == null) {
throw new IllegalArgumentException("method argument 'qualifier' may not be null.");
}
Attribute attribute = metacard.getAttribute(Metacard.DERIVED_RESOURCE_URI);
if (attribute != null) {
List<Serializable> values = attribute.getValues();
if (values == null) {
throw new IllegalStateException(String.format("metacard attribute %s has no values assigned.", Metacard.DERIVED_RESOURCE_URI));
}
URI qualifiedUri = findDerivedResourceUri(values, qualifier);
return new ResourceRequestByProductUri(qualifiedUri);
}
throw new IllegalStateException(String.format("The supplied metacard does not contain the " + "'%s' attribute.", Metacard.DERIVED_RESOURCE_URI));
}
use of ddf.catalog.operation.impl.ResourceRequestByProductUri in project ddf by codice.
the class ExportCommand method doContentExport.
@SuppressWarnings("squid:S3776")
private List<ExportItem> doContentExport(ZipOutputStream zipOutputStream, List<ExportItem> exportedItems) {
List<ExportItem> contentItemsToExport = exportedItems.stream().filter(ei -> ei.getResourceUri() != null).filter(ei -> ei.getResourceUri().getScheme() != null).filter(ei -> ei.getResourceUri().getScheme().startsWith(ContentItem.CONTENT_SCHEME)).filter(ei -> !ei.getMetacardTag().equals(DELETED_METACARD)).filter(ei -> !ei.getMetacardTag().equals(REVISION_METACARD) || ei.getResourceUri().getSchemeSpecificPart().equals(ei.getId())).filter(distinctByKey(ei -> ei.getResourceUri().getSchemeSpecificPart())).collect(Collectors.toList());
List<ExportItem> exportedContentItems = new ArrayList<>();
for (ExportItem contentItem : contentItemsToExport) {
ResourceResponse resource;
try {
resource = catalogFramework.getLocalResource(new ResourceRequestByProductUri(contentItem.getResourceUri()));
} catch (IOException | ResourceNotSupportedException e) {
throw new CatalogCommandRuntimeException("Unable to retrieve resource for " + contentItem.getId(), e);
} catch (ResourceNotFoundException e) {
continue;
}
writeResourceToZip(zipOutputStream, contentItem, resource);
exportedContentItems.add(contentItem);
if (!contentItem.getMetacardTag().equals(REVISION_METACARD)) {
for (String derivedUri : contentItem.getDerivedUris()) {
URI uri;
try {
uri = new URI(derivedUri);
} catch (URISyntaxException e) {
LOGGER.debug("Uri [{}] is not a valid URI. Derived content will not be included in export", derivedUri);
continue;
}
ResourceResponse derivedResource;
try {
derivedResource = catalogFramework.getLocalResource(new ResourceRequestByProductUri(uri));
} catch (IOException e) {
throw new CatalogCommandRuntimeException("Unable to retrieve resource for " + contentItem.getId(), e);
} catch (ResourceNotFoundException | ResourceNotSupportedException e) {
LOGGER.warn("Could not retreive resource [{}]", uri, e);
console.printf("%sUnable to retrieve resource for export : %s%s%n", Ansi.ansi().fg(Ansi.Color.RED).toString(), uri, Ansi.ansi().reset().toString());
continue;
}
writeResourceToZip(zipOutputStream, contentItem, derivedResource);
}
}
}
return exportedContentItems;
}
Aggregations