Created library dataminer-invocation-model

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-analysis/dataminer-invocation-model@174541 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2018-12-04 15:09:51 +00:00
parent 720daf4a4a
commit 87f8acabee
14 changed files with 937 additions and 0 deletions

31
.classpath Normal file
View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry including="**/*.java" kind="src" output="target/dataminer-invocation-model-0.1.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/dataminer-invocation-model-0.1.0-SNAPSHOT/WEB-INF/classes"/>
</classpath>

23
.project Normal file
View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>dataminer-invocation-model</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View File

@ -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/<project>=UTF-8

View File

@ -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

View File

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

198
pom.xml Normal file
View File

@ -0,0 +1,198 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>maven-parent</artifactId>
<groupId>org.gcube.tools</groupId>
<version>1.0.0</version>
<relativePath />
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.gcube.data.analysis</groupId>
<artifactId>dataminer-invocation-model</artifactId>
<version>0.1.0-SNAPSHOT</version>
<name>dataminer-invocation-model</name>
<description>This library manages the dataminer-invocation model that is the xml format interpretable by DataMiner to invoke an algorithm execution</description>
<scm>
<url>https://svn.d4science.research-infrastructures.eu/gcube/data/analysis/${project.artifactId}</url>
</scm>
<developers>
<developer>
<name>Francesco Mangiacrapa</name>
<email>francesco.mangiacrapa@isti.cnr.it</email>
<organization>CNR Pisa, Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo"</organization>
<roles>
<role>architect</role>
<role>developer</role>
</roles>
</developer>
</developers>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId>
<version>LATEST</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<properties>
<distroDirectory>${project.basedir}/distro</distroDirectory>
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
<distroDirectory>distro</distroDirectory>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!-- GWT needs at least java 1.6 -->
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.2.11</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2.11</version>
<scope>provided</scope>
</dependency>
<!-- LOGGER -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>compile</scope>
</dependency>
<!-- JUNIT -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<!-- Generate compiled stuff in the folder used for developing mode -->
<outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>copy-profile</id>
<phase>install</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>target</outputDirectory>
<resources>
<resource>
<directory>${distroDirectory}</directory>
<filtering>true</filtering>
<includes>
<include>profile.xml</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2</version>
<configuration>
<descriptors>
<descriptor>${distroDirectory}/descriptor.xml</descriptor>
</descriptors>
<archive>
<manifest>
<mainClass>fully.qualified.MainClass</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>servicearchive</id>
<phase>install</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -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);
}
}

View File

@ -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<DataMinerParam> 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<DataMinerParam> listParam) {
super();
this.listParam = listParam;
}
/**
* Gets the list param.
*
* @return the listParam
*/
public List<DataMinerParam> getListParam() {
return listParam;
}
/**
* Sets the list param.
*
* @param listParam the listParam to set
*/
public void setListParam(List<DataMinerParam> 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();
}
}

View File

@ -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();
}
}

View File

@ -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<DataMinerParam> params;
/**
* Instantiates a new data miner output params.
*/
public DataMinerOutputParams() {
}
/**
* Instantiates a new data miner output params.
*
* @param params the params
*/
public DataMinerOutputParams(List<DataMinerParam> params) {
super();
this.params = params;
}
/**
* Gets the params.
*
* @return the params
*/
public List<DataMinerParam> getParams() {
return params;
}
/**
* Sets the params.
*
* @param params the params to set
*/
public void setParams(List<DataMinerParam> 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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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<String,String> parameters = new HashMap<String,String>();
@Before
public void init(){
parameters.put("key1", "value1");
parameters.put("key2", "value2");
}
@Test
public void marshallingTest() throws JAXBException {
//LOADING PARAMETERS
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);
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);
}
}

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<dataminer-invocation>
<operator-id>THE_OPERATOR_ID</operator-id>
<parameters>
<input>
<param>
<key>key1</key>
<value>value1</value>
</param>
<param>
<key>key2</key>
<value>value2</value>
</param>
</input>
<output/>
</parameters>
</dataminer-invocation>