Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/CheckCredentialTicketBeforeAdvice.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -rd140daaaa506ac792804b3ce302724b3dde9c830 --- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/CheckCredentialTicketBeforeAdvice.java (.../CheckCredentialTicketBeforeAdvice.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/CheckCredentialTicketBeforeAdvice.java (.../CheckCredentialTicketBeforeAdvice.java) (revision d140daaaa506ac792804b3ce302724b3dde9c830) @@ -21,7 +21,6 @@ * **************************************************************** */ - package org.lamsfoundation.lams.contentrepository; import java.lang.reflect.Method; @@ -63,8 +62,8 @@ + (args != null && args.length > 0 ? args[0] : "null")); } - if (m != null && "toString".equals(m.getName())) { - // don't check toString - let it through + if (m != null && ("toString".equals(m.getName()) || m.getName().startsWith("dao"))) { + // don't check toString and dao* methods - let them through return; } Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/applicationContext.xml =================================================================== diff -u -r0bf13f382910d76f7792c3639066ddae6997fbaa -rd140daaaa506ac792804b3ce302724b3dde9c830 --- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/applicationContext.xml (.../applicationContext.xml) (revision 0bf13f382910d76f7792c3639066ddae6997fbaa) +++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/applicationContext.xml (.../applicationContext.xml) (revision d140daaaa506ac792804b3ce302724b3dde9c830) @@ -45,6 +45,7 @@ PROPAGATION_REQUIRED PROPAGATION_REQUIRED PROPAGATION_REQUIRED + PROPAGATION_REQUIRED @@ -58,20 +59,19 @@ + + - - + - - - + - - + + Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/dao/INodeDAO.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -rd140daaaa506ac792804b3ce302724b3dde9c830 --- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/dao/INodeDAO.java (.../INodeDAO.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/dao/INodeDAO.java (.../INodeDAO.java) (revision d140daaaa506ac792804b3ce302724b3dde9c830) @@ -21,7 +21,6 @@ * **************************************************************** */ - package org.lamsfoundation.lams.contentrepository.dao; import java.util.List; @@ -37,8 +36,6 @@ */ public interface INodeDAO extends IBaseDAO { - public void saveOrUpdate(Object object); - public List findChildNodes(CrNodeVersion parentNodeVersion); public CrNode findChildNode(CrNodeVersion parentNodeVersion, String relPath); Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/dao/hibernate/NodeDAO.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -rd140daaaa506ac792804b3ce302724b3dde9c830 --- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/dao/hibernate/NodeDAO.java (.../NodeDAO.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/dao/hibernate/NodeDAO.java (.../NodeDAO.java) (revision d140daaaa506ac792804b3ce302724b3dde9c830) @@ -21,7 +21,6 @@ * **************************************************************** */ - package org.lamsfoundation.lams.contentrepository.dao.hibernate; import java.util.List; @@ -42,11 +41,6 @@ public class NodeDAO extends LAMSBaseDAO implements INodeDAO { protected Logger log = Logger.getLogger(NodeDAO.class); - @Override - public void saveOrUpdate(Object object) { - insertOrUpdate(object); - } - /** * Get all child nodes for a node/version. * Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/INodeFactory.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -rd140daaaa506ac792804b3ce302724b3dde9c830 --- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/INodeFactory.java (.../INodeFactory.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/INodeFactory.java (.../INodeFactory.java) (revision d140daaaa506ac792804b3ce302724b3dde9c830) @@ -21,14 +21,12 @@ * **************************************************************** */ - package org.lamsfoundation.lams.contentrepository.service; import java.io.InputStream; import org.lamsfoundation.lams.contentrepository.CrNode; import org.lamsfoundation.lams.contentrepository.CrWorkspace; -import org.lamsfoundation.lams.contentrepository.dao.INodeDAO; import org.lamsfoundation.lams.contentrepository.exception.FileException; import org.lamsfoundation.lams.contentrepository.exception.InvalidParameterException; import org.lamsfoundation.lams.contentrepository.exception.ItemNotFoundException; @@ -43,7 +41,7 @@ /** * Create a new file node (which is assumed to be a newly created Spring * bean) with relPath and node type. - * + * * @param relPath * The path of the new Node that is to be created, * the last item of this path will be the name of the new Node. @@ -59,7 +57,7 @@ /** * Create a new package node (which is assumed to be a newly created Spring * bean) with the default file and node type. Package node cannot have a parent node. - * + * * @param initialPath * The path of the default content. * @throws org.lamsfoundation.lams.contentrepository.exception.InvalidParameterException @@ -74,7 +72,7 @@ /** * Create a new data node (which is assumed to be a newly created Spring * bean). This node may have a parent node. - * + * * @throws org.lamsfoundation.lams.contentrepository.exception.InvalidParameterException * if the file parameters are invalid * @throws RepositoryRuntimeException @@ -87,7 +85,7 @@ /** * Build a SimpleVersionedNode, given a CrNode from the database. If versionId == null * then gets the latest version. - * + * * @see org.lamsfoundation.lams.contentrepository.IVersionedNode#getNode(String relPath) */ public abstract SimpleVersionedNode getNode(CrNode databaseNode, Long versionId); @@ -97,12 +95,12 @@ * Creates the CrNode and CrNodeVersion objects. * Equivalent of createFileNode/createPackageNode for existing nodes * Checks that the workspace found in the database is the expected workspace. - * + * * If this node object is returned to a web app, then the * crNode and crNodeVersion objects will be disconnected * from the session, as the session will have been ended * with the Spring transaction. - * + * * If versionId is null, then gets the latest version */ public abstract SimpleVersionedNode getNode(Long workspaceId, Long uuid, Long versionId) @@ -118,9 +116,9 @@ * crNode and crNodeVersion objects will be disconnected * from the session, as the session will have been ended * with the Spring transaction. - * + * * @throws ItemNotFoundException - * + * * @throws RepositoryRuntimeException * if an internal error occurs. * @see org.lamsfoundation.lams.contentrepository.IVersionedNode#createNewVersion(java.lang.String, @@ -132,11 +130,11 @@ /** * Copy the supplied node/version to a new node. Does not copy the history * of the node. Copies any child nodes of the current version. All files are duplicated. - * + * * This method only works as we know that we have two levels of nodes - the * childNodes can't have their own childNodes. If this is no longer the case, * this method and SimpleVersionedNode.save() will need to be changed. - * + * * @throws FileException * will occur if there is a problem reading a file from the repository * @throws InvalidParameterException @@ -148,16 +146,4 @@ */ public abstract SimpleVersionedNode copy(SimpleVersionedNode originalNode, Integer userId) throws FileException, ValueFormatException, InvalidParameterException; - - /** - * @return Returns the nodeDAO. - */ - public abstract INodeDAO getNodeDAO(); - - /** - * @param nodeDAO - * The nodeDAO to set. - */ - public abstract void setNodeDAO(INodeDAO nodeDAO); - } \ No newline at end of file Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/IRepositoryService.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -rd140daaaa506ac792804b3ce302724b3dde9c830 --- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/IRepositoryService.java (.../IRepositoryService.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/IRepositoryService.java (.../IRepositoryService.java) (revision d140daaaa506ac792804b3ce302724b3dde9c830) @@ -29,6 +29,8 @@ import java.util.SortedMap; import java.util.SortedSet; +import org.lamsfoundation.lams.contentrepository.CrNode; +import org.lamsfoundation.lams.contentrepository.CrNodeVersion; import org.lamsfoundation.lams.contentrepository.CrWorkspace; import org.lamsfoundation.lams.contentrepository.ICredentials; import org.lamsfoundation.lams.contentrepository.ITicket; @@ -485,4 +487,43 @@ public boolean workspaceExists(ICredentials credentials, Long workspaceId); public boolean workspaceExists(ICredentials credentials, String workspaceName); + + // Below are methods which are just transactional proxy to DAO metods + // They are prefixed DAO so CheckCredentialTicketBeforeAdvice does not pick them up + + /** + * Write out a file to the repository. Closes the stream. Overwrites any existing files. + * + * @return the path to which the file was written + */ + public String daoWriteFile(Long uuid, Long versionId, InputStream is) throws FileException; + + /** + * Gets a file from the repository. + */ + public InputStream daoGetFile(Long uuid, Long versionId) throws FileException; + + /** + * Delete a file from the repository. If this makes the directory + * empty, then the directory should be deleted. + * + * @return 1 if deleted okay, 0 if file not found, -1 if file found but a delete error occured. + */ + public int daoDelete(Long uuid, Long versionId) throws FileException; + + /** + * Get the actual path of the file ie the path on disk + */ + public String daoGetFilePath(Long uuid, Long versionId) throws FileException; + + /** + * Is there a file on disk? + *

+ * Used to validate file nodes. + */ + public boolean daoFileExists(Long uuid, Long versionId) throws FileException; + + public List daoFindChildNodes(CrNodeVersion parentNodeVersion); + + public CrNode daoFindChildNode(CrNodeVersion parentNodeVersion, String relPath); } \ No newline at end of file Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/NodeFactory.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -rd140daaaa506ac792804b3ce302724b3dde9c830 --- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/NodeFactory.java (.../NodeFactory.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/NodeFactory.java (.../NodeFactory.java) (revision d140daaaa506ac792804b3ce302724b3dde9c830) @@ -21,7 +21,6 @@ * **************************************************************** */ - package org.lamsfoundation.lams.contentrepository.service; import java.io.InputStream; @@ -37,11 +36,11 @@ import org.lamsfoundation.lams.contentrepository.IValue; import org.lamsfoundation.lams.contentrepository.NodeType; import org.lamsfoundation.lams.contentrepository.PropertyName; -import org.lamsfoundation.lams.contentrepository.dao.INodeDAO; import org.lamsfoundation.lams.contentrepository.exception.FileException; import org.lamsfoundation.lams.contentrepository.exception.InvalidParameterException; import org.lamsfoundation.lams.contentrepository.exception.ItemNotFoundException; import org.lamsfoundation.lams.contentrepository.exception.ValueFormatException; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; @@ -60,15 +59,11 @@ protected Logger log = Logger.getLogger(NodeFactory.class); private BeanFactory beanFactory = null; - private INodeDAO nodeDAO = null; + private IUserManagementService userManagementService = null; - public NodeFactory() { - super(); - } - /* * (non-Javadoc) - * + * * @see org.lamsfoundation.lams.contentrepository.service.INodeFactory#createFileNode(org.lamsfoundation.lams. * contentrepository.CrWorkspace, org.lamsfoundation.lams.contentrepository.service.SimpleVersionedNode, * java.lang.String, java.io.InputStream, java.lang.String, java.lang.String, java.lang.String) @@ -87,7 +82,7 @@ /* * (non-Javadoc) - * + * * @see org.lamsfoundation.lams.contentrepository.service.INodeFactory#createPackageNode(org.lamsfoundation.lams. * contentrepository.CrWorkspace, java.lang.String, java.lang.String) */ @@ -104,7 +99,7 @@ /* * (non-Javadoc) - * + * * @see org.lamsfoundation.lams.contentrepository.service.INodeFactory#createDataNode(org.lamsfoundation.lams. * contentrepository.CrWorkspace, org.lamsfoundation.lams.contentrepository.service.SimpleVersionedNode, * java.lang.String) @@ -144,7 +139,7 @@ /* * (non-Javadoc) - * + * * @see * org.lamsfoundation.lams.contentrepository.service.INodeFactory#getNode(org.lamsfoundation.lams.contentrepository. * CrNode, java.lang.Long) @@ -159,7 +154,7 @@ /* * (non-Javadoc) - * + * * @see org.lamsfoundation.lams.contentrepository.service.INodeFactory#getNode(java.lang.Long, java.lang.Long, * java.lang.Long) */ @@ -176,7 +171,7 @@ CrNode node = null; - node = (CrNode) nodeDAO.find(CrNode.class, uuid); + node = (CrNode) getUserManagementService().findById(CrNode.class, uuid); if (node == null) { throw new ItemNotFoundException("Node " + uuid + " not found."); @@ -194,7 +189,7 @@ /* * (non-Javadoc) - * + * * @see org.lamsfoundation.lams.contentrepository.service.INodeFactory#getNode(java.lang.Long, java.lang.Long, * java.lang.Long, java.lang.String) */ @@ -220,7 +215,7 @@ /* * (non-Javadoc) - * + * * @see * org.lamsfoundation.lams.contentrepository.service.INodeFactory#copy(org.lamsfoundation.lams.contentrepository. * service.SimpleVersionedNode) @@ -235,7 +230,7 @@ /** * Private method to handle the recursive copy. The parent node is needed to set up the * node -> parent link in the CrNode object. - * + * * @param originalNode * @param parentNode * @return new Node @@ -268,7 +263,7 @@ } } - // copy any attached file. don't actually copy the file - set up + // copy any attached file. don't actually copy the file - set up // and input stream and the file will be copied when the node is saved. // this is likely to recopy the Filename and Mimetype properties. if (originalNode.isNodeType(NodeType.FILENODE)) { @@ -298,31 +293,10 @@ * ********************************************************** */ - /* - * (non-Javadoc) - * - * @see org.lamsfoundation.lams.contentrepository.service.INodeFactory#getNodeDAO() - */ - @Override - public INodeDAO getNodeDAO() { - return nodeDAO; - } - - /* - * (non-Javadoc) - * - * @see org.lamsfoundation.lams.contentrepository.service.INodeFactory#setNodeDAO(org.lamsfoundation.lams. - * contentrepository.dao.INodeDAO) - */ - @Override - public void setNodeDAO(INodeDAO nodeDAO) { - this.nodeDAO = nodeDAO; - } - /* **** Method for BeanFactoryAware interface *****************/ /* * (non-Javadoc) - * + * * @see * org.lamsfoundation.lams.contentrepository.service.INodeFactory#setBeanFactory(org.springframework.beans.factory. * BeanFactory) @@ -332,4 +306,12 @@ this.beanFactory = beanFactory; } -} + public IUserManagementService getUserManagementService() { + // this can not be done by injection as bean factory is not fully initialised when it happens and we get an exception on start up + if (userManagementService == null) { + userManagementService = beanFactory.getBean("userManagementService", IUserManagementService.class); + } + return userManagementService; + } + +} \ No newline at end of file Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/SimpleRepository.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -rd140daaaa506ac792804b3ce302724b3dde9c830 --- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/SimpleRepository.java (.../SimpleRepository.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/SimpleRepository.java (.../SimpleRepository.java) (revision d140daaaa506ac792804b3ce302724b3dde9c830) @@ -21,7 +21,6 @@ * **************************************************************** */ - package org.lamsfoundation.lams.contentrepository.service; import java.io.FileNotFoundException; @@ -43,6 +42,7 @@ import org.apache.log4j.Logger; import org.lamsfoundation.lams.contentrepository.CrCredential; import org.lamsfoundation.lams.contentrepository.CrNode; +import org.lamsfoundation.lams.contentrepository.CrNodeVersion; import org.lamsfoundation.lams.contentrepository.CrWorkspace; import org.lamsfoundation.lams.contentrepository.CrWorkspaceCredential; import org.lamsfoundation.lams.contentrepository.ICredentials; @@ -54,6 +54,8 @@ import org.lamsfoundation.lams.contentrepository.NodeType; import org.lamsfoundation.lams.contentrepository.PropertyName; import org.lamsfoundation.lams.contentrepository.dao.ICredentialDAO; +import org.lamsfoundation.lams.contentrepository.dao.IFileDAO; +import org.lamsfoundation.lams.contentrepository.dao.INodeDAO; import org.lamsfoundation.lams.contentrepository.dao.IWorkspaceDAO; import org.lamsfoundation.lams.contentrepository.exception.AccessDeniedException; import org.lamsfoundation.lams.contentrepository.exception.FileException; @@ -87,7 +89,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 @@ -108,6 +110,8 @@ private ICredentialDAO credentialDAO = null; private IWorkspaceDAO workspaceDAO = null; private INodeFactory nodeFactory = null; + private IFileDAO fileDAO = null; + private INodeDAO nodeDAO = null; private Set ticketIdSet = new HashSet(); // set of currently known tickets. @@ -134,10 +138,10 @@ } return user.getUserID(); } - 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 workspaceId @@ -155,7 +159,7 @@ /* * (non-Javadoc) - * + * * @see org.lamsfoundation.lams.contentrepository.IRepository#login(org.lamsfoundation.lams.contentrepository. * ICredentials, java.lang.String) */ @@ -182,7 +186,7 @@ } // 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; @@ -191,7 +195,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 @@ -266,7 +270,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 @@ -304,9 +308,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 @@ -404,7 +408,7 @@ /* * (non-Javadoc) - * + * * @see * org.lamsfoundation.lams.contentrepository.IRepository#logout(org.lamsfoundation.lams.contentrepository.ITicket) */ @@ -426,7 +430,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) */ @@ -452,7 +456,7 @@ /* * (non-Javadoc) - * + * * @see * org.lamsfoundation.lams.contentrepository.IRepository#addPackageItem(org.lamsfoundation.lams.contentrepository. * ITicket, java.lang.String, java.lang.String, java.lang.String) @@ -486,7 +490,7 @@ /* * (non-Javadoc) - * + * * @see org.lamsfoundation.lams.contentrepository.IRepository#getFileItem(org.lamsfoundation.lams.contentrepository. * ITicket, java.lang.Long, java.lang.Long) */ @@ -499,7 +503,7 @@ /* * (non-Javadoc) - * + * * @see org.lamsfoundation.lams.contentrepository.IRepository#getFileItem(org.lamsfoundation.lams.contentrepository. * ITicket, java.lang.Long, java.lang.Long, java.lang.String) */ @@ -530,7 +534,7 @@ /* * (non-Javadoc) - * + * * @see org.lamsfoundation.lams.contentrepository.IRepository#getFileItem(org.lamsfoundation.lams.contentrepository. * ITicket, java.lang.Long, java.lang.Long, java.lang.String) */ @@ -556,7 +560,7 @@ /* * (non-Javadoc) - * + * * @see org.lamsfoundation.lams.contentrepository.IRepository#getNodeList(org.lamsfoundation.lams.contentrepository. * ITicket) */ @@ -582,7 +586,7 @@ /* * (non-Javadoc) - * + * * @see * org.lamsfoundation.lams.contentrepository.IRepository#getVersionHistory(org.lamsfoundation.lams.contentrepository * .ITicket, java.lang.Long) @@ -596,7 +600,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) @@ -627,7 +631,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) @@ -690,7 +694,7 @@ /* * (non-Javadoc) - * + * * @see * org.lamsfoundation.lams.contentrepository.IRepository#copyNodeVersion(org.lamsfoundation.lams.contentrepository. * ITicket, java.lang.Long, java.lang.Long) @@ -723,7 +727,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) @@ -804,7 +808,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) @@ -830,7 +834,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) @@ -850,22 +854,53 @@ } + @Override public boolean workspaceExists(ICredentials credentials, Long workspaceId) { return workspaceDAO.find(CrWorkspace.class, workspaceId) != null; } + @Override public boolean workspaceExists(ICredentials credentials, String workspaceName) { return workspaceDAO.findByName(workspaceName) != null; } - /* ********** setters and getters for DAOs *******************/ - /** - * @return Returns the workspaceDAO. - */ - public IWorkspaceDAO getWorkspaceDAO() { - return workspaceDAO; + @Override + public InputStream daoGetFile(Long uuid, Long versionId) throws FileException { + return fileDAO.getFile(uuid, versionId); } + @Override + public String daoWriteFile(Long uuid, Long versionId, InputStream is) throws FileException { + return fileDAO.writeFile(uuid, versionId, is); + } + + @Override + public int daoDelete(Long uuid, Long versionId) throws FileException { + return fileDAO.delete(uuid, versionId); + } + + @Override + public String daoGetFilePath(Long uuid, Long versionId) throws FileException { + return fileDAO.getFilePath(uuid, versionId); + } + + @Override + public boolean daoFileExists(Long uuid, Long versionId) throws FileException { + return fileDAO.fileExists(uuid, versionId); + } + + @Override + public List daoFindChildNodes(CrNodeVersion parentNodeVersion) { + return nodeDAO.findChildNodes(parentNodeVersion); + } + + @Override + public CrNode daoFindChildNode(CrNodeVersion parentNodeVersion, String relPath) { + return nodeDAO.findChildNode(parentNodeVersion, relPath); + } + + /* ********** setters and getters for DAOs *******************/ + /** * @param workspaceDAO * The workspaceDAO to set. @@ -875,26 +910,22 @@ } /** - * @return Returns the credentialDAO. - */ - public ICredentialDAO getCredentialDAO() { - return credentialDAO; - } - - /** * @param credentialDAO * The credentialDAO to set. */ public void setCredentialDAO(ICredentialDAO credentialDAO) { this.credentialDAO = credentialDAO; } - public INodeFactory getNodeFactory() { - return nodeFactory; - } - public void setNodeFactory(INodeFactory nodeFactory) { this.nodeFactory = nodeFactory; } -} + public void setFileDAO(IFileDAO fileDAO) { + this.fileDAO = fileDAO; + } + + public void setNodeDAO(INodeDAO nodeDAO) { + this.nodeDAO = nodeDAO; + } +} \ No newline at end of file Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/SimpleVersionedNode.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -rd140daaaa506ac792804b3ce302724b3dde9c830 --- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/SimpleVersionedNode.java (.../SimpleVersionedNode.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/SimpleVersionedNode.java (.../SimpleVersionedNode.java) (revision d140daaaa506ac792804b3ce302724b3dde9c830) @@ -21,7 +21,6 @@ * **************************************************************** */ - package org.lamsfoundation.lams.contentrepository.service; import java.io.File; @@ -53,14 +52,13 @@ import org.lamsfoundation.lams.contentrepository.NodeType; import org.lamsfoundation.lams.contentrepository.PropertyName; import org.lamsfoundation.lams.contentrepository.PropertyType; -import org.lamsfoundation.lams.contentrepository.dao.IFileDAO; -import org.lamsfoundation.lams.contentrepository.dao.INodeDAO; import org.lamsfoundation.lams.contentrepository.exception.FileException; import org.lamsfoundation.lams.contentrepository.exception.InvalidParameterException; import org.lamsfoundation.lams.contentrepository.exception.ItemNotFoundException; import org.lamsfoundation.lams.contentrepository.exception.RepositoryRuntimeException; import org.lamsfoundation.lams.contentrepository.exception.ValidationException; import org.lamsfoundation.lams.contentrepository.exception.ValueFormatException; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; import org.lamsfoundation.lams.util.FileUtil; /** @@ -105,10 +103,11 @@ private ITicket ticket = null; // transient data - using for grouping nodes in a session /* Spring configured varibles */ - private INodeDAO nodeDAO = null; - private IFileDAO fileDAO = null; - private INodeFactory nodeFactory = null; + private IRepositoryService repositoryService; + private IUserManagementService userManagementService; + private INodeFactory nodeFactory; + // TODO This is a case for AOP! /** * Check that all the necessary objects exists - node, nodeVersion, nodeDAO and fileDAO @@ -124,13 +123,10 @@ throw new RepositoryRuntimeException("Node details missing (nodeVersion=null). " + specialisedMessage); } - if (nodeDAO == null) { - throw new RepositoryRuntimeException("Node details missing (nodeDAO=null). " + specialisedMessage); + if (repositoryService == null) { + throw new RepositoryRuntimeException( + "Node details missing (repositoryService=null). " + specialisedMessage); } - - if (fileDAO == null) { - throw new RepositoryRuntimeException("Node details missing (fileDAO=null). " + specialisedMessage); - } } /** Add a child to the node. To be used by SimpleVersionedNode and the NodeFactory only */ @@ -148,7 +144,7 @@ /* * (non-Javadoc) - * + * * @see org.lamsfoundation.lams.contentrepository.IVersionedNode#setProperty(java.lang.String, java.lang.String, * int) */ @@ -160,7 +156,7 @@ /* * (non-Javadoc) - * + * * @see org.lamsfoundation.lams.contentrepository.IVersionedNode#setProperty(java.lang.String, java.lang.String) */ @Override @@ -171,7 +167,7 @@ /* * (non-Javadoc) - * + * * @see org.lamsfoundation.lams.contentrepository.IVersionedNode#setProperty(java.lang.String, boolean) */ @Override @@ -182,7 +178,7 @@ /* * (non-Javadoc) - * + * * @see org.lamsfoundation.lams.contentrepository.IVersionedNode#setProperty(java.lang.String, double) */ @Override @@ -193,7 +189,7 @@ /* * (non-Javadoc) - * + * * @see org.lamsfoundation.lams.contentrepository.IVersionedNode#setProperty(java.lang.String, long) */ @Override @@ -204,7 +200,7 @@ /* * (non-Javadoc) - * + * * @see org.lamsfoundation.lams.contentrepository.IVersionedNode#setProperty(java.lang.String, java.util.Calendar) */ @Override @@ -271,7 +267,7 @@ /** * (non-Javadoc) - * + * * @see org.lamsfoundation.lams.contentrepository.IVersionedNode#isNodeType(java.lang.String) */ @Override @@ -284,7 +280,7 @@ * Get the history for this node. Quite intensive operation * as it has to build all the data structures. Can't be easily * cached. - * + * * @return SortedSet of IVersionDetail objects, ordered by version */ @Override @@ -380,7 +376,7 @@ * of the caller to close the stream. Note: this should only be * called once the node is saved - do not call it directly after * setting the file stream - * + * * If the node is a package node, it will get the input stream * of the first file. */ @@ -390,7 +386,7 @@ if (isNodeType(NodeType.FILENODE)) { - return fileDAO.getFile(node.getNodeId(), nodeVersion.getVersionId()); + return repositoryService.daoGetFile(node.getNodeId(), nodeVersion.getVersionId()); } else if (isNodeType(NodeType.PACKAGENODE)) { @@ -416,7 +412,7 @@ /** * Set the file, passed in as an inputstream. The stream will be closed * when the file is saved. Only nodes of type FILENODE can have a file! - * + * * @param iStream * mandatory * @param filename @@ -478,7 +474,7 @@ * we could just be doing a setProperty save, in which case the file * will already exist. *

  • Package nodes must not have a file, must have a INITIALPATH property - * + * * @throws ValidationException * if problems exist. */ @@ -510,7 +506,7 @@ // if it is a new node or a new version then it must have a file, otherwise check on disk. // version id will always be set. uuid isn't set until the record is written to the db, // but don't want to rely on that if we can help it in case it changes in future. - if (newIStream == null && (uuid == null || !fileDAO.fileExists(uuid, versionId))) { + if (newIStream == null && (uuid == null || !repositoryService.daoFileExists(uuid, versionId))) { errors = errors + "\nNode is a file node but the file is missing. "; } } catch (FileException fe) { @@ -541,19 +537,19 @@ * Save the changes to this node. This method must be called when saving a file * or package node for the first time - it does both the database and the file * saves. - * + * * If it is a file node, then it writes out the db changes and then saves * the file. - * + * * If is is a package node, then it writes out the db changes for all the nodes, * then saves all the file. Why do it this way - we want to do all the file * changes at the end as they cannot be rolled back if there is a db error. - * + * * This method only works as we know that we have two levels of nodes - the * childNodes can't have their own childNodes. If this is no longer the case, * this method and copy() will need to be changed. - * * + * * TODO This needs a lot of testing */ protected Long save() throws ValidationException, FileException { @@ -606,7 +602,7 @@ SimpleVersionedNode element = (SimpleVersionedNode) writtenIter.next(); int delStatus = -1; try { - delStatus = fileDAO.delete(element.getUUID(), element.getVersion()); + delStatus = repositoryService.daoDelete(element.getUUID(), element.getVersion()); } catch (Exception e2) { // things are getting bad - throwing exceptions on the delete! } @@ -615,7 +611,8 @@ : element.getFilePath(); } else { failedDeleted = failedDeleted != null - ? failedDeleted + File.pathSeparator + element.getFilePath() : element.getFilePath(); + ? failedDeleted + File.pathSeparator + element.getFilePath() + : element.getFilePath(); } } String msg = "Result of rolling back file changes:"; @@ -650,7 +647,7 @@ // nodeDAO to take care of insert or update (uses saveOrUpdate) // the nodeVersion and nodeVersionProperty collections cascade // updates and deletes, so we can just save the node! - nodeDAO.saveOrUpdate(node); + userManagementService.save(node); // child nodes are done manually as the set is lazy loaded // and can't work out how to do that properly using the DAO template! @@ -659,21 +656,21 @@ Iterator iter = childNodes.iterator(); while (iter.hasNext()) { SimpleVersionedNode node = (SimpleVersionedNode) iter.next(); - nodeDAO.saveOrUpdate(node.getNode()); + userManagementService.save(node.getNode()); } } } /** * Write the file out (if one exists). Sets the private attribute filePath. - * + * * @return the path to which the file was written */ private void writeFile() throws FileException { String filePath = null; if (newIStream != null) { - filePath = fileDAO.writeFile(node.getNodeId(), nodeVersion.getVersionId(), newIStream); + filePath = repositoryService.daoWriteFile(node.getNodeId(), nodeVersion.getVersionId(), newIStream); } setFilePath(filePath); } @@ -695,7 +692,7 @@ /** * Another case for the factory? - * + * * @see org.lamsfoundation.lams.contentrepository.IVersionedNode#getNode(String relPath) */ @Override @@ -707,7 +704,7 @@ log.debug("getNode for path " + relPath + " start."); } - CrNode childNode = nodeDAO.findChildNode(nodeVersion, relPath); + CrNode childNode = repositoryService.daoFindChildNode(nodeVersion, relPath); if (childNode != null) { return nodeFactory.getNode(childNode, null); @@ -719,12 +716,12 @@ /** * If no nodes are found, returns an empty set. - * + * * @see org.lamsfoundation.lams.contentrepository.IVersionedNode#getChildNodes() */ @Override public Set getChildNodes() { - List childCrNodes = nodeDAO.findChildNodes(nodeVersion); + List childCrNodes = repositoryService.daoFindChildNodes(nodeVersion); Set childNodes = new HashSet(); if (childCrNodes != null) { @@ -775,20 +772,20 @@ */ @Override public boolean hasNodes() { - List childNodes = nodeDAO.findChildNodes(nodeVersion); + List childNodes = repositoryService.daoFindChildNodes(nodeVersion); return (childNodes != null && childNodes.size() > 0); } /** * Delete all versions of this node, returning the number of nodes * deleted. If it is a package node, all child nodes will be deleted. - * + * * @see org.lamsfoundation.lams.contentrepository.IVersionedNodeAdmin#deleteNode() */ @Override public List deleteNode() { - // first make a list of all the versions to delete. + // first make a list of all the versions to delete. // don't iterate over the set, deleting as we go so that // we can't run into any issues trying to access something // that is deleted or belongs to an iterator. @@ -822,16 +819,16 @@ // doing file system changes if the db would fail later. deleteVersionFromDB(nodeKeysDeleted); - // now delete the files. If it fails due to the file not being found, then + // now delete the files. If it fails due to the file not being found, then // that's fine. ArrayList failedList = new ArrayList(); Iterator iter = nodeKeysDeleted.iterator(); while (iter.hasNext()) { NodeKey nk = (NodeKey) iter.next(); try { - int delStatus = fileDAO.delete(nk.getUuid(), nk.getVersion()); + int delStatus = repositoryService.daoDelete(nk.getUuid(), nk.getVersion()); if (delStatus == -1) { - failedList.add(fileDAO.getFilePath(nk.getUuid(), nk.getVersion())); + failedList.add(repositoryService.daoGetFilePath(nk.getUuid(), nk.getVersion())); } } catch (FileException e) { log.error("FileException occured while deleting files for " + nodeDescription, e); @@ -882,15 +879,15 @@ // if this was the last version for the node, delete the node if (node.getCrNodeVersions() == null || node.getCrNodeVersions().size() == 0) { - nodeDAO.delete(node); + userManagementService.delete(node); } } /** * Process files in the package. Create a List of file nodes but do not persist * the nodes. - * + * * @param dirPath: * the directory from which to get files. Mandatory. * @param packageNode: @@ -1009,11 +1006,11 @@ /** * Copy the supplied node/version to a new node. Does not copy the history * of the node. Copies any child nodes of the current version. All files are duplicated. - * + * * This method only works as we know that we have two levels of nodes - the * childNodes can't have their own childNodes. If this is no longer the case, * this method and SimpleVersionedNode.save() will need to be changed. - * + * * @throws FileException * will occur if there is a problem reading a file from the repository * @throws InvalidParameterException @@ -1064,45 +1061,19 @@ * ********************************************************** */ - /** - * @return Returns the nodeDAO. - */ - public INodeDAO getNodeDAO() { - return nodeDAO; + public void setRepositoryService(IRepositoryService repositoryService) { + this.repositoryService = repositoryService; } - /** - * @param nodeDAO - * The nodeDAO to set. - */ - public void setNodeDAO(INodeDAO nodeDAO) { - this.nodeDAO = nodeDAO; + public void setNodeFactory(INodeFactory nodeFactory) { + this.nodeFactory = nodeFactory; } - /** - * @return Returns the fileDAO. - */ - public IFileDAO getFileDAO() { - return fileDAO; + public void setUserManagementService(IUserManagementService userManagementService) { + this.userManagementService = userManagementService; } /** - * @param fileDAO - * The fileDAO to set. - */ - public void setFileDAO(IFileDAO fileDAO) { - this.fileDAO = fileDAO; - } - - public INodeFactory getNodeFactory() { - return nodeFactory; - } - - public void setNodeFactory(INodeFactory nodeFactory) { - this.nodeFactory = nodeFactory; - } - - /** * Clean up any resources that will not be cleaned up by the garbage * collector after this object is destroyed. At present, all it does is * close the filestream if needed @@ -1117,5 +1088,4 @@ log.debug("Unable to close stream - was it already closed perhaps?", e); } } - -} +} \ No newline at end of file Index: lams_learning/src/java/org/lamsfoundation/lams/learning/command/CommandWebsocketServer.java =================================================================== diff -u -r18a207719c2aa30f683987fd0bb9176521b704de -rd140daaaa506ac792804b3ce302724b3dde9c830 --- lams_learning/src/java/org/lamsfoundation/lams/learning/command/CommandWebsocketServer.java (.../CommandWebsocketServer.java) (revision 18a207719c2aa30f683987fd0bb9176521b704de) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/command/CommandWebsocketServer.java (.../CommandWebsocketServer.java) (revision d140daaaa506ac792804b3ce302724b3dde9c830) @@ -122,7 +122,7 @@ static { // run the singleton thread - CommandWebsocketServer.sendWorker.start(); +// CommandWebsocketServer.sendWorker.start(); } /**