Search in sources :

Example 6 with LiteralType

use of org.geotoolkit.ogc.xml.v100.LiteralType in project flytekit-java by flyteorg.

the class JacksonSdkType method toLiteralMap.

@Override
public Map<String, Literal> toLiteralMap(T value) {
    try {
        JsonNode tree = OBJECT_MAPPER.valueToTree(value);
        Map<String, LiteralType> literalTypeMap = getVariableMap().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, x -> x.getValue().literalType()));
        // The previous trick with JavaType and withValueHandler did't work because
        // Jackson caches serializers, without considering valueHandler as significant part
        // of the caching key.
        JsonParser tokens = OBJECT_MAPPER.treeAsTokens(tree);
        tokens.nextToken();
        LiteralMapDeserializer deserializer = new LiteralMapDeserializer(literalTypeMap);
        // this is how OBJECT_MAPPER creates deserialization context, otherwise, nested deserializers
        // don't work
        DefaultDeserializationContext cctx = ((DefaultDeserializationContext) OBJECT_MAPPER.getDeserializationContext()).createInstance(OBJECT_MAPPER.getDeserializationConfig(), tokens, OBJECT_MAPPER.getInjectableValues());
        JacksonLiteralMap jacksonLiteralMap = deserializer.deserialize(tokens, cctx);
        return jacksonLiteralMap.getLiteralMap();
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : JsonParser(com.fasterxml.jackson.core.JsonParser) LiteralType(org.flyte.api.v1.LiteralType) DefaultDeserializationContext(com.fasterxml.jackson.databind.deser.DefaultDeserializationContext) Literal(org.flyte.api.v1.Literal) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) Variable(org.flyte.api.v1.Variable) ParameterNamesModule(com.fasterxml.jackson.module.paramnames.ParameterNamesModule) Collectors(java.util.stream.Collectors) UncheckedIOException(java.io.UncheckedIOException) Objects(java.util.Objects) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) SdkType(org.flyte.flytekit.SdkType) Map(java.util.Map) JsonSerializer(com.fasterxml.jackson.databind.JsonSerializer) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) SerializerProvider(com.fasterxml.jackson.databind.SerializerProvider) DefaultDeserializationContext(com.fasterxml.jackson.databind.deser.DefaultDeserializationContext) JsonNode(com.fasterxml.jackson.databind.JsonNode) LiteralType(org.flyte.api.v1.LiteralType) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) Map(java.util.Map) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 7 with LiteralType

use of org.geotoolkit.ogc.xml.v100.LiteralType in project flytekit-java by flyteorg.

the class SdkLaunchPlan method verifyMatchedInput.

private void verifyMatchedInput(Map<String, LiteralType> newInputTypes, String inputType) {
    for (Map.Entry<String, LiteralType> lpInputType : newInputTypes.entrySet()) {
        String inputName = lpInputType.getKey();
        LiteralType lpType = lpInputType.getValue();
        LiteralType wfType = workflowInputTypeMap().get(inputName);
        if (wfType == null) {
            String message = String.format("unexpected %s input %s", inputType, inputName);
            throw new IllegalArgumentException(message);
        }
        if (!lpType.equals(wfType)) {
            String message = String.format("invalid %s input wrong type %s, expected %s, got %s instead", inputType, inputName, wfType, lpType);
            throw new IllegalArgumentException(message);
        }
    }
}
Also used : LiteralType(org.flyte.api.v1.LiteralType) LinkedHashMap(java.util.LinkedHashMap) Collectors.toMap(java.util.stream.Collectors.toMap) MoreCollectors.toUnmodifiableMap(org.flyte.flytekit.MoreCollectors.toUnmodifiableMap) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap)

Example 8 with LiteralType

use of org.geotoolkit.ogc.xml.v100.LiteralType in project flytekit-java by flyteorg.

the class SdkBindingData method ofStruct.

public static SdkBindingData ofStruct(SdkStruct struct) {
    BindingData bindingData = BindingData.ofScalar(Scalar.ofGeneric(struct.struct()));
    LiteralType literalType = LiteralType.ofSimpleType(SimpleType.STRUCT);
    return create(bindingData, literalType);
}
Also used : LiteralType(org.flyte.api.v1.LiteralType) BindingData(org.flyte.api.v1.BindingData)

Example 9 with LiteralType

use of org.geotoolkit.ogc.xml.v100.LiteralType in project geotoolkit by Geomatys.

the class FilterFactoryImpl method equal.

@Override
public BinaryComparisonOperator<Object> equal(final Expression<Object, ?> expr1, final Expression<Object, ?> expr2) {
    LiteralType lit = null;
    PropertyNameType propName = null;
    if (expr1 instanceof PropertyNameType) {
        propName = (PropertyNameType) expr1;
    } else if (expr2 instanceof PropertyNameType) {
        propName = (PropertyNameType) expr2;
    }
    if (expr1 instanceof LiteralType) {
        lit = (LiteralType) expr1;
    } else if (expr2 instanceof LiteralType) {
        lit = (LiteralType) expr2;
    }
    return new PropertyIsEqualToType(lit, propName, null);
}
Also used : PropertyIsEqualToType(org.geotoolkit.ogc.xml.v110.PropertyIsEqualToType) LiteralType(org.geotoolkit.ogc.xml.v110.LiteralType) PropertyNameType(org.geotoolkit.ogc.xml.v110.PropertyNameType)

Example 10 with LiteralType

use of org.geotoolkit.ogc.xml.v100.LiteralType in project geotoolkit by Geomatys.

the class FilterFactoryImpl method less.

@Override
public BinaryComparisonOperator<Object> less(final Expression<Object, ?> expr1, final Expression<Object, ?> expr2, final boolean matchCase, final MatchAction action) {
    LiteralType lit = null;
    PropertyNameType propName = null;
    if (expr1 instanceof PropertyNameType) {
        propName = (PropertyNameType) expr1;
    } else if (expr2 instanceof PropertyNameType) {
        propName = (PropertyNameType) expr2;
    }
    if (expr1 instanceof LiteralType) {
        lit = (LiteralType) expr1;
    } else if (expr2 instanceof LiteralType) {
        lit = (LiteralType) expr2;
    }
    return new PropertyIsLessThanType(lit, propName, matchCase);
}
Also used : PropertyIsLessThanType(org.geotoolkit.ogc.xml.v110.PropertyIsLessThanType) LiteralType(org.geotoolkit.ogc.xml.v110.LiteralType) PropertyNameType(org.geotoolkit.ogc.xml.v110.PropertyNameType)

Aggregations

LiteralType (org.geotoolkit.ogc.xml.v110.LiteralType)40 PropertyNameType (org.geotoolkit.ogc.xml.v110.PropertyNameType)40 JAXBElement (javax.xml.bind.JAXBElement)39 Literal (org.opengis.filter.Literal)34 Marshaller (javax.xml.bind.Marshaller)33 Unmarshaller (javax.xml.bind.Unmarshaller)33 Test (org.junit.Test)33 ValueReference (org.opengis.filter.ValueReference)33 Filter (org.opengis.filter.Filter)25 BinaryComparisonOperator (org.opengis.filter.BinaryComparisonOperator)21 LiteralType (org.geotoolkit.ogc.xml.v100.LiteralType)17 PropertyNameType (org.geotoolkit.ogc.xml.v100.PropertyNameType)16 FilterType (org.geotoolkit.ogc.xml.v110.FilterType)13 FilterType (org.geotoolkit.ogc.xml.v100.FilterType)11 Expression (org.opengis.filter.Expression)11 LiteralType (org.flyte.api.v1.LiteralType)10 BinaryComparisonOpType (org.geotoolkit.ogc.xml.v100.BinaryComparisonOpType)9 ComparisonOpsType (org.geotoolkit.ogc.xml.v100.ComparisonOpsType)9 BinaryComparisonOpType (org.geotoolkit.ogc.xml.v110.BinaryComparisonOpType)9 LogicalOperator (org.opengis.filter.LogicalOperator)9