Improve GisClient implementation Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-gis/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-gis/commit/92947edc Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-gis/tree/92947edc Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-gis/diff/92947edc
Branch: refs/heads/taverna2 Commit: 92947edc11cf6b10c38e814e7b75dd6e0285dc21 Parents: 826c605 Author: edikaradumi <[email protected]> Authored: Sun Aug 7 18:40:48 2016 +0100 Committer: edikaradumi <[email protected]> Committed: Sun Aug 7 18:40:48 2016 +0100 ---------------------------------------------------------------------- .../org/apache/taverna/gis/GisActivity.java | 202 +++++++++++++------ .../gis/client/impl/GisClientNorthImpl.java | 10 +- 2 files changed, 145 insertions(+), 67 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-gis/blob/92947edc/apache-taverna-plugin-gis-activity/src/main/java/org/apache/taverna/gis/GisActivity.java ---------------------------------------------------------------------- diff --git a/apache-taverna-plugin-gis-activity/src/main/java/org/apache/taverna/gis/GisActivity.java b/apache-taverna-plugin-gis-activity/src/main/java/org/apache/taverna/gis/GisActivity.java index e7ac881..50eddc6 100644 --- a/apache-taverna-plugin-gis-activity/src/main/java/org/apache/taverna/gis/GisActivity.java +++ b/apache-taverna-plugin-gis-activity/src/main/java/org/apache/taverna/gis/GisActivity.java @@ -22,6 +22,11 @@ public class GisActivity extends AbstractAsynchronousActivity<GisActivityConfigu implements AsynchronousActivity<GisActivityConfigurationBean> { private GisActivityConfigurationBean configBean; + + private final static String ENCODING_PORT_POSTFIX = "_encoding"; + private final static String MIMETYPE_PORT_POSTFIX = "_mimeType"; + private final static String SCHEMA_PORT_POSTFIX = "_schema"; + private static Logger logger = Logger.getLogger(GisActivity.class); @@ -50,9 +55,10 @@ public class GisActivity extends AbstractAsynchronousActivity<GisActivityConfigu { if (inputPort instanceof ComplexPortDataDescriptor) { - addInput( inputPort.getName() + "_schema",0,true, null, null); - addInput(inputPort.getName() + "_encoding",0,true, null, null); - addInput(inputPort.getName() + "_mimetype",0,true, null, null); + // Depth is 0 as it only gets 1 value + addInput( inputPort.getName() + SCHEMA_PORT_POSTFIX,0,true, null, null); + addInput(inputPort.getName() + ENCODING_PORT_POSTFIX,0,true, null, null); + addInput(inputPort.getName() + MIMETYPE_PORT_POSTFIX,0,true, null, null); } addInput(inputPort.getName(),inputPort.getDepth(),inputPort.isAllowLiteralValues(),null, inputPort.getTranslatedElementType()); @@ -65,9 +71,9 @@ public class GisActivity extends AbstractAsynchronousActivity<GisActivityConfigu if (outputPort instanceof ComplexPortDataDescriptor) { - addOutput(outputPort.getName() + "_schema",0); - addOutput(outputPort.getName() + "_encoding",0); - addOutput(outputPort.getName() + "_mimetype",0); + addOutput(outputPort.getName() + SCHEMA_PORT_POSTFIX,0); + addOutput(outputPort.getName() + ENCODING_PORT_POSTFIX,0); + addOutput(outputPort.getName() + MIMETYPE_PORT_POSTFIX,0); } } @@ -88,74 +94,22 @@ public class GisActivity extends AbstractAsynchronousActivity<GisActivityConfigu try { - // prepare the execute object + // Get client instance IGisClient gisClient = GisClientFactory.getInstance().getGisClient( configBean.getOgcServiceUri().toString()); - HashMap<String, IPortDataDescriptor> serviceInputs = new HashMap<String, IPortDataDescriptor>(); - - for (IPortDataDescriptor activityInputPort : configBean.getInputPortDefinitions()) - { - // Optional inputs are not stored in the map if no value is provided, hence they are skipped - if (inputs.containsKey(activityInputPort.getName())) - { - Object inputValue = referenceService.renderIdentifier(inputs.get(activityInputPort.getName()), String.class, context); - - activityInputPort.setValue(inputValue); - - if (activityInputPort instanceof ComplexPortDataDescriptor) - { - //TODO: set format - ComplexDataFormat complexFormat = new ComplexDataFormat(); - - complexFormat.setEncoding(null); - //complexFormat.setMimeType("application/wkt"); - complexFormat.setSchema(null); - - ((ComplexPortDataDescriptor) activityInputPort).setComplexFormat(complexFormat); - } - - serviceInputs.put(activityInputPort.getName(), activityInputPort); - } - - } - - HashMap<String, IPortDataDescriptor> serviceOutputs = new HashMap<String, IPortDataDescriptor>(); + // Prepare inputs + HashMap<String, IPortDataDescriptor> serviceInputs = prepareInputs(inputs, context, referenceService); - for (IPortDataDescriptor activityOutputPort : configBean.getOutputPortDefinitions()) - { - if (activityOutputPort instanceof ComplexPortDataDescriptor) - { - //TODO: set format - ComplexDataFormat complexFormat = new ComplexDataFormat(); - - complexFormat.setEncoding(null); - //complexFormat.setMimeType("application/wkt"); - //complexFormat.setMimeType("text/plain"); - complexFormat.setSchema(null); - - ((ComplexPortDataDescriptor) activityOutputPort).setComplexFormat(complexFormat); - } - - serviceOutputs.put(activityOutputPort.getName(), activityOutputPort); - - } + // Prepare outputs + HashMap<String, IPortDataDescriptor> serviceOutputs = prepareOutputs(inputs, context, referenceService); // Execute process HashMap<String, String> serviceOutput = gisClient.executeProcess( configBean.getProcessIdentifier().toString(), serviceInputs, serviceOutputs); - outputs = new HashMap<String, T2Reference>(); - T2Reference simpleRef = null; - - for (Map.Entry<String, String> entry : serviceOutput.entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); - - simpleRef = referenceService.register(value, 0, true, context); - outputs.put(key, simpleRef); - - } + // Retrieve output + outputs = retrieveResponseOutput(context, referenceService, serviceOutput); } catch (Exception e) { logger.error("Error executing service/process: " @@ -172,5 +126,123 @@ public class GisActivity extends AbstractAsynchronousActivity<GisActivityConfigu public GisActivityConfigurationBean getConfiguration() { return this.configBean; } + + private Map<String, T2Reference> retrieveResponseOutput(InvocationContext context, + ReferenceService referenceService, HashMap<String, String> serviceOutput) + { + Map<String, T2Reference> outputs; + outputs = new HashMap<String, T2Reference>(); + T2Reference simpleRef = null; + + for (Map.Entry<String, String> entry : serviceOutput.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + + simpleRef = referenceService.register(value, 0, true, context); + outputs.put(key, simpleRef); + + } + return outputs; + } + + // Checks if input ports have defined the execution output format + private HashMap<String, IPortDataDescriptor> prepareOutputs(final Map<String, T2Reference> inputs, + InvocationContext context, ReferenceService referenceService) + { + + HashMap<String, IPortDataDescriptor> serviceOutputs = new HashMap<String, IPortDataDescriptor>(); + + for (IPortDataDescriptor activityOutputPort : configBean.getOutputPortDefinitions()) + { + if (activityOutputPort instanceof ComplexPortDataDescriptor) + { + ComplexDataFormat complexFormat = getComplexDataFormat( + inputs, referenceService, context, activityOutputPort.getName()); + + ((ComplexPortDataDescriptor) activityOutputPort).setComplexFormat(complexFormat); + +// // test format +// ComplexDataFormat complexFormat = new ComplexDataFormat(); +// +// complexFormat.setMimeType("text/xml"); +// complexFormat.setSchema("http://schemas.opengis.net/gml/2.1.2/feature.xsd"); +// +// ((ComplexPortDataDescriptor) activityOutputPort).setComplexFormat(complexFormat); + + } + + serviceOutputs.put(activityOutputPort.getName(), activityOutputPort); + + } + + return serviceOutputs; + } + + private HashMap<String, IPortDataDescriptor> prepareInputs(final Map<String, T2Reference> inputs, + InvocationContext context, ReferenceService referenceService) + { + HashMap<String, IPortDataDescriptor> serviceInputs = new HashMap<String, IPortDataDescriptor>(); + + for (IPortDataDescriptor activityInputPort : configBean.getInputPortDefinitions()) + { + // Optional inputs are not stored in the map if no value is provided, hence they are skipped + if (inputs.containsKey(activityInputPort.getName())) + { + Object inputValue = referenceService.renderIdentifier(inputs.get(activityInputPort.getName()), String.class, context); + + activityInputPort.setValue(inputValue); + + if (activityInputPort instanceof ComplexPortDataDescriptor) + { + ComplexDataFormat complexFormat = getComplexDataFormat( + inputs, referenceService, context, activityInputPort.getName()); + + ((ComplexPortDataDescriptor) activityInputPort).setComplexFormat(complexFormat); + +// ComplexDataFormat complexFormat = new ComplexDataFormat(); +// +// complexFormat.setMimeType("text/XML"); +// complexFormat.setSchema("http://schemas.opengis.net/gml/2.1.2/feature.xsd"); +// +// ((ComplexPortDataDescriptor) activityInputPort).setComplexFormat(complexFormat); + + } + + serviceInputs.put(activityInputPort.getName(), activityInputPort); + } + + } + return serviceInputs; + } + + private ComplexDataFormat getComplexDataFormat(Map<String, T2Reference> inputs, + ReferenceService referenceService, InvocationContext context, String activityPortName) + { + ComplexDataFormat complexFormat = new ComplexDataFormat(); + + complexFormat.setEncoding(getComplexDataPortValue(inputs, referenceService, context, + activityPortName, ENCODING_PORT_POSTFIX)); + + complexFormat.setMimeType(getComplexDataPortValue(inputs, referenceService, context, + activityPortName, MIMETYPE_PORT_POSTFIX)); + + complexFormat.setSchema(getComplexDataPortValue(inputs, referenceService, context, + activityPortName, SCHEMA_PORT_POSTFIX)); + + return complexFormat; + + } + + private String getComplexDataPortValue(Map<String, T2Reference> inputs, ReferenceService referenceService, + InvocationContext context, String portName, String portPostFix) + { + String value = null; + if (inputs.containsKey(portName + portPostFix)) + value = (String) referenceService.renderIdentifier( + inputs.get(portName + portPostFix), String.class, context); + + return value; + + } } http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-gis/blob/92947edc/apache-taverna-plugin-gis-client/src/main/java/org/apache/taverna/gis/client/impl/GisClientNorthImpl.java ---------------------------------------------------------------------- diff --git a/apache-taverna-plugin-gis-client/src/main/java/org/apache/taverna/gis/client/impl/GisClientNorthImpl.java b/apache-taverna-plugin-gis-client/src/main/java/org/apache/taverna/gis/client/impl/GisClientNorthImpl.java index 170213f..85e0e7f 100644 --- a/apache-taverna-plugin-gis-client/src/main/java/org/apache/taverna/gis/client/impl/GisClientNorthImpl.java +++ b/apache-taverna-plugin-gis-client/src/main/java/org/apache/taverna/gis/client/impl/GisClientNorthImpl.java @@ -40,6 +40,7 @@ import org.n52.wps.client.WPSClientException; import org.n52.wps.client.WPSClientSession; import net.opengis.ows.x11.LanguageStringType; +import net.opengis.ows.x11.impl.ExceptionReportDocumentImpl; import net.opengis.wps.x100.CapabilitiesDocument; import net.opengis.wps.x100.DataType; import net.opengis.wps.x100.InputDescriptionType; @@ -261,7 +262,7 @@ public class GisClientNorthImpl implements IGisClient { // Execute service responseObject = wpsClient.execute(serviceURI.toString(), execute); } catch (WPSClientException e) { - throw new Exception(e.getServerException().xmlText()); + throw new Exception(e.getServerException().xmlText(),e); } // Get outputs @@ -271,7 +272,7 @@ public class GisClientNorthImpl implements IGisClient { } private HashMap<String, String> getResponseOutput(ProcessDescriptionType processDescription, - ExecuteDocument execute, Object responseObject) throws WPSClientException { + ExecuteDocument execute, Object responseObject) throws Exception { HashMap<String, String> executeOutput = new HashMap<String, String>(); @@ -306,6 +307,10 @@ public class GisClientNorthImpl implements IGisClient { } } } + else if (responseObject instanceof ExceptionReportDocumentImpl) + { + throw new Exception("Error: " + ((ExceptionReportDocumentImpl)responseObject).getExceptionReport()); + } return executeOutput; @@ -347,6 +352,7 @@ public class GisClientNorthImpl implements IGisClient { // is supported by the service ComplexDataFormat selectedFormat = complexPort.getComplexFormat(); + // TODO: Check if contains should not be case sensitive if (!complexPort.getSupportedComplexFormats().contains(selectedFormat)) { logger.warn("Provided format not supported.");
