Search in sources :

Example 6 with AttributeType

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);
}
Also used : Expression(org.opengis.filter.expression.Expression) AttributeType(ddf.catalog.data.AttributeType) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl) Literal(org.opengis.filter.expression.Literal) Date(java.util.Date)

Example 7 with AttributeType

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());
}
Also used : Expression(org.opengis.filter.expression.Expression) AttributeType(ddf.catalog.data.AttributeType) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl)

Example 8 with AttributeType

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;
    }
}
Also used : Serializable(java.io.Serializable) AttributeType(ddf.catalog.data.AttributeType) Calendar(java.util.Calendar) Nullable(javax.annotation.Nullable)

Example 9 with AttributeType

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);
        }
    });
}
Also used : AttributeType(ddf.catalog.data.AttributeType) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) Instant(java.time.Instant) IOException(java.io.IOException)

Aggregations

AttributeType (ddf.catalog.data.AttributeType)9 LiteralExpressionImpl (org.geotools.filter.LiteralExpressionImpl)7 Expression (org.opengis.filter.expression.Expression)7 Literal (org.opengis.filter.expression.Literal)4 Date (java.util.Date)3 DefaultInstant (org.geotools.temporal.object.DefaultInstant)2 DefaultPeriod (org.geotools.temporal.object.DefaultPeriod)2 DefaultPosition (org.geotools.temporal.object.DefaultPosition)2 Instant (org.opengis.temporal.Instant)2 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)1 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 Instant (java.time.Instant)1 Calendar (java.util.Calendar)1 Nullable (javax.annotation.Nullable)1