Search in sources :

Example 11 with ContentItemImpl

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"));
}
Also used : Metacard(ddf.catalog.data.Metacard) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URI(java.net.URI) ContentItem(ddf.catalog.content.data.ContentItem) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl) Test(org.junit.Test)

Example 12 with ContentItemImpl

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"));
}
Also used : Metacard(ddf.catalog.data.Metacard) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) URI(java.net.URI) ContentItem(ddf.catalog.content.data.ContentItem) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl) Test(org.junit.Test)

Example 13 with ContentItemImpl

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"));
}
Also used : Metacard(ddf.catalog.data.Metacard) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) URI(java.net.URI) ContentItem(ddf.catalog.content.data.ContentItem) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl) Test(org.junit.Test)

Example 14 with ContentItemImpl

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);
}
Also used : Serializable(java.io.Serializable) Action(ddf.catalog.core.versioning.MetacardVersion.Action) ResourceResponse(ddf.catalog.operation.ResourceResponse) UpdateStorageRequestImpl(ddf.catalog.content.operation.impl.UpdateStorageRequestImpl) HashMap(java.util.HashMap) CreateStorageRequestImpl(ddf.catalog.content.operation.impl.CreateStorageRequestImpl) ResourceRequestById(ddf.catalog.operation.impl.ResourceRequestById) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl)

Example 15 with ContentItemImpl

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;
}
Also used : AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ContentItem(ddf.catalog.content.data.ContentItem) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl)

Aggregations

ContentItemImpl (ddf.catalog.content.data.impl.ContentItemImpl)29 ContentItem (ddf.catalog.content.data.ContentItem)25 Metacard (ddf.catalog.data.Metacard)24 Test (org.junit.Test)17 ByteSource (com.google.common.io.ByteSource)14 CreateStorageRequestImpl (ddf.catalog.content.operation.impl.CreateStorageRequestImpl)14 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)12 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)10 IOException (java.io.IOException)8 InputStream (java.io.InputStream)8 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)8 CreateStorageResponse (ddf.catalog.content.operation.CreateStorageResponse)7 CreateResponse (ddf.catalog.operation.CreateResponse)7 UpdateStorageRequestImpl (ddf.catalog.content.operation.impl.UpdateStorageRequestImpl)6 Serializable (java.io.Serializable)6 URI (java.net.URI)6 CreateStorageRequest (ddf.catalog.content.operation.CreateStorageRequest)5 UpdateStorageRequest (ddf.catalog.content.operation.UpdateStorageRequest)5 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)5