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.inventory.server.command;
018
019import com.echothree.control.user.inventory.common.form.GetInventoryCostingPoolForm;
020import com.echothree.control.user.inventory.common.result.InventoryResultFactory;
021import com.echothree.model.control.inventory.server.control.InventoryCostingPoolControl;
022import com.echothree.model.control.inventory.server.logic.InventoryCostingPoolLogic;
023import com.echothree.model.control.party.common.PartyTypes;
024import com.echothree.model.control.security.common.SecurityRoleGroups;
025import com.echothree.model.control.security.common.SecurityRoles;
026import com.echothree.model.data.inventory.server.entity.InventoryCostingPool;
027import com.echothree.util.common.command.BaseResult;
028import com.echothree.util.common.validation.FieldDefinition;
029import com.echothree.util.common.validation.FieldType;
030import com.echothree.util.server.control.BaseSingleEntityCommand;
031import com.echothree.util.server.control.CommandSecurityDefinition;
032import com.echothree.util.server.control.PartyTypeDefinition;
033import com.echothree.util.server.control.SecurityRoleDefinition;
034import java.util.List;
035import javax.enterprise.context.Dependent;
036import javax.inject.Inject;
037
038@Dependent
039public class GetInventoryCostingPoolCommand
040        extends BaseSingleEntityCommand<InventoryCostingPool, GetInventoryCostingPoolForm> {
041
042    private static final CommandSecurityDefinition COMMAND_SECURITY_DEFINITION = new CommandSecurityDefinition(List.of(
043            new PartyTypeDefinition(PartyTypes.UTILITY.name(), null),
044            new PartyTypeDefinition(PartyTypes.EMPLOYEE.name(), List.of(
045                    new SecurityRoleDefinition(SecurityRoleGroups.InventoryCostingPool.name(), SecurityRoles.Review.name())
046            ))
047    ));
048
049    private static final List<FieldDefinition> FORM_FIELD_DEFINITIONS = List.of(
050            new FieldDefinition("PartyName", FieldType.ENTITY_NAME, false, null, null),
051            new FieldDefinition("CompanyName", FieldType.ENTITY_NAME, false, null, null),
052            new FieldDefinition("ItemName", FieldType.ENTITY_NAME, false, null, null),
053            new FieldDefinition("InventoryConditionName", FieldType.ENTITY_NAME, false, null, null),
054            new FieldDefinition("EntityRef", FieldType.ENTITY_REF, false, null, null),
055            new FieldDefinition("Uuid", FieldType.UUID, false, null, null)
056    );
057
058    @Inject
059    InventoryCostingPoolControl inventoryCostingPoolControl;
060
061    @Inject
062    InventoryCostingPoolLogic inventoryCostingPoolLogic;
063
064    public GetInventoryCostingPoolCommand() {
065        super(COMMAND_SECURITY_DEFINITION, FORM_FIELD_DEFINITIONS, true);
066    }
067
068    @Override
069    protected InventoryCostingPool getEntity() {
070        return inventoryCostingPoolLogic.getInventoryCostingPoolByUniversalSpec(this, form);
071    }
072
073    @Override
074    protected BaseResult getResult(InventoryCostingPool inventoryCostingPool) {
075        var result = InventoryResultFactory.getGetInventoryCostingPoolResult();
076
077        if(!hasExecutionErrors()) {
078            result.setInventoryCostingPool(inventoryCostingPoolControl.getInventoryCostingPoolTransfer(getUserVisit(), inventoryCostingPool));
079        }
080
081        return result;
082    }
083
084}