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.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 com.echothree.util.server.persistence.Session; 035import java.util.Arrays; 036import java.util.Collections; 037import java.util.List; 038import javax.enterprise.context.RequestScoped; 039 040@RequestScoped 041public class GetFontWeightCommand 042 extends BaseSingleEntityCommand<FontWeight, GetFontWeightForm> { 043 044 // No COMMAND_SECURITY_DEFINITION, anyone may execute this command. 045 private final static List<FieldDefinition> FORM_FIELD_DEFINITIONS; 046 047 static { 048 FORM_FIELD_DEFINITIONS = Collections.unmodifiableList(Arrays.asList( 049 new FieldDefinition("FontWeightName", FieldType.ENTITY_NAME, false, null, null), 050 new FieldDefinition("EntityRef", FieldType.ENTITY_REF, false, null, null), 051 new FieldDefinition("Uuid", FieldType.UUID, false, null, null) 052 )); 053 } 054 055 /** Creates a new instance of GetFontWeightCommand */ 056 public GetFontWeightCommand() { 057 super(null, FORM_FIELD_DEFINITIONS, true); 058 } 059 060 @Override 061 protected FontWeight getEntity() { 062 FontWeight fontWeight = null; 063 var fontWeightName = form.getFontWeightName(); 064 var parameterCount = (fontWeightName == null ? 0 : 1) + EntityInstanceLogic.getInstance().countPossibleEntitySpecs(form); 065 066 if(parameterCount == 1) { 067 if(fontWeightName == null) { 068 var entityInstance = EntityInstanceLogic.getInstance().getEntityInstance(this, form, 069 ComponentVendors.ECHO_THREE.name(), EntityTypes.FontWeight.name()); 070 071 if(!hasExecutionErrors()) { 072 var fontControl = Session.getModelController(FontControl.class); 073 074 fontWeight = fontControl.getFontWeightByEntityInstance(entityInstance); 075 } 076 } else { 077 fontWeight = FontLogic.getInstance().getFontWeightByName(this, fontWeightName); 078 } 079 080 if(fontWeight != null) { 081 sendEvent(fontWeight.getPrimaryKey(), EventTypes.READ, null, null, getPartyPK()); 082 } 083 } else { 084 addExecutionError(ExecutionErrors.InvalidParameterCount.name()); 085 } 086 087 return fontWeight; 088 } 089 090 @Override 091 protected BaseResult getResult(FontWeight fontWeight) { 092 var fontControl = Session.getModelController(FontControl.class); 093 var result = CoreResultFactory.getGetFontWeightResult(); 094 095 if(fontWeight != null) { 096 result.setFontWeight(fontControl.getFontWeightTransfer(getUserVisit(), fontWeight)); 097 } 098 099 return result; 100 } 101 102}