From: Richard Millet Date: Mon, 1 Jul 2019 23:57:31 +0000 (-0700) Subject: CSPACE-6826: Enabling Index service to allow reindex requests for the fulltext and... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=3ea7bd7434a268749a74e1b0393267f598031343;p=tmp%2Fjakarta-migration.git CSPACE-6826: Enabling Index service to allow reindex requests for the fulltext and elasticsearch indexes. --- diff --git a/services/JaxRsServiceProvider/pom.xml b/services/JaxRsServiceProvider/pom.xml index 65c9b37e8..cc6274ad5 100644 --- a/services/JaxRsServiceProvider/pom.xml +++ b/services/JaxRsServiceProvider/pom.xml @@ -292,6 +292,11 @@ org.collectionspace.services.systeminfo.service ${project.version} + + org.collectionspace.services + org.collectionspace.services.index.service + ${project.version} + org.collectionspace.services org.collectionspace.services.media.service diff --git a/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java b/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java index 5d17455f2..2b9115943 100644 --- a/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java +++ b/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java @@ -30,6 +30,7 @@ import org.collectionspace.services.id.IDResource; import org.collectionspace.services.media.MediaResource; import org.collectionspace.services.group.GroupResource; import org.collectionspace.services.intake.IntakeResource; +import org.collectionspace.services.index.IndexResource; import org.collectionspace.services.loanin.LoaninResource; import org.collectionspace.services.loanout.LoanoutResource; import org.collectionspace.services.uoc.UocResource; @@ -111,6 +112,7 @@ public class CollectionSpaceJaxRsApplication extends Application singletons.add(new ImportsResource()); singletons.add(new StructuredDateResource()); singletons.add(new SystemInfoResource()); + singletons.add(new IndexResource()); addResourceToMapAndSingletons(new VocabularyResource()); addResourceToMapAndSingletons(new PersonAuthorityResource()); diff --git a/services/client/src/main/java/org/collectionspace/services/client/index/IndexClient.java b/services/client/src/main/java/org/collectionspace/services/client/index/IndexClient.java index 3faba944e..b886659d7 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/index/IndexClient.java +++ b/services/client/src/main/java/org/collectionspace/services/client/index/IndexClient.java @@ -37,7 +37,12 @@ public class IndexClient extends AbstractCommonListPoxServiceClientImpl default-domain - org.collectionspace.services.common.index.service.nuxeo.WorkflowDocumentModelHandler + org.collectionspace.services.index.nuxeo.IndexDocumentModelHandler - org.collectionspace.services.index.nuxeo.WorkflowValidatorHandler + org.collectionspace.services.index.nuxeo.IndexValidatorHandler + + + fulltextquery + SELECT ecm:uuid, ecm:primaryType FROM Document WHERE ecm:isProxy = 0 AND ecm:currentLifeCycleState <> 'deleted' ORDER BY ecm:uuid + + ctx = handler.getServiceContext(); @@ -242,9 +275,6 @@ public class NuxeoRepositoryClientImpl implements RepositoryClient ctx = handler.getServiceContext(); + + try { + ElasticSearchIndexing esi = Framework.getService(ElasticSearchIndexing.class); + ElasticSearchAdmin esa = Framework.getService(ElasticSearchAdmin.class); + + String queryString = handler.getDocumentsToIndexQuery(indexid, csid); + esa.initIndexes(true); + esa.refresh(); + repoSession = getRepositorySession(ctx); + esi.runReindexingWorker(repoSession.getRepositoryName(), queryString); + result = true; + } catch (Throwable e) { + rollbackTransaction(repoSession); + if (logger.isDebugEnabled()) { + logger.debug("Caught exception trying to reindex Nuxeo repository ", e); + } + throw new NuxeoDocumentException(e); + } finally { + if (repoSession != null) { + releaseRepositorySession(ctx, repoSession); + } + } + + return result; + } @Override public boolean synchronize(ServiceContext ctx, Object specifier, DocumentHandler handler) diff --git a/services/index/jaxb/src/main/java/org/collectionspace/services/IndexJAXBSchema.java b/services/index/jaxb/src/main/java/org/collectionspace/services/IndexJAXBSchema.java new file mode 100644 index 000000000..ca620f39a --- /dev/null +++ b/services/index/jaxb/src/main/java/org/collectionspace/services/IndexJAXBSchema.java @@ -0,0 +1,12 @@ +/** + * + */ +package org.collectionspace.services; + +/** + * @author remillet + * + */ +public interface IndexJAXBSchema { + final static String INDEX_NAME = "indexName"; +} diff --git a/services/index/jaxb/src/main/java/org/collectionspace/services/IndexListItemJAXBSchema.java b/services/index/jaxb/src/main/java/org/collectionspace/services/IndexListItemJAXBSchema.java new file mode 100644 index 000000000..3bdc58366 --- /dev/null +++ b/services/index/jaxb/src/main/java/org/collectionspace/services/IndexListItemJAXBSchema.java @@ -0,0 +1,6 @@ +package org.collectionspace.services; + +public interface IndexListItemJAXBSchema { + final static String INDEX_NAME = "indexName"; + +} diff --git a/services/index/jaxb/src/main/resources/index-common.xsd b/services/index/jaxb/src/main/resources/index-common.xsd new file mode 100644 index 000000000..ef50d16a9 --- /dev/null +++ b/services/index/jaxb/src/main/resources/index-common.xsd @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + diff --git a/services/index/pom.xml b/services/index/pom.xml index bd5b60d3c..87d110056 100644 --- a/services/index/pom.xml +++ b/services/index/pom.xml @@ -13,6 +13,7 @@ pom + jaxb 3rdparty client service diff --git a/services/index/service/src/main/java/org/collectionspace/services/index/IndexResource.java b/services/index/service/src/main/java/org/collectionspace/services/index/IndexResource.java index 8fad7f3ce..b6bad20b9 100644 --- a/services/index/service/src/main/java/org/collectionspace/services/index/IndexResource.java +++ b/services/index/service/src/main/java/org/collectionspace/services/index/IndexResource.java @@ -23,11 +23,16 @@ */ package org.collectionspace.services.index; +import org.collectionspace.services.client.PoxPayloadIn; +import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.client.index.IndexClient; import org.collectionspace.services.common.CSWebApplicationException; import org.collectionspace.services.common.NuxeoBasedResource; import org.collectionspace.services.common.ResourceMap; import org.collectionspace.services.common.ServiceMessages; +import org.collectionspace.services.common.UriInfoWrapper; +import org.collectionspace.services.common.context.RemoteServiceContext; +import org.collectionspace.services.common.document.DocumentHandler; import org.collectionspace.services.jaxb.AbstractCommonList; import javax.ws.rs.Consumes; @@ -37,8 +42,8 @@ import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; -import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Context; +import javax.ws.rs.core.Request; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; @@ -90,6 +95,34 @@ public class IndexResource extends NuxeoBasedResource { return response; } + @POST + @Path("{indexid}") + public Response reindex( + @Context Request request, + @Context UriInfo uriInfo, + @PathParam("indexid") String indexid) { + uriInfo = new UriInfoWrapper(uriInfo); + Response result = Response.noContent().build(); + boolean success = false; + String docType = null; + + try { + RemoteServiceContext ctx = (RemoteServiceContext) createServiceContext(uriInfo); + docType = ctx.getTenantQualifiedDoctype(); // this will used in the error message if an error occurs + DocumentHandler handler = createDocumentHandler(ctx); + success = getRepositoryClient(ctx).reindex(handler, indexid); + } catch (Exception e) { + throw bigReThrow(e, ServiceMessages.REINDEX_FAILED); + } + + if (success == false) { + Response response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + ServiceMessages.REINDEX_FAILED + ServiceMessages.resourceNotReindexedMsg(docType)).type("text/plain").build(); + throw new CSWebApplicationException(response); + } + + return result; + } /* (non-Javadoc) * @see org.collectionspace.services.common.ResourceBase#getList(javax.ws.rs.core.UriInfo, java.lang.String) diff --git a/services/index/service/src/main/java/org/collectionspace/services/index/nuxeo/IndexDocumentModelHandler.java b/services/index/service/src/main/java/org/collectionspace/services/index/nuxeo/IndexDocumentModelHandler.java new file mode 100644 index 000000000..dd06e39bb --- /dev/null +++ b/services/index/service/src/main/java/org/collectionspace/services/index/nuxeo/IndexDocumentModelHandler.java @@ -0,0 +1,114 @@ +/** + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + + * http://www.collectionspace.org + * http://wiki.collectionspace.org + + * Copyright 2009 University of California at Berkeley + + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + + * You may obtain a copy of the ECL 2.0 License at + + * https://source.collectionspace.org/collection-space/LICENSE.txt + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.collectionspace.services.index.nuxeo; + +import java.util.List; + +import org.collectionspace.services.client.index.IndexClient; +import org.collectionspace.services.common.ServiceMain; +import org.collectionspace.services.common.api.Tools; +import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl; +import org.collectionspace.services.common.context.ServiceBindingUtils; +import org.collectionspace.services.common.context.ServiceContext; +import org.collectionspace.services.common.document.DocumentException; +import org.collectionspace.services.config.service.ServiceBindingType; +import org.collectionspace.services.config.types.PropertyItemType; +import org.collectionspace.services.index.IndexCommon; +import org.collectionspace.services.nuxeo.client.java.NuxeoDocumentModelHandler; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * IntakeDocumentModelHandler + * + * $LastChangedRevision: $ + * $LastChangedDate: $ + */ +public class IndexDocumentModelHandler + extends NuxeoDocumentModelHandler { + private final Logger logger = LoggerFactory.getLogger(IndexDocumentModelHandler.class); + + + @Override + public String getDocumentsToIndexQuery(String indexId, String csid) throws DocumentException, Exception { + String result = null; + + switch (indexId) { + case IndexClient.FULLTEXT_ID: + result = getReindexQuery(indexId, csid); + break; + case IndexClient.ELASTICSEARCH_ID: + result = getReindexQuery(indexId, csid); + + break; + } + + if (Tools.isEmpty(result) == true) { + 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'", + indexId, IndexClient.DEFAULT_REINDEX_QUERY); + logger.warn(msg); + result = IndexClient.DEFAULT_REINDEX_QUERY; + } + + return result; + } + + /** + * Reads the Index service bindings to get the query that will be used to find all documents needing + * reindexing. + * + * @param indexId + * @param csid + * @return + * @throws DocumentException + * @throws Exception + * + * TODO: Use the incoming CSID param to qualify the returned query. + */ + private String getReindexQuery(String indexId, String csid) throws DocumentException, Exception { + String result = null; + + // + // Read in the NXQL query to use when performing a full + // + TenantBindingConfigReaderImpl tReader = + ServiceMain.getInstance().getTenantBindingConfigReader(); + ServiceContext ctx = this.getServiceContext(); + + ServiceBindingType reportServiceBinding = tReader.getServiceBinding(ctx.getTenantId(), ctx.getServiceName()); + List queryTypeList = ServiceBindingUtils.getPropertyValueList(reportServiceBinding, indexId); + + if (queryTypeList != null && queryTypeList.isEmpty() == false) { + PropertyItemType propertyItemType = queryTypeList.get(0); + if (propertyItemType != null) { + result = propertyItemType.getValue(); + } + } + + return result; + } + +} + diff --git a/services/index/service/src/main/java/org/collectionspace/services/index/nuxeo/IndexValidatorHandler.java b/services/index/service/src/main/java/org/collectionspace/services/index/nuxeo/IndexValidatorHandler.java index 4c378e763..456e3506c 100644 --- a/services/index/service/src/main/java/org/collectionspace/services/index/nuxeo/IndexValidatorHandler.java +++ b/services/index/service/src/main/java/org/collectionspace/services/index/nuxeo/IndexValidatorHandler.java @@ -15,7 +15,7 @@ public class IndexValidatorHandler extends ValidatorHandlerImpl