]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
289fcd5485bc60528585ba466b3df9da6e003b4d
[tmp/jakarta-migration.git] /
1 /**\r
2  *  This document is a part of the source code and related artifacts\r
3  *  for CollectionSpace, an open source collections management system\r
4  *  for museums and related institutions:\r
5 \r
6  *  http://www.collectionspace.org\r
7  *  http://wiki.collectionspace.org\r
8 \r
9  *  Copyright 2009 University of California at Berkeley\r
10 \r
11  *  Licensed under the Educational Community License (ECL), Version 2.0.\r
12  *  You may not use this file except in compliance with this License.\r
13 \r
14  *  You may obtain a copy of the ECL 2.0 License at\r
15 \r
16  *  https://source.collectionspace.org/collection-space/LICENSE.txt\r
17 \r
18  *  Unless required by applicable law or agreed to in writing, software\r
19  *  distributed under the License is distributed on an "AS IS" BASIS,\r
20  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
21  *  See the License for the specific language governing permissions and\r
22  *  limitations under the License.\r
23  *//**\r
24  *  This document is a part of the source code and related artifacts\r
25  *  for CollectionSpace, an open source collections management system\r
26  *  for museums and related institutions:\r
27 \r
28  *  http://www.collectionspace.org\r
29  *  http://wiki.collectionspace.org\r
30 \r
31  *  Copyright 2009 University of California at Berkeley\r
32 \r
33  *  Licensed under the Educational Community License (ECL), Version 2.0.\r
34  *  You may not use this file except in compliance with this License.\r
35 \r
36  *  You may obtain a copy of the ECL 2.0 License at\r
37 \r
38  *  https://source.collectionspace.org/collection-space/LICENSE.txt\r
39 \r
40  *  Unless required by applicable law or agreed to in writing, software\r
41  *  distributed under the License is distributed on an "AS IS" BASIS,\r
42  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
43  *  See the License for the specific language governing permissions and\r
44  *  limitations under the License.\r
45  */\r
46 /*\r
47  * To change this template, choose Tools | Templates\r
48  * and open the template in the editor.\r
49  */\r
50 package org.collectionspace.services.collectionobject.nuxeo;\r
51 \r
52 import org.collectionspace.services.client.PoxPayloadIn;\r
53 import org.collectionspace.services.client.PoxPayloadOut;\r
54 import org.collectionspace.services.collectionobject.CollectionobjectsCommon;\r
55 //import org.collectionspace.services.common.context.MultipartServiceContext;\r
56 //import org.collectionspace.services.common.context.ServiceContext;\r
57 import org.collectionspace.services.common.document.InvalidDocumentException;\r
58 import org.collectionspace.services.common.document.ValidatorHandlerImpl;\r
59 \r
60 import org.slf4j.Logger;\r
61 import org.slf4j.LoggerFactory;\r
62 \r
63 /**\r
64  *\r
65  * @author \r
66  */\r
67 public class CollectionObjectValidatorHandler extends ValidatorHandlerImpl<PoxPayloadIn, PoxPayloadOut> {\r
68 \r
69     final Logger logger = LoggerFactory.getLogger(CollectionObjectValidatorHandler.class);\r
70 \r
71     //\r
72     // Error Strings\r
73     //\r
74     private static final String VALIDATION_ERROR = "The collection object record payload was invalid. See log file for more details.";\r
75     private static final String OBJECTNUMBER_NULL_ERROR = "The collection object field \"objectNumber\" cannot be empty or missing.";\r
76 \r
77     @Override\r
78     protected Class<?> getCommonPartClass() {\r
79         return CollectionobjectsCommon.class;\r
80     }\r
81     \r
82         @Override\r
83         protected void handleGet(){\r
84                 // TODO Auto-generated method stub\r
85                 \r
86         }\r
87 \r
88         @Override\r
89         protected void handleGetAll() {\r
90                 // TODO Auto-generated method stub\r
91                 \r
92         }\r
93 \r
94         @Override\r
95         protected void handleUpdate()\r
96                         throws InvalidDocumentException {\r
97         try {\r
98             CollectionobjectsCommon co = (CollectionobjectsCommon) getCommonPart();\r
99             validateCollectionobjectsCommon(co);                        \r
100         } catch (AssertionError e) {\r
101                 if (logger.isErrorEnabled() == true) {\r
102                         logger.error(e.getMessage(), e);\r
103                 }\r
104                 throw new InvalidDocumentException(VALIDATION_ERROR, e);\r
105         }\r
106         }\r
107 \r
108         @Override\r
109         protected void handleDelete() {\r
110                 // TODO Auto-generated method stub\r
111                 \r
112         }\r
113     \r
114     @Override\r
115     protected void handleCreate()\r
116                 throws InvalidDocumentException {\r
117         try {\r
118             CollectionobjectsCommon co = (CollectionobjectsCommon) getCommonPart();\r
119             validateCollectionobjectsCommon(co);                        \r
120         } catch (AssertionError e) {\r
121                 if (logger.isErrorEnabled() == true) {\r
122                         logger.error(e.getMessage(), e);\r
123                 }\r
124                 throw new InvalidDocumentException(VALIDATION_ERROR, e);\r
125         }\r
126     }\r
127     \r
128     //\r
129     // Private Methods\r
130     //    \r
131     private void validateCollectionobjectsCommon(CollectionobjectsCommon co) throws AssertionError {\r
132         CS_ASSERT(co != null);\r
133         String objectNumber = co.getObjectNumber();\r
134         CS_ASSERT(objectNumber != null);\r
135         CS_ASSERT(objectNumber.isEmpty() == false, OBJECTNUMBER_NULL_ERROR);\r
136 \r
137     }\r
138 }\r