use of ddf.catalog.content.data.ContentItem in project ddf by codice.
the class ContentItemValidatorTest method testValidItemWithEmptyQualifier.
@Test
public void testValidItemWithEmptyQualifier() throws Exception {
String id = "634e8505-bd4b-436e-97e8-2045d1b0d265".replace("-", "");
String qualifier = "";
ContentItem item = new ContentItemImpl(id, qualifier, null, "", null);
assertThat(item.getQualifier(), nullValue());
assertThat(ContentItemValidator.validate(item), is(true));
}
use of ddf.catalog.content.data.ContentItem in project ddf by codice.
the class ContentItemValidatorTest method testInvalidIdColon.
@Test
public void testInvalidIdColon() throws Exception {
/* content colon should not be added by the caller */
String id = "content:634e8505-bd4b-436e-97e8-2045d1b0d265".replace("-", "");
String qualifier = "zoom-and-enhanced-overview";
ContentItem item = new ContentItemImpl(id, qualifier, null, "", null);
assertThat(ContentItemValidator.validate(item), is(false));
}
use of ddf.catalog.content.data.ContentItem in project ddf by codice.
the class ContentItemValidatorTest method testValidItemWithBlankNotEmptyQualifier.
@Test
public void testValidItemWithBlankNotEmptyQualifier() throws Exception {
String id = "634e8505-bd4b-436e-97e8-2045d1b0d265".replace("-", "");
String qualifier = " ";
ContentItem item = new ContentItemImpl(id, qualifier, null, "", null);
assertThat(item.getQualifier(), nullValue());
assertThat(ContentItemValidator.validate(item), is(true));
}
use of ddf.catalog.content.data.ContentItem 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.content.data.ContentItem in project ddf by codice.
the class ContentResourceReader method retrieveResource.
@Override
public ResourceResponse retrieveResource(URI resourceUri, Map<String, Serializable> arguments) throws IOException, ResourceNotFoundException, ResourceNotSupportedException {
LOGGER.trace("ENTERING: retrieveResource");
ResourceResponse response = null;
if (resourceUri == null) {
throw new ResourceNotFoundException("Unable to find resource - resource URI was null");
}
if (resourceUri.getScheme().equals(ContentItem.CONTENT_SCHEME)) {
LOGGER.debug("Resource URI is content scheme");
String contentId = resourceUri.getSchemeSpecificPart();
if (contentId != null && !contentId.isEmpty()) {
if (arguments != null && arguments.get(ContentItem.QUALIFIER) instanceof String && StringUtils.isNotBlank((String) arguments.get(ContentItem.QUALIFIER))) {
try {
resourceUri = new URI(resourceUri.getScheme(), resourceUri.getSchemeSpecificPart(), (String) arguments.get(ContentItem.QUALIFIER));
} catch (URISyntaxException e) {
throw new ResourceNotFoundException("Unable to create with qualifier", e);
}
}
ReadStorageRequest readRequest = new ReadStorageRequestImpl(resourceUri, arguments);
try {
ReadStorageResponse readResponse = storage.read(readRequest);
ContentItem contentItem = readResponse.getContentItem();
String fileName = contentItem.getFilename();
LOGGER.debug("resource name: {}", fileName);
InputStream is = contentItem.getInputStream();
response = new ResourceResponseImpl(new ResourceImpl(new BufferedInputStream(is), contentItem.getMimeType(), fileName));
} catch (StorageException e) {
throw new ResourceNotFoundException(e);
}
}
}
LOGGER.trace("EXITING: retrieveResource");
return response;
}
Aggregations