Search in sources :

Example 61 with MetacardType

use of ddf.catalog.data.MetacardType 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) Matchers.anyString(org.mockito.Matchers.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 62 with MetacardType

use of ddf.catalog.data.MetacardType 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);
    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) ArrayList(java.util.ArrayList) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) Matchers.anyString(org.mockito.Matchers.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 63 with MetacardType

use of ddf.catalog.data.MetacardType in project ddf by codice.

the class TestGenericFeatureConverter method testMetacardCollectionToFeatureCollectionXml.

@Test
public void testMetacardCollectionToFeatureCollectionXml() {
    XStream xstream = new XStream(new EnhancedStaxDriver());
    xstream.setMode(XStream.NO_REFERENCES);
    xstream.registerConverter(new FeatureCollectionConverterWfs20());
    xstream.registerConverter(new GenericFeatureConverterWfs20());
    xstream.registerConverter(new GmlGeometryConverter());
    // Required the Implementing class. The interface would not work...
    xstream.alias(Wfs20Constants.WFS_NAMESPACE_PREFIX + ":" + "FeatureCollection", Wfs20FeatureCollection.class);
    Metacard mc = new SampleMetacard().getMetacard();
    Wfs20FeatureCollection wfc = new Wfs20FeatureCollection();
    wfc.getMembers().add(mc);
    MetacardImpl mc2 = new SampleMetacard().getMetacard();
    // Ignore the hack stuff, this was just to imitate having two different
    // "MetacardTypes"
    mc2.setType(new MetacardType() {

        @Override
        public String getName() {
            return "otherType";
        }

        @Override
        public Set<AttributeDescriptor> getAttributeDescriptors() {
            return BasicTypes.BASIC_METACARD.getAttributeDescriptors();
        }

        @Override
        public AttributeDescriptor getAttributeDescriptor(String arg0) {
            return BasicTypes.BASIC_METACARD.getAttributeDescriptor(arg0);
        }
    });
    wfc.getMembers().add(mc2);
    String xml = xstream.toXML(wfc);
}
Also used : Set(java.util.Set) GmlGeometryConverter(org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GmlGeometryConverter) XStream(com.thoughtworks.xstream.XStream) Wfs20FeatureCollection(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs20FeatureCollection) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) MetacardType(ddf.catalog.data.MetacardType) FeatureMetacardType(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType) Metacard(ddf.catalog.data.Metacard) EnhancedStaxDriver(org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.EnhancedStaxDriver) Test(org.junit.Test)

Example 64 with MetacardType

use of ddf.catalog.data.MetacardType in project ddf by codice.

the class TestGenericFeatureConverter method testUnmarshalSingleFeatureXmlToObject.

@Test
//DDF-733
@Ignore
public void testUnmarshalSingleFeatureXmlToObject() {
    XStream xstream = new XStream(new WstxDriver());
    MetacardType metacardType = buildMetacardType();
    GenericFeatureConverterWfs20 converter = new GenericFeatureConverterWfs20();
    converter.setMetacardType(buildMetacardType());
    converter.setSourceId(SOURCE_ID);
    converter.setCoordinateOrder(GeospatialUtil.LAT_LON_ORDER);
    xstream.registerConverter(converter);
    xstream.registerConverter(new GmlGeometryConverter());
    xstream.alias(FEATURE_TYPE, MetacardImpl.class);
    InputStream is = TestGenericFeatureConverter.class.getResourceAsStream("/video_data_set.xml");
    Metacard mc = (Metacard) xstream.fromXML(is);
    assertEquals("video_data_set.2", mc.getId());
    assertEquals(FEATURE_TYPE, mc.getContentTypeName());
    assertEquals(metacardType.getName(), mc.getMetacardType().getName());
    assertEquals(SOURCE_ID, mc.getSourceId());
    assertEquals("video_data_set.2", mc.getTitle());
    assertEquals(2L, mc.getAttribute(PROPERTY_PREFIX + ID_ELEMENT).getValue());
    assertEquals(Long.valueOf(1L), mc.getAttribute(PROPERTY_PREFIX + VERSION_ELEMENT).getValue());
    assertEquals(DatatypeConverter.parseDateTime("2005-04-07T09:54:38.983").getTime(), mc.getAttribute(PROPERTY_PREFIX + END_DATE_ELEMENT).getValue());
    assertEquals("/data/test_suite/video/video/videoFile.mpg", mc.getAttribute(PROPERTY_PREFIX + FILENAME_ELEMENT).getValue());
    assertEquals(720L, mc.getAttribute(PROPERTY_PREFIX + HEIGHT_ELEMENT).getValue());
    assertEquals("a8a55092f0afae881099637ef7746cd8d7066270d9af4cf0f52c41dab53c4005", mc.getAttribute(PROPERTY_PREFIX + INDEX_ID_ELEMENT).getValue());
    assertEquals(getOtherTagsXml(), mc.getAttribute(PROPERTY_PREFIX + OTHER_TAGS_XML_ELEMENT).getValue());
    assertEquals(26L, mc.getAttribute(PROPERTY_PREFIX + REPOSITORY_ID_ELEMENT).getValue());
    assertEquals(DatatypeConverter.parseDateTime("2005-04-07T09:53:39.000").getTime(), mc.getAttribute(PROPERTY_PREFIX + START_DATE_ELEMENT).getValue());
    assertEquals(1280L, mc.getAttribute(PROPERTY_PREFIX + WIDTH_ELEMENT).getValue());
    assertEquals(getLocation(), mc.getLocation());
    assertEquals(mc.getLocation(), mc.getAttribute(PROPERTY_PREFIX + GROUND_GEOM_ELEMENT).getValue());
    assertNotNull(mc.getCreatedDate());
    assertNotNull(mc.getEffectiveDate());
    assertNotNull(mc.getModifiedDate());
    assertNotNull(mc.getContentTypeNamespace());
    assertEquals(mc.getContentTypeNamespace().toString(), Wfs20Constants.NAMESPACE_URN_ROOT + metacardType.getName());
}
Also used : WstxDriver(com.thoughtworks.xstream.io.xml.WstxDriver) Metacard(ddf.catalog.data.Metacard) GmlGeometryConverter(org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GmlGeometryConverter) XStream(com.thoughtworks.xstream.XStream) InputStream(java.io.InputStream) MetacardType(ddf.catalog.data.MetacardType) FeatureMetacardType(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 65 with MetacardType

use of ddf.catalog.data.MetacardType in project ddf by codice.

the class AttributeRegistryImplTest method testDeregisterMetacardType.

@Test
public void testDeregisterMetacardType() {
    MetacardType metacardType = generateMetacardType();
    registry.deregisterMetacardType(generateMetacardType());
    metacardType.getAttributeDescriptors().forEach(attributeDescriptor -> assertThat(registry.lookup(attributeDescriptor.getName()).isPresent(), is(false)));
}
Also used : MetacardType(ddf.catalog.data.MetacardType) Test(org.junit.Test)

Aggregations

MetacardType (ddf.catalog.data.MetacardType)88 Test (org.junit.Test)57 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)41 Metacard (ddf.catalog.data.Metacard)35 ArrayList (java.util.ArrayList)29 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)20 MetacardTypeImpl (ddf.catalog.data.impl.MetacardTypeImpl)17 HashSet (java.util.HashSet)15 Attribute (ddf.catalog.data.Attribute)12 Serializable (java.io.Serializable)10 IOException (java.io.IOException)8 Date (java.util.Date)8 HashMap (java.util.HashMap)8 List (java.util.List)8 Map (java.util.Map)8 AttributeDescriptorImpl (ddf.catalog.data.impl.AttributeDescriptorImpl)7 InputStream (java.io.InputStream)7 Set (java.util.Set)7 ContentItem (ddf.catalog.content.data.ContentItem)6 ContentItemImpl (ddf.catalog.content.data.impl.ContentItemImpl)6