]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
dd06e39bb9a892ad293364f261c3f86e8a25ff5f
[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.index.nuxeo;
25
26 import java.util.List;
27
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;
39
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
42
43 /**
44  * IntakeDocumentModelHandler
45  *
46  * $LastChangedRevision: $
47  * $LastChangedDate: $
48  */
49 public class IndexDocumentModelHandler
50         extends NuxeoDocumentModelHandler<IndexCommon> {
51         private final Logger logger = LoggerFactory.getLogger(IndexDocumentModelHandler.class);
52
53         
54         @Override
55     public String getDocumentsToIndexQuery(String indexId, String csid) throws DocumentException, Exception {
56                 String result = null;
57                 
58         switch (indexId) {
59                 case IndexClient.FULLTEXT_ID:
60                         result = getReindexQuery(indexId, csid);
61                         break;
62                 case IndexClient.ELASTICSEARCH_ID:
63                         result = getReindexQuery(indexId, csid);
64                         
65                         break;
66         }
67         
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);
71                 logger.warn(msg);
72                 result = IndexClient.DEFAULT_REINDEX_QUERY;
73         }
74
75         return result;
76     }
77         
78         /**
79          * Reads the Index service bindings to get the query that will be used to find all documents needing
80          * reindexing.
81          * 
82          * @param indexId
83          * @param csid
84          * @return
85          * @throws DocumentException
86          * @throws Exception
87          * 
88          * TODO: Use the incoming CSID param to qualify the returned query.
89          */
90         private String getReindexQuery(String indexId, String csid) throws DocumentException, Exception {
91                 String result = null;
92                 
93         //
94         // Read in the NXQL query to use when performing a full 
95         //
96         TenantBindingConfigReaderImpl tReader =
97                 ServiceMain.getInstance().getTenantBindingConfigReader();
98         ServiceContext ctx = this.getServiceContext();
99         
100         ServiceBindingType reportServiceBinding = tReader.getServiceBinding(ctx.getTenantId(), ctx.getServiceName());
101         List<PropertyItemType> queryTypeList = ServiceBindingUtils.getPropertyValueList(reportServiceBinding, indexId);
102         
103         if (queryTypeList != null && queryTypeList.isEmpty() == false) {
104                 PropertyItemType propertyItemType = queryTypeList.get(0);
105                 if (propertyItemType != null) {
106                         result = propertyItemType.getValue();
107                 }
108         }
109         
110         return result;
111     }
112
113 }
114