]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
fe26bbf72b4880bb34477da7eb4651c5f31156f8
[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 javax.management.RuntimeErrorException;
29
30 import org.collectionspace.services.client.PoxPayloadIn;
31 import org.collectionspace.services.client.PoxPayloadOut;
32 import org.collectionspace.services.common.api.RefName;
33 import org.collectionspace.services.common.context.MultipartServiceContext;
34 import org.collectionspace.services.common.context.ServiceContext;
35 import org.collectionspace.services.common.document.DocumentException;
36 import org.collectionspace.services.common.document.DocumentNotFoundException;
37 import org.collectionspace.services.common.document.DocumentWrapper;
38 import org.collectionspace.services.common.service.ObjectPartType;
39 import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema;
40
41 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
42 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
43 import org.nuxeo.ecm.core.api.ClientException;
44 import org.nuxeo.ecm.core.api.DocumentModel;
45
46 /**
47  * AuthorityDocumentModelHandler
48  *
49  * $LastChangedRevision: $
50  * $LastChangedDate: $
51  */
52 public abstract class AuthorityDocumentModelHandler<AuthCommon, AuthCommonList>
53         extends RemoteDocumentModelHandlerImpl<AuthCommon, AuthCommonList> {
54
55         private String authorityCommonSchemaName;
56         
57     /**
58      * authority is used to stash JAXB object to use when handle is called
59      * for Action.CREATE, Action.UPDATE or Action.GET
60      */
61     private AuthCommon authority;
62     /**
63      * authorityList is stashed when handle is called
64      * for ACTION.GET_ALL
65      */
66     private AuthCommonList authorityList;
67
68
69     public AuthorityDocumentModelHandler(String authorityCommonSchemaName) {
70         this.authorityCommonSchemaName = authorityCommonSchemaName;
71     }
72
73     /**
74      * getCommonPart get associated authority
75      * @return
76      */
77     @Override
78     public AuthCommon getCommonPart() {
79         return authority;
80     }
81
82     /**
83      * setCommonPart set associated authority
84      * @param authority
85      */
86     @Override
87     public void setCommonPart(AuthCommon authority) {
88         this.authority = authority;
89     }
90
91     /**
92      * getCommonPartList get associated authority (for index/GET_ALL)
93      * @return
94      */
95     @Override
96     public AuthCommonList getCommonPartList() {
97         return authorityList;
98     }
99
100     /* (non-Javadoc)
101      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPartList(java.lang.Object)
102      */
103     @Override
104     public void setCommonPartList(AuthCommonList authorityList) {
105         this.authorityList = authorityList;
106     }
107
108     /* (non-Javadoc)
109      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPart(org.collectionspace.services.common.document.DocumentWrapper)
110      */
111     @Override
112     public AuthCommon extractCommonPart(DocumentWrapper<DocumentModel> wrapDoc)
113             throws Exception {
114         throw new UnsupportedOperationException();
115     }
116
117     /* (non-Javadoc)
118      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#fillCommonPart(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper)
119      */
120     @Override
121     public void fillCommonPart(AuthCommon vocabularyObject, DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
122         throw new UnsupportedOperationException();
123     }
124
125     /* (non-Javadoc)
126      * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#extractPart(org.nuxeo.ecm.core.api.DocumentModel, java.lang.String, org.collectionspace.services.common.service.ObjectPartType)
127      */
128     @Override
129     protected Map<String, Object> extractPart(DocumentModel docModel, String schema, ObjectPartType partMeta)
130             throws Exception {
131         Map<String, Object> unQObjectProperties = super.extractPart(docModel, schema, partMeta);
132         
133         // Add the CSID to the common part
134         if (partMeta.getLabel().equalsIgnoreCase(authorityCommonSchemaName)) {
135                 String csid = getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString());
136                 unQObjectProperties.put("csid", csid);
137         }
138         
139         return unQObjectProperties;
140     }
141     
142     @Override
143     public void handleCreate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
144         super.handleCreate(wrapDoc);
145         // Uncomment once debugged and App layer is read to integrate
146         //updateRefnameForAuthority(wrapDoc, authorityCommonSchemaName);//CSPACE-3178
147     }
148
149     protected void updateRefnameForAuthority(DocumentWrapper<DocumentModel> wrapDoc, String schemaName) throws Exception {
150         DocumentModel docModel = wrapDoc.getWrappedObject();
151         String shortIdentifier = (String)docModel.getProperty(schemaName, AuthorityJAXBSchema.SHORT_IDENTIFIER);
152         String displayName =     (String)docModel.getProperty(schemaName, AuthorityJAXBSchema.DISPLAY_NAME);
153         MultipartServiceContext ctx = (MultipartServiceContext)getServiceContext();
154         RefName.Authority authority = RefName.buildAuthority(ctx.getTenantName(),
155                                                              ctx.getServiceName(),
156                                                              shortIdentifier,
157                                                              displayName);
158         String refName = authority.toString();
159         docModel.setProperty(schemaName , AuthorityJAXBSchema.REF_NAME, refName);
160     }
161     
162
163     public String getShortIdentifier(DocumentWrapper<DocumentModel> wrapDoc, String schemaName) {
164         DocumentModel docModel = wrapDoc.getWrappedObject();
165         String shortIdentifier = null;
166         try {
167                 shortIdentifier = (String)docModel.getProperty(schemaName, AuthorityJAXBSchema.SHORT_IDENTIFIER);
168         } catch (ClientException ce) {
169                 throw new RuntimeException("AuthorityDocHandler Internal Error: cannot get shortId!", ce);
170         }
171         return shortIdentifier;
172     }
173
174 }
175