Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/client/Download.java =================================================================== diff -u -r2de8f805211b6433aff4efd6fa9275a1b9933033 -r78eab2ee1acaf8d47f55aa94fc683a4f919e84ae --- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/client/Download.java (.../Download.java) (revision 2de8f805211b6433aff4efd6fa9275a1b9933033) +++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/client/Download.java (.../Download.java) (revision 78eab2ee1acaf8d47f55aa94fc683a4f919e84ae) @@ -23,30 +23,25 @@ package org.lamsfoundation.lams.contentrepository.client; -import java.io.BufferedInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; -import org.lamsfoundation.lams.contentrepository.ITicket; -import org.lamsfoundation.lams.contentrepository.IValue; -import org.lamsfoundation.lams.contentrepository.IVersionedNode; -import org.lamsfoundation.lams.contentrepository.NodeType; -import org.lamsfoundation.lams.contentrepository.PropertyName; +import org.lamsfoundation.lams.contentrepository.*; import org.lamsfoundation.lams.contentrepository.exception.FileException; import org.lamsfoundation.lams.contentrepository.exception.RepositoryCheckedException; import org.lamsfoundation.lams.contentrepository.exception.ValueFormatException; import org.lamsfoundation.lams.contentrepository.service.IRepositoryService; import org.lamsfoundation.lams.util.FileUtil; import org.lamsfoundation.lams.web.util.AttributeNames; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + /** * This is a specialised servlet that supports the downloading of single files and the rendering of packages. *

@@ -218,7 +213,7 @@ throw new RepositoryCheckedException("Filename is missing. " + Download.expectedFormat); } - IVersionedNode node = getRepositoryService().getFileItem(ticket, uuid, version); + IVersionedNode node = getRepositoryService().getFileItem(ticket, uuid, version, relPathString); if (!node.isNodeType(NodeType.FILENODE)) { throw new RepositoryCheckedException( "Unexpected type of node " + node.getNodeType() + " Expected File node. Data is " + node); @@ -353,4 +348,4 @@ protected static boolean getBoolean(String booleanAsString) { return Boolean.valueOf(booleanAsString).booleanValue(); } -} +} \ No newline at end of file Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/IRepositoryService.java =================================================================== diff -u -r2de8f805211b6433aff4efd6fa9275a1b9933033 -r78eab2ee1acaf8d47f55aa94fc683a4f919e84ae --- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/IRepositoryService.java (.../IRepositoryService.java) (revision 2de8f805211b6433aff4efd6fa9275a1b9933033) +++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/IRepositoryService.java (.../IRepositoryService.java) (revision 78eab2ee1acaf8d47f55aa94fc683a4f919e84ae) @@ -23,38 +23,22 @@ package org.lamsfoundation.lams.contentrepository.service; +import org.lamsfoundation.lams.contentrepository.*; +import org.lamsfoundation.lams.contentrepository.exception.*; + import java.io.IOException; import java.io.InputStream; import java.util.List; import java.util.SortedMap; import java.util.SortedSet; import java.util.UUID; -import org.lamsfoundation.lams.contentrepository.CrWorkspace; -import org.lamsfoundation.lams.contentrepository.ICredentials; -import org.lamsfoundation.lams.contentrepository.ITicket; -import org.lamsfoundation.lams.contentrepository.IVersionedNode; -import org.lamsfoundation.lams.contentrepository.NodeKey; -import org.lamsfoundation.lams.contentrepository.exception.AccessDeniedException; -import org.lamsfoundation.lams.contentrepository.exception.FileException; -import org.lamsfoundation.lams.contentrepository.exception.InvalidParameterException; -import org.lamsfoundation.lams.contentrepository.exception.ItemExistsException; -import org.lamsfoundation.lams.contentrepository.exception.ItemNotFoundException; -import org.lamsfoundation.lams.contentrepository.exception.LoginException; -import org.lamsfoundation.lams.contentrepository.exception.RepositoryCheckedException; -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.contentrepository.exception.WorkspaceNotFoundException; - /** * Tool access to the repository. *

- * Runtime exceptions will trigger the transaction to be marked for rollback. - * Checked exceptions will NOT trigger the transaction to be marked for - * rollback so it is up to the calling code to trigger a rollback if needed. - * This allows the calling code to handle the exception and continue the - * transaction. + * Runtime exceptions will trigger the transaction to be marked for rollback. Checked exceptions will NOT trigger the + * transaction to be marked for rollback so it is up to the calling code to trigger a rollback if needed. This allows + * the calling code to handle the exception and continue the transaction. */ public interface IRepositoryService { @@ -70,42 +54,39 @@ "/org/lamsfoundation/lams/toolApplicationContext.xml" }; /** - * Login, creating a new ticket for the given credentials and specified - * 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. + * Login, creating a new ticket for the given credentials and specified 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 - * The credentials of the user + * The credentials of the user * @param workspaceName - * the name of a workspace. + * the name of a workspace. * @return a valid {@link ITicket} for the user to access the repository. * @throws LoginException - * Login authentication fails. + * Login authentication fails. * @throws AccessDeniedException - * User is not allowed to access this workspace. + * User is not allowed to access this workspace. * @throws WorkspaceNotFoundException - * Workspace name doesn't exist. + * Workspace name doesn't exist. */ public ITicket login(ICredentials credentials, String workspaceName) throws LoginException, AccessDeniedException, WorkspaceNotFoundException; /** - * Create a new workspace, with the tool identified in the creditials - * as the owner. - * It does not clear the password in the credentials + * 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. + * this user/password must already exist in the repository. Password will be checked. * @param workspaceName * @throws LoginException - * if credentials are not authorised to add/access the new workspace. + * if credentials are not authorised to add/access the new workspace. * @throws ItemExistsException - * if the workspace already exists. + * if the workspace already exists. * @throws RepositoryCheckedException - * if parameters are missing. + * if parameters are missing. */ public CrWorkspace addWorkspace(ICredentials credentials, String workspaceName) throws LoginException, AccessDeniedException, ItemExistsException, RepositoryCheckedException; @@ -117,15 +98,15 @@ * * 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. + * 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 + * this user/password will be added to the repository * @throws RepositoryCheckedException - * if parameters are missing. + * if parameters are missing. * @throws ItemExistsException - * if the credential already exists. + * if the credential already exists. */ public void createCredentials(ICredentials newCredential) throws AccessDeniedException, RepositoryCheckedException, ItemExistsException; @@ -136,131 +117,124 @@ * The password must be at least 6 chars. * * @param oldCredential - * the current user/password + * the current user/password * @param newCredential - * the new user/password + * the new user/password * @throws LoginException - * if the oldCredential fails login test (e.g. wrong password) + * if the oldCredential fails login test (e.g. wrong password) * @throws RepositoryCheckedException - * if one of the credentials objects are missing + * if one of the credentials objects are missing */ public void updateCredentials(ICredentials oldCredential, ICredentials newCredential) throws AccessDeniedException, RepositoryCheckedException; /** - * Add a new file to the repository. This will create - * a completely new entry (node) in the repository, starting - * with version 1. + * 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 + * ticket issued on login. Identifies tool and workspace - mandatory * @param istream - * new file, as an input stream - mandatory + * new file, as an input stream - mandatory * @param mimeType - * mime type of file - optional + * mime type of file - optional * @param versionDescription - * human readable comment about the version - optional + * human readable comment about the version - optional * @return nodeKey (uuid and version) * @throws AccessDeniedException - * if ticket doesn't allow this action + * if ticket doesn't allow this action * @throws FileException - * if unable to save node due to file error + * if unable to save node due to file error * @throws InvalidParameterException - * if a required parameter is missing + * if a required parameter is missing * @throws RepositoryRuntimeException - * if any internal errors have occured + * if any internal errors have occured */ public abstract NodeKey addFileItem(ITicket ticket, InputStream istream, String filename, String mimeType, - String versionDescription) - throws FileException, AccessDeniedException, InvalidParameterException; + String versionDescription) throws FileException, AccessDeniedException, InvalidParameterException; /** - * Add a new package of files to the repository. If startFile - * is not supplied, then it is assumed to be index.html. + * 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. + * 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 + * ticket issued on login. Identifies tool and workspace - mandatory * @param dirPath - * directory path containing files - mandatory + * directory path containing files - mandatory * @param startFile - * relative path of initial file - optional + * relative path of initial file - optional * @param versionDescription - * human readable comment about the version - optional + * human readable comment about the version - optional * @return nodeKey (uuid and version) * @throws AccessDeniedException - * if ticket doesn't allow this action + * if ticket doesn't allow this action * @throws FileException - * if unable to save node due to file error + * if unable to save node due to file error * @throws InvalidParameterException - * if a required parameter is missing + * if a required parameter is missing * @throws RepositoryRuntimeException - * if any internal errors have occured + * if any internal errors have occured */ public abstract NodeKey addPackageItem(ITicket ticket, String dirPath, String startFile, String versionDescription) throws AccessDeniedException, InvalidParameterException, FileException; /** - * Update an existing file in the repository. This will create - * a new version of this file. + * 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 + * ticket issued on login. Identifies tool and workspace - mandatory * @param uuid - * unique id of the file - mandatory + * unique id of the file - mandatory * @param istream - * new file, as an input stream - mandatory + * new file, as an input stream - mandatory * @param versionDescription - * human readable comment about the version - optional + * human readable comment about the version - optional * @param mimeType - * mime type of file - optional + * mime type of file - optional * @throws AccessDeniedException - * if ticket doesn't allow this action + * if ticket doesn't allow this action * @throws ItemNotFoundException - * if node with uuid cannot be found + * if node with uuid cannot be found * @throws FileException - * if unable to save node due to file error + * if unable to save node due to file error * @throws InvalidParameterException - * if a required parameter is missing + * if a required parameter is missing * @throws RepositoryRuntimeException - * if any internal errors have occured + * if any internal errors have occured */ public NodeKey updateFileItem(ITicket ticket, Long uuid, String filename, InputStream istream, String mimeType, String versionDescription) throws AccessDeniedException, ItemNotFoundException, FileException, InvalidParameterException; /** - * Add a new package of files to the repository. If startFile - * is not supplied, then it is assumed to be index.html. + * 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. + * 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 + * ticket issued on login. Identifies tool and workspace - mandatory * @param uuid - * unique id of the package - mandatory + * unique id of the package - mandatory * @param dirPath - * directory path containing files - mandatory + * directory path containing files - mandatory * @param startFile - * relative path of initial file - optional + * relative path of initial file - optional * @param versionDescription - * human readable comment about the version - optional + * human readable comment about the version - optional * @return nodeKey (uuid and version) * @throws AccessDeniedException - * if ticket doesn't allow this action + * if ticket doesn't allow this action * @throws ItemNotFoundException - * if node with uuid cannot be found + * if node with uuid cannot be found * @throws FileException - * if unable to save node due to file error + * if unable to save node due to file error * @throws InvalidParameterException - * if a required parameter is missing + * if a required parameter is missing * @throws RepositoryRuntimeException - * if any internal errors have occured + * if any internal errors have occured */ public abstract NodeKey updatePackageItem(ITicket ticket, Long uuid, String dirPath, String startFile, String versionDescription) @@ -270,62 +244,57 @@ * Sets the property to a value, based on the specified type. Removes the property if the value is null. * * @param ticket - * Mandatory + * Mandatory * @param uuid - * Mandatory + * Mandatory * @param versionId - * Mandatory + * Mandatory * @param name - * The name of a property of this node + * The name of a property of this node * @param value - * The value to be assigned + * The value to be assigned * @param type - * The type of the property. See org.lamsfoundation.lams.contentrepository.PropertyType - * for values. + * The type of the property. See org.lamsfoundation.lams.contentrepository.PropertyType for values. * @throws ValueFormatException - * if the type or format of a value - * is incompatible with the type of the specified property or if - * value is incompatible with (i.e. can not be converted to) type. + * if the type or format of a value is incompatible with the type of the specified property or if value is + * incompatible with (i.e. can not be converted to) type. */ public void setProperty(ITicket ticket, Long uuid, Long versionId, String name, Object value, int type) throws AccessDeniedException, ItemNotFoundException, ValidationException; /** - * Copy node, copying the specified/latest version of the existing node - * to version 1 of the new node. + * Copy node, copying the specified/latest version of the existing node to version 1 of the new node. *

- * Copies a node (identified by uuid/version). The file(s) attached to the - * supplied version are duplicated and become version 1 of the new node. Therefore - * any "history" of the original node is lost. If the version is not supplied, - * then it uses the latest version of the node as the basis for the new node. + * Copies a node (identified by uuid/version). The file(s) attached to the supplied version are duplicated and + * become version 1 of the new node. Therefore any "history" of the original node is lost. If the version is not + * supplied, 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 + * ticket issued on login. Identifies tool and workspace - mandatory * @param uuid - * id of the file/package - mandatory + * id of the file/package - mandatory * @param version - * desired version - if null gets latest version + * desired version - if null gets latest version * @return nodeKey (uuid and version) * @throws AccessDeniedException - * if the ticket is invalid + * if the ticket is invalid * @throws ItemNotFoundException - * if the node cannot be found + * if the node cannot be found */ public NodeKey copyNodeVersion(ITicket ticket, Long uuid, Long versionId) throws AccessDeniedException, ItemNotFoundException; /** - * Get an item from the repository based on the UUID. This - * may be either a file or package node. + * 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 + * ticket issued on login. Identifies tool and workspace - mandatory * @param nodeId - * id of the file/package - mandatory + * id of the file/package - mandatory * @param version - * desired version - if null gets latest version + * desired version - if null gets latest version * @return node. */ public abstract IVersionedNode getFileItem(ITicket ticket, Long nodeId, Long version) @@ -335,48 +304,43 @@ throws AccessDeniedException, ItemNotFoundException, FileException; /** - * Get an item from the repository based on the UUID and relative - * 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. + * Get an item from the repository based on the UUID and relative 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 "\". + * 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 + * ticket issued on login. Identifies tool and workspace - mandatory * @param nodeId - * id of the package - mandatory + * id of the package - mandatory * @param versionId - * desired version - if null gets latest version. This is the version - * of the package node, not the related file. + * desired version - if null gets latest version. This is the version of the package node, not the related file. * @param relPath - * relative path within the package - if null, - * returns start file. + * relative path within the package - if null, returns start file. + * @return node. * @throws AccessDeniedException - * if ticket doesn't allow this action + * if ticket doesn't allow this action * @throws ItemNotFoundException - * if node with uuid cannot be found + * if node with uuid cannot be found * @throws FileException - * if unable to save node due to file error + * if unable to save node due to file error * @throws RepositoryRuntimeException - * if any internal errors have occured - * @return node. + * if any internal errors have occured */ - public abstract IVersionedNode getFileItem(ITicket ticket, Long nodeId, Long versionId, String relPath) + public abstract IVersionedNode getFileItem(ITicket ticket, String nodeId, Long versionId, String relPath) throws AccessDeniedException, ItemNotFoundException, FileException; /** - * 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. + * 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 + * uuid of the package node * @param version - * version of the package node + * version of the package node * @return list of all nodes for package. * @throws AccessDeniedException * @throws ItemNotFoundException @@ -386,62 +350,55 @@ throws AccessDeniedException, ItemNotFoundException, FileException; /** - * 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. + * 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 + * ticket issued on login. Identifies tool and workspace - mandatory * @return SortedSet of IVersionDetail objects, ordered by version */ public SortedSet getVersionHistory(ITicket ticket, Long uuid) throws ItemNotFoundException, AccessDeniedException; /** - * Delete the current version of a node, returning a list of the files - * that could not be deleted properly. If it is a package node, the child - * nodes will be deleted. + * Delete the current version of a node, returning a list of the files that could not be deleted properly. If it is + * a package node, the child nodes will be deleted. * - * You cannot delete the child of a package node - you have to delete the - * whole package. + * You cannot delete the child of a package node - you have to delete the whole package. * - * If after deleting the version, we find that there a no other versions - * for a node, then delete the node. + * If after deleting the version, we find that there a no other versions for a node, then delete the node. * - * A file missing from the disk is ignored, allowing nodes with lost files - * to be deleted. + * A file missing from the disk is ignored, allowing nodes with lost files to be deleted. * + * @return the list of file(paths) that could not be deleted. The db entries will have been deleted but these files + * could not be deleted. * @throws AccessDeniedException - * if ticket doesn't allow this action + * if ticket doesn't allow this action * @throws ItemNotFoundException - * if node with uuid cannot be found + * if node with uuid cannot be found * @throws InvalidParameterException - * if a required parameter is missing + * if a required parameter is missing * @throws RepositoryRuntimeException - * if any internal errors have occured - * @return the list of file(paths) that could not be deleted. The db entries - * will have been deleted but these files could not be deleted. + * if any internal errors have occured */ public String[] deleteVersion(ITicket ticket, Long uuid, Long version) throws AccessDeniedException, InvalidParameterException, ItemNotFoundException; /** - * Delete a node and all its versions, returning a list of the files - * that could not be deleted properly. If it is a package node, the child - * nodes will be deleted. + * Delete a node and all its versions, returning a list of the files that could not be deleted properly. If it is a + * package node, the child nodes will be deleted. * - * A file missing from the disk is ignored, allowing nodes with lost files - * to be deleted. + * A file missing from the disk is ignored, allowing nodes with lost files to be deleted. * + * @return the list of file(paths) that could not be deleted. The db entries will have been deleted but these files + * could not be deleted. * @throws AccessDeniedException - * if ticket doesn't allow this action + * if ticket doesn't allow this action * @throws ItemNotFoundException - * if node with uuid cannot be found + * if node with uuid cannot be found * @throws InvalidParameterException - * if a required parameter is missing + * if a required parameter is missing * @throws RepositoryRuntimeException - * if any internal errors have occured - * @return the list of file(paths) that could not be deleted. The db entries - * will have been deleted but these files could not be deleted. + * if any internal errors have occured */ public String[] deleteNode(ITicket ticket, Long uuid) throws AccessDeniedException, InvalidParameterException, ItemNotFoundException; @@ -450,42 +407,39 @@ throws AccessDeniedException, InvalidParameterException, ItemNotFoundException; /** - * Finish using this ticket. No more updates may be used with this ticket - * after logout(). Allows any resources to be freed. + * 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 + * ticket issued on login. Identifies tool and workspace - mandatory */ public void logout(ITicket ticket) throws AccessDeniedException; /** - * Get a complete list of all nodes in the workspace and their - * version histories. + * Get a complete list of all nodes in the workspace and their version histories. *

- * Warning: Once a workspace gets a lot of nodes, this will be - * a very very expensive call!!!!! + * 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 + * ticket issued on login. Identifies tool and workspace - mandatory * @return SortedMap key Long uuid, value IVersionDetail version history */ public SortedMap getNodeList(ITicket ticket) throws AccessDeniedException; /** - * Save current version of a node to local file by given file name. If the toFileName is - * null, file name use original file name instead and file save path will be system temporary directory. + * Save current version of a node to local file by given file name. If the toFileName is null, file + * name use original file name instead and file save path will be system temporary directory. *

* * @param ticket - * ticket issued on login. Identifies tool and workspace - mandatory + * ticket issued on login. Identifies tool and workspace - mandatory * @param uuid - * id of the file/package - mandatory + * id of the file/package - mandatory * @param version - * desired version - if null gets latest version - * + * desired version - if null gets latest version * @param toFileName - * the local file name with directory information. + * the local file name with directory information. */ public void saveFile(ITicket ticket, Long uuid, Long versionId, String toFileName) throws RepositoryCheckedException, AccessDeniedException, ItemNotFoundException, IOException; Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/SimpleRepository.java =================================================================== diff -u -r2de8f805211b6433aff4efd6fa9275a1b9933033 -r78eab2ee1acaf8d47f55aa94fc683a4f919e84ae --- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/SimpleRepository.java (.../SimpleRepository.java) (revision 2de8f805211b6433aff4efd6fa9275a1b9933033) +++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/SimpleRepository.java (.../SimpleRepository.java) (revision 78eab2ee1acaf8d47f55aa94fc683a4f919e84ae) @@ -23,49 +23,11 @@ package org.lamsfoundation.lams.contentrepository.service; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import java.util.SortedMap; -import java.util.SortedSet; -import java.util.TreeMap; -import java.util.UUID; - -import javax.servlet.http.HttpSession; - import org.apache.log4j.Logger; -import org.lamsfoundation.lams.contentrepository.CrCredential; -import org.lamsfoundation.lams.contentrepository.CrNode; -import org.lamsfoundation.lams.contentrepository.CrWorkspace; -import org.lamsfoundation.lams.contentrepository.CrWorkspaceCredential; -import org.lamsfoundation.lams.contentrepository.ICredentials; -import org.lamsfoundation.lams.contentrepository.ITicket; -import org.lamsfoundation.lams.contentrepository.IValue; -import org.lamsfoundation.lams.contentrepository.IVersionedNode; -import org.lamsfoundation.lams.contentrepository.IVersionedNodeAdmin; -import org.lamsfoundation.lams.contentrepository.NodeKey; -import org.lamsfoundation.lams.contentrepository.NodeType; -import org.lamsfoundation.lams.contentrepository.PropertyName; +import org.lamsfoundation.lams.contentrepository.*; import org.lamsfoundation.lams.contentrepository.dao.ICredentialDAO; import org.lamsfoundation.lams.contentrepository.dao.IWorkspaceDAO; -import org.lamsfoundation.lams.contentrepository.exception.AccessDeniedException; -import org.lamsfoundation.lams.contentrepository.exception.FileException; -import org.lamsfoundation.lams.contentrepository.exception.InvalidParameterException; -import org.lamsfoundation.lams.contentrepository.exception.ItemExistsException; -import org.lamsfoundation.lams.contentrepository.exception.ItemNotFoundException; -import org.lamsfoundation.lams.contentrepository.exception.LoginException; -import org.lamsfoundation.lams.contentrepository.exception.RepositoryCheckedException; -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.contentrepository.exception.WorkspaceNotFoundException; +import org.lamsfoundation.lams.contentrepository.exception.*; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; import org.lamsfoundation.lams.util.FileUtil; import org.lamsfoundation.lams.util.FileUtilException; @@ -74,30 +36,26 @@ import org.lamsfoundation.lams.web.session.SessionManager; import org.lamsfoundation.lams.web.util.AttributeNames; +import javax.servlet.http.HttpSession; +import java.io.*; +import java.util.*; + /** - * Many methods in this class will throw a RepositoryRuntimeException - * if the internal data is missing. This is not indicated - * on the method signatures. + * Many methods in this class will throw a RepositoryRuntimeException if the internal data is missing. This is not + * indicated on the method signatures. * - * The methods in this class do not explicitly check that a credential - * or ticket has been supplied. This is checked by the - * checkCredentialTicketBeforeAdvice advisor, for all transactioned - * calls (see the application context file). Therefore this - * class must be used in the Spring framework - if it is ever - * 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). + * The methods in this class do not explicitly check that a credential or ticket has been supplied. This is checked by + * the checkCredentialTicketBeforeAdvice advisor, for all transactioned calls (see the application context file). + * Therefore this class must be used in the Spring framework - if it is ever 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 - * hibernate session in the DAO and all sorts of errors will occur - * on lazy loading (even lazy loading withing the DAO) and when we - * write out nodes. + * 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 hibernate session in the DAO and all sorts + * of errors will occur on lazy loading (even lazy loading withing the DAO) and when we write out nodes. * - * So while the only footprint you see here of Spring is the beanfactory, - * the use of this as a singleton (generated by Spring) affects - * more than just how the object is created. + * So while the only footprint you see here of Spring is the beanfactory, the use of this as a singleton (generated by + * Spring) affects more than just how the object is created. * * @author Fiona Malikoff */ @@ -118,10 +76,9 @@ /* ********** 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. + * 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(); @@ -189,18 +146,18 @@ } /** - * Add a workspace, giving the credentials as the user of this workspace. - * It does not clear the password in the credentials + * 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. + * this user/password must already exist in the repository. Password will be checked. * @param workspaceName * @throws LoginException - * if credentials are not authorised to add/access the new workspace. + * if credentials are not authorised to add/access the new workspace. * @throws ItemExistsException - * if the workspace already exists. + * if the workspace already exists. * @throws RepositoryCheckedException - * if parameters are missing. + * if parameters are missing. */ @Override public CrWorkspace addWorkspace(ICredentials credentials, String workspaceName) @@ -231,11 +188,9 @@ } /** - * 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. - * Possibly this should only be available to an internal management tool - * *** Security Risk - I'm converting two passwords to a string... *** + * 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. Possibly this should only be available to an internal management + * tool *** Security Risk - I'm converting two passwords to a string... *** */ @Override public void createCredentials(ICredentials newCredential) @@ -262,17 +217,16 @@ } /** - * Update a credential. Name cannot change, so really only the password changes - * 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... *** + * Update a credential. Name cannot change, so really only the password changes 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) + * if the oldCredential fails login test (e.g. wrong password) * @throws RepositoryCheckedException - * if one of the credentials objects are missing + * if one of the credentials objects are missing * @throws RepositoryRuntimeException - * if an internal error occurs. + * if an internal error occurs. */ @Override public void updateCredentials(ICredentials oldCredential, ICredentials newCredential) @@ -302,14 +256,14 @@ } /** - * Checks that a password meets our password criteria. This could be implemented - * as a Strategy, but that's overkill! + * 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 + * if */ private void verifyNewPassword(char[] password) throws RepositoryCheckedException { if (password != null && password.length < 6) { @@ -319,9 +273,8 @@ } /** - * Assign credentials to a workspace. - * Will check the credentials to ensure they are in the database. - * Possibly this should only be available to an internal management tool + * Assign credentials to a workspace. Will check the credentials to ensure they are in the database. Possibly this + * should only be available to an internal management tool */ @Override public void assignCredentials(ICredentials credentials, String workspaceName) @@ -349,10 +302,9 @@ } /** - * Assign credentials to a workspace. Assume credentials are already checked. - * Possibly this should only be available to an internal management tool. Workspace - * is expected to be attached to a session. - * *** Security Risk - I'm converting the password to a string by reading it in from the database... *** + * Assign credentials to a workspace. Assume credentials are already checked. Possibly this should only be available + * to an internal management tool. Workspace is expected to be attached to a session. *** Security Risk - I'm + * converting the password to a string by reading it in from the database... *** */ private void assignCredentials(ICredentials credentials, CrWorkspace workspace) throws RepositoryCheckedException { @@ -386,9 +338,8 @@ CrWorkspaceCredential found = null; while (iter.hasNext() && found == null) { CrWorkspaceCredential item = (CrWorkspaceCredential) iter.next(); - if (item.getCrCredential() != null - && item.getCrCredential().getCredentialId().equals(crCredential.getCredentialId()) - && item.getCrWorkspace() != null + if (item.getCrCredential() != null && item.getCrCredential().getCredentialId() + .equals(crCredential.getCredentialId()) && item.getCrWorkspace() != null && item.getCrWorkspace().getWorkspaceId().equals(workspace.getWorkspaceId())) { found = item; } @@ -503,20 +454,14 @@ return nodeFactory.getNode(ticket.getWorkspaceId(), UUID.fromString(uuid), version); } - /* - * (non-Javadoc) - * - * @see org.lamsfoundation.lams.contentrepository.IRepository#getFileItem(org.lamsfoundation.lams.contentrepository. - * ITicket, java.lang.Long, java.lang.Long, java.lang.String) - */ @Override - public IVersionedNode getFileItem(ITicket ticket, Long nodeId, Long version, String relPath) + public IVersionedNode getFileItem(ITicket ticket, String nodeId, Long version, String relPath) throws AccessDeniedException, ItemNotFoundException, FileException { long start = System.currentTimeMillis(); String key = "getFileItem " + nodeId; - IVersionedNode latestNodeVersion = nodeFactory.getNode(ticket.getWorkspaceId(), nodeId, version); + IVersionedNode latestNodeVersion = getFileItem(ticket, nodeId, version); log.error(key + " latestNodeVersion " + (System.currentTimeMillis() - start)); if (relPath == null) { @@ -671,18 +616,17 @@ } /** - * Sets the property to a value, based on the specified type. Removes the property if the value is null. - * Use this for custom properties only - change the filename or mimetype at your own risk. + * Sets the property to a value, based on the specified type. Removes the property if the value is null. Use this + * for custom properties only - change the filename or mimetype at your own risk. * * @param name - * The name of a property of this node + * The name of a property of this node * @param value - * The value to be assigned + * The value to be assigned * @param type - * The type of the property + * The type of the property * @throws ValidationException - * if the call has made the node invalid. This would occur if the - * call had set the filename to blank. + * if the call has made the node invalid. This would occur if the call had set the filename to blank. */ @Override public void setProperty(ITicket ticket, Long uuid, Long versionId, String name, Object value, int type) @@ -886,6 +830,7 @@ } /* ********** setters and getters for DAOs *******************/ + /** * @return Returns the workspaceDAO. */ @@ -895,7 +840,7 @@ /** * @param workspaceDAO - * The workspaceDAO to set. + * The workspaceDAO to set. */ public void setWorkspaceDAO(IWorkspaceDAO workspaceDAO) { this.workspaceDAO = workspaceDAO; @@ -910,7 +855,7 @@ /** * @param credentialDAO - * The credentialDAO to set. + * The credentialDAO to set. */ public void setCredentialDAO(ICredentialDAO credentialDAO) { this.credentialDAO = credentialDAO; @@ -924,4 +869,4 @@ this.nodeFactory = nodeFactory; } -} +} \ No newline at end of file