Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/service/ExportToolContentService.java =================================================================== diff -u -r9ad43dec7eb0960145bc92da0ae6435a2c412a58 -r2fc4a8b63d3086df2ab75ada593e5d36528d6281 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/service/ExportToolContentService.java (.../ExportToolContentService.java) (revision 9ad43dec7eb0960145bc92da0ae6435a2c412a58) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/service/ExportToolContentService.java (.../ExportToolContentService.java) (revision 2fc4a8b63d3086df2ab75ada593e5d36528d6281) @@ -539,19 +539,11 @@ } return folder; } - /** - * Import tool content - * TODO Remove once all tools converted to supply user id. - */ - public Object importToolContent(String toolContentPath, IToolContentHandler toolContentHandler) throws ImportToolContentException{ - log.error("importToolContent(String toolContentPath, IToolContentHandler toolContentHandler) to be removed - it sets the owner of files in the content repository to 1. Some tool needs to be updated."); - return importToolContent(toolContentPath, toolContentHandler, new Integer(1)); - } /** * Import tool content */ - public Object importToolContent(String toolContentPath, IToolContentHandler toolContentHandler, Integer userId ) throws ImportToolContentException{ + public Object importToolContent(String toolContentPath, IToolContentHandler toolContentHandler) throws ImportToolContentException{ Object toolPOJO = null; // change xml to Tool POJO XStream toolXml = new XStream(); @@ -630,10 +622,10 @@ //upload to repository: file or pacakge NodeKey key; if(!isPackage) - key = toolContentHandler.uploadFile(is,fileName,mimeType,fileProperty, userId); + key = toolContentHandler.uploadFile(is,fileName,mimeType,fileProperty); else{ String packageDirectory = ZipFileUtil.expandZip(is, realFileName); - key = toolContentHandler.uploadPackage(packageDirectory,initalItem, userId); + key = toolContentHandler.uploadPackage(packageDirectory,initalItem); } //refresh file node Uuid and Version value to latest. Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/service/IExportToolContentService.java =================================================================== diff -u -r9ad43dec7eb0960145bc92da0ae6435a2c412a58 -r2fc4a8b63d3086df2ab75ada593e5d36528d6281 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/service/IExportToolContentService.java (.../IExportToolContentService.java) (revision 9ad43dec7eb0960145bc92da0ae6435a2c412a58) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/service/IExportToolContentService.java (.../IExportToolContentService.java) (revision 2fc4a8b63d3086df2ab75ada593e5d36528d6281) @@ -96,18 +96,8 @@ /** * Import the tool content. This is called by tools to do the actual content import, once the tool * has set up whatever it needs to do. - * TODO To be removed from the system and replaced with the call with the user id. - * @Deprecated */ Object importToolContent(String toolContentPath, IToolContentHandler toolContentHandler) - throws ImportToolContentException; - - /** - * Import the tool content. This is called by tools to do the actual content import, once the tool - * has set up whatever it needs to do. To be removed from the system and replaced with the call with the - * user id. - */ - Object importToolContent(String toolContentPath, IToolContentHandler toolContentHandler, Integer userId) throws ImportToolContentException; /** Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/client/IToolContentHandler.java =================================================================== diff -u -r9ad43dec7eb0960145bc92da0ae6435a2c412a58 -r2fc4a8b63d3086df2ab75ada593e5d36528d6281 --- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/client/IToolContentHandler.java (.../IToolContentHandler.java) (revision 9ad43dec7eb0960145bc92da0ae6435a2c412a58) +++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/client/IToolContentHandler.java (.../IToolContentHandler.java) (revision 2fc4a8b63d3086df2ab75ada593e5d36528d6281) @@ -87,9 +87,6 @@ /** * Save a file in the content repository. * - * TODO To be removed from the system and replaced with the call with the user id. - * @Deprecated - * * @param stream Input filestream. Mandatory. * @param fileName Input filename. Mandatory. * @param mimeType Mimetype of file. Optional. @@ -105,35 +102,8 @@ RepositoryCheckedException; /** - * Save a file in the content repository. - * - * @param stream Input filestream. Mandatory. - * @param fileName Input filename. Mandatory. - * @param mimeType Mimetype of file. Optional. - * @param fileProperty is this for online or offline instructions? Should be TYPE_ONLINE or TYPE_OFFLINE. Mandatory. - * @return key to the new content repository node - * @throws InvalidParameterException One of the mandatory parameters is missing. - * @throws FileException An error occured writing the input stream to disk. - * @throws RepositoryCheckedException Some other error occured. - */ - public abstract NodeKey uploadFile(InputStream stream, String fileName, - String mimeType, String fileProperty, Integer userId) - throws RepositoryCheckedException, InvalidParameterException, - RepositoryCheckedException; - - /** * Save a directory of files in the content repository. * - * TODO To be removed from the system and replaced with the call with the user id. - * @Deprecated - */ - public abstract NodeKey uploadPackage(String dirPath, String startFile) - throws RepositoryCheckedException, InvalidParameterException, - RepositoryCheckedException; - - /** - * Save a directory of files in the content repository. - * * @param ticket ticket issued on login. Identifies tool and workspace - mandatory * @param dirPath directory path containing files - mandatory * @param startFile relative path of initial file - optional @@ -142,7 +112,7 @@ * @throws FileException An error occured writing the files to disk. * @throws RepositoryCheckedException Some other error occured. */ - public abstract NodeKey uploadPackage(String dirPath, String startFile, Integer userId) + public abstract NodeKey uploadPackage(String dirPath, String startFile) throws RepositoryCheckedException, InvalidParameterException, RepositoryCheckedException; @@ -157,26 +127,14 @@ /** * Copy an entry in the content repository. - * TODO To be removed from the system and replaced with the call with the user id. - * @Deprecated - * + * * @param uuid id of the file node. Mandatory * @throws ItemNotFoundException Node to copy cannot be found * @throws RepositoryCheckedException Some other error occured. */ public abstract NodeKey copyFile(Long uuid) throws ItemNotFoundException, RepositoryCheckedException; - /** - * Copy an entry in the content repository. - * - * @param uuid id of the file node. Mandatory - * @throws ItemNotFoundException Node to copy cannot be found - * @throws RepositoryCheckedException Some other error occured. - */ - public abstract NodeKey copyFile(Long uuid, Integer userId) - throws ItemNotFoundException, RepositoryCheckedException; - /** Get a file node. * @param uuid id of the file node. Mandatory * @throws FileException An error occured writing the input stream to disk. Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/client/ToolContentHandler.java =================================================================== diff -u -r9ad43dec7eb0960145bc92da0ae6435a2c412a58 -r2fc4a8b63d3086df2ab75ada593e5d36528d6281 --- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/client/ToolContentHandler.java (.../ToolContentHandler.java) (revision 9ad43dec7eb0960145bc92da0ae6435a2c412a58) +++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/client/ToolContentHandler.java (.../ToolContentHandler.java) (revision 2fc4a8b63d3086df2ab75ada593e5d36528d6281) @@ -188,14 +188,6 @@ } /** - * TODO To be removed from the system and replaced with the call with the user id. - */ - public NodeKey uploadFile(InputStream stream, String fileName, String mimeType, String fileProperty) throws RepositoryCheckedException, InvalidParameterException, RepositoryCheckedException { - log.error("uploadFile(InputStream stream, String fileName, String mimeType, String fileProperty) to be removed - it sets the owner of files in the content repository to 1. Some tool needs to be updated."); - return uploadFile(stream, fileName, mimeType, fileProperty, new Integer(1)); - } - - /** * Save a file in the content repository. * * @param stream Input filestream. Mandatory. @@ -207,18 +199,18 @@ * @throws FileException An error occured writing the input stream to disk. * @throws RepositoryCheckedException Some other error occured. */ - public NodeKey uploadFile(InputStream stream, String fileName, String mimeType, String fileProperty, Integer userId) throws RepositoryCheckedException, InvalidParameterException, RepositoryCheckedException { + public NodeKey uploadFile(InputStream stream, String fileName, String mimeType, String fileProperty) throws RepositoryCheckedException, InvalidParameterException, RepositoryCheckedException { if ( fileProperty == null ) throw new InvalidParameterException("uploadFile: fileProperty parameter empty. Should be either TYPE_ONLINE or TYPE_OFFLINE"); NodeKey nodeKey = null; try { try { - nodeKey = getRepositoryService().addFileItem(getTicket(false), stream, fileName, mimeType, null, userId); + 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."); - nodeKey = getRepositoryService().addFileItem(getTicket(true), stream, fileName, mimeType, null, userId); + nodeKey = getRepositoryService().addFileItem(getTicket(true), stream, fileName, mimeType, null); } try { @@ -264,11 +256,11 @@ NodeKey nodeKey = null; try { try { - nodeKey = getRepositoryService().addPackageItem(getTicket(false), dirPath, startFile, null, userId); + nodeKey = getRepositoryService().addPackageItem(getTicket(false), dirPath, startFile, null); } catch (AccessDeniedException e) { log.warn("Unable to access repository to add directory of files. AccessDeniedException: " +e.getMessage()+" Retrying login."); - nodeKey = getRepositoryService().addPackageItem(getTicket(true), dirPath, startFile, null, userId); + nodeKey = getRepositoryService().addPackageItem(getTicket(true), dirPath, startFile, null); } } catch (RepositoryCheckedException e2) { @@ -330,11 +322,11 @@ NodeKey nodeKey = null; try { try { - nodeKey = getRepositoryService().copyNodeVersion(getTicket(false), uuid, null, userId); + nodeKey = getRepositoryService().copyNodeVersion(getTicket(false), uuid, null); } catch (AccessDeniedException e) { log.warn("Unable to access repository to add copy node "+uuid +"AccessDeniedException: "+e.getMessage()+" Retrying login."); - nodeKey = getRepositoryService().copyNodeVersion(getTicket(true), uuid, null, userId); + nodeKey = getRepositoryService().copyNodeVersion(getTicket(true), uuid, null); } } catch (ItemNotFoundException e) { log.warn("Unable to to copy node "+uuid Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/IRepositoryService.java =================================================================== diff -u -r9ad43dec7eb0960145bc92da0ae6435a2c412a58 -r2fc4a8b63d3086df2ab75ada593e5d36528d6281 --- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/IRepositoryService.java (.../IRepositoryService.java) (revision 9ad43dec7eb0960145bc92da0ae6435a2c412a58) +++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/IRepositoryService.java (.../IRepositoryService.java) (revision 2fc4a8b63d3086df2ab75ada593e5d36528d6281) @@ -131,15 +131,6 @@ public void updateCredentials(ICredentials oldCredential, ICredentials newCredential) throws AccessDeniedException, RepositoryCheckedException; - /** - * TODO To be removed from the system and replaced with the call with the user id. - * @Deprecated - */ - public abstract NodeKey addFileItem(ITicket ticket, InputStream istream, String filename, - String mimeType, String versionDescription) - throws FileException, AccessDeniedException, InvalidParameterException; - - /** * Add a new file to the repository. This will create * a completely new entry (node) in the repository, starting @@ -148,15 +139,14 @@ * @param istream new file, as an input stream - mandatory * @param mimeType mime type of file - optional * @param versionDescription human readable comment about the version - optional - * @param userId user who is creating this node - mandatory * @return nodeKey (uuid and version) * @throws AccessDeniedException if ticket doesn't allow this action * @throws FileException if unable to save node due to file error * @throws InvalidParameterException if a required parameter is missing * @throws RepositoryRuntimeException if any internal errors have occured */ public abstract NodeKey addFileItem(ITicket ticket, InputStream istream, String filename, - String mimeType, String versionDescription, Integer userId) + String mimeType, String versionDescription) throws FileException, AccessDeniedException, InvalidParameterException; /** @@ -171,15 +161,14 @@ * @param dirPath directory path containing files - mandatory * @param startFile relative path of initial file - optional * @param versionDescription human readable comment about the version - optional - * @param userId user who is creating this node - mandatory * @return nodeKey (uuid and version) * @throws AccessDeniedException if ticket doesn't allow this action * @throws FileException if unable to save node due to file error * @throws InvalidParameterException if a required parameter is missing * @throws RepositoryRuntimeException if any internal errors have occured */ public abstract NodeKey addPackageItem(ITicket ticket, String dirPath, String startFile, - String versionDescription, Integer userId) + String versionDescription) throws AccessDeniedException, InvalidParameterException, FileException; /** @@ -190,7 +179,6 @@ * @param istream new file, as an input stream - mandatory * @param versionDescription human readable comment about the version - optional * @param mimeType mime type of file - optional - * @param userId user who is creating this node - mandatory * @throws AccessDeniedException if ticket doesn't allow this action * @throws ItemNotFoundException if node with uuid cannot be found * @throws FileException if unable to save node due to file error @@ -199,7 +187,7 @@ */ public NodeKey updateFileItem(ITicket ticket, Long uuid, String filename, InputStream istream, String mimeType, - String versionDescription, Integer userId) + String versionDescription) throws AccessDeniedException, ItemNotFoundException, FileException, InvalidParameterException; @@ -217,15 +205,14 @@ * @param startFile relative path of initial file - optional * @param versionDescription human readable comment about the version - optional * @return nodeKey (uuid and version) - * @param userId user who is creating this node - mandatory * @throws AccessDeniedException if ticket doesn't allow this action * @throws ItemNotFoundException if node with uuid cannot be found * @throws FileException if unable to save node due to file error * @throws InvalidParameterException if a required parameter is missing * @throws RepositoryRuntimeException if any internal errors have occured */ public abstract NodeKey updatePackageItem(ITicket ticket, Long uuid, String dirPath, - String startFile, String versionDescription, Integer userId) + String startFile, String versionDescription) throws AccessDeniedException, ItemNotFoundException, FileException, InvalidParameterException ; @@ -259,12 +246,11 @@ * @param ticket ticket issued on login. Identifies tool and workspace - mandatory * @param uuid id of the file/package - mandatory * @param version desired version - if null gets latest version - * @param userId user who is creating this node - mandatory * @return nodeKey (uuid and version) * @throws AccessDeniedException if the ticket is invalid * @throws ItemNotFoundException if the node cannot be found */ - public NodeKey copyNodeVersion(ITicket ticket, Long uuid, Long versionId, Integer userId) throws AccessDeniedException, ItemNotFoundException; + public NodeKey copyNodeVersion(ITicket ticket, Long uuid, Long versionId) throws AccessDeniedException, ItemNotFoundException; /** * Get an item from the repository based on the UUID. This Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/SimpleRepository.java =================================================================== diff -u -r9ad43dec7eb0960145bc92da0ae6435a2c412a58 -r2fc4a8b63d3086df2ab75ada593e5d36528d6281 --- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/SimpleRepository.java (.../SimpleRepository.java) (revision 9ad43dec7eb0960145bc92da0ae6435a2c412a58) +++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/SimpleRepository.java (.../SimpleRepository.java) (revision 2fc4a8b63d3086df2ab75ada593e5d36528d6281) @@ -38,6 +38,8 @@ import java.util.SortedSet; import java.util.TreeMap; +import javax.servlet.http.HttpSession; + import org.apache.log4j.Logger; import org.lamsfoundation.lams.contentrepository.AccessDeniedException; import org.lamsfoundation.lams.contentrepository.CrCredential; @@ -62,14 +64,15 @@ import org.lamsfoundation.lams.contentrepository.ValidationException; import org.lamsfoundation.lams.contentrepository.ValueFormatException; import org.lamsfoundation.lams.contentrepository.WorkspaceNotFoundException; -import org.lamsfoundation.lams.contentrepository.client.IToolContentHandler; import org.lamsfoundation.lams.contentrepository.dao.ICredentialDAO; import org.lamsfoundation.lams.contentrepository.dao.IWorkspaceDAO; -import org.lamsfoundation.lams.learningdesign.service.ImportToolContentException; +import org.lamsfoundation.lams.usermanagement.dto.UserDTO; import org.lamsfoundation.lams.util.FileUtil; import org.lamsfoundation.lams.util.FileUtilException; import org.lamsfoundation.lams.util.zipfile.ZipFileUtil; import org.lamsfoundation.lams.util.zipfile.ZipFileUtilException; +import org.lamsfoundation.lams.web.session.SessionManager; +import org.lamsfoundation.lams.web.util.AttributeNames; /** @@ -115,6 +118,20 @@ /* ********** Whole of repository methods - login, logout, addWorkspace, etc ****/ + /** + * Get the current user from the user's session. This is used to record the user + * who creates piece of content in the content repository. By doing it here, the + * tools do not have to be modified nor do we rely on other web-apps to tell + * us the correct user. + */ + private Integer getCurrentUserId() throws AccessDeniedException { + HttpSession ss = SessionManager.getSession(); + UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); + if ( user == null ) { + throw new AccessDeniedException("Cannot get user details for content repository. User may not be logged in."); + } + return user.getUserID(); + } /** * @param workspaceName * @return @@ -361,29 +378,17 @@ return ( ticket != null && ticketIdSet.contains(ticket.getTicketId()) ); } - /** - * Import tool content - * TODO Remove once all tools converted to supply user id. - */ - public NodeKey addFileItem(ITicket ticket, InputStream istream, - String filename, String mimeType, String versionDescription) - throws FileException, AccessDeniedException, - InvalidParameterException { - log.error("addFileItem() to be removed - it sets the owner of files in the content repository to 1. Some tool needs to be updated."); - return addFileItem(ticket, istream, - filename, mimeType, versionDescription, new Integer(1)); - } - /* (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) */ public NodeKey addFileItem(ITicket ticket, InputStream istream, - String filename, String mimeType, String versionDescription, Integer userId) + String filename, String mimeType, String versionDescription) throws FileException, AccessDeniedException, InvalidParameterException { - try { + try { CrWorkspace workspace = getWorkspace(ticket.getWorkspaceId()); + Integer userId = getCurrentUserId(); SimpleVersionedNode initialNodeVersion = nodeFactory.createFileNode(workspace, null, null, istream, filename, mimeType, versionDescription, userId); initialNodeVersion.save(); @@ -404,7 +409,7 @@ * @see org.lamsfoundation.lams.contentrepository.IRepository#addPackageItem(org.lamsfoundation.lams.contentrepository.ITicket, java.lang.String, java.lang.String, java.lang.String) */ public NodeKey addPackageItem(ITicket ticket, String dirPath, - String startFile, String versionDescription, Integer userId) + String startFile, String versionDescription) throws AccessDeniedException, InvalidParameterException, FileException { @@ -418,6 +423,7 @@ +e.getMessage(), e); } + Integer userId = getCurrentUserId(); SimpleVersionedNode packageNode = null; packageNode = nodeFactory.createPackageNode(workspace, startFile, versionDescription, userId); @@ -525,10 +531,11 @@ * @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) */ public NodeKey updateFileItem(ITicket ticket, Long uuid, String filename, - InputStream istream, String mimeType, String versionDescription, Integer userId) + InputStream istream, String mimeType, String versionDescription) throws AccessDeniedException, ItemNotFoundException, FileException, InvalidParameterException { + Integer userId = getCurrentUserId(); SimpleVersionedNode newNodeVersion = nodeFactory.getNodeNewVersion(ticket.getWorkspaceId(), uuid, null, versionDescription, userId); @@ -550,10 +557,11 @@ * @see org.lamsfoundation.lams.contentrepository.IRepository#updatePackageItem(org.lamsfoundation.lams.contentrepository.ITicket, java.lang.Long, java.lang.String, java.lang.String, java.lang.String) */ public NodeKey updatePackageItem(ITicket ticket, Long uuid, String dirPath, - String startFile, String versionDescription, Integer userId) + String startFile, String versionDescription) throws AccessDeniedException, ItemNotFoundException, FileException, InvalidParameterException { + Integer userId = getCurrentUserId(); SimpleVersionedNode newNodeVersion = nodeFactory.getNodeNewVersion(ticket.getWorkspaceId(), uuid, null, versionDescription, userId); @@ -604,9 +612,10 @@ /* (non-Javadoc) * @see org.lamsfoundation.lams.contentrepository.IRepository#copyNodeVersion(org.lamsfoundation.lams.contentrepository.ITicket, java.lang.Long, java.lang.Long) */ - public NodeKey copyNodeVersion(ITicket ticket, Long uuid, Long versionId, Integer userId) throws AccessDeniedException, ItemNotFoundException { + public NodeKey copyNodeVersion(ITicket ticket, Long uuid, Long versionId) throws AccessDeniedException, ItemNotFoundException { + Integer userId = getCurrentUserId(); try { SimpleVersionedNode originalNode = nodeFactory.getNode(ticket.getWorkspaceId(),uuid,versionId); SimpleVersionedNode newNode = nodeFactory.copy(originalNode, userId); Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/struts/action/AddFileContentAction.java =================================================================== diff -u -r9ad43dec7eb0960145bc92da0ae6435a2c412a58 -r2fc4a8b63d3086df2ab75ada593e5d36528d6281 --- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/struts/action/AddFileContentAction.java (.../AddFileContentAction.java) (revision 9ad43dec7eb0960145bc92da0ae6435a2c412a58) +++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/struts/action/AddFileContentAction.java (.../AddFileContentAction.java) (revision 2fc4a8b63d3086df2ab75ada593e5d36528d6281) @@ -121,11 +121,11 @@ if ( uuid != null ) { // create a new version of this node nodeKey = getRepository().updateFileItem(ticket, uuid, filename, - is, contentType, versionDescription, dummyUserId); + is, contentType, versionDescription); } else { // create a new node nodeKey = getRepository().addFileItem(ticket, is, filename, - contentType, versionDescription, dummyUserId); + contentType, versionDescription); } // normally the application would store the node key and @@ -199,10 +199,10 @@ if ( uuid != null ) { // create a new version of this node nodeKey = getRepository().updatePackageItem(ticket, uuid, dirName, - entryString, versionDescription, dummyUserId); + entryString, versionDescription); } else { // create a new node - nodeKey = getRepository().addPackageItem(ticket,dirName, entryString, versionDescription, dummyUserId); + nodeKey = getRepository().addPackageItem(ticket,dirName, entryString, versionDescription); } // normally the application would store the node key and Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/struts/action/NodeSelectionAction.java =================================================================== diff -u -r9ad43dec7eb0960145bc92da0ae6435a2c412a58 -r2fc4a8b63d3086df2ab75ada593e5d36528d6281 --- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/struts/action/NodeSelectionAction.java (.../NodeSelectionAction.java) (revision 9ad43dec7eb0960145bc92da0ae6435a2c412a58) +++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/struts/action/NodeSelectionAction.java (.../NodeSelectionAction.java) (revision 2fc4a8b63d3086df2ab75ada593e5d36528d6281) @@ -305,7 +305,7 @@ log.debug("Copy node "+uuid+" version "+version); try { - NodeKey key = getRepository().copyNodeVersion(ticket,uuid,version, AddFileContentAction.dummyUserId); + NodeKey key = getRepository().copyNodeVersion(ticket,uuid,version); log.info("Copy node, new ids "+key); return getList(mapping,form,request,response); Index: lams_contentrepository/test/java/org/lamsfoundation/lams/contentrepository/client/TestToolContentHandlerImpl.java =================================================================== diff -u -r9ad43dec7eb0960145bc92da0ae6435a2c412a58 -r2fc4a8b63d3086df2ab75ada593e5d36528d6281 --- lams_contentrepository/test/java/org/lamsfoundation/lams/contentrepository/client/TestToolContentHandlerImpl.java (.../TestToolContentHandlerImpl.java) (revision 9ad43dec7eb0960145bc92da0ae6435a2c412a58) +++ lams_contentrepository/test/java/org/lamsfoundation/lams/contentrepository/client/TestToolContentHandlerImpl.java (.../TestToolContentHandlerImpl.java) (revision 2fc4a8b63d3086df2ab75ada593e5d36528d6281) @@ -104,9 +104,9 @@ public void testUploadFile() { try { NodeKey offlineNodeKey = handler.uploadFile(CRResources.getSingleFile(), CRResources.singleFileName, - CRResources.singleFileMimeType, ToolContentHandlerImpl.TYPE_OFFLINE, mmmUser); + CRResources.singleFileMimeType, ToolContentHandlerImpl.TYPE_OFFLINE); NodeKey onlineNodeKey = handler.uploadFile(CRResources.getSingleFile(), CRResources.singleFileName, - CRResources.singleFileMimeType, ToolContentHandlerImpl.TYPE_ONLINE, mmmUser); + CRResources.singleFileMimeType, ToolContentHandlerImpl.TYPE_ONLINE); Long uuid = offlineNodeKey.getUuid(); IVersionedNode node = handler.getFileNode(uuid); @@ -137,7 +137,7 @@ try { // unpack the zip file so we have a directory to play with String tempDir = ZipFileUtil.expandZip(CRResources.getZipFile(), CRResources.zipFileName); - NodeKey nodeKey = handler.uploadPackage(tempDir, "index.html", mmmUser); + NodeKey nodeKey = handler.uploadPackage(tempDir, "index.html"); Long uuid = nodeKey.getUuid(); IVersionedNode node = handler.getFileNode(uuid); Index: lams_contentrepository/test/java/org/lamsfoundation/lams/contentrepository/service/TestSimpleRepository.java =================================================================== diff -u -r9ad43dec7eb0960145bc92da0ae6435a2c412a58 -r2fc4a8b63d3086df2ab75ada593e5d36528d6281 --- lams_contentrepository/test/java/org/lamsfoundation/lams/contentrepository/service/TestSimpleRepository.java (.../TestSimpleRepository.java) (revision 9ad43dec7eb0960145bc92da0ae6435a2c412a58) +++ lams_contentrepository/test/java/org/lamsfoundation/lams/contentrepository/service/TestSimpleRepository.java (.../TestSimpleRepository.java) (revision 2fc4a8b63d3086df2ab75ada593e5d36528d6281) @@ -436,15 +436,15 @@ try { if ( uuid == null ) { // new file - keys = repository.addFileItem(ticket, file, filename, null, v1Description, mmmUser); + keys = repository.addFileItem(ticket, file, filename, null, v1Description); assertTrue("File save returns uuid",keys != null && keys.getUuid() != null); assertTrue("File save got expected version "+expectedVersion, keys != null && keys.getVersion() != null && keys.getVersion().equals(expectedVersion)); } else { // update existing node keys = repository.updateFileItem(ticket, uuid, filename, - file, null, v2Description, mmmUser); + file, null, v2Description); assertTrue("File save returns same uuid",keys != null && keys.getUuid().equals(uuid)); assertTrue("File save got expected version "+expectedVersion, keys != null && keys.getVersion() != null @@ -484,8 +484,8 @@ // copy each version of the file node try { - NodeKey copy1 = repository.copyNodeVersion(ticket, keys.getUuid(), one, mmmUser); - NodeKey copylatest = repository.copyNodeVersion(ticket, keys.getUuid(), null, mmmUser); + NodeKey copy1 = repository.copyNodeVersion(ticket, keys.getUuid(), one); + NodeKey copylatest = repository.copyNodeVersion(ticket, keys.getUuid(), null); assertNotSame("Copy 1 is a different uuid to the original.", copy1.getUuid(), keys.getUuid()); checkFileNodeExist(fileDAO, copy1.getUuid(), one, 1, v1Description); @@ -562,13 +562,13 @@ directory.list(); if ( uuid == null ) { - keys = repository.addPackageItem(ticket, tempDir, "index.html", v1Description, mmmUser); + keys = repository.addPackageItem(ticket, tempDir, "index.html", v1Description); assertTrue("Package save returns uuid",keys != null && keys.getUuid() != null); assertTrue("Package save got version 1", keys != null && keys.getVersion() != null && keys.getVersion().longValue() == 1); } else { - keys = repository.updatePackageItem(ticket, uuid, tempDir, "index.html", v2Description, mmmUser); + keys = repository.updatePackageItem(ticket, uuid, tempDir, "index.html", v2Description); assertTrue("Package save returns uuid",keys != null && keys.getUuid() != null); assertTrue("Package save got version >1", keys != null && keys.getVersion() != null @@ -606,7 +606,7 @@ // copy the package node try { - NodeKey copy = repository.copyNodeVersion(ticket, keys.getUuid(), null, mmmUser); + NodeKey copy = repository.copyNodeVersion(ticket, keys.getUuid(), null); assertNotSame("Copy 1 is a different uuid to the original.", copy.getUuid(), keys.getUuid()); checkPackage(copy); Index: lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/NoticeboardContent.java =================================================================== diff -u -r76f7b5fee0d226d36814affd2b6888ff605ee08b -r2fc4a8b63d3086df2ab75ada593e5d36528d6281 --- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/NoticeboardContent.java (.../NoticeboardContent.java) (revision 76f7b5fee0d226d36814affd2b6888ff605ee08b) +++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/NoticeboardContent.java (.../NoticeboardContent.java) (revision 2fc4a8b63d3086df2ab75ada593e5d36528d6281) @@ -31,6 +31,7 @@ import java.util.Set; import org.lamsfoundation.lams.contentrepository.ItemNotFoundException; +import org.lamsfoundation.lams.contentrepository.NodeKey; import org.lamsfoundation.lams.contentrepository.RepositoryCheckedException; import org.lamsfoundation.lams.contentrepository.client.IToolContentHandler; @@ -392,9 +393,17 @@ while (iter.hasNext()) { NoticeboardAttachment element = (NoticeboardAttachment) iter.next(); NoticeboardAttachment newAttachment = new NoticeboardAttachment(newContent, element.getFilename(), element.isOnlineFile()); - // point to the existing tool content - newAttachment.setUuid(element.getUuid()); - newAttachment.setVersionId(element.getVersionId()); + if(toolContentHandler != null){ + //if it is not null, copy file node and refresh uuid and version + NodeKey keys = toolContentHandler.copyFile(element.getUuid()); + newAttachment.setUuid(keys.getUuid()); + newAttachment.setVersionId(keys.getVersion()); + }else{ + //keep old value + newAttachment.setUuid(element.getUuid()); + newAttachment.setVersionId(element.getVersionId()); + } + newAttachmentSet.add(newAttachment); } newContent.setNbAttachments(newAttachmentSet); Index: lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/service/INoticeboardService.java =================================================================== diff -u -r76f7b5fee0d226d36814affd2b6888ff605ee08b -r2fc4a8b63d3086df2ab75ada593e5d36528d6281 --- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/service/INoticeboardService.java (.../INoticeboardService.java) (revision 76f7b5fee0d226d36814affd2b6888ff605ee08b) +++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/service/INoticeboardService.java (.../INoticeboardService.java) (revision 2fc4a8b63d3086df2ab75ada593e5d36528d6281) @@ -84,16 +84,14 @@ /** *
Delete the given instance of NoticeboardContent with the
- * given tool content id nbContentId
. Does not remove
- * any attachments as they may be shared with another design.
+ * given tool content id nbContentId
*
* @param nbContentId The tool content Id.
*/
public void removeNoticeboard(Long nbContentId);
/**
- *
Delete the given instance of NoticeboardContent. Does not remove - * any attachments as they may be shared with another design.
+ *Delete the given instance of NoticeboardContent
* * @param nbContent The instance of NoticeboardContent to delete. */ @@ -304,8 +302,7 @@ public void saveAttachment(NoticeboardContent content, NoticeboardAttachment attachment); /** - * Removes the NoticeboardAttachment object from the database. Does not remove - * the actual file from the content repository as they may be shared with another design. + * Removes the NoticeboardAttachment object from the database. * @param content The overall noticeboard content object to which the attachment is to be added * @param attachment The instance of NoticeboardAttachment to delete. */ @@ -315,7 +312,7 @@ * Add a file to the content repository. Does not add a record to the noticeboard tables. * @throws RepositoryCheckedException */ - public NodeKey uploadFile(InputStream istream, String filename, String contentType, String fileType, Integer userId) throws RepositoryCheckedException; + public NodeKey uploadFile(InputStream istream, String filename, String contentType, String fileType) throws RepositoryCheckedException; /** * This method retrieves the default content id. Index: lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/service/NoticeboardServicePOJO.java =================================================================== diff -u -r76f7b5fee0d226d36814affd2b6888ff605ee08b -r2fc4a8b63d3086df2ab75ada593e5d36528d6281 --- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/service/NoticeboardServicePOJO.java (.../NoticeboardServicePOJO.java) (revision 76f7b5fee0d226d36814affd2b6888ff605ee08b) +++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/service/NoticeboardServicePOJO.java (.../NoticeboardServicePOJO.java) (revision 2fc4a8b63d3086df2ab75ada593e5d36528d6281) @@ -745,6 +745,7 @@ { attachment.setNbContent(null); content.getNbAttachments().remove(attachment); + nbToolContentHandler.deleteFile(attachment.getUuid()); saveNoticeboard(content); } catch (DataAccessException e) @@ -755,10 +756,10 @@ } /** @throws RepositoryCheckedException - * @see org.lamsfoundation.lams.tool.noticeboard.service.INoticeboardService#uploadFile(java.io.InputStream, java.lang.String, java.lang.String, java.lang.String, java.lang.Integer) */ - public NodeKey uploadFile(InputStream istream, String filename, String contentType, String fileType, Integer userId) throws RepositoryCheckedException + * @see org.lamsfoundation.lams.tool.noticeboard.service.INoticeboardService#uploadFile(java.io.InputStream, java.lang.String, java.lang.String, java.lang.String) */ + public NodeKey uploadFile(InputStream istream, String filename, String contentType, String fileType) throws RepositoryCheckedException { - return nbToolContentHandler.uploadFile(istream, filename, contentType, fileType, userId); + return nbToolContentHandler.uploadFile(istream, filename, contentType, fileType); } /* ===============Methods implemented from ToolContentManager =============== */ @@ -925,7 +926,7 @@ exportContentService.registerFileClassForImport(NoticeboardAttachment.class.getName() ,"uuid","versionId","filename","fileProperty",null,null); - Object toolPOJO = exportContentService.importToolContent(toolContentPath,nbToolContentHandler,newUserUid); + Object toolPOJO = exportContentService.importToolContent(toolContentPath,nbToolContentHandler); if(!(toolPOJO instanceof NoticeboardContent)) throw new ImportToolContentException("Import Noteice board tool content failed. Deserialized object is " + toolPOJO); NoticeboardContent toolContentObj = (NoticeboardContent) toolPOJO; @@ -936,7 +937,7 @@ } catch (ImportToolContentException e) { throw new ToolException(e); } - } + } /* ===============Methods implemented from ToolSessionManager =============== */ /** @see org.lamsfoundation.lams.tool.ToolSessionManager#createToolSession(java.lang.Long, java.lang.String, java.lang.Long) */ Index: lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbAuthoringAction.java =================================================================== diff -u -r76f7b5fee0d226d36814affd2b6888ff605ee08b -r2fc4a8b63d3086df2ab75ada593e5d36528d6281 --- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbAuthoringAction.java (.../NbAuthoringAction.java) (revision 76f7b5fee0d226d36814affd2b6888ff605ee08b) +++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbAuthoringAction.java (.../NbAuthoringAction.java) (revision 2fc4a8b63d3086df2ab75ada593e5d36528d6281) @@ -351,8 +351,6 @@ checkContentId(content_id); NoticeboardContent nbContent = nbService.retrieveNoticeboard(content_id); - UserDTO user = getUser(request); - //check if the file uploaded is an online instructions file or offline instructions file. //if one of the types is null, then the other one must have been uploaded. //here we check if the file is an online one @@ -375,7 +373,7 @@ { // This is a new file and so is saved to the content repository. Add it to the // attachments collection, but don't add it to the tool's tables yet. - NodeKey node = nbService.uploadFile(theFile.getInputStream(), theFile.getFileName(), theFile.getContentType(), fileType, user.getUserID()); + NodeKey node = nbService.uploadFile(theFile.getInputStream(), theFile.getFileName(), theFile.getContentType(), fileType); NoticeboardAttachment file = new NoticeboardAttachment(); file.setFilename(theFile.getFileName()); file.setOnlineFile(isOnlineFile);