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.control.user.search.server.command; 018 019import com.echothree.control.user.search.common.form.GetSecurityRoleGroupResultsForm; 020import com.echothree.control.user.search.common.result.GetSecurityRoleGroupResultsResult; 021import com.echothree.control.user.search.common.result.SearchResultFactory; 022import com.echothree.model.control.search.common.SearchKinds; 023import com.echothree.model.control.search.server.control.SearchControl; 024import com.echothree.model.control.search.server.logic.SearchLogic; 025import com.echothree.model.control.security.server.control.SecurityRoleGroupControl; 026import com.echothree.model.data.search.server.entity.SearchKind; 027import com.echothree.model.data.search.server.entity.SearchType; 028import com.echothree.model.data.search.server.entity.UserVisitSearch; 029import com.echothree.model.data.user.common.pk.UserVisitPK; 030import com.echothree.model.data.user.server.entity.UserVisit; 031import com.echothree.util.common.message.ExecutionErrors; 032import com.echothree.util.common.validation.FieldDefinition; 033import com.echothree.util.common.validation.FieldType; 034import com.echothree.util.common.command.BaseResult; 035import com.echothree.util.server.control.BaseSimpleCommand; 036import com.echothree.util.server.persistence.Session; 037import java.util.Arrays; 038import java.util.Collections; 039import java.util.List; 040 041public class GetSecurityRoleGroupResultsCommand 042 extends BaseSimpleCommand<GetSecurityRoleGroupResultsForm> { 043 044 private final static List<FieldDefinition> FORM_FIELD_DEFINITIONS; 045 046 static { 047 FORM_FIELD_DEFINITIONS = Collections.unmodifiableList(Arrays.asList( 048 new FieldDefinition("SearchTypeName", FieldType.ENTITY_NAME, true, null, null) 049 )); 050 } 051 052 /** Creates a new instance of GetSecurityRoleGroupResultsCommand */ 053 public GetSecurityRoleGroupResultsCommand(UserVisitPK userVisitPK, GetSecurityRoleGroupResultsForm form) { 054 super(userVisitPK, form, null, FORM_FIELD_DEFINITIONS, true); 055 } 056 057 @Override 058 protected BaseResult execute() { 059 GetSecurityRoleGroupResultsResult result = SearchResultFactory.getGetSecurityRoleGroupResultsResult(); 060 var searchControl = Session.getModelController(SearchControl.class); 061 SearchKind searchKind = searchControl.getSearchKindByName(SearchKinds.SECURITY_ROLE_GROUP.name()); 062 063 if(searchKind != null) { 064 String searchTypeName = form.getSearchTypeName(); 065 SearchType searchType = searchControl.getSearchTypeByName(searchKind, searchTypeName); 066 067 if(searchType != null) { 068 UserVisit userVisit = getUserVisit(); 069 UserVisitSearch userVisitSearch = searchControl.getUserVisitSearch(userVisit, searchType); 070 071 if(userVisitSearch != null) { 072 var securityRoleGroupControl = Session.getModelController(SecurityRoleGroupControl.class); 073 074 if(session.hasLimit(com.echothree.model.data.search.server.factory.SearchResultFactory.class)) { 075 result.setSecurityRoleGroupResultCount(SearchLogic.getInstance().countSearchResults(userVisitSearch.getSearch())); 076 } 077 078 result.setSecurityRoleGroupResults(securityRoleGroupControl.getSecurityRoleGroupResultTransfers(userVisit, userVisitSearch)); 079 } else { 080 addExecutionError(ExecutionErrors.UnknownUserVisitSearch.name()); 081 } 082 } else { 083 addExecutionError(ExecutionErrors.UnknownSearchTypeName.name(), SearchKinds.SECURITY_ROLE_GROUP.name(), searchTypeName); 084 } 085 } else { 086 addExecutionError(ExecutionErrors.UnknownSearchKindName.name(), SearchKinds.SECURITY_ROLE_GROUP.name()); 087 } 088 089 return result; 090 } 091}