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