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