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));
}
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);
}
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);
}
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());
}
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);
}
Aggregations