This commit is contained in:
Giancarlo Panichi 2019-06-13 09:49:21 +00:00
parent 924ecdbdb9
commit 54dacbf31c
1 changed files with 182 additions and 151 deletions

View File

@ -15,23 +15,6 @@ import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import net.opengis.ows.x11.OperationDocument.Operation;
import net.opengis.wps.x100.CapabilitiesDocument;
import net.opengis.wps.x100.ComplexDataType;
import net.opengis.wps.x100.ExecuteDocument;
import net.opengis.wps.x100.ExecuteResponseDocument;
import net.opengis.wps.x100.ExecuteResponseDocument.ExecuteResponse.ProcessOutputs;
import net.opengis.wps.x100.InputDescriptionType;
import net.opengis.wps.x100.InputType;
import net.opengis.wps.x100.OutputDataType;
import net.opengis.wps.x100.OutputDescriptionType;
import net.opengis.wps.x100.ProcessBriefType;
import net.opengis.wps.x100.ProcessDescriptionType;
import net.opengis.wps.x100.ResponseDocumentType;
import net.opengis.wps.x100.StatusType;
import net.opengis.wps.x100.SupportedComplexDataInputType;
import net.opengis.wps.x100.impl.ExecuteResponseDocumentImpl;
import org.apache.xmlbeans.XmlString; import org.apache.xmlbeans.XmlString;
import org.gcube.data.analysis.dataminermanagercl.server.dmservice.wps.ProcessInformations; import org.gcube.data.analysis.dataminermanagercl.server.dmservice.wps.ProcessInformations;
import org.gcube.data.analysis.dataminermanagercl.server.dmservice.wps.ResponseWPS; import org.gcube.data.analysis.dataminermanagercl.server.dmservice.wps.ResponseWPS;
@ -70,6 +53,23 @@ import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
import net.opengis.ows.x11.OperationDocument.Operation;
import net.opengis.wps.x100.CapabilitiesDocument;
import net.opengis.wps.x100.ComplexDataType;
import net.opengis.wps.x100.ExecuteDocument;
import net.opengis.wps.x100.ExecuteResponseDocument;
import net.opengis.wps.x100.ExecuteResponseDocument.ExecuteResponse.ProcessOutputs;
import net.opengis.wps.x100.InputDescriptionType;
import net.opengis.wps.x100.InputType;
import net.opengis.wps.x100.OutputDataType;
import net.opengis.wps.x100.OutputDescriptionType;
import net.opengis.wps.x100.ProcessBriefType;
import net.opengis.wps.x100.ProcessDescriptionType;
import net.opengis.wps.x100.ResponseDocumentType;
import net.opengis.wps.x100.StatusType;
import net.opengis.wps.x100.SupportedComplexDataInputType;
import net.opengis.wps.x100.impl.ExecuteResponseDocumentImpl;
/** /**
* Client 4 WPS Service * Client 4 WPS Service
* *
@ -224,12 +224,11 @@ public class SClient4WPS extends SClient {
} }
} }
@Override @Override
public Operator getOperatorById(String id) throws Exception { public Operator getOperatorById(String id) throws Exception {
return getOperatorById(id, false); return getOperatorById(id, false);
} }
@Override @Override
public Operator getOperatorById(String id, boolean refresh) throws Exception { public Operator getOperatorById(String id, boolean refresh) throws Exception {
if (id == null || id.isEmpty()) { if (id == null || id.isEmpty()) {
@ -278,18 +277,18 @@ public class SClient4WPS extends SClient {
public List<OperatorsClassification> getOperatorsClassifications() throws ServiceException { public List<OperatorsClassification> getOperatorsClassifications() throws ServiceException {
return getOperatorsClassifications(false); return getOperatorsClassifications(false);
} }
@Override @Override
public List<OperatorsClassification> getOperatorsClassifications(boolean refresh) throws ServiceException{ public List<OperatorsClassification> getOperatorsClassifications(boolean refresh) throws ServiceException {
logger.debug("getOperatorsClassifications: "+refresh); logger.debug("getOperatorsClassifications: " + refresh);
LinkedHashMap<String, String> operatorsToCategoriesMap = new LinkedHashMap<>(); LinkedHashMap<String, String> operatorsToCategoriesMap = new LinkedHashMap<>();
LinkedHashMap<String, List<Operator>> categoriesToOperatorsMap = new LinkedHashMap<>(); LinkedHashMap<String, List<Operator>> categoriesToOperatorsMap = new LinkedHashMap<>();
if(refresh){ if (refresh) {
logger.debug("Clear Processes Descriptions: Refresh"); logger.debug("Clear Processes Descriptions: Refresh");
process.clear(); process.clear();
} }
requestCapability(refresh); requestCapability(refresh);
if (processesBriefs == null || processesDescriptionType == null) { if (processesBriefs == null || processesDescriptionType == null) {
throw new ServiceException("Algorithms WPS not available!"); throw new ServiceException("Algorithms WPS not available!");
@ -373,7 +372,6 @@ public class SClient4WPS extends SClient {
logger.debug("OperatorClass: " + operatorsClass); logger.debug("OperatorClass: " + operatorsClass);
return operatorsClass; return operatorsClass;
} }
private ProcessInformations describeProcess(String processId) throws ServiceException { private ProcessInformations describeProcess(String processId) throws ServiceException {
return describeProcess(processId, null); return describeProcess(processId, null);
@ -429,7 +427,7 @@ public class SClient4WPS extends SClient {
return processInformations; return processInformations;
} catch (Throwable e) { } catch (Throwable e) {
logger.error(e.getLocalizedMessage(),e); logger.error(e.getLocalizedMessage(), e);
throw new ServiceException(e.getLocalizedMessage(), e); throw new ServiceException(e.getLocalizedMessage(), e);
} finally { } finally {
wpsClient.disconnect(wpsProcessingServlet); wpsClient.disconnect(wpsProcessingServlet);
@ -440,13 +438,13 @@ public class SClient4WPS extends SClient {
SClient4WPSSession wpsClient = null; SClient4WPSSession wpsClient = null;
processesDescriptionType = null; processesDescriptionType = null;
processesBriefs = null; processesBriefs = null;
logger.debug("Request Capability: refresh="+refresh); logger.debug("Request Capability: refresh=" + refresh);
try { try {
wpsClient = createWPSClientSession(); wpsClient = createWPSClientSession();
wpsClient.connect(wpsProcessingServlet,refresh); wpsClient.connect(wpsProcessingServlet, refresh);
processesDescriptionType = wpsClient.getAllProcessDescriptions(wpsProcessingServlet); processesDescriptionType = wpsClient.getAllProcessDescriptions(wpsProcessingServlet);
@ -483,8 +481,13 @@ public class SClient4WPS extends SClient {
for (OutputDescriptionType odt : odts) { for (OutputDescriptionType odt : odts) {
// executeBuilder.setMimeTypeForOutput("text/xml", // executeBuilder.setMimeTypeForOutput("text/xml",
// "result"); // "result");
if (odt.isSetComplexOutput())
if (odt.isSetComplexOutput()) {
executeBuilder.setMimeTypeForOutput("text/xml", odt.getIdentifier().getStringValue()); executeBuilder.setMimeTypeForOutput("text/xml", odt.getIdentifier().getStringValue());
if (odt.getIdentifier().getStringValue().compareTo("non_deterministic_output") != 0) {
executeBuilder.setAsReference(odt.getIdentifier().getStringValue(), true);
}
}
} }
} catch (Exception e) { } catch (Exception e) {
logger.debug("Execute Process-> Warning, no xml structured objects will be provided: " logger.debug("Execute Process-> Warning, no xml structured objects will be provided: "
@ -506,6 +509,14 @@ public class SClient4WPS extends SClient {
documentType.setStoreExecuteResponse(true); documentType.setStoreExecuteResponse(true);
documentType.setStatus(true); documentType.setStatus(true);
documentType.setLineage(false); documentType.setLineage(false);
/*
* DocumentOutputDefinitionType[]
* documentOutputDefinitionType=documentType.getOutputArray();
* for(DocumentOutputDefinitionType
* dodt:documentOutputDefinitionType){
* dodt.getIdentifier().getStringValue()
* dodt.setAsReference(true); }
*/
execute.getExecute().getResponseForm().setResponseDocument(documentType); execute.getExecute().getResponseForm().setResponseDocument(documentType);
} }
Object responseObject = wpsClient.execute(wpsProcessingServlet, execute); Object responseObject = wpsClient.execute(wpsProcessingServlet, execute);
@ -948,7 +959,7 @@ public class SClient4WPS extends SClient {
return statusLocation; return statusLocation;
} catch (Throwable e) { } catch (Throwable e) {
logger.error(e.getLocalizedMessage(),e); logger.error(e.getLocalizedMessage(), e);
throw new ServiceException(e.getLocalizedMessage(), e); throw new ServiceException(e.getLocalizedMessage(), e);
} }
} }
@ -1060,7 +1071,7 @@ public class SClient4WPS extends SClient {
} }
} catch (Throwable e) { } catch (Throwable e) {
logger.error("MonitorProcess: " + e.getLocalizedMessage(),e); logger.error("MonitorProcess: " + e.getLocalizedMessage(), e);
throw new ServiceException(e.getLocalizedMessage(), e); throw new ServiceException(e.getLocalizedMessage(), e);
} finally { } finally {
wpsClient.disconnect(wpsProcessingServlet); wpsClient.disconnect(wpsProcessingServlet);
@ -1109,135 +1120,155 @@ public class SClient4WPS extends SClient {
for (OutputDataType out : outputData) { for (OutputDataType out : outputData) {
String outputID = out.getIdentifier().getStringValue(); String outputID = out.getIdentifier().getStringValue();
String value = ""; logger.debug("Output Identifier: " + outputID);
if (out.getData().isSetLiteralData()) { if (out.isSetData()) {
value = out.getData().getLiteralData().getStringValue(); logger.debug("Is Data");
Parameter paramLiteral = outputParameters.get(outputID); readOutputOfTypeData(outputParameters, outputResource, out, outputID);
if (paramLiteral != null) { } else {
paramLiteral.setValue(value); if(out.isSetReference()){
logger.debug("Is Reference: "+out.getReference());
logger.debug("This parameter is not recovered");
} else {
logger.debug("Unknow type, this parameter is not recovered");
}
}
}
}
}
private void readOutputOfTypeData(Map<String, Parameter> outputParameters, Map<String, Resource> outputResource,
OutputDataType out, String outputID) {
String value = "";
if (out.getData().isSetLiteralData()) {
logger.debug("Is Literal Data");
value = out.getData().getLiteralData().getStringValue();
Parameter paramLiteral = outputParameters.get(outputID);
if (paramLiteral != null) {
paramLiteral.setValue(value);
logger.debug("Assigning value: " + value + " to output named: " + outputID);
Resource resource = new ObjectResource(outputID, paramLiteral.getName(),
paramLiteral.getDescription(), paramLiteral.getValue());
outputResource.put(outputID, resource);
}
} else {
if (out.getData().isSetComplexData()) {
logger.debug("Is Complex Data");
if (out.getReference() != null) {
value = out.getReference().getHref();
Parameter paramComplexData = outputParameters.get(outputID);
if (paramComplexData != null) {
paramComplexData.setValue(value);
logger.debug("Assigning value: " + value + " to output named: " + outputID); logger.debug("Assigning value: " + value + " to output named: " + outputID);
Resource resource = new ObjectResource(outputID, paramLiteral.getName(), Resource resource = new ObjectResource(outputID, paramComplexData.getName(),
paramLiteral.getDescription(), paramLiteral.getValue()); paramComplexData.getDescription(), paramComplexData.getValue());
outputResource.put(outputID, resource); outputResource.put(outputID, resource);
} }
} else { } else
if (out.getData().isSetComplexData()) { // remove the element name, which is not useful
if (out.getReference() != null) { outputParameters.remove(outputID);
value = out.getReference().getHref();
Parameter paramComplexData = outputParameters.get(outputID);
if (paramComplexData != null) {
paramComplexData.setValue(value);
logger.debug("Assigning value: " + value + " to output named: " + outputID);
Resource resource = new ObjectResource(outputID, paramComplexData.getName(),
paramComplexData.getDescription(), paramComplexData.getValue());
outputResource.put(outputID, resource);
}
} else
// remove the element name, which is not useful
outputParameters.remove(outputID);
ComplexDataType cdt = out.getData().getComplexData(); ComplexDataType cdt = out.getData().getComplexData();
LinkedHashMap<String, ResponseWPS> urls = retrieveURLsFromWPSResponse(cdt); LinkedHashMap<String, ResponseWPS> urls = retrieveURLsFromWPSResponse(cdt);
for (String key : urls.keySet()) { for (String key : urls.keySet()) {
logger.debug("Adding OBJ:" + key); logger.debug("Adding OBJ:" + key);
ResponseWPS responseWPS = urls.get(key); ResponseWPS responseWPS = urls.get(key);
ObjectParameter objP = new ObjectParameter(key, responseWPS.getDescription(), ObjectParameter objP = new ObjectParameter(key, responseWPS.getDescription(),
String.class.getName(), " "); String.class.getName(), " ");
objP.setValue(responseWPS.getData()); objP.setValue(responseWPS.getData());
logger.debug("ObjectParameter: " + objP); logger.debug("ObjectParameter: " + objP);
outputParameters.put(key, objP); outputParameters.put(key, objP);
if (responseWPS != null && responseWPS.getMimeType() != null) { if (responseWPS != null && responseWPS.getMimeType() != null) {
Resource resource; Resource resource;
switch (responseWPS.getMimeType()) { switch (responseWPS.getMimeType()) {
case "image/bmp": case "image/bmp":
case "image/gif": case "image/gif":
case "image/jpeg": case "image/jpeg":
case "image/png": case "image/png":
resource = new ImageResource(key, responseWPS.getDescription(), resource = new ImageResource(key, responseWPS.getDescription(),
responseWPS.getDescription(), responseWPS.getData(), responseWPS.getDescription(), responseWPS.getData(),
responseWPS.getMimeType()); responseWPS.getMimeType());
outputResource.put(key, resource);
break;
case "text/csv":
if (responseWPS.getData() != null && !responseWPS.getData().isEmpty()) {
if (responseWPS.getData().startsWith("http:")
|| responseWPS.getData().startsWith("https:")
|| responseWPS.getData().startsWith("smp:")) {
Parameter complexParameter = outputParameters.get(outputID);
if (complexParameter instanceof FileParameter) {
FileParameter fileParameter = (FileParameter) complexParameter;
if (fileParameter.isNetcdf()) {
resource = new FileResource(key, responseWPS.getDescription(),
responseWPS.getDescription(), responseWPS.getData(),
responseWPS.getMimeType(), true);
} else {
resource = new FileResource(key, responseWPS.getDescription(),
responseWPS.getDescription(), responseWPS.getData(),
responseWPS.getMimeType(), false);
}
} else {
resource = new FileResource(key, responseWPS.getDescription(),
responseWPS.getDescription(), responseWPS.getData(),
responseWPS.getMimeType(), false);
}
outputResource.put(key, resource);
} else {
resource = new ObjectResource(key, responseWPS.getDescription(),
responseWPS.getDescription(), responseWPS.getData());
outputResource.put(key, resource); outputResource.put(key, resource);
break;
case "text/csv":
if (responseWPS.getData() != null && !responseWPS.getData().isEmpty()) {
if (responseWPS.getData().startsWith("http:")
|| responseWPS.getData().startsWith("https:")
|| responseWPS.getData().startsWith("smp:")) {
Parameter complexParameter = outputParameters.get(outputID);
if (complexParameter instanceof FileParameter) {
FileParameter fileParameter = (FileParameter) complexParameter;
if (fileParameter.isNetcdf()) {
resource = new FileResource(key, responseWPS.getDescription(),
responseWPS.getDescription(), responseWPS.getData(),
responseWPS.getMimeType(), true);
} else {
resource = new FileResource(key, responseWPS.getDescription(),
responseWPS.getDescription(), responseWPS.getData(),
responseWPS.getMimeType(), false);
}
} else {
resource = new FileResource(key, responseWPS.getDescription(),
responseWPS.getDescription(), responseWPS.getData(),
responseWPS.getMimeType(), false);
}
outputResource.put(key, resource);
} else {
resource = new ObjectResource(key, responseWPS.getDescription(),
responseWPS.getDescription(), responseWPS.getData());
outputResource.put(key, resource);
}
} else {
resource = new ObjectResource(key, responseWPS.getDescription(),
responseWPS.getDescription(), responseWPS.getData());
outputResource.put(key, resource);
}
break;
default:
if (responseWPS.getData() != null && !responseWPS.getData().isEmpty()) {
if (responseWPS.getData().startsWith("http:")
|| responseWPS.getData().startsWith("https:")
|| responseWPS.getData().startsWith("smp:")) {
Parameter complexParameter = outputParameters.get(outputID);
if (complexParameter instanceof FileParameter) {
FileParameter fileParameter = (FileParameter) complexParameter;
if (fileParameter.isNetcdf()) {
resource = new FileResource(key, responseWPS.getDescription(),
responseWPS.getDescription(), responseWPS.getData(),
responseWPS.getMimeType(), true);
} else {
resource = new FileResource(key, responseWPS.getDescription(),
responseWPS.getDescription(), responseWPS.getData(),
responseWPS.getMimeType(), false);
}
} else {
resource = new FileResource(key, responseWPS.getDescription(),
responseWPS.getDescription(), responseWPS.getData(),
responseWPS.getMimeType(), false);
}
outputResource.put(key, resource);
} else {
resource = new ObjectResource(key, responseWPS.getDescription(),
responseWPS.getDescription(), responseWPS.getData());
outputResource.put(key, resource);
}
} else {
resource = new ObjectResource(key, responseWPS.getDescription(),
responseWPS.getDescription(), responseWPS.getData());
outputResource.put(key, resource);
}
break;
} }
} else {
resource = new ObjectResource(key, responseWPS.getDescription(),
responseWPS.getDescription(), responseWPS.getData());
outputResource.put(key, resource);
} }
break;
default:
if (responseWPS.getData() != null && !responseWPS.getData().isEmpty()) {
if (responseWPS.getData().startsWith("http:")
|| responseWPS.getData().startsWith("https:")
|| responseWPS.getData().startsWith("smp:")) {
Parameter complexParameter = outputParameters.get(outputID);
if (complexParameter instanceof FileParameter) {
FileParameter fileParameter = (FileParameter) complexParameter;
if (fileParameter.isNetcdf()) {
resource = new FileResource(key, responseWPS.getDescription(),
responseWPS.getDescription(), responseWPS.getData(),
responseWPS.getMimeType(), true);
} else {
resource = new FileResource(key, responseWPS.getDescription(),
responseWPS.getDescription(), responseWPS.getData(),
responseWPS.getMimeType(), false);
}
} else {
resource = new FileResource(key, responseWPS.getDescription(),
responseWPS.getDescription(), responseWPS.getData(),
responseWPS.getMimeType(), false);
}
outputResource.put(key, resource);
} else {
resource = new ObjectResource(key, responseWPS.getDescription(),
responseWPS.getDescription(), responseWPS.getData());
outputResource.put(key, resource);
}
} else {
resource = new ObjectResource(key, responseWPS.getDescription(),
responseWPS.getDescription(), responseWPS.getData());
outputResource.put(key, resource);
}
break;
} }
} else {
value = out.getData().getLiteralData().getStringValue();
} }
} }
} else {
logger.debug("Not is Literal or Complex");
value = out.getData().getLiteralData().getStringValue();
} }
} }
} }