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.party.server.command; 018 019import com.echothree.control.user.party.common.form.CreatePartyApplicationEditorUseForm; 020import com.echothree.control.user.party.common.result.PartyResultFactory; 021import com.echothree.model.control.core.server.logic.ApplicationLogic; 022import com.echothree.model.control.core.server.logic.EditorLogic; 023import com.echothree.model.control.party.common.PartyTypes; 024import com.echothree.model.control.party.server.control.PartyApplicationEditorUseControl; 025import com.echothree.model.control.party.server.logic.PartyLogic; 026import com.echothree.model.control.security.common.SecurityRoleGroups; 027import com.echothree.model.control.security.common.SecurityRoles; 028import com.echothree.model.data.party.server.entity.PartyApplicationEditorUse; 029import com.echothree.model.data.user.common.pk.UserVisitPK; 030import com.echothree.util.common.command.BaseResult; 031import com.echothree.util.common.message.ExecutionErrors; 032import com.echothree.util.common.validation.FieldDefinition; 033import com.echothree.util.common.validation.FieldType; 034import com.echothree.util.server.control.BaseSimpleCommand; 035import com.echothree.util.server.control.CommandSecurityDefinition; 036import com.echothree.util.server.control.PartyTypeDefinition; 037import com.echothree.util.server.control.SecurityRoleDefinition; 038import java.util.List; 039import javax.enterprise.context.Dependent; 040import javax.inject.Inject; 041 042@Dependent 043public class CreatePartyApplicationEditorUseCommand 044 extends BaseSimpleCommand<CreatePartyApplicationEditorUseForm> { 045 046 private final static CommandSecurityDefinition COMMAND_SECURITY_DEFINITION; 047 private final static List<FieldDefinition> FORM_FIELD_DEFINITIONS; 048 049 static { 050 COMMAND_SECURITY_DEFINITION = new CommandSecurityDefinition(List.of( 051 new PartyTypeDefinition(PartyTypes.UTILITY.name(), null), 052 new PartyTypeDefinition(PartyTypes.EMPLOYEE.name(), List.of( 053 new SecurityRoleDefinition(SecurityRoleGroups.PartyApplicationEditorUse.name(), SecurityRoles.Create.name()) 054 )) 055 )); 056 057 FORM_FIELD_DEFINITIONS = List.of( 058 new FieldDefinition("PartyName", FieldType.ENTITY_NAME, true, null, null), 059 new FieldDefinition("ApplicationName", FieldType.ENTITY_NAME, true, null, null), 060 new FieldDefinition("ApplicationEditorUseName", FieldType.ENTITY_NAME, true, null, null), 061 new FieldDefinition("EditorName", FieldType.ENTITY_NAME, false, null, null), 062 new FieldDefinition("PreferredHeight", FieldType.UNSIGNED_INTEGER, false, null, null), 063 new FieldDefinition("PreferredWidth", FieldType.UNSIGNED_INTEGER, false, null, null) 064 ); 065 } 066 067 @Inject 068 PartyApplicationEditorUseControl partyApplicationEditorUseControl; 069 070 @Inject 071 ApplicationLogic applicationLogic; 072 073 @Inject 074 EditorLogic editorLogic; 075 076 @Inject 077 PartyLogic partyLogic; 078 079 080 /** Creates a new instance of CreatePartyApplicationEditorUseCommand */ 081 public CreatePartyApplicationEditorUseCommand() { 082 super(COMMAND_SECURITY_DEFINITION, FORM_FIELD_DEFINITIONS, false); 083 } 084 085 @Override 086 protected BaseResult execute() { 087 var result = PartyResultFactory.getCreatePartyApplicationEditorUseResult(); 088 PartyApplicationEditorUse partyApplicationEditorUse = null; 089 var partyName = form.getPartyName(); 090 var party = partyLogic.getPartyByName(this, partyName); 091 092 if(!hasExecutionErrors()) { 093 var applicationName = form.getApplicationName(); 094 var application = applicationLogic.getApplicationByName(this, applicationName); 095 096 if(!hasExecutionErrors()) { 097 var applicationEditorUseName = form.getApplicationEditorUseName(); 098 var applicationEditorUse = applicationLogic.getApplicationEditorUseByName(this, application, applicationEditorUseName); 099 100 if(!hasExecutionErrors()) { 101 partyApplicationEditorUse = partyApplicationEditorUseControl.getPartyApplicationEditorUse(party, applicationEditorUse); 102 103 if(partyApplicationEditorUse == null) { 104 var editorName = form.getEditorName(); 105 var editor = editorName == null ? null : editorLogic.getEditorByName(this, editorName); 106 107 if(!hasExecutionErrors()) { 108 var applicationEditor = editor == null ? null : applicationLogic.getApplicationEditor(this, application, editor); 109 110 if(!hasExecutionErrors()) { 111 var strPreferredHeight = form.getPreferredHeight(); 112 var preferredHeight = strPreferredHeight == null ? null : Integer.valueOf(strPreferredHeight); 113 var strPreferredWidth = form.getPreferredWidth(); 114 var preferredWidth = strPreferredWidth == null ? null : Integer.valueOf(strPreferredWidth); 115 116 partyApplicationEditorUse = partyApplicationEditorUseControl.createPartyApplicationEditorUse(party, applicationEditorUse, applicationEditor, preferredHeight, preferredWidth, 117 getPartyPK()); 118 } 119 } 120 } else { 121 addExecutionError(ExecutionErrors.DuplicatePartyApplicationEditorUse.name(), partyName, applicationName, applicationEditorUseName); 122 } 123 } 124 } 125 } 126 127 if(partyApplicationEditorUse != null) { 128 result.setEntityRef(partyApplicationEditorUse.getPrimaryKey().getEntityRef()); 129 result.setPartyName(partyApplicationEditorUse.getLastDetail().getParty().getLastDetail().getPartyName()); 130 result.setApplicationName(partyApplicationEditorUse.getLastDetail().getApplicationEditorUse().getLastDetail().getApplication().getLastDetail().getApplicationName()); 131 result.setApplicationEditorUseName(partyApplicationEditorUse.getLastDetail().getApplicationEditorUse().getLastDetail().getApplicationEditorUseName()); 132 } 133 134 return result; 135 } 136 137}