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.util.common.command; 018 019import com.echothree.util.common.message.ExecutionErrors; 020import com.echothree.util.common.message.Messages; 021import java.io.Serializable; 022 023public class ExecutionResult<R extends BaseResult> 024 implements Serializable { 025 026 final private Messages executionWarnings; 027 final private Messages executionErrors; 028 final private R result; 029 030 /** Creates a new instance of ExecutionResult */ 031 public ExecutionResult(final Messages executionWarnings, final Messages executionErrors, final R result) { 032 this.executionWarnings = executionWarnings; 033 this.executionErrors = executionErrors; 034 this.result = result; 035 } 036 037 public Messages getExecutionWarnings() { 038 return executionWarnings; 039 } 040 041 public Messages getExecutionErrors() { 042 return executionErrors; 043 } 044 045 public Boolean getHasLockErrors() { 046 return executionErrors != null && executionErrors.containsKeys(Messages.EXECUTION_ERROR, ExecutionErrors.EntityLockFailed.name(), ExecutionErrors.EntityLockStale.name()); 047 } 048 049 public Boolean getHasWarnings() { 050 return executionWarnings != null && executionWarnings.size(Messages.EXECUTION_WARNING) != 0; 051 } 052 053 public Boolean getHasErrors() { 054 return executionErrors != null && executionErrors.size(Messages.EXECUTION_ERROR) != 0; 055 } 056 057 public Boolean getHasResults() { 058 return result != null; 059 } 060 061 public R getResult() { 062 return result; 063 } 064 065 // Migration function that allows avoiding casts until R is implemented everywhere. 066 public <T extends BaseResult> T getResult(Class<T> resultClass) { 067 return resultClass.cast(result); 068 } 069 070 @Override 071 public String toString() { 072 return "{ executionWarnings = " + executionWarnings + ", executionErrors = " + 073 executionErrors + ", result = " + result + " }"; 074 } 075 076}