Added getStorageID in order to perform Generate a Public Link
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-explorer@122238 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
6363543af3
commit
031f7d404d
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.widgets.wsexplorer.server;
|
||||
|
||||
|
@ -30,7 +30,7 @@ import org.slf4j.LoggerFactory;
|
|||
* Modified by Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
*/
|
||||
public class ItemBuilder {
|
||||
|
||||
|
||||
public static final Logger _log = LoggerFactory.getLogger(ItemBuilder.class);
|
||||
/**
|
||||
* Purge empty folders.
|
||||
|
@ -41,18 +41,22 @@ public class ItemBuilder {
|
|||
public static Item purgeEmptyFolders(Item item)
|
||||
{
|
||||
//for (Item child:item.getChildren()) purgeEmptyFolders(child); ONLY FIRST LEVEL
|
||||
|
||||
|
||||
List<Item> toRemoveList = new LinkedList<Item>();
|
||||
for (Item child:item.getChildren()) {
|
||||
boolean toRemove = isAnEmptyFolder(child);
|
||||
if (toRemove) toRemoveList.add(child);
|
||||
if (toRemove) {
|
||||
toRemoveList.add(child);
|
||||
}
|
||||
}
|
||||
for (Item child:toRemoveList) item.removeChild(child);
|
||||
|
||||
for (Item child:toRemoveList) {
|
||||
item.removeChild(child);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Checks if is an empty folder.
|
||||
*
|
||||
|
@ -63,7 +67,7 @@ public class ItemBuilder {
|
|||
{
|
||||
return Util.isFolder(item.getType()) && item.getChildren().size() == 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the item.
|
||||
*
|
||||
|
@ -77,44 +81,51 @@ public class ItemBuilder {
|
|||
*/
|
||||
public static Item getItem(Item parent, WorkspaceItem workspaceItem, List<ItemType> showableTypes, FilterCriteria filterCriteria, boolean loadChildren) throws InternalErrorException
|
||||
{
|
||||
|
||||
|
||||
ItemType type = getItemType(workspaceItem);
|
||||
|
||||
if (!showableTypes.contains(type)) return null;
|
||||
if (!filterItem(type, workspaceItem, filterCriteria)) return null;
|
||||
|
||||
|
||||
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);
|
||||
|
||||
//TODO ADD GET PATH WHEN WILL BE MORE FAST
|
||||
Item item = new Item(parent, workspaceItem.getId(), itemName, type, workspaceItem.getPath(), UserUtil.getUserFullName(workspaceItem.getOwner().getPortalLogin()), isFolder, false);
|
||||
|
||||
String storageID = null;
|
||||
if(workspaceItem instanceof FolderItem){
|
||||
storageID = workspaceItem.getStorageID();
|
||||
}
|
||||
Item item = new Item(parent, workspaceItem.getId(), itemName, type, workspaceItem.getPath(), UserUtil.getUserFullName(workspaceItem.getOwner().getPortalLogin()), storageID, isFolder, false);
|
||||
item.setSharedFolder(isSharedFolder);
|
||||
|
||||
|
||||
if(loadChildren){
|
||||
for (WorkspaceItem child: workspaceItem.getChildren()){
|
||||
_log.trace("Converting child item: "+itemName);
|
||||
Item itemChild = getItem(item, child, showableTypes, filterCriteria, false);
|
||||
Item itemChild = getItem(item, child, showableTypes, filterCriteria, false);
|
||||
_log.trace("Item: "+itemName +" converted!!!");
|
||||
if (itemChild!=null){
|
||||
item.addChild(itemChild);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
@ -135,12 +146,12 @@ public class ItemBuilder {
|
|||
return ItemType.FOLDER;
|
||||
}
|
||||
case FOLDER_ITEM: return getFolderItemType((FolderItem) item);
|
||||
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the folder item type.
|
||||
*
|
||||
|
@ -148,7 +159,7 @@ public class ItemBuilder {
|
|||
* @return the folder item type
|
||||
*/
|
||||
protected static ItemType getFolderItemType(FolderItem item){
|
||||
|
||||
|
||||
try{
|
||||
return ItemType.valueOf(item.getFolderItemType().toString());
|
||||
}catch (Exception e) {
|
||||
|
@ -156,7 +167,7 @@ public class ItemBuilder {
|
|||
return ItemType.UNKNOWN_TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Filter item.
|
||||
|
@ -168,18 +179,24 @@ public class ItemBuilder {
|
|||
* @throws InternalErrorException the internal error exception
|
||||
*/
|
||||
protected static boolean filterItem(ItemType type, WorkspaceItem item, FilterCriteria filterCriteria) throws InternalErrorException {
|
||||
if(filterCriteria==null) return true;
|
||||
|
||||
if(filterCriteria==null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean mimeTypeCheck = checkAllowedMimeTypes(type, item, filterCriteria.getAllowedMimeTypes());
|
||||
if (!mimeTypeCheck) return false;
|
||||
|
||||
if (!mimeTypeCheck) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean fileExtensionCheck = checkAllowedFileExtension(type, item, filterCriteria.getAllowedFileExtensions());
|
||||
if(!fileExtensionCheck) return false;
|
||||
|
||||
boolean propertiesCheck = checkProperties(item, filterCriteria.getRequiredProperties());
|
||||
if(!fileExtensionCheck) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean propertiesCheck = checkProperties(item, filterCriteria.getRequiredProperties());
|
||||
return propertiesCheck;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check allowed mime types.
|
||||
*
|
||||
|
@ -189,8 +206,10 @@ public class ItemBuilder {
|
|||
* @return true, if successful
|
||||
*/
|
||||
protected static boolean checkAllowedMimeTypes(ItemType type, WorkspaceItem item, List<String> allowedMimeTypes){
|
||||
if (allowedMimeTypes==null || allowedMimeTypes.size()==0) return true;
|
||||
|
||||
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();
|
||||
|
@ -198,9 +217,9 @@ public class ItemBuilder {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Check allowed file extension.
|
||||
|
@ -211,8 +230,10 @@ public class ItemBuilder {
|
|||
* @return true, if successful
|
||||
*/
|
||||
protected static boolean checkAllowedFileExtension(ItemType type, WorkspaceItem item, List<String> allowedFileExtension){
|
||||
if (allowedFileExtension==null || allowedFileExtension.size()==0) return true;
|
||||
|
||||
if (allowedFileExtension==null || allowedFileExtension.size()==0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
if (type != ItemType.FOLDER) {
|
||||
String name = item.getName();
|
||||
|
@ -224,7 +245,7 @@ public class ItemBuilder {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check file extension.
|
||||
*
|
||||
|
@ -233,27 +254,30 @@ public class ItemBuilder {
|
|||
* @return true, if successful
|
||||
*/
|
||||
protected static boolean checkFileExtension(String fileName, List<String> allowedFileExtension){
|
||||
|
||||
if(fileName==null || fileName.isEmpty()) return false;
|
||||
|
||||
|
||||
if(fileName==null || fileName.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int dot = fileName.lastIndexOf(".");
|
||||
if(dot>=0 && (dot+1)<=fileName.length()){
|
||||
|
||||
if(dot>=0 && dot+1<=fileName.length()){
|
||||
|
||||
String ext = fileName.substring(dot+1, fileName.length());
|
||||
_log.trace("Extension found: "+ext +" for: "+fileName);
|
||||
// if(ext.isEmpty())
|
||||
// return false;
|
||||
for (String fe : allowedFileExtension) {
|
||||
if(ext.compareTo(fe)==0)
|
||||
if(ext.compareTo(fe)==0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
_log.trace("Extension not found for: "+fileName);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Check properties.
|
||||
*
|
||||
|
@ -264,18 +288,24 @@ public class ItemBuilder {
|
|||
*/
|
||||
protected static boolean checkProperties(WorkspaceItem item, Map<String, String> requestedProperties) throws InternalErrorException
|
||||
{
|
||||
if (requestedProperties==null || requestedProperties.size()==0 || item.getType()!=WorkspaceItemType.FOLDER_ITEM) return true;
|
||||
|
||||
if (requestedProperties==null || requestedProperties.size()==0 || item.getType()!=WorkspaceItemType.FOLDER_ITEM) {
|
||||
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 (propertyValue == null) {
|
||||
return false;
|
||||
}
|
||||
if (!propertyValue.equals(requestProperty.getValue())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
@ -287,7 +317,7 @@ public class ItemBuilder {
|
|||
* @throws InternalErrorException the internal error exception
|
||||
*/
|
||||
public static Item buildFolderForBreadcrumbs(WorkspaceFolder wsFolder, Item parent) throws InternalErrorException {
|
||||
|
||||
|
||||
String name = "";
|
||||
boolean isSpecialFolder = false;
|
||||
boolean isRoot = false;
|
||||
|
@ -302,17 +332,19 @@ public class ItemBuilder {
|
|||
}else if(isSpecialFolder(wsFolder)){
|
||||
name = WorkspaceExplorerConstants.VRE_FOLDERS_LABEL;
|
||||
isSpecialFolder = true;
|
||||
}else
|
||||
}
|
||||
else {
|
||||
name = wsFolder.getName();
|
||||
|
||||
}
|
||||
|
||||
//BUILDS A SIMPLE ITEM FOR BREADCRUMB
|
||||
Item item = new Item(null, wsFolder.getId(), name, ItemType.FOLDER, wsFolder.getPath(), null, true, isRoot);
|
||||
Item item = new Item(null, wsFolder.getId(), name, ItemType.FOLDER, wsFolder.getPath(), null, null, true, isRoot);
|
||||
item.setSpecialFolder(isSpecialFolder);
|
||||
|
||||
|
||||
_log.debug("breadcrumb returning: "+item);
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if is special folder.
|
||||
*
|
||||
|
@ -320,9 +352,9 @@ public class ItemBuilder {
|
|||
* @return true, if is special folder
|
||||
*/
|
||||
public static boolean isSpecialFolder(WorkspaceFolder wsFolder){
|
||||
|
||||
|
||||
try {
|
||||
return (wsFolder.getName().compareTo(WorkspaceExplorerConstants.SPECIAL_FOLDERS_NAME)==0 && wsFolder.getParent()!=null && wsFolder.getParent().isRoot());
|
||||
return wsFolder.getName().compareTo(WorkspaceExplorerConstants.SPECIAL_FOLDERS_NAME)==0 && wsFolder.getParent()!=null && wsFolder.getParent().isRoot();
|
||||
} catch (InternalErrorException e) {
|
||||
_log.warn("isSpecialFolder exception, returning false");
|
||||
return false;
|
||||
|
@ -333,7 +365,7 @@ public class ItemBuilder {
|
|||
List<String> allowedFileExtension = new ArrayList<String>();
|
||||
allowedFileExtension.add("csv");
|
||||
allowedFileExtension.add("");
|
||||
|
||||
|
||||
String fileName = "t";
|
||||
System.out.println(checkFileExtension(fileName, allowedFileExtension));
|
||||
}*/
|
||||
|
|
|
@ -42,13 +42,13 @@ import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
|||
public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implements WorkspaceExplorerService {
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public static final Logger _log = LoggerFactory.getLogger(WorkspaceExplorerServiceImpl.class);
|
||||
public static final String USERNAME_ATTRIBUTE = "username";
|
||||
public static final String TEST_USER = "test.user";
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the ASL session.
|
||||
*
|
||||
|
@ -60,9 +60,11 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
|
|||
String user = (String) httpSession.getAttribute(USERNAME_ATTRIBUTE);
|
||||
|
||||
_log.error("WORKSPACE PORTLET SessionID= " + sessionID);
|
||||
|
||||
|
||||
//TODO we check for the older attribute name
|
||||
if (user == null) user = (String) httpSession.getAttribute("user");
|
||||
if (user == null) {
|
||||
user = (String) httpSession.getAttribute("user");
|
||||
}
|
||||
|
||||
if (user == null) {
|
||||
|
||||
|
@ -76,7 +78,10 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
|
|||
session.setScope("/gcube/devsec/devVRE");
|
||||
|
||||
return session;
|
||||
} else _log.trace("user found in session "+user);
|
||||
}
|
||||
else {
|
||||
_log.trace("user found in session "+user);
|
||||
}
|
||||
return SessionManager.getInstance().getASLSession(sessionID, user);
|
||||
}
|
||||
|
||||
|
@ -91,7 +96,7 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
|
|||
*/
|
||||
protected Workspace getWorkspace() throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException {
|
||||
ASLSession session = getASLSession(this.getThreadLocalRequest().getSession());
|
||||
|
||||
|
||||
Workspace workspace = HomeLibrary.getUserWorkspace(session.getUsername());
|
||||
return workspace;
|
||||
}
|
||||
|
@ -102,12 +107,12 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
|
|||
@Override
|
||||
public Item getRoot(List<ItemType> showableTypes, boolean purgeEmpyFolders, FilterCriteria filterCriteria) throws WorkspaceNavigatorServiceException {
|
||||
_log.trace("getRoot showableTypes: "+showableTypes+" purgeEmpyFolders: "+purgeEmpyFolders+" filterCriteria: "+ filterCriteria);
|
||||
|
||||
|
||||
try {
|
||||
|
||||
Workspace workspace = getWorkspace();
|
||||
_log.trace("Start getRoot...");
|
||||
|
||||
|
||||
WorkspaceItem root = workspace.getRoot();
|
||||
|
||||
_log.trace("GetRoot - Replyiing root");
|
||||
|
@ -117,13 +122,15 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
|
|||
Item rootItem = ItemBuilder.getItem(null, root, showableTypes, filterCriteria, true);
|
||||
rootItem.setName(WorkspaceExplorerConstants.HOME_LABEL);
|
||||
rootItem.setIsRoot(true);
|
||||
|
||||
|
||||
/* SPECIAL FOLDERS
|
||||
Item specialFolders = ItemBuilder.getItem(null, specials, showableTypes, filterCriteria, 2);
|
||||
specialFolders.setShared(true);
|
||||
rootItem.addChild(specialFolders);
|
||||
rootItem.addChild(specialFolders);
|
||||
*/
|
||||
if (purgeEmpyFolders) rootItem = ItemBuilder.purgeEmptyFolders(rootItem);
|
||||
if (purgeEmpyFolders) {
|
||||
rootItem = ItemBuilder.purgeEmptyFolders(rootItem);
|
||||
}
|
||||
|
||||
_log.trace("Returning:");
|
||||
Long endTime = System.currentTimeMillis() - startTime;
|
||||
|
@ -132,7 +139,7 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
|
|||
|
||||
Collections.sort(rootItem.getChildren(), new ItemComparator());
|
||||
_log.info("Returning children size: "+rootItem.getChildren().size());
|
||||
|
||||
|
||||
return rootItem;
|
||||
|
||||
} catch (Exception e) {
|
||||
|
@ -159,8 +166,10 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
|
|||
|
||||
Item itemFolder = ItemBuilder.getItem(null, folder, showableTypes, filterCriteria, true);
|
||||
_log.trace("Only showable types:");
|
||||
|
||||
if (purgeEmpyFolders) itemFolder = ItemBuilder.purgeEmptyFolders(itemFolder);
|
||||
|
||||
if (purgeEmpyFolders) {
|
||||
itemFolder = ItemBuilder.purgeEmptyFolders(itemFolder);
|
||||
}
|
||||
|
||||
_log.trace("Returning:");
|
||||
Long endTime = System.currentTimeMillis() - startTime;
|
||||
|
@ -176,7 +185,7 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
|
|||
throw new WorkspaceNavigatorServiceException("Sorry, an error occurred when performing get folder");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.gcube.portlets.widgets.wsexplorer.client.rpc.WorkspaceExplorerService#getItemByCategory(org.gcube.portlets.widgets.wsexplorer.shared.ItemCategory)
|
||||
*/
|
||||
|
@ -186,7 +195,7 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
|
|||
try {
|
||||
Workspace workspace = getWorkspace();
|
||||
Item item = null;
|
||||
|
||||
|
||||
switch(category){
|
||||
case HOME:{
|
||||
WorkspaceItem root = workspace.getRoot();
|
||||
|
@ -197,12 +206,12 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
|
|||
}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(), true, true);
|
||||
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(), WorkspaceExplorerConstants.VRE_FOLDERS_LABEL, ItemType.FOLDER, folder.getPath(), folder.getOwner().getPortalLogin(), true, false);
|
||||
item = new Item(null, folder.getId(), WorkspaceExplorerConstants.VRE_FOLDERS_LABEL, ItemType.FOLDER, folder.getPath(), folder.getOwner().getPortalLogin(), null, true, false);
|
||||
//SET SPECIAL FOLDER /Workspace/MySpecialFolders
|
||||
item.setSpecialFolder(true);
|
||||
break;
|
||||
|
@ -214,7 +223,7 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
|
|||
throw new WorkspaceNavigatorServiceException("Sorry, an error occurred when performing get item by category");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -234,13 +243,15 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
|
|||
//OVERRIDING VRE FOLDERS NAME - SET SPECIAL FOLDER /Workspace/MySpecialFolders
|
||||
itemFolder.setName(WorkspaceExplorerConstants.VRE_FOLDERS_LABEL);
|
||||
itemFolder.setSpecialFolder(true);
|
||||
|
||||
|
||||
_log.trace("Builded MySpecialFolder: "+itemFolder);
|
||||
|
||||
_log.trace("Only showable types:");
|
||||
//printName("", folderItem);
|
||||
|
||||
if (purgeEmpyFolders) itemFolder = ItemBuilder.purgeEmptyFolders(itemFolder);
|
||||
if (purgeEmpyFolders) {
|
||||
itemFolder = ItemBuilder.purgeEmptyFolders(itemFolder);
|
||||
}
|
||||
|
||||
_log.trace("Returning:");
|
||||
|
||||
|
@ -249,7 +260,7 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
|
|||
_log.trace("end time - " + time);
|
||||
|
||||
//printName("", folderItem);
|
||||
|
||||
|
||||
Collections.sort(itemFolder.getChildren(), new ItemComparator());
|
||||
|
||||
return itemFolder;
|
||||
|
@ -284,7 +295,7 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
|
|||
for (Item child:item.getChildren()) printName(indentation+"\t", child);
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
/**
|
||||
* Gets Breadcrumbs (the list of parents) by item identifier.
|
||||
*
|
||||
|
@ -297,49 +308,53 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
|
|||
public List<Item> getBreadcrumbsByItemIdentifier(String itemIdentifier, boolean includeItemAsParent) throws Exception {
|
||||
_log.trace("ListParents By Item Identifier "+ itemIdentifier);
|
||||
try {
|
||||
|
||||
|
||||
Workspace workspace = getWorkspace();
|
||||
WorkspaceItem wsItem = workspace.getItem(itemIdentifier);
|
||||
_log.trace("workspace retrieve item name: "+wsItem.getName());
|
||||
List<WorkspaceItem> parents = workspace.getParentsById(itemIdentifier);
|
||||
List<WorkspaceItem> parents = workspace.getParentsById(itemIdentifier);
|
||||
_log.trace("parents size: "+parents.size());
|
||||
Item[] arrayParents;
|
||||
|
||||
if(includeItemAsParent==true && wsItem.isFolder()){
|
||||
arrayParents = new Item[parents.size()];
|
||||
arrayParents[parents.size()-1] = ItemBuilder.buildFolderForBreadcrumbs((WorkspaceFolder) wsItem, null);
|
||||
}else
|
||||
}
|
||||
else {
|
||||
arrayParents = new Item[parents.size()-1];
|
||||
|
||||
/** HANDLE MY_SPECIAL_FOLDER TO AVOID COMPLETE PATH WORKSPACE/MY_SPECIAL_FOLDER
|
||||
}
|
||||
|
||||
/** HANDLE MY_SPECIAL_FOLDER TO AVOID COMPLETE PATH WORKSPACE/MY_SPECIAL_FOLDER
|
||||
* BUT RETURNING ONLY /MY_SPECIAL_FOLDER
|
||||
*/
|
||||
if(wsItem.isFolder()){
|
||||
if(ItemBuilder.isSpecialFolder((WorkspaceFolder) wsItem))
|
||||
{
|
||||
return new ArrayList<Item>(Arrays.asList(arrayParents));
|
||||
// return listParents;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//CONVERTING PATH
|
||||
_log.trace("converting path from second-last..");
|
||||
for (int i = parents.size()-2; i >= 0; i--) {
|
||||
WorkspaceFolder wsParentFolder = (WorkspaceFolder) parents.get(i);
|
||||
arrayParents[i] = ItemBuilder.buildFolderForBreadcrumbs((WorkspaceFolder) wsParentFolder, null);
|
||||
arrayParents[i] = ItemBuilder.buildFolderForBreadcrumbs(wsParentFolder, null);
|
||||
if(arrayParents[i].isSpecialFolder()){ //SKIP HOME PARENT FOR MY_SPECIAL_FOLDER
|
||||
_log.info("arrayParents index "+i+" is special folder, exit");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//SET PARENTS
|
||||
_log.trace("setting parents..");
|
||||
for(int i=0; i<arrayParents.length-1; i++){
|
||||
|
||||
|
||||
Item parent = arrayParents[i];
|
||||
Item fileModel = arrayParents[i+1];
|
||||
fileModel.setParent(parent);
|
||||
}
|
||||
|
||||
|
||||
_log.trace("ListParents return size: "+arrayParents.length);
|
||||
if(arrayParents[0]==null){ //EXIT BY BREAK IN CASE OF SPECIAL FOLDER
|
||||
List<Item> breadcrumbs = new ArrayList<Item>(arrayParents.length-1);
|
||||
|
@ -347,9 +362,11 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
|
|||
breadcrumbs.add(arrayParents[i]);
|
||||
}
|
||||
return breadcrumbs;
|
||||
}else
|
||||
}
|
||||
else {
|
||||
return new ArrayList<Item>(Arrays.asList(arrayParents));
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
_log.error("Error in get List Parents By Item Identifier ", e);
|
||||
throw new Exception("Sorry, an error occurred during path retrieving!");
|
||||
|
@ -375,19 +392,21 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
|
|||
Workspace workspace = getWorkspace();
|
||||
WorkspaceItem wsItem = workspace.getItem(itemIdentifier);
|
||||
_log.trace("workspace retrieve item name: "+wsItem.getName());
|
||||
List<WorkspaceItem> parents = workspace.getParentsById(itemIdentifier);
|
||||
List<WorkspaceItem> parents = workspace.getParentsById(itemIdentifier);
|
||||
_log.trace("parents size: "+parents.size());
|
||||
Item[] arrayParents;
|
||||
|
||||
if(includeItemAsParent==true && wsItem.isFolder()){
|
||||
arrayParents = new Item[parents.size()];
|
||||
arrayParents[parents.size()-1] = ItemBuilder.buildFolderForBreadcrumbs((WorkspaceFolder) wsItem, null);
|
||||
}else
|
||||
}
|
||||
else {
|
||||
arrayParents = new Item[parents.size()-1];
|
||||
|
||||
}
|
||||
|
||||
parentLimit = parentLimit!=null?parentLimit:"";
|
||||
|
||||
/** HANDLE MY_SPECIAL_FOLDER TO AVOID COMPLETE PATH WORKSPACE/MY_SPECIAL_FOLDER
|
||||
|
||||
/** HANDLE MY_SPECIAL_FOLDER TO AVOID COMPLETE PATH WORKSPACE/MY_SPECIAL_FOLDER
|
||||
* BUT RETURNING ONLY /MY_SPECIAL_FOLDER
|
||||
*/
|
||||
if(wsItem.isFolder()){
|
||||
|
@ -395,19 +414,19 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
|
|||
_log.debug("item id is special folder, returning");
|
||||
return new ArrayList<Item>(Arrays.asList(arrayParents));
|
||||
}
|
||||
|
||||
|
||||
if(itemIdentifier.compareTo(parentLimit)==0){
|
||||
_log.debug("item and parent limit are identical element, returning");
|
||||
return new ArrayList<Item>(Arrays.asList(arrayParents));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//CONVERTING PATH
|
||||
_log.trace("converting path from second-last..");
|
||||
for (int i = parents.size()-2; i >= 0; i--) {
|
||||
WorkspaceFolder wsParentFolder = (WorkspaceFolder) parents.get(i);
|
||||
arrayParents[i] = ItemBuilder.buildFolderForBreadcrumbs((WorkspaceFolder) wsParentFolder, null);
|
||||
arrayParents[i] = ItemBuilder.buildFolderForBreadcrumbs(wsParentFolder, null);
|
||||
if(arrayParents[i].isSpecialFolder()){ //SKIP HOME PARENT FOR MY_SPECIAL_FOLDER
|
||||
_log.info("arrayParents index "+i+" is special folder, break");
|
||||
break;
|
||||
|
@ -416,48 +435,52 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//SET PARENTS
|
||||
_log.trace("setting parents..");
|
||||
for(int i=0; i<arrayParents.length-1; i++){
|
||||
|
||||
|
||||
Item parent = arrayParents[i];
|
||||
Item fileModel = arrayParents[i+1];
|
||||
|
||||
if(fileModel!=null)
|
||||
|
||||
if(fileModel!=null) {
|
||||
fileModel.setParent(parent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
_log.trace("ListParents return size: "+arrayParents.length);
|
||||
if(arrayParents[0]==null){ //EXIT BY BREAK IN CASE OF SPECIAL FOLDER OR REACHED PARENT LIMIT
|
||||
List<Item> breadcrumbs = new ArrayList<Item>();
|
||||
for (int i=1; i<arrayParents.length; i++) {
|
||||
if(arrayParents[i]!=null)
|
||||
if(arrayParents[i]!=null) {
|
||||
breadcrumbs.add(arrayParents[i]);
|
||||
}
|
||||
}
|
||||
return breadcrumbs;
|
||||
}else
|
||||
}
|
||||
else {
|
||||
return new ArrayList<Item>(Arrays.asList(arrayParents));
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
_log.error("Error in get List Parents By Item Identifier ", e);
|
||||
throw new Exception("Sorry, an error occurred during path retrieving!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.gcube.portlets.widgets.wsexplorer.client.rpc.WorkspaceExplorerService#loadSizeByItemId(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public Long getSizeByItemId(String itemId) throws Exception {
|
||||
|
||||
|
||||
_log.info("get Size By ItemId "+ itemId);
|
||||
try {
|
||||
|
||||
|
||||
Workspace workspace = getWorkspace();
|
||||
WorkspaceItem wsItem = workspace.getItem(itemId);
|
||||
Long size = new Long(-1);
|
||||
|
||||
|
||||
if(wsItem instanceof FolderItem){ //ITEM
|
||||
FolderItem folderItem = (FolderItem) wsItem;
|
||||
size = new Long(folderItem.getLength());
|
||||
|
@ -470,30 +493,31 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
|
|||
}
|
||||
_log.info("returning size: " +size);
|
||||
return size;
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
_log.error("get Size By ItemId ", e);
|
||||
throw new Exception(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.gcube.portlets.widgets.wsexplorer.client.rpc.WorkspaceExplorerService#getMimeType(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public String getMimeType(String itemId) throws Exception {
|
||||
|
||||
|
||||
_log.info("get MimeType By ItemId "+ itemId);
|
||||
try {
|
||||
|
||||
|
||||
Workspace workspace = getWorkspace();
|
||||
WorkspaceItem wsItem = workspace.getItem(itemId);
|
||||
|
||||
if(!wsItem.getType().equals(WorkspaceItemType.FOLDER_ITEM))
|
||||
|
||||
if(!wsItem.getType().equals(WorkspaceItemType.FOLDER_ITEM)) {
|
||||
return null;
|
||||
|
||||
FolderItem folderItem = (FolderItem) wsItem;
|
||||
|
||||
}
|
||||
|
||||
FolderItem folderItem = (FolderItem) wsItem;
|
||||
|
||||
return folderItem.getMimeType();
|
||||
|
||||
} catch (Exception e) {
|
||||
|
@ -501,7 +525,7 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
|
|||
throw new Exception(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the user acl for folder id.
|
||||
|
@ -516,18 +540,20 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
|
|||
_log.info("Get user ACL to FOLDER id: "+folderId);
|
||||
Workspace workspace = getWorkspace();
|
||||
WorkspaceItem wsItem = workspace.getItem(folderId);
|
||||
|
||||
if(!isASharedFolder(wsItem, false))
|
||||
|
||||
if(!isASharedFolder(wsItem, false)) {
|
||||
return "OWNER";
|
||||
else //IS A SHARED FOLDER
|
||||
}
|
||||
else {
|
||||
return wsItem.getACLUser().toString();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
_log.error("Error in server get UserACLForFolderId", e);
|
||||
String error = "An error occurred when getting ACL rules for selected folder. "+e.getMessage();
|
||||
throw new Exception(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Checks if is a shared folder.
|
||||
|
@ -538,11 +564,13 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
|
|||
*/
|
||||
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?
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -558,7 +586,7 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
|
|||
*/
|
||||
@Override
|
||||
public String getReadableSizeByItemId(String itemId) throws Exception {
|
||||
|
||||
|
||||
try{
|
||||
_log.info("getFormattedSize ByItemId "+ itemId);
|
||||
long size = getSizeByItemId(itemId);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.widgets.wsexplorer.shared;
|
||||
|
||||
|
@ -28,7 +28,8 @@ public class Item implements IsSerializable {
|
|||
private boolean isSpecialFolder = false;
|
||||
private boolean isSharedFolder = false;
|
||||
private boolean isRoot = false;
|
||||
|
||||
private String storageId;
|
||||
|
||||
/**
|
||||
* Instantiates a new item.
|
||||
*/
|
||||
|
@ -47,6 +48,7 @@ public class Item implements IsSerializable {
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new item.
|
||||
*
|
||||
|
@ -56,20 +58,42 @@ public class Item implements IsSerializable {
|
|||
* @param type the type
|
||||
* @param path the path
|
||||
* @param owner the owner
|
||||
* @param storageId the storage id
|
||||
* @param isFolder the is folder
|
||||
* @param isRoot the is root
|
||||
*/
|
||||
public Item(Item parent, String id, String name, ItemType type, String path, String owner, boolean isFolder, boolean isRoot) {
|
||||
public Item(Item parent, String id, String name, ItemType type, String path, String owner, String storageId, boolean isFolder, boolean isRoot) {
|
||||
this(id, name, isFolder);
|
||||
this.parent = parent;
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.storageId = storageId;
|
||||
this.path = path;
|
||||
this.children = new ArrayList<Item>();
|
||||
this.owner = owner;
|
||||
this.isRoot = isRoot;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the storage id.
|
||||
*
|
||||
* @return the storageId
|
||||
*/
|
||||
public String getStorageId() {
|
||||
|
||||
return storageId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the storage id.
|
||||
*
|
||||
* @param storageId the storageId to set
|
||||
*/
|
||||
public void setStorageId(String storageId) {
|
||||
|
||||
this.storageId = storageId;
|
||||
}
|
||||
/**
|
||||
* Sets the id.
|
||||
*
|
||||
|
@ -78,7 +102,7 @@ public class Item implements IsSerializable {
|
|||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if is root.
|
||||
*
|
||||
|
@ -138,7 +162,7 @@ public class Item implements IsSerializable {
|
|||
|
||||
/**
|
||||
* The item parent. Null if is the root.
|
||||
*
|
||||
*
|
||||
* @return the item parent.
|
||||
*/
|
||||
public Item getParent() {
|
||||
|
@ -147,7 +171,7 @@ public class Item implements IsSerializable {
|
|||
|
||||
/**
|
||||
* The item id.
|
||||
*
|
||||
*
|
||||
* @return the id.
|
||||
*/
|
||||
public String getId() {
|
||||
|
@ -156,7 +180,7 @@ public class Item implements IsSerializable {
|
|||
|
||||
/**
|
||||
* The item name.
|
||||
*
|
||||
*
|
||||
* @return the name.
|
||||
*/
|
||||
public String getName() {
|
||||
|
@ -165,7 +189,7 @@ public class Item implements IsSerializable {
|
|||
|
||||
/**
|
||||
* The item type.
|
||||
*
|
||||
*
|
||||
* @return the type.
|
||||
*/
|
||||
public ItemType getType() {
|
||||
|
@ -174,7 +198,7 @@ public class Item implements IsSerializable {
|
|||
|
||||
/**
|
||||
* The item children.
|
||||
*
|
||||
*
|
||||
* @return the children.
|
||||
*/
|
||||
public ArrayList<Item> getChildren() {
|
||||
|
@ -222,7 +246,7 @@ public class Item implements IsSerializable {
|
|||
|
||||
/**
|
||||
* Add a child to this item.
|
||||
*
|
||||
*
|
||||
* @param child
|
||||
* the child to add.
|
||||
*/
|
||||
|
@ -257,7 +281,7 @@ public class Item implements IsSerializable {
|
|||
public void setSpecialFolder(boolean isSpecialFolder) {
|
||||
this.isSpecialFolder = isSpecialFolder;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the path.
|
||||
*
|
||||
|
@ -274,7 +298,7 @@ public class Item implements IsSerializable {
|
|||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||
result = prime * result + (id == null ? 0 : id.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -283,18 +307,23 @@ public class Item implements IsSerializable {
|
|||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
if (this == obj) {
|
||||
return true;
|
||||
if (obj == null)
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
Item other = (Item) obj;
|
||||
if (id == null) {
|
||||
if (other.id != null)
|
||||
if (other.id != null) {
|
||||
return false;
|
||||
} else if (!id.equals(other.id))
|
||||
}
|
||||
} else if (!id.equals(other.id)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -307,18 +336,14 @@ public class Item implements IsSerializable {
|
|||
public void setParent(Item parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("Item [parent=");
|
||||
builder.append(parent);
|
||||
builder.append(", id=");
|
||||
builder.append("Item [id=");
|
||||
builder.append(id);
|
||||
builder.append(", name=");
|
||||
builder.append(name);
|
||||
|
@ -326,14 +351,20 @@ public class Item implements IsSerializable {
|
|||
builder.append(type);
|
||||
builder.append(", path=");
|
||||
builder.append(path);
|
||||
builder.append(", isSharedFolder=");
|
||||
builder.append(isSharedFolder);
|
||||
builder.append(", children=");
|
||||
builder.append(children);
|
||||
builder.append(", owner=");
|
||||
builder.append(owner);
|
||||
builder.append(", isFolder=");
|
||||
builder.append(isFolder);
|
||||
builder.append(", isSpecialFolder=");
|
||||
builder.append(isSpecialFolder);
|
||||
builder.append(", isSharedFolder=");
|
||||
builder.append(isSharedFolder);
|
||||
builder.append(", isRoot=");
|
||||
builder.append(isRoot);
|
||||
builder.append(", storageId=");
|
||||
builder.append(storageId);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue