diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..8233959 --- /dev/null +++ b/.classpath @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..db26b4c --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + dataminer-invocation-model + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..cdfe4f1 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,5 @@ +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/test/java=UTF-8 +encoding//src/test/resources=UTF-8 +encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..e52a276 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..7cbc7a6 --- /dev/null +++ b/pom.xml @@ -0,0 +1,198 @@ + + + + + maven-parent + org.gcube.tools + 1.0.0 + + + + 4.0.0 + org.gcube.data.analysis + dataminer-invocation-model + 0.1.0-SNAPSHOT + dataminer-invocation-model + This library manages the dataminer-invocation model that is the xml format interpretable by DataMiner to invoke an algorithm execution + + https://svn.d4science.research-infrastructures.eu/gcube/data/analysis/${project.artifactId} + + + + + Francesco Mangiacrapa + francesco.mangiacrapa@isti.cnr.it + CNR Pisa, Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo" + + architect + developer + + + + + + + + + org.gcube.distribution + maven-portal-bom + LATEST + pom + import + + + + + + ${project.basedir}/distro + ${project.build.directory}/${project.build.finalName} + distro + UTF-8 + UTF-8 + + 1.7 + 1.8 + + + + + + + com.sun.xml.bind + jaxb-core + 2.2.11 + provided + + + + com.sun.xml.bind + jaxb-impl + 2.2.11 + provided + + + + + + log4j + log4j + compile + + + org.slf4j + slf4j-log4j12 + compile + + + org.slf4j + slf4j-api + compile + + + + + junit + junit + 4.8.1 + test + + + + + + + ${webappDirectory}/WEB-INF/classes + + + src/main/java + + **/*.* + + + + + + + maven-compiler-plugin + + ${maven.compiler.source} + ${maven.compiler.target} + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.2 + + + + test-jar + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.16 + + true + + + + org.apache.maven.plugins + maven-resources-plugin + 2.5 + + + copy-profile + install + + copy-resources + + + target + + + ${distroDirectory} + true + + profile.xml + + + + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + 2.2 + + + ${distroDirectory}/descriptor.xml + + + + fully.qualified.MainClass + + + + + + servicearchive + install + + single + + + + + + + diff --git a/src/main/java/org/gcube/data/analysis/dminvocation/DataMinerInvocationManager.java b/src/main/java/org/gcube/data/analysis/dminvocation/DataMinerInvocationManager.java new file mode 100644 index 0000000..2eb5847 --- /dev/null +++ b/src/main/java/org/gcube/data/analysis/dminvocation/DataMinerInvocationManager.java @@ -0,0 +1,61 @@ +/** + * + */ +package org.gcube.data.analysis.dminvocation; + +import java.io.ByteArrayOutputStream; +import java.io.InputStream; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; + +import org.gcube.data.analysis.dminvocation.model.DataMinerInvocation; + + +/** + * The Class DataMinerInvocationManager. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Dec 4, 2018 + */ +public class DataMinerInvocationManager { + + + /** + * Marshaling. + * + * @param dmInvocation the dm invocation + * @return the byte array output stream + * @throws JAXBException the JAXB exception + */ + public static ByteArrayOutputStream marshaling(DataMinerInvocation dmInvocation) throws JAXBException + { + JAXBContext jaxbContext = JAXBContext.newInstance(DataMinerInvocation.class); + Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); + jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + jaxbMarshaller.marshal(dmInvocation, baos); + return baos; + } + + + /** + * Unmarshaling. + * + * @param dmInvocationXMLStream the dm invocation xml file + * @return the data miner invocation + * @throws JAXBException the JAXB exception + */ + public static DataMinerInvocation unmarshaling(InputStream dmInvocationXMLStream) throws JAXBException + { + //unMarshalingCategories(); + JAXBContext jaxbContext = JAXBContext.newInstance(DataMinerInvocation.class); + Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); + + //We had written this file in marshalling example + return (DataMinerInvocation) jaxbUnmarshaller.unmarshal(dmInvocationXMLStream); + + } +} diff --git a/src/main/java/org/gcube/data/analysis/dminvocation/model/DataMinerInputParams.java b/src/main/java/org/gcube/data/analysis/dminvocation/model/DataMinerInputParams.java new file mode 100644 index 0000000..ab0194c --- /dev/null +++ b/src/main/java/org/gcube/data/analysis/dminvocation/model/DataMinerInputParams.java @@ -0,0 +1,91 @@ +/** + * + */ +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; + + +/** + * The Class DataMinerInputParams. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Dec 4, 2018 + */ +@XmlRootElement(name = "dataminer-inputparams") +@XmlAccessorType (XmlAccessType.FIELD) +public class DataMinerInputParams implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = -7241629940190729604L; + + @XmlElement(name = "param") + private List listParam; + + + /** + * Instantiates a new data miner input params. + */ + public DataMinerInputParams() { + } + + + + /** + * Instantiates a new data miner input params. + * + * @param listParam the list param + */ + public DataMinerInputParams(List listParam) { + + super(); + this.listParam = listParam; + } + + + /** + * Gets the list param. + * + * @return the listParam + */ + public List getListParam() { + + return listParam; + } + + + + /** + * Sets the list param. + * + * @param listParam the listParam to set + */ + public void setListParam(List listParam) { + + this.listParam = listParam; + } + + + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + + StringBuilder builder = new StringBuilder(); + builder.append("DataMinerInputParams [listParam="); + builder.append(listParam); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/main/java/org/gcube/data/analysis/dminvocation/model/DataMinerInvocation.java b/src/main/java/org/gcube/data/analysis/dminvocation/model/DataMinerInvocation.java new file mode 100644 index 0000000..855eb87 --- /dev/null +++ b/src/main/java/org/gcube/data/analysis/dminvocation/model/DataMinerInvocation.java @@ -0,0 +1,114 @@ +/** + * + */ +package org.gcube.data.analysis.dminvocation.model; + +import java.io.Serializable; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * The Class DataMinerInvocation. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Dec 4, 2018 + */ +@XmlRootElement(name = "dataminer-invocation") +@XmlAccessorType (XmlAccessType.FIELD) +public class DataMinerInvocation implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = -3642902539322040226L; + + @XmlElement(name = "operator-id") + private String operatorId; + + @XmlElement(name = "parameters") + private DataMinerParameters parameters; + + /** + * Instantiates a new data miner invocation. + */ + public DataMinerInvocation() { + } + + /** + * Instantiates a new data miner invocation. + * + * @param operatorId the operator id + * @param parameters the parameters + */ + public DataMinerInvocation( + String operatorId, DataMinerParameters parameters) { + + super(); + this.operatorId = operatorId; + this.parameters = parameters; + } + + + /** + * Gets the operator id. + * + * @return the operatorId + */ + public String getOperatorId() { + + return operatorId; + } + + + /** + * Gets the parameters. + * + * @return the parameters + */ + public DataMinerParameters getParameters() { + + return parameters; + } + + + /** + * Sets the operator id. + * + * @param operatorId the operatorId to set + */ + public void setOperatorId(String operatorId) { + + this.operatorId = operatorId; + } + + + /** + * Sets the parameters. + * + * @param parameters the parameters to set + */ + public void setParameters(DataMinerParameters parameters) { + + this.parameters = parameters; + } + + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + + StringBuilder builder = new StringBuilder(); + builder.append("DataMinerInvocation [operatorId="); + builder.append(operatorId); + builder.append(", parameters="); + builder.append(parameters); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/main/java/org/gcube/data/analysis/dminvocation/model/DataMinerOutputParams.java b/src/main/java/org/gcube/data/analysis/dminvocation/model/DataMinerOutputParams.java new file mode 100644 index 0000000..c11fa93 --- /dev/null +++ b/src/main/java/org/gcube/data/analysis/dminvocation/model/DataMinerOutputParams.java @@ -0,0 +1,87 @@ +/** + * + */ +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; + + +/** + * The Class DataMinerOutputParams. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Dec 4, 2018 + */ +@XmlRootElement(name = "dataminer-outputparams") +@XmlAccessorType (XmlAccessType.FIELD) +public class DataMinerOutputParams implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = -683773454747370184L; + + @XmlElement(name = "param") + private List params; + + /** + * Instantiates a new data miner output params. + */ + public DataMinerOutputParams() { + } + + + /** + * Instantiates a new data miner output params. + * + * @param params the params + */ + public DataMinerOutputParams(List params) { + + super(); + this.params = params; + } + + + /** + * Gets the params. + * + * @return the params + */ + public List getParams() { + + return params; + } + + + /** + * Sets the params. + * + * @param params the params to set + */ + public void setParams(List params) { + + this.params = params; + } + + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + + StringBuilder builder = new StringBuilder(); + builder.append("DataMinerOutputParams [params="); + builder.append(params); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/main/java/org/gcube/data/analysis/dminvocation/model/DataMinerParam.java b/src/main/java/org/gcube/data/analysis/dminvocation/model/DataMinerParam.java new file mode 100644 index 0000000..8c12f71 --- /dev/null +++ b/src/main/java/org/gcube/data/analysis/dminvocation/model/DataMinerParam.java @@ -0,0 +1,111 @@ +/** + * + */ +package org.gcube.data.analysis.dminvocation.model; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + + +/** + * The Class DataMinerParam. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Dec 4, 2018 + */ +@XmlRootElement(name = "param") +@XmlAccessorType (XmlAccessType.FIELD) +public class DataMinerParam { + + private String key; + private String value; + + + /** + * Instantiates a new data miner param. + */ + public DataMinerParam() { + + // TODO Auto-generated constructor stub + } + + + /** + * Instantiates a new data miner param. + * + * @param key the key + * @param value the value + */ + public DataMinerParam(String key, String value) { + + super(); + this.key = key; + this.value = value; + } + + + + /** + * Gets the key. + * + * @return the key + */ + public String getKey() { + + return key; + } + + + + /** + * Gets the value. + * + * @return the value + */ + public String getValue() { + + return value; + } + + + + /** + * Sets the key. + * + * @param key the key to set + */ + public void setKey(String key) { + + this.key = key; + } + + + + /** + * Sets the value. + * + * @param value the value to set + */ + public void setValue(String value) { + + this.value = value; + } + + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + + StringBuilder builder = new StringBuilder(); + builder.append("DataMinerParam [key="); + builder.append(key); + builder.append(", value="); + builder.append(value); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/main/java/org/gcube/data/analysis/dminvocation/model/DataMinerParameters.java b/src/main/java/org/gcube/data/analysis/dminvocation/model/DataMinerParameters.java new file mode 100644 index 0000000..d5cb958 --- /dev/null +++ b/src/main/java/org/gcube/data/analysis/dminvocation/model/DataMinerParameters.java @@ -0,0 +1,114 @@ +/** + * + */ +package org.gcube.data.analysis.dminvocation.model; + +import java.io.Serializable; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + + + +/** + * The Class DataMinerParameters. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Dec 4, 2018 + */ +@XmlRootElement(name = "dataminer-parameters") +@XmlAccessorType (XmlAccessType.FIELD) +public class DataMinerParameters implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = 8298755690515099551L; + @XmlElement(name = "input") + private DataMinerInputParams input; + @XmlElement(name = "output") + private DataMinerOutputParams output; + + /** + * Instantiates a new data miner params model. + */ + public DataMinerParameters() { + + } + + /** + * Instantiates a new data miner params model. + * + * @param input the input + * @param output the output + */ + public DataMinerParameters( + DataMinerInputParams input, DataMinerOutputParams output) { + + super(); + this.input = input; + this.output = output; + } + + + /** + * Gets the input. + * + * @return the input + */ + public DataMinerInputParams getInput() { + + return input; + } + + + /** + * Gets the output. + * + * @return the output + */ + public DataMinerOutputParams getOutput() { + + return output; + } + + + /** + * Sets the input. + * + * @param input the input to set + */ + public void setInput(DataMinerInputParams input) { + + this.input = input; + } + + + /** + * Sets the output. + * + * @param output the output to set + */ + public void setOutput(DataMinerOutputParams output) { + + this.output = output; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + + StringBuilder builder = new StringBuilder(); + builder.append("DataMinerParameters [input="); + builder.append(input); + builder.append(", output="); + builder.append(output); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/test/java/DataMinerInvocationTest.java b/src/test/java/DataMinerInvocationTest.java new file mode 100644 index 0000000..7d3e4c3 --- /dev/null +++ b/src/test/java/DataMinerInvocationTest.java @@ -0,0 +1,76 @@ +/** + * + */ + + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.bind.JAXBException; + +import org.gcube.data.analysis.dminvocation.DataMinerInvocationManager; +import org.gcube.data.analysis.dminvocation.model.DataMinerInputParams; +import org.gcube.data.analysis.dminvocation.model.DataMinerInvocation; +import org.gcube.data.analysis.dminvocation.model.DataMinerOutputParams; +import org.gcube.data.analysis.dminvocation.model.DataMinerParam; +import org.gcube.data.analysis.dminvocation.model.DataMinerParameters; +import org.junit.Before; +import org.junit.Test; + + +/** + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Dec 4, 2018 + */ +public class DataMinerInvocationTest { + + static String operatorID = "THE_OPERATOR_ID"; + + static Map parameters = new HashMap(); + + + @Before + public void init(){ + parameters.put("key1", "value1"); + parameters.put("key2", "value2"); + } + + + @Test + public void marshallingTest() throws JAXBException { + + //LOADING PARAMETERS + List inParams = new ArrayList(); + 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); + + DataMinerInvocation dmInvocation = new DataMinerInvocation(); + dmInvocation.setOperatorId(operatorID); + dmInvocation.setParameters(params); + System.out.println(dmInvocation); + + ByteArrayOutputStream outStream = DataMinerInvocationManager.marshaling(dmInvocation); + + System.out.println(new String(outStream.toByteArray())); + + } + + @Test + public void unmarshallingTest() throws JAXBException, FileNotFoundException{ + FileInputStream dmInvocationXMLFile = new FileInputStream(new File("./src/test/resources/DataMinerInvocation.xml")); + DataMinerInvocation dmInvocation = DataMinerInvocationManager.unmarshaling(dmInvocationXMLFile); + System.out.println(dmInvocation); + } +} diff --git a/src/test/resources/DataMinerInvocation.xml b/src/test/resources/DataMinerInvocation.xml new file mode 100644 index 0000000..b177e59 --- /dev/null +++ b/src/test/resources/DataMinerInvocation.xml @@ -0,0 +1,17 @@ + + + THE_OPERATOR_ID + + + + key1 + value1 + + + key2 + value2 + + + + + \ No newline at end of file