001// --------------------------------------------------------------------------------
002// Copyright 2002-2026 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.core.server.command;
018
019import com.echothree.control.user.core.common.form.GetEventGroupsForm;
020import com.echothree.control.user.core.common.result.CoreResultFactory;
021import com.echothree.model.data.core.server.entity.EventGroup;
022import com.echothree.model.data.core.server.factory.EventGroupFactory;
023import com.echothree.util.common.command.BaseResult;
024import com.echothree.util.common.validation.FieldDefinition;
025import com.echothree.util.server.control.BasePaginatedMultipleEntitiesCommand;
026import java.util.Collection;
027import java.util.List;
028import javax.enterprise.context.Dependent;
029
030@Dependent
031public class GetEventGroupsCommand
032        extends BasePaginatedMultipleEntitiesCommand<EventGroup, GetEventGroupsForm> {
033    
034    private final static List<FieldDefinition> FORM_FIELD_DEFINITIONS;
035
036    static {
037        FORM_FIELD_DEFINITIONS = List.of();
038    }
039
040    /** Creates a new instance of GetEventGroupsCommand */
041    public GetEventGroupsCommand() {
042        super(null, FORM_FIELD_DEFINITIONS, true);
043    }
044
045    @Override
046    protected void handleForm() {
047        // No form fields.
048    }
049
050    @Override
051    protected Long getTotalEntities() {
052        return eventControl.countEventGroups();
053    }
054
055    @Override
056    protected Collection<EventGroup> getEntities() {
057        return eventControl.getEventGroups();
058    }
059
060    @Override
061    protected BaseResult getResult(Collection<EventGroup> entities) {
062        var result = CoreResultFactory.getGetEventGroupsResult();
063
064        if(entities != null) {
065            if(session.hasLimit(EventGroupFactory.class)) {
066                result.setEventGroupCount(getTotalEntities());
067            }
068
069            result.setEventGroups(eventControl.getEventGroupTransfers(getUserVisit(), entities));
070        }
071
072        return result;
073    }
074    
075}