use of ddf.catalog.content.data.impl.ContentItemImpl in project ddf by codice.
the class OverrideAttributesSupportTest method testNoOverrideMetacard.
@Test
public void testNoOverrideMetacard() throws URISyntaxException {
List<ContentItem> contentItems = new ArrayList<>();
Map<String, Metacard> metacardMap = new HashMap<>();
MetacardImpl metacard = new MetacardImpl();
metacard.setMetadata("original");
metacard.setTitle("original");
metacard.setId("original");
metacard.setResourceURI(new URI("content:stuff"));
metacardMap.put(metacard.getId(), metacard);
contentItems.add(new ContentItemImpl("original", null, "txt/plain", null));
OverrideAttributesSupport.overrideAttributes(contentItems, metacardMap);
assertNotNull(metacardMap.get("original"));
assertThat(metacardMap.get("original").getMetadata(), is("original"));
assertThat(metacardMap.get("original").getTitle(), is("original"));
assertThat(metacardMap.get("original").getResourceURI().toString(), is("content:stuff"));
assertThat(metacardMap.get("original").getId(), is("original"));
}
use of ddf.catalog.content.data.impl.ContentItemImpl in project ddf by codice.
the class OverrideAttributesSupportTest method testOverrideAttributesBasic.
@Test
public void testOverrideAttributesBasic() throws URISyntaxException {
List<ContentItem> contentItems = new ArrayList<>();
Map<String, Metacard> metacardMap = new HashMap<>();
MetacardImpl overrideMetacard = new MetacardImpl();
MetacardImpl metacard = new MetacardImpl(new MetacardTypeImpl("special", overrideMetacard.getMetacardType().getAttributeDescriptors()));
metacard.setMetadata("original");
metacard.setTitle("original");
metacard.setId("original");
metacard.setResourceURI(new URI("content:stuff"));
overrideMetacard.setTitle("updated");
overrideMetacard.setId("updated");
overrideMetacard.setResourceURI(new URI("content:newstuff"));
overrideMetacard.setMetadata("updated");
metacardMap.put(metacard.getId(), metacard);
contentItems.add(new ContentItemImpl("original", null, "txt/plain", overrideMetacard));
OverrideAttributesSupport.overrideAttributes(contentItems, metacardMap);
assertNotNull(metacardMap.get("original"));
assertThat(metacardMap.get("original").getMetadata(), is("updated"));
assertThat(metacardMap.get("original").getTitle(), is("updated"));
assertThat(metacardMap.get("original").getResourceURI().toString(), is("content:newstuff"));
assertThat(metacardMap.get("original").getId(), is("original"));
assertThat(metacardMap.get("original").getMetacardType().getName(), is("special"));
}
use of ddf.catalog.content.data.impl.ContentItemImpl in project ddf by codice.
the class OverrideAttributesSupportTest method testOverrideAttributesOther.
@Test
public void testOverrideAttributesOther() throws URISyntaxException {
List<ContentItem> contentItems = new ArrayList<>();
Map<String, Metacard> metacardMap = new HashMap<>();
MetacardImpl metacard = new MetacardImpl();
metacard.setMetadata("original");
metacard.setTitle("original");
metacard.setId("original");
metacard.setResourceURI(new URI("content:stuff"));
MetacardImpl overrideMetacard = new MetacardImpl(new MetacardTypeImpl("other", metacard.getMetacardType().getAttributeDescriptors()));
overrideMetacard.setTitle("updated");
overrideMetacard.setId("updated");
overrideMetacard.setMetadata("updated");
overrideMetacard.setResourceURI(new URI("content:newstuff"));
metacardMap.put(metacard.getId(), metacard);
contentItems.add(new ContentItemImpl("original", null, "txt/plain", overrideMetacard));
OverrideAttributesSupport.overrideAttributes(contentItems, metacardMap);
assertNotNull(metacardMap.get("original"));
assertThat(metacardMap.get("original").getMetadata(), is("updated"));
assertThat(metacardMap.get("original").getTitle(), is("updated"));
assertThat(metacardMap.get("original").getResourceURI().toString(), is("content:newstuff"));
assertThat(metacardMap.get("original").getId(), is("original"));
assertThat(metacardMap.get("original").getMetacardType().getName(), is("other"));
}
use of ddf.catalog.content.data.impl.ContentItemImpl in project ddf by codice.
the class MetacardApplication method revertContentandMetacard.
private void revertContentandMetacard(Metacard latestContent, Metacard versionMetacard, String id) throws SourceUnavailableException, IngestException, ResourceNotFoundException, IOException, ResourceNotSupportedException, FederationException, UnsupportedQueryException {
LOGGER.trace("Reverting content and metacard for metacard [{}]. \nLatest content: [{}] \nVersion metacard: [{}]", id, latestContent.getId(), versionMetacard.getId());
Map<String, Serializable> properties = new HashMap<>();
properties.put("no-default-tags", true);
ResourceResponse latestResource = catalogFramework.getLocalResource(new ResourceRequestById(latestContent.getId(), properties));
ContentItemImpl contentItem = new ContentItemImpl(id, new ByteSourceWrapper(() -> latestResource.getResource().getInputStream()), latestResource.getResource().getMimeTypeValue(), latestResource.getResource().getName(), latestResource.getResource().getSize(), MetacardVersionImpl.toMetacard(versionMetacard, types));
// Try to delete the "deleted metacard" marker first.
boolean alreadyCreated = false;
Action action = Action.fromKey((String) versionMetacard.getAttribute(MetacardVersion.ACTION).getValue());
if (DELETE_ACTIONS.contains(action)) {
alreadyCreated = true;
catalogFramework.create(new CreateStorageRequestImpl(Collections.singletonList(contentItem), id, new HashMap<>()));
} else {
// Currently we can't guarantee the metacard will exist yet because of the 1 second
// soft commit in solr. this busy wait loop should be fixed when alternate solution
// is found.
tryUpdate(4, () -> {
catalogFramework.update(new UpdateStorageRequestImpl(Collections.singletonList(contentItem), id, new HashMap<>()));
return true;
});
}
LOGGER.trace("Successfully reverted metacard content for [{}]", id);
revertMetacard(versionMetacard, id, alreadyCreated);
}
use of ddf.catalog.content.data.impl.ContentItemImpl in project ddf by codice.
the class PreviewStoragePlugin method createPreviewItem.
private ContentItem createPreviewItem(Metacard metacard) {
ContentItem preview = new ContentItemImpl(metacard.getId(), "preview", ByteSource.wrap(metacard.getThumbnail()), "image/jpg", metacard.getTitle(), metacard.getThumbnail().length, metacard);
metacard.setAttribute(new AttributeImpl(Metacard.DERIVED_RESOURCE_URI, preview.getUri()));
return preview;
}
Aggregations