working on migration to SHUB

This commit is contained in:
Francesco Mangiacrapa 2020-04-09 15:33:21 +02:00
parent 06b3a2a987
commit dc656a78e2
5 changed files with 245 additions and 218 deletions

View File

@ -51,6 +51,7 @@ public interface WorkspaceExplorerAppService extends RemoteService {
* @param filterCriteria the filter criteria
* @return the folder
* @throws WorkspaceNavigatorServiceException the workspace navigator service exception
* @throws
*/
Item getFolder(
Item folder, List<ItemType> showableTypes, boolean purgeEmpyFolders,

View File

@ -10,8 +10,12 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItemType;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceSharedFolder;
import org.gcube.common.storagehubwrapper.shared.tohl.items.FileItem;
import org.gcube.common.storagehubwrapper.shared.tohl.items.PropertyMap;
import org.gcube.portlets.user.workspaceexplorerapp.client.Util;
import org.gcube.portlets.user.workspaceexplorerapp.client.WorkspaceExplorerAppConstants;
import org.gcube.portlets.user.workspaceexplorerapp.shared.FilterCriteria;
@ -21,6 +25,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// TODO: Auto-generated Javadoc
/**
* The Class ItemBuilder.
*
@ -79,62 +84,73 @@ public class ItemBuilder {
* @return the item
* @throws InternalErrorException the internal error exception
*/
public static Item getItem(Item parent, WorkspaceItem workspaceItem, String workspaceItemPath, List<ItemType> showableTypes, FilterCriteria filterCriteria, boolean loadChildren) throws InternalErrorException
public static Item getItem(Item parent, WorkspaceItem workspaceItem, String workspaceItemPath, List<ItemType> showableTypes, FilterCriteria filterCriteria, boolean loadChildren) throws Exception
{
ItemType type = getItemType(workspaceItem);
if (!showableTypes.contains(type)) {
return null;
}
if (!filterItem(type, workspaceItem, filterCriteria)) {
return null;
}
// //TODO ADD CONTROL ON THE PATH WHEN WILL BE MORE FAST
// if (itemName.equals(WorkspaceExplorerConstants.SPECIAL_FOLDERS_LABEL))
// itemName = WorkspaceExplorerConstants.VRE_FOLDERS_LABEL;
boolean isFolder = type.equals(ItemType.FOLDER)?true:false;
boolean isSharedFolder = workspaceItem.getType().equals(WorkspaceItemType.SHARED_FOLDER)?true:false;
String itemName = workspaceItem.getName();
if(isSharedFolder){
_log.debug("Is shared folder");
WorkspaceSharedFolder shared = (WorkspaceSharedFolder) workspaceItem;
itemName = shared.isVreFolder()?shared.getDisplayName():workspaceItem.getName();
}
// _log.debug("Building Item for: "+itemName);
Item item = null;
try{
item = new Item(parent, workspaceItem.getId(), itemName, type, workspaceItemPath, workspaceItem.getOwner().getPortalLogin(), toDate(workspaceItem.getCreationTime()), isFolder, false);
item.setSharedFolder(isSharedFolder);
}catch(Exception e){
_log.error("Error on getting item: "+itemName+" with id: "+workspaceItem.getId()+", from HL, so skipping item");
return null;
}
if(loadChildren){
//TODO A PATCH TO AVOID A SLOW GETPATH
// workspaceItemPath = workspaceItem.getPath();
for (WorkspaceItem child: workspaceItem.getChildren()){
String itemPath = workspaceItemPath;
if(child.isFolder())
itemPath+="/"+child.getName();
// _log.trace("\nConverting child item: "+child.getName());
Item itemChild = getItem(item, child, itemPath, showableTypes, filterCriteria, false);
// _log.trace("Item: "+child.getName() +" converted!!!");
if (itemChild!=null){
item.addChild(itemChild);
try {
String itemName = workspaceItem.getName();
boolean isFolder = workspaceItem.isFolder();
ItemType type = getItemType(workspaceItem);
if (!showableTypes.contains(type)) {
return null;
}
if (!filterItem(workspaceItem, filterCriteria)) {
return null;
}
boolean isSharedFolder = false;
if(workspaceItem instanceof WorkspaceSharedFolder){
isSharedFolder = true;
_log.debug("Is shared folder");
WorkspaceSharedFolder shared = (WorkspaceSharedFolder) workspaceItem;
//itemName = shared.isVreFolder()?shared.getDisplayName():workspaceItem.getName(); //NOT IMPLEMENTED BY SHUB
itemName = shared.isVreFolder()?shared.getName():workspaceItem.getName();
}
// _log.debug("Building Item for: "+itemName);
Item item = null;
try{
item = new Item(parent,
workspaceItem.getId(),
itemName,
type,
workspaceItemPath,
workspaceItem.getOwner(),
toDate(workspaceItem.getCreationTime()),
isFolder,
false);
item.setSharedFolder(isSharedFolder);
}catch(Exception e){
_log.error("Error on getting item: "+itemName+" with id: "+workspaceItem.getId()+", from HL, so skipping item");
return null;
}
if(loadChildren){
//TODO A PATCH TO AVOID A SLOW GETPATH
// workspaceItemPath = workspaceItem.getPath();
for (WorkspaceItem child: workspaceItem.getChildren()){
String itemPath = workspaceItemPath;
if(child.isFolder())
itemPath+="/"+child.getName();
// _log.trace("\nConverting child item: "+child.getName());
Item itemChild = getItem(item, child, itemPath, showableTypes, filterCriteria, false);
// _log.trace("Item: "+child.getName() +" converted!!!");
if (itemChild!=null){
item.addChild(itemChild);
}
}
}
}
return item;
return item;
}catch (Exception e) {
_log.error("Error on getting item: "+workspaceItem.getName()+" with id: "+workspaceItem.getId(), e);
throw new Exception("Error on retrieving the item: "+workspaceItem.getName());
}
}
@ -156,7 +172,6 @@ public class ItemBuilder {
*
* @param item the item
* @return the item type
* @throws InternalErrorException the internal error exception
*/
protected static ItemType getItemType(WorkspaceItem item) {
switch (item.getType()) {
@ -196,51 +211,49 @@ public class ItemBuilder {
}
}
/**
* Filter item.
* Filter item using the input Filter Criteria
*
* @param type the type
* @param item the item
* @param filterCriteria the filter criteria
* @return true, if successful
* @throws InternalErrorException the internal error exception
*/
protected static boolean filterItem(ItemType type, WorkspaceItem item, FilterCriteria filterCriteria) throws InternalErrorException {
protected static boolean filterItem(WorkspaceItem item, FilterCriteria filterCriteria) {
if(filterCriteria==null) {
return true;
}
boolean mimeTypeCheck = checkAllowedMimeTypes(type, item, filterCriteria.getAllowedMimeTypes());
boolean mimeTypeCheck = checkAllowedMimeTypes(item, filterCriteria.getAllowedMimeTypes());
if (!mimeTypeCheck) {
return false;
}
boolean fileExtensionCheck = checkAllowedFileExtension(type, item, filterCriteria.getAllowedFileExtensions());
boolean fileExtensionCheck = checkAllowedFileExtension(item, filterCriteria.getAllowedFileExtensions());
if(!fileExtensionCheck) {
return false;
}
boolean propertiesCheck = checkProperties(item, filterCriteria.getRequiredProperties());
return propertiesCheck;
}
/**
* Check allowed mime types.
* Check allowed mime types on file.
*
* @param type the type
* @param item the item
* @param allowedMimeTypes the allowed mime types
* @return true, if successful
*/
protected static boolean checkAllowedMimeTypes(ItemType type, WorkspaceItem item, List<String> allowedMimeTypes){
protected static boolean checkAllowedMimeTypes(WorkspaceItem item, List<String> allowedMimeTypes){
if (allowedMimeTypes==null || allowedMimeTypes.size()==0) {
return true;
}
if (type == ItemType.EXTERNAL_FILE || type == ItemType.EXTERNAL_IMAGE || type == ItemType.EXTERNAL_PDF_FILE) {
ExternalFile externalFile = (ExternalFile)item;
String mimeType = externalFile.getMimeType();
if (item instanceof FileItem) {
FileItem fileItem = (FileItem) item;
String mimeType = fileItem.getMimeType();
return allowedMimeTypes.contains(mimeType);
}
return true;
@ -250,25 +263,24 @@ public class ItemBuilder {
/**
* Check allowed file extension.
* Check allowed file extension on file.
*
* @param type the type
* @param item the item
* @param allowedFileExtension the allowed mime types
* @return true, if successful
*/
protected static boolean checkAllowedFileExtension(ItemType type, WorkspaceItem item, List<String> allowedFileExtension){
protected static boolean checkAllowedFileExtension(WorkspaceItem item, List<String> allowedFileExtension){
if (allowedFileExtension==null || allowedFileExtension.size()==0) {
return true;
}
try {
if (type != ItemType.FOLDER) {
if (item instanceof FileItem) {
String name = item.getName();
return checkFileExtension(name, allowedFileExtension);
}
return true;
} catch (InternalErrorException e) {
} catch (Exception e) {
_log.error("checkAllowedFileExtension, InternalErrorException: ",e);
return false;
}
@ -312,22 +324,26 @@ public class ItemBuilder {
* @param item the item
* @param requestedProperties the requested properties
* @return true, if successful
* @throws InternalErrorException the internal error exception
*/
protected static boolean checkProperties(WorkspaceItem item, Map<String, String> requestedProperties) throws InternalErrorException
{
if (requestedProperties==null || requestedProperties.size()==0 || item.getType()!=WorkspaceItemType.FOLDER_ITEM) {
protected static boolean checkProperties(WorkspaceItem item, Map<String, String> requestedProperties) {
if (requestedProperties == null || requestedProperties.size() == 0) {
return true;
}
Map<String, String> itemProperties = item.getProperties().getProperties();
for (Entry<String, String> requestProperty:requestedProperties.entrySet()) {
String propertyValue = itemProperties.get(requestProperty.getKey());
if (propertyValue == null) {
return false;
}
if (!propertyValue.equals(requestProperty.getValue())) {
return false;
if (item.getPropertyMap() != null) {
PropertyMap mapProp = item.getPropertyMap();
if (mapProp != null && mapProp.getValues() != null) {
Map<String, Object> itemProperties = mapProp.getValues();
for (Entry<String, String> requestProperty : requestedProperties.entrySet()) {
Object propertyValue = itemProperties.get(requestProperty.getKey());
if (propertyValue == null) {
return false;
}
if (!propertyValue.equals(requestProperty.getValue())) {
return false;
}
}
}
}
@ -344,7 +360,7 @@ public class ItemBuilder {
* @return the item
* @throws InternalErrorException the internal error exception
*/
public static Item buildFolderForBreadcrumbs(WorkspaceFolder wsFolder, Item parent) throws InternalErrorException {
public static Item buildFolderForBreadcrumbs(WorkspaceFolder wsFolder, Item parent) throws Exception {
String name = "";
boolean isSpecialFolder = false;
@ -353,11 +369,14 @@ public class ItemBuilder {
if(wsFolder.isRoot()){ //IS ROOT
name = WorkspaceExplorerAppConstants.HOME_LABEL;
isRoot = true;
}else if(wsFolder.isShared() && wsFolder.getType().equals(WorkspaceItemType.SHARED_FOLDER)){ //MANAGEMENT SHARED FOLDER NAME
}else if(wsFolder.isShared() && wsFolder instanceof WorkspaceSharedFolder){
//MANAGEMENT SHARED FOLDER NAME
WorkspaceSharedFolder shared = (WorkspaceSharedFolder) wsFolder;
name = shared.isVreFolder()?shared.getDisplayName():wsFolder.getName();
//MANAGEMENT SPECIAL FOLDER
//name = shared.isVreFolder()?shared.getDisplayName():wsFolder.getName();
name = shared.isVreFolder()?shared.getName():wsFolder.getName(); //not implemented by SHUB
}else if(isSpecialFolder(wsFolder)){
//MANAGEMENT SPECIAL FOLDER
name = WorkspaceExplorerAppConstants.VRE_FOLDERS_LABEL;
isSpecialFolder = true;
}
@ -383,8 +402,8 @@ public class ItemBuilder {
public static boolean isSpecialFolder(WorkspaceFolder wsFolder){
try {
return wsFolder.getName().compareTo(WorkspaceExplorerAppConstants.SPECIAL_FOLDERS_NAME)==0 && wsFolder.getParent()!=null && wsFolder.getParent().isRoot();
} catch (InternalErrorException e) {
return wsFolder.getName().compareTo(WorkspaceExplorerAppConstants.SPECIAL_FOLDERS_NAME)==0 && wsFolder.getParentId()!=null && wsFolder.getParent().isRoot();
} catch (Exception e) {
_log.warn("isSpecialFolder exception, returning false");
return false;
}

View File

@ -9,7 +9,11 @@ import java.util.concurrent.TimeUnit;
import org.gcube.common.encryption.StringEncrypter;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.storagehubwrapper.server.tohl.Workspace;
import org.gcube.common.storagehubwrapper.shared.tohl.impl.WorkspaceFolder;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItemType;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceSharedFolder;
import org.gcube.common.storagehubwrapper.shared.tohl.items.FileItem;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder;
import org.gcube.portlets.user.workspaceexplorerapp.client.WorkspaceExplorerAppConstants;
import org.gcube.portlets.user.workspaceexplorerapp.client.rpc.WorkspaceExplorerAppService;
import org.gcube.portlets.user.workspaceexplorerapp.shared.FilterCriteria;
@ -23,6 +27,7 @@ import org.slf4j.LoggerFactory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
// TODO: Auto-generated Javadoc
/**
* The Class WorkspaceExplorerAppServiceImpl.
*
@ -86,86 +91,89 @@ public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implem
}
}
/**
* {@inheritDoc}
* Gets the folder.
*
* @param item the item
* @param showableTypes the showable types
* @param purgeEmpyFolders the purge empy folders
* @param filterCriteria the filter criteria
* @return the folder
* @throws Exception the exception
*/
@Override
public Item getFolder(Item item, List<ItemType> showableTypes, boolean purgeEmpyFolders, FilterCriteria filterCriteria) throws WorkspaceNavigatorServiceException {
logger.trace("getFolder item: "+item+" showableTypes: "+showableTypes+" purgeEmpyFolders: "+purgeEmpyFolders+" filterCriteria: "+filterCriteria);
WorkspaceItem workspaceItem = null;
try {
if(item==null || item.getId()==null)
throw new Exception("Item id is null");
Workspace workspace = WsUtil.getWorkspace(this.getThreadLocalRequest().getSession());
WorkspaceItem folder = workspace.getItem(item.getId());
logger.trace("GetFolder - Replyiing folder");
long startTime = System.currentTimeMillis();
logger.trace("start time - " + startTime);
String path = item.getPath()!=null && !item.getPath().isEmpty()?item.getPath():folder.getPath();
Item itemFolder = ItemBuilder.getItem(null, folder, path, showableTypes, filterCriteria, true);
// _log.trace("Only showable types:");
if (purgeEmpyFolders) {
itemFolder = ItemBuilder.purgeEmptyFolders(itemFolder);
}
logger.trace("Returning:");
Long endTime = System.currentTimeMillis() - startTime;
String time = String.format("%d msc %d sec", endTime, TimeUnit.MILLISECONDS.toSeconds(endTime));
logger.info("end time - " + time);
Collections.sort(itemFolder.getChildren(), new ItemComparator());
return itemFolder;
workspaceItem = workspace.getItem(item.getId());
} catch (Exception e) {
logger.error("Error during folder retrieving", e);
throw new WorkspaceNavigatorServiceException("Sorry, an error occurred when performing get folder");
logger.error("Error during item retrieving", e);
throw new WorkspaceNavigatorServiceException("Sorry, an error occurred when performing get folder. Does it still exist?");
}
if(workspaceItem != null && workspaceItem.isFolder()) {
try {
WorkspaceItem folder = workspaceItem;
logger.trace("GetFolder - Replyiing folder");
long startTime = System.currentTimeMillis();
logger.trace("start time - " + startTime);
String path = item.getPath()!=null && !item.getPath().isEmpty()?item.getPath():folder.getPath();
Item itemFolder = ItemBuilder.getItem(null, folder, path, showableTypes, filterCriteria, true);
// _log.trace("Only showable types:");
if (purgeEmpyFolders) {
itemFolder = ItemBuilder.purgeEmptyFolders(itemFolder);
}
logger.trace("Returning:");
Long endTime = System.currentTimeMillis() - startTime;
String time = String.format("%d msc %d sec", endTime, TimeUnit.MILLISECONDS.toSeconds(endTime));
logger.info("end time - " + time);
Collections.sort(itemFolder.getChildren(), new ItemComparator());
return itemFolder;
}catch (Exception e) {
throw new WorkspaceNavigatorServiceException(e.getMessage());
}
}else {
logger.error("The item requested is not a folder");
throw new WorkspaceNavigatorServiceException("Error, the item requested is not a folder");
}
}
/**
* Gets the item by category.
*
* @param category the category
* @return the item by category
* @throws WorkspaceNavigatorServiceException the workspace navigator service exception
*/
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.wsexplorer.client.rpc.WorkspaceExplorerService#getItemByCategory(org.gcube.portlets.widgets.wsexplorer.shared.ItemCategory)
*/
@Override
public Item getItemByCategory(ItemCategory category) throws WorkspaceNavigatorServiceException{
logger.trace("GetItemByCategory category: "+category);
return null; //TODO
// try {
// Workspace workspace = WsUtil.getWorkspace();
// Item item = null;
//
// switch(category){
// case HOME:{
// WorkspaceItem root = workspace.getRoot();
//// String fullName = UserUtil.getUserFullName(session.getUsername());
// String fullName = session.getUsername();
// if(fullName.indexOf(" ")>0){
// fullName = fullName.substring(0, fullName.indexOf(" "));
// }else if(fullName.indexOf(".")>0){
// fullName = fullName.substring(0, fullName.indexOf("."));
// }
// item = new Item(null, root.getId(), fullName+"'s", ItemType.FOLDER, root.getPath(), root.getOwner().getPortalLogin(), null, true, true);
// break;
// }
// case VRE_FOLDER:{
// WorkspaceItem folder = workspace.getMySpecialFolders();
// item = new Item(null, folder.getId(), WorkspaceExplorerAppConstants.VRE_FOLDERS_LABEL, ItemType.FOLDER, folder.getPath(), folder.getOwner().getPortalLogin(), null, true, false);
// //SET SPECIAL FOLDER /Workspace/MySpecialFolders
// item.setSpecialFolder(true);
// break;
// }
// }
// return item;
// } catch (Exception e) {
// logger.error("Error during get item by category", e);
// throw new WorkspaceNavigatorServiceException("Sorry, an error occurred when performing get item by category");
// }
throw new WorkspaceNavigatorServiceException("The method getItemByCategory is not implemented");
}
/**
@ -179,34 +187,24 @@ public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implem
Workspace workspace = WsUtil.getWorkspace(this.getThreadLocalRequest().getSession());
WorkspaceItem folder = workspace.getMySpecialFolders();
long startTime = System.currentTimeMillis();
logger.trace("start time - " + startTime);
Item itemFolder = ItemBuilder.getItem(null, folder, folder.getPath(), showableTypes, filterCriteria, true);
//OVERRIDING VRE FOLDERS NAME - SET SPECIAL FOLDER /Workspace/MySpecialFolders
itemFolder.setName(WorkspaceExplorerAppConstants.VRE_FOLDERS_LABEL);
itemFolder.setSpecialFolder(true);
logger.trace("Builded MySpecialFolder: "+itemFolder);
logger.trace("Only showable types:");
//printName("", folderItem);
if (purgeEmpyFolders) {
itemFolder = ItemBuilder.purgeEmptyFolders(itemFolder);
}
logger.trace("Returning:");
Long endTime = System.currentTimeMillis() - startTime;
String time = String.format("%d msc %d sec", endTime, TimeUnit.MILLISECONDS.toSeconds(endTime));
logger.trace("end time - " + time);
//printName("", folderItem);
Collections.sort(itemFolder.getChildren(), new ItemComparator());
return itemFolder;
} catch (Exception e) {
@ -221,13 +219,14 @@ public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implem
@Override
public boolean checkName(String name) throws WorkspaceNavigatorServiceException {
logger.trace("checkName name: "+name);
try {
Workspace workspace = WsUtil.getWorkspace(this.getThreadLocalRequest().getSession());
return workspace.isValidName(name);
} catch (Exception e) {
logger.error("Error during folder retrieving", e);
throw new WorkspaceNavigatorServiceException(e.getMessage());
}
throw new WorkspaceNavigatorServiceException("The method checkName is not implemented");
// try {
// Workspace workspace = WsUtil.getWorkspace(this.getThreadLocalRequest().getSession());
// return workspace.isValidName(name);
// } catch (Exception e) {
// logger.error("Error during folder retrieving", e);
// throw new WorkspaceNavigatorServiceException(e.getMessage());
// }
}
/*protected void printName(String indentation, Item item)
@ -254,7 +253,7 @@ public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implem
Workspace workspace = WsUtil.getWorkspace(this.getThreadLocalRequest().getSession());
WorkspaceItem wsItem = workspace.getItem(itemIdentifier);
logger.trace("workspace retrieve item name: "+wsItem.getName());
List<WorkspaceItem> parents = workspace.getParentsById(itemIdentifier);
List<? extends WorkspaceItem> parents = workspace.getParentsById(itemIdentifier);
logger.trace("parents size: "+parents.size());
Item[] arrayParents;
@ -262,12 +261,13 @@ public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implem
switch (parents.size()) {
case 0: // itemIdentifier is ROOT
logger.trace("itemIdentifier isRoot...");
if (includeItemAsParent) { //ADDIND ROOT
WorkspaceFolder wsFolder =(WorkspaceFolder) workspace.getItem(itemIdentifier);
if (includeItemAsParent) { //ADDING ROOT
org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder wsFolder =
(org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder) wsItem;
Item root = ItemBuilder.buildFolderForBreadcrumbs(wsFolder, null);
List<Item> listParents = new ArrayList<Item>(1);
listParents.add(root);
// workspaceLogger.trace("returning: "+listParents.toString());
//workspaceLogger.trace("returning: "+listParents.toString());
return listParents;
}
else{
@ -278,11 +278,12 @@ public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implem
case 1: //itemIdentifier is first level from root
logger.trace("itemIdentifier is first level...");
List<Item> listParents = new ArrayList<Item>();
WorkspaceFolder wsRootFolder = (WorkspaceFolder) parents.get(0); //isRoot
org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder wsRootFolder = (org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder) parents.get(0); //isRoot
Item root = ItemBuilder.buildFolderForBreadcrumbs(wsRootFolder, null);
Item parent = null;
if(includeItemAsParent){
WorkspaceFolder wsFolder1 =(WorkspaceFolder) workspace.getItem(itemIdentifier); //root
org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder wsFolder1 =
(org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder) workspace.getItem(itemIdentifier); //root
parent = ItemBuilder.buildFolderForBreadcrumbs(wsFolder1, null);
}
listParents.add(root);
@ -370,7 +371,7 @@ public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implem
Workspace workspace = WsUtil.getWorkspace(this.getThreadLocalRequest().getSession());
WorkspaceItem wsItem = workspace.getItem(itemIdentifier);
logger.trace("workspace retrieve item name: "+wsItem.getName());
List<WorkspaceItem> parents = null;
List<? extends WorkspaceItem> parents = null;
try{
parents = workspace.getParentsById(itemIdentifier);
}catch(Exception e){
@ -405,7 +406,7 @@ public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implem
WorkspaceItem lastItem = parents.get(parents.size()-1);
//CONVERTING LAST ELEMENT IF NECESSARY
//CONVERTING LAST ELEMENT IF NEEDED...
logger.debug("converting last element..");
if(includeItemAsParent && lastItem.isFolder()){ //FIX BUG #298
arrayParents = new Item[parents.size()];
@ -476,6 +477,13 @@ public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implem
}
}
/**
* Gets the size by item id.
*
* @param itemId the item id
* @return the size by item id
* @throws Exception the exception
*/
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.wsexplorer.client.rpc.WorkspaceExplorerService#loadSizeByItemId(java.lang.String)
*/
@ -489,15 +497,15 @@ public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implem
WorkspaceItem wsItem = workspace.getItem(itemId);
Long size = new Long(-1);
if(wsItem instanceof FolderItem){ //ITEM
FolderItem folderItem = (FolderItem) wsItem;
size = new Long(folderItem.getLength());
if(wsItem instanceof FileItem){ //ITEM
FileItem fileItem = (FileItem) wsItem;
size = new Long(fileItem.getSize());
} else if (wsItem instanceof WorkspaceFolder ){ //FOLDER
WorkspaceFolder theFolder = (WorkspaceFolder) wsItem;
size = theFolder.getSize();
//size = theFolder.getSize(); NOT SUPPORTED BY SHUB
} else if (wsItem instanceof WorkspaceSharedFolder){ //SHARED FOLDER
WorkspaceSharedFolder theFolder = (WorkspaceSharedFolder) wsItem;
size = theFolder.getSize();
//size = theFolder.getSize(); NOT SUPPORTED BY SHUB
}
logger.info("returning size: " +size);
return size;
@ -508,6 +516,13 @@ public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implem
}
}
/**
* Gets the mime type.
*
* @param itemId the item id
* @return the mime type
* @throws Exception the exception
*/
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.wsexplorer.client.rpc.WorkspaceExplorerService#getMimeType(java.lang.String)
*/
@ -519,14 +534,12 @@ public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implem
Workspace workspace = WsUtil.getWorkspace(this.getThreadLocalRequest().getSession());
WorkspaceItem wsItem = workspace.getItem(itemId);
if(!wsItem.getType().equals(WorkspaceItemType.FOLDER_ITEM)) {
if(wsItem instanceof FileItem) {
FileItem fileItem = (FileItem) wsItem;
return fileItem.getMimeType();
}else
return null;
}
FolderItem folderItem = (FolderItem) wsItem;
return folderItem.getMimeType();
} catch (Exception e) {
logger.error("get MimeType By ItemId ", e);
@ -570,25 +583,31 @@ public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implem
* @param asRoot the as root
* @return true, if is a shared folder
*/
private boolean isASharedFolder(WorkspaceItem item, boolean asRoot){
private boolean isASharedFolder(WorkspaceItem item, boolean asRoot) {
try {
if(item!=null && item.isFolder() && item.isShared()){ //IS A SHARED SUB-FOLDER
if(asRoot)
{
return item.getType().equals(WorkspaceItemType.SHARED_FOLDER); //IS ROOT?
if (item != null && item.isFolder() && item.isShared()) { // IS A SHARED SUB-FOLDER
if (asRoot) {
return item.getType().equals(WorkspaceItemType.SHARED_FOLDER); // IS ROOT?
}
return true;
}
return false;
}catch(Exception e){
} catch (Exception e) {
logger.error("Error in server isASharedFolder", e);
return false;
}
}
/**
* Gets the readable size by item id.
*
* @param itemId the item id
* @return the readable size by item id
* @throws Exception the exception
*/
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.wsexplorer.client.rpc.WorkspaceExplorerService#getFormattedSizeByItemId(java.lang.String, org.gcube.portlets.widgets.wsexplorer.shared.SizeFormatter)
*/
@ -605,6 +624,15 @@ public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implem
}
}
/**
* Creates the folder.
*
* @param nameFolder the name folder
* @param description the description
* @param parentId the parent id
* @return the item
* @throws Exception the exception
*/
/* (non-Javadoc)
* @see org.gcube.portlets.user.workspaceexplorerapp.client.rpc.WorkspaceExplorerAppService#createFolder(java.lang.String, java.lang.String, java.lang.String)
*/

View File

@ -40,12 +40,11 @@ public class WsUtil {
return new StorageHubWrapper(scope, token, false, false, true);
} catch (Exception e) {
logger.error("Error during getting storageHub wrapper", e);
throw new Exception("Error on inizializing the StorageHub");
logger.error("Error when instancing the storageHub wrapper", e);
throw new Exception("Error on inizializing the StorageHub wrapper");
}
}
/**
* Gets the workpace.
*
@ -64,28 +63,6 @@ public class WsUtil {
}
}
// /**
// * Gets the workspace.
// *
// * @param httpSession the http session
// * @return the workspace
// * @throws InternalErrorException the internal error exception
// * @throws HomeNotFoundException the home not found exception
// * @throws WorkspaceFolderNotFoundException the workspace folder not found
// * exception
// * @throws UserNotFoundException the user not found exception
// */
// public static Workspace getWorkspace(HttpSession httpSession) throws InternalErrorException, HomeNotFoundException,
// WorkspaceFolderNotFoundException, UserNotFoundException {
//// ASLSession session = getASLSession(httpSession);
//
// String scope = getScope(httpSession);
// // GET CONTEXT
// logger.info("Setting scope: " + scope);
// ScopeProvider.instance.set(scope);
// return HomeLibrary.getHomeManagerFactory().getHomeManager().getGuestLogin().getWorkspace();
// }
/**
* Gets the scope.
*

View File

@ -3,10 +3,12 @@
*/
package org.gcube.portlets.user.workspaceexplorerapp.shared;
/**
* The Enum ItemType.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Jun 18, 2015
* @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy)
* Apr 9, 2020
*/
public enum ItemType {