1452: Implement a GUI for StatMan Algorithms Importer

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

Added Constraint on Software Creation

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/statistical-algorithms-importer@122372 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2016-01-20 15:41:37 +00:00
parent 0c8ad1cfba
commit 7293907826
1 changed files with 61 additions and 34 deletions

View File

@ -19,7 +19,6 @@ import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.SessionUtil;
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.project.Project;
@ -51,7 +50,7 @@ public class ProjectBuilder {
private static final String ECOLOGICAL_ENGINE_JAR_URL = "http://data.d4science.org/id?fileName=ecological-engine.jar&smp-id=56952e9ce4b0e2fd6457272c&contentType=application%2Fjava-archive";
private static final String ECOLOGICAL_ENGINE_SMART_EXECUTOR_JAR_URL = "http://data.d4science.org/id?fileName=ecological-engine-smart-executor.jar&smp-id=56952e9ce4b0e2fd6457272e&contentType=application%2Fjava-archive";
private static final String ECOLOGICAL_ENGINE_SMART_EXECUTOR_JAR = "ecological-engine-smart-executor.jar";
private static final String CODE_JAR_MIMETYPE = "application/java-archive";
private static final String CODE_JAR_DESCRIPTION = "Statistical Algorithm Jar";
private static final String JAR_EXTENTION = ".jar";
@ -61,7 +60,6 @@ public class ProjectBuilder {
private Project project;
private ASLSession aslSession;
private HttpSession session;
private ProjectTarget projectTarget;
private Path algorithmJava;
private Path infoTXT;
@ -70,7 +68,6 @@ public class ProjectBuilder {
HttpSession session) {
this.project = project;
this.aslSession = aslSession;
this.session = session;
}
private void checkInfo() throws StatAlgoImporterServiceException {
@ -94,21 +91,44 @@ public class ProjectBuilder {
"Attention No Project Information Set!");
}
if (project.getInputData().getProjectInfo().getAlgorithmName() == null) {
if (project.getInputData().getProjectInfo().getAlgorithmName() == null
|| project.getInputData().getProjectInfo().getAlgorithmName()
.isEmpty()) {
throw new StatAlgoImporterServiceException(
"Attention No Algorithm Name Set!");
"Attention No Info Name Set!");
}
if (project.getMainCode() == null) {
if (project.getInputData().getProjectInfo().getAlgorithmDescription() == null
|| project.getInputData().getProjectInfo()
.getAlgorithmDescription().isEmpty()) {
throw new StatAlgoImporterServiceException(
"Attention No Info Description Set!");
}
if (project.getInputData().getInterpreterInfo() == null) {
throw new StatAlgoImporterServiceException(
"Attention No Interpreter Info Set!");
}
if (project.getInputData().getInterpreterInfo().getVersion() == null
|| project.getInputData().getInterpreterInfo().getVersion()
.isEmpty()) {
throw new StatAlgoImporterServiceException(
"Attention No Interpreter Version Set!");
}
if (project.getInputData().getListInputOutputVariables() == null
|| project.getInputData().getListInputOutputVariables().size() < 1) {
throw new StatAlgoImporterServiceException(
"Attention No Input/Output Set!");
}
if (project.getMainCode() == null
|| project.getMainCode().getItemDescription() == null) {
throw new StatAlgoImporterServiceException(
"Attention No Main Code Set");
}
if (project.getInputData() == null) {
throw new StatAlgoImporterServiceException(
"Attention No Input Data Set!");
}
}
public Project build() throws StatAlgoImporterServiceException {
@ -119,7 +139,7 @@ public class ProjectBuilder {
createProjectJarFile();
return project;
}
protected void createAlgorithm() throws StatAlgoImporterServiceException {
@ -207,7 +227,8 @@ public class ProjectBuilder {
try {
projectPackageItem = filesStorage.createItemOnWorkspace(
aslSession.getUsername(), inputStream, project
.getInputData().getProjectInfo().getAlgorithmNameToClassName()
.getInputData().getProjectInfo()
.getAlgorithmNameToClassName()
+ PROJECT_PACKAGE_EXTENTION,
PROJECT_PACKAGE_DESCRIPTION, PROJECT_PACKAGE_MIMETYPE,
targetFolder.getId());
@ -240,8 +261,7 @@ public class ProjectBuilder {
private void createIntegrationInfo()
throws StatAlgoImporterServiceException {
InfoGenerator integrationInfoGenerator = new InfoGenerator(
project);
InfoGenerator integrationInfoGenerator = new InfoGenerator(project);
infoTXT = integrationInfoGenerator.createInfo();
FilesStorage filesStorage = new FilesStorage();
@ -251,9 +271,9 @@ public class ProjectBuilder {
infoItem = filesStorage.createItemOnWorkspace(
aslSession.getUsername(),
Files.newInputStream(infoTXT, StandardOpenOption.READ),
INFO_NAME + INFO_EXTENTION,
INFO_DESCRIPTION, INFO_MIMETYPE,
project.getProjectTarget().getTargetFolder().getId());
INFO_NAME + INFO_EXTENTION, INFO_DESCRIPTION,
INFO_MIMETYPE, project.getProjectTarget().getTargetFolder()
.getId());
} catch (IOException e) {
logger.error(e.getLocalizedMessage());
e.printStackTrace();
@ -297,12 +317,12 @@ public class ProjectBuilder {
storage.downloadInputFile(ECOLOGICAL_ENGINE_SMART_EXECUTOR_JAR_URL,
ecologicalEngineSmartExecutorJar);
Path algorithmTempFile = new File(tempDirectory.toFile(), project
.getInputData().getProjectInfo().getAlgorithmNameToClassName()
.getInputData().getProjectInfo()
.getAlgorithmNameToClassName()
+ ALGORITHM_EXTENTION).toPath();
Files.copy(algorithmJava, algorithmTempFile);
Path infoTempFile = new File(tempDirectory.toFile(),
INFO_NAME + INFO_EXTENTION)
.toPath();
Path infoTempFile = new File(tempDirectory.toFile(), INFO_NAME
+ INFO_EXTENTION).toPath();
Files.copy(infoTXT, infoTempFile);
createClassFile(tempDirectory);
@ -321,18 +341,22 @@ public class ProjectBuilder {
}
}
private void copyJarOnWorkspace(Path tempDirectory) throws StatAlgoImporterServiceException {
Path codeJar=Paths.get(tempDirectory.toString(),project.getInputData().getProjectInfo().getAlgorithmNameToClassName()
private void copyJarOnWorkspace(Path tempDirectory)
throws StatAlgoImporterServiceException {
Path codeJar = Paths.get(tempDirectory.toString(), project
.getInputData().getProjectInfo().getAlgorithmNameToClassName()
+ JAR_EXTENTION);
FilesStorage filesStorage = new FilesStorage();
WorkspaceItem codeJarItem;
try {
codeJarItem = filesStorage.createItemOnWorkspace(aslSession
.getUsername(), Files.newInputStream(codeJar,
StandardOpenOption.READ), project.getInputData().getProjectInfo().getAlgorithmNameToClassName()
+ JAR_EXTENTION, CODE_JAR_DESCRIPTION,
codeJarItem = filesStorage.createItemOnWorkspace(
aslSession.getUsername(),
Files.newInputStream(codeJar, StandardOpenOption.READ),
project.getInputData().getProjectInfo()
.getAlgorithmNameToClassName()
+ JAR_EXTENTION, CODE_JAR_DESCRIPTION,
CODE_JAR_MIMETYPE, project.getProjectTarget()
.getTargetFolder().getId());
} catch (IOException e) {
@ -347,8 +371,9 @@ public class ProjectBuilder {
codeJarItemDescription = new ItemDescription(codeJarItem.getId(),
codeJarItem.getName(), codeJarItem.getOwner()
.getPortalLogin(), codeJarItem.getPath(),
codeJarItem.getType().name());
codeJarItemDescription.setPublicLink(codeJarItem.getPublicLink(true));
codeJarItem.getType().name());
codeJarItemDescription.setPublicLink(codeJarItem
.getPublicLink(true));
} catch (InternalErrorException e) {
logger.error(e.getLocalizedMessage());
e.printStackTrace();
@ -369,7 +394,8 @@ public class ProjectBuilder {
ProcessBuilder pb = new ProcessBuilder("javac", "-cp",
tempDirectory.toAbsolutePath().toString() + "/*", project
.getInputData().getProjectInfo().getAlgorithmNameToClassName()
.getInputData().getProjectInfo()
.getAlgorithmNameToClassName()
+ ALGORITHM_EXTENTION);
pb.directory(tempDirectory.toFile());
Path logTXT = new File(tempDirectory.toFile(), LOG_TXT).toPath();
@ -398,7 +424,8 @@ public class ProjectBuilder {
List<String> commands = new ArrayList<>();
commands.add("jar");
commands.add("-cvf");
commands.add(project.getInputData().getProjectInfo().getAlgorithmNameToClassName()
commands.add(project.getInputData().getProjectInfo()
.getAlgorithmNameToClassName()
+ JAR_EXTENTION);
DirectoryStream<Path> directoryStream = Files