Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/client/ToolContentHandler.java =================================================================== diff -u -r51fb2a37254f24bb2a805d4ffd54482c779f43fa -r5af735c7b7eded85eca276fe808a667175910267 --- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/client/ToolContentHandler.java (.../ToolContentHandler.java) (revision 51fb2a37254f24bb2a805d4ffd54482c779f43fa) +++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/client/ToolContentHandler.java (.../ToolContentHandler.java) (revision 5af735c7b7eded85eca276fe808a667175910267) @@ -35,11 +35,9 @@ import org.lamsfoundation.lams.contentrepository.ITicket; import org.lamsfoundation.lams.contentrepository.IVersionedNode; import org.lamsfoundation.lams.contentrepository.InvalidParameterException; -import org.lamsfoundation.lams.contentrepository.ItemExistsException; import org.lamsfoundation.lams.contentrepository.ItemNotFoundException; import org.lamsfoundation.lams.contentrepository.NodeKey; import org.lamsfoundation.lams.contentrepository.RepositoryCheckedException; -import org.lamsfoundation.lams.contentrepository.WorkspaceNotFoundException; import org.lamsfoundation.lams.contentrepository.service.IRepositoryService; import org.lamsfoundation.lams.contentrepository.service.SimpleCredentials; @@ -137,38 +135,20 @@ @Override public abstract char[] getRepositoryId(); - private void configureContentRepository() throws RepositoryCheckedException { - ICredentials cred = new SimpleCredentials(getRepositoryUser(), getRepositoryId()); - try { - getRepositoryService().createCredentials(cred); - getRepositoryService().addWorkspace(cred, getRepositoryWorkspaceName()); - } catch (ItemExistsException ie) { - log.warn("Tried to configure repository but it " + " appears to be already configured." + "Workspace name " - + getRepositoryWorkspaceName() + ". Exception thrown by repository being ignored. ", ie); - } catch (RepositoryCheckedException e) { - log.error("Error occured while trying to configure repository." + "Workspace name " - + getRepositoryWorkspaceName() + " Unable to recover from error: " + e.getMessage(), e); - throw e; - } - } - @Override public ITicket getTicket(boolean forceLogin) throws RepositoryCheckedException { - if (ticket == null || forceLogin) { - ICredentials cred = new SimpleCredentials(getRepositoryUser(), getRepositoryId()); - try { - try { - ticket = getRepositoryService().login(cred, getRepositoryWorkspaceName()); - } catch (WorkspaceNotFoundException e) { - log.error("Content Repository workspace " + getRepositoryWorkspaceName() - + " not configured. Attempting to configure now."); - configureContentRepository(); - ticket = getRepositoryService().login(cred, getRepositoryWorkspaceName()); + ICredentials cred = null; + boolean doLogin = ticket == null || forceLogin; + if (!doLogin) { + // make sure workspace exists - sometimes it does not get created when creating a ticket + cred = new SimpleCredentials(getRepositoryUser(), getRepositoryId()); + doLogin = !getRepositoryService().workspaceExists(cred, getRepositoryWorkspaceName()); } - } catch (RepositoryCheckedException e) { - log.error("Unable to get ticket for workspace " + getRepositoryWorkspaceName(), e); - throw e; + if (doLogin) { + if (cred == null) { + cred = new SimpleCredentials(getRepositoryUser(), getRepositoryId()); } + ticket = getRepositoryService().login(cred, getRepositoryWorkspaceName()); } return ticket; } @@ -179,7 +159,7 @@ NodeKey nodeKey = null; try { try { - nodeKey = getRepositoryService().addFileItem(getTicket(true), stream, fileName, mimeType, null); + nodeKey = getRepositoryService().addFileItem(getTicket(false), stream, fileName, mimeType, null); } catch (AccessDeniedException e) { log.warn("Unable to access repository to add file " + fileName + "AccessDeniedException: " + e.getMessage() + " Retrying login."); Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/IRepositoryService.java =================================================================== diff -u -r51fb2a37254f24bb2a805d4ffd54482c779f43fa -r5af735c7b7eded85eca276fe808a667175910267 --- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/IRepositoryService.java (.../IRepositoryService.java) (revision 51fb2a37254f24bb2a805d4ffd54482c779f43fa) +++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/IRepositoryService.java (.../IRepositoryService.java) (revision 5af735c7b7eded85eca276fe808a667175910267) @@ -21,7 +21,6 @@ * **************************************************************** */ - package org.lamsfoundation.lams.contentrepository.service; import java.io.IOException; @@ -31,6 +30,7 @@ import java.util.SortedSet; import org.lamsfoundation.lams.contentrepository.AccessDeniedException; +import org.lamsfoundation.lams.contentrepository.CrWorkspace; import org.lamsfoundation.lams.contentrepository.FileException; import org.lamsfoundation.lams.contentrepository.ICredentials; import org.lamsfoundation.lams.contentrepository.ITicket; @@ -73,7 +73,7 @@ * workspace. If login fails, a LoginException is thrown and * no valid ticket is generated. The credentials object in the ticket * does not contain the password. - * + * * It does not clear the password in the input credentials object. * * @param credentials @@ -95,7 +95,7 @@ * Create a new workspace, with the tool identified in the creditials * as the owner. * It does not clear the password in the credentials - * + * * @param credentials * this user/password must already exist in the repository. Password will be checked. * @param workspaceName @@ -106,19 +106,19 @@ * @throws RepositoryCheckedException * if parameters are missing. */ - public void addWorkspace(ICredentials credentials, String workspaceName) + public CrWorkspace addWorkspace(ICredentials credentials, String workspaceName) throws LoginException, AccessDeniedException, ItemExistsException, RepositoryCheckedException; /** * Create a new repository "user" - usually a tool. - * + * * The password must be at least 6 chars. - * + * * This method will not wipe out the password in the newCredential object. - * + * * At this stage it is publically accessable - may need to move * it to a private management tool if considered to insecure. - * + * * @param newCredential * this user/password will be added to the repository * @throws RepositoryCheckedException @@ -131,9 +131,9 @@ /** * Update a credential. Name cannot change, so really only the password changes - * + * * The password must be at least 6 chars. - * + * * @param oldCredential * the current user/password * @param newCredential @@ -150,7 +150,7 @@ * Add a new file to the repository. This will create * a completely new entry (node) in the repository, starting * with version 1. - * + * * @param ticket * ticket issued on login. Identifies tool and workspace - mandatory * @param istream @@ -175,11 +175,11 @@ /** * Add a new package of files to the repository. If startFile * is not supplied, then it is assumed to be index.html. - * + * * The directory separator character in the paths of the files in the package * will be converted to "/" so that a web style path can be used to * access the file. - * + * * @param ticket * ticket issued on login. Identifies tool and workspace - mandatory * @param dirPath @@ -204,7 +204,7 @@ /** * Update an existing file in the repository. This will create * a new version of this file. - * + * * @param ticket * ticket issued on login. Identifies tool and workspace - mandatory * @param uuid @@ -233,11 +233,11 @@ /** * Add a new package of files to the repository. If startFile * is not supplied, then it is assumed to be index.html. - * + * * The directory separator character in the paths of the files in the package * will be converted to "/" so that a web style path can be used to * access the file. - * + * * @param ticket * ticket issued on login. Identifies tool and workspace - mandatory * @param uuid @@ -298,7 +298,7 @@ * then it uses the latest version of the node as the basis for the new node. *
* This method works for both file nodes and package nodes. - * + * * @param ticket * ticket issued on login. Identifies tool and workspace - mandatory * @param uuid @@ -317,7 +317,7 @@ /** * Get an item from the repository based on the UUID. This * may be either a file or package node. - * + * * @param ticket * ticket issued on login. Identifies tool and workspace - mandatory * @param uuid @@ -334,12 +334,12 @@ * path. Only used to get the content from a package. The * UUID is the id of the package, and relPath is the relative * path within the package. - * + * * If the item is a package and relPath is null, return the package node. - * + * * The relPath must be specified in web format ie use a separator * of "/" not "\". - * + * * @param ticket * ticket issued on login. Identifies tool and workspace - mandatory * @param uuid @@ -366,7 +366,7 @@ /** * Return a list of all the nodes for a package. The first in the list * is the package node. The others are in arbitrary order. - * + * * @param ticket * @param uuid * uuid of the package node @@ -384,7 +384,7 @@ * Get the history for a node. Quite intensive operation the * first time it is run on a node as it has to build all the * data structures. - * + * * @param ticket * ticket issued on login. Identifies tool and workspace - mandatory * @return SortedSet of IVersionDetail objects, ordered by version @@ -444,7 +444,7 @@ /** * Finish using this ticket. No more updates may be used with this ticket * after logout(). Allows any resources to be freed. - * + * * @param ticket * ticket issued on login. Identifies tool and workspace - mandatory */ @@ -457,7 +457,7 @@ * Warning: Once a workspace gets a lot of nodes, this will be * a very very expensive call!!!!! *
- * + * * @param ticket * ticket issued on login. Identifies tool and workspace - mandatory * @return SortedMap key Long uuid, value IVersionDetail version history @@ -481,4 +481,8 @@ */ public void saveFile(ITicket ticket, Long uuid, Long versionId, String toFileName) throws RepositoryCheckedException, AccessDeniedException, ItemNotFoundException, IOException; -} + + public boolean workspaceExists(ICredentials credentials, Long workspaceId); + + public boolean workspaceExists(ICredentials credentials, String workspaceName); +} \ No newline at end of file Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/SimpleRepository.java =================================================================== diff -u -r51fb2a37254f24bb2a805d4ffd54482c779f43fa -r5af735c7b7eded85eca276fe808a667175910267 --- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/SimpleRepository.java (.../SimpleRepository.java) (revision 51fb2a37254f24bb2a805d4ffd54482c779f43fa) +++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/SimpleRepository.java (.../SimpleRepository.java) (revision 5af735c7b7eded85eca276fe808a667175910267) @@ -133,25 +133,11 @@ "Cannot get user details for content repository. User may not be logged in."); } return user.getUserID(); - } else { + } throw new AccessDeniedException( "Cannot get user details for content repository. No session found - user not logged in or the webservice call has not set up the session details."); - } - } - /** - * @param workspaceName - * @return - * @throws WorkspaceNotFoundException - */ - private CrWorkspace getWorkspace(String workspaceName) throws WorkspaceNotFoundException { - // call workspace dao to get the workspace - CrWorkspace workspace = workspaceDAO.findByName(workspaceName); - if (workspace == null) { - throw new WorkspaceNotFoundException("Workspace " + workspaceName + " does not exist."); } - return workspace; - } /** * @param workspaceId @@ -173,6 +159,7 @@ * @see org.lamsfoundation.lams.contentrepository.IRepository#login(org.lamsfoundation.lams.contentrepository. * ICredentials, java.lang.String) */ + @SuppressWarnings("unchecked") @Override public ITicket login(ICredentials credentials, String workspaceName) throws AccessDeniedException, LoginException, WorkspaceNotFoundException { @@ -182,9 +169,15 @@ "Workspace or Credential DAO object missing. Unable to process login."); } - CrWorkspace workspace = getWorkspace(workspaceName); - - if (!credentialDAO.checkCredential(credentials, workspace)) { + CrWorkspace workspace = workspaceDAO.findByName(workspaceName); + if (workspace == null) { + try { + createCredentials(credentials); + workspace = addWorkspace(credentials, workspaceName); + } catch (Exception e) { + throw new RepositoryRuntimeException("Error while creating workspace \"" + workspaceName + "\"", e); + } + } else if (!credentialDAO.checkCredential(credentials, workspace)) { throw new LoginException("Login failed. Password incorrect or not authorised to access this workspace."); } @@ -210,7 +203,7 @@ * if parameters are missing. */ @Override - public void addWorkspace(ICredentials credentials, String workspaceName) + public CrWorkspace addWorkspace(ICredentials credentials, String workspaceName) throws AccessDeniedException, LoginException, ItemExistsException, RepositoryCheckedException { // call workspace dao to check the login and get the workspace @@ -234,6 +227,7 @@ crWorkspace.setName(workspaceName); workspaceDAO.insert(crWorkspace); assignCredentials(credentials, crWorkspace); + return crWorkspace; } /** @@ -346,7 +340,7 @@ } // call workspace dao to get the workspace - CrWorkspace workspace = getWorkspace(workspaceName); + CrWorkspace workspace = workspaceDAO.findByName(workspaceName); if (workspace == null) { throw new WorkspaceNotFoundException("Workspace " + workspaceName + " does not exist."); } @@ -856,6 +850,14 @@ } + public boolean workspaceExists(ICredentials credentials, Long workspaceId) { + return workspaceDAO.find(CrWorkspace.class, workspaceId) != null; + } + + public boolean workspaceExists(ICredentials credentials, String workspaceName) { + return workspaceDAO.findByName(workspaceName) != null; + } + /* ********** setters and getters for DAOs *******************/ /** * @return Returns the workspaceDAO. Index: lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/service/ImageGalleryServiceImpl.java =================================================================== diff -u -rce9f4e0c6d1e5814bf0dcb0fa16ae888a8c854a3 -r5af735c7b7eded85eca276fe808a667175910267 --- lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/service/ImageGalleryServiceImpl.java (.../ImageGalleryServiceImpl.java) (revision ce9f4e0c6d1e5814bf0dcb0fa16ae888a8c854a3) +++ lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/service/ImageGalleryServiceImpl.java (.../ImageGalleryServiceImpl.java) (revision 5af735c7b7eded85eca276fe808a667175910267) @@ -722,9 +722,12 @@ } // don't export following fields - for (LearnerItemRatingCriteria criteria : toolContentObj.getRatingCriterias()) { + Set