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.GetPartyInventoryCostingMethodForm; 020import com.echothree.control.user.inventory.common.result.InventoryResultFactory; 021import com.echothree.model.control.inventory.server.control.InventoryCostingMethodControl; 022import com.echothree.model.control.inventory.server.logic.PartyInventoryCostingMethodLogic; 023import com.echothree.model.control.party.common.PartyTypes; 024import com.echothree.model.control.party.server.logic.PartyLogic; 025import com.echothree.model.control.security.common.SecurityRoleGroups; 026import com.echothree.model.control.security.common.SecurityRoles; 027import com.echothree.model.data.inventory.server.entity.PartyInventoryCostingMethod; 028import com.echothree.util.common.command.BaseResult; 029import com.echothree.util.common.validation.FieldDefinition; 030import com.echothree.util.common.validation.FieldType; 031import com.echothree.util.server.control.BaseSingleEntityCommand; 032import com.echothree.util.server.control.CommandSecurityDefinition; 033import com.echothree.util.server.control.PartyTypeDefinition; 034import com.echothree.util.server.control.SecurityRoleDefinition; 035import java.util.List; 036import javax.enterprise.context.Dependent; 037import javax.inject.Inject; 038 039@Dependent 040public class GetPartyInventoryCostingMethodCommand 041 extends BaseSingleEntityCommand<PartyInventoryCostingMethod, GetPartyInventoryCostingMethodForm> { 042 043 private static final CommandSecurityDefinition COMMAND_SECURITY_DEFINITION = new CommandSecurityDefinition(List.of( 044 new PartyTypeDefinition(PartyTypes.UTILITY.name(), null), 045 new PartyTypeDefinition(PartyTypes.EMPLOYEE.name(), List.of( 046 new SecurityRoleDefinition(SecurityRoleGroups.InventoryCostingMethod.name(), SecurityRoles.Review.name()) 047 )) 048 )); 049 050 private static final List<FieldDefinition> FORM_FIELD_DEFINITIONS = List.of( 051 new FieldDefinition("PartyName", FieldType.ENTITY_NAME, false, null, null), 052 new FieldDefinition("EntityRef", FieldType.ENTITY_REF, false, null, null), 053 new FieldDefinition("Uuid", FieldType.UUID, false, null, null) 054 ); 055 056 @Inject 057 InventoryCostingMethodControl inventoryCostingMethodControl; 058 059 @Inject 060 PartyInventoryCostingMethodLogic partyInventoryCostingMethodLogic; 061 062 @Inject 063 PartyLogic partyLogic; 064 065 public GetPartyInventoryCostingMethodCommand() { 066 super(COMMAND_SECURITY_DEFINITION, FORM_FIELD_DEFINITIONS, true); 067 } 068 069 @Override 070 protected PartyInventoryCostingMethod getEntity() { 071 var party = partyLogic.getPartyByName(this, form.getPartyName(), form); 072 PartyInventoryCostingMethod partyInventoryCostingMethod = null; 073 074 if(!hasExecutionErrors()) { 075 partyInventoryCostingMethod = partyInventoryCostingMethodLogic.getPartyInventoryCostingMethod(this, party, 076 false, getPartyPK()); 077 } 078 079 return partyInventoryCostingMethod; 080 } 081 082 @Override 083 protected BaseResult getResult(PartyInventoryCostingMethod partyInventoryCostingMethod) { 084 var result = InventoryResultFactory.getGetPartyInventoryCostingMethodResult(); 085 086 if(partyInventoryCostingMethod != null) { 087 result.setPartyInventoryCostingMethod(inventoryCostingMethodControl.getPartyInventoryCostingMethodTransfer( 088 getUserVisit(), partyInventoryCostingMethod)); 089 } 090 091 return result; 092 } 093}