Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/client/ToolContentHandler.java =================================================================== RCS file: /usr/local/cvsroot/lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/client/ToolContentHandler.java,v diff -u -r1.17 -r1.18 --- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/client/ToolContentHandler.java 11 May 2016 07:29:18 -0000 1.17 +++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/client/ToolContentHandler.java 4 Jul 2016 09:27:53 -0000 1.18 @@ -21,7 +21,6 @@ * **************************************************************** */ - package org.lamsfoundation.lams.contentrepository.client; import java.io.IOException; @@ -35,11 +34,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; @@ -68,7 +65,7 @@ * Content Repository's applicationContext.xml. The name must be unique to this project. * * For example: - * + * *
* <bean id="blahToolContentHandler" class="your class name here"> * <property name="repositoryService"> <ref bean="repositoryService"/</property> @@ -88,7 +85,7 @@ *
* NodeKey nodeKey = handler.uploadFile(istream, fileName, fileMimeType);
* Long uuid = nodeKey.getUuid();
@@ -137,38 +134,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()); - } - } catch (RepositoryCheckedException e) { - log.error("Unable to get ticket for workspace " + getRepositoryWorkspaceName(), e); - throw e; + 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()); + } + if (doLogin) { + if (cred == null) { + cred = new SimpleCredentials(getRepositoryUser(), getRepositoryId()); } + ticket = getRepositoryService().login(cred, getRepositoryWorkspaceName()); } return ticket; } @@ -208,7 +187,7 @@ /** * Save a directory of files in the content repository. - * + * * @param ticket * ticket issued on login. Identifies tool and workspace - mandatory * @param dirPath @@ -385,7 +364,7 @@ * out.flush(); * return file; * } - * + * * protected byte[] getBytes(File file) throws FileNotFoundException, Exception { * byte[] byteArray = new byte[(int) file.length()]; * FileInputStream stream = new FileInputStream(file); Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/IRepositoryService.java =================================================================== RCS file: /usr/local/cvsroot/lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/IRepositoryService.java,v diff -u -r1.17 -r1.18 --- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/IRepositoryService.java 11 May 2016 07:29:18 -0000 1.17 +++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/IRepositoryService.java 4 Jul 2016 09:27:53 -0000 1.18 @@ -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 =================================================================== RCS file: /usr/local/cvsroot/lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/SimpleRepository.java,v diff -u -r1.18 -r1.19 --- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/SimpleRepository.java 11 May 2016 07:29:18 -0000 1.18 +++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/SimpleRepository.java 4 Jul 2016 09:27:53 -0000 1.19 @@ -21,7 +21,6 @@ * **************************************************************** */ - package org.lamsfoundation.lams.contentrepository.service; import java.io.FileNotFoundException; @@ -87,7 +86,7 @@ * run separately and without suitable AOP support then * each transaction method must check that the credential is okay * or that the ticket is a known ticket (isTicketOkay() method). - * + * * This class also depends on the transactions defined in the * application context for the hibernate sessions to work properly. * If the method isn't transactioned, then there won't be a proper @@ -133,24 +132,10 @@ "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."); } - } + 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; } /** @@ -169,10 +154,11 @@ /* * (non-Javadoc) - * + * * @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,14 +168,20 @@ "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."); } // okay, we should now be able to create a ticket - // make ticket, create new credentials without the password + // make ticket, create new credentials without the password ITicket ticket = new SimpleTicket(workspace.getWorkspaceId()); ticketIdSet.add(ticket.getTicketId()); return ticket; @@ -198,7 +190,7 @@ /** * Add a workspace, giving the credentials as the user of this workspace. * 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 @@ -210,7 +202,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 +226,7 @@ crWorkspace.setName(workspaceName); workspaceDAO.insert(crWorkspace); assignCredentials(credentials, crWorkspace); + return crWorkspace; } /** @@ -272,7 +265,7 @@ * The password must be at least 6 chars. * Possibly this should only be available to an internal management tool * *** Security Risk - I'm converting the password to a string... *** - * + * * @throws LoginException * if the oldCredential fails login test (e.g. wrong password) * @throws RepositoryCheckedException @@ -310,9 +303,9 @@ /** * Checks that a password meets our password criteria. This could be implemented * as a Strategy, but that's overkill! - * + * * Checks that the password is six or more characters. - * + * * @param password * @throws RepositoryCheckedException * if @@ -346,7 +339,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."); } @@ -410,7 +403,7 @@ /* * (non-Javadoc) - * + * * @see * org.lamsfoundation.lams.contentrepository.IRepository#logout(org.lamsfoundation.lams.contentrepository.ITicket) */ @@ -432,7 +425,7 @@ /* * (non-Javadoc) - * + * * @see org.lamsfoundation.lams.contentrepository.IRepository#addFileItem(org.lamsfoundation.lams.contentrepository. * ITicket, java.io.InputStream, java.lang.String, java.lang.String, java.lang.String) */ @@ -458,7 +451,7 @@ /* * (non-Javadoc) - * + * * @see * org.lamsfoundation.lams.contentrepository.IRepository#addPackageItem(org.lamsfoundation.lams.contentrepository. * ITicket, java.lang.String, java.lang.String, java.lang.String) @@ -492,7 +485,7 @@ /* * (non-Javadoc) - * + * * @see org.lamsfoundation.lams.contentrepository.IRepository#getFileItem(org.lamsfoundation.lams.contentrepository. * ITicket, java.lang.Long, java.lang.Long) */ @@ -505,7 +498,7 @@ /* * (non-Javadoc) - * + * * @see org.lamsfoundation.lams.contentrepository.IRepository#getFileItem(org.lamsfoundation.lams.contentrepository. * ITicket, java.lang.Long, java.lang.Long, java.lang.String) */ @@ -536,7 +529,7 @@ /* * (non-Javadoc) - * + * * @see org.lamsfoundation.lams.contentrepository.IRepository#getFileItem(org.lamsfoundation.lams.contentrepository. * ITicket, java.lang.Long, java.lang.Long, java.lang.String) */ @@ -562,7 +555,7 @@ /* * (non-Javadoc) - * + * * @see org.lamsfoundation.lams.contentrepository.IRepository#getNodeList(org.lamsfoundation.lams.contentrepository. * ITicket) */ @@ -588,7 +581,7 @@ /* * (non-Javadoc) - * + * * @see * org.lamsfoundation.lams.contentrepository.IRepository#getVersionHistory(org.lamsfoundation.lams.contentrepository * .ITicket, java.lang.Long) @@ -602,7 +595,7 @@ /* * (non-Javadoc) - * + * * @see * org.lamsfoundation.lams.contentrepository.IRepository#updateFileItem(org.lamsfoundation.lams.contentrepository. * ITicket, java.lang.Long, java.lang.String, java.io.InputStream, java.lang.String, java.lang.String) @@ -633,7 +626,7 @@ /* * (non-Javadoc) - * + * * @see * org.lamsfoundation.lams.contentrepository.IRepository#updatePackageItem(org.lamsfoundation.lams.contentrepository * .ITicket, java.lang.Long, java.lang.String, java.lang.String, java.lang.String) @@ -696,7 +689,7 @@ /* * (non-Javadoc) - * + * * @see * org.lamsfoundation.lams.contentrepository.IRepository#copyNodeVersion(org.lamsfoundation.lams.contentrepository. * ITicket, java.lang.Long, java.lang.Long) @@ -729,7 +722,7 @@ /* * (non-Javadoc) - * + * * @see * org.lamsfoundation.lams.contentrepository.IRepository#saveFile(org.lamsfoundation.lams.contentrepository.ITicket, * java.lang.Long, java.lang.String, java.lang.String, java.lang.String) @@ -810,7 +803,7 @@ /* * (non-Javadoc) - * + * * @see * org.lamsfoundation.lams.contentrepository.IRepository#updatePackageItem(org.lamsfoundation.lams.contentrepository * .ITicket, java.lang.Long, java.lang.String, java.lang.String, java.lang.String) @@ -836,7 +829,7 @@ /* * (non-Javadoc) - * + * * @see * org.lamsfoundation.lams.contentrepository.IRepository#updatePackageItem(org.lamsfoundation.lams.contentrepository * .ITicket, java.lang.Long, java.lang.String, java.lang.String, java.lang.String) @@ -856,6 +849,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 =================================================================== RCS file: /usr/local/cvsroot/lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/service/ImageGalleryServiceImpl.java,v diff -u -r1.47 -r1.48 --- lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/service/ImageGalleryServiceImpl.java 13 Jun 2016 14:52:57 -0000 1.47 +++ lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/service/ImageGalleryServiceImpl.java 4 Jul 2016 09:27:55 -0000 1.48 @@ -791,8 +791,11 @@ } // don't export following fields - for (LearnerItemRatingCriteria criteria : toolContentObj.getRatingCriterias()) { - criteria.setToolContentId(null); + Setcriterias = toolContentObj.getRatingCriterias(); + if (criterias != null) { + for (LearnerItemRatingCriteria criteria : criterias) { + criteria.setToolContentId(null); + } } // set ImageGalleryToolContentHandler as null to avoid copy file node in repository again. @@ -857,8 +860,11 @@ // reset it to new toolContentId toolContentObj.setContentId(toolContentId); - for (LearnerItemRatingCriteria criteria : toolContentObj.getRatingCriterias()) { - criteria.setToolContentId(toolContentId); + Set criterias = toolContentObj.getRatingCriterias(); + if (criterias != null) { + for (LearnerItemRatingCriteria criteria : criterias) { + criteria.setToolContentId(toolContentId); + } } ImageGalleryUser user = imageGalleryUserDao.getUserByUserIDAndContentID(new Long(newUserUid.longValue()), toolContentId); Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaServicePOJO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaServicePOJO.java,v diff -u -r1.138 -r1.139 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaServicePOJO.java 13 Jun 2016 14:52:04 -0000 1.138 +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaServicePOJO.java 4 Jul 2016 09:27:54 -0000 1.139 @@ -935,8 +935,11 @@ // reset it to new toolContentID toolContentObj.setQaContentId(toolContentID); toolContentObj.setCreatedBy(newUserUid); - for (LearnerItemRatingCriteria criteria : toolContentObj.getRatingCriterias()) { - criteria.setToolContentId(toolContentID); + Set criterias = toolContentObj.getRatingCriterias(); + if (criterias != null) { + for (LearnerItemRatingCriteria criteria : toolContentObj.getRatingCriterias()) { + criteria.setToolContentId(toolContentID); + } } // set back the tool content