From d5fe4657c5ad5b380bc689864044bf49f43f87e6 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Fri, 8 Jan 2016 16:03:44 +0000 Subject: [PATCH] 1452: Implement a GUI for StatMan Algorithms Importer Task-Url: https://support.d4science.org/issues/1452 Updated UI behavior git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/statistical-algorithms-importer@122173 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../client/codeparser/CodeParser.java | 26 +++++++-- .../input/EnvironmentVariablesPanel.java | 2 +- .../client/tools/input/SelectedRowsPanel.java | 2 +- .../server/generator/AlgorithmGenerator.java | 55 +++++++++++++++++++ .../shared/project/Project.java | 47 ++++++++++++---- .../statalgoimporter.gwt.xml | 16 +++--- .../example/FileTemplate.java | 43 +++++++++++++++ 7 files changed, 165 insertions(+), 26 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/generator/AlgorithmGenerator.java create mode 100644 src/test/resources/org/gcube/portlets/user/statisticalalgorithmsimporter/example/FileTemplate.java diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/codeparser/CodeParser.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/codeparser/CodeParser.java index 5fbe065..3c5b567 100644 --- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/codeparser/CodeParser.java +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/codeparser/CodeParser.java @@ -4,6 +4,7 @@ import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.input.DataTy import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.input.IOType; import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.input.SelectedRowsVariables; +import com.allen_sauer.gwt.log.client.Log; import com.google.gwt.regexp.shared.RegExp; /** @@ -32,24 +33,37 @@ public class CodeParser { if (parameter.contains("<-")) { String[] varDescription = parameter.split("<-"); + String defaultValue = varDescription[1].trim(); + if (defaultValue.startsWith("\"")) + defaultValue = defaultValue.substring(1); + if (defaultValue.endsWith("\"")) + defaultValue = defaultValue.substring(0, + defaultValue.length() - 1); + selectedRowsVariables = new SelectedRowsVariables( varDescription[0].trim(), varDescription[0].trim(), - varDescription[1].trim(), - checkDataType(varDescription[1].trim()), ioType, parameter); - + defaultValue, checkDataType(varDescription[1].trim()), + ioType, parameter); } else { if (parameter.contains("=")) { String[] varDescription = parameter.split("="); + String defaultValue = varDescription[1].trim(); + if (defaultValue.startsWith("\"")) + defaultValue = defaultValue.substring(1); + if (defaultValue.endsWith("\"")) + defaultValue = defaultValue.substring(0, + defaultValue.length() - 1); selectedRowsVariables = new SelectedRowsVariables( varDescription[0].trim(), varDescription[0].trim(), - varDescription[1].trim(), - checkDataType(varDescription[1].trim()), ioType, - parameter); + defaultValue, checkDataType(varDescription[1].trim()), + ioType, parameter); + } else { return null; } } + Log.debug("CodeParser: " + selectedRowsVariables); return selectedRowsVariables; } diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/tools/input/EnvironmentVariablesPanel.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/tools/input/EnvironmentVariablesPanel.java index 8fb84bf..81ed43d 100644 --- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/tools/input/EnvironmentVariablesPanel.java +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/tools/input/EnvironmentVariablesPanel.java @@ -106,7 +106,7 @@ public class EnvironmentVariablesPanel extends ContentPanel { // nameColumn.setMenuDisabled(true); ColumnConfig descriptionColumn = new ColumnConfig( - props.name(), 100, "Description"); + props.description(), 100, "Description"); // descriptionColumn.setMenuDisabled(true); ColumnConfig inputTypeColumn = new ColumnConfig( diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/tools/input/SelectedRowsPanel.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/tools/input/SelectedRowsPanel.java index 0716e70..b0da266 100644 --- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/tools/input/SelectedRowsPanel.java +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/tools/input/SelectedRowsPanel.java @@ -118,7 +118,7 @@ public class SelectedRowsPanel extends ContentPanel { // nameColumn.setMenuDisabled(true); ColumnConfig descriptionColumn = new ColumnConfig( - props.name(), 100, "Description"); + props.description(), 100, "Description"); // descriptionColumn.setMenuDisabled(true); ColumnConfig dataTypeColumn = new ColumnConfig( diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/generator/AlgorithmGenerator.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/generator/AlgorithmGenerator.java new file mode 100644 index 0000000..95c0dc8 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/generator/AlgorithmGenerator.java @@ -0,0 +1,55 @@ +package org.gcube.portlets.user.statisticalalgorithmsimporter.server.generator; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.List; + +import org.apache.commons.io.IOUtils; +import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterServiceException; +import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.Project; + +/** + * + * @author Giancarlo Panichi email: g.panichi@isti.cnr.it + * + */ +public class AlgorithmGenerator { + + private static final String EXTENTION_JAVA = ".java"; + private Project project; + + public AlgorithmGenerator(Project project) { + super(); + this.project = project; + } + + @Override + public String toString() { + return "AlgorithmGenerator [project=" + project + "]"; + } + + public File createAlgorithm() throws StatAlgoImporterServiceException { + try { + File fileTmp = File.createTempFile(project.getClassName(), + EXTENTION_JAVA); + fileTmp.deleteOnExit(); + /* + List lines = Arrays.asList("The first line", "The second line"); + Path file = Paths.g; + Files.write(file, lines, Charset.forName("UTF-8")); + */ + return fileTmp; + + } catch (IOException e) { + e.printStackTrace(); + throw new StatAlgoImporterServiceException(e.getLocalizedMessage()); + } + + } + +} diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/shared/project/Project.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/shared/project/Project.java index ea87062..aabec9b 100644 --- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/shared/project/Project.java +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/shared/project/Project.java @@ -10,22 +10,50 @@ import java.io.Serializable; */ public class Project implements Serializable { + private static final long serialVersionUID = -7906477664944910362L; - + + private String name; + private String description; + private String className; private ProjectFolder projectFolder; private MainCode mainCode; private InputData inputData; - - public Project(){ + + public Project() { super(); } - + public Project(ProjectFolder projectFolder) { super(); - this.projectFolder=projectFolder; + this.projectFolder = projectFolder; } + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getClassName() { + return className; + } + + public void setClassName(String className) { + this.className = className; + } + public MainCode getMainCode() { return mainCode; } @@ -52,12 +80,11 @@ public class Project implements Serializable { @Override public String toString() { - return "Project [projectFolder=" + projectFolder + ", mainCode=" - + mainCode + ", inputData=" + inputData + "]"; + return "Project [name=" + name + ", description=" + description + + ", className=" + className + ", projectFolder=" + + projectFolder + ", mainCode=" + mainCode + ", inputData=" + + inputData + "]"; } - - - } diff --git a/src/main/resources/org/gcube/portlets/user/statisticalalgorithmsimporter/statalgoimporter.gwt.xml b/src/main/resources/org/gcube/portlets/user/statisticalalgorithmsimporter/statalgoimporter.gwt.xml index 36970ac..a39443a 100644 --- a/src/main/resources/org/gcube/portlets/user/statisticalalgorithmsimporter/statalgoimporter.gwt.xml +++ b/src/main/resources/org/gcube/portlets/user/statisticalalgorithmsimporter/statalgoimporter.gwt.xml @@ -51,17 +51,17 @@ name="locale" values="es" /> --> - - - - + - + + + + diff --git a/src/test/resources/org/gcube/portlets/user/statisticalalgorithmsimporter/example/FileTemplate.java b/src/test/resources/org/gcube/portlets/user/statisticalalgorithmsimporter/example/FileTemplate.java new file mode 100644 index 0000000..24298e0 --- /dev/null +++ b/src/test/resources/org/gcube/portlets/user/statisticalalgorithmsimporter/example/FileTemplate.java @@ -0,0 +1,43 @@ +package org.gcube.dataanalysis.executor.rscripts; + +import java.io.File; +import java.util.ArrayList; +import java.util.LinkedHashMap; + +import org.gcube.dataanalysis.ecoengine.datatypes.PrimitiveType; +import org.gcube.dataanalysis.ecoengine.datatypes.StatisticalType; +import org.gcube.dataanalysis.ecoengine.datatypes.enumtypes.PrimitiveTypes; +import org.gcube.dataanalysis.executor.rscripts.generic.GenericRScript; + +public class KnitrCompiler extends GenericRScript { + + @Override + public String getDescription() { + return "An algorithm to compile Knitr documents. Developed by IRD (reference Julien Bard, julien.barde@ird.fr)"; + } + + protected void initVariables(){ + mainScriptName="IRDTunaAtlas-master/report/knitr/compileKnitR_CNR.R"; + packageURL="http://goo.gl/T7V8LV"; + + environmentalvariables = new ArrayList(); + inputvariables.add("zipfile"); + inputvariables.add("file.inout"); + outputvariables.add("pdfresult"); + } + + @Override + protected void setInputParameters() { + inputs.add(new PrimitiveType(File.class.getName(), null, PrimitiveTypes.FILE, "zipfile", "The file containing R and the markdown (Rnw) files to compile","knitr_wfs.zip")); + inputs.add(new PrimitiveType(String.class.getName(), null, PrimitiveTypes.STRING, "file.inout", "The name of the R file in the zip package", "main.r")); + } + + @Override + public StatisticalType getOutput() { + output.put("pdfresult",new PrimitiveType(File.class.getName(), new File(outputValues.get("pdfresult")), PrimitiveTypes.FILE, "pdfresult", "The compiled PDF file")); + PrimitiveType o = new PrimitiveType(LinkedHashMap.class.getName(), output, PrimitiveTypes.MAP, "Output", ""); + return o; + } + +} + \ No newline at end of file