WpsProductionRequestConverter { public ProductionRequest loadProductionRequest(String userName) throws IOException { Element executeElement = document.getRootElement(); Namespace wps = executeElement.getNamespace("wps"); Namespace ows = executeElement.getNamespace("ows"); Namespace xlink = executeElement.getNamespace("xlink"); String processIdentifier = executeElement.getChildText("Identifier", ows); Element dataInputs = executeElement.getChild("DataInputs", wps); @SuppressWarnings({"unchecked"}) List<Element> inputElements = (List<Element>) dataInputs.getChildren("Input", wps); HashMap<String, String> parameterMap = new HashMap<String, String>(); for (Element inputElement : inputElements) { String parameterName = inputElement.getChildText("Identifier", ows).trim(); String parameterValue = null; Element dataElement = inputElement.getChild("Data", wps); Element literalDataElement = dataElement.getChild("LiteralData", wps); if (literalDataElement != null) { parameterValue = getStringFromElement(literalDataElement); } else { Element complexDataElement = dataElement.getChild("ComplexData", wps); if (complexDataElement != null) { parameterValue = getStringFromElement(complexDataElement); } else { Element referenceElement = dataElement.getChild("Reference", wps); if (referenceElement != null) { parameterValue = referenceElement.getAttributeValue("href", xlink); } } } if (parameterValue != null) { parameterValue = parameterValue.trim(); if (parameterMap.containsKey(parameterName)) { parameterValue = String.format("%s,%s", parameterMap.get(parameterName), parameterValue); } parameterMap.put(parameterName, parameterValue); } } return new ProductionRequest(processIdentifier, userName, parameterMap); } WpsProductionRequestConverter(String xml);  WpsProductionRequestConverter(Reader reader); ProductionRequest loadProductionRequest(String userName);  }
@Test public void testConversionToMap() throws Exception { InputStream resourceAsStream = getClass().getResourceAsStream("ma-request.xml"); InputStreamReader inputStreamReader = new InputStreamReader(resourceAsStream); ProductionRequest productionRequest = new WpsProductionRequestConverter(inputStreamReader).loadProductionRequest("testuser"); assertNotNull(productionRequest); assertEquals("MA", productionRequest.getProductionType()); assertNotNull(productionRequest.getUserName()); assertEquals("testuser", productionRequest.getUserName()); Map<String, String> parameters = productionRequest.getParameters(); assertNotNull(parameters); assertEquals(10, parameters.size()); assertTrue(parameters.containsKey("calvalus.processor.package")); assertEquals("beam-meris-radiometry", parameters.get("calvalus.processor.package")); assertTrue(parameters.containsKey("calvalus.processor.version")); assertEquals("1.0", parameters.get("calvalus.processor.version")); assertTrue(parameters.containsKey("calvalus.input")); String inputValue = parameters.get("calvalus.input"); assertTrue(inputValue.contains(",")); String[] splits = inputValue.split(","); assertEquals(2, splits.length); assertEquals("hdfs: assertEquals("hdfs: assertTrue(parameters.containsKey("calvalus.l2.parameters")); String l2Parameters = parameters.get("calvalus.l2.parameters"); assertTrue(l2Parameters.startsWith("<parameters>")); assertTrue(l2Parameters.endsWith("</parameters>")); assertTrue(l2Parameters.contains("<doSmile>true</doSmile>")); assertTrue(l2Parameters.contains("<reproVersion>AUTO_DETECT</reproVersion>")); assertTrue(parameters.containsKey("calvalus.output.compression")); assertNotNull(parameters.get("calvalus.output.compression")); assertEquals("", parameters.get("calvalus.output.compression")); assertEquals("BEAM-DIMAP", parameters.get("calvalus.input.format")); assertNull(productionRequest.getRegionGeometry(null)); assertNotNull(parameters.get("calvalus.plainText.parameter")); String expectedPlainText = "<parameters>\nThis is a multiline\nTextfield\n</parameters>"; assertEquals(expectedPlainText, parameters.get("calvalus.plainText.parameter")); }