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.GetEntityClobAttributeForm; 020import com.echothree.control.user.core.common.result.CoreResultFactory; 021import com.echothree.model.control.core.server.control.EntityInstanceControl; 022import com.echothree.model.control.party.server.control.PartyControl; 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.BaseSimpleCommand; 029import com.echothree.util.server.persistence.Session; 030import java.util.List; 031import javax.enterprise.context.Dependent; 032 033@Dependent 034public class GetEntityClobAttributeCommand 035 extends BaseSimpleCommand<GetEntityClobAttributeForm> { 036 037 private final static List<FieldDefinition> FORM_FIELD_DEFINITIONS; 038 039 static { 040 FORM_FIELD_DEFINITIONS = List.of( 041 new FieldDefinition("EntityRef", FieldType.ENTITY_REF, true, null, null), 042 new FieldDefinition("EntityAttributeName", FieldType.ENTITY_NAME, true, null, null), 043 new FieldDefinition("LanguageIsoName", FieldType.ENTITY_NAME, false, null, null) 044 ); 045 } 046 047 /** Creates a new instance of GetEntityClobAttributeCommand */ 048 public GetEntityClobAttributeCommand() { 049 super(null, FORM_FIELD_DEFINITIONS, false); 050 } 051 052 @Override 053 protected BaseResult execute() { 054 var entityInstanceControl = Session.getModelController(EntityInstanceControl.class); 055 var result = CoreResultFactory.getGetEntityClobAttributeResult(); 056 var entityRef = form.getEntityRef(); 057 var entityInstance = entityInstanceControl.getEntityInstanceByEntityRef(entityRef); 058 059 if(entityInstance != null) { 060 var entityAttributeName = form.getEntityAttributeName(); 061 var entityAttribute = coreControl.getEntityAttributeByName(entityInstance.getEntityType(), entityAttributeName); 062 063 if(entityAttribute != null) { 064 var partyControl = Session.getModelController(PartyControl.class); 065 var languageIsoName = form.getLanguageIsoName(); 066 var language = languageIsoName == null ? null : partyControl.getLanguageByIsoName(languageIsoName); 067 068 if(language != null) { 069 var entityClobAttribute = language == null ? coreControl.getBestEntityClobAttribute(entityAttribute, entityInstance, getPreferredLanguage()) 070 : coreControl.getEntityClobAttribute(entityAttribute, entityInstance, language); 071 072 if(entityClobAttribute != null) { 073 result.setEntityClobAttribute(coreControl.getEntityClobAttributeTransfer(getUserVisit(), entityClobAttribute, entityInstance)); 074 } else { 075 var entityTypeDetail = entityInstance.getEntityType().getLastDetail(); 076 077 addExecutionError(ExecutionErrors.UnknownEntityClobAttribute.name(), entityRef, 078 entityTypeDetail.getComponentVendor().getLastDetail().getComponentVendorName(), 079 entityTypeDetail.getEntityTypeName(), entityAttributeName, languageIsoName); 080 } 081 } else { 082 addExecutionError(ExecutionErrors.UnknownLanguageIsoName.name(), languageIsoName); 083 } 084 } else { 085 var entityTypeDetail = entityInstance.getEntityType().getLastDetail(); 086 087 addExecutionError(ExecutionErrors.UnknownEntityAttributeName.name(), entityTypeDetail.getComponentVendor().getLastDetail().getComponentVendorName(), 088 entityTypeDetail.getEntityTypeName(), entityAttributeName); 089 } 090 } else { 091 addExecutionError(ExecutionErrors.UnknownEntityRef.name(), entityRef); 092 } 093 094 return result; 095 } 096 097}