RM-2045 Add validation that the node is a content node.

This is needed as the API method is specifically for content nodes. We
will deal with record nodes later, and possible folder nodes much later.

+review RM-25

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@102157 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tom Page
2015-04-20 08:39:06 +00:00
parent 173c323665
commit 9d888b256e
4 changed files with 48 additions and 6 deletions

View File

@@ -21,8 +21,10 @@ package org.alfresco.module.org_alfresco_module_rm.classification;
import java.util.List;
import java.util.Set;
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationServiceException.InvalidNode;
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationServiceException.LevelIdNotFound;
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationServiceException.ReasonIdNotFound;
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.NodeRef;
/**
@@ -58,7 +60,10 @@ public interface ClassificationService
* @param document The node to classify.
* @throws LevelIdNotFound If the supplied level id is not found.
* @throws ReasonIdNotFound If any of the supplied reason ids are not found.
* @throws InvalidNodeRefException If the node could not be found.
* @throws InvalidNode If the supplied node is not a document node.
*/
void addClassificationToDocument(String classificationLevelId, String classificationAuthority,
Set<String> classificationReasonIds, NodeRef document) throws LevelIdNotFound, ReasonIdNotFound;
Set<String> classificationReasonIds, NodeRef document) throws LevelIdNotFound, ReasonIdNotFound,
InvalidNodeRefException, InvalidNode;
}

View File

@@ -19,6 +19,7 @@
package org.alfresco.module.org_alfresco_module_rm.classification;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* Generic class for any runtime exception thrown within the {@link ClassificationService}.
@@ -87,4 +88,15 @@ public class ClassificationServiceException extends AlfrescoRuntimeException
super("Could not find classification reason with id " + reasonId);
}
}
public static class InvalidNode extends ClassificationServiceException
{
/** serial version uid */
private static final long serialVersionUID = -4485335425932302477L;
public InvalidNode(NodeRef nodeRef, String message)
{
super("Operation not permitted on node " + nodeRef + ", error message: " + message);
}
}
}

View File

@@ -28,6 +28,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationServiceException.InvalidNode;
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationServiceException.LevelIdNotFound;
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationServiceException.MissingConfiguration;
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationServiceException.ReasonIdNotFound;
@@ -224,6 +226,11 @@ public class ClassificationServiceImpl extends ServiceBaseImpl
mandatory("classificationReasonIds", classificationReasonIds);
mandatory("document", document);
if (!nodeService.getType(document).equals(ContentModel.TYPE_CONTENT))
{
throw new InvalidNode(document, "The supplied node is not a content node.");
}
Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
checkClassificationLevelId(classificationLevelId);

View File

@@ -34,6 +34,9 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
import com.google.common.collect.Sets;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationServiceException.InvalidNode;
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationServiceException.MissingConfiguration;
import org.alfresco.module.org_alfresco_module_rm.test.util.ExceptionUtils;
import org.alfresco.module.org_alfresco_module_rm.test.util.MockAuthenticationUtilHelper;
@@ -253,20 +256,20 @@ public class ClassificationServiceImplUnitTest
}
/** Classify a document with a couple of reasons and check the NodeService is called correctly. */
@Test public void addClassificationToDocument()
@Test public void addClassificationToDocument_success()
{
// FIXME: Needs to be changed
/*
// Create a level and two reasons.
ClassificationLevel level = new ClassificationLevel("levelId1", "displayLabelKey");
ClassificationReason reason1 = new ClassificationReason("reasonId1", "displayLabelKey1");
ClassificationReason reason2 = new ClassificationReason("reasonId2", "displayLabelKey2");
Set<ClassificationReason> reasons = Sets.newHashSet(reason1, reason2);
NodeRef document = new NodeRef("fake://document/");
// Set up the managers to return these objects when the ids are provided.
doReturn(level).when(mockLevelManager).findLevelById("levelId1");
doReturn(reason1).when(mockReasonManager).findReasonById("reasonId1");
doReturn(reason2).when(mockReasonManager).findReasonById("reasonId2");
// Create a document node.
NodeRef document = new NodeRef("fake://document/");
doReturn(ContentModel.TYPE_CONTENT).when(mockNodeService).getType(document);
// Call the method under test.
classificationServiceImpl.addClassificationToDocument("levelId1", "classificationAuthority",
@@ -285,6 +288,21 @@ public class ClassificationServiceImplUnitTest
assertEquals("Unexpected current classification.", level, properties.get(ClassifiedContentModel.PROP_CURRENT_CLASSIFICATION));
assertEquals("Unexpected authority.", "classificationAuthority", properties.get(ClassifiedContentModel.PROP_CLASSIFICATION_AUTHORITY));
assertEquals("Unexpected set of reasons.", reasons, properties.get(ClassifiedContentModel.PROP_CLASSIFICATION_REASONS));
*/
}
/**
* Classify a folder using the <code>addClassificationToDocument</code> method and check that an exception is
* raised.
*/
@Test(expected = InvalidNode.class)
public void addClassificationToDocument_notDocument()
{
// Create a folder node.
NodeRef notADocument = new NodeRef("not://a/document/");
doReturn(ContentModel.TYPE_FOLDER).when(mockNodeService).getType(notADocument);
// Call the method under test.
classificationServiceImpl.addClassificationToDocument("levelId1", "classificationAuthority",
Sets.newHashSet("reasonId1", "reasonId2"), notADocument);
}
}