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
38 assert(relationsCommon.getDocumentId1() != null);
\r
39 assert(relationsCommon.getDocumentId1().length() != 0);
\r
41 assert(relationsCommon.getDocumentId2() != null);
\r
42 assert(relationsCommon.getDocumentId2().length() != 0);
\r
44 assert(relationsCommon.getRelationshipType() != null);
\r
46 // Assert that the Subject ID and Predicate ID are not the same
\r
48 assert(relationsCommon.getDocumentId1().equalsIgnoreCase(relationsCommon.getDocumentId2()) == false) :
\r
49 SUBJECT_EQUALS_PREDICATE_ERROR;
\r
50 } catch (AssertionError e) {
\r
51 if (logger.isErrorEnabled() == true) {
\r
52 logger.error(e.getMessage(), e);
\r
54 throw new InvalidDocumentException(VALIDATION_ERROR, e);
\r
59 protected void handleGet() {
\r
60 // TODO Auto-generated method stub
\r
65 protected void handleGetAll() {
\r
66 // TODO Auto-generated method stub
\r
71 protected void handleUpdate() {
\r
72 // TODO Auto-generated method stub
\r
77 protected void handleDelete() {
\r
78 // TODO Auto-generated method stub
\r