Search in sources :

Example 16 with AttributeDescriptor

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

the class AttributeRegistryImplTest method testAddAttribute.

@Test
public void testAddAttribute() {
    final String attributeName = "test";
    final AttributeDescriptor descriptor = new AttributeDescriptorImpl(attributeName, true, false, true, false, BasicTypes.STRING_TYPE);
    registry.register(descriptor);
    final Optional<AttributeDescriptor> descriptorOptional = registry.lookup(attributeName);
    assertThat(descriptorOptional.isPresent(), is(true));
    assertThat(descriptorOptional.get(), is(descriptor));
}
Also used : AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) Test(org.junit.Test)

Example 17 with AttributeDescriptor

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

the class MetacardTypeRegistryTest method sampleMetacardTypeA.

private QualifiedMetacardType sampleMetacardTypeA() {
    Set<AttributeDescriptor> descriptors = new HashSet<AttributeDescriptor>();
    descriptors.add(new AttributeDescriptorImpl(FREQUENCY_ATTRIBUTE_NAME_SAMPLE_METACARD_TYPE_A, true, /* indexed */
    true, /* stored */
    false, /* tokenized */
    false, /* multivalued */
    BasicTypes.LONG_TYPE));
    descriptors.add(new AttributeDescriptorImpl(MIN_FREQUENCY_ATTRIBUTE_NAME_SAMPLE_METACARD_TYPE_A, true, /* indexed */
    true, /* stored */
    false, /* tokenized */
    false, /* multivalued */
    BasicTypes.LONG_TYPE));
    descriptors.add(new AttributeDescriptorImpl(MAX_FREQUENCY_ATTRIBUTE_NAME_SAMPLE_METACARD_TYPE_A, true, /* indexed */
    true, /* stored */
    false, /* tokenized */
    false, /* multivalued */
    BasicTypes.LONG_TYPE));
    descriptors.add(new AttributeDescriptorImpl(ANGLE_ATTRIBUTE_NAME_SAMPLE_METACARD_TYPE_A, true, /* indexed */
    true, /* stored */
    false, /* tokenized */
    false, /* multivalued */
    BasicTypes.INTEGER_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));
    return new QualifiedMetacardTypeImpl("", SAMPLE_A_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 18 with AttributeDescriptor

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

the class MetacardTypeRegistryTest method setupMetacardTypeRegistry.

@BeforeClass
public static void setupMetacardTypeRegistry() throws Exception {
    mtr = MetacardTypeRegistryImpl.getInstance();
    qmtAttributes = new HashSet<AttributeDescriptor>();
    AttributeDescriptor ad1 = new AttributeDescriptorImpl(GEO_ATTRIBUTE_DESCRIPTOR_NAME, true, true, false, false, BasicTypes.GEO_TYPE);
    qmtAttributes.add(ad1);
    AttributeDescriptor ad2 = new AttributeDescriptorImpl(METADATA_ATTRIBUTE_DESCRIPTOR_NAME, true, true, false, false, BasicTypes.XML_TYPE);
    qmtAttributes.add(ad2);
    QualifiedMetacardTypeImpl qmt1 = new QualifiedMetacardTypeImpl(QUALIFIED_METACARD_TYPE_NAMESPACE_1, QUALIFIED_METACARD_TYPE_NAME_1, qmtAttributes);
    mtr.register(qmt1);
    QualifiedMetacardTypeImpl qmt2 = new QualifiedMetacardTypeImpl(QUALIFIED_METACARD_TYPE_NAMESPACE_1, QUALIFIED_METACARD_TYPE_NAME_2, qmtAttributes);
    mtr.register(qmt2);
    QualifiedMetacardTypeImpl qmt3 = new QualifiedMetacardTypeImpl(QualifiedMetacardType.DEFAULT_METACARD_TYPE_NAMESPACE, QUALIFIED_METACARD_TYPE_NAME_3, qmtAttributes);
    mtr.register(qmt3);
}
Also used : QualifiedMetacardTypeImpl(ddf.catalog.data.impl.QualifiedMetacardTypeImpl) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) AttributeDescriptorImpl(ddf.catalog.data.impl.AttributeDescriptorImpl) BeforeClass(org.junit.BeforeClass)

Example 19 with AttributeDescriptor

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

the class MetacardTypeRegistryTest method assertOnSampleMetacardTypeAExpectedAttributes.

private void assertOnSampleMetacardTypeAExpectedAttributes(QualifiedMetacardType qmtResult) {
    Set<AttributeDescriptor> attributeDescriptors = qmtResult.getAttributeDescriptors();
    assertNotNull(attributeDescriptors);
    assertEquals(NUM_ATTRIBUTES_SAMPLE_METACARD_TYPE_A, attributeDescriptors.size());
    AttributeDescriptor angle = qmtResult.getAttributeDescriptor(ANGLE_ATTRIBUTE_NAME_SAMPLE_METACARD_TYPE_A);
    assertNotNull(angle);
    assertEquals(ANGLE_ATTRIBUTE_NAME_SAMPLE_METACARD_TYPE_A, angle.getName());
    AttributeDescriptor maxFreq = qmtResult.getAttributeDescriptor(MAX_FREQUENCY_ATTRIBUTE_NAME_SAMPLE_METACARD_TYPE_A);
    assertNotNull(maxFreq);
    assertEquals(MAX_FREQUENCY_ATTRIBUTE_NAME_SAMPLE_METACARD_TYPE_A, maxFreq.getName());
    AttributeDescriptor minFreq = qmtResult.getAttributeDescriptor(MIN_FREQUENCY_ATTRIBUTE_NAME_SAMPLE_METACARD_TYPE_A);
    assertNotNull(minFreq);
    assertEquals(MIN_FREQUENCY_ATTRIBUTE_NAME_SAMPLE_METACARD_TYPE_A, minFreq.getName());
    AttributeDescriptor freq = qmtResult.getAttributeDescriptor(FREQUENCY_ATTRIBUTE_NAME_SAMPLE_METACARD_TYPE_A);
    assertNotNull(freq);
    assertEquals(FREQUENCY_ATTRIBUTE_NAME_SAMPLE_METACARD_TYPE_A, freq.getName());
    AttributeDescriptor metacardId = qmtResult.getAttributeDescriptor(Metacard.ID);
    assertNotNull(metacardId);
    assertEquals(Metacard.ID, metacardId.getName());
    AttributeDescriptor metacardTitle = qmtResult.getAttributeDescriptor(Metacard.TITLE);
    assertNotNull(metacardTitle);
    assertEquals(Metacard.TITLE, metacardTitle.getName());
}
Also used : AttributeDescriptor(ddf.catalog.data.AttributeDescriptor)

Example 20 with AttributeDescriptor

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

the class DynamicSchemaResolver method addFields.

/**
     * Adds the fields of the Metacard into the {@link SolrInputDocument}
     */
public void addFields(Metacard metacard, SolrInputDocument solrInputDocument) throws MetacardCreationException {
    MetacardType schema = metacard.getMetacardType();
    for (AttributeDescriptor ad : schema.getAttributeDescriptors()) {
        if (metacard.getAttribute(ad.getName()) != null) {
            List<Serializable> attributeValues = metacard.getAttribute(ad.getName()).getValues();
            if (attributeValues != null && attributeValues.size() > 0 && attributeValues.get(0) != null) {
                AttributeFormat format = ad.getType().getAttributeFormat();
                String formatIndexName = ad.getName() + getFieldSuffix(format);
                if (AttributeFormat.XML.equals(format)) {
                    List<String> parsedTexts = parseTextFrom(attributeValues);
                    // text => metadata_txt_ws
                    String whitespaceTokenizedIndexName = ad.getName() + getFieldSuffix(AttributeFormat.STRING) + SchemaFields.WHITESPACE_TEXT_SUFFIX;
                    solrInputDocument.addField(whitespaceTokenizedIndexName, parsedTexts);
                    // text => metadata_txt_ws_has_case
                    String whiteSpaceTokenizedHasCaseIndexName = ad.getName() + getFieldSuffix(AttributeFormat.STRING) + SchemaFields.WHITESPACE_TEXT_SUFFIX + SchemaFields.HAS_CASE;
                    solrInputDocument.addField(whiteSpaceTokenizedHasCaseIndexName, parsedTexts);
                    // text => metadata_txt_tokenized
                    String specialStringIndexName = ad.getName() + getFieldSuffix(AttributeFormat.STRING) + getSpecialIndexSuffix(AttributeFormat.STRING);
                    solrInputDocument.addField(specialStringIndexName, parsedTexts);
                    // text case sensitive
                    solrInputDocument.addField(specialStringIndexName + SchemaFields.HAS_CASE, parsedTexts);
                } else if (AttributeFormat.OBJECT.equals(format)) {
                    ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream();
                    List<Serializable> byteArrays = new ArrayList<>();
                    try (ObjectOutputStream out = new ObjectOutputStream(byteArrayOS)) {
                        for (Serializable serializable : attributeValues) {
                            out.writeObject(serializable);
                            byteArrays.add(byteArrayOS.toByteArray());
                            out.reset();
                        }
                    } catch (IOException e) {
                        throw new MetacardCreationException(COULD_NOT_SERIALIZE_OBJECT_MESSAGE, e);
                    }
                    attributeValues = byteArrays;
                }
                // Prevent adding a field already on document
                if (solrInputDocument.getFieldValue(formatIndexName) == null) {
                    solrInputDocument.addField(formatIndexName, attributeValues);
                    if (AttributeFormat.GEOMETRY.equals(format)) {
                        solrInputDocument.addField(formatIndexName + SchemaFields.SORT_KEY_SUFFIX, createCenterPoint(attributeValues));
                    } else if (!(AttributeFormat.BINARY.equals(format) || AttributeFormat.OBJECT.equals(format))) {
                        solrInputDocument.addField(formatIndexName + SchemaFields.SORT_KEY_SUFFIX, attributeValues.get(0));
                    }
                } else {
                    LOGGER.trace("Skipping adding field already found on document ({})", formatIndexName);
                }
            }
        }
    }
    if (!ConfigurationStore.getInstance().isDisableTextPath()) {
        if (StringUtils.isNotBlank(metacard.getMetadata())) {
            try {
                byte[] luxXml = createTinyBinary(metacard.getMetadata());
                solrInputDocument.addField(LUX_XML_FIELD_NAME, luxXml);
            } catch (XMLStreamException | SaxonApiException e) {
                LOGGER.debug("Unable to parse metadata field.  XPath support unavailable for metacard {}", metacard.getId());
            }
        }
    }
    /*
         * Lastly the metacardType must be added to the solr document. These are internal fields
         */
    String schemaName = String.format("%s#%s", schema.getName(), schema.hashCode());
    solrInputDocument.addField(SchemaFields.METACARD_TYPE_FIELD_NAME, schemaName);
    byte[] metacardTypeBytes = metacardTypeNameToSerialCache.getIfPresent(schemaName);
    if (metacardTypeBytes == null) {
        MetacardType coreMetacardType = new MetacardTypeImpl(schema.getName(), convertAttributeDescriptors(schema.getAttributeDescriptors()));
        metacardTypesCache.put(schemaName, coreMetacardType);
        metacardTypeBytes = serialize(coreMetacardType);
        metacardTypeNameToSerialCache.put(schemaName, metacardTypeBytes);
        addToFieldsCache(coreMetacardType.getAttributeDescriptors());
    }
    solrInputDocument.addField(SchemaFields.METACARD_TYPE_OBJECT_FIELD_NAME, metacardTypeBytes);
}
Also used : Serializable(java.io.Serializable) MetacardCreationException(ddf.catalog.data.MetacardCreationException) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) SaxonApiException(net.sf.saxon.s9api.SaxonApiException) MetacardType(ddf.catalog.data.MetacardType) AttributeFormat(ddf.catalog.data.AttributeType.AttributeFormat) XMLStreamException(javax.xml.stream.XMLStreamException) List(java.util.List) ArrayList(java.util.ArrayList)

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