trying to change with DataMinerParamList

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-analysis/dataminer-invocation-model@175997 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2018-12-18 16:39:39 +00:00
parent 427b9b8efe
commit e28d0a4c94
11 changed files with 302 additions and 128 deletions

View File

@ -115,13 +115,13 @@ public class DataMinerInvocationManager {
/**
* Unmarshaling.
*
* @param dmInvocationXMLStream the dm invocation xml stream
* @param dmInvocationIS the dm invocation input stream
* @param mediaType the media type see at {@link MediaType}
* @param validateModel the validate model. If true performs model validation against the xml schema generated for {@link DataMinerInvocation}
* @return the data miner invocation
* @throws JAXBException the JAXB exception
*/
public DataMinerInvocation unmarshaling(InputStream dmInvocationXMLStream, MediaType mediaType, boolean validateModel) throws JAXBException
public DataMinerInvocation unmarshaling(InputStream dmInvocationIS, MediaType mediaType, boolean validateModel) throws JAXBException
{
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
@ -141,7 +141,7 @@ public class DataMinerInvocationManager {
}
jaxbUnmarshaller.setProperty(JAXBContextProperties.MEDIA_TYPE, mediaType.getMimeType());
return (DataMinerInvocation) jaxbUnmarshaller.unmarshal(dmInvocationXMLStream);
return (DataMinerInvocation) jaxbUnmarshaller.unmarshal(dmInvocationIS);
}

View File

@ -0,0 +1,54 @@
/**
*
*/
package org.gcube.data.analysis.dminvocation;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import org.gcube.data.analysis.dminvocation.model.DataMinerParam;
import org.gcube.data.analysis.dminvocation.model.DataMinerParamList;
/**
* The Class DataMinerParamListAdaptor.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Dec 18, 2018
*/
public class DataMinerParamListAdaptor extends XmlAdapter<DataMinerParamList, List<DataMinerParam>>
{
/* (non-Javadoc)
* @see javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal(java.lang.Object)
*/
@Override
public List<DataMinerParam> unmarshal(DataMinerParamList list) throws Exception{
System.out.println("Unmarshal called: ");
List<DataMinerParam> retVal = new ArrayList<DataMinerParam>();
for (DataMinerParam dmp : list.getValues()){
System.out.println("key: "+dmp.getKey()+" value: "+ dmp.getValue());
retVal.add(new DataMinerParam(dmp.getKey(), dmp.getValue()));
}
return retVal;
}
/* (non-Javadoc)
* @see javax.xml.bind.annotation.adapters.XmlAdapter#marshal(java.lang.Object)
*/
@Override
public DataMinerParamList marshal(List<DataMinerParam> list) throws Exception{
System.out.println("Marshal called: ");
DataMinerParamList retVal = new DataMinerParamList();
System.out.println(list);
// List<DataMinerParam> values = new ArrayList<DataMinerParam>();
// for (DataMinerParam dmp : list){
// System.out.println("key: "+dmp.getKey()+" value: "+ dmp.getValue());
// values.add(new DataMinerParam(dmp.getKey(), dmp.getValue()));
// }
retVal.setValues(list);
return retVal;
}
}

View File

@ -0,0 +1,51 @@
///**
// *
// */
//package org.gcube.data.analysis.dminvocation;
//
//import java.util.HashMap;
//import java.util.Map;
//
//import javax.xml.bind.annotation.adapters.XmlAdapter;
//
//import org.gcube.data.analysis.dminvocation.model.DataMinerParam;
//import org.gcube.data.analysis.dminvocation.model.DataMinerParamList;
//
//
///**
// * The Class MapAdaptor.
// *
// * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
// * Dec 18, 2018
// */
//public class MapAdaptor extends XmlAdapter<DataMinerParamList, Map<String, String>>
//{
//
// /* (non-Javadoc)
// * @see javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal(java.lang.Object)
// */
// @Override
// public Map<String, String> unmarshal(DataMinerParamList list) throws Exception{
// System.out.println("Unmarshal called: ");
// Map<String, String> retVal = new HashMap<String, String>();
// for (DataMinerParam keyValue : list.getValues()){
// System.out.println("key: "+keyValue.getKey()+" value: "+ keyValue.getValue());
// retVal.put(keyValue.getKey(), keyValue.getValue());
// }
// return retVal;
// }
//
// /* (non-Javadoc)
// * @see javax.xml.bind.annotation.adapters.XmlAdapter#marshal(java.lang.Object)
// */
// @Override
// public DataMinerParamList marshal(Map<String, String> map) throws Exception{
// System.out.println("Marshal called: ");
// DataMinerParamList retVal = new DataMinerParamList();
// for (String key : map.keySet()){
// System.out.println("key: "+key+" value: "+ map.get(key));
// retVal.getValues().add(new DataMinerParam(key, map.get(key)));
// }
// return retVal;
// }
//}

View File

@ -1,51 +1,51 @@
/**
*
*/
package org.gcube.data.analysis.dminvocation.model;
import java.io.Serializable;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* The Class DataMinerInputParams.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Dec 4, 2018
*/
@XmlRootElement(name = "dataminer-inputparams")
@XmlAccessorType (XmlAccessType.FIELD)
//@JsonIgnoreProperties(ignoreUnknown=true)
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@ToString
public class DataMinerInputParams implements Serializable{
/**
*
*/
private static final long serialVersionUID = -7241629940190729604L;
@XmlElement(name = "param", required=true, nillable=false)
@JsonProperty(value="param", required=true)
private List<DataMinerParam> listParam;
}
///**
// *
// */
//package org.gcube.data.analysis.dminvocation.model;
//
//import java.io.Serializable;
//import java.util.List;
//
//import javax.xml.bind.annotation.XmlAccessType;
//import javax.xml.bind.annotation.XmlAccessorType;
//import javax.xml.bind.annotation.XmlElement;
//import javax.xml.bind.annotation.XmlRootElement;
//
//import lombok.AllArgsConstructor;
//import lombok.Getter;
//import lombok.NoArgsConstructor;
//import lombok.Setter;
//import lombok.ToString;
//
//import com.fasterxml.jackson.annotation.JsonProperty;
//
//
///**
// * The Class DataMinerInputParams.
// *
// * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
// * Dec 4, 2018
// */
//@XmlRootElement(name = "dataminer-inputparams")
//@XmlAccessorType (XmlAccessType.FIELD)
////@JsonIgnoreProperties(ignoreUnknown=true)
//@NoArgsConstructor
//@AllArgsConstructor
//@Getter
//@Setter
//@ToString
//public class DataMinerInputParams implements Serializable{
//
// /**
// *
// */
// private static final long serialVersionUID = -7241629940190729604L;
//
// @XmlElement(name = "param", required=true, nillable=false)
// @JsonProperty(value="param", required=true)
// private List<DataMinerParam> listParam;
//
//
//
//
//}

View File

@ -1,48 +1,48 @@
/**
*
*/
package org.gcube.data.analysis.dminvocation.model;
import java.io.Serializable;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* The Class DataMinerOutputParams.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Dec 4, 2018
*/
@XmlRootElement(name = "dataminer-outputparams")
@XmlAccessorType (XmlAccessType.FIELD)
//@JsonIgnoreProperties(ignoreUnknown=true)
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@ToString
public class DataMinerOutputParams implements Serializable{
/**
*
*/
private static final long serialVersionUID = -683773454747370184L;
@XmlElement(name = "param", required=false, nillable=false)
@JsonProperty(value="param", required=true)
private List<DataMinerParam> params;
}
///**
// *
// */
//package org.gcube.data.analysis.dminvocation.model;
//
//import java.io.Serializable;
//import java.util.List;
//
//import javax.xml.bind.annotation.XmlAccessType;
//import javax.xml.bind.annotation.XmlAccessorType;
//import javax.xml.bind.annotation.XmlElement;
//import javax.xml.bind.annotation.XmlRootElement;
//
//import lombok.AllArgsConstructor;
//import lombok.Getter;
//import lombok.NoArgsConstructor;
//import lombok.Setter;
//import lombok.ToString;
//
//import com.fasterxml.jackson.annotation.JsonProperty;
//
//
///**
// * The Class DataMinerOutputParams.
// *
// * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
// * Dec 4, 2018
// */
//@XmlRootElement(name = "dataminer-outputparams")
//@XmlAccessorType (XmlAccessType.FIELD)
////@JsonIgnoreProperties(ignoreUnknown=true)
//@NoArgsConstructor
//@AllArgsConstructor
//@Getter
//@Setter
//@ToString
//public class DataMinerOutputParams implements Serializable{
//
// /**
// *
// */
// private static final long serialVersionUID = -683773454747370184L;
//
// @XmlElement(name = "param", required=false, nillable=false)
// @JsonProperty(value="param", required=true)
// private List<DataMinerParam> params;
//
//}

View File

@ -13,6 +13,8 @@ import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
/**
* The Class DataMinerParam.
@ -20,8 +22,9 @@ import lombok.ToString;
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Dec 4, 2018
*/
@XmlRootElement(name = "param")
@XmlRootElement(name = "dataminer-param")
@XmlAccessorType (XmlAccessType.FIELD)
@JsonIgnoreProperties(ignoreUnknown=true)
@NoArgsConstructor
@AllArgsConstructor
@Getter

View File

@ -0,0 +1,48 @@
/**
*
*/
package org.gcube.data.analysis.dminvocation.model;
import java.io.Serializable;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* The Class DataMinerParamList.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Dec 18, 2018
*/
@XmlAccessorType (XmlAccessType.FIELD)
@XmlRootElement(name = "dataminer-param-list")
@JsonIgnoreProperties(ignoreUnknown=true)
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@ToString
public class DataMinerParamList implements Serializable{
/**
*
*/
private static final long serialVersionUID = 623106816934429133L;
@XmlElement(name = "param", required=true, nillable=false)
@JsonProperty(value="param", required=true)
private List<DataMinerParam> values;
}

View File

@ -37,15 +37,14 @@ import com.fasterxml.jackson.annotation.JsonProperty;
@ToString
public class DataMinerParameters implements Serializable{
/**
*
*/
private static final long serialVersionUID = 8298755690515099551L;
@XmlElement(name = "input", required=true, nillable=false)
@JsonProperty(required=true)
private DataMinerInputParams input;
//@XmlJavaTypeAdapter(value = DataMinerParamListAdaptor.class)
private DataMinerParamList input;
@XmlElement(name = "output", required=false, nillable=false)
@JsonProperty(required=false)
private DataMinerOutputParams output;
private DataMinerParamList output;
}

View File

@ -7,7 +7,9 @@ import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.bind.JAXBException;
@ -15,7 +17,11 @@ import javax.xml.bind.JAXBException;
import org.gcube.data.analysis.dminvocation.DataMinerInvocationManager;
import org.gcube.data.analysis.dminvocation.MediaType;
import org.gcube.data.analysis.dminvocation.model.DataMinerInvocation;
import org.gcube.data.analysis.dminvocation.model.DataMinerParam;
import org.gcube.data.analysis.dminvocation.model.DataMinerParamList;
import org.gcube.data.analysis.dminvocation.model.DataMinerParameters;
import org.junit.Before;
import org.junit.Test;
import org.xml.sax.SAXException;
@ -35,28 +41,31 @@ public class DataMinerInvocationTest {
@Before
public void init() throws JAXBException, IOException, SAXException{
parameters.put("[key1]", "[value1]");
parameters.put("fileId", "http://publicLinkToFile");
parameters.put("[key2]", "[value2]");
dmMng = DataMinerInvocationManager.getInstance();
}
//@Test
@Test
public void marshallingTest() throws JAXBException, IOException, SAXException {
System.out.println(DataMinerInvocationTest.class.getMethods()[0].getName()+" called");
//LOADING PARAMETERS
// List<DataMinerParam> inParams = new ArrayList<DataMinerParam>();
// for (String pm : parameters.keySet()) {
// inParams.add(new DataMinerParam(pm, parameters.get(pm)));
// }
//
List<DataMinerParam> inParams = new ArrayList<DataMinerParam>();
for (String pm : parameters.keySet()) {
inParams.add(new DataMinerParam(pm, parameters.get(pm)));
}
// DataMinerInputParams inputParams = new DataMinerInputParams(inParams);
// DataMinerOutputParams outputParams = new DataMinerOutputParams(null);
// DataMinerParameters params = new DataMinerParameters(inputParams, outputParams);
// Map<String, String> inputList = new HashMap<String, String>();
// inputList.putAll(parameters);
//new DataMinerParamList(parameters)
DataMinerParameters parameters = new DataMinerParameters(new DataMinerParamList(inParams), null);
DataMinerInvocation dmInvocation = new DataMinerInvocation();
dmInvocation.setOperatorId(operatorID);
//dmInvocation.setParameters(params);
dmInvocation.setParameters(parameters);
System.out.println(dmInvocation);
// ByteArrayOutputStream outStreamJSON = DataMinerInvocationManager.marshaling(dmInvocation, MediaType.ApplicationJSON);
@ -64,9 +73,13 @@ public class DataMinerInvocationTest {
ByteArrayOutputStream outStreamXML = dmMng.marshaling(dmInvocation, MediaType.ApplicationXML, true);
System.out.println(new String(outStreamXML.toByteArray()));
ByteArrayOutputStream outStreamJSON = dmMng.marshaling(dmInvocation, MediaType.ApplicationJSON, true);
System.out.println(new String(outStreamJSON.toByteArray()));
}
//@Test
@Test
public void unmarshallingXMLTest() throws JAXBException, IOException, SAXException{
System.out.println(DataMinerInvocationTest.class.getMethods()[1].getName()+" called");
FileInputStream dmInvocationXMLFile = new FileInputStream(new File("./src/test/resources/DataMinerInvocation.xml"));
@ -76,13 +89,14 @@ public class DataMinerInvocationTest {
ByteArrayOutputStream outStreamJSON = dmMng.marshaling(dmInvocation, MediaType.ApplicationXML, true);
System.out.println(new String(outStreamJSON.toByteArray()));
//
outStreamJSON = dmMng.marshaling(dmInvocation, MediaType.ApplicationJSON, true);
System.out.println(new String(outStreamJSON.toByteArray()));
}
//@Test
@Test
public void unmarshallingJSONTest() throws JAXBException, IOException, SAXException{
System.out.println(DataMinerInvocationTest.class.getMethods()[2].getName()+" called");
FileInputStream dmInvocationJSONFile = new FileInputStream(new File("./src/test/resources/DataMinerInvocation.json"));
@ -94,6 +108,7 @@ public class DataMinerInvocationTest {
}
// public static void main(String[] args) throws JAXBException, IOException, SAXException {
// parameters.put("[key1]", "[value1]");
// parameters.put("[key2]", "[value2]");

View File

@ -1,16 +1,16 @@
{
"dataminer-invocation" : {
"operator-id" : "org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.MPA_INTERSECT",
"operator-id" : "[THE_OPERATOR_ID]",
"action" : "RUN",
"parameters" : {
"input" : {
"param" : {
"key" : "fileId",
"value" : "http://publicLinkToFile"
"key" : "[key2]",
"value" : "[value2]"
},
"param" : {
"key" : "param2",
"value" : "value2"
"key" : "fileId",
"value" : "http://publicLinkToFile22222"
}
}
}

View File

@ -1,12 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<dataminer-invocation>
<operator-id>org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.MPA_INTERSECT</operator-id>
<operator-id>[THE_OPERATOR_ID]</operator-id>
<action>RUN</action>
<parameters>
<input>
<param>
<key>param2</key>
<value>value2</value>
<key>[key2]</key>
<value>[value2]</value>
</param>
<param>
<key>fileId</key>
<value>http://publicLinkToFile</value>
</param>
</input>
</parameters>