Search in sources :

Example 36 with ContentItem

use of ddf.catalog.content.data.ContentItem 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 37 with ContentItem

use of ddf.catalog.content.data.ContentItem 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 38 with ContentItem

use of ddf.catalog.content.data.ContentItem 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 39 with ContentItem

use of ddf.catalog.content.data.ContentItem in project ddf by codice.

the class CatalogFrameworkImplTest method testCreateStorageWithAttributeOverridesInvalidType.

/**
     * Tests that the framework properly passes a create request to the local provider with attribute overrides.
     */
@Test
public void testCreateStorageWithAttributeOverridesInvalidType() throws Exception {
    List<ContentItem> contentItems = new ArrayList<>();
    Map<String, Serializable> propertiesMap = new HashMap<>();
    HashMap<String, Object> attributeMap = new HashMap<>();
    attributeMap.put(Metacard.CREATED, "bad date");
    propertiesMap.put(Constants.ATTRIBUTE_OVERRIDES_KEY, attributeMap);
    MetacardImpl newCard = new MetacardImpl();
    newCard.setId(null);
    MetacardType metacardType = mock(MetacardType.class);
    AttributeDescriptor dateAttributeDescriptor = new AttributeDescriptorImpl(Metacard.CREATED, true, true, true, true, new AttributeType<Date>() {

        private static final long serialVersionUID = 1L;

        @Override
        public Class<Date> getBinding() {
            return Date.class;
        }

        @Override
        public AttributeFormat getAttributeFormat() {
            return AttributeFormat.DATE;
        }
    });
    when(metacardType.getAttributeDescriptor(Metacard.TITLE)).thenReturn(dateAttributeDescriptor);
    newCard.setType(metacardType);
    ByteSource byteSource = new ByteSource() {

        @Override
        public InputStream openStream() throws IOException {
            return new ByteArrayInputStream("blah".getBytes());
        }
    };
    ContentItemImpl newItem = new ContentItemImpl(uuidGenerator.generateUuid(), byteSource, "application/octet-stream", "blah", 0L, newCard);
    contentItems.add(newItem);
    CreateResponse response = framework.create(new CreateStorageRequestImpl(contentItems, propertiesMap));
    assertEquals(response.getCreatedMetacards().size(), provider.size());
    assertEquals(response.getCreatedMetacards().size(), storageProvider.size());
    for (Metacard curCard : response.getCreatedMetacards()) {
        assertNotNull(curCard.getId());
        // Assert value is not set for invalid format
        assertThat(curCard.getCreatedDate(), nullValue());
    }
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) CreateResponse(ddf.catalog.operation.CreateResponse) ArrayList(java.util.ArrayList) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) Matchers.anyString(org.mockito.Matchers.anyString) CreateStorageRequestImpl(ddf.catalog.content.operation.impl.CreateStorageRequestImpl) AttributeDescriptorImpl(ddf.catalog.data.impl.AttributeDescriptorImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) MetacardType(ddf.catalog.data.MetacardType) Date(java.util.Date) Metacard(ddf.catalog.data.Metacard) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteSource(com.google.common.io.ByteSource) Matchers.anyObject(org.mockito.Matchers.anyObject) ContentItem(ddf.catalog.content.data.ContentItem) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl) Test(org.junit.Test)

Example 40 with ContentItem

use of ddf.catalog.content.data.ContentItem in project ddf by codice.

the class FanoutCatalogFrameworkTest method testBlacklistedTagUpdateStorageRequestFails.

@Test(expected = IngestException.class)
public void testBlacklistedTagUpdateStorageRequestFails() throws Exception {
    Metacard metacard = new MetacardImpl();
    metacard.setAttribute(new AttributeImpl(Metacard.ID, "metacardId"));
    metacard.setAttribute(new AttributeImpl(Metacard.TAGS, "blacklisted"));
    ContentItem item = new ContentItemImpl(uuidGenerator.generateUuid(), ByteSource.empty(), "text/xml", "filename.xml", 0L, metacard);
    UpdateStorageRequest request = new UpdateStorageRequestImpl(Collections.singletonList(item), new HashMap<>());
    framework.setFanoutTagBlacklist(Collections.singletonList("blacklisted"));
    framework.update(request);
}
Also used : Metacard(ddf.catalog.data.Metacard) UpdateStorageRequestImpl(ddf.catalog.content.operation.impl.UpdateStorageRequestImpl) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) ContentItem(ddf.catalog.content.data.ContentItem) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl) Test(org.junit.Test)

Aggregations

ContentItem (ddf.catalog.content.data.ContentItem)65 Metacard (ddf.catalog.data.Metacard)37 Test (org.junit.Test)36 ContentItemImpl (ddf.catalog.content.data.impl.ContentItemImpl)27 ArrayList (java.util.ArrayList)22 CreateStorageResponse (ddf.catalog.content.operation.CreateStorageResponse)20 HashMap (java.util.HashMap)19 URI (java.net.URI)17 ByteSource (com.google.common.io.ByteSource)16 CreateStorageRequestImpl (ddf.catalog.content.operation.impl.CreateStorageRequestImpl)16 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)15 IOException (java.io.IOException)14 UpdateStorageRequest (ddf.catalog.content.operation.UpdateStorageRequest)13 StorageException (ddf.catalog.content.StorageException)12 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)12 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)11 InputStream (java.io.InputStream)11 Map (java.util.Map)11 StorageProvider (ddf.catalog.content.StorageProvider)10 UpdateStorageResponse (ddf.catalog.content.operation.UpdateStorageResponse)10