1452: Implement a GUI for StatMan Algorithms Importer
Task-Url: https://support.d4science.org/issues/1452 Added Annotation Parser git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/statistical-algorithms-importer@122702 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
cdb0ea5424
commit
b308f1c32b
33
pom.xml
33
pom.xml
|
@ -302,6 +302,25 @@
|
|||
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 52n-wps-client -->
|
||||
<dependency>
|
||||
<groupId>org.n52.wps</groupId>
|
||||
<artifactId>52n-wps-client-lib</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>gt-opengis</artifactId>
|
||||
<groupId>org.geotools</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.n52.wps</groupId>
|
||||
<artifactId>52n-wps-r</artifactId>
|
||||
<version>(0.0.1,5.0.0)</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
<!-- LOGGING -->
|
||||
<dependency>
|
||||
|
@ -515,7 +534,21 @@
|
|||
</plugins>
|
||||
|
||||
</build>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>n52-releases</id>
|
||||
<name>52n Releases</name>
|
||||
<url>http://52north.org/maven/repo/releases/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
|
|
@ -14,7 +14,6 @@ import org.gcube.portlets.user.statisticalalgorithmsimporter.client.type.Session
|
|||
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.utils.UtilsGXT3;
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterSessionExpiredException;
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.InputData;
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.MainCode;
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.Project;
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.ProjectFolder;
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.workspace.ItemDescription;
|
||||
|
@ -403,7 +402,7 @@ public class ProjectManager {
|
|||
|
||||
Log.debug("Set Main Code: " + itemDescription);
|
||||
StatAlgoImporterServiceAsync.INSTANCE.setMainCode(itemDescription,
|
||||
new AsyncCallback<Void>() {
|
||||
new AsyncCallback<Project>() {
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
|
@ -421,8 +420,8 @@ public class ProjectManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(Void result) {
|
||||
project.setMainCode(new MainCode(itemDescription));
|
||||
public void onSuccess(Project result) {
|
||||
project=result;
|
||||
fireProjectStatusMainCodeSetEvent();
|
||||
}
|
||||
});
|
||||
|
@ -433,7 +432,7 @@ public class ProjectManager {
|
|||
final StatAlgoImporterMonitor monitor) {
|
||||
StatAlgoImporterServiceAsync.INSTANCE.setNewMainCode(
|
||||
newMainCodeEvent.getFile(), newMainCodeEvent.getCode(),
|
||||
new AsyncCallback<ItemDescription>() {
|
||||
new AsyncCallback<Project>() {
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
|
@ -452,8 +451,8 @@ public class ProjectManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(ItemDescription itemDescription) {
|
||||
project.setMainCode(new MainCode(itemDescription));
|
||||
public void onSuccess(Project result) {
|
||||
project=result;
|
||||
fireProjectStatusMainCodeSetEvent();
|
||||
monitor.hide();
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ public interface StatAlgoImporterService extends RemoteService {
|
|||
throws StatAlgoImporterServiceException;
|
||||
|
||||
//
|
||||
public void setMainCode(ItemDescription itemDescription)
|
||||
public Project setMainCode(ItemDescription itemDescription)
|
||||
throws StatAlgoImporterServiceException;
|
||||
|
||||
public void addResourceToProject(ItemDescription itemDescription)
|
||||
|
@ -73,7 +73,7 @@ public interface StatAlgoImporterService extends RemoteService {
|
|||
public Project restoreUISession(String value)
|
||||
throws StatAlgoImporterServiceException;
|
||||
|
||||
public ItemDescription setNewMainCode(ItemDescription itemDescription,
|
||||
public Project setNewMainCode(ItemDescription itemDescription,
|
||||
String code) throws StatAlgoImporterServiceException;
|
||||
|
||||
public void publishSoftware() throws StatAlgoImporterServiceException;
|
||||
|
|
|
@ -39,7 +39,8 @@ public interface StatAlgoImporterServiceAsync {
|
|||
void createProjectOnWorkspace(ItemDescription itemDescription,
|
||||
AsyncCallback<Void> callback);
|
||||
|
||||
void setMainCode(ItemDescription itemDescription, AsyncCallback<Void> callback);
|
||||
void setMainCode(ItemDescription itemDescription,
|
||||
AsyncCallback<Project> callback);
|
||||
|
||||
void addResourceToProject(ItemDescription itemDescription,
|
||||
AsyncCallback<Void> asyncCallback);
|
||||
|
@ -55,7 +56,8 @@ public interface StatAlgoImporterServiceAsync {
|
|||
|
||||
void saveCode(String code, AsyncCallback<Void> asyncCallback);
|
||||
|
||||
void setNewMainCode(ItemDescription itemDescription, String code, AsyncCallback<ItemDescription> asyncCallback);
|
||||
void setNewMainCode(ItemDescription itemDescription, String code,
|
||||
AsyncCallback<Project> asyncCallback);
|
||||
|
||||
void createSoftware(InputData inputData, AsyncCallback<Void> callback);
|
||||
|
||||
|
|
|
@ -429,7 +429,7 @@ public class GlobalVariablesPanel extends ContentPanel {
|
|||
return listGlobalVarialbles;
|
||||
}
|
||||
|
||||
public void setMainCode(Project project) {
|
||||
public void clearVariables(Project project) {
|
||||
storeGlobalVariable.clear();
|
||||
storeGlobalVariable.commitChanges();
|
||||
seq = 0;
|
||||
|
|
|
@ -485,7 +485,7 @@ public class InputOutputVariablesPanel extends ContentPanel {
|
|||
return listInputOutputVarialbles;
|
||||
}
|
||||
|
||||
public void setMainCode(Project project) {
|
||||
public void clearVariables(Project project) {
|
||||
storeInputOutputVariables.clear();
|
||||
storeInputOutputVariables.commitChanges();
|
||||
seq = 0;
|
||||
|
|
|
@ -77,9 +77,10 @@ public class InputVariableTabPanel extends TabPanel {
|
|||
//
|
||||
public void setMainCode(Project project) {
|
||||
try {
|
||||
globalVariablesPanel.setMainCode(project);
|
||||
inputOutputVariablesPanel.setMainCode(project);
|
||||
|
||||
globalVariablesPanel.update(project);
|
||||
inputOutputVariablesPanel.update(project);
|
||||
projectInfoPanel.update(project);
|
||||
interpreterInfoPanel.update(project);
|
||||
forceLayout();
|
||||
} catch (Throwable e) {
|
||||
Log.error("Error in InputVariableTabPanel: "
|
||||
|
|
|
@ -391,10 +391,14 @@ public class InterpreterInfoPanel extends ContentPanel {
|
|||
seq = project.getInputData().getInterpreterInfo()
|
||||
.getInterpreterPackagesInfo().size();
|
||||
} else {
|
||||
storeInterpreterPackageInfo.clear();
|
||||
storeInterpreterPackageInfo.commitChanges();
|
||||
seq = 0;
|
||||
}
|
||||
} else {
|
||||
interpreterVersion.clear();
|
||||
storeInterpreterPackageInfo.clear();
|
||||
storeInterpreterPackageInfo.commitChanges();
|
||||
seq = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ import javax.servlet.http.HttpSession;
|
|||
import org.apache.commons.io.IOUtils;
|
||||
import org.gcube.application.framework.core.session.ASLSession;
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.rpc.StatAlgoImporterService;
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.annotation.WPS4RParser;
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.file.CodeReader;
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.generator.ProjectBuilder;
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.social.AlgorithmNotification;
|
||||
|
@ -260,21 +261,25 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setMainCode(ItemDescription itemDescription)
|
||||
public Project setMainCode(ItemDescription itemDescription)
|
||||
throws StatAlgoImporterServiceException {
|
||||
try {
|
||||
HttpSession session = this.getThreadLocalRequest().getSession();
|
||||
SessionUtil.getAslSession(session);
|
||||
ASLSession aslSession=SessionUtil.getAslSession(session);
|
||||
logger.debug("SetMainCode()");
|
||||
Project project = SessionUtil.getProjectSession(session);
|
||||
if (project != null) {
|
||||
project.setMainCode(new MainCode(itemDescription));
|
||||
project.setInputData(null);
|
||||
project.setProjectTarget(null);
|
||||
WPS4RParser wps4Parser=new WPS4RParser(project, aslSession);
|
||||
project=wps4Parser.parse();
|
||||
SessionUtil.setProjectSession(session, project);
|
||||
} else {
|
||||
throw new StatAlgoImporterServiceException("No project open!");
|
||||
}
|
||||
|
||||
return;
|
||||
return project;
|
||||
} catch (StatAlgoImporterServiceException e) {
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
|
@ -498,7 +503,7 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public ItemDescription setNewMainCode(ItemDescription fileDescription,
|
||||
public Project setNewMainCode(ItemDescription fileDescription,
|
||||
String code) throws StatAlgoImporterServiceException {
|
||||
try {
|
||||
HttpSession session = this.getThreadLocalRequest().getSession();
|
||||
|
@ -513,8 +518,12 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
|
|||
aslSession, fileDescription, code, project);
|
||||
MainCode mainCode = new MainCode(mainCodeItemDescription);
|
||||
project.setMainCode(mainCode);
|
||||
project.setInputData(null);
|
||||
project.setProjectTarget(null);
|
||||
WPS4RParser wps4Parser=new WPS4RParser(project, aslSession);
|
||||
project=wps4Parser.parse();
|
||||
SessionUtil.setProjectSession(session, project);
|
||||
return mainCodeItemDescription;
|
||||
return project;
|
||||
} else {
|
||||
throw new StatAlgoImporterServiceException("No project open!");
|
||||
}
|
||||
|
|
|
@ -0,0 +1,174 @@
|
|||
package org.gcube.portlets.user.statisticalalgorithmsimporter.server.annotation;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.application.framework.core.session.ASLSession;
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.storage.FilesStorage;
|
||||
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.IOType;
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.input.InputOutputVariables;
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.input.ProjectInfo;
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.InputData;
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.Project;
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.workspace.ItemDescription;
|
||||
import org.n52.wps.server.r.R_Config;
|
||||
import org.n52.wps.server.r.metadata.RAnnotationParser;
|
||||
import org.n52.wps.server.r.syntax.RAnnotation;
|
||||
import org.n52.wps.server.r.syntax.RAnnotationType;
|
||||
import org.n52.wps.server.r.syntax.RAttribute;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Giancarlo Panichi email: <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class WPS4RParser {
|
||||
|
||||
public static final Logger logger = LoggerFactory
|
||||
.getLogger(WPS4RParser.class);
|
||||
|
||||
|
||||
private Project project;
|
||||
private ASLSession aslSession;
|
||||
|
||||
public WPS4RParser(Project project, ASLSession aslSession) {
|
||||
this.project = project;
|
||||
this.aslSession = aslSession;
|
||||
}
|
||||
|
||||
public Project parse() throws StatAlgoImporterServiceException {
|
||||
ItemDescription mainCode = project.getMainCode().getItemDescription();
|
||||
FilesStorage fileStorage = new FilesStorage();
|
||||
InputStream is = fileStorage.retrieveItemOnWorkspace(
|
||||
aslSession.getUsername(), mainCode.getId());
|
||||
|
||||
R_Config config = R_Config.getInstance();
|
||||
|
||||
List<RAnnotation> annotations;
|
||||
try {
|
||||
RAnnotationParser parser = new RAnnotationParser(config);
|
||||
annotations = parser.parseAnnotationsfromScript(is);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
||||
} finally {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
WPSAlgorithmInfo wpsAlgorithmInfo = mapAnnotations(annotations);
|
||||
logger.debug("wpsAlgorithmInfo: "+wpsAlgorithmInfo);
|
||||
if (wpsAlgorithmInfo.getAlgorithmName() == null)
|
||||
return project;
|
||||
else
|
||||
return mapToProject(wpsAlgorithmInfo);
|
||||
|
||||
}
|
||||
|
||||
private Project mapToProject(WPSAlgorithmInfo wpsAlgorithmInfo) throws StatAlgoImporterServiceException {
|
||||
if(project==null){
|
||||
throw new StatAlgoImporterServiceException("Open project before!");
|
||||
}
|
||||
|
||||
if(project.getInputData()==null){
|
||||
ProjectInfo projectInfo=new ProjectInfo(wpsAlgorithmInfo.getAlgorithmName(), wpsAlgorithmInfo.getDescription(), null);
|
||||
InputData inputData=new InputData(projectInfo, null, null, wpsAlgorithmInfo.getInputOutputVariables());
|
||||
project.setInputData(inputData);
|
||||
} else {
|
||||
InputData inputData=project.getInputData();
|
||||
ProjectInfo projectInfo=new ProjectInfo(wpsAlgorithmInfo.getAlgorithmName(), wpsAlgorithmInfo.getDescription(), null);
|
||||
inputData.setProjectInfo(projectInfo);
|
||||
inputData.setListInputOutputVariables(wpsAlgorithmInfo.getInputOutputVariables());
|
||||
inputData.setListGlobalVariables(null);
|
||||
}
|
||||
return project;
|
||||
|
||||
}
|
||||
|
||||
private WPSAlgorithmInfo mapAnnotations(List<RAnnotation> annotations)
|
||||
throws StatAlgoImporterServiceException {
|
||||
try {
|
||||
|
||||
WPSAlgorithmInfo wpsAlgorithmInfo = new WPSAlgorithmInfo();
|
||||
ArrayList<InputOutputVariables> inputOutputVariables = new ArrayList<>();
|
||||
int index=1;
|
||||
for (RAnnotation rAnnotation : annotations) {
|
||||
if (rAnnotation.getType().equals(RAnnotationType.DESCRIPTION)) {
|
||||
wpsAlgorithmInfo.setVersion(rAnnotation
|
||||
.getStringValue(RAttribute.VERSION));
|
||||
wpsAlgorithmInfo.setDescription(rAnnotation
|
||||
.getStringValue(RAttribute.ABSTRACT));
|
||||
wpsAlgorithmInfo.setAlgorithmName(rAnnotation
|
||||
.getStringValue(RAttribute.TITLE));
|
||||
wpsAlgorithmInfo.setVersion(rAnnotation
|
||||
.getStringValue(RAttribute.VERSION));
|
||||
} else if (rAnnotation.getType().equals(RAnnotationType.OUTPUT)
|
||||
|| rAnnotation.getType().equals(RAnnotationType.INPUT)) {
|
||||
// output, text, Random number list,
|
||||
|
||||
String type = rAnnotation.getStringValue(RAttribute.TYPE);
|
||||
String name = rAnnotation
|
||||
.getStringValue(RAttribute.IDENTIFIER);
|
||||
String description = rAnnotation
|
||||
.getStringValue(RAttribute.TITLE);
|
||||
String defaultValue = rAnnotation
|
||||
.getStringValue(RAttribute.DEFAULT_VALUE);
|
||||
if (type == null)
|
||||
type = "string";
|
||||
if (name == null)
|
||||
name = "";
|
||||
if (description == null)
|
||||
description = "";
|
||||
if (defaultValue == null)
|
||||
defaultValue = "";
|
||||
|
||||
IOType ioType = IOType.INPUT;
|
||||
|
||||
if (rAnnotation.getType().equals(RAnnotationType.OUTPUT))
|
||||
ioType = IOType.OUTPUT;
|
||||
|
||||
DataType dataType = WPStype2DataType(type);
|
||||
if (defaultValue != null && defaultValue.contains("|")
|
||||
&& dataType == DataType.STRING)
|
||||
dataType = DataType.ENUMERATED;
|
||||
|
||||
InputOutputVariables ioVariable = new InputOutputVariables(
|
||||
index, name, description, defaultValue, dataType, ioType,
|
||||
"");
|
||||
inputOutputVariables.add(ioVariable);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
wpsAlgorithmInfo.setInputOutputVariables(inputOutputVariables);
|
||||
return wpsAlgorithmInfo;
|
||||
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static DataType WPStype2DataType(String type) {
|
||||
if (type.equalsIgnoreCase("double"))
|
||||
return DataType.DOUBLE;
|
||||
else if (type.equalsIgnoreCase("integer"))
|
||||
return DataType.INTEGER;
|
||||
else if (type.equalsIgnoreCase("string"))
|
||||
return DataType.STRING;
|
||||
else if (type.equalsIgnoreCase("boolean"))
|
||||
return DataType.BOOLEAN;
|
||||
else
|
||||
return DataType.FILE;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
package org.gcube.portlets.user.statisticalalgorithmsimporter.server.annotation;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.input.InputOutputVariables;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Giancarlo Panichi email: <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class WPSAlgorithmInfo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 6333710590825979561L;
|
||||
private String description;
|
||||
private String algorithmName;
|
||||
private String version;
|
||||
private ArrayList<InputOutputVariables> inputOutputVariables;
|
||||
|
||||
public WPSAlgorithmInfo() {
|
||||
super();
|
||||
}
|
||||
|
||||
public WPSAlgorithmInfo(String description, String algorithmName,
|
||||
String version, ArrayList<InputOutputVariables> inputOutputVariables) {
|
||||
super();
|
||||
this.description = description;
|
||||
this.algorithmName = algorithmName;
|
||||
this.version = version;
|
||||
this.inputOutputVariables = inputOutputVariables;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getAlgorithmName() {
|
||||
return algorithmName;
|
||||
}
|
||||
|
||||
public void setAlgorithmName(String algorithmName) {
|
||||
this.algorithmName = algorithmName;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public ArrayList<InputOutputVariables> getInputOutputVariables() {
|
||||
return inputOutputVariables;
|
||||
}
|
||||
|
||||
public void setInputOutputVariables(
|
||||
ArrayList<InputOutputVariables> inputOutputVariables) {
|
||||
this.inputOutputVariables = inputOutputVariables;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "WPSAlgorithmInfo [description=" + description
|
||||
+ ", algorithmName=" + algorithmName + ", version=" + version
|
||||
+ ", inputOutputVariables=" + inputOutputVariables + "]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue