001/* 002 * #%L 003 * HAPI FHIR JPA Server 004 * %% 005 * Copyright (C) 2014 - 2024 Smile CDR, Inc. 006 * %% 007 * Licensed under the Apache License, Version 2.0 (the "License"); 008 * you may not use this file except in compliance with the License. 009 * You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 * #L% 019 */ 020package ca.uhn.fhir.jpa.search; 021 022import ca.uhn.fhir.jpa.entity.TermConcept; 023import org.hibernate.search.mapper.pojo.bridge.RoutingBridge; 024import org.hibernate.search.mapper.pojo.bridge.binding.RoutingBindingContext; 025import org.hibernate.search.mapper.pojo.bridge.mapping.programmatic.RoutingBinder; 026import org.hibernate.search.mapper.pojo.bridge.runtime.RoutingBridgeRouteContext; 027import org.hibernate.search.mapper.pojo.route.DocumentRoutes; 028 029public class DeferConceptIndexingRoutingBinder implements RoutingBinder { 030 @Override 031 public void bind(RoutingBindingContext theRoutingBindingContext) { 032 theRoutingBindingContext.dependencies().use("myIndexStatus"); 033 034 theRoutingBindingContext.bridge(TermConcept.class, new TermConceptBridge()); 035 } 036 037 private class TermConceptBridge implements RoutingBridge<TermConcept> { 038 @Override 039 public void route( 040 DocumentRoutes theDocumentRoutes, 041 Object theO, 042 TermConcept theTermConcept, 043 RoutingBridgeRouteContext theRoutingBridgeRouteContext) { 044 if (theTermConcept.getIndexStatus() == null) { 045 theDocumentRoutes.notIndexed(); 046 } else { 047 theDocumentRoutes.addRoute(); 048 } 049 } 050 051 @Override 052 public void previousRoutes( 053 DocumentRoutes theDocumentRoutes, 054 Object theO, 055 TermConcept theTermConcept, 056 RoutingBridgeRouteContext theRoutingBridgeRouteContext) { 057 theDocumentRoutes.addRoute(); 058 } 059 } 060}