001// -------------------------------------------------------------------------------- 002// Copyright 2002-2024 Echo Three, LLC 003// 004// Licensed under the Apache License, Version 2.0 (the "License"); 005// you may not use this file except in compliance with the License. 006// You may obtain a copy of the License at 007// 008// http://www.apache.org/licenses/LICENSE-2.0 009// 010// Unless required by applicable law or agreed to in writing, software 011// distributed under the License is distributed on an "AS IS" BASIS, 012// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013// See the License for the specific language governing permissions and 014// limitations under the License. 015// -------------------------------------------------------------------------------- 016 017package com.echothree.model.control.warehouse.server.search; 018 019import com.echothree.model.control.index.common.IndexFields; 020import com.echothree.model.control.index.common.Indexes; 021import com.echothree.model.control.party.common.PartyTypes; 022import com.echothree.model.control.party.server.search.PartySearchEvaluator; 023import com.echothree.model.control.search.server.search.EntityInstancePKHolder; 024import com.echothree.model.control.warehouse.server.analysis.WarehouseAnalyzer; 025import com.echothree.model.control.warehouse.server.control.WarehouseControl; 026import com.echothree.model.data.party.server.entity.Language; 027import com.echothree.model.data.search.server.entity.SearchDefaultOperator; 028import com.echothree.model.data.search.server.entity.SearchSortDirection; 029import com.echothree.model.data.search.server.entity.SearchSortOrder; 030import com.echothree.model.data.search.server.entity.SearchType; 031import com.echothree.model.data.user.server.entity.UserVisit; 032import com.echothree.model.data.warehouse.server.entity.Warehouse; 033import com.echothree.util.server.message.ExecutionErrorAccumulator; 034import com.echothree.util.server.persistence.Session; 035import org.apache.lucene.analysis.Analyzer; 036 037public class WarehouseSearchEvaluator 038 extends PartySearchEvaluator { 039 040 private String warehouseName; 041 042 /** Creates a new instance of WarehouseSearchEvaluator */ 043 public WarehouseSearchEvaluator(UserVisit userVisit, SearchType searchType, SearchDefaultOperator searchDefaultOperator, 044 SearchSortOrder searchSortOrder, SearchSortDirection searchSortDirection) { 045 super(userVisit, searchType, searchDefaultOperator, searchSortOrder, searchSortDirection, PartyTypes.WAREHOUSE.name(), 046 IndexFields.warehouseName.name(), Indexes.WAREHOUSE.name()); 047 } 048 049 public String getWarehouseName() { 050 return warehouseName; 051 } 052 053 public void setWarehouseName(String warehouseName) { 054 this.warehouseName = warehouseName; 055 } 056 057 @Override 058 public Analyzer getAnalyzer(final ExecutionErrorAccumulator eea, final Language language) { 059 return new WarehouseAnalyzer(eea, language, entityType, partyType, entityNameIndexField); 060 } 061 062 @Override 063 protected EntityInstancePKHolder executeSearch(final ExecutionErrorAccumulator eea) { 064 EntityInstancePKHolder resultSet = null; 065 066 if(warehouseName == null) { 067 resultSet = super.executeSearch(eea); 068 } else { 069 Warehouse warehouse = null; 070 071 if(warehouseName != null) { 072 var warehouseControl = Session.getModelController(WarehouseControl.class); 073 074 warehouse = warehouseControl.getWarehouseByName(warehouseName); 075 } 076 077 if(warehouse != null) { 078 resultSet = new EntityInstancePKHolder(1); 079 resultSet.add(getCoreControl().getEntityInstanceByBasePK(warehouse.getPartyPK()).getPrimaryKey(), null); 080 } 081 } 082 083 return resultSet; 084 } 085 086}