diff --git a/pom.xml b/pom.xml
index daf8840..19a5fee 100644
--- a/pom.xml
+++ b/pom.xml
@@ -42,11 +42,11 @@
distro
config
${project.build.directory}/${project.build.finalName}
-
+
1.7
-
-
+
+
2.6.1
3.3.2
@@ -255,11 +255,8 @@
-
+
org.gcube.applicationsupportlayer
aslsocial
diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/StatAlgoImporterServiceImpl.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/StatAlgoImporterServiceImpl.java
index 814af8e..cabf4e9 100644
--- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/StatAlgoImporterServiceImpl.java
+++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/StatAlgoImporterServiceImpl.java
@@ -15,10 +15,9 @@ import org.gcube.portlets.user.statisticalalgorithmsimporter.server.file.CodeRea
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.generator.ProjectBuilder;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.generator.ProjectDeploy;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.is.BuildSAIDescriptor;
-import org.gcube.portlets.user.statisticalalgorithmsimporter.server.social.AlgorithmNotification;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.social.Recipient;
-import org.gcube.portlets.user.statisticalalgorithmsimporter.server.storage.FilesStorage;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.storage.CodeSave;
+import org.gcube.portlets.user.statisticalalgorithmsimporter.server.storage.FilesStorage;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.storage.ProjectArchiver;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.util.ServiceCredentials;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.code.CodeData;
diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/generator/AlgorithmGenerator.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/generator/AlgorithmGenerator.java
index 7c89da0..0bce1f4 100644
--- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/generator/AlgorithmGenerator.java
+++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/generator/AlgorithmGenerator.java
@@ -58,8 +58,7 @@ public class AlgorithmGenerator {
return tempFile;
} catch (IOException e) {
- logger.error(e.getLocalizedMessage());
- e.printStackTrace();
+ logger.error(e.getLocalizedMessage(),e);
throw new StatAlgoImporterServiceException(e.getLocalizedMessage(),
e);
}
diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/generator/ProjectDeploy.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/generator/ProjectDeploy.java
index 119f5ee..618d8de 100644
--- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/generator/ProjectDeploy.java
+++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/generator/ProjectDeploy.java
@@ -6,6 +6,7 @@ import javax.servlet.http.HttpServletRequest;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.social.AlgorithmNotification;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.social.Recipient;
+import org.gcube.portlets.user.statisticalalgorithmsimporter.server.storage.DeploySave;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.util.ServiceCredentials;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterServiceException;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.info.InfoData;
@@ -41,13 +42,19 @@ public class ProjectDeploy {
public void deploy() throws StatAlgoImporterServiceException{
InfoGenerator infoGenerator=new InfoGenerator(project, serviceCredentials);
InfoData infoData=infoGenerator.readInfo();
+ logger.debug("Deploy Save");
+ DeploySave deploySave=new DeploySave(serviceCredentials, project, infoData);
+ deploySave.save();
logger.debug("Send notify");
- sendNotify(infoData);
+ sendNotify(deploySave.getInfoText());
}
- private void sendNotify(InfoData infoData){
+ private void sendNotify(String body){
AlgorithmNotification notify = new AlgorithmNotification(httpServletRequest,
- serviceCredentials, project, recipients, infoData);
+ serviceCredentials, recipients, body);
notify.run();
}
+
+
+
}
diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/social/AlgorithmNotification.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/social/AlgorithmNotification.java
index 1a31bcc..e64f32a 100644
--- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/social/AlgorithmNotification.java
+++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/social/AlgorithmNotification.java
@@ -17,8 +17,6 @@ import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNot
import org.gcube.portal.notifications.bean.GenericItemBean;
import org.gcube.portal.notifications.thread.MessageNotificationsThread;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.util.ServiceCredentials;
-import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.info.InfoData;
-import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.Project;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -33,17 +31,15 @@ public class AlgorithmNotification extends Thread {
private static Logger logger = LoggerFactory.getLogger(AlgorithmNotification.class);
private HttpServletRequest httpServletRequest;
private ServiceCredentials serviceCredentials;
- private Project project;
private ArrayList recipients;
- private InfoData infoData;
+ private String body;
public AlgorithmNotification(HttpServletRequest httpServletRequest, ServiceCredentials serviceCredentials,
- Project project, ArrayList recipients, InfoData infoData) {
+ ArrayList recipients, String body) {
this.serviceCredentials = serviceCredentials;
- this.project = project;
this.recipients = recipients;
this.httpServletRequest = httpServletRequest;
- this.infoData = infoData;
+ this.body=body;
}
@@ -60,19 +56,6 @@ public class AlgorithmNotification extends Thread {
List recipients = retrieveRecipients();
String subject = "[SAI] New software publication requested";
- String body = "Username: " + serviceCredentials.getUserName() + "\nFull Name: "
- + serviceCredentials.getFullName() + "\nEmail: " + serviceCredentials.getEmail() + "\n\nin VRE: "
- + serviceCredentials.getScope() + "\n\nhas requested to publish the algorithm: " + "\nLanguage: "
- + infoData.getLanguage() + "\nAlgorithm Name: " + infoData.getAlgorithmName() + "\nClass Name: "
- + infoData.getClassName() + "\nAlgorithm Description: " + infoData.getAlgorithmDescription()
- + "\nAlgorithm Category: " + infoData.getAlgorithmCategory() + "\n\nInterpreter Version: "
- + infoData.getInterpreterVersion() + "\n\nwith the following jar: "
- + project.getProjectTarget().getProjectDeploy().getCodeJar().getPublicLink() + "\n\nInstaller: "
- + "\n./addAlgorithm.sh " + infoData.getAlgorithmName() + " " + infoData.getAlgorithmCategory() + " "
- + infoData.getClassName() + " " + serviceCredentials.getScope() + " transducerers N "
- + project.getProjectTarget().getProjectDeploy().getCodeJar().getPublicLink() + " \""
- + infoData.getAlgorithmDescription() + "\"";
-
String messageId;
diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/storage/CodeSave.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/storage/CodeSave.java
index c271f34..5910d15 100644
--- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/storage/CodeSave.java
+++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/storage/CodeSave.java
@@ -52,8 +52,7 @@ public class CodeSave {
return tempFile;
} catch (IOException e) {
- logger.error(e.getLocalizedMessage());
- e.printStackTrace();
+ logger.error(e.getLocalizedMessage(),e);
throw new StatAlgoImporterServiceException(e.getLocalizedMessage(), e);
}
}
@@ -68,8 +67,7 @@ public class CodeSave {
Files.newInputStream(tempFile, StandardOpenOption.READ), file.getName(), ALGORITHM_DESCRIPTION,
ALGORITHM_MIMETYPE, folderId);
} catch (IOException e) {
- logger.error(e.getLocalizedMessage());
- e.printStackTrace();
+ logger.error(e.getLocalizedMessage(),e);
throw new StatAlgoImporterServiceException(e.getLocalizedMessage(), e);
}
@@ -78,8 +76,7 @@ public class CodeSave {
mainCode = new ItemDescription(mainCodeItem.getId(), mainCodeItem.getName(),
mainCodeItem.getOwner().getPortalLogin(), mainCodeItem.getPath(), mainCodeItem.getType().name());
} catch (InternalErrorException e) {
- logger.error(e.getLocalizedMessage());
- e.printStackTrace();
+ logger.error(e.getLocalizedMessage(),e);
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
}
diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/storage/DeploySave.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/storage/DeploySave.java
new file mode 100644
index 0000000..95d590c
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/storage/DeploySave.java
@@ -0,0 +1,120 @@
+package org.gcube.portlets.user.statisticalalgorithmsimporter.server.storage;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardOpenOption;
+import java.util.Arrays;
+import java.util.List;
+
+import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
+import org.gcube.portlets.user.statisticalalgorithmsimporter.server.util.ServiceCredentials;
+import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterServiceException;
+import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.info.InfoData;
+import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.Project;
+import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.workspace.ItemDescription;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * @author Giancarlo Panichi
+ *
+ *
+ */
+public class DeploySave {
+ private static final String ADMIN_USER = "statistical.manager";
+ private static final String CODE_JAR_MIMETYPE = "application/java-archive";
+ private static final String CODE_JAR_DESCRIPTION = "Statistical Algorithm Jar";
+ private static final String DESTINATION_FOLDER = "DataMinerAlgorithms";
+ private static final String TXT_MIMETYPE = "text/plain";
+ private static final String EXTENTION_TXT = ".txt";
+
+ public static final Logger logger = LoggerFactory.getLogger(DeploySave.class);
+ private FilesStorage filesStorage;
+
+ private ServiceCredentials serviceCredentials;
+ private Project project;
+ private InfoData infoData;
+ private String infoText;
+
+ public DeploySave(ServiceCredentials serviceCredentials, Project project, InfoData infoData) {
+ this.serviceCredentials = serviceCredentials;
+ this.project = project;
+ this.infoData = infoData;
+ this.infoText = null;
+ filesStorage = new FilesStorage();
+
+ }
+
+ public void save() throws StatAlgoImporterServiceException {
+ ItemDescription codeJar = project.getProjectTarget().getProjectDeploy().getCodeJar();
+
+ InputStream codeJarInputStream = filesStorage.retrieveItemOnWorkspace(serviceCredentials.getUserName(),
+ codeJar.getId());
+
+ WorkspaceItem codeJarItem = filesStorage.createItemOnWorkspaceHowAdmin(ADMIN_USER, codeJarInputStream,
+ codeJar.getName(), CODE_JAR_DESCRIPTION, CODE_JAR_MIMETYPE, DESTINATION_FOLDER);
+
+ ItemDescription codeJarAdminCopy;
+ try {
+ codeJarAdminCopy = new ItemDescription(codeJarItem.getId(), codeJarItem.getName(),
+ codeJarItem.getOwner().getPortalLogin(), codeJarItem.getPath(), codeJarItem.getType().name());
+ codeJarAdminCopy.setPublicLink(codeJarItem.getPublicLink(false));
+ } catch (Throwable e) {
+ logger.error(e.getLocalizedMessage(), e);
+ throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
+
+ }
+
+ createInfoText(codeJarAdminCopy);
+
+
+ try {
+ int codeJarNamelenght = codeJar.getName().length();
+ String codeJarName;
+ if (codeJarNamelenght > 4) {
+ codeJarName = codeJar.getName().substring(0, codeJarNamelenght - 4);
+ } else {
+ throw new StatAlgoImporterServiceException("Error in code jar name: " + codeJar.getName());
+ }
+
+ Path reportInstallTempFile = Files.createTempFile(codeJarName + "_install", EXTENTION_TXT);
+
+ List lines = Arrays.asList(infoText.split("\\n"));
+ Files.write(reportInstallTempFile, lines, Charset.defaultCharset(), StandardOpenOption.WRITE);
+ logger.debug(reportInstallTempFile.toString());
+ InputStream reportInstallInputStream = Files.newInputStream(reportInstallTempFile);
+
+ filesStorage.createItemOnWorkspaceHowAdmin(ADMIN_USER, reportInstallInputStream,
+ codeJarName + "_install.txt", codeJarName + "_install.txt", TXT_MIMETYPE, DESTINATION_FOLDER);
+
+ } catch (IOException e) {
+ logger.error("Error writing report install information: " + e.getLocalizedMessage(), e);
+ throw new StatAlgoImporterServiceException(e.getLocalizedMessage(), e);
+ }
+
+ }
+
+ private void createInfoText(ItemDescription codeJarAdminCopy) {
+ infoText = "Username: " + serviceCredentials.getUserName() + "\nFull Name: " + serviceCredentials.getFullName()
+ + "\nEmail: " + serviceCredentials.getEmail() + "\n\nin VRE: " + serviceCredentials.getScope()
+ + "\n\nhas requested to publish the algorithm: " + "\nLanguage: " + infoData.getLanguage()
+ + "\nAlgorithm Name: " + infoData.getAlgorithmName() + "\nClass Name: " + infoData.getClassName()
+ + "\nAlgorithm Description: " + infoData.getAlgorithmDescription() + "\nAlgorithm Category: "
+ + infoData.getAlgorithmCategory() + "\n\nInterpreter Version: " + infoData.getInterpreterVersion()
+ + "\n\nwith the following original jar: "
+ + project.getProjectTarget().getProjectDeploy().getCodeJar().getPublicLink() + "\nadmin copy jar: "
+ + codeJarAdminCopy.getPublicLink() + "\n\nInstaller: " + "\n./addAlgorithm.sh "
+ + infoData.getAlgorithmName() + " " + infoData.getAlgorithmCategory() + " " + infoData.getClassName()
+ + " " + serviceCredentials.getScope() + " transducerers N " + codeJarAdminCopy.getPublicLink() + " \""
+ + infoData.getAlgorithmDescription() + "\"";
+ }
+
+ public String getInfoText() {
+ return infoText;
+ }
+
+}
diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/storage/FilesStorage.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/storage/FilesStorage.java
index c376a03..6949e3e 100644
--- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/storage/FilesStorage.java
+++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/storage/FilesStorage.java
@@ -281,6 +281,41 @@ public class FilesStorage {
}
+ /**
+ *
+ * @param user
+ * User
+ * @param parentName
+ * Parent name
+ * @param name
+ * Name
+ * @return WorkspaceItem
+ * @throws StatAlgoImporterServiceException
+ * Exception
+ */
+ public WorkspaceItem findInParentName(String user, String parentName, String name)
+ throws StatAlgoImporterServiceException {
+ Workspace ws;
+ try {
+ logger.info("Find by parent name: [user=" + user + ", parentName=" + parentName + ", name=" + name + "]");
+
+ ws = HomeLibrary.getUserWorkspace(user);
+
+ WorkspaceItem parentItem = ws.getItem(parentName);
+ if (!parentItem.isFolder()) {
+ throw new StatAlgoImporterServiceException("No valid folder: " + parentName + "!");
+ }
+
+ return ws.find(name, parentItem.getId());
+
+ } catch (Throwable e) {
+ logger.error("Find by parent name: " + e.getLocalizedMessage(), e);
+ throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
+
+ }
+
+ }
+
/**
*
* @param user
@@ -398,6 +433,7 @@ public class FilesStorage {
ws = HomeLibrary.getUserWorkspace(user);
WorkspaceItem workSpaceItem = ws.getItem(folderId);
+
if (!workSpaceItem.isFolder()) {
throw new StatAlgoImporterServiceException("Destination is not a folder!");
}
@@ -412,6 +448,55 @@ public class FilesStorage {
}
}
+ /**
+ *
+ * @param user
+ * User
+ * @param inputStream
+ * InputStream
+ * @param name
+ * Name
+ * @param description
+ * Description
+ * @param mimeType
+ * MimeType
+ * @param folderName
+ * Folder Path
+ * @return WorkspaceItem
+ * @throws StatAlgoImporterServiceException
+ * Exception
+ */
+ public WorkspaceItem createItemOnWorkspaceHowAdmin(String user, InputStream inputStream, String name,
+ String description, String mimeType, String folderName) throws StatAlgoImporterServiceException {
+ Workspace ws;
+ try {
+ logger.info("Create item on workspace how admin: [user=" + user + ", name=" + name + ", description="
+ + description + ", mimeType=" + mimeType + ", folderName=" + folderName + "]");
+
+ ws = HomeLibrary.getUserWorkspace(user);
+ WorkspaceItem root = ws.getRoot();
+ WorkspaceItem folderItem=ws.find(folderName, root.getId());
+
+ if (folderItem==null||!folderItem.isFolder()) {
+ throw new StatAlgoImporterServiceException("Destination "+folderName+" is not a valid folder!");
+ }
+
+ WorkspaceItem codeJar = ws.find(name, folderItem.getId());
+
+ if (codeJar == null) {
+ return ws.createExternalFile(name, description, mimeType, inputStream, folderItem.getId());
+ } else {
+ ws.updateItem(codeJar.getId(), inputStream);
+ return codeJar;
+ }
+
+ } catch (Throwable e) {
+ logger.error("Create item on workspace how admin: " + e.getLocalizedMessage(), e);
+ throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
+
+ }
+ }
+
/**
*
* @param user