1452: Implement a GUI for StatMan Algorithms Importer
Task-Url: https://support.d4science.org/issues/1452 Fixed InputStream on Annotations git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/statistical-algorithms-importer@122714 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
b308f1c32b
commit
3afec34257
|
@ -2,6 +2,10 @@ package org.gcube.portlets.user.statisticalalgorithmsimporter.server.annotation;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.nio.file.StandardOpenOption;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -18,6 +22,7 @@ import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.workspace.It
|
||||||
import org.n52.wps.server.r.R_Config;
|
import org.n52.wps.server.r.R_Config;
|
||||||
import org.n52.wps.server.r.metadata.RAnnotationParser;
|
import org.n52.wps.server.r.metadata.RAnnotationParser;
|
||||||
import org.n52.wps.server.r.syntax.RAnnotation;
|
import org.n52.wps.server.r.syntax.RAnnotation;
|
||||||
|
import org.n52.wps.server.r.syntax.RAnnotationException;
|
||||||
import org.n52.wps.server.r.syntax.RAnnotationType;
|
import org.n52.wps.server.r.syntax.RAnnotationType;
|
||||||
import org.n52.wps.server.r.syntax.RAttribute;
|
import org.n52.wps.server.r.syntax.RAttribute;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -34,7 +39,6 @@ public class WPS4RParser {
|
||||||
public static final Logger logger = LoggerFactory
|
public static final Logger logger = LoggerFactory
|
||||||
.getLogger(WPS4RParser.class);
|
.getLogger(WPS4RParser.class);
|
||||||
|
|
||||||
|
|
||||||
private Project project;
|
private Project project;
|
||||||
private ASLSession aslSession;
|
private ASLSession aslSession;
|
||||||
|
|
||||||
|
@ -44,52 +48,84 @@ public class WPS4RParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Project parse() throws StatAlgoImporterServiceException {
|
public Project parse() throws StatAlgoImporterServiceException {
|
||||||
|
logger.debug("MainCode: " + project.getMainCode());
|
||||||
ItemDescription mainCode = project.getMainCode().getItemDescription();
|
ItemDescription mainCode = project.getMainCode().getItemDescription();
|
||||||
FilesStorage fileStorage = new FilesStorage();
|
FilesStorage fileStorage = new FilesStorage();
|
||||||
InputStream is = fileStorage.retrieveItemOnWorkspace(
|
InputStream is = fileStorage.retrieveItemOnWorkspace(
|
||||||
aslSession.getUsername(), mainCode.getId());
|
aslSession.getUsername(), mainCode.getId());
|
||||||
|
logger.debug("MainCode InputStream: " + is);
|
||||||
|
|
||||||
R_Config config = R_Config.getInstance();
|
Path tempFile=null;
|
||||||
|
|
||||||
List<RAnnotation> annotations;
|
|
||||||
try {
|
try {
|
||||||
RAnnotationParser parser = new RAnnotationParser(config);
|
tempFile = Files.createTempFile("RCodeToParse", ".R");
|
||||||
annotations = parser.parseAnnotationsfromScript(is);
|
Files.copy(is, tempFile, StandardCopyOption.REPLACE_EXISTING);
|
||||||
} catch (Throwable e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
is.close();
|
is.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
logger.debug("" + tempFile);
|
||||||
|
|
||||||
|
|
||||||
|
R_Config config = R_Config.getInstance();
|
||||||
|
logger.debug("R_Config: " + config);
|
||||||
|
List<RAnnotation> annotations;
|
||||||
|
try {
|
||||||
|
RAnnotationParser parser = new RAnnotationParser(config);
|
||||||
|
logger.debug("RAnnotations Parser:" + parser);
|
||||||
|
annotations = parser.parseAnnotationsfromScript(Files.newInputStream(tempFile, StandardOpenOption.READ));
|
||||||
|
} catch (RAnnotationException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
||||||
|
} catch (Throwable e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Files.delete(tempFile);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug("RAnnotations: " + annotations);
|
||||||
|
|
||||||
WPSAlgorithmInfo wpsAlgorithmInfo = mapAnnotations(annotations);
|
WPSAlgorithmInfo wpsAlgorithmInfo = mapAnnotations(annotations);
|
||||||
logger.debug("wpsAlgorithmInfo: " + wpsAlgorithmInfo);
|
logger.debug("wpsAlgorithmInfo: " + wpsAlgorithmInfo);
|
||||||
if (wpsAlgorithmInfo.getAlgorithmName() == null)
|
if (wpsAlgorithmInfo==null || wpsAlgorithmInfo.getAlgorithmName() == null)
|
||||||
return project;
|
return project;
|
||||||
else
|
else
|
||||||
return mapToProject(wpsAlgorithmInfo);
|
return mapToProject(wpsAlgorithmInfo);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Project mapToProject(WPSAlgorithmInfo wpsAlgorithmInfo) throws StatAlgoImporterServiceException {
|
private Project mapToProject(WPSAlgorithmInfo wpsAlgorithmInfo)
|
||||||
|
throws StatAlgoImporterServiceException {
|
||||||
if (project == null) {
|
if (project == null) {
|
||||||
throw new StatAlgoImporterServiceException("Open project before!");
|
throw new StatAlgoImporterServiceException("Open project before!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (project.getInputData() == null) {
|
if (project.getInputData() == null) {
|
||||||
ProjectInfo projectInfo=new ProjectInfo(wpsAlgorithmInfo.getAlgorithmName(), wpsAlgorithmInfo.getDescription(), null);
|
ProjectInfo projectInfo = new ProjectInfo(
|
||||||
InputData inputData=new InputData(projectInfo, null, null, wpsAlgorithmInfo.getInputOutputVariables());
|
wpsAlgorithmInfo.getAlgorithmName(),
|
||||||
|
wpsAlgorithmInfo.getDescription(), null);
|
||||||
|
InputData inputData = new InputData(projectInfo, null, null,
|
||||||
|
wpsAlgorithmInfo.getInputOutputVariables());
|
||||||
project.setInputData(inputData);
|
project.setInputData(inputData);
|
||||||
} else {
|
} else {
|
||||||
InputData inputData = project.getInputData();
|
InputData inputData = project.getInputData();
|
||||||
ProjectInfo projectInfo=new ProjectInfo(wpsAlgorithmInfo.getAlgorithmName(), wpsAlgorithmInfo.getDescription(), null);
|
ProjectInfo projectInfo = new ProjectInfo(
|
||||||
|
wpsAlgorithmInfo.getAlgorithmName(),
|
||||||
|
wpsAlgorithmInfo.getDescription(), null);
|
||||||
inputData.setProjectInfo(projectInfo);
|
inputData.setProjectInfo(projectInfo);
|
||||||
inputData.setListInputOutputVariables(wpsAlgorithmInfo.getInputOutputVariables());
|
inputData.setListInputOutputVariables(wpsAlgorithmInfo
|
||||||
|
.getInputOutputVariables());
|
||||||
inputData.setListGlobalVariables(null);
|
inputData.setListGlobalVariables(null);
|
||||||
}
|
}
|
||||||
return project;
|
return project;
|
||||||
|
@ -104,13 +140,16 @@ public class WPS4RParser {
|
||||||
ArrayList<InputOutputVariables> inputOutputVariables = new ArrayList<>();
|
ArrayList<InputOutputVariables> inputOutputVariables = new ArrayList<>();
|
||||||
int index = 1;
|
int index = 1;
|
||||||
for (RAnnotation rAnnotation : annotations) {
|
for (RAnnotation rAnnotation : annotations) {
|
||||||
|
logger.debug("RAnnotation: " + rAnnotation);
|
||||||
if (rAnnotation.getType().equals(RAnnotationType.DESCRIPTION)) {
|
if (rAnnotation.getType().equals(RAnnotationType.DESCRIPTION)) {
|
||||||
wpsAlgorithmInfo.setVersion(rAnnotation
|
wpsAlgorithmInfo.setVersion(rAnnotation
|
||||||
.getStringValue(RAttribute.VERSION));
|
.getStringValue(RAttribute.VERSION));
|
||||||
wpsAlgorithmInfo.setDescription(rAnnotation
|
wpsAlgorithmInfo.setDescription(rAnnotation
|
||||||
.getStringValue(RAttribute.ABSTRACT));
|
.getStringValue(RAttribute.ABSTRACT));
|
||||||
wpsAlgorithmInfo.setAlgorithmName(rAnnotation
|
String algorithmName=rAnnotation
|
||||||
.getStringValue(RAttribute.TITLE));
|
.getStringValue(RAttribute.TITLE);
|
||||||
|
algorithmName=algorithmName.replaceAll("[^A-Za-z0-9]", "_");
|
||||||
|
wpsAlgorithmInfo.setAlgorithmName(algorithmName);
|
||||||
wpsAlgorithmInfo.setVersion(rAnnotation
|
wpsAlgorithmInfo.setVersion(rAnnotation
|
||||||
.getStringValue(RAttribute.VERSION));
|
.getStringValue(RAttribute.VERSION));
|
||||||
} else if (rAnnotation.getType().equals(RAnnotationType.OUTPUT)
|
} else if (rAnnotation.getType().equals(RAnnotationType.OUTPUT)
|
||||||
|
@ -144,8 +183,8 @@ public class WPS4RParser {
|
||||||
dataType = DataType.ENUMERATED;
|
dataType = DataType.ENUMERATED;
|
||||||
|
|
||||||
InputOutputVariables ioVariable = new InputOutputVariables(
|
InputOutputVariables ioVariable = new InputOutputVariables(
|
||||||
index, name, description, defaultValue, dataType, ioType,
|
index, name, description, defaultValue, dataType,
|
||||||
"");
|
ioType, "");
|
||||||
inputOutputVariables.add(ioVariable);
|
inputOutputVariables.add(ioVariable);
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,6 +84,19 @@ public class ProjectBuilder {
|
||||||
createAlgorithm();
|
createAlgorithm();
|
||||||
createIntegrationInfo();
|
createIntegrationInfo();
|
||||||
createProjectJarFile();
|
createProjectJarFile();
|
||||||
|
try {
|
||||||
|
if (algorithmJava != null)
|
||||||
|
Files.delete(algorithmJava);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (infoTXT != null)
|
||||||
|
Files.delete(infoTXT);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
return project;
|
return project;
|
||||||
|
|
||||||
|
@ -128,24 +141,23 @@ public class ProjectBuilder {
|
||||||
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
filesStorage.saveInputStreamInItem(aslSession.getUsername(), project
|
||||||
|
.getProjectTarget().getProjectDeploy().getPackageProject()
|
||||||
|
.getId(), inputStream);
|
||||||
|
|
||||||
filesStorage.saveInputStreamInItem(
|
WorkspaceItem packageProject = filesStorage
|
||||||
aslSession.getUsername(), project.getProjectTarget()
|
.retrieveItemInfoOnWorkspace(aslSession.getUsername(), project
|
||||||
.getProjectDeploy().getPackageProject().getId(),
|
.getProjectTarget().getProjectDeploy()
|
||||||
inputStream);
|
.getPackageProject().getId());
|
||||||
|
|
||||||
|
|
||||||
WorkspaceItem packageProject=filesStorage.retrieveItemInfoOnWorkspace(aslSession.getUsername(), project.getProjectTarget()
|
|
||||||
.getProjectDeploy().getPackageProject().getId());
|
|
||||||
|
|
||||||
ItemDescription packageProjectItemDescription;
|
ItemDescription packageProjectItemDescription;
|
||||||
try {
|
try {
|
||||||
packageProjectItemDescription = new ItemDescription(packageProject.getId(),
|
packageProjectItemDescription = new ItemDescription(
|
||||||
packageProject.getName(), packageProject
|
packageProject.getId(), packageProject.getName(),
|
||||||
.getOwner().getPortalLogin(),
|
packageProject.getOwner().getPortalLogin(),
|
||||||
packageProject.getPath(), packageProject
|
packageProject.getPath(), packageProject.getType().name());
|
||||||
.getType().name());
|
packageProjectItemDescription.setPublicLink(packageProject
|
||||||
packageProjectItemDescription.setPublicLink(packageProject.getPublicLink(true));
|
.getPublicLink(true));
|
||||||
} catch (InternalErrorException e) {
|
} catch (InternalErrorException e) {
|
||||||
logger.error(e.getLocalizedMessage());
|
logger.error(e.getLocalizedMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -153,11 +165,11 @@ public class ProjectBuilder {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
project.getProjectTarget().getProjectDeploy().setPackageProject(packageProjectItemDescription);
|
project.getProjectTarget().getProjectDeploy()
|
||||||
|
.setPackageProject(packageProjectItemDescription);
|
||||||
logger.debug("ProjectDeploy: "
|
logger.debug("ProjectDeploy: "
|
||||||
+ project.getProjectTarget().getProjectDeploy());
|
+ project.getProjectTarget().getProjectDeploy());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void copyJarInDeploy() throws StatAlgoImporterServiceException {
|
private void copyJarInDeploy() throws StatAlgoImporterServiceException {
|
||||||
|
@ -447,7 +459,8 @@ public class ProjectBuilder {
|
||||||
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
||||||
|
|
||||||
}
|
}
|
||||||
project.getProjectTarget().getProjectDeploy().setPackageProject(packageUrl);
|
project.getProjectTarget().getProjectDeploy()
|
||||||
|
.setPackageProject(packageUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createTargetFolder() throws StatAlgoImporterServiceException {
|
private void createTargetFolder() throws StatAlgoImporterServiceException {
|
||||||
|
|
Loading…
Reference in New Issue