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 java.util.List; 030import javax.enterprise.context.Dependent; 031import javax.inject.Inject; 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 @Inject 048 EntityInstanceControl entityInstanceControl; 049 050 @Inject 051 PartyControl partyControl; 052 053 054 /** Creates a new instance of GetEntityClobAttributeCommand */ 055 public GetEntityClobAttributeCommand() { 056 super(null, FORM_FIELD_DEFINITIONS, false); 057 } 058 059 @Override 060 protected BaseResult execute() { 061 var result = CoreResultFactory.getGetEntityClobAttributeResult(); 062 var entityRef = form.getEntityRef(); 063 var entityInstance = entityInstanceControl.getEntityInstanceByEntityRef(entityRef); 064 065 if(entityInstance != null) { 066 var entityAttributeName = form.getEntityAttributeName(); 067 var entityAttribute = coreControl.getEntityAttributeByName(entityInstance.getEntityType(), entityAttributeName); 068 069 if(entityAttribute != null) { 070 var languageIsoName = form.getLanguageIsoName(); 071 var language = languageIsoName == null ? null : partyControl.getLanguageByIsoName(languageIsoName); 072 073 if(language != null) { 074 var entityClobAttribute = language == null ? coreControl.getBestEntityClobAttribute(entityAttribute, entityInstance, getPreferredLanguage()) 075 : coreControl.getEntityClobAttribute(entityAttribute, entityInstance, language); 076 077 if(entityClobAttribute != null) { 078 result.setEntityClobAttribute(coreControl.getEntityClobAttributeTransfer(getUserVisit(), entityClobAttribute, entityInstance)); 079 } else { 080 var entityTypeDetail = entityInstance.getEntityType().getLastDetail(); 081 082 addExecutionError(ExecutionErrors.UnknownEntityClobAttribute.name(), entityRef, 083 entityTypeDetail.getComponentVendor().getLastDetail().getComponentVendorName(), 084 entityTypeDetail.getEntityTypeName(), entityAttributeName, languageIsoName); 085 } 086 } else { 087 addExecutionError(ExecutionErrors.UnknownLanguageIsoName.name(), languageIsoName); 088 } 089 } else { 090 var entityTypeDetail = entityInstance.getEntityType().getLastDetail(); 091 092 addExecutionError(ExecutionErrors.UnknownEntityAttributeName.name(), entityTypeDetail.getComponentVendor().getLastDetail().getComponentVendorName(), 093 entityTypeDetail.getEntityTypeName(), entityAttributeName); 094 } 095 } else { 096 addExecutionError(ExecutionErrors.UnknownEntityRef.name(), entityRef); 097 } 098 099 return result; 100 } 101 102}