Search in sources :

Example 6 with ValueType

use of org.omg.dmn.tck.marshaller._20160719.ValueType in project tck by dmn-tck.

the class DroolsTCKTest method parseType.

private Object parseType(ValueType value, DMNType dmnType) {
    if (value.getList() != null && !value.getList().isNil()) {
        List<Object> result = new ArrayList<>();
        ValueType.List list = value.getList().getValue();
        for (ValueType vt : list.getItem()) {
            result.add(parseType(vt, dmnType));
        }
        return result;
    } else if (!dmnType.isComposite()) {
        String text = null;
        Object val = value.getValue();
        if (val != null && !value.getValue().isNil() && val instanceof JAXBElement<?> && ((JAXBElement<?>) val).getValue() instanceof Node && !isDateTimeOrDuration(((JAXBElement<?>) val).getValue())) {
            Node nodeVal = (Node) ((JAXBElement<?>) val).getValue();
            if (nodeVal.getFirstChild() != null) {
                text = nodeVal.getFirstChild().getTextContent();
            }
            return text != null ? ((BuiltInType) ((BaseDMNTypeImpl) dmnType).getFeelType()).fromString(text) : null;
        } else if (val instanceof JAXBElement<?> && !(((JAXBElement<?>) val).getValue() instanceof Node) && !isDateTimeOrDuration(((JAXBElement<?>) val).getValue())) {
            return ((JAXBElement<?>) val).getValue();
        } else {
            try {
                Object dateTimeOrDurationValue = (val != null) ? ((JAXBElement<?>) val).getValue() : null;
                if (dateTimeOrDurationValue instanceof Duration || dateTimeOrDurationValue instanceof XMLGregorianCalendar) {
                    // need to convert to java.time.* equivalent
                    text = dateTimeOrDurationValue.toString();
                    return text != null ? ((BuiltInType) ((BaseDMNTypeImpl) dmnType).getFeelType()).fromString(text) : null;
                }
            } catch (Exception e) {
                logger.error("Error trying to coerce JAXB type " + val.getClass().getName() + " with value '" + val.toString() + "': " + e.getMessage());
            }
            return val;
        }
    } else {
        Map<String, Object> result = new HashMap<>();
        for (ValueType.Component component : value.getComponent()) {
            if (!dmnType.getFields().containsKey(component.getName())) {
                throw new RuntimeException("Error parsing input: unknown field '" + component.getName() + "' for type '" + dmnType.getName() + "'");
            }
            DMNType fieldType = dmnType.getFields().get(component.getName());
            if (fieldType == null) {
                throw new RuntimeException("Error parsing input: unknown type for field '" + component.getName() + "' on type " + dmnType.getName() + "'");
            }
            Object fieldValue = parseType(component, fieldType);
            result.put(component.getName(), fieldValue);
        }
        return result;
    }
}
Also used : ValueType(org.omg.dmn.tck.marshaller._20160719.ValueType) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) Node(org.w3c.dom.Node) InputDataNode(org.kie.dmn.api.core.ast.InputDataNode) ArrayList(java.util.ArrayList) Duration(javax.xml.datatype.Duration) JAXBElement(javax.xml.bind.JAXBElement) BuiltInType(org.kie.dmn.feel.lang.types.BuiltInType) BaseDMNTypeImpl(org.kie.dmn.core.impl.BaseDMNTypeImpl) MalformedURLException(java.net.MalformedURLException) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) HashMap(java.util.HashMap) Map(java.util.Map) DMNType(org.kie.dmn.api.core.DMNType)

Aggregations

ValueType (net.opengis.ows.v_1_1_0.ValueType)4 ArrayList (java.util.ArrayList)3 ConformanceType (net.opengis.filter.v_2_0_0.ConformanceType)3 FilterCapabilities (net.opengis.filter.v_2_0_0.FilterCapabilities)3 DomainType (net.opengis.ows.v_1_1_0.DomainType)3 AllowedValues (net.opengis.ows.v_1_1_0.AllowedValues)2 Test (org.junit.Test)2 CustomProcessFunction (com.sldeditor.rendertransformation.CustomProcessFunction)1 ProcessFunctionParameterValue (com.sldeditor.rendertransformation.ProcessFunctionParameterValue)1 LineString (com.vividsolutions.jts.geom.LineString)1 SortByImpl (ddf.catalog.filter.impl.SortByImpl)1 QueryImpl (ddf.catalog.operation.impl.QueryImpl)1 MalformedURLException (java.net.MalformedURLException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 JAXBElement (javax.xml.bind.JAXBElement)1 Duration (javax.xml.datatype.Duration)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 QName (javax.xml.namespace.QName)1 ComparisonOperatorType (net.opengis.filter.v_2_0_0.ComparisonOperatorType)1