]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
8d6db72cd8788ff80fa079742be9a879d87792fa
[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.collectionobject.CollectionobjectsCommon;\r
53 //import org.collectionspace.services.common.context.MultipartServiceContext;\r
54 //import org.collectionspace.services.common.context.ServiceContext;\r
55 import org.collectionspace.services.common.document.InvalidDocumentException;\r
56 import org.collectionspace.services.common.document.ValidatorHandlerImpl;\r
57 \r
58 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;\r
59 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;\r
60 \r
61 import org.slf4j.Logger;\r
62 import org.slf4j.LoggerFactory;\r
63 \r
64 /**\r
65  *\r
66  * @author \r
67  */\r
68 public class CollectionObjectValidatorHandler extends ValidatorHandlerImpl<MultipartInput, MultipartOutput> {\r
69 \r
70     final Logger logger = LoggerFactory.getLogger(CollectionObjectValidatorHandler.class);\r
71 \r
72     //\r
73     // Error Strings\r
74     //\r
75     private static final String VALIDATION_ERROR = "The collection object record payload was invalid. See log file for more details.";\r
76     private static final String OBJECTNUMBER_NULL_ERROR = "The collection object field \"objectNumber\" cannot be empty or missing.";\r
77 \r
78     @Override\r
79     protected Class<?> getCommonPartClass() {\r
80         return CollectionobjectsCommon.class;\r
81     }\r
82     \r
83         @Override\r
84         protected void handleGet(){\r
85                 // TODO Auto-generated method stub\r
86                 \r
87         }\r
88 \r
89         @Override\r
90         protected void handleGetAll() {\r
91                 // TODO Auto-generated method stub\r
92                 \r
93         }\r
94 \r
95         @Override\r
96         protected void handleUpdate()\r
97                         throws InvalidDocumentException {\r
98         try {\r
99             CollectionobjectsCommon co = (CollectionobjectsCommon) getCommonPart();\r
100             validateCollectionobjectsCommon(co);                        \r
101         } catch (AssertionError e) {\r
102                 if (logger.isErrorEnabled() == true) {\r
103                         logger.error(e.getMessage(), e);\r
104                 }\r
105                 throw new InvalidDocumentException(VALIDATION_ERROR, e);\r
106         }\r
107         }\r
108 \r
109         @Override\r
110         protected void handleDelete() {\r
111                 // TODO Auto-generated method stub\r
112                 \r
113         }\r
114     \r
115     @Override\r
116     protected void handleCreate()\r
117                 throws InvalidDocumentException {\r
118         try {\r
119             CollectionobjectsCommon co = (CollectionobjectsCommon) getCommonPart();\r
120             validateCollectionobjectsCommon(co);                        \r
121         } catch (AssertionError e) {\r
122                 if (logger.isErrorEnabled() == true) {\r
123                         logger.error(e.getMessage(), e);\r
124                 }\r
125                 throw new InvalidDocumentException(VALIDATION_ERROR, e);\r
126         }\r
127     }\r
128     \r
129     //\r
130     // Private Methods\r
131     //    \r
132     private void validateCollectionobjectsCommon(CollectionobjectsCommon co) throws AssertionError {\r
133         assert(co != null);\r
134         String objectNumber = co.getObjectNumber();\r
135         assert(objectNumber != null);\r
136         assert(objectNumber.isEmpty() == false) : OBJECTNUMBER_NULL_ERROR;\r
137 \r
138     }\r
139 }\r