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.vendor.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.vendor.server.analysis.VendorAnalyzer; 025import com.echothree.model.control.vendor.server.control.VendorControl; 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.vendor.server.entity.Vendor; 033import com.echothree.util.server.message.ExecutionErrorAccumulator; 034import com.echothree.util.server.persistence.Session; 035import org.apache.lucene.analysis.Analyzer; 036 037public class VendorSearchEvaluator 038 extends PartySearchEvaluator { 039 040 private String vendorName; 041 042 /** Creates a new instance of VendorSearchEvaluator */ 043 public VendorSearchEvaluator(UserVisit userVisit, SearchType searchType, SearchDefaultOperator searchDefaultOperator, 044 SearchSortOrder searchSortOrder, SearchSortDirection searchSortDirection) { 045 super(userVisit, searchType, searchDefaultOperator, searchSortOrder, searchSortDirection, PartyTypes.VENDOR.name(), 046 IndexFields.vendorName.name(), Indexes.VENDOR.name()); 047 } 048 049 public String getVendorName() { 050 return vendorName; 051 } 052 053 public void setVendorName(String vendorName) { 054 this.vendorName = vendorName; 055 } 056 057 @Override 058 public Analyzer getAnalyzer(final ExecutionErrorAccumulator eea, final Language language) { 059 return new VendorAnalyzer(eea, language, entityType, partyType, entityNameIndexField); 060 } 061 062 @Override 063 protected EntityInstancePKHolder executeSearch(final ExecutionErrorAccumulator eea) { 064 EntityInstancePKHolder resultSet = null; 065 066 if(vendorName == null) { 067 resultSet = super.executeSearch(eea); 068 } else { 069 Vendor vendor = null; 070 071 if(vendorName != null) { 072 var vendorControl = Session.getModelController(VendorControl.class); 073 074 vendor = vendorControl.getVendorByName(vendorName); 075 } 076 077 if(vendor != null) { 078 resultSet = new EntityInstancePKHolder(1); 079 resultSet.add(getCoreControl().getEntityInstanceByBasePK(vendor.getPartyPK()).getPrimaryKey(), null); 080 } 081 } 082 083 return resultSet; 084 } 085 086}