001/*-
002 * #%L
003 * HAPI FHIR JPA Model
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.model.search;
021
022import ca.uhn.fhir.jpa.model.entity.ResourceTable;
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 ResourceTableRoutingBinder implements RoutingBinder {
030        @Override
031        public void bind(RoutingBindingContext theRoutingBindingContext) {
032                theRoutingBindingContext.dependencies().use("myDeleted").use("myIndexStatus");
033                theRoutingBindingContext.bridge(ResourceTable.class, new ResourceTableBridge());
034        }
035
036        private static class ResourceTableBridge implements RoutingBridge<ResourceTable> {
037
038                @Override
039                public void route(
040                                DocumentRoutes theDocumentRoutes,
041                                Object theO,
042                                ResourceTable theResourceTable,
043                                RoutingBridgeRouteContext theRoutingBridgeRouteContext) {
044                        if (theResourceTable.getDeleted() == null && theResourceTable.getIndexStatus() != null) {
045                                theDocumentRoutes.addRoute();
046                        } else {
047                                theDocumentRoutes.notIndexed();
048                        }
049                }
050
051                @Override
052                public void previousRoutes(
053                                DocumentRoutes theDocumentRoutes,
054                                Object theO,
055                                ResourceTable theResourceTable,
056                                RoutingBridgeRouteContext theRoutingBridgeRouteContext) {
057                        theDocumentRoutes.addRoute();
058                }
059        }
060}