Search in sources :

Example 6 with ValueType

use of net.opengis.ows.v_1_1_0.ValueType in project ddf by codice.

the class WfsFilterDelegateTest method testConformanceAllowedValues.

@Test
public void testConformanceAllowedValues() {
    // Setup
    FilterCapabilities capabilities = MockWfsServer.getFilterCapabilities();
    ConformanceType conformance = capabilities.getConformance();
    List<DomainType> domainTypes = conformance.getConstraint();
    for (DomainType domainType : domainTypes) {
        if (StringUtils.equals(domainType.getName(), "ImplementsSorting")) {
            domainType.setNoValues(null);
            ValueType asc = new ValueType();
            asc.setValue("ASC");
            ValueType desc = new ValueType();
            desc.setValue("DESC");
            AllowedValues allowedValues = new AllowedValues();
            List<Object> values = new ArrayList<>();
            values.add(asc);
            values.add(desc);
            allowedValues.setValueOrRange(values);
            domainType.setAllowedValues(allowedValues);
            ValueType defaultValue = new ValueType();
            defaultValue.setValue("ASC");
            domainType.setDefaultValue(defaultValue);
            break;
        }
    }
    // Perform Test
    WfsFilterDelegate delegate = new WfsFilterDelegate(mockFeatureMetacardType, capabilities, GeospatialUtil.EPSG_4326_URN, mockMapper, GeospatialUtil.LAT_LON_ORDER);
    // Verify
    assertThat(delegate.isSortingSupported(), is(true));
    assertThat(delegate.getAllowedSortOrders().size(), is(2));
    assertThat(delegate.getAllowedSortOrders().contains(SortOrder.ASCENDING), is(true));
    assertThat(delegate.getAllowedSortOrders().contains(SortOrder.DESCENDING), is(true));
}
Also used : FilterCapabilities(net.opengis.filter.v_2_0_0.FilterCapabilities) DomainType(net.opengis.ows.v_1_1_0.DomainType) AllowedValues(net.opengis.ows.v_1_1_0.AllowedValues) ValueType(net.opengis.ows.v_1_1_0.ValueType) ArrayList(java.util.ArrayList) ConformanceType(net.opengis.filter.v_2_0_0.ConformanceType) Test(org.junit.Test)

Example 7 with ValueType

use of net.opengis.ows.v_1_1_0.ValueType in project ddf by codice.

the class WfsSourceTest method testSortingAscendingSortingNotSupported.

/**
 * Verify that the SortBy is NOT set. In this case, sorting is not supported in the capabilities.
 */
@Test
public void testSortingAscendingSortingNotSupported() throws Exception {
    // Setup
    final String searchPhrase = "*";
    final String mockTemporalFeatureProperty = "myTemporalFeatureProperty";
    final String mockFeatureType = "{http://example.com}" + SAMPLE_FEATURE_NAME + 0;
    final int pageSize = 1;
    // Set ImplementsSorting to FALSE (sorting not supported)
    FilterCapabilities mockCapabilitiesSortingNotSupported = MockWfsServer.getFilterCapabilities();
    ConformanceType conformance = mockCapabilitiesSortingNotSupported.getConformance();
    List<DomainType> domainTypes = conformance.getConstraint();
    for (DomainType domainType : domainTypes) {
        if (StringUtils.equals(domainType.getName(), "ImplementsSorting")) {
            ValueType valueType = new ValueType();
            valueType.setValue("FALSE");
            domainType.setDefaultValue(valueType);
            break;
        }
    }
    WfsSource source = getWfsSource(ONE_TEXT_PROPERTY_SCHEMA, mockCapabilitiesSortingNotSupported, 1, false, false, 0);
    MetacardMapper mockMetacardMapper = mock(MetacardMapper.class);
    when(mockMetacardMapper.getFeatureType()).thenReturn(mockFeatureType);
    when(mockMetacardMapper.getSortByTemporalFeatureProperty()).thenReturn(mockTemporalFeatureProperty);
    List<MetacardMapper> mappers = new ArrayList<>(1);
    mappers.add(mockMetacardMapper);
    source.setMetacardToFeatureMapper(mappers);
    QueryImpl query = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text(searchPhrase));
    query.setPageSize(pageSize);
    SortBy sortBy = new SortByImpl(Result.TEMPORAL, SortOrder.ASCENDING);
    query.setSortBy(sortBy);
    // Perform Test
    GetFeatureType featureType = source.buildGetFeatureRequest(query);
    // Verify
    QueryType queryType = (QueryType) featureType.getAbstractQueryExpression().get(0).getValue();
    assertFalse(queryType.isSetAbstractSortingClause());
}
Also used : ValueType(net.opengis.ows.v_1_1_0.ValueType) SortBy(org.opengis.filter.sort.SortBy) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) FilterCapabilities(net.opengis.filter.v_2_0_0.FilterCapabilities) QueryImpl(ddf.catalog.operation.impl.QueryImpl) DomainType(net.opengis.ows.v_1_1_0.DomainType) SortByImpl(ddf.catalog.filter.impl.SortByImpl) ConformanceType(net.opengis.filter.v_2_0_0.ConformanceType) QueryType(net.opengis.wfs.v_2_0_0.QueryType) MetacardMapper(org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper) GetFeatureType(net.opengis.wfs.v_2_0_0.GetFeatureType) Test(org.junit.Test)

Example 8 with ValueType

use of net.opengis.ows.v_1_1_0.ValueType in project sldeditor by robward-scisys.

the class CustomProcessFunctionTest method createProcessDescriptionEnum.

/**
 * Test the process description enumeration values.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void createProcessDescriptionEnum() {
    ProcessDescriptionType process = Wps10FactoryImpl.init().createProcessDescriptionType();
    CodeType codeType = Ows11FactoryImpl.init().createCodeType();
    codeType.setValue("JTS:area");
    process.setIdentifier(codeType);
    InputDescriptionType inputDescription = Wps10FactoryImpl.init().createInputDescriptionType();
    CodeType codeType2 = Ows11FactoryImpl.init().createCodeType();
    codeType2.setValue("dummyParameter");
    inputDescription.setIdentifier(codeType2);
    inputDescription.setMinOccurs(BigInteger.valueOf(1));
    inputDescription.setMaxOccurs(BigInteger.valueOf(1));
    AllowedValuesType allowedValues = Ows11FactoryImpl.init().createAllowedValuesType();
    EList allowedValueList = allowedValues.getValue();
    ValueType item1 = Ows11FactoryImpl.init().createValueType();
    item1.setValue("item 1");
    allowedValueList.add(item1);
    ValueType item2 = Ows11FactoryImpl.init().createValueType();
    item2.setValue("item 2");
    allowedValueList.add(item2);
    ValueType item3 = Ows11FactoryImpl.init().createValueType();
    item1.setValue("item 3");
    allowedValueList.add(item3);
    LiteralInputType literal = Wps10FactoryImpl.init().createLiteralInputType();
    literal.setAllowedValues(allowedValues);
    inputDescription.setLiteralData(literal);
    DataInputsType dataInputs = Wps10FactoryImpl.init().createDataInputsType();
    EList dataInputList = dataInputs.getInput();
    dataInputList.add(inputDescription);
    process.setDataInputs(dataInputs);
    CustomProcessFunction obj = new CustomProcessFunction();
    List<ProcessFunctionParameterValue> valueList = obj.extractParameters(process);
    assertEquals(1, valueList.size());
    ProcessFunctionParameterValue value = valueList.get(0);
    assertEquals(1, value.getMinOccurences());
    assertEquals(1, value.getMaxOccurences());
}
Also used : InputDescriptionType(net.opengis.wps10.InputDescriptionType) EList(org.eclipse.emf.common.util.EList) ValueType(net.opengis.ows11.ValueType) AllowedValuesType(net.opengis.ows11.AllowedValuesType) ProcessDescriptionType(net.opengis.wps10.ProcessDescriptionType) DataInputsType(net.opengis.wps10.DataInputsType) ProcessFunctionParameterValue(com.sldeditor.rendertransformation.ProcessFunctionParameterValue) CustomProcessFunction(com.sldeditor.rendertransformation.CustomProcessFunction) CodeType(net.opengis.ows11.CodeType) LiteralInputType(net.opengis.wps10.LiteralInputType) Test(org.junit.jupiter.api.Test)

Example 9 with ValueType

use of net.opengis.ows.v_1_1_0.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.isCollection()) ? dmnType : REGISTRY.unknown()));
        }
        return result;
    } else if (isDMNSimpleType(dmnType) || (isDMNAny(dmnType) && isJAXBValue(value) && !isJAXBComponent(value))) {
        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();
            }
            if (text != null) {
                if (isDMNSimpleType(dmnType)) {
                    return recurseSimpleDMNTypeToFindBuiltInFEELType((BaseDMNTypeImpl) dmnType).fromString(text);
                } else {
                    // no information from DMN; try to use the xml test case file.
                    Class<?> xmlClass = value.getValue().getDeclaredType();
                    if (!xmlClass.equals(Object.class) && !xmlClass.equals(String.class)) {
                        try {
                            Method m = xmlClass.getMethod("valueOf", String.class);
                            Object valueOfResult = m.invoke(null, text);
                            return valueOfResult;
                        } catch (Exception e) {
                            return text;
                        }
                    } else {
                        return text;
                    }
                }
            } else {
                return 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) {
                    if (!isDMNAny(dmnType)) {
                        // need to convert to java.time.* equivalent
                        text = dateTimeOrDurationValue.toString();
                        return text != null ? recurseSimpleDMNTypeToFindBuiltInFEELType((BaseDMNTypeImpl) dmnType).fromString(text) : null;
                    } else {
                        // no DMN type information from the DMN model
                        if (dateTimeOrDurationValue instanceof Duration) {
                            try {
                                return java.time.Duration.parse(dateTimeOrDurationValue.toString());
                            } catch (DateTimeParseException e) {
                                return ComparablePeriod.parse(dateTimeOrDurationValue.toString());
                            }
                        } else if (dateTimeOrDurationValue instanceof XMLGregorianCalendar) {
                            XMLGregorianCalendar xmlCal = (XMLGregorianCalendar) dateTimeOrDurationValue;
                            if (xmlCal.getTimezone() != DatatypeConstants.FIELD_UNDEFINED && xmlCal.getXMLSchemaType() == DatatypeConstants.DATETIME) {
                                return ZonedDateTime.parse(xmlCal.toXMLFormat());
                            } else if (xmlCal.getTimezone() != DatatypeConstants.FIELD_UNDEFINED && xmlCal.getXMLSchemaType() == DatatypeConstants.TIME) {
                                return OffsetTime.parse(xmlCal.toXMLFormat());
                            } else if (xmlCal.getXMLSchemaType() == DatatypeConstants.DATETIME) {
                                return LocalDateTime.of(LocalDate.of(xmlCal.getYear(), xmlCal.getMonth(), xmlCal.getDay()), LocalTime.of(xmlCal.getHour(), xmlCal.getMinute(), xmlCal.getSecond()));
                            } else if (xmlCal.getXMLSchemaType() == DatatypeConstants.DATE) {
                                return LocalDate.of(xmlCal.getYear(), xmlCal.getMonth(), xmlCal.getDay());
                            } else if (xmlCal.getXMLSchemaType() == DatatypeConstants.TIME) {
                                return LocalTime.parse(xmlCal.toXMLFormat());
                            }
                            return xmlCal.toGregorianCalendar();
                        } else {
                            return dateTimeOrDurationValue;
                        }
                    }
                }
            } catch (Exception e) {
                logger.error("Error trying to coerce JAXB type " + val.getClass().getName() + " with value '" + val.toString() + "': " + e.getMessage());
            }
            return val;
        }
    } else if (isDMNCompositeType(dmnType)) {
        Map<String, Object> result = new HashMap<>();
        if (value.getComponent().size() == 0) {
            return null;
        }
        for (ValueType.Component component : value.getComponent()) {
            DMNType fieldType = dmnType.getFields().get(component.getName());
            if (!dmnType.getFields().containsKey(component.getName())) {
                logger.warn("Error TCK Runner type check: unknown field '" + component.getName() + "' for type '" + dmnType.getName() + "'. This usually happens when a TCK test leverages coercion.");
                fieldType = REGISTRY.unknown();
            }
            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;
    } else if (isDMNAny(dmnType) && !isJAXBValue(value) && isJAXBComponent(value)) {
        Map<String, Object> result = new HashMap<>();
        for (ValueType.Component component : value.getComponent()) {
            Object fieldValue = parseType(component, REGISTRY.unknown());
            result.put(component.getName(), fieldValue);
        }
        return result;
    } else {
        throw new RuntimeException("Unable to infer information from JAXB type");
    }
}
Also used : ValueType(org.omg.dmn.tck.marshaller._20160719.ValueType) HashMap(java.util.HashMap) InputDataNode(org.kie.dmn.api.core.ast.InputDataNode) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) Duration(javax.xml.datatype.Duration) JAXBElement(javax.xml.bind.JAXBElement) Method(java.lang.reflect.Method) FileNotFoundException(java.io.FileNotFoundException) UncheckedIOException(java.io.UncheckedIOException) DateTimeParseException(java.time.format.DateTimeParseException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) DateTimeParseException(java.time.format.DateTimeParseException) Map(java.util.Map) HashMap(java.util.HashMap) DMNType(org.kie.dmn.api.core.DMNType)

Example 10 with ValueType

use of net.opengis.ows.v_1_1_0.ValueType in project tck by dmn-tck.

the class DmnScalaTCKTest method getValue.

private Object getValue(ValueType valueType) {
    final JAXBElement<Object> value = valueType.getValue();
    final JAXBElement<ValueType.List> listValue = valueType.getList();
    final List<Component> componentValue = valueType.getComponent();
    if (value == null && listValue == null && componentValue == null) {
        return null;
    }
    if (listValue != null) {
        final List<Object> list = new ArrayList<>();
        for (ValueType item : listValue.getValue().getItem()) {
            list.add(getValue(item));
        }
        return list;
    }
    if (componentValue != null && !componentValue.isEmpty()) {
        final Map<String, Object> context = new HashMap<>();
        for (Component component : componentValue) {
            final Object compValue = getValue(component);
            context.put(component.getName(), compValue);
        }
        return context;
    }
    if (value instanceof Node) {
        final Node node = (Node) value;
        final String text = node.getFirstChild().getTextContent();
        if ("true".equalsIgnoreCase(text) || "false".equalsIgnoreCase(text)) {
            return Boolean.valueOf(text);
        }
        try {
            return Long.valueOf(text);
        } catch (NumberFormatException e) {
        }
        try {
            return Double.valueOf(text);
        } catch (NumberFormatException e) {
        }
        return text;
    }
    if (value != null) {
        final Object singleValue = value.getValue();
        if (singleValue instanceof XMLGregorianCalendar) {
            return transformDateTime((XMLGregorianCalendar) singleValue);
        }
        if (singleValue instanceof Duration) {
            return transformDuration((Duration) singleValue);
        }
        if (singleValue instanceof String[]) {
            String[] array = (String[]) singleValue;
            return Arrays.asList(array);
        }
        return singleValue;
    }
    throw new RuntimeException(String.format("Unexpected value: '%s'", valueType));
}
Also used : ValueType(org.omg.dmn.tck.marshaller._20160719.ValueType) HashMap(java.util.HashMap) Node(org.w3c.dom.Node) ResultNode(org.omg.dmn.tck.marshaller._20160719.TestCases.TestCase.ResultNode) ArrayList(java.util.ArrayList) Duration(javax.xml.datatype.Duration) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ArrayList(java.util.ArrayList) List(java.util.List) Component(org.omg.dmn.tck.marshaller._20160719.ValueType.Component)

Aggregations

ArrayList (java.util.ArrayList)7 ValueType (net.opengis.ows.v_1_1_0.ValueType)6 ConformanceType (net.opengis.filter.v_2_0_0.ConformanceType)5 FilterCapabilities (net.opengis.filter.v_2_0_0.FilterCapabilities)5 DomainType (net.opengis.ows.v_1_1_0.DomainType)5 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 Duration (javax.xml.datatype.Duration)3 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)3 AllowedValues (net.opengis.ows.v_1_1_0.AllowedValues)3 ValueType (org.omg.dmn.tck.marshaller._20160719.ValueType)3 Node (org.w3c.dom.Node)3 SortByImpl (ddf.catalog.filter.impl.SortByImpl)2 QueryImpl (ddf.catalog.operation.impl.QueryImpl)2 List (java.util.List)2 CustomProcessFunction (com.sldeditor.rendertransformation.CustomProcessFunction)1 ProcessFunctionParameterValue (com.sldeditor.rendertransformation.ProcessFunctionParameterValue)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1