moved get list of parents from HL to SHUB
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@179057 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
12a5803750
commit
16bcb87124
|
@ -11,6 +11,7 @@ import org.gcube.portlets.user.workspace.client.resources.Resources;
|
|||
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel;
|
||||
|
||||
import com.extjs.gxt.ui.client.data.BaseModelData;
|
||||
import com.google.gwt.user.client.rpc.IsSerializable;
|
||||
import com.google.gwt.user.client.ui.AbstractImagePrototype;
|
||||
import com.google.gwt.user.client.ui.Image;
|
||||
|
||||
|
@ -22,7 +23,7 @@ import com.google.gwt.user.client.ui.Image;
|
|||
* @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
||||
* Sep 15, 2016
|
||||
*/
|
||||
public class FileModel extends BaseModelData implements Serializable {
|
||||
public class FileModel extends BaseModelData implements Serializable, IsSerializable {
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
|
@ -7,7 +7,6 @@ import java.io.File;
|
|||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
|
@ -1169,125 +1168,6 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list parents by item identifier.
|
||||
*
|
||||
* @param itemIdentifier
|
||||
* the item identifier
|
||||
* @param includeItemAsParent
|
||||
* - if parameter is true and item passed in input is a folder,
|
||||
* the folder is included in path returned as last parent
|
||||
* @return the list parents by item identifier
|
||||
* @throws Exception
|
||||
* the exception
|
||||
*/
|
||||
@Override
|
||||
public List<FileModel> getListParentsByItemIdentifier(String itemIdentifier, boolean includeItemAsParent)
|
||||
throws Exception {
|
||||
|
||||
workspaceLogger.debug("get List Parents By Item Identifier " + itemIdentifier
|
||||
+ ", include Item As (Last) Parent: " + includeItemAsParent);
|
||||
|
||||
if (isSessionExpired())
|
||||
throw new SessionExpiredException();
|
||||
|
||||
if (itemIdentifier == null)
|
||||
return new ArrayList<FileModel>(); // empty list
|
||||
|
||||
try {
|
||||
|
||||
Workspace workspace = getWorkspace();
|
||||
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder();
|
||||
List<WorkspaceItem> parents = workspace.getParentsById(itemIdentifier);
|
||||
workspaceLogger.debug("parents returned by HL, size: " + parents.size());
|
||||
String nameSpecialFolder = getNameForSpecialFolder();
|
||||
|
||||
switch (parents.size()) {
|
||||
case 0: // itemIdentifier is ROOT
|
||||
workspaceLogger.trace("itemIdentifier isRoot...");
|
||||
if (includeItemAsParent) { // ADDIND ROOT
|
||||
WorkspaceFolder wsFolder = (WorkspaceFolder) workspace.getItem(itemIdentifier);
|
||||
FolderModel root = builder.buildGXTFolderModelItemHandleSpecialFolder(wsFolder, null,
|
||||
nameSpecialFolder);
|
||||
List<FileModel> listParents = new ArrayList<FileModel>(1);
|
||||
listParents.add(root);
|
||||
// workspaceLogger.trace("returning:
|
||||
// "+listParents.toString());
|
||||
return listParents;
|
||||
} else {
|
||||
workspaceLogger.trace("returning empty list");
|
||||
return new ArrayList<FileModel>(); // empty list
|
||||
}
|
||||
|
||||
case 1: // itemIdentifier is first level from root
|
||||
workspaceLogger.trace("itemIdentifier is first level...");
|
||||
List<FileModel> listParents = new ArrayList<FileModel>();
|
||||
WorkspaceFolder wsRootFolder = (WorkspaceFolder) parents.get(0); // isRoot
|
||||
FolderModel root = builder.buildGXTFolderModelItemHandleSpecialFolder(wsRootFolder, null,
|
||||
nameSpecialFolder);
|
||||
FolderModel parent = null;
|
||||
if (includeItemAsParent) {
|
||||
WorkspaceFolder wsFolder1 = (WorkspaceFolder) workspace.getItem(itemIdentifier); // root
|
||||
parent = builder.buildGXTFolderModelItemHandleSpecialFolder(wsFolder1, null, nameSpecialFolder);
|
||||
}
|
||||
listParents.add(root);
|
||||
if (parent != null)
|
||||
listParents.add(parent);
|
||||
// workspaceLogger.trace("returning: "+listParents.toString());
|
||||
return listParents;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
WorkspaceItem lastItem = parents.get(parents.size() - 1);
|
||||
FileModel[] arrayParents;
|
||||
|
||||
// CONVERTING LAST ELEMENT IF NECESSARY
|
||||
workspaceLogger.trace("converting last element..");
|
||||
if (includeItemAsParent && lastItem.isFolder()) { // FIX BUG #298
|
||||
arrayParents = new FileModel[parents.size()];
|
||||
workspaceLogger.debug("including last item into path: " + lastItem.getName());
|
||||
arrayParents[parents.size() - 1] = builder.buildGXTFolderModelItemHandleSpecialFolder(
|
||||
(WorkspaceFolder) lastItem, null, nameSpecialFolder);
|
||||
} else
|
||||
arrayParents = new FileModel[parents.size() - 1];
|
||||
|
||||
// CONVERTING PATH
|
||||
workspaceLogger.trace("converting path from second-last..");
|
||||
for (int i = parents.size() - 2; i >= 0; i--) {
|
||||
WorkspaceFolder wsFolder = (WorkspaceFolder) parents.get(i);
|
||||
arrayParents[i] = builder.buildGXTFolderModelItemHandleSpecialFolder(wsFolder, null, nameSpecialFolder);
|
||||
}
|
||||
|
||||
// SET PARENTS
|
||||
workspaceLogger.trace("setting parents..");
|
||||
for (int i = 0; i < arrayParents.length - 1; i++) {
|
||||
FileModel parent = arrayParents[i];
|
||||
FileModel fileModel = arrayParents[i + 1];
|
||||
fileModel.setParentFileModel(parent);
|
||||
}
|
||||
// workspaceLogger.trace("list parents returning size:
|
||||
// "+arrayParents.length);
|
||||
// return new ArrayList<FileModel>(Arrays.asList(arrayParents));
|
||||
workspaceLogger.trace("list parents returning size: " + arrayParents.length);
|
||||
if (arrayParents[0] == null) { // EXIT BY BREAK IN CASE OF SPECIAL
|
||||
// FOLDER
|
||||
List<FileModel> breadcrumbs = new ArrayList<FileModel>(arrayParents.length - 1);
|
||||
for (int i = 1; i < arrayParents.length; i++) {
|
||||
breadcrumbs.add(arrayParents[i]);
|
||||
}
|
||||
return breadcrumbs;
|
||||
} else
|
||||
return new ArrayList<FileModel>(Arrays.asList(arrayParents));
|
||||
|
||||
} catch (Exception e) {
|
||||
workspaceLogger.error("Error in get List Parents By Item Identifier ", e);
|
||||
e.printStackTrace();
|
||||
throw new Exception(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
|
@ -2784,8 +2664,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
|||
try {
|
||||
|
||||
String vreFolderId = shWorkspace.getVREFoldersId();
|
||||
org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem baseVREFolder = shWorkspace
|
||||
.getItem(vreFolderId);
|
||||
org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem baseVREFolder = shWorkspace.getItem(vreFolderId);
|
||||
FileGridModel specialFolderModel = converter.toGridFileModel(baseVREFolder, folder);
|
||||
|
||||
specialFolderModel.setSpecialFolder(true);
|
||||
|
@ -3765,5 +3644,103 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
|||
throw new Exception(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the list parents by item identifier.
|
||||
*
|
||||
* @param itemIdentifier
|
||||
* the item identifier
|
||||
* @param includeItemAsParent
|
||||
* - if parameter is true and item passed in input is a folder,
|
||||
* the folder is included in path returned as last parent
|
||||
* @return the list parents by item identifier
|
||||
* @throws Exception
|
||||
* the exception
|
||||
*/
|
||||
@Override
|
||||
public List<FileModel> getListParentsByItemIdentifier(String itemIdentifier, boolean includeItemAsParent)
|
||||
throws Exception {
|
||||
|
||||
workspaceLogger.debug("get List Parents by SHUB for id " + itemIdentifier
|
||||
+ ", include Item As (Last) Parent: " + includeItemAsParent);
|
||||
|
||||
if (isSessionExpired())
|
||||
throw new SessionExpiredException();
|
||||
|
||||
if (itemIdentifier == null)
|
||||
return new ArrayList<FileModel>(); // empty list
|
||||
|
||||
try {
|
||||
|
||||
org.gcube.common.storagehubwrapper.server.tohl.Workspace workspace = getWorkspaceFromStorageHub();
|
||||
StorageHubToWorkpaceConverter converter = getStorageHubToWorkpaceConverter();
|
||||
List<? extends org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem> parents = workspace.getParentsById(itemIdentifier);
|
||||
workspaceLogger.info("The Parents returned by SHUB are: " + parents.size());
|
||||
if(workspaceLogger.isTraceEnabled()) {
|
||||
workspaceLogger.trace("They are: ");
|
||||
for (org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem workspaceItem : parents) {
|
||||
workspaceLogger.trace(workspaceItem.getName());
|
||||
}
|
||||
}
|
||||
|
||||
if(parents.size()==0) {
|
||||
//IT IS THE ROOT
|
||||
workspaceLogger.info("The item id "+itemIdentifier+" is the root, returning empty list");
|
||||
return new ArrayList<FileModel>(1);
|
||||
}
|
||||
|
||||
String nameSpecialFolder = getNameForSpecialFolder();
|
||||
|
||||
List<FileModel> arrayParents = new ArrayList<FileModel>(parents.size());
|
||||
//loop from last to first index of list of parents
|
||||
int lastIndex = parents.size()-1;
|
||||
for (int i=lastIndex; i>=0; i--) {
|
||||
org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem wsFolder = parents.get(i);
|
||||
workspaceLogger.trace("Adding the item "+ wsFolder.getName()+" at index "+i+" to list of parent");
|
||||
org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem parent = null;
|
||||
if(i<lastIndex) {
|
||||
parent = parents.get(i+1);
|
||||
workspaceLogger.trace("Passing the item "+ parent.getName()+" as parent of "+wsFolder.getName()+". Is it right?");
|
||||
}
|
||||
arrayParents.add(converter.buildGXTFolderModelItemHandleSpecialFolder(wsFolder, parent, nameSpecialFolder));
|
||||
workspaceLogger.trace("Added "+ wsFolder.getName()+" as parent to index "+(arrayParents.size()-1));
|
||||
}
|
||||
|
||||
if(includeItemAsParent) {
|
||||
org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem theItem = workspace.getItem(itemIdentifier);
|
||||
if(theItem.isFolder()) {
|
||||
workspaceLogger.trace("The item passed is a folder, including it as last parent as requested");
|
||||
FolderModel passedFolder = converter.buildGXTFolderModelItemHandleSpecialFolder(theItem, parents.get(parents.size()), nameSpecialFolder);
|
||||
arrayParents.add(passedFolder);
|
||||
}
|
||||
}
|
||||
|
||||
// SET PARENTS
|
||||
workspaceLogger.trace("setting parents..");
|
||||
for (int i=0; i < arrayParents.size()-1; i++) {
|
||||
FileModel parent = arrayParents.get(i);
|
||||
FileModel fileModel = arrayParents.get(i+1);
|
||||
fileModel.setParentFileModel(parent);
|
||||
}
|
||||
|
||||
workspaceLogger.trace("list parents returning size: " + arrayParents.size());
|
||||
//IS THIS CHECK ALREADY NEEDED?
|
||||
if (arrayParents.get(0) == null) { // EXIT BY BREAK IN CASE OF SPECIAL FOLDER
|
||||
List<FileModel> breadcrumbs = new ArrayList<FileModel>(arrayParents.size() - 1);
|
||||
for (int i = 1; i < arrayParents.size(); i++) {
|
||||
breadcrumbs.add(arrayParents.get(i));
|
||||
}
|
||||
return breadcrumbs;
|
||||
} else
|
||||
return arrayParents;
|
||||
|
||||
} catch (Exception e) {
|
||||
workspaceLogger.error("Error in get List Parents By Item Identifier ", e);
|
||||
e.printStackTrace();
|
||||
throw new Exception(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -10,11 +10,14 @@ import java.util.List;
|
|||
|
||||
import org.apache.log4j.Logger;
|
||||
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.exceptions.InternalErrorException;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.impl.WorkspaceFileVersion;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.items.PropertyMap;
|
||||
import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status;
|
||||
import org.gcube.portal.wssynclibrary.thredds.WorkspaceThreddsSynchronize;
|
||||
import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
|
||||
import org.gcube.portlets.user.workspace.client.model.FileGridModel;
|
||||
import org.gcube.portlets.user.workspace.client.model.FileModel;
|
||||
import org.gcube.portlets.user.workspace.client.model.FileTrashedModel;
|
||||
|
@ -246,6 +249,64 @@ public class StorageHubToWorkpaceConverter implements Serializable{
|
|||
|
||||
return new InfoContactModel(portalLogin, portalLogin, UserUtil.getUserFullName(portalLogin), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO ********TEMPORARY SOLUTION HL MUST MANAGE SPECIAL FOLDER AS WORKSPACESPECIALFOLDER****
|
||||
* REMOVE THIS METHOD AND ADDING INSTANCE OF AT buildGXTFolderModelItem.
|
||||
*
|
||||
* @param wsFolder the ws folder
|
||||
* @param parent the parent
|
||||
* @param specialFolderName the special folder name
|
||||
* @return the folder model
|
||||
* @throws InternalErrorException the internal error exception
|
||||
*/
|
||||
public FolderModel buildGXTFolderModelItemHandleSpecialFolder(org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem wsFolder, org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem parent, String specialFolderName) throws InternalErrorException {
|
||||
|
||||
String name = "";
|
||||
|
||||
logger.debug("buildGXTFolderModelItemHandleSpecialFolder to folder: "+wsFolder.getName());
|
||||
if(logger.isTraceEnabled()) {
|
||||
logger.trace("buildGXTFolderModelItemHandleSpecialFolder has parent: "+parent);
|
||||
}
|
||||
//MANAGEMENT SHARED FOLDER NAME
|
||||
if(wsFolder.isShared() && wsFolder.getType().equals(WorkspaceItemType.SHARED_FOLDER)){
|
||||
logger.debug("MANAGEMENT SHARED Folder name..");
|
||||
WorkspaceSharedFolder shared = (WorkspaceSharedFolder) wsFolder;
|
||||
logger.debug("shared.isVreFolder(): "+shared.isVreFolder());
|
||||
//name = shared.isVreFolder()?shared.getName():wsFolder.getName();
|
||||
name = shared.getName();
|
||||
|
||||
//MANAGEMENT SPECIAL FOLDER
|
||||
}else if(wsFolder.getName().compareTo(ConstantsExplorer.MY_SPECIAL_FOLDERS)==0 && parent!=null && parent.isRoot()){
|
||||
//MANAGEMENT SPECIAL FOLDER
|
||||
logger.debug("MANAGEMENT SPECIAL FOLDER NAME REWRITING AS: "+specialFolderName);
|
||||
if(specialFolderName!=null && !specialFolderName.isEmpty())
|
||||
name = specialFolderName;
|
||||
else
|
||||
name = wsFolder.getName();
|
||||
}else{
|
||||
logger.debug("MANAGEMENT Base Folder name..");
|
||||
name = wsFolder.getName();
|
||||
}
|
||||
|
||||
logger.debug("Name is: "+name);
|
||||
boolean isPublicDir = ((org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder) wsFolder).isPublicFolder(); //TODO
|
||||
FileModel parentModel = null;
|
||||
if(parent!=null)
|
||||
parentModel = ObjectStorageHubToWorkpaceMapper.toTreeFileModelItem(parent, null, parent.isShared());
|
||||
|
||||
FolderModel folder = new FolderModel(wsFolder.getId(), name, parentModel, true, wsFolder.isShared(), false, isPublicDir);
|
||||
folder.setShareable(true);
|
||||
folder.setIsRoot(wsFolder.isRoot());
|
||||
folder.setDescription(wsFolder.getDescription());
|
||||
// folder.setOwner(wsFolder.getOwner());
|
||||
|
||||
if(parent != null && parent.isShared()){
|
||||
folder.setShared(true);
|
||||
folder.setShareable(false);
|
||||
}
|
||||
return folder;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue