]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
eb2ee39bc482e41ed23a5f7c995b41261936421d
[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         // CSPACE-3178:
76         // Uncomment once debugged and App layer is read to integrate
77         // Experimenting with this uncommented now ...
78         updateRefnameForAuthority(wrapDoc, authorityCommonSchemaName);//CSPACE-3178
79     }
80
81     protected void updateRefnameForAuthority(DocumentWrapper<DocumentModel> wrapDoc, String schemaName) throws Exception {
82         DocumentModel docModel = wrapDoc.getWrappedObject();
83         String suppliedRefName = (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.REF_NAME);
84         // CSPACE-3178:
85         // Temporarily accept client-supplied refName values, rather than always generating such values,
86         // Remove the surrounding 'if' statement when clients should no longer supply refName values.
87         if (suppliedRefName == null || suppliedRefName.isEmpty()) {
88             String shortIdentifier = (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.SHORT_IDENTIFIER);
89             String displayName = (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.DISPLAY_NAME);
90             MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext();
91             RefName.Authority authority = RefName.buildAuthority(ctx.getTenantName(),
92                     ctx.getServiceName(),
93                     shortIdentifier,
94                     displayName);
95             String refName = authority.toString();
96             docModel.setProperty(schemaName, AuthorityJAXBSchema.REF_NAME, refName);
97         }
98     }
99
100     public String getShortIdentifier(DocumentWrapper<DocumentModel> wrapDoc, String schemaName) {
101         DocumentModel docModel = wrapDoc.getWrappedObject();
102         String shortIdentifier = null;
103         try {
104             shortIdentifier = (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.SHORT_IDENTIFIER);
105         } catch (ClientException ce) {
106             throw new RuntimeException("AuthorityDocHandler Internal Error: cannot get shortId!", ce);
107         }
108         return shortIdentifier;
109     }
110
111     /**
112      * Filters out values supplied in the request
113      * @param objectProps the properties parsed from the update payload
114      * @param partMeta metadata for the object to fill
115      */
116     @Override
117     public void filterReadOnlyPropertiesForPart(
118             Map<String, Object> objectProps, ObjectPartType partMeta) {
119         super.filterReadOnlyPropertiesForPart(objectProps, partMeta);
120         String commonPartLabel = getServiceContext().getCommonPartLabel();
121         if (partMeta.getLabel().equalsIgnoreCase(commonPartLabel)) {
122             objectProps.remove(AuthorityJAXBSchema.CSID);
123             // Enable when clients should no longer supply refName values
124             // objectProps.remove(AuthorityItemJAXBSchema.REF_NAME); // CSPACE-3178
125
126         }
127     }
128 }