use of ddf.catalog.data.impl.AttributeDescriptorImpl in project ddf by codice.
the class ValidationParser method parseAttributeTypes.
private List<Callable<Boolean>> parseAttributeTypes(Changeset changeset, Map<String, Outer.AttributeType> attributeTypes) {
List<Callable<Boolean>> staged = new ArrayList<>();
for (Map.Entry<String, Outer.AttributeType> entry : attributeTypes.entrySet()) {
final AttributeDescriptor descriptor = new AttributeDescriptorImpl(entry.getKey(), entry.getValue().indexed, entry.getValue().stored, entry.getValue().tokenized, entry.getValue().multivalued, BasicTypes.getAttributeType(entry.getValue().type));
staged.add(() -> {
attributeRegistry.register(descriptor);
changeset.attributes.add(descriptor);
return true;
});
}
return staged;
}
use of ddf.catalog.data.impl.AttributeDescriptorImpl in project ddf by codice.
the class FeatureMetacardType method addDescriptors.
/**
* we don't want to expose these in a query interface ie wfs endpoint, so we need to create new
* attributes for each and set them to stored = false note: indexed is being used to determine
* whether or not to query certain wfs fields so it did not seem appropriate to hide those
* fields from the endpoint schema
*/
private void addDescriptors(Set<AttributeDescriptor> attrDescriptors) {
for (AttributeDescriptor descriptor : attrDescriptors) {
AttributeDescriptorImpl basicAttributeDescriptor = (AttributeDescriptorImpl) descriptor;
AttributeDescriptor attributeDescriptor = new AttributeDescriptorImpl(basicAttributeDescriptor.getName(), false, false, basicAttributeDescriptor.isTokenized(), basicAttributeDescriptor.isMultiValued(), basicAttributeDescriptor.getType());
descriptors.add(attributeDescriptor);
}
}
use of ddf.catalog.data.impl.AttributeDescriptorImpl in project ddf by codice.
the class CatalogFrameworkImplTest method testInjectsAttributesOnUpdate.
@Test
public void testInjectsAttributesOnUpdate() throws Exception {
final String injectAttributeName = "new attribute";
final AttributeDescriptor injectAttribute = new AttributeDescriptorImpl(injectAttributeName, true, true, false, false, BasicTypes.DOUBLE_TYPE);
stubMetacardInjection(injectAttribute);
final String id = framework.create(new CreateRequestImpl(Collections.singletonList(new MetacardImpl()), null)).getCreatedMetacards().get(0).getId();
final String title = "Update";
final double injectAttributeValue = -1;
final MetacardImpl metacard = new MetacardImpl();
metacard.setId(id);
metacard.setTitle(title);
metacard.setAttribute(injectAttributeName, injectAttributeValue);
final UpdateRequest request = new UpdateRequestImpl(id, metacard);
List<Result> mockFederationResults = Stream.of(metacard).map(m -> {
Result mockResult = mock(Result.class);
when(mockResult.getMetacard()).thenReturn(m);
return mockResult;
}).collect(Collectors.toList());
QueryResponseImpl queryResponse = new QueryResponseImpl(mock(QueryRequest.class), mockFederationResults, 1);
when(mockFederationStrategy.federate(anyList(), anyObject())).thenReturn(queryResponse);
final UpdateResponse response = framework.update(request);
final Metacard updatedMetacard = response.getUpdatedMetacards().get(0).getNewMetacard();
final MetacardType originalMetacardType = metacard.getMetacardType();
final MetacardType updatedMetacardType = updatedMetacard.getMetacardType();
assertThat(updatedMetacardType.getName(), is(originalMetacardType.getName()));
final Set<AttributeDescriptor> expectedAttributeDescriptors = new HashSet<>(originalMetacardType.getAttributeDescriptors());
expectedAttributeDescriptors.add(injectAttribute);
assertThat(updatedMetacardType.getAttributeDescriptors(), is(expectedAttributeDescriptors));
assertThat(updatedMetacard.getTitle(), is(title));
assertThat(updatedMetacard.getAttribute(injectAttributeName).getValue(), is(injectAttributeValue));
}
use of ddf.catalog.data.impl.AttributeDescriptorImpl in project ddf by codice.
the class CatalogFrameworkImplTest method testInjectsAttributesOnCreate.
@Test
public void testInjectsAttributesOnCreate() throws Exception {
final String title = "Create";
final String injectAttributeName = "new attribute";
final double injectAttributeValue = 2;
final MetacardImpl originalMetacard = new MetacardImpl(BASIC_METACARD);
originalMetacard.setTitle(title);
originalMetacard.setAttribute(injectAttributeName, injectAttributeValue);
final List<Metacard> metacards = Collections.singletonList(originalMetacard);
final CreateRequest request = new CreateRequestImpl(metacards, null);
final AttributeDescriptor injectAttribute = new AttributeDescriptorImpl(injectAttributeName, true, true, false, false, BasicTypes.DOUBLE_TYPE);
stubMetacardInjection(injectAttribute);
final CreateResponse response = framework.create(request);
final Metacard createdMetacard = response.getCreatedMetacards().get(0);
final MetacardType createdMetacardType = createdMetacard.getMetacardType();
final MetacardType originalMetacardType = originalMetacard.getMetacardType();
assertThat(createdMetacardType.getName(), is(originalMetacardType.getName()));
final Set<AttributeDescriptor> expectedAttributeDescriptors = new HashSet<>(originalMetacardType.getAttributeDescriptors());
expectedAttributeDescriptors.add(injectAttribute);
assertThat(createdMetacardType.getAttributeDescriptors(), is(expectedAttributeDescriptors));
assertThat(createdMetacard.getTitle(), is(title));
assertThat(createdMetacard.getAttribute(injectAttributeName).getValue(), is(injectAttributeValue));
}
use of ddf.catalog.data.impl.AttributeDescriptorImpl in project ddf by codice.
the class CatalogFrameworkImplTest method testInjectsAttributesOnQuery.
@Test
public void testInjectsAttributesOnQuery() throws Exception {
final Metacard original = new MetacardImpl();
final String id = framework.create(new CreateRequestImpl(Collections.singletonList(original), null)).getCreatedMetacards().get(0).getId();
final AttributeDescriptor injectAttribute = new AttributeDescriptorImpl("new attribute", true, true, false, false, BasicTypes.DOUBLE_TYPE);
stubMetacardInjection(injectAttribute);
final FilterFactory filterFactory = new FilterFactoryImpl();
final Filter filter = filterFactory.equals(filterFactory.property(Metacard.ID), filterFactory.literal(id));
final QueryRequest request = new QueryRequestImpl(new QueryImpl(filter));
final QueryResponse response = framework.query(request);
final Metacard queryMetacard = response.getResults().get(0).getMetacard();
final MetacardType originalMetacardType = original.getMetacardType();
final MetacardType queryMetacardType = queryMetacard.getMetacardType();
assertThat(originalMetacardType.getName(), is(queryMetacardType.getName()));
final Set<AttributeDescriptor> expectedAttributeDescriptors = new HashSet<>(originalMetacardType.getAttributeDescriptors());
expectedAttributeDescriptors.add(injectAttribute);
assertThat(queryMetacardType.getAttributeDescriptors(), is(expectedAttributeDescriptors));
}
Aggregations