Search in sources :

Example 21 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);
    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 22 with AttributeDescriptorImpl

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

the class MetacardTypeRegistryTest method sampleMetacardTypeB.

private QualifiedMetacardType sampleMetacardTypeB() {
    Set<AttributeDescriptor> descriptors = new HashSet<AttributeDescriptor>();
    descriptors.add(new AttributeDescriptorImpl(COLUMNS_ATTRIBUTE_KEY, true, /* indexed */
    true, /* stored */
    false, /* tokenized */
    false, /* multivalued */
    BasicTypes.INTEGER_TYPE));
    descriptors.add(new AttributeDescriptorImpl(ROWS_ATTRIBUTE_KEY, true, /* indexed */
    true, /* stored */
    false, /* tokenized */
    false, /* multivalued */
    BasicTypes.INTEGER_TYPE));
    descriptors.add(new AttributeDescriptorImpl(DESCRIPTION_ATTRIBUTE_KEY, true, /* indexed */
    true, /* stored */
    false, /* tokenized */
    false, /* multivalued */
    BasicTypes.STRING_TYPE));
    descriptors.add(new AttributeDescriptorImpl(Metacard.ID, true, /* indexed */
    true, /* stored */
    false, /* tokenized */
    false, /* multivalued */
    BasicTypes.STRING_TYPE));
    descriptors.add(new AttributeDescriptorImpl(Metacard.TITLE, true, /* indexed */
    true, /* stored */
    true, /* tokenized */
    false, /* multivalued */
    BasicTypes.STRING_TYPE));
    descriptors.add(new AttributeDescriptorImpl(REVIEWED_ATTRIBUTE_KEY, true, /* indexed */
    true, /* stored */
    true, /* tokenized */
    false, /* multivalued */
    BasicTypes.BOOLEAN_TYPE));
    descriptors.add(new AttributeDescriptorImpl(PRECISE_LENGTH_METERS_ATTRIBUTE_KEY, true, /* indexed */
    true, /* stored */
    true, /* tokenized */
    false, /* multivalued */
    BasicTypes.DOUBLE_TYPE));
    descriptors.add(new AttributeDescriptorImpl(PRECISE_HEIGHT_METERS_ATTRIBUTE_KEY, true, /* indexed */
    true, /* stored */
    true, /* tokenized */
    false, /* multivalued */
    BasicTypes.FLOAT_TYPE));
    descriptors.add(new AttributeDescriptorImpl(NUMBER_REVIEWERS_ATTRIBUTE_KEY, true, /* indexed */
    true, /* stored */
    true, /* tokenized */
    false, /* multivalued */
    BasicTypes.SHORT_TYPE));
    return new QualifiedMetacardTypeImpl(SAMPLE_B_METACARD_TYPE_NAMESPACE, SAMPLE_B_METACARD_TYPE_NAME, descriptors);
}
Also used : QualifiedMetacardTypeImpl(ddf.catalog.data.impl.QualifiedMetacardTypeImpl) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) AttributeDescriptorImpl(ddf.catalog.data.impl.AttributeDescriptorImpl) HashSet(java.util.HashSet)

Example 23 with AttributeDescriptorImpl

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

the class SolrProviderTest method testExtensibleMetacards.

@Test
public void testExtensibleMetacards() throws IngestException, UnsupportedQueryException {
    deleteAllIn(provider);
    String brandNewField1 = "description";
    String brandNewFieldValue1 = "myDescription";
    /* BASIC STRINGS */
    Set<AttributeDescriptor> descriptors = new HashSet<AttributeDescriptor>();
    descriptors.add(new AttributeDescriptorImpl(Metacard.ID, true, true, true, false, BasicTypes.STRING_TYPE));
    descriptors.add(new AttributeDescriptorImpl(brandNewField1, true, true, true, false, BasicTypes.STRING_TYPE));
    MetacardTypeImpl mType = new MetacardTypeImpl("custom1", descriptors);
    MetacardImpl customMetacard = new MetacardImpl(mType);
    // customMetacard.setAttribute("id", "44567880");
    customMetacard.setAttribute(brandNewField1, brandNewFieldValue1);
    create(customMetacard);
    // search id
    Query query = new QueryImpl(filterBuilder.attribute("id").like().text("*"));
    QueryRequest request = new QueryRequestImpl(query);
    SourceResponse response = provider.query(request);
    assertEquals(1, response.getResults().size());
    assertEquals("custom1", response.getResults().get(0).getMetacard().getMetacardType().getName());
    assertThat(response.getResults().get(0).getMetacard().getMetacardType().getAttributeDescriptors(), equalTo(descriptors));
    // search title - *
    query = new QueryImpl(filterBuilder.attribute(brandNewField1).like().text("*"));
    request = new QueryRequestImpl(query);
    response = provider.query(request);
    assertEquals(1, response.getResults().size());
    assertEquals("custom1", response.getResults().get(0).getMetacard().getMetacardType().getName());
    assertThat(response.getResults().get(0).getMetacard().getMetacardType().getAttributeDescriptors(), equalTo(descriptors));
    // search title - exact
    query = new QueryImpl(filterBuilder.attribute(brandNewField1).equalTo().text(brandNewFieldValue1));
    request = new QueryRequestImpl(query);
    response = provider.query(request);
    assertEquals(1, response.getResults().size());
    // search negative
    query = new QueryImpl(filterBuilder.attribute(brandNewField1).like().text("no"));
    request = new QueryRequestImpl(query);
    response = provider.query(request);
    assertEquals(0, response.getResults().size());
    // NEW TYPE
    String brandNewXmlField1 = "author";
    String brandNewXmlFieldValue1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" + "<author>john doe</author>";
    descriptors = new HashSet<AttributeDescriptor>();
    descriptors.add(new AttributeDescriptorImpl(Metacard.ID, true, true, true, false, BasicTypes.STRING_TYPE));
    descriptors.add(new AttributeDescriptorImpl(brandNewXmlField1, true, true, true, false, BasicTypes.XML_TYPE));
    mType = new MetacardTypeImpl("34ga$^TGHfg:/", descriptors);
    customMetacard = new MetacardImpl(mType);
    // customMetacard.setAttribute(Metacard.ID, "44567880");
    customMetacard.setAttribute(brandNewXmlField1, brandNewXmlFieldValue1);
    create(customMetacard);
    // Two Ids
    query = new QueryImpl(filterBuilder.attribute(Metacard.ID).like().text("*"));
    request = new QueryRequestImpl(query);
    response = provider.query(request);
    assertEquals(2, response.getResults().size());
    // search xml
    query = new QueryImpl(filterBuilder.attribute(brandNewXmlField1).like().caseSensitiveText("doe"));
    request = new QueryRequestImpl(query);
    response = provider.query(request);
    assertEquals(1, response.getResults().size());
    assertEquals("34ga$^TGHfg:/", response.getResults().get(0).getMetacard().getMetacardType().getName());
    assertThat(response.getResults().get(0).getMetacard().getMetacardType().getAttributeDescriptors(), equalTo(descriptors));
    // search xml - negative
    query = new QueryImpl(filterBuilder.attribute(brandNewXmlField1).like().text("author"));
    request = new QueryRequestImpl(query);
    response = provider.query(request);
    assertEquals(0, response.getResults().size());
    // EVERYTHING ELSE type
    String doubleField = "hertz";
    double doubleFieldValue = 16065.435;
    String floatField = "inches";
    float floatFieldValue = 4.435f;
    String intField = "count";
    int intFieldValue = 4;
    String longField = "milliseconds";
    long longFieldValue = 987654322111L;
    String byteField = "bytes";
    byte[] byteFieldValue = { 86 };
    String booleanField = "expected";
    boolean booleanFieldValue = true;
    String dateField = "lost";
    Date dateFieldValue = new Date();
    String geoField = "geo";
    String geoFieldValue = GULF_OF_GUINEA_POINT_WKT;
    String shortField = "daysOfTheWeek";
    short shortFieldValue = 1;
    String objectField = "payload";
    BevelBorder objectFieldValue = new BevelBorder(BevelBorder.RAISED);
    descriptors = new HashSet<AttributeDescriptor>();
    descriptors.add(new AttributeDescriptorImpl(Metacard.ID, true, true, true, false, BasicTypes.STRING_TYPE));
    descriptors.add(new AttributeDescriptorImpl(doubleField, true, true, false, false, BasicTypes.DOUBLE_TYPE));
    descriptors.add(new AttributeDescriptorImpl(floatField, true, true, false, false, BasicTypes.FLOAT_TYPE));
    descriptors.add(new AttributeDescriptorImpl(intField, true, true, false, false, BasicTypes.INTEGER_TYPE));
    descriptors.add(new AttributeDescriptorImpl(longField, true, true, false, false, BasicTypes.LONG_TYPE));
    descriptors.add(new AttributeDescriptorImpl(byteField, false, true, false, false, BasicTypes.BINARY_TYPE));
    descriptors.add(new AttributeDescriptorImpl(booleanField, true, true, false, false, BasicTypes.BOOLEAN_TYPE));
    descriptors.add(new AttributeDescriptorImpl(dateField, true, true, false, false, BasicTypes.DATE_TYPE));
    descriptors.add(new AttributeDescriptorImpl(geoField, true, true, false, false, BasicTypes.GEO_TYPE));
    descriptors.add(new AttributeDescriptorImpl(shortField, true, true, false, false, BasicTypes.SHORT_TYPE));
    descriptors.add(new AttributeDescriptorImpl(objectField, false, true, false, false, BasicTypes.OBJECT_TYPE));
    mType = new MetacardTypeImpl("numbersMT", descriptors);
    customMetacard = new MetacardImpl(mType);
    // customMetacard.setAttribute(Metacard.ID, "245gasg324");
    customMetacard.setAttribute(doubleField, doubleFieldValue);
    customMetacard.setAttribute(floatField, floatFieldValue);
    customMetacard.setAttribute(intField, intFieldValue);
    customMetacard.setAttribute(longField, longFieldValue);
    customMetacard.setAttribute(byteField, byteFieldValue);
    customMetacard.setAttribute(booleanField, booleanFieldValue);
    customMetacard.setAttribute(dateField, dateFieldValue);
    customMetacard.setAttribute(geoField, geoFieldValue);
    customMetacard.setAttribute(shortField, shortFieldValue);
    customMetacard.setAttribute(objectField, objectFieldValue);
    create(customMetacard);
    // Three Ids
    query = new QueryImpl(filterBuilder.attribute(Metacard.ID).like().text("*"));
    request = new QueryRequestImpl(query);
    response = provider.query(request);
    assertEquals(3, response.getResults().size());
    // search double
    query = new QueryImpl(filterBuilder.attribute(doubleField).greaterThan().number(doubleFieldValue - 1.0));
    request = new QueryRequestImpl(query);
    response = provider.query(request);
    assertEquals(1, response.getResults().size());
    // search int
    query = new QueryImpl(filterBuilder.attribute(intField).greaterThan().number(intFieldValue - 1));
    request = new QueryRequestImpl(query);
    response = provider.query(request);
    assertEquals(1, response.getResults().size());
    Metacard resultMetacard = response.getResults().get(0).getMetacard();
    assertThat(resultMetacard.getAttribute(Metacard.ID), notNullValue());
    assertThat((Double) (resultMetacard.getAttribute(doubleField).getValue()), equalTo(doubleFieldValue));
    assertThat((Integer) (resultMetacard.getAttribute(intField).getValue()), equalTo(intFieldValue));
    assertThat((Float) (resultMetacard.getAttribute(floatField).getValue()), equalTo(floatFieldValue));
    assertThat((Long) (resultMetacard.getAttribute(longField).getValue()), equalTo(longFieldValue));
    assertThat((byte[]) (resultMetacard.getAttribute(byteField).getValue()), equalTo(byteFieldValue));
    assertThat((Boolean) (resultMetacard.getAttribute(booleanField).getValue()), equalTo(booleanFieldValue));
    assertThat((Date) (resultMetacard.getAttribute(dateField).getValue()), equalTo(dateFieldValue));
    assertThat((String) (resultMetacard.getAttribute(geoField).getValue()), equalTo(geoFieldValue));
    assertThat((Short) (resultMetacard.getAttribute(shortField).getValue()), equalTo(shortFieldValue));
    assertThat((BevelBorder) (resultMetacard.getAttribute(objectField).getValue()), instanceOf(BevelBorder.class));
    /*
         * Going to use the XMLEncoder. If it writes out the objects the same way in xml, then they
         * are the same.
         */
    ByteArrayOutputStream beveledBytesStreamFromSolr = new ByteArrayOutputStream();
    XMLEncoder solrXMLEncoder = new XMLEncoder(new BufferedOutputStream(beveledBytesStreamFromSolr));
    solrXMLEncoder.writeObject((resultMetacard.getAttribute(objectField).getValue()));
    solrXMLEncoder.close();
    ByteArrayOutputStream beveledBytesStreamOriginal = new ByteArrayOutputStream();
    XMLEncoder currendEncoder = new XMLEncoder(new BufferedOutputStream(beveledBytesStreamOriginal));
    currendEncoder.writeObject(objectFieldValue);
    currendEncoder.close();
    assertThat(beveledBytesStreamFromSolr.toByteArray(), equalTo(beveledBytesStreamOriginal.toByteArray()));
    // search short
    query = new QueryImpl(filterBuilder.attribute(shortField).greaterThanOrEqualTo().number(shortFieldValue));
    request = new QueryRequestImpl(query);
    response = provider.query(request);
    assertEquals(1, response.getResults().size());
    resultMetacard = response.getResults().get(0).getMetacard();
}
Also used : Query(ddf.catalog.operation.Query) BevelBorder(javax.swing.border.BevelBorder) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) Matchers.containsString(org.hamcrest.Matchers.containsString) QueryImpl(ddf.catalog.operation.impl.QueryImpl) BufferedOutputStream(java.io.BufferedOutputStream) HashSet(java.util.HashSet) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) AttributeDescriptorImpl(ddf.catalog.data.impl.AttributeDescriptorImpl) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Date(java.util.Date) Metacard(ddf.catalog.data.Metacard) XMLEncoder(java.beans.XMLEncoder) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Test(org.junit.Test)

Example 24 with AttributeDescriptorImpl

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

the class SolrProviderTest method numericalDescriptors.

private Set<AttributeDescriptor> numericalDescriptors(String doubleField, String floatField, String intField, String longField, String shortField) {
    Set<AttributeDescriptor> descriptors = new HashSet<AttributeDescriptor>();
    descriptors.add(new AttributeDescriptorImpl(Metacard.ID, true, true, true, false, BasicTypes.STRING_TYPE));
    descriptors.add(new AttributeDescriptorImpl(doubleField, true, true, true, false, BasicTypes.DOUBLE_TYPE));
    descriptors.add(new AttributeDescriptorImpl(floatField, true, true, true, false, BasicTypes.FLOAT_TYPE));
    descriptors.add(new AttributeDescriptorImpl(intField, true, true, true, false, BasicTypes.INTEGER_TYPE));
    descriptors.add(new AttributeDescriptorImpl(longField, true, true, true, false, BasicTypes.LONG_TYPE));
    descriptors.add(new AttributeDescriptorImpl(shortField, true, true, true, false, BasicTypes.SHORT_TYPE));
    return descriptors;
}
Also used : AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) AttributeDescriptorImpl(ddf.catalog.data.impl.AttributeDescriptorImpl) HashSet(java.util.HashSet)

Example 25 with AttributeDescriptorImpl

use of ddf.catalog.data.impl.AttributeDescriptorImpl 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)

Aggregations

AttributeDescriptorImpl (ddf.catalog.data.impl.AttributeDescriptorImpl)25 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)23 HashSet (java.util.HashSet)18 Metacard (ddf.catalog.data.Metacard)13 Test (org.junit.Test)13 MetacardTypeImpl (ddf.catalog.data.impl.MetacardTypeImpl)12 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)10 MetacardType (ddf.catalog.data.MetacardType)7 QueryImpl (ddf.catalog.operation.impl.QueryImpl)5 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)5 Matchers.anyString (org.mockito.Matchers.anyString)5 ByteSource (com.google.common.io.ByteSource)4 ContentItem (ddf.catalog.content.data.ContentItem)4 ContentItemImpl (ddf.catalog.content.data.impl.ContentItemImpl)4 CreateStorageRequestImpl (ddf.catalog.content.operation.impl.CreateStorageRequestImpl)4 CreateResponse (ddf.catalog.operation.CreateResponse)4 SourceResponse (ddf.catalog.operation.SourceResponse)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Metadata (org.apache.tika.metadata.Metadata)4