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.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.gcube.data.analysis.dataminermanagercl.server.dmservice.wps.ProcessInformations;
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.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
*
@ -224,12 +224,11 @@ public class SClient4WPS extends SClient {
}
}
@Override
public Operator getOperatorById(String id) throws Exception {
return getOperatorById(id, false);
}
@Override
public Operator getOperatorById(String id, boolean refresh) throws Exception {
if (id == null || id.isEmpty()) {
@ -278,18 +277,18 @@ public class SClient4WPS extends SClient {
public List<OperatorsClassification> getOperatorsClassifications() throws ServiceException {
return getOperatorsClassifications(false);
}
@Override
public List<OperatorsClassification> getOperatorsClassifications(boolean refresh) throws ServiceException{
logger.debug("getOperatorsClassifications: "+refresh);
public List<OperatorsClassification> getOperatorsClassifications(boolean refresh) throws ServiceException {
logger.debug("getOperatorsClassifications: " + refresh);
LinkedHashMap<String, String> operatorsToCategoriesMap = new LinkedHashMap<>();
LinkedHashMap<String, List<Operator>> categoriesToOperatorsMap = new LinkedHashMap<>();
if(refresh){
if (refresh) {
logger.debug("Clear Processes Descriptions: Refresh");
process.clear();
}
requestCapability(refresh);
if (processesBriefs == null || processesDescriptionType == null) {
throw new ServiceException("Algorithms WPS not available!");
@ -373,7 +372,6 @@ public class SClient4WPS extends SClient {
logger.debug("OperatorClass: " + operatorsClass);
return operatorsClass;
}
private ProcessInformations describeProcess(String processId) throws ServiceException {
return describeProcess(processId, null);
@ -429,7 +427,7 @@ public class SClient4WPS extends SClient {
return processInformations;
} catch (Throwable e) {
logger.error(e.getLocalizedMessage(),e);
logger.error(e.getLocalizedMessage(), e);
throw new ServiceException(e.getLocalizedMessage(), e);
} finally {
wpsClient.disconnect(wpsProcessingServlet);
@ -440,13 +438,13 @@ public class SClient4WPS extends SClient {
SClient4WPSSession wpsClient = null;
processesDescriptionType = null;
processesBriefs = null;
logger.debug("Request Capability: refresh="+refresh);
logger.debug("Request Capability: refresh=" + refresh);
try {
wpsClient = createWPSClientSession();
wpsClient.connect(wpsProcessingServlet,refresh);
wpsClient.connect(wpsProcessingServlet, refresh);
processesDescriptionType = wpsClient.getAllProcessDescriptions(wpsProcessingServlet);
@ -483,8 +481,13 @@ public class SClient4WPS extends SClient {
for (OutputDescriptionType odt : odts) {
// executeBuilder.setMimeTypeForOutput("text/xml",
// "result");
if (odt.isSetComplexOutput())
if (odt.isSetComplexOutput()) {
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) {
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.setStatus(true);
documentType.setLineage(false);
/*
* DocumentOutputDefinitionType[]
* documentOutputDefinitionType=documentType.getOutputArray();
* for(DocumentOutputDefinitionType
* dodt:documentOutputDefinitionType){
* dodt.getIdentifier().getStringValue()
* dodt.setAsReference(true); }
*/
execute.getExecute().getResponseForm().setResponseDocument(documentType);
}
Object responseObject = wpsClient.execute(wpsProcessingServlet, execute);
@ -948,7 +959,7 @@ public class SClient4WPS extends SClient {
return statusLocation;
} catch (Throwable e) {
logger.error(e.getLocalizedMessage(),e);
logger.error(e.getLocalizedMessage(), e);
throw new ServiceException(e.getLocalizedMessage(), e);
}
}
@ -1060,7 +1071,7 @@ public class SClient4WPS extends SClient {
}
} catch (Throwable e) {
logger.error("MonitorProcess: " + e.getLocalizedMessage(),e);
logger.error("MonitorProcess: " + e.getLocalizedMessage(), e);
throw new ServiceException(e.getLocalizedMessage(), e);
} finally {
wpsClient.disconnect(wpsProcessingServlet);
@ -1109,135 +1120,155 @@ public class SClient4WPS extends SClient {
for (OutputDataType out : outputData) {
String outputID = out.getIdentifier().getStringValue();
String value = "";
if (out.getData().isSetLiteralData()) {
value = out.getData().getLiteralData().getStringValue();
Parameter paramLiteral = outputParameters.get(outputID);
if (paramLiteral != null) {
paramLiteral.setValue(value);
logger.debug("Output Identifier: " + outputID);
if (out.isSetData()) {
logger.debug("Is Data");
readOutputOfTypeData(outputParameters, outputResource, out, outputID);
} else {
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);
Resource resource = new ObjectResource(outputID, paramLiteral.getName(),
paramLiteral.getDescription(), paramLiteral.getValue());
Resource resource = new ObjectResource(outputID, paramComplexData.getName(),
paramComplexData.getDescription(), paramComplexData.getValue());
outputResource.put(outputID, resource);
}
} else {
if (out.getData().isSetComplexData()) {
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);
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);
} else
// remove the element name, which is not useful
outputParameters.remove(outputID);
ComplexDataType cdt = out.getData().getComplexData();
LinkedHashMap<String, ResponseWPS> urls = retrieveURLsFromWPSResponse(cdt);
ComplexDataType cdt = out.getData().getComplexData();
LinkedHashMap<String, ResponseWPS> urls = retrieveURLsFromWPSResponse(cdt);
for (String key : urls.keySet()) {
logger.debug("Adding OBJ:" + key);
ResponseWPS responseWPS = urls.get(key);
ObjectParameter objP = new ObjectParameter(key, responseWPS.getDescription(),
String.class.getName(), " ");
objP.setValue(responseWPS.getData());
logger.debug("ObjectParameter: " + objP);
outputParameters.put(key, objP);
if (responseWPS != null && responseWPS.getMimeType() != null) {
Resource resource;
switch (responseWPS.getMimeType()) {
case "image/bmp":
case "image/gif":
case "image/jpeg":
case "image/png":
resource = new ImageResource(key, responseWPS.getDescription(),
responseWPS.getDescription(), responseWPS.getData(),
responseWPS.getMimeType());
for (String key : urls.keySet()) {
logger.debug("Adding OBJ:" + key);
ResponseWPS responseWPS = urls.get(key);
ObjectParameter objP = new ObjectParameter(key, responseWPS.getDescription(),
String.class.getName(), " ");
objP.setValue(responseWPS.getData());
logger.debug("ObjectParameter: " + objP);
outputParameters.put(key, objP);
if (responseWPS != null && responseWPS.getMimeType() != null) {
Resource resource;
switch (responseWPS.getMimeType()) {
case "image/bmp":
case "image/gif":
case "image/jpeg":
case "image/png":
resource = new ImageResource(key, responseWPS.getDescription(),
responseWPS.getDescription(), responseWPS.getData(),
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);
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();
}
}
}