Search in sources :

Example 21 with AttributeDescriptor

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

the class DynamicSchemaResolver method convertAttributeDescriptors.

private Set<AttributeDescriptor> convertAttributeDescriptors(Set<AttributeDescriptor> attributeDescriptors) {
    Set<AttributeDescriptor> newAttributeDescriptors = new HashSet<>(attributeDescriptors.size());
    for (AttributeDescriptor attributeDescriptor : attributeDescriptors) {
        String name = attributeDescriptor.getName();
        boolean isIndexed = attributeDescriptor.isIndexed();
        boolean isStored = attributeDescriptor.isStored();
        boolean isTokenized = attributeDescriptor.isTokenized();
        boolean isMultiValued = attributeDescriptor.isMultiValued();
        AttributeType<?> attributeType = attributeDescriptor.getType();
        newAttributeDescriptors.add(new AttributeDescriptorImpl(name, isIndexed, isStored, isTokenized, isMultiValued, attributeType));
    }
    return newAttributeDescriptors;
}
Also used : AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) AttributeDescriptorImpl(ddf.catalog.data.impl.AttributeDescriptorImpl) HashSet(java.util.HashSet)

Example 22 with AttributeDescriptor

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

the class DynamicSchemaResolver method addToFieldsCache.

private void addToFieldsCache(Set<AttributeDescriptor> descriptors) {
    for (AttributeDescriptor ad : descriptors) {
        AttributeFormat format = ad.getType().getAttributeFormat();
        fieldsCache.add(ad.getName() + schemaFields.getFieldSuffix(format));
        if (!getSpecialIndexSuffix(format).equals("")) {
            fieldsCache.add(ad.getName() + schemaFields.getFieldSuffix(format) + getSpecialIndexSuffix(format));
        }
        if (format.equals(AttributeFormat.STRING)) {
            fieldsCache.add(ad.getName() + schemaFields.getFieldSuffix(format) + getSpecialIndexSuffix(format) + SchemaFields.HAS_CASE);
            anyTextFieldsCache.add(ad.getName() + schemaFields.getFieldSuffix(format));
        }
        if (format.equals(AttributeFormat.XML)) {
            fieldsCache.add(ad.getName() + SchemaFields.TEXT_SUFFIX + SchemaFields.TOKENIZED);
            fieldsCache.add(ad.getName() + SchemaFields.TEXT_SUFFIX + SchemaFields.TOKENIZED + SchemaFields.HAS_CASE);
            fieldsCache.add(ad.getName() + schemaFields.getFieldSuffix(format) + getSpecialIndexSuffix(format));
        }
    }
}
Also used : AttributeFormat(ddf.catalog.data.AttributeType.AttributeFormat) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor)

Example 23 with AttributeDescriptor

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

the class TestMetacardGroomerPlugin method copy.

private Metacard copy(Metacard inputMetacard) {
    MetacardImpl newMetacard = new MetacardImpl(getHybridMetacardType());
    newMetacard.setSourceId(inputMetacard.getSourceId());
    newMetacard.setType(inputMetacard.getMetacardType());
    for (AttributeDescriptor ad : inputMetacard.getMetacardType().getAttributeDescriptors()) {
        newMetacard.setAttribute(inputMetacard.getAttribute(ad.getName()));
    }
    return newMetacard;
}
Also used : AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) MetacardImpl(ddf.catalog.data.impl.MetacardImpl)

Example 24 with AttributeDescriptor

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

the class DynamicSchemaResolverTest method testAddFields.

/**
     * Verify that when a metacard type has attribute descriptors that inherit from AttributeDescriptorImpl, the attribute
     * descriptors are recreated as AttributeDescriptorsImpls before serialization into the solr cache.
     */
@Test
public void testAddFields() throws Exception {
    // Setup
    String metacardTypeName = "states";
    Set<AttributeDescriptor> addtributeDescriptors = new HashSet<AttributeDescriptor>(1);
    String propertyName = "title";
    String name = metacardTypeName + "." + propertyName;
    boolean indexed = true;
    boolean stored = true;
    boolean tokenized = false;
    boolean multiValued = false;
    addtributeDescriptors.add(new AttributeDescriptorImplTest(name, propertyName, indexed, stored, tokenized, multiValued, BasicTypes.OBJECT_TYPE));
    Serializable mockValue = mock(Serializable.class);
    Attribute mockAttribute = mock(Attribute.class);
    when(mockAttribute.getValue()).thenReturn(mockValue);
    Metacard mockMetacard = mock(Metacard.class, RETURNS_DEEP_STUBS);
    when(mockMetacard.getMetacardType().getName()).thenReturn(metacardTypeName);
    when(mockMetacard.getMetacardType().getAttributeDescriptors()).thenReturn(addtributeDescriptors);
    when(mockMetacard.getAttribute(name)).thenReturn(mockAttribute);
    ArgumentCaptor<byte[]> metacardTypeBytes = ArgumentCaptor.forClass(byte[].class);
    SolrInputDocument mockSolrInputDocument = mock(SolrInputDocument.class);
    DynamicSchemaResolver resolver = new DynamicSchemaResolver();
    // Perform Test
    resolver.addFields(mockMetacard, mockSolrInputDocument);
    // Verify: Verify that TestAttributeDescritorImpl has been recreated as a AttributeDescriptorImpl.
    verify(mockSolrInputDocument).addField(eq(SchemaFields.METACARD_TYPE_OBJECT_FIELD_NAME), metacardTypeBytes.capture());
    byte[] serializedMetacardType = metacardTypeBytes.getValue();
    MetacardType metacardType = deserializeMetacardType(serializedMetacardType);
    for (AttributeDescriptor attributeDescriptor : metacardType.getAttributeDescriptors()) {
        assertThat(attributeDescriptor.getClass().getName(), is(AttributeDescriptorImpl.class.getName()));
    }
}
Also used : Serializable(java.io.Serializable) Attribute(ddf.catalog.data.Attribute) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) MetacardType(ddf.catalog.data.MetacardType) Metacard(ddf.catalog.data.Metacard) SolrInputDocument(org.apache.solr.common.SolrInputDocument) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 25 with AttributeDescriptor

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

the class SolrProviderTest method testNumericalFields.

@Test
public void testNumericalFields() throws Exception {
    deleteAllIn(provider);
    /* SETUP */
    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 = 9876543293L;
    String shortField = "daysOfTheWeek";
    short shortFieldValue = 1;
    Set<AttributeDescriptor> descriptors = numericalDescriptors(doubleField, floatField, intField, longField, shortField);
    MetacardTypeImpl mType = new MetacardTypeImpl("numberMetacardType", descriptors);
    MetacardImpl customMetacard1 = new MetacardImpl(mType);
    customMetacard1.setAttribute(Metacard.ID, "");
    customMetacard1.setAttribute(doubleField, doubleFieldValue);
    customMetacard1.setAttribute(floatField, floatFieldValue);
    customMetacard1.setAttribute(intField, intFieldValue);
    customMetacard1.setAttribute(longField, longFieldValue);
    customMetacard1.setAttribute(shortField, shortFieldValue);
    create(Arrays.asList((Metacard) customMetacard1));
    // searching double field with int value
    greaterThanQueryAssertion(doubleField, intFieldValue, 1);
    // searching float field with double value
    greaterThanQueryAssertion(floatField, 4.0, 1);
    // searching long field with int value
    greaterThanQueryAssertion(longField, intFieldValue, 1);
    // searching int field with long value
    greaterThanQueryAssertion(intField, 3L, 1);
    // searching int field with long value
    greaterThanQueryAssertion(shortField, 0L, 1);
}
Also used : Metacard(ddf.catalog.data.Metacard) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) Matchers.containsString(org.hamcrest.Matchers.containsString) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Aggregations

AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)111 Test (org.junit.Test)51 MetacardType (ddf.catalog.data.MetacardType)40 Metacard (ddf.catalog.data.Metacard)38 HashSet (java.util.HashSet)29 Attribute (ddf.catalog.data.Attribute)26 AttributeDescriptorImpl (ddf.catalog.data.impl.AttributeDescriptorImpl)24 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)24 MetacardTypeImpl (ddf.catalog.data.impl.MetacardTypeImpl)24 ArrayList (java.util.ArrayList)23 Serializable (java.io.Serializable)16 FeatureMetacardType (org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType)9 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)7 IOException (java.io.IOException)7 Date (java.util.Date)7 List (java.util.List)7 QName (javax.xml.namespace.QName)7