1452: Implement a GUI for StatMan Algorithms Importer

Task-Url: https://support.d4science.org/issues/1452

Fixed enumerated Input/Output parameters

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/statistical-algorithms-importer@122680 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2016-02-01 15:08:07 +00:00
parent b289d6718f
commit cdb0ea5424
10 changed files with 301 additions and 90 deletions

View File

@ -323,7 +323,7 @@ public class StatAlgoImporterController {
pm.saveProject(event.getInputData(), monitor);
break;
case SoftwareCreate:
pm.createSofware(event.getInputData(), monitor);
pm.softwareCreate(event.getInputData(), monitor);
break;
default:
break;

View File

@ -17,8 +17,8 @@ public class CodeParser {
private static final String IMAGE_PATTERN = "([^\\s]+(\\.(jpg|png|gif|bmp)\"))";
private static final String FILE_PATTERN = "([^\\s]+(\\.(txt|csv|pdf|doc|zip|bin|dat|mat|java|m|exe|sh|tar|gz|r)\"))";
private static final String ENUM1_PATTERN = "(c\\([^\\)]*\\))";
private static final String ENUM2_PATTERN = "(\\{[^\\}]*\\})";
//private static final String ENUM1_PATTERN = "(c\\([^\\)]*\\))";
//private static final String ENUM2_PATTERN = "(\\{[^\\}]*\\})";
public CodeParser() {
@ -111,6 +111,7 @@ public class CodeParser {
return DataType.FILE;
}
/*
RegExp regExpEnum1 = RegExp.compile(ENUM1_PATTERN);
if (regExpEnum1.test(data)) {
return DataType.ENUMERATED;
@ -119,7 +120,7 @@ public class CodeParser {
RegExp regExpEnum2 = RegExp.compile(ENUM2_PATTERN);
if (regExpEnum2.test(data)) {
return DataType.ENUMERATED;
}
}*/
try {
Integer.parseInt(data);

View File

@ -73,6 +73,7 @@ public class MainDataPanel extends SimpleContainer {
case SOFTWARE_REPACKAGE:
case ADD_RESOURCE:
case DELETE_RESOURCE:
case EXPLORER_REFRESH:
break;
default:
break;

View File

@ -330,7 +330,7 @@ public class ProjectManager {
});
}
public void createSofware(final InputData inputData,
public void softwareCreate(final InputData inputData,
final StatAlgoImporterMonitor monitor) {
StatAlgoImporterServiceAsync.INSTANCE.createSoftware(inputData,
@ -355,6 +355,8 @@ public class ProjectManager {
+ caught.getLocalizedMessage());
UtilsGXT3.alert("Error",
caught.getLocalizedMessage());
fireProjectStatusExplorerRefreshEvent();
}
caught.printStackTrace();
@ -548,7 +550,6 @@ public class ProjectManager {
}
public void startProjectManager(String value) {
StatAlgoImporterServiceAsync.INSTANCE.restoreUISession(value,
@ -605,7 +606,6 @@ public class ProjectManager {
UtilsGXT3.alert("Error", "Project not open!");
}
}
private void softwareRepackageOnServer() {
@ -621,7 +621,7 @@ public class ProjectManager {
} else {
UtilsGXT3.alert("Error",
caught.getLocalizedMessage());
fireProjectStatusExplorerRefreshEvent();
}
}
@ -635,8 +635,6 @@ public class ProjectManager {
});
}
public void softwarePublish() {
if (project != null) {
final ConfirmMessageBox mb = new ConfirmMessageBox(
@ -681,6 +679,7 @@ public class ProjectManager {
} else {
UtilsGXT3.alert("Error",
caught.getLocalizedMessage());
fireProjectStatusExplorerRefreshEvent();
}
}
@ -707,7 +706,6 @@ public class ProjectManager {
}
@SuppressWarnings("unused")
private void fireProjectStatusSaveProjectEvent() {
ProjectStatusEvent projectStatusEvent = new ProjectStatusEvent(
@ -745,6 +743,13 @@ public class ProjectManager {
Log.debug("ProjectStatusEvent fired! " + projectStatusEvent);
}
private void fireProjectStatusExplorerRefreshEvent() {
ProjectStatusEvent projectStatusEvent = new ProjectStatusEvent(
ProjectStatusEventType.EXPLORER_REFRESH, project);
eventBus.fireEvent(projectStatusEvent);
Log.debug("ProjectStatusEvent fired! " + projectStatusEvent);
}
private void fireProjectStatusMainCodeSetEvent() {
ProjectStatusEvent projectStatusEvent = new ProjectStatusEvent(
ProjectStatusEventType.MAIN_CODE_SET, project);
@ -773,8 +778,6 @@ public class ProjectManager {
Log.debug("ProjectStatusEvent fired! " + projectStatusEvent);
}
private void fireProjectStatusStartEvent() {
ProjectStatusEvent projectStatusEvent = new ProjectStatusEvent(
ProjectStatusEventType.START, project);
@ -782,5 +785,4 @@ public class ProjectManager {
Log.debug("ProjectStatusEvent fired! " + projectStatusEvent);
}
}

View File

@ -120,6 +120,7 @@ public class ExplorerProjectPanel extends ContentPanel {
case SOFTWARE_CREATED:
case SOFTWARE_PUBLISH:
case SOFTWARE_REPACKAGE:
case EXPLORER_REFRESH:
reloadWSResourceExplorerPanel();
break;
default:

View File

@ -397,7 +397,8 @@ public class GlobalVariablesPanel extends ContentPanel {
int row = storeGlobalVariable.indexOf(newGlobalVariable);
storeComboInputType.clear();
storeComboInputType.addAll(DataType.asList());
storeComboInputType.addAll(DataType.asListForGlobalVariables());
storeComboInputType.commitChanges();
gridGlobalVariableEditing.startEditing(new GridCell(row, 0));

View File

@ -115,6 +115,7 @@ public class InputVariablePanel extends ContentPanel {
case START:
case ADD_RESOURCE:
case DELETE_RESOURCE:
case EXPLORER_REFRESH:
break;
case OPEN:
create(event.getProject());

View File

@ -17,6 +17,7 @@ public enum ProjectStatusEventType {
SOFTWARE_CREATED,
SOFTWARE_PUBLISH,
SOFTWARE_REPACKAGE,
EXPLORER_REFRESH,
SAVE;

View File

@ -7,9 +7,12 @@ import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterServiceException;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.input.DataType;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.input.GlobalVariables;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.input.IOType;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.input.InputOutputVariables;
@ -30,6 +33,7 @@ public class AlgorithmGenerator {
.getLogger(AlgorithmGenerator.class);
private Project project;
private HashMap<String, String> enumUUID;
public AlgorithmGenerator(Project project) {
super();
@ -42,10 +46,10 @@ public class AlgorithmGenerator {
}
public Path createAlgorithm() throws StatAlgoImporterServiceException {
try {
Path tempFile = Files.createTempFile(project.getInputData()
.getProjectInfo().getAlgorithmNameToClassName(), EXTENTION_JAVA);
.getProjectInfo().getAlgorithmNameToClassName(),
EXTENTION_JAVA);
List<String> lines = createJavaCode();
Files.write(tempFile, lines, Charset.defaultCharset(),
@ -65,8 +69,8 @@ public class AlgorithmGenerator {
private List<String> createJavaCode() {
String mainScriptRelativePath = retrieveMainScriptRelativePath();
String packageUrl = retrievePackageUrl();
ArrayList<String> code = new ArrayList<String>();
enumUUID = new HashMap<>();
ArrayList<String> code = new ArrayList<>();
code.addAll(Arrays
.asList("package org.gcube.dataanalysis.executor.rscripts;",
@ -78,26 +82,177 @@ public class AlgorithmGenerator {
"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 "
"import org.gcube.dataanalysis.ecoengine.utils.DynamicEnum;",
"import java.lang.reflect.Field;", "", "public class "
+ project.getInputData().getProjectInfo()
.getAlgorithmNameToClassName()
+ " extends GenericRScript {", "",
+ " extends GenericRScript {"));
" public static enum operators {",
" EQUAL, NOT_EQUAL, CONTAINS, BEGINS_WITH, ENDS_WITH",
" };", "", " @Override",
for (GlobalVariables globalVariable : project.getInputData()
.getListGlobalVariables()) {
if (globalVariable.getDataType().compareTo(DataType.ENUMERATED) == 0) {
if (globalVariable.getDefaultValue() == null
|| globalVariable.getDefaultValue().isEmpty()) {
} else {
String uuid = "" + UUID.randomUUID();
uuid = uuid.replaceAll("-", "");
String nameEnum = "opGV" + globalVariable.getId() + uuid;
enumUUID.put("opGV" + globalVariable.getId(), nameEnum);
code.add("");
code.add(" static class " + nameEnum
+ " extends DynamicEnum {");
code.add(" public enum E" + nameEnum + " {};");
code.add(" public Field[] getFields() {");
code.add(" Field[] fields = E" + nameEnum
+ ".class.getDeclaredFields();");
code.add(" return fields;");
code.add(" }");
code.add(" }");
/*
* code.add(" String[] "+ nameEnum + " = {"); String[]
* values = globalVariable.getDefaultValue().split( "\\|");
* if (values.length < 1) {
*
* } else { for (int i = 0; i < values.length; i++) { if (i
* == values.length - 1) { code.add(" \"" + values[i] +
* "\""); } else { code.add(" \"" + values[i] + "\","); } }
* } code.add(" };");
*/
/*
* code.add(" public static enum opGV" +
* globalVariable.getId() + " {"); String[] values =
* globalVariable.getDefaultValue().split( "\\|"); if
* (values.length < 1) {
*
* } else { for (int i = 0; i < values.length; i++) { String
* identifier = values[i].trim();
* identifier=identifier.replaceAll("\\s+","");
*
* if (i == values.length - 1) { code.add(" " + identifier
* + "(\"" + values[i] + "\");"); } else { code.add(" " +
* identifier + "(\"" + values[i] + "\"),"); } } }
*
* code.add(" "); code.add(" private final String id;");
* code.add(" "); code.add(" private opGV" +
* globalVariable.getId() + "(final String id) {");
* code.add(" this.id = id;"); code.add(" }");
* code.add(" "); code.add(" @Override");
* code.add(" public String toString() {");
* code.add(" return id;"); code.add(" }");
* code.add(" "); code.add(" public String getId() {");
* code.add(" return id;"); code.add(" }");
* code.add(" ");
*
* code.add(" public opIO" + globalVariable.getId() +
* " getIdentifier(String identifier){");
* code.add(" if(identifier==null|| identifier.isEmpty()){"
* ); code.add(" return null;"); code.add(" }");
* code.add(" "); code.add(" for(opIO" +
* globalVariable.getId() + " value:opIO" +
* globalVariable.getId() + ".values()){");
* code.add(" if(value.id.compareTo(identifier)==0){");
* code.add(" return value;"); code.add(" }");
* code.add(" }"); code.add(" return null;");
* code.add(" }"); code.add(" "); code.add(" }");
*/
}
}
}
for (InputOutputVariables inputOutputVariable : project.getInputData()
.getListInputOutputVariables()) {
if (inputOutputVariable.getDataType()
.compareTo(DataType.ENUMERATED) == 0) {
if (inputOutputVariable.getDefaultValue() == null
|| inputOutputVariable.getDefaultValue().isEmpty()) {
} else {
String uuid = "" + UUID.randomUUID();
uuid = uuid.replaceAll("-", "");
String nameEnum = "opIO" + inputOutputVariable.getId()
+ uuid;
enumUUID.put("opIO" + inputOutputVariable.getId(), nameEnum);
code.add("");
code.add(" static class " + nameEnum
+ " extends DynamicEnum {");
code.add(" public enum E" + nameEnum + " {};");
code.add(" public Field[] getFields() {");
code.add(" Field[] fields = E" + nameEnum
+ ".class.getDeclaredFields();");
code.add(" return fields;");
code.add(" }");
code.add(" }");
/*
* code.add(" String[] opIO" + inputOutputVariable.getId() +
* " = {"); String[] values =
* inputOutputVariable.getDefaultValue() .split("\\|"); if
* (values.length < 1) {
*
* } else { for (int i = 0; i < values.length; i++) { if (i
* == values.length - 1) { code.add(" \"" + values[i] +
* "\""); } else { code.add(" \"" + values[i] + "\","); } }
* } code.add(" };");
*/
/*
* code.add(" public static enum opIO"
*
* + inputOutputVariable.getId() + " {"); String[] values =
* inputOutputVariable.getDefaultValue() .split("\\|"); if
* (values.length < 1) {
*
* } else { for (int i = 0; i < values.length; i++) { String
* identifier = values[i].trim(); identifier =
* identifier.replaceAll("\\s+", ""); if (i == values.length
* - 1) { code.add(" " + identifier + "(\"" + values[i] +
* "\");"); } else { code.add(" " + identifier + "(\"" +
* values[i] + "\"),"); } } } code.add(" ");
* code.add(" private final String id;"); code.add(" ");
* code.add(" private opIO" + inputOutputVariable.getId() +
* "(final String id) {"); code.add(" this.id = id;");
* code.add(" }"); code.add(" "); code.add(" @Override");
* code.add(" public String toString() {");
* code.add(" return id;"); code.add(" }");
* code.add(" "); code.add(" public String getId() {");
* code.add(" return id;"); code.add(" }");
* code.add(" "); code.add(" public opIO" +
* inputOutputVariable.getId() +
* " getIdentifier(String identifier){");
* code.add(" if(identifier==null|| identifier.isEmpty()){"
* ); code.add(" return null;"); code.add(" }");
* code.add(" "); code.add(" for(opIO" +
* inputOutputVariable.getId() + " value:opIO" +
* inputOutputVariable.getId() + ".values()){");
* code.add(" if(value.id.compareTo(identifier)==0){");
* code.add(" return value;"); code.add(" }");
* code.add(" }"); code.add(" return null;");
* code.add(" }"); code.add(" "); code.add(" }");
*/
}
}
}
code.addAll(Arrays.asList("", " @Override",
" public String getDescription() {", " return \""
+ project.getInputData().getProjectInfo()
.getAlgorithmDescription() + "\";", " }", "",
" protected void initVariables(){",
" mainScriptName=\"" + mainScriptRelativePath + "\";",
" packageURL=\"" + packageUrl + "\";",
" protected void initVariables(){", " mainScriptName=\""
+ mainScriptRelativePath + "\";", " packageURL=\""
+ packageUrl + "\";",
" environmentalvariables = new ArrayList<String>();"));
for (GlobalVariables envVariable : project.getInputData()
for (GlobalVariables globalVariable : project.getInputData()
.getListGlobalVariables()) {
code.add(" environmentalvariables.add(\"" + envVariable.getName()
+ "\");");
code.add(" environmentalvariables.add(\""
+ globalVariable.getName() + "\");");
}
for (InputOutputVariables selVariable : project.getInputData()
@ -158,12 +313,60 @@ public class AlgorithmGenerator {
+ selVariable.getDefaultValue() + "\"));");
break;
case ENUMERATED:
code.add(" inputs.add(new PrimitiveType(Enum.class.getName(), operators.values(),PrimitiveTypes.ENUMERATED, \""
String[] values = selVariable.getDefaultValue()
.split("\\|");
if (values.length > 0) {
// TODO
String nameEnum = enumUUID.get("opIO"
+ selVariable.getId());
code.add(" if (org.gcube.dataanalysis.executor.rscripts."
+ project.getInputData().getProjectInfo()
.getAlgorithmNameToClassName()
+ "."
+ nameEnum
+ ".E"
+ nameEnum
+ ".values().length==0){");
code.add(" " + nameEnum + " en = new " + nameEnum
+ "();");
for (String val : values) {
code.add(" en.addEnum(org.gcube.dataanalysis.executor.rscripts."
+ project.getInputData().getProjectInfo()
.getAlgorithmNameToClassName()
+ "."
+ nameEnum
+ ".E"
+ nameEnum
+ ".class, \"" + val + "\");");
}
code.add(" }");
code.add("");
code.add(" addEnumerateInput(org.gcube.dataanalysis.executor.rscripts."
+ project.getInputData().getProjectInfo()
.getAlgorithmNameToClassName()
+ "."
+ nameEnum
+ ".E"
+ nameEnum
+ ".values(), \""
+ selVariable.getName()
+ "\", \""
+ selVariable.getDescription()
+ "\", \""
+ selVariable.getDefaultValue() + "\"));");
+ values[0] + "\");");
/*
* code.add(
* " inputs.add(new PrimitiveType(Enum.class.getName(), opIO"
* + selVariable.getId() +
* ".values(),PrimitiveTypes.ENUMERATED, \"" +
* selVariable.getName() + "\", \"" +
* selVariable.getDescription() + "\", \"" + values[0] +
* "\"));");
*/
}
break;
case FILE:
code.add(" inputs.add(new PrimitiveType(File.class.getName(), null,PrimitiveTypes.FILE, \""
@ -271,13 +474,11 @@ public class AlgorithmGenerator {
}
private String retrieveMainScriptRelativePath() {
String projectPath = project.getProjectFolder().getFolder()
.getPath();
String projectPath = project.getProjectFolder().getFolder().getPath();
String mainCodePath = project.getMainCode().getItemDescription()
.getPath();
String relativePath = project.getProjectFolder().getFolder()
.getName()
String relativePath = project.getProjectFolder().getFolder().getName()
+ mainCodePath.substring(projectPath.length());
return relativePath;
@ -285,12 +486,14 @@ public class AlgorithmGenerator {
private String retrievePackageUrl() {
String packageUrl = "";
if (project.getProjectTarget()!=null&&
project.getProjectTarget().getProjectDeploy() != null
&& project.getProjectTarget().getProjectDeploy().getPackageProject() != null) {
if (project.getProjectTarget().getProjectDeploy().getPackageProject().getPublicLink() != null) {
packageUrl = project.getProjectTarget().getProjectDeploy().getPackageProject()
.getPublicLink();
if (project.getProjectTarget() != null
&& project.getProjectTarget().getProjectDeploy() != null
&& project.getProjectTarget().getProjectDeploy()
.getPackageProject() != null) {
if (project.getProjectTarget().getProjectDeploy()
.getPackageProject().getPublicLink() != null) {
packageUrl = project.getProjectTarget().getProjectDeploy()
.getPackageProject().getPublicLink();
}
}
return packageUrl;

View File

@ -5,30 +5,24 @@ import java.util.List;
/**
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
* @author "Giancarlo Panichi" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public enum DataType {
STRING("String"),
INTEGER("Integer"),
DOUBLE("Double"),
ENUMERATED("Enumerated"),
FILE("File"),
BOOLEAN("Boolean");
STRING("String"), INTEGER("Integer"), DOUBLE("Double"), ENUMERATED(
"Enumerated"), FILE("File"), BOOLEAN("Boolean");
//private static InputTypeMessages msgs=GWT.create(InputTypeMessages.class);
// private static InputTypeMessages
// msgs=GWT.create(InputTypeMessages.class);
private String id;
// private static List<String> inputTypeI18NList;
/*static {
inputTypeI18NList = new ArrayList<String>();
for (InputType itype : values()) {
inputTypeI18NList.add(msgs.inputType(itype));
}
}*/
/*
* static { inputTypeI18NList = new ArrayList<String>(); for (InputType
* itype : values()) { inputTypeI18NList.add(msgs.inputType(itype)); } }
*/
private DataType(String id) {
this.id = id;
@ -47,15 +41,21 @@ public enum DataType {
return id;
}
public static List<DataType> asList() {
List<DataType> list = Arrays.asList(values());
return list;
}
/*public static List<String> asI18NList() {
return inputTypeI18NList;
public static List<DataType> asListForGlobalVariables() {
List<DataType> list = Arrays.asList(DataType.STRING, DataType.INTEGER,
DataType.DOUBLE, DataType.FILE, DataType.BOOLEAN);
return list;
}
}*/
/*
* public static List<String> asI18NList() { return inputTypeI18NList;
*
* }
*/
}