Search in sources :

Example 36 with AttributeDescriptorImpl

use of ddf.catalog.data.impl.AttributeDescriptorImpl in project ddf by codice.

the class CatalogFrameworkImplTest method testInjectsAttributesOnCreate.

@Test
public void testInjectsAttributesOnCreate() throws Exception {
    final String title = "Create";
    final String injectAttributeName = "new attribute";
    final double injectAttributeValue = 2;
    final MetacardImpl originalMetacard = new MetacardImpl();
    originalMetacard.setTitle(title);
    originalMetacard.setAttribute(injectAttributeName, injectAttributeValue);
    final List<Metacard> metacards = Collections.singletonList(originalMetacard);
    final CreateRequest request = new CreateRequestImpl(metacards, null);
    final AttributeDescriptor injectAttribute = new AttributeDescriptorImpl(injectAttributeName, true, true, false, false, BasicTypes.DOUBLE_TYPE);
    stubMetacardInjection(injectAttribute);
    final CreateResponse response = framework.create(request);
    final Metacard createdMetacard = response.getCreatedMetacards().get(0);
    final MetacardType createdMetacardType = createdMetacard.getMetacardType();
    final MetacardType originalMetacardType = originalMetacard.getMetacardType();
    assertThat(createdMetacardType.getName(), is(originalMetacardType.getName()));
    final Set<AttributeDescriptor> expectedAttributeDescriptors = new HashSet<>(originalMetacardType.getAttributeDescriptors());
    expectedAttributeDescriptors.add(injectAttribute);
    assertThat(createdMetacardType.getAttributeDescriptors(), is(expectedAttributeDescriptors));
    assertThat(createdMetacard.getTitle(), is(title));
    assertThat(createdMetacard.getAttribute(injectAttributeName).getValue(), is(injectAttributeValue));
}
Also used : CreateRequest(ddf.catalog.operation.CreateRequest) CreateResponse(ddf.catalog.operation.CreateResponse) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AttributeDescriptorImpl(ddf.catalog.data.impl.AttributeDescriptorImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) MetacardType(ddf.catalog.data.MetacardType) Metacard(ddf.catalog.data.Metacard) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 37 with AttributeDescriptorImpl

use of ddf.catalog.data.impl.AttributeDescriptorImpl in project ddf by codice.

the class CatalogFrameworkImplTest method testCreateStorageWithAttributeOverrides.

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

        private static final long serialVersionUID = 1L;

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

        @Override
        public AttributeFormat getAttributeFormat() {
            return AttributeFormat.STRING;
        }
    });
    when(metacardType.getAttributeDescriptor(Metacard.TITLE)).thenReturn(stringAttributeDescriptor);
    when(metacardType.getAttributeDescriptors()).thenReturn(Collections.singleton(new CoreAttributes().getAttributeDescriptor(Core.TITLE)));
    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 valid attribute is set for the metacard
        assertThat(curCard.getTitle(), is("test"));
        // Assert invalid attribute is not set for the metacard
        assertThat(curCard.getAttribute("foo"), nullValue());
    }
    // Assert That Attribute Overrides do not exist after create
    assertThat(attributeMap.get(Constants.ATTRIBUTE_OVERRIDES_KEY), nullValue());
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) CreateResponse(ddf.catalog.operation.CreateResponse) CoreAttributes(ddf.catalog.data.impl.types.CoreAttributes) ArrayList(java.util.ArrayList) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AttributeDescriptorImpl(ddf.catalog.data.impl.AttributeDescriptorImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) MetacardType(ddf.catalog.data.MetacardType) Metacard(ddf.catalog.data.Metacard) ByteArrayInputStream(java.io.ByteArrayInputStream) CreateStorageRequestImpl(ddf.catalog.content.operation.impl.CreateStorageRequestImpl) ByteSource(com.google.common.io.ByteSource) ContentItem(ddf.catalog.content.data.ContentItem) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl) Test(org.junit.Test)

Example 38 with AttributeDescriptorImpl

use of ddf.catalog.data.impl.AttributeDescriptorImpl in project ddf by codice.

the class CatalogFrameworkImplTest method testInjectsAttributesOnQuery.

@Test
public void testInjectsAttributesOnQuery() throws Exception {
    final Metacard original = new MetacardImpl();
    final String id = framework.create(new CreateRequestImpl(Collections.singletonList(original), null)).getCreatedMetacards().get(0).getId();
    final AttributeDescriptor injectAttribute = new AttributeDescriptorImpl("new attribute", true, true, false, false, BasicTypes.DOUBLE_TYPE);
    stubMetacardInjection(injectAttribute);
    final FilterFactory filterFactory = new FilterFactoryImpl();
    final Filter filter = filterFactory.equals(filterFactory.property(Metacard.ID), filterFactory.literal(id));
    final QueryRequest request = new QueryRequestImpl(new QueryImpl(filter));
    final QueryResponse response = framework.query(request);
    final Metacard queryMetacard = response.getResults().get(0).getMetacard();
    final MetacardType originalMetacardType = original.getMetacardType();
    final MetacardType queryMetacardType = queryMetacard.getMetacardType();
    assertThat(originalMetacardType.getName(), is(queryMetacardType.getName()));
    final Set<AttributeDescriptor> expectedAttributeDescriptors = new HashSet<>(originalMetacardType.getAttributeDescriptors());
    expectedAttributeDescriptors.add(injectAttribute);
    assertThat(queryMetacardType.getAttributeDescriptors(), is(expectedAttributeDescriptors));
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AttributeDescriptorImpl(ddf.catalog.data.impl.AttributeDescriptorImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) FilterFactory(org.opengis.filter.FilterFactory) MetacardType(ddf.catalog.data.MetacardType) Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 39 with AttributeDescriptorImpl

use of ddf.catalog.data.impl.AttributeDescriptorImpl in project ddf by codice.

the class GetRecordsResponseConverterTest method createMetacardList.

private List<Metacard> createMetacardList(int start, int finish) {
    List<Metacard> list = new LinkedList<>();
    for (int i = start; i <= finish; i++) {
        MetacardImpl metacard = new MetacardImpl();
        metacard.setId(ID_PREFIX + i);
        metacard.setSourceId(SOURCE_PREFIX + i);
        metacard.setTitle(TITLE_PREFIX + i);
        // for testing an attribute with multiple values
        AttributeDescriptor ad = new AttributeDescriptorImpl(FORMAT, true, true, true, true, BasicTypes.STRING_TYPE);
        Set<AttributeDescriptor> ads = new HashSet<>(metacard.getMetacardType().getAttributeDescriptors());
        ads.add(ad);
        metacard.setType(new MetacardTypeImpl("test", ads));
        metacard.setLocation(WKT);
        AttributeImpl attr = new AttributeImpl(FORMAT, FORMAT);
        attr.addValue(FORMAT);
        metacard.setAttribute(attr);
        // for testing an attribute with no attribute descriptor
        metacard.setAttribute(RELATION, RELATION);
        list.add(metacard);
    }
    return list;
}
Also used : Metacard(ddf.catalog.data.Metacard) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) AttributeDescriptorImpl(ddf.catalog.data.impl.AttributeDescriptorImpl) LinkedList(java.util.LinkedList) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) HashSet(java.util.HashSet)

Example 40 with AttributeDescriptorImpl

use of ddf.catalog.data.impl.AttributeDescriptorImpl in project ddf by codice.

the class GeoJsonMetacardTransformerTest method testWithMultiValueAttributes.

@Test
public void testWithMultiValueAttributes() throws Exception {
    Set<AttributeDescriptor> descriptors = new HashSet(MetacardImpl.BASIC_METACARD.getAttributeDescriptors());
    descriptors.add(new AttributeDescriptorImpl("multi-string", true, true, false, true, /* multivalued */
    BasicTypes.STRING_TYPE));
    MetacardType type = new MetacardTypeImpl("multi", descriptors);
    MetacardImpl metacard = new MetacardImpl(type);
    metacard.setAttribute("multi-string", (Serializable) Arrays.asList("foo", "bar"));
    GeoJsonMetacardTransformer transformer = new GeoJsonMetacardTransformer();
    BinaryContent content = transformer.transform(metacard, null);
    String jsonText = new String(content.getByteArray());
    JSONObject json = (JSONObject) PARSER.parse(jsonText);
    Map properties = (Map) json.get("properties");
    List<String> strings = (List<String>) properties.get("multi-string");
    assertThat(strings.get(0), is("foo"));
    assertThat(strings.get(1), is("bar"));
}
Also used : AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) AttributeDescriptorImpl(ddf.catalog.data.impl.AttributeDescriptorImpl) LineString(ddf.geo.formatter.LineString) MultiLineString(ddf.geo.formatter.MultiLineString) BinaryContent(ddf.catalog.data.BinaryContent) MetacardType(ddf.catalog.data.MetacardType) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) JSONObject(org.json.simple.JSONObject) List(java.util.List) Map(java.util.Map) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

AttributeDescriptorImpl (ddf.catalog.data.impl.AttributeDescriptorImpl)44 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)34 HashSet (java.util.HashSet)26 MetacardTypeImpl (ddf.catalog.data.impl.MetacardTypeImpl)24 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)19 Test (org.junit.Test)19 Metacard (ddf.catalog.data.Metacard)17 MetacardType (ddf.catalog.data.MetacardType)11 ArrayList (java.util.ArrayList)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 SourceResponse (ddf.catalog.operation.SourceResponse)6 QueryImpl (ddf.catalog.operation.impl.QueryImpl)6 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)6 Before (org.junit.Before)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Metadata (org.apache.tika.metadata.Metadata)5 Filter (org.opengis.filter.Filter)5 ByteSource (com.google.common.io.ByteSource)4