]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
5f2466d6a232b0a16f3785cff7a46a77a9f7fdc7
[tmp/jakarta-migration.git] /
1 package org.collectionspace.services.relation.nuxeo;\r
2 \r
3 //import junit.framework.Assert;\r
4 \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
8 \r
9 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;\r
10 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;\r
11 \r
12 import org.slf4j.Logger;\r
13 import org.slf4j.LoggerFactory;\r
14 //import org.testng.Assert;\r
15 \r
16 public class RelationValidatorHandler extends ValidatorHandlerImpl<MultipartInput, MultipartOutput>      {\r
17 \r
18     /** The logger. */\r
19     private final Logger logger = LoggerFactory.getLogger(RelationValidatorHandler.class);\r
20     \r
21     /* Error messages \r
22      */\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
25     \r
26     @Override\r
27     protected Class<?> getCommonPartClass() {\r
28         return RelationsCommon.class;\r
29     }\r
30     \r
31     @Override\r
32     protected void handleCreate()\r
33                 throws InvalidDocumentException{\r
34         try {\r
35                 RelationsCommon relationsCommon = (RelationsCommon)getCommonPart();\r
36                 assert(relationsCommon != null);\r
37                 if (logger.isTraceEnabled() == true) {\r
38                         logger.trace(relationsCommon.toString());\r
39                 }\r
40                 \r
41                 assert(relationsCommon.getDocumentId1() != null);\r
42                 assert(relationsCommon.getDocumentId1().length() != 0);\r
43                 \r
44                 assert(relationsCommon.getDocumentId2() != null);\r
45                 assert(relationsCommon.getDocumentId2().length() != 0);\r
46                 \r
47                 assert(relationsCommon.getRelationshipType() != null);\r
48                 //\r
49                 // Assert that the Subject ID and Predicate ID are not the same\r
50                 //\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
56                 }\r
57                 throw new InvalidDocumentException(VALIDATION_ERROR, e);\r
58         }\r
59     }\r
60 \r
61         @Override\r
62         protected void handleGet() {\r
63                 // TODO Auto-generated method stub\r
64                 \r
65         }\r
66 \r
67         @Override\r
68         protected void handleGetAll() {\r
69                 // TODO Auto-generated method stub\r
70                 \r
71         }\r
72 \r
73         @Override\r
74         protected void handleUpdate() {\r
75                 // TODO Auto-generated method stub\r
76                 \r
77         }\r
78 \r
79         @Override\r
80         protected void handleDelete() {\r
81                 // TODO Auto-generated method stub\r
82                 \r
83         }\r
84 \r
85 }\r