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.GetFontWeightForm; 020import com.echothree.control.user.core.common.result.CoreResultFactory; 021import com.echothree.model.control.core.common.ComponentVendors; 022import com.echothree.model.control.core.common.EntityTypes; 023import com.echothree.model.control.core.common.EventTypes; 024import com.echothree.model.control.core.server.control.FontControl; 025import com.echothree.model.control.core.server.logic.EntityInstanceLogic; 026import com.echothree.model.control.core.server.logic.FontLogic; 027import com.echothree.model.data.core.server.entity.FontWeight; 028import com.echothree.model.data.user.common.pk.UserVisitPK; 029import com.echothree.util.common.command.BaseResult; 030import com.echothree.util.common.message.ExecutionErrors; 031import com.echothree.util.common.validation.FieldDefinition; 032import com.echothree.util.common.validation.FieldType; 033import com.echothree.util.server.control.BaseSingleEntityCommand; 034import java.util.List; 035import javax.enterprise.context.Dependent; 036import javax.inject.Inject; 037 038@Dependent 039public class GetFontWeightCommand 040 extends BaseSingleEntityCommand<FontWeight, GetFontWeightForm> { 041 042 // No COMMAND_SECURITY_DEFINITION, anyone may execute this command. 043 private final static List<FieldDefinition> FORM_FIELD_DEFINITIONS; 044 045 static { 046 FORM_FIELD_DEFINITIONS = List.of( 047 new FieldDefinition("FontWeightName", FieldType.ENTITY_NAME, false, null, null), 048 new FieldDefinition("EntityRef", FieldType.ENTITY_REF, false, null, null), 049 new FieldDefinition("Uuid", FieldType.UUID, false, null, null) 050 ); 051 } 052 053 @Inject 054 FontControl fontControl; 055 056 @Inject 057 EntityInstanceLogic entityInstanceLogic; 058 059 @Inject 060 FontLogic fontLogic; 061 062 063 /** Creates a new instance of GetFontWeightCommand */ 064 public GetFontWeightCommand() { 065 super(null, FORM_FIELD_DEFINITIONS, true); 066 } 067 068 @Override 069 protected FontWeight getEntity() { 070 FontWeight fontWeight = null; 071 var fontWeightName = form.getFontWeightName(); 072 var parameterCount = (fontWeightName == null ? 0 : 1) + entityInstanceLogic.countPossibleEntitySpecs(form); 073 074 if(parameterCount == 1) { 075 if(fontWeightName == null) { 076 var entityInstance = entityInstanceLogic.getEntityInstance(this, form, 077 ComponentVendors.ECHO_THREE.name(), EntityTypes.FontWeight.name()); 078 079 if(!hasExecutionErrors()) { 080 fontWeight = fontControl.getFontWeightByEntityInstance(entityInstance); 081 } 082 } else { 083 fontWeight = fontLogic.getFontWeightByName(this, fontWeightName); 084 } 085 086 if(fontWeight != null) { 087 sendEvent(fontWeight.getPrimaryKey(), EventTypes.READ, null, null, getPartyPK()); 088 } 089 } else { 090 addExecutionError(ExecutionErrors.InvalidParameterCount.name()); 091 } 092 093 return fontWeight; 094 } 095 096 @Override 097 protected BaseResult getResult(FontWeight fontWeight) { 098 var result = CoreResultFactory.getGetFontWeightResult(); 099 100 if(fontWeight != null) { 101 result.setFontWeight(fontControl.getFontWeightTransfer(getUserVisit(), fontWeight)); 102 } 103 104 return result; 105 } 106 107}