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:
parent
b289d6718f
commit
cdb0ea5424
|
@ -323,7 +323,7 @@ public class StatAlgoImporterController {
|
||||||
pm.saveProject(event.getInputData(), monitor);
|
pm.saveProject(event.getInputData(), monitor);
|
||||||
break;
|
break;
|
||||||
case SoftwareCreate:
|
case SoftwareCreate:
|
||||||
pm.createSofware(event.getInputData(), monitor);
|
pm.softwareCreate(event.getInputData(), monitor);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -17,8 +17,8 @@ public class CodeParser {
|
||||||
|
|
||||||
private static final String IMAGE_PATTERN = "([^\\s]+(\\.(jpg|png|gif|bmp)\"))";
|
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 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 ENUM1_PATTERN = "(c\\([^\\)]*\\))";
|
||||||
private static final String ENUM2_PATTERN = "(\\{[^\\}]*\\})";
|
//private static final String ENUM2_PATTERN = "(\\{[^\\}]*\\})";
|
||||||
|
|
||||||
public CodeParser() {
|
public CodeParser() {
|
||||||
|
|
||||||
|
@ -111,6 +111,7 @@ public class CodeParser {
|
||||||
return DataType.FILE;
|
return DataType.FILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
RegExp regExpEnum1 = RegExp.compile(ENUM1_PATTERN);
|
RegExp regExpEnum1 = RegExp.compile(ENUM1_PATTERN);
|
||||||
if (regExpEnum1.test(data)) {
|
if (regExpEnum1.test(data)) {
|
||||||
return DataType.ENUMERATED;
|
return DataType.ENUMERATED;
|
||||||
|
@ -119,7 +120,7 @@ public class CodeParser {
|
||||||
RegExp regExpEnum2 = RegExp.compile(ENUM2_PATTERN);
|
RegExp regExpEnum2 = RegExp.compile(ENUM2_PATTERN);
|
||||||
if (regExpEnum2.test(data)) {
|
if (regExpEnum2.test(data)) {
|
||||||
return DataType.ENUMERATED;
|
return DataType.ENUMERATED;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Integer.parseInt(data);
|
Integer.parseInt(data);
|
||||||
|
|
|
@ -73,6 +73,7 @@ public class MainDataPanel extends SimpleContainer {
|
||||||
case SOFTWARE_REPACKAGE:
|
case SOFTWARE_REPACKAGE:
|
||||||
case ADD_RESOURCE:
|
case ADD_RESOURCE:
|
||||||
case DELETE_RESOURCE:
|
case DELETE_RESOURCE:
|
||||||
|
case EXPLORER_REFRESH:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -194,7 +194,7 @@ public class ProjectManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addResourceToProject(Item item) {
|
private void addResourceToProject(Item item) {
|
||||||
final StatAlgoImporterMonitor monitor=new StatAlgoImporterMonitor();
|
final StatAlgoImporterMonitor monitor = new StatAlgoImporterMonitor();
|
||||||
Log.debug("Add Resource To Project Item selected: " + item);
|
Log.debug("Add Resource To Project Item selected: " + item);
|
||||||
ItemDescription itemDescription = new ItemDescription(item.getId(),
|
ItemDescription itemDescription = new ItemDescription(item.getId(),
|
||||||
item.getName(), item.getOwner(), item.getPath(), item.getType()
|
item.getName(), item.getOwner(), item.getPath(), item.getType()
|
||||||
|
@ -228,7 +228,7 @@ public class ProjectManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createProjectOnServer(Item item) {
|
private void createProjectOnServer(Item item) {
|
||||||
final StatAlgoImporterMonitor monitor=new StatAlgoImporterMonitor();
|
final StatAlgoImporterMonitor monitor = new StatAlgoImporterMonitor();
|
||||||
Log.debug("Create Project Item selected: " + item);
|
Log.debug("Create Project Item selected: " + item);
|
||||||
final ItemDescription newProjectFolder = new ItemDescription(
|
final ItemDescription newProjectFolder = new ItemDescription(
|
||||||
item.getId(), item.getName(), item.getOwner(), item.getPath(),
|
item.getId(), item.getName(), item.getOwner(), item.getPath(),
|
||||||
|
@ -263,7 +263,7 @@ public class ProjectManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void openProjectOnServer(Item item) {
|
protected void openProjectOnServer(Item item) {
|
||||||
final StatAlgoImporterMonitor monitor=new StatAlgoImporterMonitor();
|
final StatAlgoImporterMonitor monitor = new StatAlgoImporterMonitor();
|
||||||
|
|
||||||
Log.debug("Open Project Item selected: " + item);
|
Log.debug("Open Project Item selected: " + item);
|
||||||
final ItemDescription newProjectFolder = new ItemDescription(
|
final ItemDescription newProjectFolder = new ItemDescription(
|
||||||
|
@ -330,7 +330,7 @@ public class ProjectManager {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createSofware(final InputData inputData,
|
public void softwareCreate(final InputData inputData,
|
||||||
final StatAlgoImporterMonitor monitor) {
|
final StatAlgoImporterMonitor monitor) {
|
||||||
|
|
||||||
StatAlgoImporterServiceAsync.INSTANCE.createSoftware(inputData,
|
StatAlgoImporterServiceAsync.INSTANCE.createSoftware(inputData,
|
||||||
|
@ -355,6 +355,8 @@ public class ProjectManager {
|
||||||
+ caught.getLocalizedMessage());
|
+ caught.getLocalizedMessage());
|
||||||
UtilsGXT3.alert("Error",
|
UtilsGXT3.alert("Error",
|
||||||
caught.getLocalizedMessage());
|
caught.getLocalizedMessage());
|
||||||
|
fireProjectStatusExplorerRefreshEvent();
|
||||||
|
|
||||||
}
|
}
|
||||||
caught.printStackTrace();
|
caught.printStackTrace();
|
||||||
|
|
||||||
|
@ -548,7 +550,6 @@ public class ProjectManager {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void startProjectManager(String value) {
|
public void startProjectManager(String value) {
|
||||||
|
|
||||||
StatAlgoImporterServiceAsync.INSTANCE.restoreUISession(value,
|
StatAlgoImporterServiceAsync.INSTANCE.restoreUISession(value,
|
||||||
|
@ -605,7 +606,6 @@ public class ProjectManager {
|
||||||
UtilsGXT3.alert("Error", "Project not open!");
|
UtilsGXT3.alert("Error", "Project not open!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void softwareRepackageOnServer() {
|
private void softwareRepackageOnServer() {
|
||||||
|
@ -621,7 +621,7 @@ public class ProjectManager {
|
||||||
} else {
|
} else {
|
||||||
UtilsGXT3.alert("Error",
|
UtilsGXT3.alert("Error",
|
||||||
caught.getLocalizedMessage());
|
caught.getLocalizedMessage());
|
||||||
|
fireProjectStatusExplorerRefreshEvent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -635,8 +635,6 @@ public class ProjectManager {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void softwarePublish() {
|
public void softwarePublish() {
|
||||||
if (project != null) {
|
if (project != null) {
|
||||||
final ConfirmMessageBox mb = new ConfirmMessageBox(
|
final ConfirmMessageBox mb = new ConfirmMessageBox(
|
||||||
|
@ -681,6 +679,7 @@ public class ProjectManager {
|
||||||
} else {
|
} else {
|
||||||
UtilsGXT3.alert("Error",
|
UtilsGXT3.alert("Error",
|
||||||
caught.getLocalizedMessage());
|
caught.getLocalizedMessage());
|
||||||
|
fireProjectStatusExplorerRefreshEvent();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -707,7 +706,6 @@ public class ProjectManager {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private void fireProjectStatusSaveProjectEvent() {
|
private void fireProjectStatusSaveProjectEvent() {
|
||||||
ProjectStatusEvent projectStatusEvent = new ProjectStatusEvent(
|
ProjectStatusEvent projectStatusEvent = new ProjectStatusEvent(
|
||||||
|
@ -745,6 +743,13 @@ public class ProjectManager {
|
||||||
Log.debug("ProjectStatusEvent fired! " + projectStatusEvent);
|
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() {
|
private void fireProjectStatusMainCodeSetEvent() {
|
||||||
ProjectStatusEvent projectStatusEvent = new ProjectStatusEvent(
|
ProjectStatusEvent projectStatusEvent = new ProjectStatusEvent(
|
||||||
ProjectStatusEventType.MAIN_CODE_SET, project);
|
ProjectStatusEventType.MAIN_CODE_SET, project);
|
||||||
|
@ -773,8 +778,6 @@ public class ProjectManager {
|
||||||
Log.debug("ProjectStatusEvent fired! " + projectStatusEvent);
|
Log.debug("ProjectStatusEvent fired! " + projectStatusEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void fireProjectStatusStartEvent() {
|
private void fireProjectStatusStartEvent() {
|
||||||
ProjectStatusEvent projectStatusEvent = new ProjectStatusEvent(
|
ProjectStatusEvent projectStatusEvent = new ProjectStatusEvent(
|
||||||
ProjectStatusEventType.START, project);
|
ProjectStatusEventType.START, project);
|
||||||
|
@ -782,5 +785,4 @@ public class ProjectManager {
|
||||||
Log.debug("ProjectStatusEvent fired! " + projectStatusEvent);
|
Log.debug("ProjectStatusEvent fired! " + projectStatusEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,6 +120,7 @@ public class ExplorerProjectPanel extends ContentPanel {
|
||||||
case SOFTWARE_CREATED:
|
case SOFTWARE_CREATED:
|
||||||
case SOFTWARE_PUBLISH:
|
case SOFTWARE_PUBLISH:
|
||||||
case SOFTWARE_REPACKAGE:
|
case SOFTWARE_REPACKAGE:
|
||||||
|
case EXPLORER_REFRESH:
|
||||||
reloadWSResourceExplorerPanel();
|
reloadWSResourceExplorerPanel();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -397,7 +397,8 @@ public class GlobalVariablesPanel extends ContentPanel {
|
||||||
int row = storeGlobalVariable.indexOf(newGlobalVariable);
|
int row = storeGlobalVariable.indexOf(newGlobalVariable);
|
||||||
|
|
||||||
storeComboInputType.clear();
|
storeComboInputType.clear();
|
||||||
storeComboInputType.addAll(DataType.asList());
|
|
||||||
|
storeComboInputType.addAll(DataType.asListForGlobalVariables());
|
||||||
storeComboInputType.commitChanges();
|
storeComboInputType.commitChanges();
|
||||||
|
|
||||||
gridGlobalVariableEditing.startEditing(new GridCell(row, 0));
|
gridGlobalVariableEditing.startEditing(new GridCell(row, 0));
|
||||||
|
|
|
@ -115,6 +115,7 @@ public class InputVariablePanel extends ContentPanel {
|
||||||
case START:
|
case START:
|
||||||
case ADD_RESOURCE:
|
case ADD_RESOURCE:
|
||||||
case DELETE_RESOURCE:
|
case DELETE_RESOURCE:
|
||||||
|
case EXPLORER_REFRESH:
|
||||||
break;
|
break;
|
||||||
case OPEN:
|
case OPEN:
|
||||||
create(event.getProject());
|
create(event.getProject());
|
||||||
|
|
|
@ -17,6 +17,7 @@ public enum ProjectStatusEventType {
|
||||||
SOFTWARE_CREATED,
|
SOFTWARE_CREATED,
|
||||||
SOFTWARE_PUBLISH,
|
SOFTWARE_PUBLISH,
|
||||||
SOFTWARE_REPACKAGE,
|
SOFTWARE_REPACKAGE,
|
||||||
|
EXPLORER_REFRESH,
|
||||||
SAVE;
|
SAVE;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,12 @@ import java.nio.file.Path;
|
||||||
import java.nio.file.StandardOpenOption;
|
import java.nio.file.StandardOpenOption;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterServiceException;
|
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.GlobalVariables;
|
||||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.input.IOType;
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.input.IOType;
|
||||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.input.InputOutputVariables;
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.input.InputOutputVariables;
|
||||||
|
@ -30,6 +33,7 @@ public class AlgorithmGenerator {
|
||||||
.getLogger(AlgorithmGenerator.class);
|
.getLogger(AlgorithmGenerator.class);
|
||||||
|
|
||||||
private Project project;
|
private Project project;
|
||||||
|
private HashMap<String, String> enumUUID;
|
||||||
|
|
||||||
public AlgorithmGenerator(Project project) {
|
public AlgorithmGenerator(Project project) {
|
||||||
super();
|
super();
|
||||||
|
@ -42,10 +46,10 @@ public class AlgorithmGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Path createAlgorithm() throws StatAlgoImporterServiceException {
|
public Path createAlgorithm() throws StatAlgoImporterServiceException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Path tempFile = Files.createTempFile(project.getInputData()
|
Path tempFile = Files.createTempFile(project.getInputData()
|
||||||
.getProjectInfo().getAlgorithmNameToClassName(), EXTENTION_JAVA);
|
.getProjectInfo().getAlgorithmNameToClassName(),
|
||||||
|
EXTENTION_JAVA);
|
||||||
|
|
||||||
List<String> lines = createJavaCode();
|
List<String> lines = createJavaCode();
|
||||||
Files.write(tempFile, lines, Charset.defaultCharset(),
|
Files.write(tempFile, lines, Charset.defaultCharset(),
|
||||||
|
@ -65,8 +69,8 @@ public class AlgorithmGenerator {
|
||||||
private List<String> createJavaCode() {
|
private List<String> createJavaCode() {
|
||||||
String mainScriptRelativePath = retrieveMainScriptRelativePath();
|
String mainScriptRelativePath = retrieveMainScriptRelativePath();
|
||||||
String packageUrl = retrievePackageUrl();
|
String packageUrl = retrievePackageUrl();
|
||||||
|
enumUUID = new HashMap<>();
|
||||||
ArrayList<String> code = new ArrayList<String>();
|
ArrayList<String> code = new ArrayList<>();
|
||||||
|
|
||||||
code.addAll(Arrays
|
code.addAll(Arrays
|
||||||
.asList("package org.gcube.dataanalysis.executor.rscripts;",
|
.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.StatisticalType;",
|
||||||
"import org.gcube.dataanalysis.ecoengine.datatypes.enumtypes.PrimitiveTypes;",
|
"import org.gcube.dataanalysis.ecoengine.datatypes.enumtypes.PrimitiveTypes;",
|
||||||
"import org.gcube.dataanalysis.executor.rscripts.generic.GenericRScript;",
|
"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()
|
+ project.getInputData().getProjectInfo()
|
||||||
.getAlgorithmNameToClassName()
|
.getAlgorithmNameToClassName()
|
||||||
+ " extends GenericRScript {", "",
|
+ " extends GenericRScript {"));
|
||||||
|
|
||||||
" public static enum operators {",
|
for (GlobalVariables globalVariable : project.getInputData()
|
||||||
" EQUAL, NOT_EQUAL, CONTAINS, BEGINS_WITH, ENDS_WITH",
|
.getListGlobalVariables()) {
|
||||||
" };", "", " @Override",
|
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 \""
|
" public String getDescription() {", " return \""
|
||||||
+ project.getInputData().getProjectInfo()
|
+ project.getInputData().getProjectInfo()
|
||||||
.getAlgorithmDescription() + "\";", " }", "",
|
.getAlgorithmDescription() + "\";", " }", "",
|
||||||
" protected void initVariables(){",
|
" protected void initVariables(){", " mainScriptName=\""
|
||||||
" mainScriptName=\"" + mainScriptRelativePath + "\";",
|
+ mainScriptRelativePath + "\";", " packageURL=\""
|
||||||
" packageURL=\"" + packageUrl + "\";",
|
+ packageUrl + "\";",
|
||||||
" environmentalvariables = new ArrayList<String>();"));
|
" environmentalvariables = new ArrayList<String>();"));
|
||||||
|
|
||||||
for (GlobalVariables envVariable : project.getInputData()
|
for (GlobalVariables globalVariable : project.getInputData()
|
||||||
.getListGlobalVariables()) {
|
.getListGlobalVariables()) {
|
||||||
code.add(" environmentalvariables.add(\"" + envVariable.getName()
|
code.add(" environmentalvariables.add(\""
|
||||||
+ "\");");
|
+ globalVariable.getName() + "\");");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (InputOutputVariables selVariable : project.getInputData()
|
for (InputOutputVariables selVariable : project.getInputData()
|
||||||
|
@ -158,12 +313,60 @@ public class AlgorithmGenerator {
|
||||||
+ selVariable.getDefaultValue() + "\"));");
|
+ selVariable.getDefaultValue() + "\"));");
|
||||||
break;
|
break;
|
||||||
case ENUMERATED:
|
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.getName()
|
||||||
+ "\", \""
|
+ "\", \""
|
||||||
+ selVariable.getDescription()
|
+ 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;
|
break;
|
||||||
case FILE:
|
case FILE:
|
||||||
code.add(" inputs.add(new PrimitiveType(File.class.getName(), null,PrimitiveTypes.FILE, \""
|
code.add(" inputs.add(new PrimitiveType(File.class.getName(), null,PrimitiveTypes.FILE, \""
|
||||||
|
@ -271,13 +474,11 @@ public class AlgorithmGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String retrieveMainScriptRelativePath() {
|
private String retrieveMainScriptRelativePath() {
|
||||||
String projectPath = project.getProjectFolder().getFolder()
|
String projectPath = project.getProjectFolder().getFolder().getPath();
|
||||||
.getPath();
|
|
||||||
String mainCodePath = project.getMainCode().getItemDescription()
|
String mainCodePath = project.getMainCode().getItemDescription()
|
||||||
.getPath();
|
.getPath();
|
||||||
|
|
||||||
String relativePath = project.getProjectFolder().getFolder()
|
String relativePath = project.getProjectFolder().getFolder().getName()
|
||||||
.getName()
|
|
||||||
+ mainCodePath.substring(projectPath.length());
|
+ mainCodePath.substring(projectPath.length());
|
||||||
return relativePath;
|
return relativePath;
|
||||||
|
|
||||||
|
@ -285,12 +486,14 @@ public class AlgorithmGenerator {
|
||||||
|
|
||||||
private String retrievePackageUrl() {
|
private String retrievePackageUrl() {
|
||||||
String packageUrl = "";
|
String packageUrl = "";
|
||||||
if (project.getProjectTarget()!=null&&
|
if (project.getProjectTarget() != null
|
||||||
project.getProjectTarget().getProjectDeploy() != null
|
&& project.getProjectTarget().getProjectDeploy() != null
|
||||||
&& project.getProjectTarget().getProjectDeploy().getPackageProject() != null) {
|
&& project.getProjectTarget().getProjectDeploy()
|
||||||
if (project.getProjectTarget().getProjectDeploy().getPackageProject().getPublicLink() != null) {
|
.getPackageProject() != null) {
|
||||||
packageUrl = project.getProjectTarget().getProjectDeploy().getPackageProject()
|
if (project.getProjectTarget().getProjectDeploy()
|
||||||
.getPublicLink();
|
.getPackageProject().getPublicLink() != null) {
|
||||||
|
packageUrl = project.getProjectTarget().getProjectDeploy()
|
||||||
|
.getPackageProject().getPublicLink();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return packageUrl;
|
return packageUrl;
|
||||||
|
|
|
@ -5,30 +5,24 @@ import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author "Giancarlo Panichi"
|
* @author "Giancarlo Panichi" <a
|
||||||
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public enum DataType {
|
public enum DataType {
|
||||||
STRING("String"),
|
STRING("String"), INTEGER("Integer"), DOUBLE("Double"), ENUMERATED(
|
||||||
INTEGER("Integer"),
|
"Enumerated"), FILE("File"), BOOLEAN("Boolean");
|
||||||
DOUBLE("Double"),
|
|
||||||
ENUMERATED("Enumerated"),
|
|
||||||
FILE("File"),
|
|
||||||
BOOLEAN("Boolean");
|
|
||||||
|
|
||||||
|
// private static InputTypeMessages
|
||||||
//private static InputTypeMessages msgs=GWT.create(InputTypeMessages.class);
|
// msgs=GWT.create(InputTypeMessages.class);
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
//private static List<String> inputTypeI18NList;
|
// private static List<String> inputTypeI18NList;
|
||||||
|
|
||||||
/*static {
|
/*
|
||||||
inputTypeI18NList = new ArrayList<String>();
|
* static { inputTypeI18NList = new ArrayList<String>(); for (InputType
|
||||||
for (InputType itype : values()) {
|
* itype : values()) { inputTypeI18NList.add(msgs.inputType(itype)); } }
|
||||||
inputTypeI18NList.add(msgs.inputType(itype));
|
*/
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
private DataType(String id) {
|
private DataType(String id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
@ -42,20 +36,26 @@ public enum DataType {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLabel(){
|
public String getLabel() {
|
||||||
//return msgs.inputType(this);
|
// return msgs.inputType(this);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static List<DataType> asList() {
|
public static List<DataType> asList() {
|
||||||
List<DataType> list = Arrays.asList(values());
|
List<DataType> list = Arrays.asList(values());
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*public static List<String> asI18NList() {
|
public static List<DataType> asListForGlobalVariables() {
|
||||||
return inputTypeI18NList;
|
List<DataType> list = Arrays.asList(DataType.STRING, DataType.INTEGER,
|
||||||
|
DataType.DOUBLE, DataType.FILE, DataType.BOOLEAN);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
}*/
|
/*
|
||||||
|
* public static List<String> asI18NList() { return inputTypeI18NList;
|
||||||
|
*
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue