diff --git a/.project b/.project index 987779f..314f7a5 100644 --- a/.project +++ b/.project @@ -1,6 +1,6 @@ - workspace-explorer + workspace-explorer-TRUNK-1.5.0-SNAPSHOT diff --git a/pom.xml b/pom.xml index 26d599b..68e5db8 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ 4.0.0 org.gcube.portlets.widgets workspace-explorer - 1.4.0-SNAPSHOT + 1.5.0-SNAPSHOT gCube Workspace Explorer gCube Workspace Explorer widget allows to navigate (gCube) Workspace diff --git a/src/main/java/org/gcube/portlets/widgets/wsexplorer/client/select/WorkspaceExplorerSelectDialog.java b/src/main/java/org/gcube/portlets/widgets/wsexplorer/client/select/WorkspaceExplorerSelectDialog.java index 80560a4..99586d1 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsexplorer/client/select/WorkspaceExplorerSelectDialog.java +++ b/src/main/java/org/gcube/portlets/widgets/wsexplorer/client/select/WorkspaceExplorerSelectDialog.java @@ -8,6 +8,7 @@ import java.util.List; import org.gcube.portlets.widgets.wsexplorer.client.WorkspaceExplorerConstants; import org.gcube.portlets.widgets.wsexplorer.client.WorkspaceExplorerController; +import org.gcube.portlets.widgets.wsexplorer.client.event.LoadFolderEvent; import org.gcube.portlets.widgets.wsexplorer.client.event.LoadRootEvent; import org.gcube.portlets.widgets.wsexplorer.client.notification.WorkspaceExplorerSelectNotification.HasWorskpaceExplorerSelectNotificationListener; import org.gcube.portlets.widgets.wsexplorer.client.notification.WorkspaceExplorerSelectNotification.WorskpaceExplorerSelectNotificationListener; @@ -30,11 +31,12 @@ import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.user.client.Event; + /** - * The Class WorkspaceExplorerLoadDialog. + * The Class WorkspaceExplorerSelectDialog. * * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Jun 30, 2015 + * Sep 21, 2016 */ public class WorkspaceExplorerSelectDialog extends Modal implements HasWorskpaceExplorerSelectNotificationListener{ @@ -52,23 +54,23 @@ public class WorkspaceExplorerSelectDialog extends Modal implements HasWorskpace /** * Instantiates a new workspace explorer select dialog. * You can implement {@link WorskpaceExplorerSelectNotificationListener} to receive events - * @param captionTxt the caption txt + * @param captionTxt the dialog caption * */ public WorkspaceExplorerSelectDialog(String captionTxt) { controller = new WorkspaceExplorerController(WorkspaceExplorerConstants.HEIGHT_EXPLORER_PANEL); - loadExplorer(captionTxt); + loadExplorer(captionTxt, null); } /** * Instantiates a new workspace explorer select dialog. * You can implement {@link WorskpaceExplorerSelectNotificationListener} to receive events - * @param captionTxt the caption txt + * @param captionTxt the dialog caption * @param filterCriteria the filter criteria */ public WorkspaceExplorerSelectDialog(String captionTxt, FilterCriteria filterCriteria) { controller = new WorkspaceExplorerController(filterCriteria, WorkspaceExplorerConstants.HEIGHT_EXPLORER_PANEL); - loadExplorer(captionTxt); + loadExplorer(captionTxt, null); } /** @@ -86,10 +88,40 @@ public class WorkspaceExplorerSelectDialog extends Modal implements HasWorskpace itemsType = selectableTypes.toArray(itemsType); setSelectableTypes(selectableTypes.toArray(itemsType)); } - loadExplorer(captionTxt); + loadExplorer(captionTxt, null); } + + /** + * Instantiates a new workspace explorer select dialog. + * You can implement {@link WorskpaceExplorerSelectNotificationListener} to receive events + * + * @param folderId the folder id + * @param captionTxt the dialog caption + * @param filterCriteria the filter criteria + * @param selectableTypes the selectable types + * @param showableTypes the showable types + */ + public WorkspaceExplorerSelectDialog(String folderId, String captionTxt, FilterCriteria filterCriteria, List selectableTypes, List showableTypes) { + controller = new WorkspaceExplorerController(filterCriteria, WorkspaceExplorerConstants.HEIGHT_EXPLORER_PANEL); + if(selectableTypes!=null){ + ItemType[] itemsType = new ItemType[selectableTypes.size()]; + itemsType = selectableTypes.toArray(itemsType); + setSelectableTypes(selectableTypes.toArray(itemsType)); + } + + if(showableTypes!=null){ + ItemType[] itemsType = new ItemType[showableTypes.size()]; + itemsType = showableTypes.toArray(itemsType); + setShowableTypes(showableTypes.toArray(itemsType)); + } + + loadExplorer(captionTxt, folderId); + } + + + /** * Instantiates a new workspace explorer select dialog. * @@ -104,7 +136,8 @@ public class WorkspaceExplorerSelectDialog extends Modal implements HasWorskpace setSelectableTypes(itemsType); setShowableTypes(itemsType); } - loadExplorer(captionTxt); + + loadExplorer(captionTxt, null); } /** @@ -130,17 +163,26 @@ public class WorkspaceExplorerSelectDialog extends Modal implements HasWorskpace setShowableTypes(showableTypes.toArray(itemsType)); } - loadExplorer(captionTxt); + loadExplorer(captionTxt, null); } /** * Load explorer. + * If folder id is null or empty the explorer loads the root element + * Otherwise, it loads the folder id * * @param captionTxt the caption txt + * @param folderId the folder id */ - private void loadExplorer(String captionTxt){ - controller.getEventBus().fireEvent(new LoadRootEvent()); + private void loadExplorer(String captionTxt, String folderId){ + + if(folderId==null || folderId.isEmpty()) + controller.getEventBus().fireEvent(new LoadRootEvent()); + else{ + Item item = new Item(folderId, "", true); + controller.getEventBus().fireEvent(new LoadFolderEvent(item)); + } initDialog(captionTxt); } diff --git a/src/main/java/org/gcube/portlets/widgets/wsexplorer/client/select/WorkspaceExplorerSelectPanel.java b/src/main/java/org/gcube/portlets/widgets/wsexplorer/client/select/WorkspaceExplorerSelectPanel.java index 4426e50..fe0fc5e 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsexplorer/client/select/WorkspaceExplorerSelectPanel.java +++ b/src/main/java/org/gcube/portlets/widgets/wsexplorer/client/select/WorkspaceExplorerSelectPanel.java @@ -13,6 +13,7 @@ import org.gcube.portlets.widgets.wsexplorer.client.event.BreadcrumbClickEvent; import org.gcube.portlets.widgets.wsexplorer.client.event.BreadcrumbClickEventHandler; import org.gcube.portlets.widgets.wsexplorer.client.event.ClickItemEvent; import org.gcube.portlets.widgets.wsexplorer.client.event.ClickItemEventHandler; +import org.gcube.portlets.widgets.wsexplorer.client.event.LoadFolderEvent; import org.gcube.portlets.widgets.wsexplorer.client.event.LoadMySpecialFolderEvent; import org.gcube.portlets.widgets.wsexplorer.client.event.LoadMySpecialFolderEventHandler; import org.gcube.portlets.widgets.wsexplorer.client.event.LoadRootEvent; @@ -61,25 +62,25 @@ public class WorkspaceExplorerSelectPanel extends ScrollPanel implements HasWors */ public WorkspaceExplorerSelectPanel(String captionTxt) { controller = new WorkspaceExplorerController(WorkspaceExplorerConstants.AUTO); - loadExplorer(captionTxt); + loadExplorer(captionTxt, null); } /** * Instantiates a new workspace explorer select panel. * - * @param captionTxt the caption txt + * @param captionTxt the tool-tip of the panel * @param filterCriteria the filter criteria */ public WorkspaceExplorerSelectPanel(String captionTxt, FilterCriteria filterCriteria) { controller = new WorkspaceExplorerController(filterCriteria, WorkspaceExplorerConstants.AUTO); - loadExplorer(captionTxt); + loadExplorer(captionTxt, null); } /** * Instantiates a new workspace explorer select panel. * - * @param captionTxt the caption txt + * @param captionTxt the tool-tip of the panel * @param filterCriteria the filter criteria * @param selectableTypes the selectable types */ @@ -90,13 +91,39 @@ public class WorkspaceExplorerSelectPanel extends ScrollPanel implements HasWors itemsType = selectableTypes.toArray(itemsType); setSelectableTypes(selectableTypes.toArray(itemsType)); } - loadExplorer(captionTxt); + loadExplorer(captionTxt, null); + } + + + /** + * Instantiates a new workspace explorer select panel. + * + * @param folderId the folder id + * @param captionTxt the tool-tip of the panel + * @param filterCriteria the filter criteria + * @param selectableTypes the selectable types + */ + public WorkspaceExplorerSelectPanel(String folderId, String captionTxt, FilterCriteria filterCriteria, List selectableTypes, List showableTypes) { + controller = new WorkspaceExplorerController(filterCriteria, WorkspaceExplorerConstants.AUTO); + if(selectableTypes!=null){ + ItemType[] itemsType = new ItemType[selectableTypes.size()]; + itemsType = selectableTypes.toArray(itemsType); + setSelectableTypes(selectableTypes.toArray(itemsType)); + } + + if(showableTypes!=null){ + ItemType[] itemsType = new ItemType[showableTypes.size()]; + itemsType = showableTypes.toArray(itemsType); + setShowableTypes(showableTypes.toArray(itemsType)); + } + + loadExplorer(captionTxt, folderId); } /** * Instantiates a new workspace explorer select panel. * - * @param captionTxt the caption txt + * @param captionTxt the tool-tip of the panel * @param showOnlyFolders the show only folders */ public WorkspaceExplorerSelectPanel(String captionTxt, boolean showOnlyFolders) { @@ -107,14 +134,14 @@ public class WorkspaceExplorerSelectPanel extends ScrollPanel implements HasWors setSelectableTypes(itemsType); setShowableTypes(itemsType); } - loadExplorer(captionTxt); + loadExplorer(captionTxt, null); } /** * Instantiates a new workspace explorer select panel. * - * @param captionTxt the caption txt + * @param captionTxt the tool-tip of the panel * @param selectableTypes the selectable types * @param showableTypes the showable types */ @@ -132,7 +159,7 @@ public class WorkspaceExplorerSelectPanel extends ScrollPanel implements HasWors setShowableTypes(showableTypes.toArray(itemsType)); } - loadExplorer(captionTxt); + loadExplorer(captionTxt, null); } @@ -207,6 +234,9 @@ public class WorkspaceExplorerSelectPanel extends ScrollPanel implements HasWors }); } + /* (non-Javadoc) + * @see com.google.gwt.user.client.ui.ScrollPanel#onResize() + */ @Override public void onResize() { super.onResize(); @@ -225,6 +255,9 @@ public class WorkspaceExplorerSelectPanel extends ScrollPanel implements HasWors adjustSize(); } + /** + * Adjust size. + */ private void adjustSize(){ if(this.getParent()!=null && this.getParent().getElement()!=null) Util.adjustSize(this.getParent().getElement(), controller.getWsExplorer().getPanel(), 85); @@ -234,11 +267,20 @@ public class WorkspaceExplorerSelectPanel extends ScrollPanel implements HasWors /** * Load explorer. + * If folder id is null or empty the explorer loads the root element + * Otherwise, it loads the folder id * * @param captionTxt the caption txt + * @param folderId the folder id */ - private void loadExplorer(String captionTxt){ - controller.getEventBus().fireEvent(new LoadRootEvent()); + private void loadExplorer(String captionTxt, String folderId){ + + if(folderId==null || folderId.isEmpty()) + controller.getEventBus().fireEvent(new LoadRootEvent()); + else{ + Item item = new Item(folderId, "", true); + controller.getEventBus().fireEvent(new LoadFolderEvent(item)); + } bindEvents(); initPanel(captionTxt); } diff --git a/src/main/java/org/gcube/portlets/widgets/wsexplorer/server/WorkspaceExplorerServiceImpl.java b/src/main/java/org/gcube/portlets/widgets/wsexplorer/server/WorkspaceExplorerServiceImpl.java index 92a452b..330bba5 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsexplorer/server/WorkspaceExplorerServiceImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/wsexplorer/server/WorkspaceExplorerServiceImpl.java @@ -38,30 +38,33 @@ import org.slf4j.LoggerFactory; import com.google.gwt.user.server.rpc.RemoteServiceServlet; + /** - * The server side implementation of the RPC service. + * The Class WorkspaceExplorerServiceImpl. * * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Jun 25, 2015 + * Sep 21, 2016 */ @SuppressWarnings("serial") public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implements WorkspaceExplorerService { public static final Logger logger = LoggerFactory.getLogger(WorkspaceExplorerServiceImpl.class); public static final String USERNAME_ATTRIBUTE = "username"; - public static final String TEST_USER = "francesco.mangiacrapa"; - public static final String TEST_SCOPE = "/gcube/devsec/devVRE"; //DEV + public static final String TEST_USER = "test.user"; + public static final String TEST_SCOPE = "/gcube"; //DEV // public static final String PRODUCTION_SCOPE = "/d4science.research-infrastructures.eu/gCubeApps"; //PRODUCTION /** - * Gets the ASL session. - * - * @param httpSession the http session - * @return the ASL session - */ - private ASLSession getASLSession(HttpSession httpSession) { + * Gets the ASL session. + * + * @param httpSession the http session + * @return the ASL session + * @throws Exception the exception + */ + private ASLSession getASLSession(HttpSession httpSession) throws Exception { String sessionID = httpSession.getId(); String user = (String) httpSession.getAttribute(USERNAME_ATTRIBUTE); + ASLSession session; //TODO we check for the older attribute name if (user == null) { @@ -70,15 +73,29 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement if (user == null) { - logger.error("WORKSPACE PORTLET STARTING IN TEST MODE - NO USER FOUND"); + /*USE ANOTHER ACCOUNT (OTHERWHISE BY TEST_USER) FOR RUNNING + * COMMENT THIS IN DEVELOP ENVIROMENT (UNCOMMENT IN PRODUCTION)*/ + user=TEST_USER; + + logger.warn("WORKSPACE EXPLORER STARTING IN TEST MODE - NO USER FOUND - USING FOLLOWING SETTINGS:"); + + if (!UserUtil.isWithinPortal()) { //DEV MODE + user = "francesco.mangiacrapa"; + } + + logger.warn("session id: "+sessionID); + logger.warn("TEST_USER: "+user); + logger.warn("TEST_SCOPE: "+TEST_SCOPE); + logger.warn("USERNAME_ATTRIBUTE: "+USERNAME_ATTRIBUTE); + session = SessionManager.getInstance().getASLSession(sessionID, user); + if(session==null) + throw new Exception("ASLSession is null"); - //for test only -// user = "test.user"; - user = TEST_USER; - httpSession.setAttribute(USERNAME_ATTRIBUTE, user); - ASLSession session = SessionManager.getInstance().getASLSession(sessionID, user); session.setScope(TEST_SCOPE); + //SET HTTP SESSION ATTRIBUTE + httpSession.setAttribute(USERNAME_ATTRIBUTE, user); + return session; } else { @@ -92,14 +109,19 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement * Gets the workspace. * * @return the workspace - * @throws InternalErrorException the internal error exception - * @throws HomeNotFoundException the home not found exception - * @throws WorkspaceFolderNotFoundException the workspace folder not found exception + * @throws Exception the exception */ - protected Workspace getWorkspace() throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException { + protected Workspace getWorkspace() throws Exception { ASLSession session = getASLSession(this.getThreadLocalRequest().getSession()); - ScopeProvider.instance.set(session.getScope()); - Workspace workspace = HomeLibrary.getUserWorkspace(session.getUsername()); + Workspace workspace; + try{ + ScopeProvider.instance.set(session.getScope()); + workspace = HomeLibrary.getUserWorkspace(session.getUsername()); + }catch(InternalErrorException | HomeNotFoundException | WorkspaceFolderNotFoundException e){ + String msg = "Sorry, an error occurred when retrieving workspace item, Refresh an try again"; + logger.error("HL error: ",e); + throw new Exception(msg); + } return workspace; } @@ -192,6 +214,13 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement /* (non-Javadoc) * @see org.gcube.portlets.widgets.wsexplorer.client.rpc.WorkspaceExplorerService#getItemByCategory(org.gcube.portlets.widgets.wsexplorer.shared.ItemCategory) */ + /** + * Gets the item by category. + * + * @param category the category + * @return the item by category + * @throws WorkspaceNavigatorServiceException the workspace navigator service exception + */ @Override public Item getItemByCategory(ItemCategory category) throws WorkspaceNavigatorServiceException{ logger.trace("GetItemByCategory category: "+category); @@ -375,13 +404,11 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement /** * Gets the parents by item identifier to limit. * - * @param itemIdentifier - * the item identifier - * @param includeItemAsParent - * the include item as parent + * @param itemIdentifier the item identifier + * @param parentLimit the parent limit + * @param includeItemAsParent the include item as parent * @return the parents by item identifier to limit - * @throws Exception - * the exception + * @throws Exception the exception */ @Override public List getBreadcrumbsByItemIdentifierToParentLimit(String itemIdentifier, String parentLimit, boolean includeItemAsParent) throws Exception { @@ -470,6 +497,13 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement /* (non-Javadoc) * @see org.gcube.portlets.widgets.wsexplorer.client.rpc.WorkspaceExplorerService#loadSizeByItemId(java.lang.String) */ + /** + * Gets the size by item id. + * + * @param itemId the item id + * @return the size by item id + * @throws Exception the exception + */ @Override public Long getSizeByItemId(String itemId) throws Exception { @@ -502,6 +536,13 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement /* (non-Javadoc) * @see org.gcube.portlets.widgets.wsexplorer.client.rpc.WorkspaceExplorerService#getMimeType(java.lang.String) */ + /** + * Gets the mime type. + * + * @param itemId the item id + * @return the mime type + * @throws Exception the exception + */ @Override public String getMimeType(String itemId) throws Exception { @@ -583,6 +624,13 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement /* (non-Javadoc) * @see org.gcube.portlets.widgets.wsexplorer.client.rpc.WorkspaceExplorerService#getFormattedSizeByItemId(java.lang.String, org.gcube.portlets.widgets.wsexplorer.shared.SizeFormatter) */ + /** + * Gets the readable size by item id. + * + * @param itemId the item id + * @return the readable size by item id + * @throws Exception the exception + */ @Override public String getReadableSizeByItemId(String itemId) throws Exception { @@ -596,6 +644,15 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement } } + /** + * Creates the folder. + * + * @param nameFolder the name folder + * @param description the description + * @param parentId the parent id + * @return the item + * @throws Exception the exception + */ @Override public Item createFolder(String nameFolder, String description, String parentId) throws Exception { @@ -659,6 +716,13 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement /* (non-Javadoc) * @see org.gcube.portlets.widgets.wsexplorer.client.rpc.WorkspaceExplorerService#getGcubePropertiesForWorspaceId(java.lang.String) */ + /** + * Gets the gcube properties for worspace id. + * + * @param id the id + * @return the gcube properties for worspace id + * @throws Exception the exception + */ @Override public Map getGcubePropertiesForWorspaceId(String id) throws Exception { logger.trace("getGcubePropertiesForWorspaceId "+id);