]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
f4b609d8c12f09dc2bb50d269eda4d50c9f62123
[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.api.RefName;
29 import org.collectionspace.services.common.context.MultipartServiceContext;
30 import org.collectionspace.services.common.document.DocumentWrapper;
31 import org.collectionspace.services.common.service.ObjectPartType;
32 import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema;
33
34 import org.collectionspace.services.nuxeo.client.java.DocHandlerBase;
35 import org.nuxeo.ecm.core.api.ClientException;
36 import org.nuxeo.ecm.core.api.DocumentModel;
37
38 /**
39  * AuthorityDocumentModelHandler
40  *
41  * $LastChangedRevision: $
42  * $LastChangedDate: $
43  */
44 public abstract class AuthorityDocumentModelHandler<AuthCommon>
45         extends DocHandlerBase<AuthCommon> {
46
47         private String authorityCommonSchemaName;
48         
49     public AuthorityDocumentModelHandler(String authorityCommonSchemaName) {
50         this.authorityCommonSchemaName = authorityCommonSchemaName;
51     }
52
53     /*
54      * Non standard injection of CSID into common part, since caller may access through
55      * shortId, and not know the CSID.
56      * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#extractPart(org.nuxeo.ecm.core.api.DocumentModel, java.lang.String, org.collectionspace.services.common.service.ObjectPartType)
57      */
58     @Override
59     protected Map<String, Object> extractPart(DocumentModel docModel, String schema, ObjectPartType partMeta)
60             throws Exception {
61         Map<String, Object> unQObjectProperties = super.extractPart(docModel, schema, partMeta);
62         
63         // Add the CSID to the common part
64         if (partMeta.getLabel().equalsIgnoreCase(authorityCommonSchemaName)) {
65                 String csid = getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString());
66                 unQObjectProperties.put("csid", csid);
67         }
68         
69         return unQObjectProperties;
70     }
71     
72     @Override
73     public void handleCreate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
74         super.handleCreate(wrapDoc);
75         // Uncomment once debugged and App layer is read to integrate
76         //updateRefnameForAuthority(wrapDoc, authorityCommonSchemaName);//CSPACE-3178
77     }
78
79     protected void updateRefnameForAuthority(DocumentWrapper<DocumentModel> wrapDoc, String schemaName) throws Exception {
80         DocumentModel docModel = wrapDoc.getWrappedObject();
81         String shortIdentifier = (String)docModel.getProperty(schemaName, AuthorityJAXBSchema.SHORT_IDENTIFIER);
82         String displayName =     (String)docModel.getProperty(schemaName, AuthorityJAXBSchema.DISPLAY_NAME);
83         MultipartServiceContext ctx = (MultipartServiceContext)getServiceContext();
84         RefName.Authority authority = RefName.buildAuthority(ctx.getTenantName(),
85                                                              ctx.getServiceName(),
86                                                              shortIdentifier,
87                                                              displayName);
88         String refName = authority.toString();
89         docModel.setProperty(schemaName , AuthorityJAXBSchema.REF_NAME, refName);
90     }
91     
92
93     public String getShortIdentifier(DocumentWrapper<DocumentModel> wrapDoc, String schemaName) {
94         DocumentModel docModel = wrapDoc.getWrappedObject();
95         String shortIdentifier = null;
96         try {
97                 shortIdentifier = (String)docModel.getProperty(schemaName, AuthorityJAXBSchema.SHORT_IDENTIFIER);
98         } catch (ClientException ce) {
99                 throw new RuntimeException("AuthorityDocHandler Internal Error: cannot get shortId!", ce);
100         }
101         return shortIdentifier;
102     }
103
104 }
105