2 * This document is a part of the source code and related artifacts
\r
3 * for CollectionSpace, an open source collections management system
\r
4 * for museums and related institutions:
\r
6 * http://www.collectionspace.org
\r
7 * http://wiki.collectionspace.org
\r
9 * Copyright 2009 University of California at Berkeley
\r
11 * Licensed under the Educational Community License (ECL), Version 2.0.
\r
12 * You may not use this file except in compliance with this License.
\r
14 * You may obtain a copy of the ECL 2.0 License at
\r
16 * https://source.collectionspace.org/collection-space/LICENSE.txt
\r
18 * Unless required by applicable law or agreed to in writing, software
\r
19 * distributed under the License is distributed on an "AS IS" BASIS,
\r
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
21 * See the License for the specific language governing permissions and
\r
22 * limitations under the License.
\r
24 package org.collectionspace.services.common.vocabulary;
\r
26 import java.util.ArrayList;
\r
27 import java.util.List;
\r
29 import org.nuxeo.ecm.core.api.DocumentModelList;
\r
30 import org.slf4j.Logger;
\r
31 import org.slf4j.LoggerFactory;
\r
32 import org.collectionspace.services.common.ServiceMain;
\r
33 import org.collectionspace.services.common.authorityref.AuthorityRefDocList;
\r
34 import org.collectionspace.services.common.authorityref.AuthorityRefList;
\r
35 import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl;
\r
36 import org.collectionspace.services.common.context.ServiceBindingUtils;
\r
37 import org.collectionspace.services.common.document.DocumentException;
\r
38 import org.collectionspace.services.common.document.DocumentNotFoundException;
\r
39 import org.collectionspace.services.common.document.DocumentWrapper;
\r
40 import org.collectionspace.services.common.repository.RepositoryClient;
\r
41 import org.collectionspace.services.common.service.ServiceBindingType;
\r
44 * RefNameServiceUtils is a collection of services utilities related to refName usage.
\r
46 * $LastChangedRevision: $
\r
47 * $LastChangedDate: $
\r
49 public class RefNameServiceUtils {
\r
51 public static final String AUTH_REF_PROP = "authRef";
\r
53 private final Logger logger = LoggerFactory.getLogger(RefNameServiceUtils.class);
\r
55 public AuthorityRefDocList getAuthorityRefDocs(RepositoryClient repoClient,
\r
56 String tenantId, String serviceType, String refName,
\r
57 int pageSize, int pageNum, boolean computeTotal )
\r
58 throws DocumentException, DocumentNotFoundException {
\r
59 AuthorityRefDocList wrapperList = new AuthorityRefDocList();
\r
60 List<AuthorityRefDocList.AuthorityRefDocItem> list =
\r
61 wrapperList.getAuthorityRefDocItem();
\r
62 TenantBindingConfigReaderImpl tReader =
\r
63 ServiceMain.getInstance().getTenantBindingConfigReader();
\r
64 List<ServiceBindingType> servicebindings = tReader.getServiceBindingsByType(tenantId, serviceType);
\r
65 if(servicebindings==null || servicebindings.size()>0)
\r
67 String domain = tReader.getTenantBinding(tenantId).getRepositoryDomain();
\r
68 ArrayList<String> docTypes = new ArrayList<String>();
\r
69 StringBuilder whereClause = new StringBuilder();
\r
70 for(ServiceBindingType sb:servicebindings) {
\r
71 List<String> authRefFields = ServiceBindingUtils.getAllPartsPropertyValues(sb, AUTH_REF_PROP);
\r
72 String docType = sb.getObject().getName();
\r
73 docTypes.add(docType);
\r
74 for(String field:authRefFields) {
\r
75 // Build up the where clause for each authRef field
\r
76 throw new UnsupportedOperationException();
\r
79 // Now we have to issue the search
\r
80 DocumentWrapper<DocumentModelList> docListWrapper = repoClient.findDocs(
\r
81 docTypes, whereClause.toString(), domain, pageSize, pageNum, computeTotal );
\r