use of ddf.catalog.data.impl.MetacardTypeImpl in project ddf by codice.
the class SolrProviderTest method testNumericalOperations.
@Test()
public void testNumericalOperations() 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("anotherCustom", 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);
MetacardImpl customMetacard2 = new MetacardImpl(mType);
customMetacard2.setAttribute(Metacard.ID, "");
customMetacard2.setAttribute(doubleField, doubleFieldValue + 10.0);
customMetacard2.setAttribute(floatField, (floatFieldValue + 10.0f));
customMetacard2.setAttribute(intField, intFieldValue + 1);
customMetacard2.setAttribute(longField, longFieldValue + 10L);
customMetacard2.setAttribute(shortField, (shortFieldValue + 1));
create(Arrays.asList((Metacard) customMetacard1, customMetacard2));
// on exact DOUBLE
greaterThanQueryAssertion(doubleField, doubleFieldValue, 1);
greaterThanOrEqualToQueryAssertion(doubleField, doubleFieldValue, 2);
// beyond the DOUBLE
greaterThanQueryAssertion(doubleField, doubleFieldValue - 0.00000001, 2);
greaterThanOrEqualToQueryAssertion(doubleField, doubleFieldValue - 0.00000001, 2);
greaterThanQueryAssertion(doubleField, doubleFieldValue + 12.0, 0);
greaterThanOrEqualToQueryAssertion(doubleField, doubleFieldValue + 12.0, 0);
// on exact FLOAT
greaterThanQueryAssertion(floatField, floatFieldValue, 1);
greaterThanOrEqualToQueryAssertion(floatField, floatFieldValue, 2);
// beyond the FLOAT
greaterThanQueryAssertion(floatField, floatFieldValue - 0.00001f, 2);
greaterThanOrEqualToQueryAssertion(floatField, floatFieldValue - 0.00001f, 2);
greaterThanQueryAssertion(floatField, floatFieldValue + 12.0f, 0);
greaterThanOrEqualToQueryAssertion(floatField, floatFieldValue + 12.0f, 0);
// on exact LONG
greaterThanQueryAssertion(longField, longFieldValue, 1);
greaterThanOrEqualToQueryAssertion(longField, longFieldValue, 2);
// beyond the LONG
greaterThanQueryAssertion(longField, longFieldValue - 1L, 2);
greaterThanOrEqualToQueryAssertion(longField, longFieldValue - 1L, 2);
greaterThanQueryAssertion(longField, longFieldValue + 12L, 0);
greaterThanOrEqualToQueryAssertion(longField, longFieldValue + 12L, 0);
// on exact INT
greaterThanQueryAssertion(intField, intFieldValue, 1);
greaterThanOrEqualToQueryAssertion(intField, intFieldValue, 2);
// beyond the INT
greaterThanQueryAssertion(intField, intFieldValue - 1, 2);
greaterThanOrEqualToQueryAssertion(intField, intFieldValue - 1, 2);
greaterThanQueryAssertion(intField, intFieldValue + 2, 0);
greaterThanOrEqualToQueryAssertion(intField, intFieldValue + 2, 0);
// on exact SHORT
greaterThanQueryAssertion(shortField, shortFieldValue, 1);
greaterThanOrEqualToQueryAssertion(shortField, shortFieldValue, 2);
// beyond the SHORT
greaterThanQueryAssertion(shortField, (short) (shortFieldValue - 1), 2);
greaterThanOrEqualToQueryAssertion(shortField, (short) (shortFieldValue - 1), 2);
greaterThanQueryAssertion(shortField, (short) (shortFieldValue + 2), 0);
greaterThanOrEqualToQueryAssertion(shortField, (short) (shortFieldValue + 2), 0);
}
use of ddf.catalog.data.impl.MetacardTypeImpl in project ddf by codice.
the class TestGetRecordsResponseConverter method createMetacardList.
private List<Metacard> createMetacardList(int start, int finish) {
List<Metacard> list = new LinkedList<>();
for (int i = start; i <= finish; i++) {
MetacardImpl metacard = new MetacardImpl();
metacard.setId(ID_PREFIX + i);
metacard.setSourceId(SOURCE_PREFIX + i);
metacard.setTitle(TITLE_PREFIX + i);
// for testing an attribute with multiple values
AttributeDescriptor ad = new AttributeDescriptorImpl(FORMAT, true, true, true, true, BasicTypes.STRING_TYPE);
Set<AttributeDescriptor> ads = new HashSet<>(metacard.getMetacardType().getAttributeDescriptors());
ads.add(ad);
metacard.setType(new MetacardTypeImpl("test", ads));
metacard.setLocation(WKT);
AttributeImpl attr = new AttributeImpl(FORMAT, FORMAT);
attr.addValue(FORMAT);
metacard.setAttribute(attr);
// for testing an attribute with no attribute descriptor
metacard.setAttribute(RELATION, RELATION);
list.add(metacard);
}
return list;
}
use of ddf.catalog.data.impl.MetacardTypeImpl in project ddf by codice.
the class ValidationParser method parseMetacardTypes.
private List<Callable<Boolean>> parseMetacardTypes(Changeset changeset, List<Outer.MetacardType> metacardTypes) {
List<Callable<Boolean>> staged = new ArrayList<>();
BundleContext context = getBundleContext();
for (Outer.MetacardType metacardType : metacardTypes) {
Set<AttributeDescriptor> attributeDescriptors = new HashSet<>(BasicTypes.BASIC_METACARD.getAttributeDescriptors());
Set<String> requiredAttributes = new HashSet<>();
metacardType.attributes.forEach((attributeName, attribute) -> {
AttributeDescriptor descriptor = attributeRegistry.lookup(attributeName).orElseThrow(() -> new IllegalStateException(String.format("Metacard type [%s] includes the attribute [%s], but that attribute is not in the attribute registry.", metacardType.type, attributeName)));
attributeDescriptors.add(descriptor);
if (attribute.required) {
requiredAttributes.add(attributeName);
}
});
if (!requiredAttributes.isEmpty()) {
final MetacardValidator validator = new RequiredAttributesMetacardValidator(metacardType.type, requiredAttributes);
staged.add(() -> {
ServiceRegistration<MetacardValidator> registration = context.registerService(MetacardValidator.class, validator, null);
changeset.metacardValidatorServices.add(registration);
return registration != null;
});
}
Dictionary<String, Object> properties = new Hashtable<>();
properties.put(NAME_PROPERTY, metacardType.type);
MetacardType type = new MetacardTypeImpl(metacardType.type, attributeDescriptors);
staged.add(() -> {
ServiceRegistration<MetacardType> registration = context.registerService(MetacardType.class, type, properties);
changeset.metacardTypeServices.add(registration);
return registration != null;
});
}
return staged;
}
use of ddf.catalog.data.impl.MetacardTypeImpl in project ddf by codice.
the class TikaInputTransformer method transform.
@Override
public Metacard transform(InputStream input, String id) throws IOException, CatalogTransformerException {
LOGGER.debug("Transforming input stream using Tika.");
if (input == null) {
throw new CatalogTransformerException("Cannot transform null input.");
}
try (TemporaryFileBackedOutputStream fileBackedOutputStream = new TemporaryFileBackedOutputStream()) {
try {
IOUtils.copy(input, fileBackedOutputStream);
} catch (IOException e) {
throw new CatalogTransformerException("Could not copy bytes of content message.", e);
}
Parser parser = new AutoDetectParser();
ToXMLContentHandler xmlContentHandler = new ToXMLContentHandler();
ToTextContentHandler textContentHandler = null;
ContentHandler contentHandler;
if (!contentMetadataExtractors.isEmpty()) {
textContentHandler = new ToTextContentHandler();
contentHandler = new TeeContentHandler(xmlContentHandler, textContentHandler);
} else {
contentHandler = xmlContentHandler;
}
TikaMetadataExtractor tikaMetadataExtractor = new TikaMetadataExtractor(parser, contentHandler);
Metadata metadata;
try (InputStream inputStreamCopy = fileBackedOutputStream.asByteSource().openStream()) {
metadata = tikaMetadataExtractor.parseMetadata(inputStreamCopy, new ParseContext());
}
String metadataText = xmlContentHandler.toString();
if (templates != null) {
metadataText = transformToXml(metadataText);
}
String metacardContentType = metadata.get(Metadata.CONTENT_TYPE);
MetacardType metacardType = getMetacardTypeFromMimeType(metacardContentType);
if (metacardType == null) {
metacardType = commonTikaMetacardType;
}
Metacard metacard;
if (textContentHandler != null) {
String plainText = textContentHandler.toString();
Set<AttributeDescriptor> attributes = contentMetadataExtractors.values().stream().map(ContentMetadataExtractor::getMetacardAttributes).flatMap(Collection::stream).collect(Collectors.toSet());
MetacardTypeImpl extendedMetacardType = new MetacardTypeImpl(metacardType.getName(), metacardType, attributes);
metacard = MetacardCreator.createMetacard(metadata, id, metadataText, extendedMetacardType);
for (ContentMetadataExtractor contentMetadataExtractor : contentMetadataExtractors.values()) {
contentMetadataExtractor.process(plainText, metacard);
}
} else {
metacard = MetacardCreator.createMetacard(metadata, id, metadataText, metacardType);
}
if (StringUtils.isNotBlank(metacardContentType)) {
metacard.setAttribute(new AttributeImpl(Core.DATATYPE, getDatatype(metacardContentType)));
}
if (StringUtils.startsWith(metacardContentType, "image")) {
try (InputStream inputStreamCopy = fileBackedOutputStream.asByteSource().openStream()) {
createThumbnail(inputStreamCopy, metacard);
}
}
LOGGER.debug("Finished transforming input stream using Tika.");
return metacard;
}
}
use of ddf.catalog.data.impl.MetacardTypeImpl in project ddf by codice.
the class FilterPluginTest method getMoreRolesMetacard.
private Metacard getMoreRolesMetacard() {
MetacardImpl metacard = new MetacardImpl();
metacard.setResourceSize("100");
try {
metacard.setResourceURI(new URI("http://some.fancy.uri/goes/here"));
} catch (URISyntaxException e) {
LOGGER.error("", e);
}
metacard.setContentTypeName("Resource");
metacard.setTitle("Metacard 1");
metacard.setContentTypeVersion("1");
metacard.setType(new MetacardTypeImpl(MetacardType.DEFAULT_METACARD_TYPE_NAME, new HashSet<>()));
HashMap<String, List<String>> security = new HashMap<>();
security.put("Roles", Arrays.asList("A", "B", "CR", "WS"));
metacard.setSecurity(security);
return metacard;
}
Aggregations