Index: lams_build/lib/lams/lams-contentrepository.jar
===================================================================
diff -u -r757c334b1beed73d02cc15c996d08079d5228fee -r12315777fce60950a53e92b6c992e602531dea8b
Binary files differ
Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/dao/IFileDAO.java
===================================================================
diff -u -rd69fd0c0b6e3af330bb1ddbf3099022feca3f092 -r12315777fce60950a53e92b6c992e602531dea8b
--- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/dao/IFileDAO.java (.../IFileDAO.java) (revision d69fd0c0b6e3af330bb1ddbf3099022feca3f092)
+++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/dao/IFileDAO.java (.../IFileDAO.java) (revision 12315777fce60950a53e92b6c992e602531dea8b)
@@ -59,4 +59,9 @@
public String getFilePath(Long uuid, Long versionId)
throws FileException;
+ /**
+ * Is there a file on disk? Used to validate file nodes
+ */
+ public boolean fileExists(Long uuid, Long versionId )
+ throws FileException;
}
\ No newline at end of file
Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/dao/file/FileDAO.java
===================================================================
diff -u -r59a810e17dffd1a080d8f1637cd202b9cc6fa4cb -r12315777fce60950a53e92b6c992e602531dea8b
--- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/dao/file/FileDAO.java (.../FileDAO.java) (revision 59a810e17dffd1a080d8f1637cd202b9cc6fa4cb)
+++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/dao/file/FileDAO.java (.../FileDAO.java) (revision 12315777fce60950a53e92b6c992e602531dea8b)
@@ -222,6 +222,16 @@
}
/**
+ * Is there a file on disk? Used to validate file nodes
+ */
+ public boolean fileExists(Long uuid, Long versionId )
+ throws FileException {
+ File file = new File( getFilePath(uuid, versionId));
+ return ( file.exists() );
+ }
+
+ /* ***************** Getters and setters for Spring *****************/
+ /**
* @return Returns the repositoryLocation.
*/
public String getRepositoryLocation() {
Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/SimpleVersionedNode.java
===================================================================
diff -u -r1492a6385b0f6e855ce08f2fe7570b4af8b53b21 -r12315777fce60950a53e92b6c992e602531dea8b
--- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/SimpleVersionedNode.java (.../SimpleVersionedNode.java) (revision 1492a6385b0f6e855ce08f2fe7570b4af8b53b21)
+++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/SimpleVersionedNode.java (.../SimpleVersionedNode.java) (revision 12315777fce60950a53e92b6c992e602531dea8b)
@@ -491,7 +491,6 @@
.append("node", node)
.append("nodeVersion", nodeVersion)
.append("newIStream", newIStream)
- .append("ticket", ticket)
.toString();
}
@@ -538,7 +537,9 @@
*
* - All nodes must have a node type and created date.
*
- Root nodes must not have a file
- *
- File nodes must have a file, must have a MIMETYPE property
+ *
- File nodes must have a file, must have a MIMETYPE property. Note:
+ * 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.
*/
@@ -560,8 +561,19 @@
errors = errors + "\nCreated datetimestamp is missing. ";
if ( isNodeType(NodeType.FILENODE) ) {
- if ( newIStream == null )
- errors = errors + "\nNode is a file node but the file is missing. ";
+ Long uuid = node.getNodeId();
+ Long versionId = nodeVersion.getVersionId();
+ try {
+ // 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)) )
+ errors = errors + "\nNode is a file node but the file is missing. ";
+ } catch (FileException fe){
+ errors = "Unable to validation node due to file exception: "+fe.getMessage();
+ log.error("File exception occured while validating node "+this.toString(), fe);
+ }
if ( ! hasProperty(PropertyName.FILENAME) )
errors = errors + "\nNode is a file node but the filename is unknown";
} else {
@@ -579,7 +591,9 @@
}
}
- /** Save the changes to this node.
+ /** 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.
Index: lams_contentrepository/test/java/org/lamsfoundation/lams/contentrepository/service/TestSimpleRepository.java
===================================================================
diff -u -r1492a6385b0f6e855ce08f2fe7570b4af8b53b21 -r12315777fce60950a53e92b6c992e602531dea8b
--- lams_contentrepository/test/java/org/lamsfoundation/lams/contentrepository/service/TestSimpleRepository.java (.../TestSimpleRepository.java) (revision 1492a6385b0f6e855ce08f2fe7570b4af8b53b21)
+++ lams_contentrepository/test/java/org/lamsfoundation/lams/contentrepository/service/TestSimpleRepository.java (.../TestSimpleRepository.java) (revision 12315777fce60950a53e92b6c992e602531dea8b)
@@ -243,12 +243,13 @@
deleteVersion(keys.getUuid(), one);
checkFileNodeDoesNotExist(fileDAO, keys.getUuid(), one, 0);
checkFileNodeDoesNotExist(fileDAO, keys.getUuid(), two, 0);
+
} catch (FileNotFoundException e) {
fail("Unexpected exception "+e.getMessage());
}
}
- /** create a node with two versions and test deleting them using delete node */
+ /** create a node with two versions and test deleting them using delete node. ALso tests set property */
public void testFileItemDeleteNode() {
IFileDAO fileDAO = (FileDAO)context.getBean("fileDAO", FileDAO.class);
@@ -259,6 +260,8 @@
testAddFileItem(CRResources.getZipFile(), CRResources.zipFileName,keys.getUuid(),two);
checkFileNodeExist(fileDAO, keys.getUuid(), two, 2);
+ testSetPropertyFile(keys);
+
deleteNode(keys.getUuid());
checkFileNodeDoesNotExist(fileDAO, keys.getUuid(), one, 0);
checkFileNodeDoesNotExist(fileDAO, keys.getUuid(), two, 0);
@@ -469,7 +472,7 @@
public void testPackageItem() {
NodeKey keys = testPackageItem(null);
testPackageItem(keys.getUuid());
- testSetProperty(keys);
+ testSetPropertyPackage(keys);
}
private NodeKey testPackageItem(Long uuid) {
@@ -543,8 +546,8 @@
return keys;
}
- private void testSetProperty(NodeKey keys) {
- String propertyName = "CUSTOM";
+ private void testSetPropertyPackage(NodeKey keys) {
+ String propertyName = "CUSTOMA";
Boolean value = Boolean.TRUE;
List nodes;
@@ -579,6 +582,27 @@
}
+ private void testSetPropertyFile(NodeKey keys) {
+ String propertyName = "CUSTOMB";
+ String value = "avalue";
+
+ try {
+ IVersionedNode node = repository.getFileItem(ticket, keys.getUuid(), keys.getVersion());
+ assertTrue("File node found (A)", node != null && node.isNodeType(NodeType.FILENODE));
+ repository.setProperty(ticket, keys.getUuid(), keys.getVersion(), propertyName, value, PropertyType.BOOLEAN);
+
+ // now, is the property set?
+ node = repository.getFileItem(ticket, keys.getUuid(), keys.getVersion());
+ assertTrue("File node found (A)", node != null && node.isNodeType(NodeType.FILENODE));
+ IValue newValue = node.getProperty(propertyName);
+ assertEquals("newValue "+newValue+" equals "+value, value, newValue.getString());
+
+ } catch (RepositoryCheckedException e) {
+ failUnexpectedException("testSetProperty",e);
+ }
+
+ }
+
/**
* @param keys
* @param relPath