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:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright 2009 University of California at Berkeley
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
16 * https://source.collectionspace.org/collection-space/LICENSE.txt
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.
24 package org.collectionspace.services.index.nuxeo;
26 import java.util.List;
28 import org.collectionspace.services.client.index.IndexClient;
29 import org.collectionspace.services.common.ServiceMain;
30 import org.collectionspace.services.common.api.Tools;
31 import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl;
32 import org.collectionspace.services.common.context.ServiceBindingUtils;
33 import org.collectionspace.services.common.context.ServiceContext;
34 import org.collectionspace.services.common.document.DocumentException;
35 import org.collectionspace.services.config.service.ServiceBindingType;
36 import org.collectionspace.services.config.types.PropertyItemType;
37 import org.collectionspace.services.index.IndexCommon;
38 import org.collectionspace.services.nuxeo.client.java.NuxeoDocumentModelHandler;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
44 * IntakeDocumentModelHandler
46 * $LastChangedRevision: $
49 public class IndexDocumentModelHandler
50 extends NuxeoDocumentModelHandler<IndexCommon> {
51 private final Logger logger = LoggerFactory.getLogger(IndexDocumentModelHandler.class);
55 public String getDocumentsToIndexQuery(String indexId, String csid) throws DocumentException, Exception {
59 case IndexClient.FULLTEXT_ID:
60 result = getReindexQuery(indexId, csid);
62 case IndexClient.ELASTICSEARCH_ID:
63 result = getReindexQuery(indexId, csid);
68 if (Tools.isEmpty(result) == true) {
69 String msg = String.format("There is no reindex query in the Index service bindings for index '%s', so we'll use this default query: '%s'",
70 indexId, IndexClient.DEFAULT_REINDEX_QUERY);
72 result = IndexClient.DEFAULT_REINDEX_QUERY;
79 * Reads the Index service bindings to get the query that will be used to find all documents needing
85 * @throws DocumentException
88 * TODO: Use the incoming CSID param to qualify the returned query.
90 private String getReindexQuery(String indexId, String csid) throws DocumentException, Exception {
94 // Read in the NXQL query to use when performing a full
96 TenantBindingConfigReaderImpl tReader =
97 ServiceMain.getInstance().getTenantBindingConfigReader();
98 ServiceContext ctx = this.getServiceContext();
100 ServiceBindingType reportServiceBinding = tReader.getServiceBinding(ctx.getTenantId(), ctx.getServiceName());
101 List<PropertyItemType> queryTypeList = ServiceBindingUtils.getPropertyValueList(reportServiceBinding, indexId);
103 if (queryTypeList != null && queryTypeList.isEmpty() == false) {
104 PropertyItemType propertyItemType = queryTypeList.get(0);
105 if (propertyItemType != null) {
106 result = propertyItemType.getValue();