ref 12474:AccountingManager - Update to StorageHub
https://support.d4science.org/issues/12474 Updated to StorageHub git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/admin/accounting-manager@171441 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
95f6942661
commit
9063a84dd5
|
@ -1,12 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/accounting-manager-1.9.1-SNAPSHOT/WEB-INF/classes" path="src/main/java">
|
||||
<classpathentry kind="src" output="target/accounting-manager-1.10.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/accounting-manager-1.9.1-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
|
||||
<classpathentry excluding="**" kind="src" output="target/accounting-manager-1.10.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
|
@ -45,5 +45,5 @@
|
|||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/accounting-manager-1.9.1-SNAPSHOT/WEB-INF/classes"/>
|
||||
<classpathentry kind="output" path="target/accounting-manager-1.10.0-SNAPSHOT/WEB-INF/classes"/>
|
||||
</classpath>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
|
||||
<wb-module deploy-name="accounting-manager-1.9.1-SNAPSHOT">
|
||||
<wb-module deploy-name="accounting-manager-1.10.0-SNAPSHOT">
|
||||
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
|
||||
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
<root>
|
||||
<facet id="jst.jaxrs">
|
||||
<node name="libprov">
|
||||
<attribute name="provider-id" value="jaxrs-no-op-library-provider"/>
|
||||
</node>
|
||||
</facet>
|
||||
</root>
|
|
@ -4,4 +4,5 @@
|
|||
<installed facet="jst.web" version="3.0"/>
|
||||
<installed facet="wst.jsdt.web" version="1.0"/>
|
||||
<installed facet="java" version="1.7"/>
|
||||
<installed facet="jst.jaxrs" version="2.0"/>
|
||||
</faceted-project>
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
<ReleaseNotes>
|
||||
<Changeset component="org.gcube.portlets.admin.accounting-manager.1-10-0"
|
||||
date="2018-10-01">
|
||||
<Change>Updated to StorageHub [Ticket #12474]</Change>
|
||||
</Changeset>
|
||||
<Changeset component="org.gcube.portlets.admin.accounting-manager.1-9-1"
|
||||
date="2018-04-11">
|
||||
<Change>Updated log level to debug [Ticket #11259]</Change>
|
||||
|
|
64
pom.xml
64
pom.xml
|
@ -13,7 +13,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.gcube.portlets.admin</groupId>
|
||||
<artifactId>accounting-manager</artifactId>
|
||||
<version>1.9.1-SNAPSHOT</version>
|
||||
<version>1.10.0-SNAPSHOT</version>
|
||||
<packaging>war</packaging>
|
||||
|
||||
|
||||
|
@ -77,35 +77,13 @@
|
|||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- Storage -->
|
||||
<!-- StorageHub -->
|
||||
<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>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>storagehub-client-library</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Home Library -->
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>home-library</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>home-library-jcr</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>home-library-model</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Logger -->
|
||||
<dependency>
|
||||
|
@ -251,38 +229,12 @@
|
|||
<artifactId>common-encryption</artifactId>
|
||||
<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>
|
||||
|
||||
<!-- Home Library -->
|
||||
|
||||
<!-- StorageHub -->
|
||||
<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>
|
||||
<artifactId>storagehub-client-library</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Accounting Lib -->
|
||||
|
|
|
@ -536,7 +536,8 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet
|
|||
.getServiceCredentials(this.getThreadLocalRequest());
|
||||
|
||||
logger.debug("GetPublicLink(): " + itemDescription);
|
||||
String link = StorageUtil.getPublicLink(
|
||||
StorageUtil storageUtil=new StorageUtil();
|
||||
String link = storageUtil.getPublicLink(
|
||||
serviceCredentials.getUserName(), itemDescription.getId());
|
||||
|
||||
return link;
|
||||
|
|
|
@ -101,13 +101,13 @@ public class CSVManager {
|
|||
// close the printer
|
||||
printer.close();
|
||||
printStream.close();
|
||||
|
||||
String destinationFolderId = StorageUtil
|
||||
StorageUtil storageUtil=new StorageUtil();
|
||||
String destinationFolderId = storageUtil
|
||||
.createAccountingFolderOnWorkspace(userName);
|
||||
ItemDescription itemDescription=null;
|
||||
try (InputStream is = Files.newInputStream(tempFile,
|
||||
StandardOpenOption.READ)) {
|
||||
itemDescription=StorageUtil.saveOnWorkspace(userName, destinationFolderId,
|
||||
itemDescription=storageUtil.saveOnWorkspace(userName, destinationFolderId,
|
||||
accountingDataModel.getName() + FILE_EXTENSION,
|
||||
accountingDataModel.getName(), is);
|
||||
}
|
||||
|
|
|
@ -117,12 +117,13 @@ public class JSONManager {
|
|||
jsonObj.write(bw);
|
||||
}
|
||||
|
||||
String destinationFolderId = StorageUtil
|
||||
StorageUtil storageUtil=new StorageUtil();
|
||||
String destinationFolderId = storageUtil
|
||||
.createAccountingFolderOnWorkspace(userName);
|
||||
ItemDescription itemDescription = null;
|
||||
try (InputStream is = Files.newInputStream(tempFile,
|
||||
StandardOpenOption.READ)) {
|
||||
itemDescription = StorageUtil.saveOnWorkspace(userName,
|
||||
itemDescription = storageUtil.saveOnWorkspace(userName,
|
||||
destinationFolderId, accountingDataModel.getName()
|
||||
+ FILE_EXTENSION,
|
||||
accountingDataModel.getName(), is);
|
||||
|
|
|
@ -99,13 +99,13 @@ public class XMLManager {
|
|||
logger.debug("Archived:" + os);
|
||||
}
|
||||
|
||||
|
||||
String destinationFolderId = StorageUtil
|
||||
StorageUtil storageUtil=new StorageUtil();
|
||||
String destinationFolderId = storageUtil
|
||||
.createAccountingFolderOnWorkspace(userName);
|
||||
ItemDescription itemDescription = null;
|
||||
try (InputStream is = Files.newInputStream(tempFile,
|
||||
StandardOpenOption.READ)) {
|
||||
itemDescription = StorageUtil.saveOnWorkspace(userName,
|
||||
itemDescription = storageUtil.saveOnWorkspace(userName,
|
||||
destinationFolderId, accountingDataModel.getName()
|
||||
+ FILE_EXTENSION,
|
||||
accountingDataModel.getName(), is);
|
||||
|
|
|
@ -1,15 +1,21 @@
|
|||
package org.gcube.portlets.admin.accountingmanager.server.storage;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
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.homelibrary.home.workspace.folder.FolderItem;
|
||||
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.ListResolver;
|
||||
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.admin.accountingmanager.shared.exception.ServiceException;
|
||||
import org.gcube.portlets.admin.accountingmanager.shared.workspace.ItemDescription;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -20,7 +26,7 @@ import org.gcube.portlets.admin.accountingmanager.shared.workspace.ItemDescripti
|
|||
public class StorageUtil {
|
||||
|
||||
private static final String ACCOUNTING_MANAGER = "AccountingManager";
|
||||
private static Logger logger = Logger.getLogger(StorageUtil.class);
|
||||
private static Logger logger = LoggerFactory.getLogger(StorageUtil.class);
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -32,25 +38,16 @@ public class StorageUtil {
|
|||
* @throws ServiceException
|
||||
* service exception
|
||||
*/
|
||||
public static String getPublicLink(String user, String itemId) throws ServiceException {
|
||||
Workspace ws;
|
||||
public String getPublicLink(String user, String itemId) throws ServiceException {
|
||||
|
||||
try {
|
||||
logger.info("Get public link: [user=" + user + ", itemId=" + itemId + "]");
|
||||
ws = HomeLibrary.getUserWorkspace(user);
|
||||
|
||||
WorkspaceItem workSpaceItem = ws.getItem(itemId);
|
||||
if (workSpaceItem.isFolder()) {
|
||||
throw new ServiceException("Attention this is a folder!");
|
||||
}
|
||||
|
||||
if (workSpaceItem instanceof FolderItem) {
|
||||
return workSpaceItem.getPublicLink(false);
|
||||
} else {
|
||||
throw new ServiceException("Attention no public link for this item!");
|
||||
}
|
||||
logger.info("getPublicLink: [user=" + user + ", itemId=" + itemId + "]");
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
URL url = shc.open(itemId).asFile().getPublicLink();
|
||||
return url.toString();
|
||||
|
||||
} catch (Throwable e) {
|
||||
logger.error("getPublicLink: " + e.getLocalizedMessage(), e);
|
||||
logger.error("Get public link: " + e.getLocalizedMessage(), e);
|
||||
throw new ServiceException(e.getLocalizedMessage());
|
||||
|
||||
}
|
||||
|
@ -64,18 +61,34 @@ public class StorageUtil {
|
|||
* @throws ServiceException
|
||||
* service exception
|
||||
*/
|
||||
public static String createAccountingFolderOnWorkspace(String user) throws ServiceException {
|
||||
public String createAccountingFolderOnWorkspace(String user) throws ServiceException {
|
||||
try {
|
||||
logger.debug("CreateAccountingFolderOnWorkspace: [User=" + user + "]");
|
||||
Workspace ws = HomeLibrary.getUserWorkspace(user);
|
||||
WorkspaceItem workspaceItem = ws.find(ACCOUNTING_MANAGER);
|
||||
if (workspaceItem == null) {
|
||||
workspaceItem = ws.createFolder(ACCOUNTING_MANAGER, ACCOUNTING_MANAGER, ws.getRoot().getId());
|
||||
logger.info("CreateAccountingFolderOnWorkspace: [User=" + user + "]");
|
||||
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
FolderContainer root = shc.getWSRoot();
|
||||
ListResolver listResolver = root.findByName(ACCOUNTING_MANAGER);
|
||||
List<? extends Item> items = listResolver.getItems();
|
||||
if (items == null || items.isEmpty()) {
|
||||
logger.debug("No folder found");
|
||||
FolderContainer folderContainer = root.newFolder(ACCOUNTING_MANAGER, ACCOUNTING_MANAGER);
|
||||
FolderItem folderItem = folderContainer.get();
|
||||
return folderItem.getId();
|
||||
} else {
|
||||
Item item = items.get(0);
|
||||
logger.debug("Item: " + item);
|
||||
if (item != null) {
|
||||
return item.getId();
|
||||
} else {
|
||||
logger.debug("No folder found");
|
||||
FolderContainer folderContainer = root.newFolder(ACCOUNTING_MANAGER, ACCOUNTING_MANAGER);
|
||||
FolderItem folderItem = folderContainer.get();
|
||||
return folderItem.getId();
|
||||
}
|
||||
}
|
||||
return workspaceItem.getId();
|
||||
|
||||
} catch (Throwable e) {
|
||||
logger.error("CreateAccountingFolderOnWorkspace: " + e.getLocalizedMessage(), e);
|
||||
logger.error("Error in create Accounting folder on workspace: " + e.getLocalizedMessage(), e);
|
||||
throw new ServiceException(e.getLocalizedMessage(), e);
|
||||
|
||||
}
|
||||
|
@ -85,41 +98,42 @@ public class StorageUtil {
|
|||
*
|
||||
* @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 item description
|
||||
* @throws ServiceException
|
||||
* service exception
|
||||
*/
|
||||
public static ItemDescription saveOnWorkspace(String user, String destinationFolderId, String fileName,
|
||||
String fileDescription, InputStream is) throws ServiceException {
|
||||
public ItemDescription 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);
|
||||
logger.info("Save item on workspace: [user=" + user + ", name=" + name + ", description=" + description
|
||||
+ ", folderId=" + folderId + "]");
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
OpenResolver openResolver = shc.open(folderId);
|
||||
|
||||
WorkspaceItem workspaceItem = ws.getItem(destinationFolderId);
|
||||
if (workspaceItem.isFolder()) {
|
||||
ExternalFile externalfile = ws.createExternalFile(fileName, fileDescription, null, is,
|
||||
destinationFolderId);
|
||||
ItemDescription itemDescription = new ItemDescription(externalfile.getId(), externalfile.getName(),
|
||||
externalfile.getOwner().getId(), externalfile.getPath(), externalfile.getType().name());
|
||||
FolderContainer folderContainer = openResolver.asFolder();
|
||||
FileContainer fileContainer = folderContainer.uploadFile(inputStream, name, description);
|
||||
AbstractFileItem item = fileContainer.get();
|
||||
|
||||
return itemDescription;
|
||||
} else {
|
||||
throw new ServiceException("Invalid destination folder!");
|
||||
}
|
||||
ItemDescription itemDescription = new ItemDescription(item.getId(), item.getName(), item.getOwner(),
|
||||
item.getPath(), item.getClass().getSimpleName());
|
||||
|
||||
logger.debug("File saved: " + itemDescription);
|
||||
|
||||
return itemDescription;
|
||||
|
||||
} catch (Throwable e) {
|
||||
logger.error("SaveOnWorkspace: " + e.getLocalizedMessage(), e);
|
||||
logger.error("Save item on workspace: " + e.getLocalizedMessage(), e);
|
||||
throw new ServiceException(e.getLocalizedMessage(), e);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import java.io.Serializable;
|
|||
|
||||
/**
|
||||
*
|
||||
* @author Giancarlo Panichi
|
||||
* @author Giancarlo Panichi
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
@ -23,8 +23,7 @@ public class ItemDescription implements Serializable {
|
|||
super();
|
||||
}
|
||||
|
||||
public ItemDescription(String id, String name, String owner, String path,
|
||||
String type) {
|
||||
public ItemDescription(String id, String name, String owner, String path, String type) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
|
@ -84,29 +83,24 @@ public class ItemDescription implements Serializable {
|
|||
/**
|
||||
* Compare basic information with another ItemDescription not null
|
||||
*
|
||||
* @param itemDescription item description
|
||||
* @return boolean true if item description match
|
||||
* @param itemDescription
|
||||
* item description
|
||||
* @return boolean true if item description match
|
||||
*
|
||||
*/
|
||||
public boolean compareInfo(ItemDescription itemDescription){
|
||||
if(itemDescription!=null && id.compareTo(itemDescription.getId())==0 &&
|
||||
name.compareTo(itemDescription.getName())==0 &&
|
||||
owner.compareTo(itemDescription.getOwner())==0 &&
|
||||
path.compareTo(itemDescription.getPath())==0 &&
|
||||
type.compareTo(itemDescription.getType())==0
|
||||
){
|
||||
public boolean compareInfo(ItemDescription itemDescription) {
|
||||
if (itemDescription != null && id.compareTo(itemDescription.getId()) == 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ItemDescription [id=" + id + ", name=" + name + ", owner="
|
||||
+ owner + ", path=" + path + ", type=" + type + ", publicLink="
|
||||
+ publicLink + "]";
|
||||
return "ItemDescription [id=" + id + ", name=" + name + ", owner=" + owner + ", path=" + path + ", type=" + type
|
||||
+ ", publicLink=" + publicLink + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue