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