]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
1299076a2d92e7ef59b013de6d3b884b81b7fb0a
[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.context.MultipartServiceContext;\r
6 import org.collectionspace.services.common.context.ServiceContext;\r
7 \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
12 \r
13 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;\r
14 import org.collectionspace.services.relation.RelationsCommon;\r
15 \r
16 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;\r
17 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;\r
18 \r
19 import org.slf4j.Logger;\r
20 import org.slf4j.LoggerFactory;\r
21 //import org.testng.Assert;\r
22 \r
23 public class RelationValidatorHandler extends ValidatorHandlerImpl<MultipartInput, MultipartOutput>      {\r
24 \r
25     /** The logger. */\r
26     private final Logger logger = LoggerFactory.getLogger(RelationValidatorHandler.class);\r
27     \r
28     /* Error messages \r
29      */\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
32     \r
33     @Override\r
34     protected Class<?> getCommonPartClass() {\r
35         return RelationsCommon.class;\r
36     }\r
37     \r
38     @Override\r
39     protected void handleCreate()\r
40                 throws InvalidDocumentException{\r
41         ServiceContext<MultipartInput, MultipartOutput> ctx = getServiceContext();\r
42         try {\r
43                 RelationsCommon relationsCommon = (RelationsCommon)getCommonPart();\r
44                 assert(relationsCommon != null);\r
45                 \r
46                 assert(relationsCommon.getDocumentId1() != null);\r
47                 assert(relationsCommon.getDocumentId1().length() != 0);\r
48                 \r
49                 assert(relationsCommon.getDocumentId2() != null);\r
50                 assert(relationsCommon.getDocumentId2().length() != 0);\r
51                 \r
52                 assert(relationsCommon.getRelationshipType() != null);\r
53                 //\r
54                 // Assert that the Subject ID and Predicate ID are not the same\r
55                 //\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
61                 }\r
62                 throw new InvalidDocumentException(VALIDATION_ERROR, e);\r
63         }\r
64     }\r
65 \r
66         @Override\r
67         protected void handleGet() {\r
68                 // TODO Auto-generated method stub\r
69                 \r
70         }\r
71 \r
72         @Override\r
73         protected void handleGetAll() {\r
74                 // TODO Auto-generated method stub\r
75                 \r
76         }\r
77 \r
78         @Override\r
79         protected void handleUpdate() {\r
80                 // TODO Auto-generated method stub\r
81                 \r
82         }\r
83 \r
84         @Override\r
85         protected void handleDelete() {\r
86                 // TODO Auto-generated method stub\r
87                 \r
88         }\r
89 \r
90 }\r