Started working on ckan data catalogue publish mechanism. Server side is almost complete

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@129324 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-06-22 16:41:51 +00:00
parent 43f7a97989
commit 1c4985b38a
4 changed files with 331 additions and 156 deletions

20
pom.xml
View File

@ -55,12 +55,12 @@
<!-- This dependency is needed to use GWT UI BInder without old Xerces <!-- This dependency is needed to use GWT UI BInder without old Xerces
version of gCore complaining --> version of gCore complaining -->
<!-- <dependency> --> <!-- <dependency> -->
<!-- <groupId>xerces</groupId> --> <!-- <groupId>xerces</groupId> -->
<!-- <artifactId>xercesImpl</artifactId> --> <!-- <artifactId>xercesImpl</artifactId> -->
<!-- <version>2.9.1</version> --> <!-- <version>2.9.1</version> -->
<!-- <scope>provided</scope> --> <!-- <scope>provided</scope> -->
<!-- </dependency> --> <!-- </dependency> -->
<!-- Google Web Toolkit (GWT) --> <!-- Google Web Toolkit (GWT) -->
<dependency> <dependency>
@ -223,6 +223,14 @@
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version> <version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
</dependency> </dependency>
<!-- Metadata publisher widget -->
<dependency>
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>ckan-metadata-publisher-widget</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
<scope>compile</scope>
</dependency>
<!-- JSON PARSER --> <!-- JSON PARSER -->
<dependency> <dependency>
<groupId>org.json</groupId> <groupId>org.json</groupId>

View File

@ -694,4 +694,11 @@ public interface GWTWorkspaceService extends RemoteService{
FileModel getItemForFileTree(String itemId) throws Exception; FileModel getItemForFileTree(String itemId) throws Exception;
/**
* Allows the user to public onto the data catalogue if he has at least
* the role editor somewhere.
* @return true if he can publish, false otherwise
*/
boolean hasUserRoleAdminOrEditor();
} }

View File

@ -248,7 +248,7 @@ public interface GWTWorkspaceServiceAsync {
*/ */
void getAllContacts(AsyncCallback<List<InfoContactModel>> callback); void getAllContacts(AsyncCallback<List<InfoContactModel>> callback);
// void sendTo(List<InfoContactModel> listContacts, List<FileModel> listAttachments, String subject, String text, AsyncCallback<Boolean> callback); // void sendTo(List<InfoContactModel> listContacts, List<FileModel> listAttachments, String subject, String text, AsyncCallback<Boolean> callback);
/** /**
* Send to by id. * Send to by id.
@ -683,6 +683,11 @@ public interface GWTWorkspaceServiceAsync {
void setGcubeItemProperties(String itemId, Map<String, String> properties, void setGcubeItemProperties(String itemId, Map<String, String> properties,
AsyncCallback<Void> callback); AsyncCallback<Void> callback);
/**
* Allows the user to public onto the data catalogue if he has at least
* the role editor somewhere.
* @return true if he can publish, false otherwise
*/
void hasUserRoleAdminOrEditor(AsyncCallback<Boolean> callback);
} }

View File

@ -12,6 +12,7 @@ import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.gcube.application.framework.core.session.ASLSession; 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.WorkspaceTrashFolder;
import org.gcube.common.homelibrary.home.workspace.trash.WorkspaceTrashItem; import org.gcube.common.homelibrary.home.workspace.trash.WorkspaceTrashItem;
import org.gcube.common.scope.api.ScopeProvider; 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.ConstantsExplorer;
import org.gcube.portlets.user.workspace.client.interfaces.GXTCategoryItemInterface; import org.gcube.portlets.user.workspace.client.interfaces.GXTCategoryItemInterface;
import org.gcube.portlets.user.workspace.client.model.FileDetailsModel; 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.workspace.shared.accounting.GxtAccountingField;
import org.gcube.portlets.user.workspaceapplicationhandler.ApplicationReaderFromGenericResource; import org.gcube.portlets.user.workspaceapplicationhandler.ApplicationReaderFromGenericResource;
import org.gcube.vomanagement.usermanagement.GroupManager; import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.RoleManager;
import org.gcube.vomanagement.usermanagement.UserManager; import org.gcube.vomanagement.usermanagement.UserManager;
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault; import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager; 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.impl.LiferayUserManager;
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
import org.gcube.vomanagement.usermanagement.model.GCubeRole;
import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import com.google.gwt.user.server.rpc.RemoteServiceServlet; 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"; public static final String SELECTION_STATE_ATTRIBUTE = "WORKSPACE.SELECTION_STATE";
protected Logger workspaceLogger = Logger.getLogger(GWTWorkspaceServiceImpl.class); 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. * Gets the GWT workspace builder.
* *
@ -224,7 +251,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
return gwtroot; return gwtroot;
} catch (Exception e) { } catch (Exception e) {
workspaceLogger.error("Error in server during root retrieving", 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 //GWT can't serialize all exceptions
throw new Exception("Error during workspace loading, please contact the support. Exception:" +e); 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(); Workspace workspace = getWorkspace();
workspaceLogger.trace("on server getRoot for scope: " + scopeId); workspaceLogger.trace("on server getRoot for scope: " + scopeId);
// GCUBEScope gcubeScope = null; // GCUBEScope gcubeScope = null;
// //
// if(scopeId.compareTo(ScopeUtilFilter.IDALLSCOPE)!=0){ // if(scopeId.compareTo(ScopeUtilFilter.IDALLSCOPE)!=0){
// gcubeScope = GCUBEScope.getScope(scopeId); // gcubeScope = GCUBEScope.getScope(scopeId);
// } // }
WorkspaceFolder root = workspace.getRoot(); WorkspaceFolder root = workspace.getRoot();
@ -298,7 +325,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
return listFileGridModels; return listFileGridModels;
} catch (Exception e) { } catch (Exception e) {
workspaceLogger.error("Error in server During search retrieving", 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 //GWT can't serialize all exceptions
throw new Exception("Error during searching, please contact the support."); throw new Exception("Error during searching, please contact the support.");
@ -354,7 +381,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
} catch (Exception e) { } catch (Exception e) {
workspaceLogger.error("Error in server During item retrieving", 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; String error = ConstantsExplorer.SERVER_ERROR + RETRIEVING_ITEM_EITHER_ITEM_DOESN_T_EXIST;
//GWT can't serialize all exceptions //GWT can't serialize all exceptions
throw new Exception(error); throw new Exception(error);
@ -409,7 +436,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
workspaceLogger.info("Folder is root, loading special folders.."); workspaceLogger.info("Folder is root, loading special folders..");
WorkspaceFolder specialFolder = workspace.getMySpecialFolders(); WorkspaceFolder specialFolder = workspace.getMySpecialFolders();
FileGridModel specialFolderModel = builder.buildGXTFileGridModelItem(specialFolder, folder); FileGridModel specialFolderModel = builder.buildGXTFileGridModelItem(specialFolder, folder);
// specialFolderModel.setShortcutCategory(GXTCategoryItemInterface.SMF_VRE_FOLDERS); // specialFolderModel.setShortcutCategory(GXTCategoryItemInterface.SMF_VRE_FOLDERS);
specialFolderModel.setSpecialFolder(true); specialFolderModel.setSpecialFolder(true);
String newName = getNameForSpecialFolder(); String newName = getNameForSpecialFolder();
@ -739,7 +766,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
} }
else else
workspaceLogger.warn("Notifies added item: "+destinationItem+ "to share doesn't sent because "+destinationSharedFolder+" is not istance of WorkspaceSharedFolder"); 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 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); 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); 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 source Item is shared and folder destination is not shared or shareChangeCondition is true.. notifies removed item to sharing
if(sourceItemIsShared && (!folderDestinationItem.isShared() || shareChangeCondition)){ if(sourceItemIsShared && (!folderDestinationItem.isShared() || shareChangeCondition)){
//get contacts //get contacts
List<InfoContactModel> listContacts = getListUserSharedByFolderSharedId(sourceSharedId); List<InfoContactModel> listContacts = getListUserSharedByFolderSharedId(sourceSharedId);
//DEBUG //DEBUG
printContacts(listContacts); printContacts(listContacts);
Workspace workspace = getWorkspace(); Workspace workspace = getWorkspace();
WorkspaceItem sourceSharedFolder = workspace.getItem(sourceSharedId); WorkspaceItem sourceSharedFolder = workspace.getItem(sourceSharedId);
NotificationsProducer np = getNotificationProducer(); NotificationsProducer np = getNotificationProducer();
if(sourceSharedFolder instanceof WorkspaceSharedFolder){ if(sourceSharedFolder instanceof WorkspaceSharedFolder){
np.notifyMovedItemToSharing(listContacts, sourceItem, (WorkspaceSharedFolder) sourceSharedFolder); np.notifyMovedItemToSharing(listContacts, sourceItem, (WorkspaceSharedFolder) sourceSharedFolder);
workspaceLogger.trace("The notifies was sent correctly"); workspaceLogger.trace("The notifies was sent correctly");
}else }else
workspaceLogger.warn("Notifies moved item: "+sourceItem+ "from share doesn't sent because "+sourceSharedFolder+" is not istance of WorkspaceSharedFolder"); workspaceLogger.warn("Notifies moved item: "+sourceItem+ "from share doesn't sent because "+sourceSharedFolder+" is not istance of WorkspaceSharedFolder");
} }
}else }else
@ -819,7 +846,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
workspaceLogger.trace("Contacts:"); workspaceLogger.trace("Contacts:");
for (InfoContactModel infoContactModel : listContacts) { 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 //Category IMAGES
if(category.equals(GXTCategoryItemInterface.SMF_IMAGES.toString())){ if(category.equals(GXTCategoryItemInterface.SMF_IMAGES.toString())){
listWorkspaceItems = workspace.getFolderItems(FolderItemType.IMAGE_DOCUMENT, FolderItemType.EXTERNAL_IMAGE); listWorkspaceItems = workspace.getFolderItems(FolderItemType.IMAGE_DOCUMENT, FolderItemType.EXTERNAL_IMAGE);
//Category BIODIVERSITY //Category BIODIVERSITY
}else if(category.equals(GXTCategoryItemInterface.SMF_BIODIVERSITY.toString())){ }else if(category.equals(GXTCategoryItemInterface.SMF_BIODIVERSITY.toString())){
// listWorkspaceItems = workspace.getFolderItems(FolderItemType.AQUAMAPS_ITEM); // listWorkspaceItems = workspace.getFolderItems(FolderItemType.AQUAMAPS_ITEM);
//Category DOCUMENTS //Category DOCUMENTS
}else if(category.equals(GXTCategoryItemInterface.SMF_DOCUMENTS.toString())){ }else if(category.equals(GXTCategoryItemInterface.SMF_DOCUMENTS.toString())){
listWorkspaceItems = workspace.getFolderItems( listWorkspaceItems = workspace.getFolderItems(
@ -1087,13 +1114,13 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
FolderItemType.DOCUMENT FolderItemType.DOCUMENT
); );
//Category LINKS //Category LINKS
}else if(category.equals(GXTCategoryItemInterface.SMF_LINKS.toString())){ }else if(category.equals(GXTCategoryItemInterface.SMF_LINKS.toString())){
// listWorkspaceItems = workspace.getFolderItems(FolderItemType.EXTERNAL_URL, FolderItemType.URL_DOCUMENT, FolderItemType.EXTERNAL_RESOURCE_LINK); // listWorkspaceItems = workspace.getFolderItems(FolderItemType.EXTERNAL_URL, FolderItemType.URL_DOCUMENT, FolderItemType.EXTERNAL_RESOURCE_LINK);
//Category REPORTS //Category REPORTS
}else if(category.equals(GXTCategoryItemInterface.SMF_REPORTS.toString())){ }else if(category.equals(GXTCategoryItemInterface.SMF_REPORTS.toString())){
listWorkspaceItems = workspace.getFolderItems(FolderItemType.REPORT_TEMPLATE, FolderItemType.REPORT); listWorkspaceItems = workspace.getFolderItems(FolderItemType.REPORT_TEMPLATE, FolderItemType.REPORT);
//Category TIME SERIES //Category TIME SERIES
}else if(category.equals(GXTCategoryItemInterface.SMF_TIMESERIES.toString())){ }else if(category.equals(GXTCategoryItemInterface.SMF_TIMESERIES.toString())){
listWorkspaceItems = workspace.getFolderItems(FolderItemType.TIME_SERIES); 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{ private void getListsChildrenByParent(ArrayList<SubTree> listSubTree, WorkspaceItem parent) throws Exception{
if(parent==null) if(parent==null)
return; return;
if(!parent.isFolder()){ if(!parent.isFolder()){
workspaceLogger.warn("getListsChildrenByParent returning: "+parent.getName() +" is not a folder"); workspaceLogger.warn("getListsChildrenByParent returning: "+parent.getName() +" is not a folder");
return; return;
} }
workspaceLogger.trace("getListsChildrenByParent: "+parent.getName()); workspaceLogger.trace("getListsChildrenByParent: "+parent.getName());
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder(); GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder();
FolderModel parentModel = (FolderModel) builder.buildGXTFileModelItem(parent, null); //get folder FolderModel parentModel = (FolderModel) builder.buildGXTFileModelItem(parent, null); //get folder
List<FileModel> childrenList = getFolderChildren(parentModel); //get children List<FileModel> childrenList = getFolderChildren(parentModel); //get children
SubTree subTree = new SubTree(parentModel, childrenList); SubTree subTree = new SubTree(parentModel, childrenList);
listSubTree.add(subTree); listSubTree.add(subTree);
getListsChildrenByParent(listSubTree, parent.getParent()); getListsChildrenByParent(listSubTree, parent.getParent());
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#createSmartFolder(java.lang.String, java.lang.String, java.lang.String) * @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) { } catch (Exception e) {
workspaceLogger.error("Error in server create smart folder by name: ", 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 //GWT can't serialize all exceptions
throw new Exception(e.getMessage()); throw new Exception(e.getMessage());
} }
@ -1316,7 +1343,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
} catch (Exception e) { } catch (Exception e) {
workspaceLogger.error("Error in server get image by id ", 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 //GWT can't serialize all exceptions
throw new Exception(e.getMessage()); throw new Exception(e.getMessage());
} }
@ -1328,7 +1355,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
@Override @Override
public FileModel createExternalUrl(FileModel parentFileModel, String name, String description, String url) throws Exception { public FileModel createExternalUrl(FileModel parentFileModel, String name, String description, String url) throws Exception {
try { try {
Workspace workspace = getWorkspace(); Workspace workspace = getWorkspace();
if(parentFileModel==null) if(parentFileModel==null)
@ -1337,12 +1364,12 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
workspaceLogger.trace("create url in parent id: "+parentFileModel.getIdentifier()); workspaceLogger.trace("create url in parent id: "+parentFileModel.getIdentifier());
//DEBUG //DEBUG
// workspaceLogger.trace("Name " + name); // workspaceLogger.trace("Name " + name);
// workspaceLogger.trace("description " + description); // workspaceLogger.trace("description " + description);
// workspaceLogger.trace("url " + url); // workspaceLogger.trace("url " + url);
// workspaceLogger.trace("parentFileModel " + parentFileModel.getIdentifier() + " " + parentFileModel.getName()); // workspaceLogger.trace("parentFileModel " + parentFileModel.getIdentifier() + " " + parentFileModel.getName());
// if(description == null) // if(description == null)
// description = ""; // description = "";
ExternalUrl ext = workspace.createExternalUrl(name, description, url, parentFileModel.getIdentifier()); ExternalUrl ext = workspace.createExternalUrl(name, description, url, parentFileModel.getIdentifier());
WorkspaceItem parent = workspace.getItem(parentFileModel.getIdentifier()); //get item from workspace WorkspaceItem parent = workspace.getItem(parentFileModel.getIdentifier()); //get item from workspace
@ -1352,7 +1379,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
} catch (Exception e) { } catch (Exception e) {
workspaceLogger.error("Error in server create url in parent id ", 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 //GWT can't serialize all exceptions
throw new Exception(e.getMessage()); throw new Exception(e.getMessage());
} }
@ -1449,7 +1476,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
} catch (Exception e) { } catch (Exception e) {
workspaceLogger.error("Error in server get all scope ", e); workspaceLogger.error("Error in server get all scope ", e);
e.printStackTrace(); 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 //GWT can't serialize all exceptions
throw new Exception(e.getMessage()); throw new Exception(e.getMessage());
} }
@ -1479,13 +1506,13 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
listContactsModel.add(contact); listContactsModel.add(contact);
} }
// //TEST USERS // //TEST USERS
// listContactsModel.add(new InfoContactModel("antonio.gioia", "antonio.gioia", "Antonio Gioia",false)); // 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("fabio.sinibaldi", "fabio.sinibaldi", "Fabio Sinibaldi",false));
// listContactsModel.add(new InfoContactModel("pasquale.pagano", "pasquale.pagano", "Pasquale Pagano",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(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("francesco.mangiacrapa", "francesco.mangiacrapa", "Francesco Mangiacrapa",false));
// listContactsModel.add(new InfoContactModel("massimiliano.assante", "massimiliano.assante", "Massimiliano Assante",false)); // listContactsModel.add(new InfoContactModel("massimiliano.assante", "massimiliano.assante", "Massimiliano Assante",false));
workspaceLogger.trace("Home Library User Manager getting list Gcube Group"); workspaceLogger.trace("Home Library User Manager getting list Gcube Group");
listContactsModel.addAll(builder.buildGXTListContactsModelFromGcubeGroup(hlUserManager.getGroups())); listContactsModel.addAll(builder.buildGXTListContactsModelFromGcubeGroup(hlUserManager.getGroups()));
@ -1510,7 +1537,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
} catch (Exception e) { } catch (Exception e) {
workspaceLogger.error("Error in server get all contacts ", e); workspaceLogger.error("Error in server get all contacts ", e);
// return new ArrayList<InfoContactModel>(); // return new ArrayList<InfoContactModel>();
throw new Exception(e.getMessage()); throw new Exception(e.getMessage());
} }
} }
@ -1524,9 +1551,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
try { try {
Workspace workspace = getWorkspace(); Workspace workspace = getWorkspace();
// workspaceLogger.trace("######### SEND TO: "); // workspaceLogger.trace("######### SEND TO: ");
// workspaceLogger.trace("subject " + subject); // workspaceLogger.trace("subject " + subject);
// workspaceLogger.trace("body " + body); // workspaceLogger.trace("body " + body);
//DEBUG //DEBUG
for(String contactId : listContactsId) for(String contactId : listContactsId)
@ -1670,7 +1697,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
} catch (Exception e) { } catch (Exception e) {
workspaceLogger.error("Error in getNewFolderBulkCreator ", 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()); throw new Exception(e.getMessage());
} }
} }
@ -1714,7 +1741,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
sharedFolder = workspace.shareFolder(listLogin, folder.getIdentifier()); sharedFolder = workspace.shareFolder(listLogin, folder.getIdentifier());
sharedFolder.setDescription(folder.getDescription()); //SET NEW DESCRIPTION sharedFolder.setDescription(folder.getDescription()); //SET NEW DESCRIPTION
//USER REMOVED FROM SHARE //USER REMOVED FROM SHARE
DifferenceBetweenInfoContactModel diff2 = new DifferenceBetweenInfoContactModel(listSharedContact, listContacts); DifferenceBetweenInfoContactModel diff2 = new DifferenceBetweenInfoContactModel(listSharedContact, listContacts);
List<InfoContactModel> listRemovedUsersFromShare = diff2.getDifferentsContacts(); List<InfoContactModel> listRemovedUsersFromShare = diff2.getDifferentsContacts();
workspaceLogger.info("List removed user from share has size: "+listRemovedUsersFromShare.size()); 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 if(!sourceFolderIsShared) //if source folder is not already shared
np.notifyFolderSharing(listContacts, sharedFolder); np.notifyFolderSharing(listContacts, sharedFolder);
else{ else{
// printContacts(listContacts); // printContacts(listContacts);
np.notifyUpdatedUsersToSharing(listSharedContact, listContacts, sharedFolder); np.notifyUpdatedUsersToSharing(listSharedContact, listContacts, sharedFolder);
} }
} }
@ -1948,7 +1975,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
FolderModel root = builder.buildGXTFolderModelItemHandleSpecialFolder(wsFolder, null, nameSpecialFolder); FolderModel root = builder.buildGXTFolderModelItemHandleSpecialFolder(wsFolder, null, nameSpecialFolder);
List<FileModel> listParents = new ArrayList<FileModel>(1); List<FileModel> listParents = new ArrayList<FileModel>(1);
listParents.add(root); listParents.add(root);
// workspaceLogger.trace("returning: "+listParents.toString()); // workspaceLogger.trace("returning: "+listParents.toString());
return listParents; return listParents;
} }
else{ else{
@ -1969,7 +1996,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
listParents.add(root); listParents.add(root);
if(parent!=null) if(parent!=null)
listParents.add(parent); listParents.add(parent);
// workspaceLogger.trace("returning: "+listParents.toString()); // workspaceLogger.trace("returning: "+listParents.toString());
return listParents; return listParents;
default: default:
@ -2002,8 +2029,8 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
FileModel fileModel = arrayParents[i+1]; FileModel fileModel = arrayParents[i+1];
fileModel.setParentFileModel(parent); fileModel.setParentFileModel(parent);
} }
// workspaceLogger.trace("list parents returning size: "+arrayParents.length); // workspaceLogger.trace("list parents returning size: "+arrayParents.length);
// return new ArrayList<FileModel>(Arrays.asList(arrayParents)); // return new ArrayList<FileModel>(Arrays.asList(arrayParents));
workspaceLogger.trace("list parents returning size: "+arrayParents.length); workspaceLogger.trace("list parents returning size: "+arrayParents.length);
if(arrayParents[0]==null){ //EXIT BY BREAK IN CASE OF SPECIAL FOLDER if(arrayParents[0]==null){ //EXIT BY BREAK IN CASE OF SPECIAL FOLDER
List<FileModel> breadcrumbs = new ArrayList<FileModel>(arrayParents.length-1); 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)); garbage.put(itemId, new GarbageItem(sourceItemIsShared, itemName, itemId, sourceFolderSharedId));
// workspace.removeItem(itemId); // workspace.removeItem(itemId);
// //IF SOURCE SHARED FOLDER IS NOT NULL // //IF SOURCE SHARED FOLDER IS NOT NULL
// if(sourceFolderSharedId!=null) // if(sourceFolderSharedId!=null)
// NotificationsUtil.checkSendNotifyRemoveItemToShare(this.getThreadLocalRequest().getSession(), sourceItemIsShared, itemName, itemId, sourceFolderSharedId); // NotificationsUtil.checkSendNotifyRemoveItemToShare(this.getThreadLocalRequest().getSession(), sourceItemIsShared, itemName, itemId, sourceFolderSharedId);
} }
//ITEM ID - ERROR //ITEM ID - ERROR
@ -2483,14 +2510,14 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
//IS ROOT SHARED FOLDER //IS ROOT SHARED FOLDER
ite = (WorkspaceSharedFolder) wsItem; ite = (WorkspaceSharedFolder) wsItem;
workspaceLogger.trace("Folder " +ite.getName()+" is a "+WorkspaceSharedFolder.class.getName()); workspaceLogger.trace("Folder " +ite.getName()+" is a "+WorkspaceSharedFolder.class.getName());
// ite = (WorkspaceSharedFolder) workspace.getItemByPath(wsItem.getPath()); // ite = (WorkspaceSharedFolder) workspace.getItemByPath(wsItem.getPath());
}else{ }else{
// IS SUB FOLDER OF THE SHARING // IS SUB FOLDER OF THE SHARING
ite = (WorkspaceFolder) wsItem; ite = (WorkspaceFolder) wsItem;
workspaceLogger.trace("Folder " +ite.getName()+" is a "+WorkspaceFolder.class.getName()); 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)); ite.setACL(listLogins, ACLType.valueOf(aclType));
}else }else
throw new Exception("Source item is not shared or shared folder"); 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) { if (isWithinPortal() && username.compareTo(WsUtil.TEST_USER) != 0) {
try { try {
LiferayUserManager l = new LiferayUserManager(); LiferayUserManager l = new LiferayUserManager();
GCubeUser user = l.getUserByUsername(username); GCubeUser user = l.getUserByUsername(username);
firstName = user.getFirstName(); firstName = user.getFirstName();
lastName = user.getLastName(); lastName = user.getLastName();
email = user.getEmail(); email = user.getEmail();
}catch (UserManagementSystemException e) { }catch (UserManagementSystemException e) {
workspaceLogger.error("UserManagementSystemException for username: "+username); workspaceLogger.error("UserManagementSystemException for username: "+username);
} }
catch (UserRetrievalFault e) { catch (UserRetrievalFault e) {
workspaceLogger.error("UserRetrievalFault for username: "+username); workspaceLogger.error("UserRetrievalFault for username: "+username);
} }
} }
return new UserBean(username, firstName, lastName, email); 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"); workspaceLogger.trace("Get SharedFolderForId: folder id "+folderId+" is shared");
//TODO REMOVE wsItem.getIdSharedFolder() //TODO REMOVE wsItem.getIdSharedFolder()
// WorkspaceSharedFolder wsFolder = (WorkspaceSharedFolder) workspace.getItem(wsItem.getIdSharedFolder()); // WorkspaceSharedFolder wsFolder = (WorkspaceSharedFolder) workspace.getItem(wsItem.getIdSharedFolder());
WorkspaceFolder wsFolder = (WorkspaceFolder) wsItem; WorkspaceFolder wsFolder = (WorkspaceFolder) wsItem;
if(wsFolder!=null){ if(wsFolder!=null){
@ -2927,18 +2954,18 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
switch (operation) { switch (operation) {
case EMPTY_TRASH: case EMPTY_TRASH:
listErrors = trash.emptyTrash(); listErrors = trash.emptyTrash();
break; break;
case RESTORE_ALL: case RESTORE_ALL:
listErrors = trash.restoreAll(); listErrors = trash.restoreAll();
break; break;
case REFRESH: case REFRESH:
default: default:
result.setTrashContent(builder.buildGXTListTrashContent(trash)); result.setTrashContent(builder.buildGXTListTrashContent(trash));
return result; return result;
} }
trash = workspace.getTrash(); trash = workspace.getTrash();
@ -2987,66 +3014,66 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
switch (operation) { switch (operation) {
case DELETE_PERMANENTLY:{ case DELETE_PERMANENTLY:{
boolean deleted = false; boolean deleted = false;
for (String trashItemId : listTrashItemIds) { for (String trashItemId : listTrashItemIds) {
try{ try{
WorkspaceTrashItem trashItem = trash.getTrashItemById(trashItemId); WorkspaceTrashItem trashItem = trash.getTrashItemById(trashItemId);
if(trashItem!=null){ if(trashItem!=null){
trashItem.deletePermanently(); trashItem.deletePermanently();
listUpdatedTrashIds.add(trashItemId); listUpdatedTrashIds.add(trashItemId);
deleted = true; deleted = true;
}
}catch (Exception e) {
workspaceLogger.warn("Error on DELETE_PERMANENTLY the item : "+trashItemId, e);
FileTrashedModel fakeFile = new FileTrashedModel();
fakeFile.setIdentifier(trashItemId);
listContentError.add(fakeFile);
} }
}catch (Exception e) {
workspaceLogger.warn("Error on DELETE_PERMANENTLY the item : "+trashItemId, e);
FileTrashedModel fakeFile = new FileTrashedModel();
fakeFile.setIdentifier(trashItemId);
listContentError.add(fakeFile);
} }
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;
} }
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; break;
for (String trashItemId : listTrashItemIds) { }
try{
WorkspaceTrashItem trashItem = trash.getTrashItemById(trashItemId);
if(trashItem!=null){
trashItem.restore();
listUpdatedTrashIds.add(trashItemId);
restored = true;
}
}catch (Exception e) { case RESTORE:{
workspaceLogger.warn("Error on RESTORE the item : "+trashItemId, e);
FileTrashedModel fakeFile = new FileTrashedModel(); boolean restored = false;
fakeFile.setIdentifier(trashItemId); for (String trashItemId : listTrashItemIds) {
listContentError.add(fakeFile); 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";
if(!restored)
throw new Exception("Sorry, an error occurred on restoring the trash "+label+", try again");
break;
} }
String label = listTrashItemIds.size()>1?"items":"item";
if(!restored)
throw new Exception("Sorry, an error occurred on restoring the trash "+label+", try again");
break;
}
default: default:
break; break;
} }
// trash = workspace.getTrash(); // trash = workspace.getTrash();
// result.setTrashContent(builder.buildGXTListTrashContent(trash)); // result.setTrashContent(builder.buildGXTListTrashContent(trash));
if(!listContentError.isEmpty()){ if(!listContentError.isEmpty()){
result.setListErrors(listContentError); result.setListErrors(listContentError);
@ -3259,7 +3286,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
workspaceLogger.info("Getting workspace size.."); workspaceLogger.info("Getting workspace size..");
Workspace workspace = getWorkspace(); Workspace workspace = getWorkspace();
long size = workspace.getDiskUsage(); long size = workspace.getDiskUsage();
// workspaceLogger.info("Root size is: "+size +" formatting.."); // workspaceLogger.info("Root size is: "+size +" formatting..");
String formatSize = GWTWorkspaceBuilder.formatFileSize(size); String formatSize = GWTWorkspaceBuilder.formatFileSize(size);
workspaceLogger.info("returning workspace size: "+formatSize); workspaceLogger.info("returning workspace size: "+formatSize);
return formatSize; return formatSize;
@ -3388,4 +3415,132 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
throw new Exception(error); 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;
}
} }