package gw.solr.mapper uses gw.api.locale.DisplayKey uses gw.xsd.config.solr_search_config.DataProperty uses com.guidewire.pl.system.dependency.PLDependencies uses gw.api.util.DisplayableException uses java.util.List /** * Builds the producer code filter query to limit search results to the * periods the user has permission to view */ class ProducerCodeSecurityMapper implements ISolrQueryMapper{ override function mapQuery(queryDataProperties : List, dataHolder : IDataHolder) : String { var user: User = PLDependencies.getCommonDependencies().getCurrentUser() if (!user.UseProducerCodeSecurity) { return null } // If producer codes security is on, but the user has no producer codes specified, throw an exception if (user.UserProducerCodes.IsEmpty) { throw new DisplayableException(DisplayKey.get("Web.PolicySearch.Solr.ProducerCodeSecurityEnabledWithNoProducerCodes")) } // TODO Investigate whether or not we ever have to encode or quote these values - this // will be necessary if they contain certain characters, such as parenthesis or spaces, // which may render the FQ malformed var codes = user.UserProducerCodes*.ProducerCode*.Code if (codes.Count == 1) { return codes.first() } return "(" + codes.join(" OR ") + ")" } }