001// -------------------------------------------------------------------------------- 002// Copyright 2002-2025 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.GetEntityIntegerRangeForm; 020import com.echothree.control.user.core.common.result.CoreResultFactory; 021import com.echothree.model.control.core.common.EntityAttributeTypes; 022import com.echothree.model.data.core.server.entity.EntityIntegerRange; 023import com.echothree.model.data.user.common.pk.UserVisitPK; 024import com.echothree.util.common.command.BaseResult; 025import com.echothree.util.common.message.ExecutionErrors; 026import com.echothree.util.common.validation.FieldDefinition; 027import com.echothree.util.common.validation.FieldType; 028import com.echothree.util.server.control.BaseSingleEntityCommand; 029import java.util.List; 030import javax.enterprise.context.RequestScoped; 031 032@RequestScoped 033public class GetEntityIntegerRangeCommand 034 extends BaseSingleEntityCommand<EntityIntegerRange, GetEntityIntegerRangeForm> { 035 036 // No COMMAND_SECURITY_DEFINITION, anyone may execute this command. 037 private final static List<FieldDefinition> FORM_FIELD_DEFINITIONS; 038 039 static { 040 FORM_FIELD_DEFINITIONS = List.of( 041 new FieldDefinition("ComponentVendorName", FieldType.ENTITY_NAME, true, null, null), 042 new FieldDefinition("EntityTypeName", FieldType.ENTITY_TYPE_NAME, true, null, null), 043 new FieldDefinition("EntityAttributeName", FieldType.ENTITY_NAME, true, null, null), 044 new FieldDefinition("EntityIntegerRangeName", FieldType.ENTITY_NAME, true, null, null) 045 ); 046 } 047 048 /** Creates a new instance of GetEntityIntegerRangeCommand */ 049 public GetEntityIntegerRangeCommand() { 050 super(null, FORM_FIELD_DEFINITIONS, true); 051 } 052 053 @Override 054 protected EntityIntegerRange getEntity() { 055 EntityIntegerRange entityIntegerRange = null; 056 var componentVendorName = form.getComponentVendorName(); 057 var componentVendor = componentControl.getComponentVendorByName(componentVendorName); 058 059 if(componentVendor != null) { 060 var entityTypeName = form.getEntityTypeName(); 061 var entityType = entityTypeControl.getEntityTypeByName(componentVendor, entityTypeName); 062 063 if(entityType != null) { 064 var entityAttributeName = form.getEntityAttributeName(); 065 var entityAttribute = coreControl.getEntityAttributeByName(entityType, entityAttributeName); 066 067 if(entityAttribute != null) { 068 var entityAttributeType = entityAttribute.getLastDetail().getEntityAttributeType(); 069 var entityAttributeTypeName = entityAttributeType.getEntityAttributeTypeName(); 070 071 if(entityAttributeTypeName.equals(EntityAttributeTypes.INTEGER.name())) { 072 var entityIntegerRangeName = form.getEntityIntegerRangeName(); 073 074 entityIntegerRange = coreControl.getEntityIntegerRangeByName(entityAttribute, entityIntegerRangeName); 075 076 if(entityIntegerRange == null) { 077 addExecutionError(ExecutionErrors.UnknownEntityIntegerRangeName.name(), componentVendorName, entityTypeName, entityAttributeName, entityIntegerRangeName); 078 } 079 } else { 080 addExecutionError(ExecutionErrors.InvalidEntityAttributeType.name(), componentVendorName, entityTypeName, entityAttributeName, entityAttributeTypeName); 081 } 082 } else { 083 addExecutionError(ExecutionErrors.UnknownEntityAttributeName.name(), componentVendorName, entityTypeName, entityAttributeName); 084 } 085 } else { 086 addExecutionError(ExecutionErrors.UnknownEntityTypeName.name(), componentVendorName, entityTypeName); 087 } 088 } else { 089 addExecutionError(ExecutionErrors.UnknownComponentVendorName.name(), componentVendorName); 090 } 091 092 return entityIntegerRange; 093 } 094 095 @Override 096 protected BaseResult getResult(EntityIntegerRange entityIntegerRange) { 097 var result = CoreResultFactory.getGetEntityIntegerRangeResult(); 098 099 if(entityIntegerRange != null) { 100 101 result.setEntityIntegerRange(coreControl.getEntityIntegerRangeTransfer(getUserVisit(), entityIntegerRange, null)); 102 } 103 104 return result; 105 } 106 107}