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
master
Giancarlo Panichi 6 years ago
parent 51c30aea93
commit 75455a0ddd

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</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>
<attribute name="maven.pomderived" value="true"/>
</attributes>
@ -34,5 +34,5 @@
</attributes>
</classpathentry>
<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>

@ -1,4 +1,8 @@
<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"
date="2017-06-12">
<Change>Support Java 8 compatibility [ticket #8541]</Change>

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

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

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

Loading…
Cancel
Save