ParameterTypeFactory { public List<ParameterType> buildStoredQueryParameters(Map<String, String> viewParams, Filter filter) { final Wfs20Factory factory = Wfs20Factory.eINSTANCE; if (filter == null) { filter = Filter.INCLUDE; } ParameterMappingContext mappingContext = new ParameterMappingContext(filter, viewParams, featureTypeInfo); List<ParameterType> ret = new ArrayList<ParameterType>(); for (ParameterExpressionType parameter : desc.getParameter()) { String value = null; ParameterMapping mapping = getStoredQueryParameterMapping(parameter.getName()); if (mapping != null && mapping.isForcible()) { value = evaluateMapping(mappingContext, mapping); } else { if (viewParams != null) { value = viewParams.get(parameter.getName()); } if (value == null && mapping != null) { value = evaluateMapping(mappingContext, mapping); } } if (value != null) { ParameterType tmp = factory.createParameterType(); tmp.setName(parameter.getName()); tmp.setValue(value); ret.add(tmp); } } return ret; } ParameterTypeFactory(StoredQueryConfiguration config, StoredQueryDescriptionType desc,
            FeatureTypeInfo featureTypeInfo); ParameterMapping getStoredQueryParameterMapping(String parameterName); List<ParameterType> buildStoredQueryParameters(Map<String, String> viewParams,
            Filter filter);  }
@Test public void testSimple() { ParameterExpressionType param1 = wfs20Factory.createParameterExpressionType(); param1.setName("foo"); desc.getParameter().add(param1); ParameterTypeFactory factory = new ParameterTypeFactory(config, desc, featureType); List<ParameterType> params = factory.buildStoredQueryParameters(new HashMap<String, String>(), null); assertEquals(0, params.size()); }
@Test public void testSingleParameter() { ParameterExpressionType param1 = wfs20Factory.createParameterExpressionType(); param1.setName("foo"); desc.getParameter().add(param1); ParameterTypeFactory factory = new ParameterTypeFactory(config, desc, featureType); Map<String, String> viewParams = new HashMap<String, String>(); viewParams.put("foo", "bar"); List<ParameterType> params = factory.buildStoredQueryParameters(viewParams, null); assertEquals(1, params.size()); ParameterType tmp = params.get(0); assertEquals("foo", tmp.getName()); assertEquals("bar", tmp.getValue()); }
@Test public void testUndefinedViewParameter() { ParameterExpressionType param1 = wfs20Factory.createParameterExpressionType(); param1.setName("foo"); desc.getParameter().add(param1); ParameterTypeFactory factory = new ParameterTypeFactory(config, desc, featureType); Map<String, String> viewParams = new HashMap<String, String>(); viewParams.put("not-defined-in-spec", "bar"); List<ParameterType> params = factory.buildStoredQueryParameters(viewParams, null); assertEquals(0, params.size()); }
@Test public void testDefaultMapping() { ParameterExpressionType param1 = wfs20Factory.createParameterExpressionType(); param1.setName("foo"); desc.getParameter().add(param1); ParameterMappingDefaultValue paramMapping = new ParameterMappingDefaultValue(); paramMapping.setParameterName("foo"); paramMapping.setDefaultValue("tiger"); config.getStoredQueryParameterMappings().add(paramMapping); ParameterTypeFactory factory = new ParameterTypeFactory(config, desc, featureType); Map<String, String> viewParams = new HashMap<String, String>(); List<ParameterType> params = factory.buildStoredQueryParameters(viewParams, null); assertEquals(1, params.size()); ParameterType tmp = params.get(0); assertEquals("foo", tmp.getName()); assertEquals("tiger", tmp.getValue()); }
@Test public void testDefaultMappingOverridden() { ParameterExpressionType param1 = wfs20Factory.createParameterExpressionType(); param1.setName("foo"); desc.getParameter().add(param1); ParameterMappingDefaultValue paramMapping = new ParameterMappingDefaultValue(); paramMapping.setParameterName("foo"); paramMapping.setDefaultValue("tiger"); config.getStoredQueryParameterMappings().add(paramMapping); ParameterTypeFactory factory = new ParameterTypeFactory(config, desc, featureType); Map<String, String> viewParams = new HashMap<String, String>(); viewParams.put("foo", "bar"); List<ParameterType> params = factory.buildStoredQueryParameters(viewParams, null); assertEquals(1, params.size()); ParameterType tmp = params.get(0); assertEquals("foo", tmp.getName()); assertEquals("bar", tmp.getValue()); }
@Test public void testCQLExpressionParameterLiterals() { ParameterExpressionType param1 = wfs20Factory.createParameterExpressionType(); param1.setName("foo"); desc.getParameter().add(param1); ParameterMappingExpressionValue paramMapping = new ParameterMappingExpressionValue(); paramMapping.setParameterName("foo"); paramMapping.setExpressionLanguage("CQL"); paramMapping.setExpression("numberFormat('0.0', 1+1*2)"); config.getStoredQueryParameterMappings().add(paramMapping); ParameterTypeFactory factory = new ParameterTypeFactory(config, desc, featureType); Map<String, String> viewParams = new HashMap<String, String>(); List<ParameterType> params = factory.buildStoredQueryParameters(viewParams, null); assertEquals(1, params.size()); ParameterType tmp = params.get(0); assertEquals("foo", tmp.getName()); assertEquals("3.0", tmp.getValue()); }
@Test public void testCQLExpressionParameterContextBboxMappings() { desc.getParameter().addAll(Arrays.asList( createParam("param1"), createParam("param2"), createParam("param3"), createParam("param4"))); config.getStoredQueryParameterMappings().addAll(Arrays.asList( createBboxExpressionParam("param1", "bboxMinX"), createBboxExpressionParam("param2", "bboxMinY"), createBboxExpressionParam("param3", "bboxMaxX"), createBboxExpressionParam("param4", "bboxMaxY"))); ParameterTypeFactory factory = new ParameterTypeFactory(config, desc, featureType); Map<String, String> viewParams = new HashMap<String, String>(); Filter f = new FilterFactoryImpl().bbox("nada", -10.0, -5.0, 10.0, 5.0, "WGS:84"); List<ParameterType> params = factory.buildStoredQueryParameters(viewParams, f); assertEquals(4, params.size()); ParameterType tmp = params.get(0); assertEquals("param1", tmp.getName()); assertEquals("-10.0", tmp.getValue()); tmp = params.get(1); assertEquals("param2", tmp.getName()); assertEquals("-5.0", tmp.getValue()); tmp = params.get(2); assertEquals("param3", tmp.getName()); assertEquals("10.0", tmp.getValue()); tmp = params.get(3); assertEquals("param4", tmp.getName()); assertEquals("5.0", tmp.getValue()); }
@Test public void testCQLExpressionSRS() { ParameterExpressionType param1 = wfs20Factory.createParameterExpressionType(); param1.setName("foo"); desc.getParameter().add(param1); ParameterMappingExpressionValue paramMapping = new ParameterMappingExpressionValue(); paramMapping.setParameterName("foo"); paramMapping.setExpressionLanguage("CQL"); paramMapping.setExpression("defaultSRS"); config.getStoredQueryParameterMappings().add(paramMapping); ParameterTypeFactory factory = new ParameterTypeFactory(config, desc, featureType); Map<String, String> viewParams = new HashMap<String, String>(); List<ParameterType> params = factory.buildStoredQueryParameters(viewParams, null); assertEquals(1, params.size()); ParameterType tmp = params.get(0); assertEquals("foo", tmp.getName()); assertEquals("EPSG:1234", tmp.getValue()); }
@Test public void testCQLExpressionViewParamMapping() { ParameterExpressionType param1 = wfs20Factory.createParameterExpressionType(); param1.setName("foo"); desc.getParameter().add(param1); ParameterMappingExpressionValue paramMapping = new ParameterMappingExpressionValue(); paramMapping.setParameterName("foo"); paramMapping.setExpressionLanguage("CQL"); paramMapping.setExpression("viewparam:mapped"); config.getStoredQueryParameterMappings().add(paramMapping); ParameterTypeFactory factory = new ParameterTypeFactory(config, desc, featureType); Map<String, String> viewParams = new HashMap<String, String>(); viewParams.put("mapped", "stuff"); List<ParameterType> params = factory.buildStoredQueryParameters(viewParams, null); assertEquals(1, params.size()); ParameterType tmp = params.get(0); assertEquals("foo", tmp.getName()); assertEquals("stuff", tmp.getValue()); }
@Test public void testCQLExpressionStringConcatenation() { ParameterExpressionType param1 = wfs20Factory.createParameterExpressionType(); param1.setName("foo"); desc.getParameter().add(param1); ParameterMappingExpressionValue paramMapping = new ParameterMappingExpressionValue(); paramMapping.setParameterName("foo"); paramMapping.setExpressionLanguage("CQL"); paramMapping.setExpression("concatenate(numberFormat('0.0', 1+1*2), ',10')"); config.getStoredQueryParameterMappings().add(paramMapping); ParameterTypeFactory factory = new ParameterTypeFactory(config, desc, featureType); Map<String, String> viewParams = new HashMap<String, String>(); List<ParameterType> params = factory.buildStoredQueryParameters(viewParams, null); assertEquals(1, params.size()); ParameterType tmp = params.get(0); assertEquals("foo", tmp.getName()); assertEquals("3.0,10", tmp.getValue()); }