use of ddf.catalog.data.AttributeType in project ddf by codice.
the class CswRecordMapperFilterVisitor method visit.
@Override
public Object visit(PropertyIsLessThanOrEqualTo filter, Object extraData) {
Expression expr1 = visit(filter.getExpression1(), extraData);
Expression expr2 = visit(filter.getExpression2(), expr1);
// work around since solr provider doesn't support lessOrEqual on temporal (DDF-311)
if (isTemporalQuery(expr1, expr2)) {
// work around #1 fails, solr provider doesn't support tEquals either (DDF-311)
//TEquals tEquals = getFactory(extraData).tequals(expr1, expr2);
//Before before = getFactory(extraData).before(expr1, expr2);
//return getFactory(extraData).or(tEquals, before);
Object val = null;
Expression other = null;
if (expr2 instanceof Literal) {
val = ((Literal) expr2).getValue();
other = expr1;
} else if (expr1 instanceof Literal) {
val = ((Literal) expr1).getValue();
other = expr2;
}
if (val != null) {
Date orig = (Date) val;
orig.setTime(orig.getTime() + 1);
Literal literal = getFactory(extraData).literal(orig);
return getFactory(extraData).before(other, literal);
}
} else {
AttributeType type = attributeTypes.get(((PropertyName) filter.getExpression1()).getPropertyName());
LiteralExpressionImpl typedExpression = (LiteralExpressionImpl) filter.getExpression2();
setExpressionType(type, typedExpression);
expr2 = visit((Expression) typedExpression, expr1);
}
return getFactory(extraData).lessOrEqual(expr1, expr2);
}
use of ddf.catalog.data.AttributeType in project ddf by codice.
the class CswRecordMapperFilterVisitor method visit.
@Override
public Object visit(PropertyIsNotEqualTo filter, Object extraData) {
AttributeType type = attributeTypes.get(((PropertyName) filter.getExpression1()).getPropertyName());
LiteralExpressionImpl typedExpression = (LiteralExpressionImpl) filter.getExpression2();
setExpressionType(type, typedExpression);
Expression expr1 = visit(filter.getExpression1(), extraData);
Expression expr2 = visit((Expression) typedExpression, expr1);
return getFactory(extraData).notEqual(expr1, expr2, filter.isMatchingCase());
}
use of ddf.catalog.data.AttributeType in project ddf by codice.
the class AttributeFactory method parseAttributeValue.
/**
* Attempts to parse a value for an {@link Attribute} according to the provided {@link AttributeDescriptor}
* whose value is represented by the given string {@param value}. Returns {@code null} if {@param value}
* could not be parsed.
* <p>
* The input {@param value} must be effectively {@link Serializable}.
*
* @param attributeDescriptor The descriptor to use to parse the value.
* @param value The string containing the value to be parsed.
* @return The deserialized object of {@param value} according to {@param attributeDescriptor}.
*/
@Nullable
public Serializable parseAttributeValue(AttributeDescriptor attributeDescriptor, String value) {
try {
notNull(attributeDescriptor);
notEmpty(value);
Serializable deserializedValue;
AttributeType attributeType = attributeDescriptor.getType();
AttributeType.AttributeFormat attributeFormat = attributeType.getAttributeFormat();
switch(attributeFormat) {
case INTEGER:
deserializedValue = Integer.parseInt(value);
break;
case FLOAT:
deserializedValue = Float.parseFloat(value);
break;
case DOUBLE:
deserializedValue = Double.parseDouble(value);
break;
case SHORT:
deserializedValue = Short.parseShort(value);
break;
case LONG:
deserializedValue = Long.parseLong(value);
break;
case DATE:
Calendar calendar = DatatypeConverter.parseDateTime(value);
deserializedValue = calendar.getTime();
break;
case BOOLEAN:
deserializedValue = Boolean.parseBoolean(value);
break;
case BINARY:
deserializedValue = value.getBytes(Charset.forName("UTF-8"));
break;
case OBJECT:
case STRING:
case GEOMETRY:
case XML:
deserializedValue = value;
break;
default:
return null;
}
return deserializedValue;
} catch (IllegalArgumentException e) {
return null;
}
}
use of ddf.catalog.data.AttributeType in project ddf by codice.
the class RESTEndpoint method parseOverrideAttributes.
private void parseOverrideAttributes(List<Attribute> attributes, String parsedName, InputStream inputStream) {
Optional<AttributeType.AttributeFormat> attributeFormat = metacardTypes.stream().map(metacardType -> metacardType.getAttributeDescriptor(parsedName)).filter(Objects::nonNull).findFirst().map(AttributeDescriptor::getType).map(AttributeType::getAttributeFormat);
attributeFormat.ifPresent(attributeFormat1 -> {
try {
switch(attributeFormat1) {
case XML:
case GEOMETRY:
case STRING:
attributes.add(new AttributeImpl(parsedName, IOUtils.toString(inputStream)));
break;
case BOOLEAN:
attributes.add(new AttributeImpl(parsedName, Boolean.valueOf(IOUtils.toString(inputStream))));
break;
case SHORT:
attributes.add(new AttributeImpl(parsedName, Short.valueOf(IOUtils.toString(inputStream))));
break;
case LONG:
attributes.add(new AttributeImpl(parsedName, Long.valueOf(IOUtils.toString(inputStream))));
break;
case INTEGER:
attributes.add(new AttributeImpl(parsedName, Integer.valueOf(IOUtils.toString(inputStream))));
break;
case FLOAT:
attributes.add(new AttributeImpl(parsedName, Float.valueOf(IOUtils.toString(inputStream))));
break;
case DOUBLE:
attributes.add(new AttributeImpl(parsedName, Double.valueOf(IOUtils.toString(inputStream))));
break;
case DATE:
Instant instant = Instant.parse(IOUtils.toString(inputStream));
if (instant == null) {
break;
}
attributes.add(new AttributeImpl(parsedName, Date.from(instant)));
break;
case BINARY:
attributes.add(new AttributeImpl(parsedName, IOUtils.toByteArray(inputStream)));
break;
case OBJECT:
LOGGER.debug("Object type not supported for override");
break;
}
} catch (IOException e) {
LOGGER.debug("Unable to read attribute to override", e);
} finally {
IOUtils.closeQuietly(inputStream);
}
});
}
Aggregations