@ -12,6 +12,7 @@ import java.util.Map;
import java.util.concurrent.TimeUnit ;
import javax.servlet.ServletContext ;
import javax.servlet.http.HttpSession ;
import org.apache.log4j.Logger ;
import org.gcube.application.framework.core.session.ASLSession ;
@ -40,6 +41,9 @@ import org.gcube.common.homelibrary.home.workspace.search.SearchItem;
import org.gcube.common.homelibrary.home.workspace.trash.WorkspaceTrashFolder ;
import org.gcube.common.homelibrary.home.workspace.trash.WorkspaceTrashItem ;
import org.gcube.common.scope.api.ScopeProvider ;
import org.gcube.datacatalogue.ckanutillibrary.CKanUtilsImpl ;
import org.gcube.datacatalogue.ckanutillibrary.models.CkanRolesIntoLiferay ;
import org.gcube.datacatalogue.ckanutillibrary.models.RolesIntoOrganization ;
import org.gcube.portlets.user.workspace.client.ConstantsExplorer ;
import org.gcube.portlets.user.workspace.client.interfaces.GXTCategoryItemInterface ;
import org.gcube.portlets.user.workspace.client.model.FileDetailsModel ;
@ -79,11 +83,15 @@ import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingEntryTyp
import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingField ;
import org.gcube.portlets.user.workspaceapplicationhandler.ApplicationReaderFromGenericResource ;
import org.gcube.vomanagement.usermanagement.GroupManager ;
import org.gcube.vomanagement.usermanagement.RoleManager ;
import org.gcube.vomanagement.usermanagement.UserManager ;
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException ;
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault ;
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager ;
import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager ;
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager ;
import org.gcube.vomanagement.usermanagement.model.GCubeGroup ;
import org.gcube.vomanagement.usermanagement.model.GCubeRole ;
import org.gcube.vomanagement.usermanagement.model.GCubeUser ;
import com.google.gwt.user.server.rpc.RemoteServiceServlet ;
@ -104,6 +112,25 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
public static final String SELECTION_STATE_ATTRIBUTE = "WORKSPACE.SELECTION_STATE" ;
protected Logger workspaceLogger = Logger . getLogger ( GWTWorkspaceServiceImpl . class ) ;
// for the data catalogue
public static final String CKAN_TOKEN_KEY = "ckanToken" ;
public static final String CKAN_ROLE = "ckanRole" ; // editor, admin, member
// ckan utils methods
private CKanUtilsImpl instance ;
@Override
public void init ( ) {
// retrieve ckan information
try {
String currentScope = ScopeProvider . instance . get ( ) ;
instance = new CKanUtilsImpl ( currentScope ) ;
} catch ( Exception e ) {
workspaceLogger . error ( "Unable to retrieve ckan information" ) ;
}
}
/ * *
* Gets the GWT workspace builder .
*
@ -224,7 +251,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
return gwtroot ;
} catch ( Exception e ) {
workspaceLogger . error ( "Error in server during root retrieving" , e ) ;
// workspaceLogger.trace("Error in server During root retrieving " + e);
// workspaceLogger.trace("Error in server During root retrieving " + e);
//GWT can't serialize all exceptions
throw new Exception ( "Error during workspace loading, please contact the support. Exception:" + e ) ;
@ -245,11 +272,11 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
Workspace workspace = getWorkspace ( ) ;
workspaceLogger . trace ( "on server getRoot for scope: " + scopeId ) ;
// GCUBEScope gcubeScope = null;
//
// if(scopeId.compareTo(ScopeUtilFilter.IDALLSCOPE)!=0){
// gcubeScope = GCUBEScope.getScope(scopeId);
// }
// GCUBEScope gcubeScope = null;
//
// if(scopeId.compareTo(ScopeUtilFilter.IDALLSCOPE)!=0){
// gcubeScope = GCUBEScope.getScope(scopeId);
// }
WorkspaceFolder root = workspace . getRoot ( ) ;
@ -298,7 +325,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
return listFileGridModels ;
} catch ( Exception e ) {
workspaceLogger . error ( "Error in server During search retrieving" , e ) ;
// workspaceLogger.trace("Error in server During search retrieving " + e);
// workspaceLogger.trace("Error in server During search retrieving " + e);
//GWT can't serialize all exceptions
throw new Exception ( "Error during searching, please contact the support." ) ;
@ -354,7 +381,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
} catch ( Exception e ) {
workspaceLogger . error ( "Error in server During item retrieving" , e ) ;
// workspaceLogger.trace("Error in server During item retrieving " + e);
// workspaceLogger.trace("Error in server During item retrieving " + e);
String error = ConstantsExplorer . SERVER_ERROR + RETRIEVING_ITEM_EITHER_ITEM_DOESN_T_EXIST ;
//GWT can't serialize all exceptions
throw new Exception ( error ) ;
@ -409,7 +436,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
workspaceLogger . info ( "Folder is root, loading special folders.." ) ;
WorkspaceFolder specialFolder = workspace . getMySpecialFolders ( ) ;
FileGridModel specialFolderModel = builder . buildGXTFileGridModelItem ( specialFolder , folder ) ;
// specialFolderModel.setShortcutCategory(GXTCategoryItemInterface.SMF_VRE_FOLDERS);
// specialFolderModel.setShortcutCategory(GXTCategoryItemInterface.SMF_VRE_FOLDERS);
specialFolderModel . setSpecialFolder ( true ) ;
String newName = getNameForSpecialFolder ( ) ;
@ -739,7 +766,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
}
else
workspaceLogger . warn ( "Notifies added item: " + destinationItem + "to share doesn't sent because " + destinationSharedFolder + " is not istance of WorkspaceSharedFolder" ) ;
// np.notifyAddedItemToSharing(listContacts, (WorkspaceFolder) folderDestinationItem);
// np.notifyAddedItemToSharing(listContacts, (WorkspaceFolder) folderDestinationItem);
}
}
else
@ -776,7 +803,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
workspaceLogger . trace ( "checkNotifyMoveItemFromShare source item: " + sourceItem . getName ( ) + " sourceSharedId: " + sourceSharedId + " folder destination: " + folderDestinationItem . getName ( ) + " sourceItemIsShared: " + sourceItemIsShared ) ;
// System.out.println("shareChangeCondition remove item: "+ shareChangeCondition);
// System.out.println("shareChangeCondition remove item: "+ shareChangeCondition);
workspaceLogger . trace ( "shareChangeCondition remove item: " + shareChangeCondition ) ;
@ -784,20 +811,20 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
//if source Item is shared and folder destination is not shared or shareChangeCondition is true.. notifies removed item to sharing
if ( sourceItemIsShared & & ( ! folderDestinationItem . isShared ( ) | | shareChangeCondition ) ) {
//get contacts
List < InfoContactModel > listContacts = getListUserSharedByFolderSharedId ( sourceSharedId ) ;
//get contacts
List < InfoContactModel > listContacts = getListUserSharedByFolderSharedId ( sourceSharedId ) ;
//DEBUG
printContacts ( listContacts ) ;
Workspace workspace = getWorkspace ( ) ;
WorkspaceItem sourceSharedFolder = workspace . getItem ( sourceSharedId ) ;
NotificationsProducer np = getNotificationProducer ( ) ;
//DEBUG
printContacts ( listContacts ) ;
Workspace workspace = getWorkspace ( ) ;
WorkspaceItem sourceSharedFolder = workspace . getItem ( sourceSharedId ) ;
NotificationsProducer np = getNotificationProducer ( ) ;
if ( sourceSharedFolder instanceof WorkspaceSharedFolder ) {
np . notifyMovedItemToSharing ( listContacts , sourceItem , ( WorkspaceSharedFolder ) sourceSharedFolder ) ;
workspaceLogger . trace ( "The notifies was sent correctly" ) ;
} else
workspaceLogger . warn ( "Notifies moved item: " + sourceItem + "from share doesn't sent because " + sourceSharedFolder + " is not istance of WorkspaceSharedFolder" ) ;
if ( sourceSharedFolder instanceof WorkspaceSharedFolder ) {
np . notifyMovedItemToSharing ( listContacts , sourceItem , ( WorkspaceSharedFolder ) sourceSharedFolder ) ;
workspaceLogger . trace ( "The notifies was sent correctly" ) ;
} else
workspaceLogger . warn ( "Notifies moved item: " + sourceItem + "from share doesn't sent because " + sourceSharedFolder + " is not istance of WorkspaceSharedFolder" ) ;
}
} else
@ -819,7 +846,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
workspaceLogger . trace ( "Contacts:" ) ;
for ( InfoContactModel infoContactModel : listContacts ) {
workspaceLogger . trace ( "User: " + infoContactModel ) ;
workspaceLogger . trace ( "User: " + infoContactModel ) ;
}
}
@ -1072,10 +1099,10 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
//Category IMAGES
if ( category . equals ( GXTCategoryItemInterface . SMF_IMAGES . toString ( ) ) ) {
listWorkspaceItems = workspace . getFolderItems ( FolderItemType . IMAGE_DOCUMENT , FolderItemType . EXTERNAL_IMAGE ) ;
//Category BIODIVERSITY
//Category BIODIVERSITY
} else if ( category . equals ( GXTCategoryItemInterface . SMF_BIODIVERSITY . toString ( ) ) ) {
// listWorkspaceItems = workspace.getFolderItems(FolderItemType.AQUAMAPS_ITEM);
//Category DOCUMENTS
// listWorkspaceItems = workspace.getFolderItems(FolderItemType.AQUAMAPS_ITEM);
//Category DOCUMENTS
} else if ( category . equals ( GXTCategoryItemInterface . SMF_DOCUMENTS . toString ( ) ) ) {
listWorkspaceItems = workspace . getFolderItems (
@ -1087,13 +1114,13 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
FolderItemType . DOCUMENT
) ;
//Category LINKS
//Category LINKS
} else if ( category . equals ( GXTCategoryItemInterface . SMF_LINKS . toString ( ) ) ) {
// listWorkspaceItems = workspace.getFolderItems(FolderItemType.EXTERNAL_URL, FolderItemType.URL_DOCUMENT, FolderItemType.EXTERNAL_RESOURCE_LINK);
//Category REPORTS
// listWorkspaceItems = workspace.getFolderItems(FolderItemType.EXTERNAL_URL, FolderItemType.URL_DOCUMENT, FolderItemType.EXTERNAL_RESOURCE_LINK);
//Category REPORTS
} else if ( category . equals ( GXTCategoryItemInterface . SMF_REPORTS . toString ( ) ) ) {
listWorkspaceItems = workspace . getFolderItems ( FolderItemType . REPORT_TEMPLATE , FolderItemType . REPORT ) ;
//Category TIME SERIES
//Category TIME SERIES
} else if ( category . equals ( GXTCategoryItemInterface . SMF_TIMESERIES . toString ( ) ) ) {
listWorkspaceItems = workspace . getFolderItems ( FolderItemType . TIME_SERIES ) ;
}
@ -1120,22 +1147,22 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
* /
private void getListsChildrenByParent ( ArrayList < SubTree > listSubTree , WorkspaceItem parent ) throws Exception {
if ( parent = = null )
return ;
if ( parent = = null )
return ;
if ( ! parent . isFolder ( ) ) {
workspaceLogger . warn ( "getListsChildrenByParent returning: " + parent . getName ( ) + " is not a folder" ) ;
return ;
}
if ( ! parent . isFolder ( ) ) {
workspaceLogger . warn ( "getListsChildrenByParent returning: " + parent . getName ( ) + " is not a folder" ) ;
return ;
}
workspaceLogger . trace ( "getListsChildrenByParent: " + parent . getName ( ) ) ;
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
FolderModel parentModel = ( FolderModel ) builder . buildGXTFileModelItem ( parent , null ) ; //get folder
workspaceLogger . trace ( "getListsChildrenByParent: " + parent . getName ( ) ) ;
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
FolderModel parentModel = ( FolderModel ) builder . buildGXTFileModelItem ( parent , null ) ; //get folder
List < FileModel > childrenList = getFolderChildren ( parentModel ) ; //get children
SubTree subTree = new SubTree ( parentModel , childrenList ) ;
listSubTree . add ( subTree ) ;
getListsChildrenByParent ( listSubTree , parent . getParent ( ) ) ;
}
listSubTree . add ( subTree ) ;
getListsChildrenByParent ( listSubTree , parent . getParent ( ) ) ;
}
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # createSmartFolder ( java . lang . String , java . lang . String , java . lang . String )
@ -1163,7 +1190,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
} catch ( Exception e ) {
workspaceLogger . error ( "Error in server create smart folder by name: " , e ) ;
// workspaceLogger.trace("Error in server create smart folder by id " + e);
// workspaceLogger.trace("Error in server create smart folder by id " + e);
//GWT can't serialize all exceptions
throw new Exception ( e . getMessage ( ) ) ;
}
@ -1316,7 +1343,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
} catch ( Exception e ) {
workspaceLogger . error ( "Error in server get image by id " , e ) ;
// workspaceLogger.trace("Error in server get image by id " + e);
// workspaceLogger.trace("Error in server get image by id " + e);
//GWT can't serialize all exceptions
throw new Exception ( e . getMessage ( ) ) ;
}
@ -1328,7 +1355,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
@Override
public FileModel createExternalUrl ( FileModel parentFileModel , String name , String description , String url ) throws Exception {
try {
try {
Workspace workspace = getWorkspace ( ) ;
if ( parentFileModel = = null )
@ -1337,12 +1364,12 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
workspaceLogger . trace ( "create url in parent id: " + parentFileModel . getIdentifier ( ) ) ;
//DEBUG
// workspaceLogger.trace("Name " + name);
// workspaceLogger.trace("description " + description);
// workspaceLogger.trace("url " + url);
// workspaceLogger.trace("parentFileModel " + parentFileModel.getIdentifier() + " " + parentFileModel.getName());
// if(description == null)
// description = "";
// workspaceLogger.trace("Name " + name);
// workspaceLogger.trace("description " + description);
// workspaceLogger.trace("url " + url);
// workspaceLogger.trace("parentFileModel " + parentFileModel.getIdentifier() + " " + parentFileModel.getName());
// if(description == null)
// description = "";
ExternalUrl ext = workspace . createExternalUrl ( name , description , url , parentFileModel . getIdentifier ( ) ) ;
WorkspaceItem parent = workspace . getItem ( parentFileModel . getIdentifier ( ) ) ; //get item from workspace
@ -1352,7 +1379,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
} catch ( Exception e ) {
workspaceLogger . error ( "Error in server create url in parent id " , e ) ;
// workspaceLogger.trace("Error in server create url in parent id " + e);
// workspaceLogger.trace("Error in server create url in parent id " + e);
//GWT can't serialize all exceptions
throw new Exception ( e . getMessage ( ) ) ;
}
@ -1449,7 +1476,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
} catch ( Exception e ) {
workspaceLogger . error ( "Error in server get all scope " , e ) ;
e . printStackTrace ( ) ;
// workspaceLogger.trace("Error in server get all scope " + e.getMessage());
// workspaceLogger.trace("Error in server get all scope " + e.getMessage());
//GWT can't serialize all exceptions
throw new Exception ( e . getMessage ( ) ) ;
}
@ -1479,13 +1506,13 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
listContactsModel . add ( contact ) ;
}
// //TEST USERS
// listContactsModel.add(new InfoContactModel("antonio.gioia", "antonio.gioia", "Antonio Gioia",false));
// listContactsModel.add(new InfoContactModel("fabio.sinibaldi", "fabio.sinibaldi", "Fabio Sinibaldi",false));
// listContactsModel.add(new InfoContactModel("pasquale.pagano", "pasquale.pagano", "Pasquale Pagano",false));
// listContactsModel.add(new InfoContactModel(WsUtil.TEST_USER, WsUtil.TEST_USER, WsUtil.TEST_USER_FULL_NAME,false));
// listContactsModel.add(new InfoContactModel("francesco.mangiacrapa", "francesco.mangiacrapa", "Francesco Mangiacrapa",false));
// listContactsModel.add(new InfoContactModel("massimiliano.assante", "massimiliano.assante", "Massimiliano Assante",false));
// //TEST USERS
// listContactsModel.add(new InfoContactModel("antonio.gioia", "antonio.gioia", "Antonio Gioia",false));
// listContactsModel.add(new InfoContactModel("fabio.sinibaldi", "fabio.sinibaldi", "Fabio Sinibaldi",false));
// listContactsModel.add(new InfoContactModel("pasquale.pagano", "pasquale.pagano", "Pasquale Pagano",false));
// listContactsModel.add(new InfoContactModel(WsUtil.TEST_USER, WsUtil.TEST_USER, WsUtil.TEST_USER_FULL_NAME,false));
// listContactsModel.add(new InfoContactModel("francesco.mangiacrapa", "francesco.mangiacrapa", "Francesco Mangiacrapa",false));
// listContactsModel.add(new InfoContactModel("massimiliano.assante", "massimiliano.assante", "Massimiliano Assante",false));
workspaceLogger . trace ( "Home Library User Manager getting list Gcube Group" ) ;
listContactsModel . addAll ( builder . buildGXTListContactsModelFromGcubeGroup ( hlUserManager . getGroups ( ) ) ) ;
@ -1510,7 +1537,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
} catch ( Exception e ) {
workspaceLogger . error ( "Error in server get all contacts " , e ) ;
// return new ArrayList<InfoContactModel>();
// return new ArrayList<InfoContactModel>();
throw new Exception ( e . getMessage ( ) ) ;
}
}
@ -1524,9 +1551,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
try {
Workspace workspace = getWorkspace ( ) ;
// workspaceLogger.trace("######### SEND TO: ");
// workspaceLogger.trace("subject " + subject);
// workspaceLogger.trace("body " + body);
// workspaceLogger.trace("######### SEND TO: ");
// workspaceLogger.trace("subject " + subject);
// workspaceLogger.trace("body " + body);
//DEBUG
for ( String contactId : listContactsId )
@ -1670,7 +1697,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
} catch ( Exception e ) {
workspaceLogger . error ( "Error in getNewFolderBulkCreator " , e ) ;
// workspaceLogger.trace("Error in getNewFolderBulkCreator " + e.getMessage());
// workspaceLogger.trace("Error in getNewFolderBulkCreator " + e.getMessage());
throw new Exception ( e . getMessage ( ) ) ;
}
}
@ -1714,7 +1741,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
sharedFolder = workspace . shareFolder ( listLogin , folder . getIdentifier ( ) ) ;
sharedFolder . setDescription ( folder . getDescription ( ) ) ; //SET NEW DESCRIPTION
//USER REMOVED FROM SHARE
//USER REMOVED FROM SHARE
DifferenceBetweenInfoContactModel diff2 = new DifferenceBetweenInfoContactModel ( listSharedContact , listContacts ) ;
List < InfoContactModel > listRemovedUsersFromShare = diff2 . getDifferentsContacts ( ) ;
workspaceLogger . info ( "List removed user from share has size: " + listRemovedUsersFromShare . size ( ) ) ;
@ -1746,7 +1773,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
if ( ! sourceFolderIsShared ) //if source folder is not already shared
np . notifyFolderSharing ( listContacts , sharedFolder ) ;
else {
// printContacts(listContacts);
// printContacts(listContacts);
np . notifyUpdatedUsersToSharing ( listSharedContact , listContacts , sharedFolder ) ;
}
}
@ -1948,7 +1975,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
FolderModel root = builder . buildGXTFolderModelItemHandleSpecialFolder ( wsFolder , null , nameSpecialFolder ) ;
List < FileModel > listParents = new ArrayList < FileModel > ( 1 ) ;
listParents . add ( root ) ;
// workspaceLogger.trace("returning: "+listParents.toString());
// workspaceLogger.trace("returning: "+listParents.toString());
return listParents ;
}
else {
@ -1969,7 +1996,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
listParents . add ( root ) ;
if ( parent ! = null )
listParents . add ( parent ) ;
// workspaceLogger.trace("returning: "+listParents.toString());
// workspaceLogger.trace("returning: "+listParents.toString());
return listParents ;
default :
@ -2002,8 +2029,8 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
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);
// 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 ) ;
@ -2409,10 +2436,10 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
garbage . put ( itemId , new GarbageItem ( sourceItemIsShared , itemName , itemId , sourceFolderSharedId ) ) ;
// workspace.removeItem(itemId);
// //IF SOURCE SHARED FOLDER IS NOT NULL
// if(sourceFolderSharedId!=null)
// NotificationsUtil.checkSendNotifyRemoveItemToShare(this.getThreadLocalRequest().getSession(), sourceItemIsShared, itemName, itemId, sourceFolderSharedId);
// workspace.removeItem(itemId);
// //IF SOURCE SHARED FOLDER IS NOT NULL
// if(sourceFolderSharedId!=null)
// NotificationsUtil.checkSendNotifyRemoveItemToShare(this.getThreadLocalRequest().getSession(), sourceItemIsShared, itemName, itemId, sourceFolderSharedId);
}
//ITEM ID - ERROR
@ -2483,14 +2510,14 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
//IS ROOT SHARED FOLDER
ite = ( WorkspaceSharedFolder ) wsItem ;
workspaceLogger . trace ( "Folder " + ite . getName ( ) + " is a " + WorkspaceSharedFolder . class . getName ( ) ) ;
// ite = (WorkspaceSharedFolder) workspace.getItemByPath(wsItem.getPath());
// ite = (WorkspaceSharedFolder) workspace.getItemByPath(wsItem.getPath());
} else {
// IS SUB FOLDER OF THE SHARING
ite = ( WorkspaceFolder ) wsItem ;
workspaceLogger . trace ( "Folder " + ite . getName ( ) + " is a " + WorkspaceFolder . class . getName ( ) ) ;
// ite = (WorkspaceSharedFolder) workspace.getItem(wsItem.getIdSharedFolder());
// ite = (WorkspaceSharedFolder) workspace.getItem(wsItem.getIdSharedFolder());
}
// validateACLToUser(ite, listLogins, aclType);
// validateACLToUser(ite, listLogins, aclType);
ite . setACL ( listLogins , ACLType . valueOf ( aclType ) ) ;
} else
throw new Exception ( "Source item is not shared or shared folder" ) ;
@ -2661,18 +2688,18 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
if ( isWithinPortal ( ) & & username . compareTo ( WsUtil . TEST_USER ) ! = 0 ) {
try {
LiferayUserManager l = new LiferayUserManager ( ) ;
GCubeUser user = l . getUserByUsername ( username ) ;
firstName = user . getFirstName ( ) ;
lastName = user . getLastName ( ) ;
email = user . getEmail ( ) ;
} catch ( UserManagementSystemException e ) {
workspaceLogger . error ( "UserManagementSystemException for username: " + username ) ;
}
catch ( UserRetrievalFault e ) {
workspaceLogger . error ( "UserRetrievalFault for username: " + username ) ;
}
try {
LiferayUserManager l = new LiferayUserManager ( ) ;
GCubeUser user = l . getUserByUsername ( username ) ;
firstName = user . getFirstName ( ) ;
lastName = user . getLastName ( ) ;
email = user . getEmail ( ) ;
} catch ( UserManagementSystemException e ) {
workspaceLogger . error ( "UserManagementSystemException for username: " + username ) ;
}
catch ( UserRetrievalFault e ) {
workspaceLogger . error ( "UserRetrievalFault for username: " + username ) ;
}
}
return new UserBean ( username , firstName , lastName , email ) ;
@ -2810,7 +2837,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
workspaceLogger . trace ( "Get SharedFolderForId: folder id " + folderId + " is shared" ) ;
//TODO REMOVE wsItem.getIdSharedFolder()
// WorkspaceSharedFolder wsFolder = (WorkspaceSharedFolder) workspace.getItem(wsItem.getIdSharedFolder());
// WorkspaceSharedFolder wsFolder = (WorkspaceSharedFolder) workspace.getItem(wsItem.getIdSharedFolder());
WorkspaceFolder wsFolder = ( WorkspaceFolder ) wsItem ;
if ( wsFolder ! = null ) {
@ -2927,18 +2954,18 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
switch ( operation ) {
case EMPTY_TRASH :
listErrors = trash . emptyTrash ( ) ;
break ;
case EMPTY_TRASH :
listErrors = trash . emptyTrash ( ) ;
break ;
case RESTORE_ALL :
listErrors = trash . restoreAll ( ) ;
break ;
case RESTORE_ALL :
listErrors = trash . restoreAll ( ) ;
break ;
case REFRESH :
default :
result . setTrashContent ( builder . buildGXTListTrashContent ( trash ) ) ;
return result ;
case REFRESH :
default :
result . setTrashContent ( builder . buildGXTListTrashContent ( trash ) ) ;
return result ;
}
trash = workspace . getTrash ( ) ;
@ -2987,66 +3014,66 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
switch ( operation ) {
case DELETE_PERMANENTLY : {
boolean deleted = false ;
for ( String trashItemId : listTrashItemIds ) {
try {
WorkspaceTrashItem trashItem = trash . getTrashItemById ( trashItemId ) ;
if ( trashItem ! = null ) {
trashItem . deletePermanently ( ) ;
listUpdatedTrashIds . add ( trashItemId ) ;
deleted = true ;
}
case DELETE_PERMANENTLY : {
} catch ( Exception e ) {
workspaceLogger . warn ( "Error on DELETE_PERMANENTLY the item : " + trashItemId , e ) ;
FileTrashedModel fakeFile = new FileTrashedModel ( ) ;
fakeFile . setIdentifier ( trashItemId ) ;
listContentError . add ( fakeFile ) ;
boolean deleted = false ;
for ( String trashItemId : listTrashItemIds ) {
try {
WorkspaceTrashItem trashItem = trash . getTrashItemById ( trashItemId ) ;
if ( trashItem ! = null ) {
trashItem . deletePermanently ( ) ;
listUpdatedTrashIds . add ( trashItemId ) ;
deleted = true ;
}
}
String label = listTrashItemIds . size ( ) > 1 ? "items" : "item" ;
if ( ! deleted )
throw new Exception ( "Sorry, an error occurred on deleting permanently the trash " + label + ", try again" ) ;
break ;
} catch ( Exception e ) {
workspaceLogger . warn ( "Error on DELETE_PERMANENTLY the item : " + trashItemId , e ) ;
FileTrashedModel fakeFile = new FileTrashedModel ( ) ;
fakeFile . setIdentifier ( trashItemId ) ;
listContentError . add ( fakeFile ) ;
}
}
case RESTORE : {
String label = listTrashItemIds . size ( ) > 1 ? "items" : "item" ;
if ( ! deleted )
throw new Exception ( "Sorry, an error occurred on deleting permanently the trash " + label + ", try again" ) ;
boolean restored = false ;
for ( String trashItemId : listTrashItemIds ) {
try {
WorkspaceTrashItem trashItem = trash . getTrashItemById ( trashItemId ) ;
if ( trashItem ! = null ) {
trashItem . restore ( ) ;
listUpdatedTrashIds . add ( trashItemId ) ;
restored = true ;
}
break ;
}
case RESTORE : {
} catch ( Exception e ) {
workspaceLogger . warn ( "Error on RESTORE the item : " + trashItemId , e ) ;
FileTrashedModel fakeFile = new FileTrashedModel ( ) ;
fakeFile . setIdentifier ( trashItemId ) ;
listContentError . add ( fakeFile ) ;
boolean restored = false ;
for ( String trashItemId : listTrashItemIds ) {
try {
WorkspaceTrashItem trashItem = trash . getTrashItemById ( trashItemId ) ;
if ( trashItem ! = null ) {
trashItem . restore ( ) ;
listUpdatedTrashIds . add ( trashItemId ) ;
restored = true ;
}
} catch ( Exception e ) {
workspaceLogger . warn ( "Error on RESTORE the item : " + trashItemId , e ) ;
FileTrashedModel fakeFile = new FileTrashedModel ( ) ;
fakeFile . setIdentifier ( trashItemId ) ;
listContentError . add ( fakeFile ) ;
}
String label = listTrashItemIds . size ( ) > 1 ? "items" : "item" ;
}
String label = listTrashItemIds . size ( ) > 1 ? "items" : "item" ;
if ( ! restored )
throw new Exception ( "Sorry, an error occurred on restoring the trash " + label + ", try again" ) ;
if ( ! restored )
throw new Exception ( "Sorry, an error occurred on restoring the trash " + label + ", try again" ) ;
break ;
}
break ;
}
default :
break ;
}
// trash = workspace.getTrash();
// result.setTrashContent(builder.buildGXTListTrashContent(trash));
// trash = workspace.getTrash();
// result.setTrashContent(builder.buildGXTListTrashContent(trash));
if ( ! listContentError . isEmpty ( ) ) {
result . setListErrors ( listContentError ) ;
@ -3259,7 +3286,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
workspaceLogger . info ( "Getting workspace size.." ) ;
Workspace workspace = getWorkspace ( ) ;
long size = workspace . getDiskUsage ( ) ;
// workspaceLogger.info("Root size is: "+size +" formatting..");
// workspaceLogger.info("Root size is: "+size +" formatting..");
String formatSize = GWTWorkspaceBuilder . formatFileSize ( size ) ;
workspaceLogger . info ( "returning workspace size: " + formatSize ) ;
return formatSize ;
@ -3388,4 +3415,132 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
throw new Exception ( error ) ;
}
}
@Override
public boolean hasUserRoleAdminOrEditor ( ) {
ASLSession asl = WsUtil . getAslSession ( this . getThreadLocalRequest ( ) . getSession ( ) ) ;
String username = asl . getUsername ( ) ;
// check if this information was already into the ASL Session
String role = ( String ) asl . getAttribute ( CKAN_ROLE ) ;
if ( role ! = null )
switch ( role ) {
case "editor" :
case "admin" : return true ;
default : return false ; // member
}
try {
if ( ! isWithinPortal ( ) ) {
workspaceLogger . warn ( "OUT FROM PORTAL DETECTED RETURNING TRUE" ) ;
asl . setAttribute ( CKAN_ROLE , "editor" ) ;
return true ;
}
// first of all, check if the user is a sysadmin in the catalog (in this case he can do everything)
boolean isSysAdmin = instance . isSysAdmin ( username , getUserCKanTokenFromSession ( ) ) ;
if ( isSysAdmin ) {
workspaceLogger . debug ( "The user is a sysadmin of the catalog -> he can edit/add" ) ;
asl . setAttribute ( CKAN_ROLE , "admin" ) ;
return true ;
} else {
// retrieve the liferay's roles for the user
UserManager userManager = new LiferayUserManager ( ) ;
RoleManager roleManager = new LiferayRoleManager ( ) ;
GroupManager groupManager = new LiferayGroupManager ( ) ;
// we need to iterate over vres
List < GCubeGroup > groups = groupManager . listGroups ( ) ;
for ( GCubeGroup gCubeGroup : groups ) {
String groupName = gCubeGroup . getGroupName ( ) ;
// skip if it is not a vre
if ( ! groupManager . isVRE ( gCubeGroup . getGroupId ( ) ) )
continue ;
List < GCubeRole > roles = roleManager . listRolesByUserAndGroup ( userManager . getUserId ( username ) , groupManager . getGroupId ( groupName ) ) ;
// the default one
RolesIntoOrganization correspondentRoleToCheck = RolesIntoOrganization . MEMBER ;
String roleToSetInSession = null ;
// NOTE: it is supposed that there is just one role for this person correspondent to the one in the catalog
for ( GCubeRole gCubeRole : roles ) {
workspaceLogger . debug ( "User " + username + " has role " + gCubeRole . getRoleName ( ) + " in " + groupName ) ;
if ( gCubeRole . getRoleName ( ) . equalsIgnoreCase ( CkanRolesIntoLiferay . CATALOG_ADMIN . toString ( ) ) ) {
correspondentRoleToCheck = RolesIntoOrganization . ADMIN ;
roleToSetInSession = "admin" ;
break ;
} else if ( gCubeRole . getRoleName ( ) . equalsIgnoreCase ( CkanRolesIntoLiferay . CATALOG_EDITOR . toString ( ) ) ) {
correspondentRoleToCheck = RolesIntoOrganization . EDITOR ;
roleToSetInSession = "editor" ;
break ;
}
}
// if the role is member, keep continuing
if ( correspondentRoleToCheck . equals ( RolesIntoOrganization . MEMBER ) )
continue ;
// with this invocation, we check if the role is present in ckan and if it is not it will be added
boolean res = instance . checkRole ( username , groupName , correspondentRoleToCheck ) ;
// set the role in the asl session
if ( res ) {
}
return res ;
}
}
} catch ( Exception e ) {
workspaceLogger . error ( "Unable to retrieve the role information for this user. Returning FALSE" , e ) ;
}
workspaceLogger . debug ( "Unable to check the role into ckan organization, returning FALSE" ) ;
// set the role member into the asl
asl . setAttribute ( CKAN_ROLE , "member" ) ;
// return false
return false ;
}
/ * *
* Get current user ' s token .
*
* @return String the ckan user ' s token
* /
private String getUserCKanTokenFromSession ( ) {
HttpSession httpSession = this . getThreadLocalRequest ( ) . getSession ( ) ;
ASLSession session = WsUtil . getAslSession ( httpSession ) ;
String username = session . getUsername ( ) ;
workspaceLogger . debug ( "User in session is " + username ) ;
String token = null ;
if ( this . getThreadLocalRequest ( ) . getSession ( ) . getAttribute ( CKAN_TOKEN_KEY ) ! = null )
token = ( String ) this . getThreadLocalRequest ( ) . getSession ( ) . getAttribute ( CKAN_TOKEN_KEY ) ;
else {
token = instance . getApiKeyFromUsername ( username ) ;
this . getThreadLocalRequest ( ) . getSession ( ) . setAttribute ( CKAN_TOKEN_KEY , token ) ;
workspaceLogger . debug ( "Ckan token has been set for user " + username ) ;
}
workspaceLogger . debug ( "Found ckan token " + token + " for user " + username ) ;
return token ;
}
}