ref 11725: GitHubConnector - Update to StorageHub

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

Updated to support StorageHub 


git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/github-connector@171425 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2018-09-13 13:53:15 +00:00
parent 51c30aea93
commit 75455a0ddd
5 changed files with 66 additions and 90 deletions

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" output="target/github-connector-1.4.0-SNAPSHOT/WEB-INF/classes" path="src/main/java"> <classpathentry kind="src" output="target/github-connector-1.5.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes> <attributes>
<attribute name="optional" value="true"/> <attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry excluding="**" kind="src" output="target/github-connector-1.4.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources"> <classpathentry excluding="**" kind="src" output="target/github-connector-1.5.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
@ -34,5 +34,5 @@
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="target/github-connector-1.4.0-SNAPSHOT/WEB-INF/classes"/> <classpathentry kind="output" path="target/github-connector-1.5.0-SNAPSHOT/WEB-INF/classes"/>
</classpath> </classpath>

View File

@ -1,4 +1,8 @@
<ReleaseNotes> <ReleaseNotes>
<Changeset component="org.gcube.portlets.widgets.githubconnector.1-5-0"
date="2018-10-01">
<Change>Updated to StorageHub [ticket #11725]</Change>
</Changeset>
<Changeset component="org.gcube.portlets.widgets.githubconnector.1-4-0" <Changeset component="org.gcube.portlets.widgets.githubconnector.1-4-0"
date="2017-06-12"> date="2017-06-12">
<Change>Support Java 8 compatibility [ticket #8541]</Change> <Change>Support Java 8 compatibility [ticket #8541]</Change>

37
pom.xml
View File

@ -12,7 +12,7 @@
<groupId>org.gcube.portlets.widgets</groupId> <groupId>org.gcube.portlets.widgets</groupId>
<artifactId>github-connector</artifactId> <artifactId>github-connector</artifactId>
<version>1.4.0-SNAPSHOT</version> <version>1.5.0-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<description>github-connector</description> <description>github-connector</description>
@ -89,20 +89,10 @@
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<!-- Home Library --> <!-- StorageHub -->
<dependency> <dependency>
<groupId>org.gcube.common</groupId> <groupId>org.gcube.common</groupId>
<artifactId>home-library</artifactId> <artifactId>storagehub-client-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> <scope>runtime</scope>
</dependency> </dependency>
@ -201,29 +191,14 @@
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- Information System Client IC-Client <dependency> <groupId>org.gcube.resources.discovery</groupId> <!-- StorageHub -->
<artifactId>ic-client</artifactId> </dependency> -->
<!-- Home Library -->
<dependency> <dependency>
<groupId>org.gcube.common</groupId> <groupId>org.gcube.common</groupId>
<artifactId>home-library</artifactId> <artifactId>storagehub-client-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> <scope>provided</scope>
</dependency> </dependency>
<!-- http://mvnrepository.com/artifact/org.eclipse.mylyn.github/org.eclipse.egit.github.core --> <!-- http://mvnrepository.com/artifact/org.eclipse.mylyn.github/org.eclipse.egit.github.core -->
<dependency> <dependency>
<groupId>org.eclipse.mylyn.github</groupId> <groupId>org.eclipse.mylyn.github</groupId>

View File

@ -167,7 +167,8 @@ public class GitConnectorService {
+ destinationFolderId + ", folderName=" + destinationFolderId + ", folderName="
+ contents.getName() + ", folderDescription=" + contents.getName() + ", folderDescription="
+ contents.getName() + "]"); + contents.getName() + "]");
String internalFolderId=StorageUtil.createFolderOnWorkspace(userName, destinationFolderId, StorageUtil storageUtil=new StorageUtil();
String internalFolderId=storageUtil.createFolderOnWorkspace(userName, destinationFolderId,
contents.getName(), contents.getName()); contents.getName(), contents.getName());
createContent(internalFolderId, repository, contents.getPath()); createContent(internalFolderId, repository, contents.getPath());
@ -198,7 +199,8 @@ public class GitConnectorService {
.getBytes()); .getBytes());
InputStream is = new ByteArrayInputStream(decodedBytes); InputStream is = new ByteArrayInputStream(decodedBytes);
StorageUtil.saveOnWorkspace(userName, destinationFolderId, StorageUtil storageUtil=new StorageUtil();
storageUtil.saveOnWorkspace(userName, destinationFolderId,
contents.getName(), contents.getName(), is); contents.getName(), contents.getName(), is);
// logger.debug(new String(decodedBytes)); // logger.debug(new String(decodedBytes));
} }

View File

@ -3,18 +3,14 @@ package org.gcube.portlets.widgets.githubconnector.server.storage;
import java.io.InputStream; import java.io.InputStream;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.gcube.common.homelibrary.home.HomeLibrary; import org.gcube.common.storagehub.client.dsl.FileContainer;
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException; import org.gcube.common.storagehub.client.dsl.FolderContainer;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException; import org.gcube.common.storagehub.client.dsl.ItemContainer;
import org.gcube.common.homelibrary.home.workspace.Workspace; import org.gcube.common.storagehub.client.dsl.OpenResolver;
import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder; import org.gcube.common.storagehub.client.dsl.StorageHubClient;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem; import org.gcube.common.storagehub.model.items.AbstractFileItem;
import org.gcube.common.homelibrary.home.workspace.exceptions.InsufficientPrivilegesException; import org.gcube.common.storagehub.model.items.FolderItem;
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemAlreadyExistException; import org.gcube.common.storagehub.model.items.Item;
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemNotFoundException;
import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
import org.gcube.common.homelibrary.home.workspace.exceptions.WrongDestinationException;
import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalFile;
import org.gcube.portlets.widgets.githubconnector.shared.exception.ServiceException; import org.gcube.portlets.widgets.githubconnector.shared.exception.ServiceException;
/** /**
@ -36,22 +32,21 @@ public class StorageUtil {
* @throws ServiceException * @throws ServiceException
* service exception * service exception
*/ */
public static void deleteItem(String user, String itemId) throws ServiceException { public void deleteItem(String user, String itemId) throws ServiceException {
Workspace ws;
try { try {
logger.debug("User: " + user + ", ItemId:" + itemId); logger.info("Delete Item: [User=" + user + ", ItemId=" + itemId + "]");
ws = HomeLibrary.getUserWorkspace(user); StorageHubClient shc = new StorageHubClient();
OpenResolver openResolver = shc.open(itemId);
ws.removeItems(itemId); ItemContainer<Item> itemContainer = openResolver.asItem();
itemContainer.delete();
return; return;
} catch (InsufficientPrivilegesException | WorkspaceFolderNotFoundException | InternalErrorException } catch (Throwable e) {
| HomeNotFoundException | ItemNotFoundException e) { logger.error("Delete Item on workspace: " + e.getLocalizedMessage(), e);
e.printStackTrace();
throw new ServiceException(e.getLocalizedMessage(), e); throw new ServiceException(e.getLocalizedMessage(), e);
} }
} }
/** /**
@ -68,65 +63,65 @@ public class StorageUtil {
* @throws ServiceException * @throws ServiceException
* service exception * service exception
*/ */
public static String createFolderOnWorkspace(String user, String destinationFolderId, String folderName, public String createFolderOnWorkspace(String user, String destinationFolderId, String folderName,
String folderDescription) throws ServiceException { String folderDescription) throws ServiceException {
try { try {
logger.debug("CreateFolderOnWorkspace: [User=" + user + ", FolderId:" + destinationFolderId logger.info("CreateFolderOnWorkspace: [User=" + user + ", FolderId:" + destinationFolderId + ", folderName="
+ ", folderName=" + folderName + ", folderDescription=" + folderDescription + "]"); + folderName + ", folderDescription=" + folderDescription + "]");
Workspace ws = HomeLibrary.getUserWorkspace(user);
WorkspaceFolder workspaceFolder = ws.createFolder(folderName, folderDescription, destinationFolderId);
return workspaceFolder.getId();
} catch (WorkspaceFolderNotFoundException | InternalErrorException | HomeNotFoundException StorageHubClient shc = new StorageHubClient();
| InsufficientPrivilegesException | ItemAlreadyExistException | WrongDestinationException OpenResolver openResolver = shc.open(destinationFolderId);
| ItemNotFoundException e) {
logger.error("CreateFolderOnWorkspace: " + e.getLocalizedMessage()); FolderContainer parentFolderContainer = openResolver.asFolder();
e.printStackTrace(); FolderContainer folderContainer = parentFolderContainer.newFolder(folderName, folderDescription);
FolderItem folderItem = folderContainer.get();
logger.debug("Folder created: " + folderItem.getId());
return folderItem.getId();
} catch (Throwable e) {
logger.error("Error in create folder on workspace: " + e.getLocalizedMessage(), e);
throw new ServiceException(e.getLocalizedMessage(), e); throw new ServiceException(e.getLocalizedMessage(), e);
} }
} }
/** /**
* *
* @param user * @param user
* user * user
* @param destinationFolderId * @param folderId
* destination folder id * destination folder id
* @param fileName * @param name
* file name * file name
* @param fileDescription * @param description
* file description * file description
* @param is * @param inputStream
* input stream * input stream
* @return file id * @return file id
* @throws ServiceException * @throws ServiceException
* service exception * service exception
*/ */
public static String saveOnWorkspace(String user, String destinationFolderId, String fileName, public String saveOnWorkspace(String user, String folderId, String name, String description,
String fileDescription, InputStream is) throws ServiceException { InputStream inputStream) throws ServiceException {
try { try {
logger.debug("saveOnWorkspace: [User=" + user + ", FolderId:" + destinationFolderId + ", fileName=" logger.info("Save item on workspace: [user=" + user + ", name=" + name + ", description=" + description
+ fileName + ", fileDescription=" + fileDescription + "]"); + ", folderId=" + folderId + "]");
Workspace ws = HomeLibrary.getUserWorkspace(user); StorageHubClient shc = new StorageHubClient();
OpenResolver openResolver = shc.open(folderId);
WorkspaceItem workspaceItem = ws.getItem(destinationFolderId); FolderContainer folderContainer = openResolver.asFolder();
if (workspaceItem.isFolder()) { FileContainer fileContainer = folderContainer.uploadFile(inputStream, name, description);
ExternalFile externalfile = ws.createExternalFile(fileName, fileDescription, null, is, AbstractFileItem abstractFileItem = fileContainer.get();
destinationFolderId);
return externalfile.getId();
} else {
throw new ServiceException("Invalid destination folder!");
}
} catch (WorkspaceFolderNotFoundException | InternalErrorException | HomeNotFoundException logger.debug("File saved id: " + abstractFileItem.getId());
| InsufficientPrivilegesException | ItemAlreadyExistException | WrongDestinationException return abstractFileItem.getId();
| ItemNotFoundException e) { } catch (Throwable e) {
logger.error("SaveOnWorkspace: " + e.getLocalizedMessage()); logger.error("Save item on workspace: " + e.getLocalizedMessage(), e);
e.printStackTrace();
throw new ServiceException(e.getLocalizedMessage(), e); throw new ServiceException(e.getLocalizedMessage(), e);
} }
} }
} }