]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
8a648a25fd47d693f5bca60bf841ffabc658025b
[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 package org.collectionspace.services.common.vocabulary.nuxeo;
25
26 import java.util.Map;
27
28 import org.collectionspace.services.common.document.DocumentWrapper;
29 import org.collectionspace.services.common.service.ObjectPartType;
30 import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema;
31 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
32 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
33 import org.nuxeo.ecm.core.api.DocumentModel;
34
35 /**
36  * AuthorityItemDocumentModelHandler
37  *
38  * $LastChangedRevision: $
39  * $LastChangedDate: $
40  */
41 public abstract class AuthorityItemDocumentModelHandler<AICommon, AICommonList>
42         extends RemoteDocumentModelHandlerImpl<AICommon, AICommonList> {
43
44         private String authorityItemCommonSchemaName;
45         
46     //private final Logger logger = LoggerFactory.getLogger(AuthorityItemDocumentModelHandler.class);
47     /**
48      * item is used to stash JAXB object to use when handle is called
49      * for Action.CREATE, Action.UPDATE or Action.GET
50      */
51     protected AICommon item;
52     /**
53      * itemList is stashed when handle is called
54      * for ACTION.GET_ALL
55      */
56     protected AICommonList itemList;
57     
58     /**
59      * inVocabulary is the parent Authority for this context
60      */
61     protected String inAuthority;
62     
63     public AuthorityItemDocumentModelHandler(String authorityItemCommonSchemaName) {
64         this.authorityItemCommonSchemaName = authorityItemCommonSchemaName;
65     }
66
67     public String getInAuthority() {
68                 return inAuthority;
69         }
70
71         public void setInAuthority(String inAuthority) {
72                 this.inAuthority = inAuthority;
73         }
74
75     /* (non-Javadoc)
76      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleCreate(org.collectionspace.services.common.document.DocumentWrapper)
77      */
78     @Override
79     public void handleCreate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
80         // first fill all the parts of the document
81         super.handleCreate(wrapDoc);            
82         handleInAuthority(wrapDoc.getWrappedObject());
83     }
84     
85     /**
86      * Check the logic around the parent pointer. Note that we only need do this on
87      * create, since we have logic to make this read-only on update. 
88      * 
89      * @param docModel
90      * 
91      * @throws Exception the exception
92      */
93     private void handleInAuthority(DocumentModel docModel) throws Exception {
94         docModel.setProperty(authorityItemCommonSchemaName, 
95                         AuthorityItemJAXBSchema.IN_AUTHORITY, inAuthority);
96     }
97
98
99     /**
100      * getCommonPart get associated item
101      * @return
102      */
103     @Override
104     public AICommon getCommonPart() {
105         return item;
106     }
107
108     /**
109      * setCommonPart set associated item
110      * @param vocabularyItem
111      */
112     @Override
113     public void setCommonPart(AICommon item) {
114         this.item = item;
115     }
116
117     /**
118      * getCommonPartList get associated item (for index/GET_ALL)
119      * @return
120      */
121     @Override
122     public AICommonList getCommonPartList() {
123         return itemList;
124     }
125
126     @Override
127     public void setCommonPartList(AICommonList itemList) {
128         this.itemList = itemList;
129     }
130
131     @Override
132     public AICommon extractCommonPart(DocumentWrapper<DocumentModel> wrapDoc)
133             throws Exception {
134         throw new UnsupportedOperationException();
135     }
136
137     @Override
138     public void fillCommonPart(AICommon itemObject, DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
139         throw new UnsupportedOperationException();
140     }
141     
142     /* (non-Javadoc)
143      * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#extractPart(org.nuxeo.ecm.core.api.DocumentModel, java.lang.String, org.collectionspace.services.common.service.ObjectPartType)
144      */
145     @Override
146     protected Map<String, Object> extractPart(DocumentModel docModel, String schema, ObjectPartType partMeta)
147             throws Exception {
148         Map<String, Object> unQObjectProperties = super.extractPart(docModel, schema, partMeta);
149         
150         // Add the CSID to the common part
151         if (partMeta.getLabel().equalsIgnoreCase(authorityItemCommonSchemaName)) {
152                 String csid = NuxeoUtils.extractId(docModel.getPathAsString());
153                 unQObjectProperties.put("csid", csid);
154         }
155         
156         return unQObjectProperties;
157     }
158     
159     /**
160      * Filters out AuthorityItemJAXBSchema.IN_AUTHORITY, to ensure that
161      * the parent link remains untouched.
162      * @param objectProps the properties parsed from the update payload
163      * @param partMeta metadata for the object to fill
164      */
165     @Override
166     public void filterReadOnlyPropertiesForPart(
167                 Map<String, Object> objectProps, ObjectPartType partMeta) {
168         super.filterReadOnlyPropertiesForPart(objectProps, partMeta);
169         objectProps.remove(AuthorityItemJAXBSchema.IN_AUTHORITY);
170         objectProps.remove(AuthorityItemJAXBSchema.CSID);
171     }
172
173 }
174