ref 11724: SAI - Update to StorageHUB

https://support.d4science.org/issues/11724

Updated to StorageHub 

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/statistical-algorithms-importer@171606 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2018-09-24 09:07:25 +00:00
parent defba72fed
commit edbef7efd5
6 changed files with 42 additions and 184 deletions

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/statistical-algorithms-importer-1.12.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<classpathentry kind="src" output="target/statistical-algorithms-importer-1.13.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/statistical-algorithms-importer-1.12.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<classpathentry excluding="**" kind="src" output="target/statistical-algorithms-importer-1.13.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
@ -45,5 +45,5 @@
</classpathentry>
<classpathentry kind="lib" path="/home/giancarlo/gwt/gwt-2.6.1/validation-api-1.0.0.GA.jar" sourcepath="/home/giancarlo/gwt/gwt-2.6.1/validation-api-1.0.0.GA-sources.jar"/>
<classpathentry kind="lib" path="/home/giancarlo/gwt/gwt-2.6.1/validation-api-1.0.0.GA-sources.jar"/>
<classpathentry kind="output" path="target/statistical-algorithms-importer-1.12.0-SNAPSHOT/WEB-INF/classes"/>
<classpathentry kind="output" path="target/statistical-algorithms-importer-1.13.0-SNAPSHOT/WEB-INF/classes"/>
</classpath>

View File

@ -1,4 +1,7 @@
<ReleaseNotes>
<Changeset component="${groupId}.${artifactId}.1-13-0" date="2018-10-01">
<Change>Updated support to StorageHub [ticket #11724]</Change>
</Changeset>
<Changeset component="${groupId}.${artifactId}.1-12-0" date="2018-07-01">
<Change>Updated to StorageHub [ticket #11724]</Change>
</Changeset>

66
pom.xml
View File

@ -13,7 +13,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>statistical-algorithms-importer</artifactId>
<version>1.12.0-SNAPSHOT</version>
<version>1.13.0-SNAPSHOT</version>
<packaging>war</packaging>
@ -82,17 +82,6 @@
<version>2.4.0</version>
</dependency>
<!-- Storage -->
<dependency>
<groupId>org.gcube.contentmanagement</groupId>
<artifactId>storage-manager-core</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.gcube.contentmanagement</groupId>
<artifactId>storage-manager-wrapper</artifactId>
<scope>runtime</scope>
</dependency>
<!-- StorageHub -->
<dependency>
@ -101,23 +90,6 @@
<scope>runtime</scope>
</dependency>
<!-- Home Library -->
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>home-library</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>home-library-jcr</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>home-library-model</artifactId>
<scope>runtime</scope>
</dependency>
<!-- Authorization -->
<dependency>
<groupId>org.gcube.common</groupId>
@ -227,19 +199,6 @@
<scope>provided</scope>
</dependency>
<!-- Storage -->
<dependency>
<groupId>org.gcube.contentmanagement</groupId>
<artifactId>storage-manager-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.contentmanagement</groupId>
<artifactId>storage-manager-wrapper</artifactId>
<scope>provided</scope>
</dependency>
<!-- StorageHub -->
<dependency>
<groupId>org.gcube.common</groupId>
@ -247,25 +206,6 @@
<scope>compile</scope>
</dependency>
<!-- Home Library -->
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>home-library</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>home-library-jcr</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>home-library-model</artifactId>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
@ -323,12 +263,12 @@
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency>
<!-- Workspace Explorer -->
<!-- Workspace Explorer -->
<dependency>
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>workspace-explorer</artifactId>
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
</dependency>
</dependency>
<!-- Workspace Uploader -->
<dependency>

View File

@ -9,21 +9,9 @@ import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
import org.gcube.applicationsupportlayer.social.NotificationsManager;
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite;
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser;
import org.gcube.common.homelibrary.home.HomeLibrary;
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
import org.gcube.common.homelibrary.home.workspace.Workspace;
import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
import org.gcube.portal.notifications.bean.GenericItemBean;
import org.gcube.portal.notifications.thread.MessageNotificationsThread;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.SessionUtil;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.is.InformationSystemUtils;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.util.ServiceCredentials;
@ -211,7 +199,7 @@ public class AlgorithmNotification extends Thread {
if (serviceUp) {
sendByService();
} else {
sendByNotificationManager();
//sendByNotificationManager();
}
}
@ -316,6 +304,8 @@ public class AlgorithmNotification extends Thread {
}
/*
private void sendByNotificationManager() {
try {
Workspace workspace = HomeLibrary.getUserWorkspace(serviceCredentials.getUserName());
@ -366,6 +356,6 @@ public class AlgorithmNotification extends Thread {
}
return addressee;
}
} */
}

View File

@ -11,9 +11,6 @@ import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import org.gcube.common.homelibrary.home.HomeLibrary;
import org.gcube.common.homelibrary.home.workspace.Workspace;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
import org.gcube.common.storagehub.client.StreamDescriptor;
import org.gcube.common.storagehub.client.dsl.FileContainer;
import org.gcube.common.storagehub.client.dsl.FolderContainer;
@ -60,7 +57,7 @@ public class FilesStorage {
public String getPublicLink(String user, String itemId) throws StatAlgoImporterServiceException {
try {
logger.debug("getPublicLink: [user=" + user + ", itemId=" + itemId + "]");
logger.info("getPublicLink: [user=" + user + ", itemId=" + itemId + "]");
StorageHubClient shc = new StorageHubClient();
URL url = shc.open(itemId).asFile().getPublicLink();
return url.toString();
@ -87,22 +84,19 @@ public class FilesStorage {
*/
public ItemDescription copyItemOnFolder(String user, String itemId, String folderId)
throws StatAlgoImporterServiceException {
Workspace ws;
try {
logger.info("Copy item on folder: [user=" + user + ", itemId=" + itemId + ", folderId=" + folderId + "]");
ws = HomeLibrary.getUserWorkspace(user);
WorkspaceItem workSpaceItem = ws.getItem(folderId);
if (!workSpaceItem.isFolder()) {
throw new StatAlgoImporterServiceException("Destination is not a folder!");
}
WorkspaceItem item = ws.copy(itemId, folderId);
ItemDescription itemDescription = new ItemDescription(item.getId(), item.getName(),
item.getOwner().getPortalLogin(), item.getPath(), item.getType().name());
itemDescription.setPublicLink(item.getPublicLink(false));
StorageHubClient shc = new StorageHubClient();
OpenResolver openResolverForFile = shc.open(itemId);
FileContainer fileContainer = openResolverForFile.asFile();
OpenResolver openResolverForFolder = shc.open(folderId);
FolderContainer folderContainer = openResolverForFolder.asFolder();
FileContainer fileCreatedContainer = fileContainer.copy(folderContainer, fileContainer.get().getName());
AbstractFileItem item = fileCreatedContainer.get();
ItemDescription itemDescription = new ItemDescription(item.getId(), item.getName(), item.getOwner(),
item.getPath(), item.getClass().getSimpleName());
itemDescription.setPublicLink(fileCreatedContainer.getPublicLink().toString());
return itemDescription;
} catch (Throwable e) {
@ -130,23 +124,22 @@ public class FilesStorage {
*/
public ItemDescription copyItemOnFolderWithNewName(String user, String itemId, String folderId, String newName)
throws StatAlgoImporterServiceException {
Workspace ws;
try {
logger.info("Copy item on folder with new name: [user=" + user + ", itemId=" + itemId + ", folderId="
+ folderId + ", newName=" + newName + "]");
ws = HomeLibrary.getUserWorkspace(user);
WorkspaceItem workSpaceItem = ws.getItem(folderId);
if (!workSpaceItem.isFolder()) {
throw new StatAlgoImporterServiceException("Destination is not a folder!");
}
WorkspaceItem item = ws.copy(itemId, newName, folderId);
ItemDescription itemDescription = new ItemDescription(item.getId(), item.getName(),
item.getOwner().getPortalLogin(), item.getPath(), item.getType().name());
StorageHubClient shc = new StorageHubClient();
OpenResolver openResolverForFile = shc.open(itemId);
FileContainer fileContainer = openResolverForFile.asFile();
OpenResolver openResolverForFolder = shc.open(folderId);
FolderContainer folderContainer = openResolverForFolder.asFolder();
FileContainer fileCreatedContainer = fileContainer.copy(folderContainer, newName);
AbstractFileItem item = fileCreatedContainer.get();
ItemDescription itemDescription = new ItemDescription(item.getId(), item.getName(), item.getOwner(),
item.getPath(), item.getClass().getSimpleName());
itemDescription.setPublicLink(fileCreatedContainer.getPublicLink().toString());
logger.debug("File created: " + itemDescription);
return itemDescription;
} catch (Throwable e) {
logger.error("Copy item on folder with new name on workspace: " + e.getLocalizedMessage(), e);
@ -166,7 +159,7 @@ public class FilesStorage {
*/
public void deleteItemOnFolder(String user, String itemId) throws StatAlgoImporterServiceException {
try {
logger.debug("Delete Item: [User=" + user + ", ItemId=" + itemId + "]");
logger.info("Delete Item: [User=" + user + ", ItemId=" + itemId + "]");
StorageHubClient shc = new StorageHubClient();
OpenResolver openResolver = shc.open(itemId);
@ -253,7 +246,7 @@ public class FilesStorage {
FolderContainer folderContainer = openResolver.asFolder();
FolderContainer folderContainerNew = folderContainer.newFolder(folderName, folderDescription);
FolderItem folderCreated = folderContainerNew.get();
ItemDescription itemDescription = new ItemDescription(folderCreated.getId(), folderCreated.getName(),
folderCreated.getOwner(), folderCreated.getPath(), folderCreated.getClass().getSimpleName());
@ -379,7 +372,7 @@ public class FilesStorage {
OpenResolver openResolver = shc.open(folderId);
FolderContainer folderContainer = openResolver.asFolder();
folderContainer.uploadFile(inputStream, name, description);
folderContainer.uploadFile(inputStream, name, description);
return;
} catch (Throwable e) {
@ -418,7 +411,7 @@ public class FilesStorage {
FolderContainer folderContainer = openResolver.asFolder();
FileContainer fileContainerNew = folderContainer.uploadFile(inputStream, name, description);
AbstractFileItem fileCreated = fileContainerNew.get();
ItemDescription itemDescription = new ItemDescription(fileCreated.getId(), fileCreated.getName(),
@ -433,70 +426,6 @@ public class FilesStorage {
}
}
/**
*
*
*
* @param user
* User
* @param inputStream
* InputStream
* @param name
* Name
* @param description
* Description
* @param mimeType
* MimeType
* @param folderName
* Folder Path
* @return Item description
* @throws StatAlgoImporterServiceException
* Exception
*/
/*
public ItemDescription 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());
ItemDescription itemDescription;
if (codeJar == null) {
WorkspaceItem item = ws.createExternalFile(name, description, mimeType, inputStream,
folderItem.getId());
itemDescription = new ItemDescription(item.getId(), item.getName(), item.getOwner().getPortalLogin(),
item.getPath(), item.getType().name());
itemDescription.setPublicLink(item.getPublicLink(false));
} else {
ws.updateItem(codeJar.getId(), inputStream);
itemDescription = new ItemDescription(codeJar.getId(), codeJar.getName(),
codeJar.getOwner().getPortalLogin(), codeJar.getPath(), codeJar.getType().name());
itemDescription.setPublicLink(codeJar.getPublicLink(false));
}
return itemDescription;
} catch (Throwable e) {
logger.error("Create item on workspace how admin: " + e.getLocalizedMessage(), e);
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
}
}*/
/**
*
*
@ -897,7 +826,7 @@ public class FilesStorage {
}
}
} else {
logger.info("Folder null: itemId=" + itemId + "]");
logger.debug("Folder null: itemId=" + itemId + "]");
}
logger.debug("Shared: " + shared);

View File

@ -83,11 +83,7 @@ public class ItemDescription implements Serializable {
public boolean compareInfo(ItemDescription itemDescription){
if(itemDescription!=null && id.compareTo(itemDescription.getId())==0 &&
name.compareTo(itemDescription.getName())==0 &&
owner.compareTo(itemDescription.getOwner())==0 &&
type.compareTo(itemDescription.getType())==0
){
if(itemDescription!=null && id.compareTo(itemDescription.getId())==0){
return true;
} else {
return false;