Index: lams_central/src/java/org/lamsfoundation/lams/web/HomeAction.java =================================================================== diff -u -rc9aead8dc4d1f820cff644f7973adf5072a1bcf7 -re6e981f6a6fff2779cdcbb39513e76b10ccc131f --- lams_central/src/java/org/lamsfoundation/lams/web/HomeAction.java (.../HomeAction.java) (revision c9aead8dc4d1f820cff644f7973adf5072a1bcf7) +++ lams_central/src/java/org/lamsfoundation/lams/web/HomeAction.java (.../HomeAction.java) (revision e6e981f6a6fff2779cdcbb39513e76b10ccc131f) @@ -338,8 +338,9 @@ UserDTO userDTO = getUser(); // get all user accessible folders and LD descriptions as JSON - JSONObject learningDesigns = getFolderContents(null, userDTO.getUserID(), false); - req.setAttribute("folderContents", learningDesigns.toString()); + String folderContentsJSON = getWorkspaceManagementService().getFolderContentsJSON(null, userDTO.getUserID(), + false); + req.setAttribute("folderContents", folderContentsJSON); Integer organisationID = new Integer(WebUtil.readIntParam(req, "organisationID")); JSONObject users = new JSONObject(); @@ -399,10 +400,11 @@ RepositoryCheckedException { Integer folderID = WebUtil.readIntParam(req, "folderID", true); boolean allowInvalidDesigns = WebUtil.readBooleanParam(req, "allowInvalidDesigns", false); - JSONObject responseJSON = getFolderContents(folderID, getUser().getUserID(), allowInvalidDesigns); + String folderContentsJSON = getWorkspaceManagementService().getFolderContentsJSON(folderID, getUser().getUserID(), + allowInvalidDesigns); - res.setContentType("application/json;charset=utf-8"); - res.getWriter().print(responseJSON.toString()); + res.setContentType("application/json;charset=UTF-8"); + res.getWriter().print(folderContentsJSON); return null; } @@ -429,76 +431,6 @@ return null; } - @SuppressWarnings("unchecked") - private JSONObject getFolderContents(Integer folderID, Integer userID, boolean allowInvalidDesigns) - throws JSONException, IOException, UserAccessDeniedException, RepositoryCheckedException { - JSONObject result = new JSONObject(); - Vector folderContents = null; - - // get user accessible folders in the start - if (folderID == null) { - folderContents = new Vector(3); - MessageService msgService = getWorkspaceManagementService().getMessageService(); - - FolderContentDTO userFolder = getWorkspaceManagementService().getUserWorkspaceFolder(userID); - if (userFolder != null) { - folderContents.add(userFolder); - } - - FolderContentDTO myGroupsFolder = new FolderContentDTO(msgService.getMessage("organisations"), - msgService.getMessage("folder"), null, null, FolderContentDTO.FOLDER, - WorkspaceAction.ORG_FOLDER_ID.longValue(), WorkspaceFolder.READ_ACCESS, null); - - folderContents.add(myGroupsFolder); - - FolderContentDTO publicFolder = getWorkspaceManagementService().getPublicWorkspaceFolder(userID); - if (publicFolder != null) { - folderContents.add(publicFolder); - } - // special behaviour for organisation folders - } else if (folderID.equals(WorkspaceAction.ORG_FOLDER_ID)) { - folderContents = getWorkspaceManagementService().getAccessibleOrganisationWorkspaceFolders(userID); - Collections.sort(folderContents); - - if (folderContents.size() == 1) { - FolderContentDTO folder = folderContents.firstElement(); - if (folder.getResourceID().equals(WorkspaceAction.ROOT_ORG_FOLDER_ID)) { - return getFolderContents(WorkspaceAction.ROOT_ORG_FOLDER_ID, userID, allowInvalidDesigns); - } - } - } else { - WorkspaceFolder folder = getWorkspaceManagementService().getWorkspaceFolder(folderID); - Integer mode = allowInvalidDesigns ? WorkspaceManagementService.AUTHORING - : WorkspaceManagementService.MONITORING; - folderContents = getWorkspaceManagementService().getFolderContents(userID, folder, mode); - Collections.sort(folderContents); - } - - // fill JSON object with folders and LDs - for (FolderContentDTO folderContent : folderContents) { - String contentType = folderContent.getResourceType(); - if (FolderContentDTO.FOLDER.equals(contentType)) { - JSONObject subfolderJSON = new JSONObject(); - subfolderJSON.put("name", folderContent.getName()); - subfolderJSON.put("isRunSequencesFolder", - WorkspaceFolder.RUN_SEQUENCES.equals(folderContent.getResourceTypeID().intValue())); - subfolderJSON.put("folderID", folderContent.getResourceID().intValue()); - result.append("folders", subfolderJSON); - } else if (FolderContentDTO.DESIGN.equals(contentType)) { - JSONObject learningDesignJSON = new JSONObject(); - learningDesignJSON.put("name", folderContent.getName()); - learningDesignJSON.put("learningDesignId", folderContent.getResourceID()); - result.append("learningDesigns", learningDesignJSON); - } else { - if (HomeAction.log.isDebugEnabled()) { - HomeAction.log.debug("Unsupported folder content found, named \"" + folderContent.getName() + "\""); - } - } - } - - return result; - } - public ActionForward logout(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { Index: lams_central/src/java/org/lamsfoundation/lams/webservice/xml/LearningDesignRepositoryServlet.java =================================================================== diff -u -rb0952eab3024458158903e62579ab202ee2a6838 -re6e981f6a6fff2779cdcbb39513e76b10ccc131f --- lams_central/src/java/org/lamsfoundation/lams/webservice/xml/LearningDesignRepositoryServlet.java (.../LearningDesignRepositoryServlet.java) (revision b0952eab3024458158903e62579ab202ee2a6838) +++ lams_central/src/java/org/lamsfoundation/lams/webservice/xml/LearningDesignRepositoryServlet.java (.../LearningDesignRepositoryServlet.java) (revision e6e981f6a6fff2779cdcbb39513e76b10ccc131f) @@ -324,6 +324,30 @@ if (method != null && method.equals("exportLD")) { // do export exportLD(request, response); + + } else if (method != null && method.equals("getLearningDesignsJSONFormat")) { + + ExtUserUseridMap userMap = null; + boolean prefix = usePrefix == null ? true : Boolean.parseBoolean(usePrefix); + if (firstName == null && lastName == null) { + userMap = integrationService.getExtUserUseridMap(serverMap, username, prefix); + } else { + userMap = integrationService.getImplicitExtUserUseridMap(serverMap, username, firstName, lastName, + lang, country, email, prefix); + } + + // create group for external course if necessary + integrationService.getExtCourseClassMap(serverMap, userMap, courseId, country, lang, courseName, LoginRequestDispatcher.METHOD_AUTHOR); + Integer userId = userMap.getUser().getUserId(); + + Integer folderID = WebUtil.readIntParam(request, "folderID", true); + boolean allowInvalidDesigns = WebUtil.readBooleanParam(request, "allowInvalidDesigns", false); + String folderContentsJSON = service.getFolderContentsJSON(folderID, userId, allowInvalidDesigns); + + response.setContentType("application/json;charset=UTF-8"); + response.getWriter().write(folderContentsJSON); + + //TODO remove the next else-paragraph as soon as all integrations will start using new method. (After this also stop checking for (method != null && method.equals("getLearningDesignsJSONFormat"))) } else { ExtUserUseridMap userMap = null; @@ -337,8 +361,9 @@ // create group for external course if necessary integrationService.getExtCourseClassMap(serverMap, userMap, courseId, country, lang, courseName, LoginRequestDispatcher.METHOD_AUTHOR); + Integer userId = userMap.getUser().getUserId(); - String contentTree = buildContentTree(userMap.getUser().getUserId(), mode).toString(); + String contentTree = buildContentTree(userId, mode).toString(); // generate response response.setContentType("text/xml"); Index: lams_central/src/java/org/lamsfoundation/lams/workspace/service/IWorkspaceManagementService.java =================================================================== diff -u -r5593d5b6d117372be17dacc3523ee0dfda5ed435 -re6e981f6a6fff2779cdcbb39513e76b10ccc131f --- lams_central/src/java/org/lamsfoundation/lams/workspace/service/IWorkspaceManagementService.java (.../IWorkspaceManagementService.java) (revision 5593d5b6d117372be17dacc3523ee0dfda5ed435) +++ lams_central/src/java/org/lamsfoundation/lams/workspace/service/IWorkspaceManagementService.java (.../IWorkspaceManagementService.java) (revision e6e981f6a6fff2779cdcbb39513e76b10ccc131f) @@ -4,15 +4,15 @@ * License Information: http://lamsfoundation.org/licensing/lams/2.0/ * * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2.0 + * it under the terms of the GNU General License version 2.0 * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General License for more details. * - * You should have received a copy of the GNU General Public License + * You should have received a copy of the GNU General License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA @@ -27,6 +27,7 @@ import java.util.List; import java.util.Vector; +import org.apache.tomcat.util.json.JSONException; import org.lamsfoundation.lams.contentrepository.RepositoryCheckedException; import org.lamsfoundation.lams.usermanagement.User; import org.lamsfoundation.lams.usermanagement.WorkspaceFolder; @@ -42,39 +43,39 @@ */ public interface IWorkspaceManagementService { - public static final String REPOSITORY_USERNAME ="workspaceManager"; - public static final String REPOSITORY_PASSWORD ="flashClient"; - public static final String REPOSITORY_WORKSPACE="FlashClientsWorkspace"; + static final String REPOSITORY_USERNAME ="workspaceManager"; + static final String REPOSITORY_PASSWORD ="flashClient"; + static final String REPOSITORY_WORKSPACE="FlashClientsWorkspace"; /* Message keys used for Flash packets. */ - public static final String MSG_KEY_MOVE = "moveResource"; - public static final String MSG_KEY_COPY = "copyResource"; - public static final String MSG_KEY_RENAME = "renameResource"; - public static final String MSG_KEY_DELETE = "deleteResource"; - public static final String MSG_KEY_CREATE_WKF_CONTENT = "createWorkspaceFolderContent"; - public static final String MSG_KEY_UPDATE_WKF_CONTENT = "updateWorkspaceFolderContent"; - public static final String MSG_KEY_DELETE_VERSION = "deleteContentWithVersion"; - public static final String MSG_KEY_ORG = "getUserOrganisation"; - public static final String MSG_KEY_ORG_BY_ROLE = "getOrganisationsByUserRole"; - public static final String MSG_KEY_USER_BY_ROLE = "getUsersFromOrganisationByRole"; + static final String MSG_KEY_MOVE = "moveResource"; + static final String MSG_KEY_COPY = "copyResource"; + static final String MSG_KEY_RENAME = "renameResource"; + static final String MSG_KEY_DELETE = "deleteResource"; + static final String MSG_KEY_CREATE_WKF_CONTENT = "createWorkspaceFolderContent"; + static final String MSG_KEY_UPDATE_WKF_CONTENT = "updateWorkspaceFolderContent"; + static final String MSG_KEY_DELETE_VERSION = "deleteContentWithVersion"; + static final String MSG_KEY_ORG = "getUserOrganisation"; + static final String MSG_KEY_ORG_BY_ROLE = "getOrganisationsByUserRole"; + static final String MSG_KEY_USER_BY_ROLE = "getUsersFromOrganisationByRole"; /** * I18n Message service. The Workspace action class needs access to the message service. * @param messageSource */ - public MessageService getMessageService(); + MessageService getMessageService(); /** * Get the workspace folder for a particular id. Does not check the user permissions - that will be checked if you try to get * anything from the folder. */ - public WorkspaceFolder getWorkspaceFolder(Integer workspaceFolderID); + WorkspaceFolder getWorkspaceFolder(Integer workspaceFolderID); /** * Get the workspace folders for a particular name. Does not check the user permissions - that will be checked if * you try to get anything from the folder. */ - public List getWorkspaceFolder(String workspaceFolderName); + List getWorkspaceFolder(String workspaceFolderName); /** * This method returns the contents of the folder with given @@ -117,7 +118,7 @@ * @return A list of the FolderContentDTOs in a format suitable for WDDX * @throws Exception */ - public Vector getFolderContents(Integer userID, WorkspaceFolder workspaceFolder, Integer mode)throws UserAccessDeniedException, RepositoryCheckedException ; + Vector getFolderContents(Integer userID, WorkspaceFolder workspaceFolder, Integer mode)throws UserAccessDeniedException, RepositoryCheckedException ; /** * This method does the same as getFolderContents() except that it doesn't return @@ -131,9 +132,16 @@ * @return A list of the FolderContentDTOs in a format suitable for WDDX * @throws Exception */ - public Vector getFolderContentsExcludeHome(Integer userID, WorkspaceFolder workspaceFolder, Integer mode)throws UserAccessDeniedException, RepositoryCheckedException ; + Vector getFolderContentsExcludeHome(Integer userID, WorkspaceFolder workspaceFolder, Integer mode)throws UserAccessDeniedException, RepositoryCheckedException ; + /** + * Returns Folder Contents in JSON format. + */ + String getFolderContentsJSON(Integer folderID, Integer userID, boolean allowInvalidDesigns) throws JSONException, + IOException, UserAccessDeniedException, RepositoryCheckedException; + + /** * This method creates a new folder under the given parentFolder * inside the user's default workspace. * @@ -145,7 +153,7 @@ * @throws UserException * @throws WorkspaceFolderException */ - public WorkspaceFolder createFolder(Integer parentFolderID, String name, Integer userID) throws UserException,WorkspaceFolderException; + WorkspaceFolder createFolder(Integer parentFolderID, String name, Integer userID) throws UserException,WorkspaceFolderException; /** * This method creates a new folder under the given parentFolder @@ -158,7 +166,7 @@ * @return String The folder_id and name of the newly created folder in WDDX format * @throws IOException */ - public String createFolderForFlash(Integer parentFolderID, String name, Integer userID)throws IOException; + String createFolderForFlash(Integer parentFolderID, String name, Integer userID)throws IOException; /** @@ -174,7 +182,7 @@ * @return String The acknowledgement/error message in WDDX format for FLASH * @throws IOException */ - public String deleteResource(Long resourceID, String resourceType, Integer userID) + String deleteResource(Long resourceID, String resourceType, Integer userID) throws IOException; /** @@ -191,7 +199,7 @@ * @return String The acknowledgement/error message to be sent to FLASH * @throws IOException */ - public String copyResource(Long resourceID, String resourceType, Integer copyType, Integer targetFolderID, Integer userID)throws IOException; + String copyResource(Long resourceID, String resourceType, Integer copyType, Integer targetFolderID, Integer userID)throws IOException; /** @@ -209,7 +217,7 @@ * @return String The acknowledgement/error message in WDDX format for FLASH * @throws IOException */ - public String moveResource(Long resourceID, Integer targetFolderID, String resourceType, Integer userID) + String moveResource(Long resourceID, Integer targetFolderID, String resourceType, Integer userID) throws IOException; /** @@ -232,7 +240,7 @@ * FLASH client. * @throws Exception */ - public String createWorkspaceFolderContent(Integer contentTypeID, String name, String description, Integer workspaceFolderID, String mimeType, String path) throws Exception; + String createWorkspaceFolderContent(Integer contentTypeID, String name, String description, Integer workspaceFolderID, String mimeType, String path) throws Exception; /** * This method updates an existing file(workspaceFolderContet) @@ -244,7 +252,7 @@ * @return String The acknowledgement/error message in WDDX format for FLASH * @throws Exception */ - public String updateWorkspaceFolderContent(Long folderContentID,String path)throws Exception; + String updateWorkspaceFolderContent(Long folderContentID,String path)throws Exception; /** * This method is called when the user knows which version of the @@ -268,7 +276,7 @@ * @return String Acknowledgement/error message in WDDX format for FLASH * @throws Exception */ - public String deleteContentWithVersion(Long uuid, Long versionToBeDeleted,Long folderContentID)throws Exception; + String deleteContentWithVersion(Long uuid, Long versionToBeDeleted,Long folderContentID)throws Exception; /** * This method returns a list of organisation workspace folders. @@ -284,9 +292,9 @@ * @return List of folders, in a format suitable for WDDX * @throws IOException */ - public Vector getAccessibleOrganisationWorkspaceFolders(Integer userID)throws IOException; + Vector getAccessibleOrganisationWorkspaceFolders(Integer userID)throws IOException; - public Vector getAccessibleOrganisationWorkspaceFolders(User user)throws IOException; + Vector getAccessibleOrganisationWorkspaceFolders(User user)throws IOException; /** * This method returns the root workspace folder for a particular user. @@ -296,17 +304,17 @@ * @return FolderContentDTO for the user's root workspace folder * @throws IOException */ - public FolderContentDTO getUserWorkspaceFolder(Integer userID)throws IOException; + FolderContentDTO getUserWorkspaceFolder(Integer userID)throws IOException; /** - * This method returns the public workspace folder for the server. + * This method returns the workspace folder for the server. * * @param userID The user_id of the user for whom the * folders have to fetched - * @return FolderContentDTO for the public workspace folder + * @return FolderContentDTO for the workspace folder * @throws IOException */ - public FolderContentDTO getPublicWorkspaceFolder(Integer userID) throws IOException; + FolderContentDTO getPublicWorkspaceFolder(Integer userID) throws IOException; /** * This method renames the workspaceFolder/learning design with the @@ -323,7 +331,7 @@ * @return String The acknowledgement/error message in WDDX format for FLASH * @throws IOException */ - public String renameResource(Long resourceID, String resourceType, String newName, Integer userID) + String renameResource(Long resourceID, String resourceType, String newName, Integer userID) throws IOException; @@ -334,7 +342,7 @@ * @return String The required information in WDDX format * @throws IOException */ - public String getWorkspace(Integer userID) throws IOException; + String getWorkspace(Integer userID) throws IOException; /** * Retrieves a tree of organisations in which the user has the specified role. @@ -348,7 +356,7 @@ * @param classID * @return organisationDTO hierarchy, in WDDX format. */ - public String getOrganisationsByUserRole(Integer userID, List roleNames, Integer courseId, List restrictToClassIds) throws IOException; + String getOrganisationsByUserRole(Integer userID, List roleNames, Integer courseId, List restrictToClassIds) throws IOException; /** * Returns the users within the Organisation with organisationID @@ -357,13 +365,13 @@ * @param role * @return */ - public Vector getUsersFromOrganisationByRole(Integer organisationID, String role) throws IOException; + Vector getUsersFromOrganisationByRole(Integer organisationID, String role) throws IOException; /** * Returns a single OrganisationDTO with the user's roles included. If the user does not have * any roles in this organisation, then no organisation is returned. */ - public String getUserOrganisation(Integer userID, Integer organisationId) throws IOException; + String getUserOrganisation(Integer userID, Integer organisationId) throws IOException; /** @@ -377,6 +385,6 @@ * @throws UserException * @throws WorkspaceFolderException */ - public boolean isUserAuthorizedToModifyFolderContents(Integer folderID, Integer userID)throws UserException, WorkspaceFolderException; + boolean isUserAuthorizedToModifyFolderContents(Integer folderID, Integer userID)throws UserException, WorkspaceFolderException; } Index: lams_central/src/java/org/lamsfoundation/lams/workspace/service/WorkspaceManagementService.java =================================================================== diff -u -r7e129f6c6d3f015eae27a8958e5d12f857e5567b -re6e981f6a6fff2779cdcbb39513e76b10ccc131f --- lams_central/src/java/org/lamsfoundation/lams/workspace/service/WorkspaceManagementService.java (.../WorkspaceManagementService.java) (revision 7e129f6c6d3f015eae27a8958e5d12f857e5567b) +++ lams_central/src/java/org/lamsfoundation/lams/workspace/service/WorkspaceManagementService.java (.../WorkspaceManagementService.java) (revision e6e981f6a6fff2779cdcbb39513e76b10ccc131f) @@ -36,6 +36,8 @@ import java.util.Vector; import org.apache.log4j.Logger; +import org.apache.tomcat.util.json.JSONException; +import org.apache.tomcat.util.json.JSONObject; import org.lamsfoundation.lams.authoring.service.IAuthoringService; import org.lamsfoundation.lams.contentrepository.AccessDeniedException; import org.lamsfoundation.lams.contentrepository.FileException; @@ -70,9 +72,11 @@ import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; import org.lamsfoundation.lams.util.MessageService; import org.lamsfoundation.lams.util.wddx.FlashMessage; +import org.lamsfoundation.lams.web.HomeAction; import org.lamsfoundation.lams.workspace.WorkspaceFolderContent; import org.lamsfoundation.lams.workspace.dto.FolderContentDTO; import org.lamsfoundation.lams.workspace.dto.UpdateContentDTO; +import org.lamsfoundation.lams.workspace.web.WorkspaceAction; /** * @author Manpreet Minhas @@ -199,7 +203,7 @@ * @return String The acknowledgement/error message in WDDX format for FLASH * @throws IOException */ - public String deleteFolder(Integer folderID, Integer userID) throws IOException { + private String deleteFolder(Integer folderID, Integer userID) throws IOException { WorkspaceFolder workspaceFolder = (WorkspaceFolder) baseDAO.find(WorkspaceFolder.class, folderID); User user = (User) userMgmtService.findById(User.class, userID); FlashMessage flashMessage = null; @@ -303,21 +307,11 @@ } - /** - * Get the workspace folder for a particular id. Does not check the user permissions - that will be checked if you - * try to get anything from the folder. - */ @Override public WorkspaceFolder getWorkspaceFolder(Integer workspaceFolderID) { return (WorkspaceFolder) baseDAO.find(WorkspaceFolder.class, workspaceFolderID); } - /** - * (non-Javadoc) - * - * @see org.lamsfoundation.lams.workspace.service.IWorkspaceManagementService#getFolderContentsExcludeHome(java.lang.Integer, - * java.lang.Integer, java.lang.Integer) - */ @Override public Vector getFolderContentsExcludeHome(Integer userID, WorkspaceFolder folder, Integer mode) throws UserAccessDeniedException, RepositoryCheckedException { @@ -326,12 +320,6 @@ (user.getWorkspace() != null) ? user.getWorkspace().getDefaultFolder() : null); } - /** - * (non-Javadoc) - * - * @see org.lamsfoundation.lams.workspace.service.IWorkspaceManagementService#getFolderContents(java.lang.Integer, - * java.lang.Integer, java.lang.Integer) - */ @Override public Vector getFolderContents(Integer userID, WorkspaceFolder folder, Integer mode) throws UserAccessDeniedException, RepositoryCheckedException { @@ -346,7 +334,7 @@ * @throws UserAccessDeniedException * @throws RepositoryCheckedException */ - public Vector getFolderContentsInternal(User user, WorkspaceFolder workspaceFolder, Integer mode, + private Vector getFolderContentsInternal(User user, WorkspaceFolder workspaceFolder, Integer mode, String methodName, WorkspaceFolder skipFolder) throws UserAccessDeniedException, RepositoryCheckedException { Vector contentDTO = new Vector(); if (user != null) { @@ -406,6 +394,76 @@ } } + @Override + @SuppressWarnings("unchecked") + public String getFolderContentsJSON(Integer folderID, Integer userID, boolean allowInvalidDesigns) + throws JSONException, IOException, UserAccessDeniedException, RepositoryCheckedException { + JSONObject result = new JSONObject(); + Vector folderContents = null; + + // get user accessible folders in the start + if (folderID == null) { + folderContents = new Vector(3); + + FolderContentDTO userFolder = getUserWorkspaceFolder(userID); + if (userFolder != null) { + folderContents.add(userFolder); + } + + FolderContentDTO myGroupsFolder = new FolderContentDTO(messageService.getMessage("organisations"), + messageService.getMessage("folder"), null, null, FolderContentDTO.FOLDER, + WorkspaceAction.ORG_FOLDER_ID.longValue(), WorkspaceFolder.READ_ACCESS, null); + + folderContents.add(myGroupsFolder); + + FolderContentDTO publicFolder = getPublicWorkspaceFolder(userID); + if (publicFolder != null) { + folderContents.add(publicFolder); + } + // special behaviour for organisation folders + } else if (folderID.equals(WorkspaceAction.ORG_FOLDER_ID)) { + folderContents = getAccessibleOrganisationWorkspaceFolders(userID); + Collections.sort(folderContents); + + if (folderContents.size() == 1) { + FolderContentDTO folder = folderContents.firstElement(); + if (folder.getResourceID().equals(WorkspaceAction.ROOT_ORG_FOLDER_ID)) { + return getFolderContentsJSON(WorkspaceAction.ROOT_ORG_FOLDER_ID, userID, allowInvalidDesigns); + } + } + } else { + WorkspaceFolder folder = getWorkspaceFolder(folderID); + Integer mode = allowInvalidDesigns ? WorkspaceManagementService.AUTHORING + : WorkspaceManagementService.MONITORING; + folderContents = getFolderContents(userID, folder, mode); + Collections.sort(folderContents); + } + + // fill JSON object with folders and LDs + for (FolderContentDTO folderContent : folderContents) { + String contentType = folderContent.getResourceType(); + if (FolderContentDTO.FOLDER.equals(contentType)) { + JSONObject subfolderJSON = new JSONObject(); + subfolderJSON.put("name", folderContent.getName()); + subfolderJSON.put("isRunSequencesFolder", + WorkspaceFolder.RUN_SEQUENCES.equals(folderContent.getResourceTypeID().intValue())); + subfolderJSON.put("folderID", folderContent.getResourceID().intValue()); + result.append("folders", subfolderJSON); + } else if (FolderContentDTO.DESIGN.equals(contentType)) { + JSONObject learningDesignJSON = new JSONObject(); + learningDesignJSON.put("name", folderContent.getName()); + learningDesignJSON.put("learningDesignId", folderContent.getResourceID()); + result.append("learningDesigns", learningDesignJSON); + } else { + if (log.isDebugEnabled()) { + log.debug("Unsupported folder content found, named \"" + folderContent.getName() + "\""); + } + } + } + + return result.toString(); + } + /** * This method returns the permissions specific to the given workspaceFolder for the given user. * @@ -415,7 +473,7 @@ * The user for whom these permissions are set. * @return Integer The permissions */ - public Integer getPermissions(WorkspaceFolder workspaceFolder, User user) { + private Integer getPermissions(WorkspaceFolder workspaceFolder, User user) { Integer permission = null; if ((workspaceFolder == null) || (user == null)) { @@ -487,10 +545,6 @@ } - /** - * @see org.lamsfoundation.lams.workspace.service.IWorkspaceManagementService#copyResource(Long, String, Integer, - * Integer, Integer) - */ @Override public String copyResource(Long resourceID, String resourceType, Integer copyType, Integer targetFolderID, Integer userID) throws IOException { @@ -772,7 +826,7 @@ * @return String The acknowledgement/error message in WDDX format for FLASH * @throws IOException */ - public String deleteLearningDesign(Long learningDesignID, Integer userID) throws IOException { + private String deleteLearningDesign(Long learningDesignID, Integer userID) throws IOException { User user = (User) baseDAO.find(User.class, userID); FlashMessage flashMessage = null; if (user != null) { @@ -851,12 +905,8 @@ } /** - * (non-Javadoc) - * - * @see org.lamsfoundation.lams.workspace.service.IWorkspaceManagementService#moveFolder(java.lang.Integer, - * java.lang.Integer, java.lang.Integer) */ - public String moveFolder(Integer currentFolderID, Integer targetFolderID, Integer userID) throws IOException { + private String moveFolder(Integer currentFolderID, Integer targetFolderID, Integer userID) throws IOException { FlashMessage flashMessage = null; try { if (currentFolderID == null) { @@ -943,10 +993,6 @@ return ticket; } - /** - * @see org.lamsfoundation.lams.workspace.service.IWorkspaceManagementService#createWorkspaceFolderContent(java.lang.Integer, - * java.lang.String, java.lang.String, java.lang.Integer, java.lang.String, java.lang.String) - */ @Override public String createWorkspaceFolderContent(Integer contentTypeID, String name, String description, Integer workspaceFolderID, String mimeType, String path) throws Exception { @@ -1024,12 +1070,6 @@ return false; } - /** - * (non-Javadoc) - * - * @see org.lamsfoundation.lams.workspace.service.IWorkspaceManagementService#updateWorkspaceFolderContent(java.lang.Long, - * java.io.InputStream) - */ @Override public String updateWorkspaceFolderContent(Long folderContentID, String path) throws Exception { FlashMessage flashMessage = null; @@ -1093,12 +1133,6 @@ return nodeKey; } - /** - * (non-Javadoc) - * - * @see org.lamsfoundation.lams.workspace.service.IWorkspaceManagementService#deleteContentWithVersion(java.lang.Long, - * java.lang.Long, java.lang.Long) - */ @Override public String deleteContentWithVersion(Long uuid, Long versionToBeDeleted, Long folderContentID) throws Exception { FlashMessage flashMessage = null; @@ -1168,7 +1202,7 @@ * @return String Acknowledgement/error message in WDDX format for FLASH * @throws Exception */ - public String deleteWorkspaceFolderContent(Long folderContentID) throws IOException { + private String deleteWorkspaceFolderContent(Long folderContentID) throws IOException { FlashMessage flashMessage = null; WorkspaceFolderContent workspaceFolderContent = (WorkspaceFolderContent) baseDAO.find( WorkspaceFolderContent.class, folderContentID);