refs 4823: DataMiner - Preserve the order of the output (Example Bionym Local)
Task-Url: https://support.d4science.org/issues/4823 In the case of Check The Computation, now the interaface shows the input and output parameters in the order requested by the algorithm git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/data-miner-manager@130973 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
e310813cde
commit
f97c3bb15e
|
@ -47,6 +47,7 @@ import org.gcube.portlets.user.dataminermanager.shared.Constants;
|
|||
import org.gcube.portlets.user.dataminermanager.shared.data.OutputData;
|
||||
import org.gcube.portlets.user.dataminermanager.shared.data.computations.ComputationData;
|
||||
import org.gcube.portlets.user.dataminermanager.shared.data.computations.ComputationId;
|
||||
import org.gcube.portlets.user.dataminermanager.shared.data.computations.ComputationItemPropertiesValue;
|
||||
import org.gcube.portlets.user.dataminermanager.shared.data.computations.ComputationValue;
|
||||
import org.gcube.portlets.user.dataminermanager.shared.data.output.FileResource;
|
||||
import org.gcube.portlets.user.dataminermanager.shared.data.output.ImageResource;
|
||||
|
@ -1313,8 +1314,8 @@ public class SClient4WPS extends SClient {
|
|||
computationId.setOperatorId(operatorId);
|
||||
computationId.setOperatorName(operatorName);
|
||||
|
||||
LinkedHashMap<String, String> inputValueParameters = new LinkedHashMap<>();
|
||||
LinkedHashMap<String, String> outputValueParameters = new LinkedHashMap<>();
|
||||
ArrayList<ComputationItemPropertiesValue> inputParametersAsProperties = new ArrayList<>();
|
||||
ArrayList<ComputationItemPropertiesValue> outputParametersAsProperties = new ArrayList<>();
|
||||
|
||||
for (String key : computationProperties.keySet()) {
|
||||
if (key != null) {
|
||||
|
@ -1324,8 +1325,18 @@ public class SClient4WPS extends SClient {
|
|||
.substring(inputSeparatorIndex + 1);
|
||||
if (inputKey.compareToIgnoreCase("user.name") != 0
|
||||
&& inputKey.compareToIgnoreCase("scope") != 0) {
|
||||
inputValueParameters.put(inputKey,
|
||||
String inputOrder = key.substring(5,
|
||||
inputSeparatorIndex);
|
||||
Integer order;
|
||||
try {
|
||||
order = Integer.parseInt(inputOrder);
|
||||
} catch (NumberFormatException e) {
|
||||
order = 0;
|
||||
}
|
||||
ComputationItemPropertiesValue inputProps = new ComputationItemPropertiesValue(
|
||||
order, inputKey,
|
||||
computationProperties.get(key));
|
||||
inputParametersAsProperties.add(inputProps);
|
||||
|
||||
}
|
||||
|
||||
|
@ -1334,9 +1345,21 @@ public class SClient4WPS extends SClient {
|
|||
int outputSeparatorIndex = key.indexOf("_");
|
||||
String outputKey = key
|
||||
.substring(outputSeparatorIndex + 1);
|
||||
outputValueParameters.put(outputKey,
|
||||
|
||||
String outputOrder = key.substring(6,
|
||||
outputSeparatorIndex);
|
||||
Integer order;
|
||||
try {
|
||||
order = Integer.parseInt(outputOrder);
|
||||
} catch (NumberFormatException e) {
|
||||
order = 0;
|
||||
}
|
||||
ComputationItemPropertiesValue outputProps = new ComputationItemPropertiesValue(
|
||||
order, outputKey,
|
||||
computationProperties.get(key));
|
||||
|
||||
outputParametersAsProperties.add(outputProps);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1344,88 +1367,25 @@ public class SClient4WPS extends SClient {
|
|||
}
|
||||
}
|
||||
|
||||
Collections.sort(inputParametersAsProperties);
|
||||
Collections.sort(outputParametersAsProperties);
|
||||
|
||||
ComputationValueBuilder computationValueBuilder = new ComputationValueBuilder(
|
||||
inputValueParameters);
|
||||
inputParametersAsProperties);
|
||||
LinkedHashMap<String, ComputationValue> inputParameters = computationValueBuilder
|
||||
.create();
|
||||
computationValueBuilder = new ComputationValueBuilder(
|
||||
outputValueParameters);
|
||||
outputParametersAsProperties);
|
||||
LinkedHashMap<String, ComputationValue> outputParameters = computationValueBuilder
|
||||
.create();
|
||||
|
||||
logger.debug("inputParameters: " + inputParameters);
|
||||
logger.debug("outputParameters: " + outputParameters);
|
||||
|
||||
LinkedHashMap<String, ComputationValue> inputParametersSorted = new LinkedHashMap<>();
|
||||
LinkedHashMap<String, ComputationValue> outputParametersSorted = new LinkedHashMap<>();
|
||||
|
||||
ProcessInformations processInfos = describeProcess(operatorId);
|
||||
if (processInfos != null) {
|
||||
for (InputDescriptionType inputDesc : processInfos.getInputs()) {
|
||||
if (inputDesc != null
|
||||
&& inputDesc.getIdentifier() != null
|
||||
&& inputDesc.getIdentifier().getStringValue() != null) {
|
||||
logger.debug("InputParametr Match: "
|
||||
+ inputDesc.getIdentifier().getStringValue());
|
||||
ComputationValue inputComputationValue = inputParameters
|
||||
.get(inputDesc.getIdentifier().getStringValue());
|
||||
inputParametersSorted.put(inputDesc.getIdentifier()
|
||||
.getStringValue(), inputComputationValue);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
inputParametersSorted.putAll(inputParameters);
|
||||
}
|
||||
|
||||
ArrayList<String> keys=new ArrayList<>(outputParameters.keySet());
|
||||
Comparator<String> comparator = new Comparator<String>() {
|
||||
public int compare(String c1, String c2) {
|
||||
Integer c1Int=null;
|
||||
|
||||
try {
|
||||
c1Int=Integer.valueOf(c1);
|
||||
} catch(NumberFormatException e){
|
||||
|
||||
}
|
||||
|
||||
Integer c2Int=null;
|
||||
|
||||
try {
|
||||
c2Int=Integer.valueOf(c2);
|
||||
} catch(NumberFormatException e){
|
||||
|
||||
}
|
||||
|
||||
if(c1Int!=null && c2Int!=null){
|
||||
return c1Int.compareTo(c2Int);
|
||||
} else {
|
||||
if(c1Int==null && c2Int==null){
|
||||
return c1.compareTo(c2);
|
||||
} else {
|
||||
if(c1Int==null){
|
||||
return -1;
|
||||
} else {
|
||||
return 1;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Collections.sort(keys, comparator);
|
||||
for(String key:keys){
|
||||
ComputationValue outputComputationValue = outputParameters
|
||||
.get(key);
|
||||
outputParametersSorted.put(key, outputComputationValue);
|
||||
}
|
||||
|
||||
ComputationData computationData = new ComputationData(
|
||||
computationId, inputParametersSorted,
|
||||
outputParametersSorted, operatorDescritpion, startDate,
|
||||
endDate, status, executionType, vre);
|
||||
computationId, inputParameters, outputParameters,
|
||||
operatorDescritpion, startDate, endDate, status,
|
||||
executionType, vre);
|
||||
|
||||
logger.debug("ComputationData: " + computationData);
|
||||
return computationData;
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.util.LinkedHashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.portlets.user.dataminermanager.shared.data.computations.ComputationItemPropertiesValue;
|
||||
import org.gcube.portlets.user.dataminermanager.shared.data.computations.ComputationValue;
|
||||
import org.gcube.portlets.user.dataminermanager.shared.data.computations.ComputationValueFile;
|
||||
import org.gcube.portlets.user.dataminermanager.shared.data.computations.ComputationValueFileList;
|
||||
|
@ -14,14 +15,21 @@ import org.gcube.portlets.user.dataminermanager.shared.data.computations.Computa
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Giancarlo Panichi
|
||||
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class ComputationValueBuilder {
|
||||
private static Logger logger = LoggerFactory
|
||||
.getLogger(ComputationValueBuilder.class);
|
||||
|
||||
private LinkedHashMap<String, String> valueParameters;
|
||||
private ArrayList<ComputationItemPropertiesValue> valueParameters;
|
||||
private LinkedHashMap<String, ComputationValue> computationsValueParameters;
|
||||
|
||||
public ComputationValueBuilder(LinkedHashMap<String, String> valueParameters) {
|
||||
public ComputationValueBuilder(
|
||||
ArrayList<ComputationItemPropertiesValue> valueParameters) {
|
||||
this.valueParameters = valueParameters;
|
||||
}
|
||||
|
||||
|
@ -31,20 +39,23 @@ public class ComputationValueBuilder {
|
|||
public LinkedHashMap<String, ComputationValue> create() {
|
||||
computationsValueParameters = new LinkedHashMap<String, ComputationValue>();
|
||||
if (valueParameters != null && !valueParameters.isEmpty()) {
|
||||
for (String key : valueParameters.keySet()) {
|
||||
String value = valueParameters.get(key);
|
||||
for (ComputationItemPropertiesValue valueParameter : valueParameters) {
|
||||
String value = valueParameter.getValue();
|
||||
if (value != null && !value.isEmpty()
|
||||
&& value.startsWith("http")) {
|
||||
if (value.contains("|")) {
|
||||
ComputationValue valueFileList = createComputationValueFileList(value);
|
||||
computationsValueParameters.put(key, valueFileList);
|
||||
computationsValueParameters.put(
|
||||
valueParameter.getKey(), valueFileList);
|
||||
} else {
|
||||
ComputationValue computationValue = retrieveFileName(value);
|
||||
computationsValueParameters.put(key, computationValue);
|
||||
computationsValueParameters.put(
|
||||
valueParameter.getKey(), computationValue);
|
||||
}
|
||||
} else {
|
||||
ComputationValue valueString = new ComputationValue(value);
|
||||
computationsValueParameters.put(key, valueString);
|
||||
computationsValueParameters.put(valueParameter.getKey(),
|
||||
valueString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -53,32 +64,32 @@ public class ComputationValueBuilder {
|
|||
|
||||
}
|
||||
|
||||
|
||||
private ComputationValue createComputationValueFileList(String value) {
|
||||
ArrayList<ComputationValue> fileList=new ArrayList<>();
|
||||
ArrayList<ComputationValue> fileList = new ArrayList<>();
|
||||
int indexSeparator;
|
||||
String file;
|
||||
ComputationValue computationValue;
|
||||
while((indexSeparator=value.indexOf("|"))!=-1){
|
||||
file=value.substring(0, indexSeparator);
|
||||
value=value.substring(indexSeparator+1);
|
||||
computationValue=retrieveFileName(file);
|
||||
while ((indexSeparator = value.indexOf("|")) != -1) {
|
||||
file = value.substring(0, indexSeparator);
|
||||
value = value.substring(indexSeparator + 1);
|
||||
computationValue = retrieveFileName(file);
|
||||
fileList.add(computationValue);
|
||||
}
|
||||
computationValue=retrieveFileName(value);
|
||||
fileList.add(computationValue);
|
||||
ComputationValueFileList computationValueFileList=new ComputationValueFileList(fileList, "|");
|
||||
computationValue = retrieveFileName(value);
|
||||
fileList.add(computationValue);
|
||||
ComputationValueFileList computationValueFileList = new ComputationValueFileList(
|
||||
fileList, "|");
|
||||
return computationValueFileList;
|
||||
|
||||
|
||||
}
|
||||
|
||||
private ComputationValue retrieveFileName(final String value) {
|
||||
URLConnection conn = null;
|
||||
logger.debug("Retrieve File Header from Storage for value: "+value);
|
||||
logger.debug("Retrieve File Header from Storage for value: " + value);
|
||||
try {
|
||||
//Use URL connection because in internal network is more fast
|
||||
// Use URL connection because in internal network is more fast
|
||||
URL url = new URL(value);
|
||||
conn = url.openConnection();
|
||||
conn = url.openConnection();
|
||||
return extractFileName(conn, value);
|
||||
|
||||
} catch (Throwable e) {
|
||||
|
@ -87,49 +98,8 @@ public class ComputationValueBuilder {
|
|||
return new ComputationValueFile(value, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
int attempts = 0;
|
||||
|
||||
|
||||
do {
|
||||
logger.debug("Attempts: "+attempts);
|
||||
|
||||
conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setConnectTimeout(30000);
|
||||
conn.setReadTimeout(30000);
|
||||
conn.setRequestMethod("HEAD");
|
||||
conn.setAllowUserInteraction(false);
|
||||
conn.setDoInput(false);
|
||||
conn.setDoOutput(false);
|
||||
|
||||
conn.connect();
|
||||
|
||||
if (conn.getResponseCode() != 200) {
|
||||
logger.error("Retrieve File Name Response Code: "
|
||||
+ conn.getResponseCode());
|
||||
try {
|
||||
logger.debug("Sleep time: 5000");
|
||||
Thread.sleep(5000);
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
}
|
||||
}
|
||||
attempts++;
|
||||
|
||||
} while (attempts <= 5 || conn.getResponseCode() != 200);
|
||||
|
||||
if (conn.getResponseCode() == 200) {
|
||||
logger.debug("Retrived Header");
|
||||
return extractFileName(conn, value);
|
||||
} else {
|
||||
logger.debug("Header not retrieved use default");
|
||||
return new ComputationValueFile(value, null, null);
|
||||
}
|
||||
*/
|
||||
|
||||
private ComputationValue extractFileName(URLConnection conn,
|
||||
String value) {
|
||||
private ComputationValue extractFileName(URLConnection conn, String value) {
|
||||
ComputationValue computationValue = null;
|
||||
String fileName = null;
|
||||
String mimeType = null;
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
package org.gcube.portlets.user.dataminermanager.shared.data.computations;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Giancarlo Panichi email: <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class ComputationItemPropertiesValue implements Serializable,
|
||||
Comparable<ComputationItemPropertiesValue> {
|
||||
|
||||
private static final long serialVersionUID = 8917614711815918760L;
|
||||
private Integer order;
|
||||
private String key;
|
||||
private String value;
|
||||
|
||||
public ComputationItemPropertiesValue() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ComputationItemPropertiesValue(Integer order, String key,
|
||||
String value) {
|
||||
super();
|
||||
this.order = order;
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Integer getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
public void setOrder(Integer order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(ComputationItemPropertiesValue o) {
|
||||
return order.compareTo(o.getOrder());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ComputationItemPropertiesValue [order=" + order + ", key="
|
||||
+ key + ", value=" + value + "]";
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue