IVersionedNode getFileNode(Long uuid)
* Gets the file node from the repository. To get the file stream, do getFileNode().getFile()
* For example:
- *
+ *
*
* NodeKey nodeKey = handler.uploadFile(istream, fileName, fileMimeType);
* Long uuid = nodeKey.getUuid();
@@ -111,7 +111,7 @@
private IRepositoryService repositoryService;
private ITicket ticket;
-
+
private String repositoryWorkspaceName;
private String repositoryUser;
private String repositoryId;
@@ -125,7 +125,7 @@
}
return repositoryWorkspaceName;
}
-
+
public void setRepositoryWorkspaceName(String repositoryWorkspaceName) {
this.repositoryWorkspaceName = repositoryWorkspaceName;
}
@@ -135,9 +135,9 @@
log.error(
"Accessing ToolContentHandler bean, but repositoryUser has not been defined. Please define this property in ApplicationContext.xml");
}
- return repositoryUser;
+ return repositoryUser;
}
-
+
public void setRepositoryUser(String repositoryUser) {
this.repositoryUser = repositoryUser;
}
@@ -147,9 +147,9 @@
log.error(
"Accessing ToolContentHandler bean, but repositoryWorkspaceName has not been defined. Please define this property in ApplicationContext.xml");
}
- return repositoryId.toCharArray();
+ return repositoryId.toCharArray();
}
-
+
public void setRepositoryId(String repositoryId) {
this.repositoryId = repositoryId;
}
@@ -162,7 +162,7 @@
// make sure workspace exists - sometimes it does not get created when creating a ticket
cred = new SimpleCredentials(getRepositoryUser(), getRepositoryId());
doLogin = !repositoryService.workspaceExists(cred, getRepositoryWorkspaceName());
- }
+ }
if (doLogin) {
if (cred == null) {
cred = new SimpleCredentials(getRepositoryUser(), getRepositoryId());
@@ -173,16 +173,18 @@
}
@Override
- public NodeKey uploadFile(InputStream stream, String fileName, String mimeType)
+ public NodeKey uploadFile(InputStream stream, String fileName, String mimeType, boolean generatePortraitUuid)
throws RepositoryCheckedException, InvalidParameterException, RepositoryCheckedException {
NodeKey nodeKey = null;
try {
try {
- nodeKey = repositoryService.addFileItem(getTicket(false), stream, fileName, mimeType, null);
+ nodeKey = repositoryService.addFileItem(getTicket(false), stream, fileName, mimeType, null,
+ generatePortraitUuid);
} catch (AccessDeniedException e) {
log.warn("Unable to access repository to add file " + fileName + "AccessDeniedException: "
+ e.getMessage() + " Retrying login.");
- nodeKey = repositoryService.addFileItem(getTicket(true), stream, fileName, mimeType, null);
+ nodeKey = repositoryService.addFileItem(getTicket(true), stream, fileName, mimeType, null,
+ generatePortraitUuid);
}
} catch (RepositoryCheckedException e2) {
@@ -193,8 +195,14 @@
return nodeKey;
}
-
+
@Override
+ public NodeKey uploadFile(InputStream stream, String fileName, String mimeType)
+ throws RepositoryCheckedException, InvalidParameterException, RepositoryCheckedException {
+ return uploadFile(stream, fileName, mimeType, false);
+ }
+
+ @Override
public NodeKey updateFile(Long uuid, InputStream stream, String fileName, String mimeType)
throws RepositoryCheckedException, InvalidParameterException, RepositoryCheckedException {
NodeKey nodeKey = null;
@@ -229,7 +237,7 @@
/**
* Save a directory of files in the content repository.
- *
+ *
* @param ticket
* ticket issued on login. Identifies tool and workspace - mandatory
* @param dirPath
@@ -354,6 +362,25 @@
}
@Override
+ public void deleteFile(UUID portraitUuid) throws InvalidParameterException, RepositoryCheckedException {
+ try {
+ try {
+ repositoryService.deleteNode(getTicket(false), portraitUuid);
+ } catch (AccessDeniedException e) {
+ log.warn("Unable to access repository to delete file id" + portraitUuid + "AccessDeniedException: "
+ + e.getMessage() + " Retrying login.");
+ repositoryService.deleteNode(getTicket(true), portraitUuid);
+ }
+ } catch (ItemNotFoundException e1) {
+ // didn't exist so don't need to delete. Ignore problem.
+ } catch (RepositoryCheckedException e2) {
+ log.error("Unable delete file id" + portraitUuid + "Repository Exception: " + e2.getMessage()
+ + " Retry not possible.");
+ throw e2;
+ }
+ }
+
+ @Override
public InputStream getFileInputStream(Long uuid)
throws ItemNotFoundException, FileException, RepositoryCheckedException {
try {
@@ -387,7 +414,7 @@
* out.flush();
* return file;
* }
- *
+ *
* protected byte[] getBytes(File file) throws FileNotFoundException, Exception {
* byte[] byteArray = new byte[(int) file.length()];
* FileInputStream stream = new FileInputStream(file);
Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/INodeFactory.java
===================================================================
diff -u -rea80430beb4497f12c92db2580341f21750a5a43 -r7a2a590146e0899d86b5b810547ba2d4ca83aa18
--- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/INodeFactory.java (.../INodeFactory.java) (revision ea80430beb4497f12c92db2580341f21750a5a43)
+++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/INodeFactory.java (.../INodeFactory.java) (revision 7a2a590146e0899d86b5b810547ba2d4ca83aa18)
@@ -21,10 +21,10 @@
* ****************************************************************
*/
-
package org.lamsfoundation.lams.contentrepository.service;
import java.io.InputStream;
+import java.util.UUID;
import org.lamsfoundation.lams.contentrepository.CrNode;
import org.lamsfoundation.lams.contentrepository.CrWorkspace;
@@ -43,7 +43,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.
@@ -54,12 +54,13 @@
*/
public abstract SimpleVersionedNode createFileNode(CrWorkspace workspace, SimpleVersionedNode parentNode,
String relPath, InputStream istream, String filename, String mimeType, String versionDescription,
- Integer userId) throws org.lamsfoundation.lams.contentrepository.exception.InvalidParameterException;
+ Integer userId, boolean generatePortraitUuid)
+ throws org.lamsfoundation.lams.contentrepository.exception.InvalidParameterException;
/**
* 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 +75,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 +88,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,17 +98,20 @@
* 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)
throws ItemNotFoundException;
+ public abstract SimpleVersionedNode getNode(Long workspaceId, UUID portraitUuid, Long versionId)
+ throws ItemNotFoundException;
+
/**
* Build a SimpleVersionedNode, reading the data from the database.
* Creates a new (empty) version ready for updating.
@@ -118,9 +122,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 +136,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
Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/IRepositoryService.java
===================================================================
diff -u -rea80430beb4497f12c92db2580341f21750a5a43 -r7a2a590146e0899d86b5b810547ba2d4ca83aa18
--- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/IRepositoryService.java (.../IRepositoryService.java) (revision ea80430beb4497f12c92db2580341f21750a5a43)
+++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/IRepositoryService.java (.../IRepositoryService.java) (revision 7a2a590146e0899d86b5b810547ba2d4ca83aa18)
@@ -28,6 +28,7 @@
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;
@@ -170,7 +171,8 @@
* 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, boolean generatePortraitUuid)
+ throws FileException, AccessDeniedException, InvalidParameterException;
/**
* Add a new package of files to the repository. If startFile
@@ -329,6 +331,9 @@
public abstract IVersionedNode getFileItem(ITicket ticket, Long uuid, Long version)
throws AccessDeniedException, ItemNotFoundException, FileException;
+ IVersionedNode getFileItem(ITicket ticket, String portraitUuid, Long version)
+ 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
@@ -441,6 +446,9 @@
public String[] deleteNode(ITicket ticket, Long uuid)
throws AccessDeniedException, InvalidParameterException, ItemNotFoundException;
+ public String[] deleteNode(ITicket ticket, UUID portraitUuid)
+ 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.
Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/NodeFactory.java
===================================================================
diff -u -rea80430beb4497f12c92db2580341f21750a5a43 -r7a2a590146e0899d86b5b810547ba2d4ca83aa18
--- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/NodeFactory.java (.../NodeFactory.java) (revision ea80430beb4497f12c92db2580341f21750a5a43)
+++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/NodeFactory.java (.../NodeFactory.java) (revision 7a2a590146e0899d86b5b810547ba2d4ca83aa18)
@@ -21,13 +21,14 @@
* ****************************************************************
*/
-
package org.lamsfoundation.lams.contentrepository.service;
import java.io.InputStream;
import java.util.Date;
import java.util.Iterator;
+import java.util.List;
import java.util.Set;
+import java.util.UUID;
import org.apache.log4j.Logger;
import org.lamsfoundation.lams.contentrepository.CrNode;
@@ -68,26 +69,27 @@
/*
* (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)
*/
@Override
public SimpleVersionedNode createFileNode(CrWorkspace workspace, SimpleVersionedNode parentNode, String relPath,
- InputStream istream, String filename, String mimeType, String versionDescription, Integer userId)
+ InputStream istream, String filename, String mimeType, String versionDescription, Integer userId,
+ boolean generatePortraitUuid)
throws org.lamsfoundation.lams.contentrepository.exception.InvalidParameterException {
SimpleVersionedNode initialNodeVersion = createBasicNode(NodeType.FILENODE, workspace, parentNode, relPath,
- versionDescription, userId);
+ versionDescription, userId, generatePortraitUuid);
initialNodeVersion.setFile(istream, filename, mimeType);
return initialNodeVersion;
}
/*
* (non-Javadoc)
- *
+ *
* @see org.lamsfoundation.lams.contentrepository.service.INodeFactory#createPackageNode(org.lamsfoundation.lams.
* contentrepository.CrWorkspace, java.lang.String, java.lang.String)
*/
@@ -96,15 +98,15 @@
Integer userId) throws org.lamsfoundation.lams.contentrepository.exception.InvalidParameterException {
SimpleVersionedNode initialNodeVersion = createBasicNode(NodeType.PACKAGENODE, workspace, null, null,
- versionDescription, userId);
+ versionDescription, userId, false);
initialNodeVersion.setProperty(PropertyName.INITIALPATH, initialPath);
return initialNodeVersion;
}
/*
* (non-Javadoc)
- *
+ *
* @see org.lamsfoundation.lams.contentrepository.service.INodeFactory#createDataNode(org.lamsfoundation.lams.
* contentrepository.CrWorkspace, org.lamsfoundation.lams.contentrepository.service.SimpleVersionedNode,
* java.lang.String)
@@ -115,21 +117,24 @@
throws org.lamsfoundation.lams.contentrepository.exception.InvalidParameterException {
SimpleVersionedNode initialNodeVersion = createBasicNode(NodeType.DATANODE, workspace, parentNode, null,
- versionDescription, userId);
+ versionDescription, userId, false);
return initialNodeVersion;
}
/** Create the core part of a node */
private SimpleVersionedNode createBasicNode(String nodeType, CrWorkspace workspace, SimpleVersionedNode parentNode,
- String relPath, String versionDescription, Integer userId) {
+ String relPath, String versionDescription, Integer userId, boolean generatePortraitUuid) {
SimpleVersionedNode initialNodeVersion = beanFactory.getBean("node", SimpleVersionedNode.class);
Date createdDate = new Date(System.currentTimeMillis());
CrNodeVersion parentNodeVersion = parentNode != null ? parentNode.getNodeVersion() : null;
CrNode node = new CrNode(relPath, nodeType, createdDate, userId, workspace, parentNodeVersion,
versionDescription);
+ if (generatePortraitUuid) {
+ node.setPortraitUuid(UUID.randomUUID());
+ }
CrNodeVersion nodeVersion = node.getNodeVersion(null);
initialNodeVersion.setNode(node);
@@ -144,7 +149,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see
* org.lamsfoundation.lams.contentrepository.service.INodeFactory#getNode(org.lamsfoundation.lams.contentrepository.
* CrNode, java.lang.Long)
@@ -159,7 +164,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.lamsfoundation.lams.contentrepository.service.INodeFactory#getNode(java.lang.Long, java.lang.Long,
* java.lang.Long)
*/
@@ -192,9 +197,39 @@
return getNode(node, versionId);
}
+ @Override
+ public SimpleVersionedNode getNode(Long workspaceId, UUID portraitUuid, Long versionId)
+ throws ItemNotFoundException {
+
+ if (portraitUuid == null) {
+ throw new ItemNotFoundException("UUID is null, unable to find node.");
+ }
+
+ if (workspaceId == null) {
+ throw new ItemNotFoundException("Workspace Id is null, unable to find node.");
+ }
+
+ CrNode node = null;
+ List result = nodeDAO.findByProperty(CrNode.class, "portraitUuid", portraitUuid);
+ node = result.isEmpty() ? null : result.get(0);
+ if (node == null) {
+
+ throw new ItemNotFoundException("Node " + portraitUuid + " not found.");
+
+ } else if (!workspaceId.equals(node.getCrWorkspace().getWorkspaceId())) {
+
+ log.error("Security warning. User of workspace " + workspaceId + " is trying to access node " + portraitUuid
+ + " which is in workspace " + node.getCrWorkspace().getWorkspaceId()
+ + " Request for node will be rejected.");
+ throw new ItemNotFoundException("Node " + portraitUuid + " does not exist in workspace " + workspaceId);
+ }
+
+ return getNode(node, versionId);
+ }
+
/*
* (non-Javadoc)
- *
+ *
* @see org.lamsfoundation.lams.contentrepository.service.INodeFactory#getNode(java.lang.Long, java.lang.Long,
* java.lang.Long, java.lang.String)
*/
@@ -220,7 +255,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see
* org.lamsfoundation.lams.contentrepository.service.INodeFactory#copy(org.lamsfoundation.lams.contentrepository.
* service.SimpleVersionedNode)
@@ -235,7 +270,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 +303,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)) {
@@ -300,7 +335,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.lamsfoundation.lams.contentrepository.service.INodeFactory#getNodeDAO()
*/
@Override
@@ -310,7 +345,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.lamsfoundation.lams.contentrepository.service.INodeFactory#setNodeDAO(org.lamsfoundation.lams.
* contentrepository.dao.INodeDAO)
*/
@@ -322,7 +357,7 @@
/* **** Method for BeanFactoryAware interface *****************/
/*
* (non-Javadoc)
- *
+ *
* @see
* org.lamsfoundation.lams.contentrepository.service.INodeFactory#setBeanFactory(org.springframework.beans.factory.
* BeanFactory)
Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/SimpleRepository.java
===================================================================
diff -u -rea80430beb4497f12c92db2580341f21750a5a43 -r7a2a590146e0899d86b5b810547ba2d4ca83aa18
--- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/SimpleRepository.java (.../SimpleRepository.java) (revision ea80430beb4497f12c92db2580341f21750a5a43)
+++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/SimpleRepository.java (.../SimpleRepository.java) (revision 7a2a590146e0899d86b5b810547ba2d4ca83aa18)
@@ -21,7 +21,6 @@
* ****************************************************************
*/
-
package org.lamsfoundation.lams.contentrepository.service;
import java.io.FileNotFoundException;
@@ -37,6 +36,7 @@
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
+import java.util.UUID;
import javax.servlet.http.HttpSession;
@@ -87,7 +87,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
@@ -134,10 +134,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 +155,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.lamsfoundation.lams.contentrepository.IRepository#login(org.lamsfoundation.lams.contentrepository.
* ICredentials, java.lang.String)
*/
@@ -182,7 +182,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 +191,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 +266,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 +304,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 +404,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see
* org.lamsfoundation.lams.contentrepository.IRepository#logout(org.lamsfoundation.lams.contentrepository.ITicket)
*/
@@ -426,19 +426,20 @@
/*
* (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)
*/
@Override
public NodeKey addFileItem(ITicket ticket, InputStream istream, String filename, String mimeType,
- String versionDescription) throws FileException, AccessDeniedException, InvalidParameterException {
+ String versionDescription, boolean generatePortraitUUid)
+ throws FileException, AccessDeniedException, InvalidParameterException {
try {
CrWorkspace workspace = getWorkspace(ticket.getWorkspaceId());
Integer userId = getCurrentUserId();
SimpleVersionedNode initialNodeVersion = nodeFactory.createFileNode(workspace, null, null, istream,
- filename, mimeType, versionDescription, userId);
+ filename, mimeType, versionDescription, userId, generatePortraitUUid);
initialNodeVersion.save();
return initialNodeVersion.getNodeKey();
} catch (ValidationException e) {
@@ -452,7 +453,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 +487,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.lamsfoundation.lams.contentrepository.IRepository#getFileItem(org.lamsfoundation.lams.contentrepository.
* ITicket, java.lang.Long, java.lang.Long)
*/
@@ -497,9 +498,15 @@
return nodeFactory.getNode(ticket.getWorkspaceId(), uuid, version);
}
+ @Override
+ public IVersionedNode getFileItem(ITicket ticket, String portraitUuid, Long version)
+ throws AccessDeniedException, ItemNotFoundException, FileException {
+ return nodeFactory.getNode(ticket.getWorkspaceId(), UUID.fromString(portraitUuid), version);
+ }
+
/*
* (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 +537,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 +563,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.lamsfoundation.lams.contentrepository.IRepository#getNodeList(org.lamsfoundation.lams.contentrepository.
* ITicket)
*/
@@ -582,7 +589,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see
* org.lamsfoundation.lams.contentrepository.IRepository#getVersionHistory(org.lamsfoundation.lams.contentrepository
* .ITicket, java.lang.Long)
@@ -596,7 +603,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 +634,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 +697,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see
* org.lamsfoundation.lams.contentrepository.IRepository#copyNodeVersion(org.lamsfoundation.lams.contentrepository.
* ITicket, java.lang.Long, java.lang.Long)
@@ -723,7 +730,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 +811,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)
@@ -828,9 +835,28 @@
}
+ @Override
+ public String[] deleteNode(ITicket ticket, UUID portraitUuid)
+ throws AccessDeniedException, InvalidParameterException, ItemNotFoundException {
+
+ if (portraitUuid == null) {
+ throw new InvalidParameterException("UUID is required for deleteItem.");
+ }
+
+ // get the first version of the node and delete from there.
+ SimpleVersionedNode latestNodeVersion = nodeFactory.getNode(ticket.getWorkspaceId(), portraitUuid, new Long(1));
+ if (latestNodeVersion.hasParentNode()) {
+ throw new InvalidParameterException("You cannot delete a node that is in a package (ie has a parent). "
+ + "Please delete the parent. Node UUID " + portraitUuid);
+ }
+ List problemPaths = latestNodeVersion.deleteNode();
+ return problemPaths != null ? (String[]) problemPaths.toArray(new String[problemPaths.size()]) : new String[0];
+
+ }
+
/*
* (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,10 +876,12 @@
}
+ @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;
}
Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/SimpleVersionedNode.java
===================================================================
diff -u -rea80430beb4497f12c92db2580341f21750a5a43 -r7a2a590146e0899d86b5b810547ba2d4ca83aa18
--- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/SimpleVersionedNode.java (.../SimpleVersionedNode.java) (revision ea80430beb4497f12c92db2580341f21750a5a43)
+++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/SimpleVersionedNode.java (.../SimpleVersionedNode.java) (revision 7a2a590146e0899d86b5b810547ba2d4ca83aa18)
@@ -21,7 +21,6 @@
* ****************************************************************
*/
-
package org.lamsfoundation.lams.contentrepository.service;
import java.io.File;
@@ -143,12 +142,12 @@
@Override
public NodeKey getNodeKey() {
- return new NodeKey(getUUID(), getVersion());
+ return new NodeKey(getUUID(), getVersion(), getPortraitUuid());
}
/*
* (non-Javadoc)
- *
+ *
* @see org.lamsfoundation.lams.contentrepository.IVersionedNode#setProperty(java.lang.String, java.lang.String,
* int)
*/
@@ -160,7 +159,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.lamsfoundation.lams.contentrepository.IVersionedNode#setProperty(java.lang.String, java.lang.String)
*/
@Override
@@ -171,7 +170,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.lamsfoundation.lams.contentrepository.IVersionedNode#setProperty(java.lang.String, boolean)
*/
@Override
@@ -182,7 +181,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.lamsfoundation.lams.contentrepository.IVersionedNode#setProperty(java.lang.String, double)
*/
@Override
@@ -193,7 +192,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.lamsfoundation.lams.contentrepository.IVersionedNode#setProperty(java.lang.String, long)
*/
@Override
@@ -204,7 +203,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.lamsfoundation.lams.contentrepository.IVersionedNode#setProperty(java.lang.String, java.util.Calendar)
*/
@Override
@@ -242,6 +241,12 @@
return node.getNodeId();
}
+ @Override
+ public String getPortraitUuid() {
+ nodeObjectInitilised("Unable to get portrait UUID");
+ return node.getPortraitUuid() == null ? null : node.getPortraitUuid().toString();
+ }
+
/**
* @see org.lamsfoundation.lams.contentrepository.IVersionedNode#hasProperty(java.lang.String)
*/
@@ -271,7 +276,7 @@
/**
* (non-Javadoc)
- *
+ *
* @see org.lamsfoundation.lams.contentrepository.IVersionedNode#isNodeType(java.lang.String)
*/
@Override
@@ -284,7 +289,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 +385,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.
*/
@@ -416,7 +421,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 +483,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.
*/
@@ -541,19 +546,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 {
@@ -615,7 +620,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:";
@@ -667,7 +673,7 @@
/**
* 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 {
@@ -695,7 +701,7 @@
/**
* Another case for the factory?
- *
+ *
* @see org.lamsfoundation.lams.contentrepository.IVersionedNode#getNode(String relPath)
*/
@Override
@@ -719,7 +725,7 @@
/**
* If no nodes are found, returns an empty set.
- *
+ *
* @see org.lamsfoundation.lams.contentrepository.IVersionedNode#getChildNodes()
*/
@Override
@@ -782,13 +788,13 @@
/**
* 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,7 +828,7 @@
// 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();
@@ -890,7 +896,7 @@
/**
* 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:
@@ -985,7 +991,7 @@
// no need to the new node as a child node, as createFileNode will do it.
FileInputStream istream = new FileInputStream(file);
nodeFactory.createFileNode(workspace, this, relPath, istream, filename, null, versionDescription,
- userId);
+ userId, false);
}
}
@@ -1009,11 +1015,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
Index: lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/dto/GBUserGridRowDTO.java
===================================================================
diff -u -rfd2cfad55c7c517931f69334ce644d509ec28140 -r7a2a590146e0899d86b5b810547ba2d4ca83aa18
--- lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/dto/GBUserGridRowDTO.java (.../GBUserGridRowDTO.java) (revision fd2cfad55c7c517931f69334ce644d509ec28140)
+++ lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/dto/GBUserGridRowDTO.java (.../GBUserGridRowDTO.java) (revision 7a2a590146e0899d86b5b810547ba2d4ca83aa18)
@@ -41,7 +41,7 @@
private String lastName;
private String login;
private String currentActivity;
- private Long portraitId;
+ private String portraitId;
private boolean hasArchivedMarks;
@@ -54,12 +54,12 @@
this.firstName = user.getFirstName();
this.lastName = user.getLastName();
this.login = user.getLogin();
- this.setPortraitId(user.getPortraitUuid());
+ this.setPortraitId(user.getPortraitUuid() == null ? null : user.getPortraitUuid().toString());
}
@Override
public ArrayList toStringArray(GBGridView view) {
- ArrayList ret = new ArrayList();
+ ArrayList ret = new ArrayList<>();
ret.add(id.toString());
@@ -150,11 +150,11 @@
this.currentActivity = currentActivity;
}
- public Long getPortraitId() {
+ public String getPortraitId() {
return portraitId;
}
- public void setPortraitId(Long portraitId) {
+ public void setPortraitId(String portraitId) {
this.portraitId = portraitId;
}
Index: lams_tool_assessment/src/java/org/lamsfoundation/lams/tool/assessment/dao/hibernate/AssessmentUserDAOHibernate.java
===================================================================
diff -u -rdcdc1487609bd4f00afaa93c09272d84ab0cd325 -r7a2a590146e0899d86b5b810547ba2d4ca83aa18
--- lams_tool_assessment/src/java/org/lamsfoundation/lams/tool/assessment/dao/hibernate/AssessmentUserDAOHibernate.java (.../AssessmentUserDAOHibernate.java) (revision dcdc1487609bd4f00afaa93c09272d84ab0cd325)
+++ lams_tool_assessment/src/java/org/lamsfoundation/lams/tool/assessment/dao/hibernate/AssessmentUserDAOHibernate.java (.../AssessmentUserDAOHibernate.java) (revision 7a2a590146e0899d86b5b810547ba2d4ca83aa18)
@@ -25,6 +25,7 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.UUID;
import org.hibernate.query.NativeQuery;
import org.hibernate.query.Query;
@@ -50,12 +51,12 @@
private static final String FIND_MARK_STATS_FOR_SESSION = "SELECT MIN(grade) min_grade, AVG(grade) avg_grade, MAX(grade) max_grade FROM tl_laasse10_assessment_result "
+ " WHERE finish_date IS NOT NULL AND latest = 1 AND session_id = :sessionId";
- private static final String LOAD_MARKS_FOR_LEADERS = "SELECT r.grade FROM tl_laasse10_assessment_result r "
+ private static final String LOAD_MARKS_FOR_LEADERS = "SELECT r.grade FROM tl_laasse10_assessment_result r "
+ " JOIN tl_laasse10_session s ON r.session_id = s.session_id AND r.user_uid = s.group_leader_uid "
+ " JOIN tl_laasse10_assessment a ON s.assessment_uid = a.uid "
+ " WHERE r.finish_date IS NOT NULL AND r.latest = 1 AND a.content_id = :toolContentId";
private static final String FIND_MARK_STATS_FOR_LEADERS = "SELECT MIN(grade) min_grade, AVG(grade) avg_grade, MAX(grade) max_grade, COUNT(grade) num_complete "
- + " FROM tl_laasse10_assessment_result r "
+ + " FROM tl_laasse10_assessment_result r "
+ " JOIN tl_laasse10_session s ON r.session_id = s.session_id AND r.user_uid = s.group_leader_uid "
+ " JOIN tl_laasse10_assessment a ON s.assessment_uid = a.uid "
+ " WHERE r.finish_date IS NOT NULL AND r.latest = 1 AND a.content_id = :toolContentId";
@@ -104,10 +105,10 @@
private static String LOAD_USERS_ORDERED_BY_SESSION_SELECT = "SELECT DISTINCT user.user_id, user.last_name, user.first_name, user.login_name, result.grade ";
private static String LOAD_USERS_ORDERED_BY_SESSION_FROM = " FROM tl_laasse10_user user ";
private static String LOAD_USERS_ORDERED_BY_SESSION_JOIN = " INNER JOIN tl_laasse10_session session"
- + " ON user.session_uid=session.uid LEFT OUTER JOIN tl_laasse10_assessment_result result "
- + " ON result.user_uid = user.uid AND result.finish_date IS NOT NULL"
- + " AND result.latest = 1 WHERE session.session_id = :sessionId "
- + " AND (CONCAT(user.last_name, ' ', user.first_name) LIKE CONCAT('%', :searchString, '%')) ";
+ + " ON user.session_uid=session.uid LEFT OUTER JOIN tl_laasse10_assessment_result result "
+ + " ON result.user_uid = user.uid AND result.finish_date IS NOT NULL"
+ + " AND result.latest = 1 WHERE session.session_id = :sessionId "
+ + " AND (CONCAT(user.last_name, ' ', user.first_name) LIKE CONCAT('%', :searchString, '%')) ";
private static String LOAD_USERS_ORDERED_ORDER_BY_NAME = "ORDER BY (CONCAT(user.last_name, ' ', user.first_name)) ";
private static String LOAD_USERS_ORDERED_ORDER_BY_TOTAL = "ORDER BY result.grade ";
@@ -116,18 +117,17 @@
public List getPagedUsersBySession(Long sessionId, int page, int size, String sortBy,
String sortOrder, String searchString, IUserManagementService userManagementService) {
String[] portraitStrings = userManagementService.getPortraitSQL("user.user_id");
-
- StringBuilder bldr = new StringBuilder(LOAD_USERS_ORDERED_BY_SESSION_SELECT)
- .append(portraitStrings[0])
- .append(LOAD_USERS_ORDERED_BY_SESSION_FROM)
- .append(portraitStrings[1])
+
+ StringBuilder bldr = new StringBuilder(LOAD_USERS_ORDERED_BY_SESSION_SELECT).append(portraitStrings[0])
+ .append(LOAD_USERS_ORDERED_BY_SESSION_FROM).append(portraitStrings[1])
.append(LOAD_USERS_ORDERED_BY_SESSION_JOIN);
- if ( "total".equalsIgnoreCase(sortBy) )
+ if ("total".equalsIgnoreCase(sortBy)) {
bldr.append(LOAD_USERS_ORDERED_ORDER_BY_TOTAL);
- else
+ } else {
bldr.append(LOAD_USERS_ORDERED_ORDER_BY_NAME);
+ }
bldr.append(sortOrder);
-
+
NativeQuery