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