1 package org.collectionspace.services.relation.nuxeo;
\r
3 //import junit.framework.Assert;
\r
5 import org.collectionspace.services.common.context.MultipartServiceContext;
\r
6 import org.collectionspace.services.common.context.ServiceContext;
\r
8 import org.collectionspace.services.common.document.InvalidDocumentException;
\r
9 import org.collectionspace.services.common.document.ValidatorHandler;
\r
10 import org.collectionspace.services.common.document.ValidatorHandlerImpl;
\r
11 import org.collectionspace.services.common.document.DocumentHandler.Action;
\r
13 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
\r
14 import org.collectionspace.services.relation.RelationsCommon;
\r
16 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
\r
17 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
\r
19 import org.slf4j.Logger;
\r
20 import org.slf4j.LoggerFactory;
\r
21 //import org.testng.Assert;
\r
23 public class RelationValidatorHandler extends ValidatorHandlerImpl<MultipartInput, MultipartOutput> {
\r
26 private final Logger logger = LoggerFactory.getLogger(RelationValidatorHandler.class);
\r
30 private static final String VALIDATION_ERROR = "The relation record is invalid. See log file for more details.";
\r
31 private static final String SUBJECT_EQUALS_PREDICATE_ERROR = "The subject ID and object ID cannot be the same.";
\r
34 protected Class<?> getCommonPartClass() {
\r
35 return RelationsCommon.class;
\r
39 protected void handleCreate()
\r
40 throws InvalidDocumentException{
\r
41 ServiceContext<MultipartInput, MultipartOutput> ctx = getServiceContext();
\r
43 RelationsCommon relationsCommon = (RelationsCommon)getCommonPart();
\r
44 assert(relationsCommon != null);
\r
46 assert(relationsCommon.getDocumentId1() != null);
\r
47 assert(relationsCommon.getDocumentId1().length() != 0);
\r
49 assert(relationsCommon.getDocumentId2() != null);
\r
50 assert(relationsCommon.getDocumentId2().length() != 0);
\r
52 assert(relationsCommon.getRelationshipType() != null);
\r
54 // Assert that the Subject ID and Predicate ID are not the same
\r
56 assert(relationsCommon.getDocumentId1().equalsIgnoreCase(relationsCommon.getDocumentId2()) == false) :
\r
57 SUBJECT_EQUALS_PREDICATE_ERROR;
\r
58 } catch (AssertionError e) {
\r
59 if (logger.isErrorEnabled() == true) {
\r
60 logger.error(e.getMessage(), e);
\r
62 throw new InvalidDocumentException(VALIDATION_ERROR, e);
\r
67 protected void handleGet() {
\r
68 // TODO Auto-generated method stub
\r
73 protected void handleGetAll() {
\r
74 // TODO Auto-generated method stub
\r
79 protected void handleUpdate() {
\r
80 // TODO Auto-generated method stub
\r
85 protected void handleDelete() {
\r
86 // TODO Auto-generated method stub
\r