1 package org.collectionspace.services.relation.nuxeo;
\r
3 //import junit.framework.Assert;
\r
5 import org.collectionspace.services.common.document.InvalidDocumentException;
\r
6 import org.collectionspace.services.common.document.ValidatorHandlerImpl;
\r
7 import org.collectionspace.services.relation.RelationsCommon;
\r
9 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
\r
10 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
\r
12 import org.slf4j.Logger;
\r
13 import org.slf4j.LoggerFactory;
\r
14 //import org.testng.Assert;
\r
16 public class RelationValidatorHandler extends ValidatorHandlerImpl<MultipartInput, MultipartOutput> {
\r
19 private final Logger logger = LoggerFactory.getLogger(RelationValidatorHandler.class);
\r
23 private static final String VALIDATION_ERROR = "The relation record payload was invalid. See log file for more details.";
\r
24 private static final String SUBJECT_EQUALS_PREDICATE_ERROR = "The subject ID and object ID cannot be the same.";
\r
27 protected Class<?> getCommonPartClass() {
\r
28 return RelationsCommon.class;
\r
32 protected void handleCreate()
\r
33 throws InvalidDocumentException{
\r
35 RelationsCommon relationsCommon = (RelationsCommon)getCommonPart();
\r
36 assert(relationsCommon != null);
\r
37 if (logger.isTraceEnabled() == true) {
\r
38 logger.trace(relationsCommon.toString());
\r
41 assert(relationsCommon.getDocumentId1() != null);
\r
42 assert(relationsCommon.getDocumentId1().length() != 0);
\r
44 assert(relationsCommon.getDocumentId2() != null);
\r
45 assert(relationsCommon.getDocumentId2().length() != 0);
\r
47 assert(relationsCommon.getRelationshipType() != null);
\r
49 // Assert that the Subject ID and Predicate ID are not the same
\r
51 assert(relationsCommon.getDocumentId1().equalsIgnoreCase(relationsCommon.getDocumentId2()) == false) :
\r
52 SUBJECT_EQUALS_PREDICATE_ERROR;
\r
53 } catch (AssertionError e) {
\r
54 if (logger.isErrorEnabled() == true) {
\r
55 logger.error(e.getMessage(), e);
\r
57 throw new InvalidDocumentException(VALIDATION_ERROR, e);
\r
62 protected void handleGet() {
\r
63 // TODO Auto-generated method stub
\r
68 protected void handleGetAll() {
\r
69 // TODO Auto-generated method stub
\r
74 protected void handleUpdate() {
\r
75 // TODO Auto-generated method stub
\r
80 protected void handleDelete() {
\r
81 // TODO Auto-generated method stub
\r