Class OperationResult
- java.lang.Object
-
- com.evolveum.midpoint.schema.result.OperationResult
-
- All Implemented Interfaces:
Visitable<OperationResult>
,OperationResultBuilder
,DebugDumpable
,ShortDumpable
,Serializable
,Cloneable
public class OperationResult extends Object implements Serializable, DebugDumpable, ShortDumpable, Cloneable, OperationResultBuilder, Visitable<OperationResult>
Nested Operation Result. This class provides information for better error handling in complex operations. It contains a status (success, failure, warning, ...) and an error message. It also contains a set of sub-results - results on inner operations. This object can be used by GUI to display smart (and interactive) error information. It can also be used by the client code to detect deeper problems in the invocations, retry or otherwise compensate for the errors or decide how severe the error was and it is possible to proceed.- Author:
- lazyman, Radovan Semancik
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
OperationResult.PreviewResult
-
Field Summary
Fields Modifier and Type Field Description static String
CONTEXT_IMPLEMENTATION_CLASS
static String
CONTEXT_ITEM
static String
CONTEXT_OBJECT
static String
CONTEXT_OID
static String
CONTEXT_PROGRESS
static String
CONTEXT_REASON
static String
CONTEXT_RESOURCE
static String
CONTEXT_TASK
static String
DEFAULT
static String
PARAM_LANGUAGE
static String
PARAM_NAME
static String
PARAM_OBJECT
static String
PARAM_OID
static String
PARAM_OPTIONS
static String
PARAM_PROJECTION
static String
PARAM_QUERY
static String
PARAM_TASK
static String
PARAM_TYPE
static String
RETURN_BACKGROUND_TASK_OID
static String
RETURN_COMMENT
static String
RETURN_COUNT
-
Constructor Summary
Constructors Constructor Description OperationResult(String operation)
OperationResult(String operation, OperationResultStatus status, LocalizableMessage userFriendlyMessage)
OperationResult(String operation, OperationResultStatus status, String message)
OperationResult(String operation, Map<String,Collection<String>> params, OperationResultStatus status, long token, String messageCode, String message, LocalizableMessage userFriendlyMessage, Throwable cause, List<OperationResult> subresults)
OperationResult(String operation, Map<String,Collection<String>> params, Map<String,Collection<String>> context, Map<String,Collection<String>> returns, OperationResultStatus status, long token, String messageCode, String message, LocalizableMessage userFriendlyMessage, Throwable cause, List<OperationResult> subresults)
-
Method Summary
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.evolveum.midpoint.util.DebugDumpable
debugDump, debugDumpLazily, debugDumpLazily
-
Methods inherited from interface com.evolveum.midpoint.util.ShortDumpable
shortDump, shortDumpLazily
-
-
-
-
Field Detail
-
CONTEXT_IMPLEMENTATION_CLASS
public static final String CONTEXT_IMPLEMENTATION_CLASS
- See Also:
- Constant Field Values
-
CONTEXT_PROGRESS
public static final String CONTEXT_PROGRESS
- See Also:
- Constant Field Values
-
CONTEXT_OID
public static final String CONTEXT_OID
- See Also:
- Constant Field Values
-
CONTEXT_OBJECT
public static final String CONTEXT_OBJECT
- See Also:
- Constant Field Values
-
CONTEXT_ITEM
public static final String CONTEXT_ITEM
- See Also:
- Constant Field Values
-
CONTEXT_TASK
public static final String CONTEXT_TASK
- See Also:
- Constant Field Values
-
CONTEXT_RESOURCE
public static final String CONTEXT_RESOURCE
- See Also:
- Constant Field Values
-
CONTEXT_REASON
public static final String CONTEXT_REASON
- See Also:
- Constant Field Values
-
PARAM_OID
public static final String PARAM_OID
- See Also:
- Constant Field Values
-
PARAM_NAME
public static final String PARAM_NAME
- See Also:
- Constant Field Values
-
PARAM_TYPE
public static final String PARAM_TYPE
- See Also:
- Constant Field Values
-
PARAM_OPTIONS
public static final String PARAM_OPTIONS
- See Also:
- Constant Field Values
-
PARAM_TASK
public static final String PARAM_TASK
- See Also:
- Constant Field Values
-
PARAM_OBJECT
public static final String PARAM_OBJECT
- See Also:
- Constant Field Values
-
PARAM_QUERY
public static final String PARAM_QUERY
- See Also:
- Constant Field Values
-
PARAM_PROJECTION
public static final String PARAM_PROJECTION
- See Also:
- Constant Field Values
-
PARAM_LANGUAGE
public static final String PARAM_LANGUAGE
- See Also:
- Constant Field Values
-
RETURN_COUNT
public static final String RETURN_COUNT
- See Also:
- Constant Field Values
-
RETURN_BACKGROUND_TASK_OID
public static final String RETURN_BACKGROUND_TASK_OID
- See Also:
- Constant Field Values
-
RETURN_COMMENT
public static final String RETURN_COMMENT
- See Also:
- Constant Field Values
-
DEFAULT
public static final String DEFAULT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
OperationResult
public OperationResult(String operation)
-
OperationResult
public OperationResult(String operation, OperationResultStatus status, LocalizableMessage userFriendlyMessage)
-
OperationResult
public OperationResult(String operation, OperationResultStatus status, String message)
-
OperationResult
public OperationResult(String operation, Map<String,Collection<String>> params, OperationResultStatus status, long token, String messageCode, String message, LocalizableMessage userFriendlyMessage, Throwable cause, List<OperationResult> subresults)
-
OperationResult
public OperationResult(String operation, Map<String,Collection<String>> params, Map<String,Collection<String>> context, Map<String,Collection<String>> returns, OperationResultStatus status, long token, String messageCode, String message, LocalizableMessage userFriendlyMessage, Throwable cause, List<OperationResult> subresults)
-
-
Method Detail
-
keepRootOnly
public static OperationResult keepRootOnly(OperationResult result)
-
subresult
public OperationResultBuilder subresult(String operation)
-
createFor
public static OperationResultBuilder createFor(String operation)
-
build
public OperationResult build()
- Specified by:
build
in interfaceOperationResultBuilder
-
createSubresult
public OperationResult createSubresult(String operation)
-
createMinorSubresult
public OperationResult createMinorSubresult(String operation)
-
recordEnd
public void recordEnd()
-
getAsynchronousOperationReference
public String getAsynchronousOperationReference()
Reference to an asynchronous operation that can be used to retrieve the status of the running operation. This may be a task identifier, identifier of a ticket in ITSM system or anything else. The exact format of this reference depends on the operation which is being executed.
-
setAsynchronousOperationReference
public void setAsynchronousOperationReference(String asynchronousOperationReference)
-
findAsynchronousOperationReference
public String findAsynchronousOperationReference()
This method partially duplicates functionality of computeStatus. However, computeStatus currently does not propagate taskOid from tasks switched to background, because switchToBackground sets its result to SUCCESS (not IN_PROGRESS) because of some historical reasons. So, until this is fixed somehow, this is a bit of hack to fetch asynchronous operation reference even in such cases.
-
isTaskOid
public static boolean isTaskOid(String ref)
-
getOperation
public String getOperation()
Contains operation name. Operation name must be defined asString
constant in module interface with description and possible parameters. It can be used for further processing. It will be used as key for translation in admin-gui.- Returns:
- always return non null, non empty string
-
getCount
public int getCount()
-
setCount
public void setCount(int count)
-
incrementCount
public void incrementCount()
-
getHiddenRecordsCount
public int getHiddenRecordsCount()
-
setHiddenRecordsCount
public void setHiddenRecordsCount(int hiddenRecordsCount)
-
representsHiddenRecords
public boolean representsHiddenRecords()
-
isSummarizeErrors
public boolean isSummarizeErrors()
-
setSummarizeErrors
public void setSummarizeErrors(boolean summarizeErrors)
-
isSummarizePartialErrors
public boolean isSummarizePartialErrors()
-
setSummarizePartialErrors
public void setSummarizePartialErrors(boolean summarizePartialErrors)
-
isSummarizeSuccesses
public boolean isSummarizeSuccesses()
-
setSummarizeSuccesses
public void setSummarizeSuccesses(boolean summarizeSuccesses)
-
isEmpty
public boolean isEmpty()
-
getSubresults
@NotNull public @NotNull List<OperationResult> getSubresults()
Method returns list of operation subresults @{linkOperationResult
.- Returns:
- never returns null
-
getLastSubresult
public OperationResult getLastSubresult()
- Returns:
- last subresult, or null if there are no subresults.
-
removeLastSubresult
public void removeLastSubresult()
-
getLastSubresultStatus
public OperationResultStatus getLastSubresultStatus()
- Returns:
- last subresult status, or null if there are no subresults.
-
addSubresult
public void addSubresult(OperationResult subresult)
-
findSubresult
public OperationResult findSubresult(String operation)
-
findSubresults
public List<OperationResult> findSubresults(String operation)
-
getStatus
public OperationResultStatus getStatus()
Contains operation status as defined inOperationResultStatus
- Returns:
- never returns null
-
setStatus
public void setStatus(OperationResultStatus status)
-
isSuccess
public boolean isSuccess()
Returns true if the result is success. This returns true if the result is absolute success. Presence of partial failures or warnings fail this test.- Returns:
- true if the result is success.
-
isWarning
public boolean isWarning()
-
isAcceptable
public boolean isAcceptable()
Returns true if the result is acceptable for further processing. In other words: if there were no fatal errors. Warnings and partial errors are acceptable. Yet, this test also fails if the operation state is not known.- Returns:
- true if the result is acceptable for further processing.
-
isUnknown
public boolean isUnknown()
-
isInProgress
public boolean isInProgress()
-
isError
public boolean isError()
-
isFatalError
public boolean isFatalError()
-
isPartialError
public boolean isPartialError()
-
isHandledError
public boolean isHandledError()
-
isNotApplicable
public boolean isNotApplicable()
-
setErrorsHandled
public void setErrorsHandled()
Set all error status in this result and all subresults as handled.
-
computeStatus
public void computeStatus(String errorMessage)
Computes operation result status based on subtask status and sets an error message if the status is FATAL_ERROR.- Parameters:
errorMessage
- error message
-
computeStatus
public void computeStatus()
Computes operation result status based on subtask status.
-
computeStatus
public void computeStatus(boolean skipFinish)
-
computeStatusComposite
public void computeStatusComposite()
Used when the result contains several composite sub-result that are of equivalent meaning. If all of them fail the result will be fatal error as well. If only some of them fail the result will be partial error. Handled error is considered a success.
-
addTrace
public void addTrace(TraceType trace)
-
tracingProfile
public OperationResultBuilder tracingProfile(CompiledTracingProfile profile)
- Specified by:
tracingProfile
in interfaceOperationResultBuilder
-
getFirstTrace
public <T> T getFirstTrace(Class<T> traceClass)
-
addReturnComment
public void addReturnComment(String comment)
-
isTracing
public boolean isTracing(Class<? extends TraceType> traceClass, TracingLevelType level)
-
getTracingLevel
@NotNull public @NotNull TracingLevelType getTracingLevel(Class<? extends TraceType> traceClass)
-
clearTracingProfile
public void clearTracingProfile()
-
accept
public void accept(Visitor<OperationResult> visitor)
- Specified by:
accept
in interfaceVisitable<OperationResult>
-
getResultStream
public Stream<OperationResult> getResultStream()
-
computePreview
public OperationResult.PreviewResult computePreview()
-
getComputeStatus
public OperationResultStatus getComputeStatus()
-
computeStatusIfUnknown
public void computeStatusIfUnknown()
-
recomputeStatus
public void recomputeStatus()
-
recomputeStatus
public void recomputeStatus(String message)
-
recordSuccessIfUnknown
public void recordSuccessIfUnknown()
-
recordNotApplicableIfUnknown
public void recordNotApplicableIfUnknown()
-
recordNotApplicable
public void recordNotApplicable()
-
isMinor
public boolean isMinor()
-
getParams
@NotNull public @NotNull Map<String,Collection<String>> getParams()
Method returnsMap
with operation parameters. Parameters keys are described in module interface for every operation.
-
getParam
public Collection<String> getParam(String name)
-
addQualifier
public OperationResult addQualifier(String value)
- Specified by:
addQualifier
in interfaceOperationResultBuilder
-
addParam
public OperationResult addParam(String name, String value)
- Specified by:
addParam
in interfaceOperationResultBuilder
-
addParam
public OperationResult addParam(String name, PrismObject<? extends ObjectType> value)
- Specified by:
addParam
in interfaceOperationResultBuilder
-
addParam
public OperationResult addParam(String name, ObjectType value)
- Specified by:
addParam
in interfaceOperationResultBuilder
-
addParam
public OperationResult addParam(String name, boolean value)
- Specified by:
addParam
in interfaceOperationResultBuilder
-
addParam
public OperationResult addParam(String name, long value)
- Specified by:
addParam
in interfaceOperationResultBuilder
-
addParam
public OperationResult addParam(String name, int value)
- Specified by:
addParam
in interfaceOperationResultBuilder
-
addParam
public OperationResult addParam(String name, Class<?> value)
- Specified by:
addParam
in interfaceOperationResultBuilder
-
addParam
public OperationResult addParam(String name, QName value)
- Specified by:
addParam
in interfaceOperationResultBuilder
-
addParam
public OperationResult addParam(String name, PolyString value)
- Specified by:
addParam
in interfaceOperationResultBuilder
-
addParam
public OperationResult addParam(String name, ObjectQuery value)
- Specified by:
addParam
in interfaceOperationResultBuilder
-
addParam
public OperationResult addParam(String name, ObjectDelta<?> value)
- Specified by:
addParam
in interfaceOperationResultBuilder
-
addParam
public OperationResult addParam(String name, String... values)
- Specified by:
addParam
in interfaceOperationResultBuilder
-
addArbitraryObjectAsParam
public OperationResult addArbitraryObjectAsParam(String paramName, Object paramValue)
- Specified by:
addArbitraryObjectAsParam
in interfaceOperationResultBuilder
-
addArbitraryObjectCollectionAsParam
public OperationResult addArbitraryObjectCollectionAsParam(String name, Collection<?> value)
- Specified by:
addArbitraryObjectCollectionAsParam
in interfaceOperationResultBuilder
-
getContext
public Map<String,Collection<String>> getContext()
-
addContext
public OperationResult addContext(String name, String value)
- Specified by:
addContext
in interfaceOperationResultBuilder
-
addContext
public OperationResult addContext(String name, PrismObject<? extends ObjectType> value)
- Specified by:
addContext
in interfaceOperationResultBuilder
-
addContext
public OperationResult addContext(String name, ObjectType value)
- Specified by:
addContext
in interfaceOperationResultBuilder
-
addContext
public OperationResult addContext(String name, boolean value)
- Specified by:
addContext
in interfaceOperationResultBuilder
-
addContext
public OperationResult addContext(String name, long value)
- Specified by:
addContext
in interfaceOperationResultBuilder
-
addContext
public OperationResult addContext(String name, int value)
- Specified by:
addContext
in interfaceOperationResultBuilder
-
addContext
public OperationResult addContext(String name, Class<?> value)
- Specified by:
addContext
in interfaceOperationResultBuilder
-
addContext
public OperationResult addContext(String name, QName value)
- Specified by:
addContext
in interfaceOperationResultBuilder
-
addContext
public OperationResult addContext(String name, PolyString value)
- Specified by:
addContext
in interfaceOperationResultBuilder
-
addContext
public OperationResult addContext(String name, ObjectQuery value)
- Specified by:
addContext
in interfaceOperationResultBuilder
-
addContext
public OperationResult addContext(String name, ObjectDelta<?> value)
- Specified by:
addContext
in interfaceOperationResultBuilder
-
addContext
public OperationResult addContext(String name, String... values)
- Specified by:
addContext
in interfaceOperationResultBuilder
-
addArbitraryObjectAsContext
public OperationResult addArbitraryObjectAsContext(String name, Object value)
- Specified by:
addArbitraryObjectAsContext
in interfaceOperationResultBuilder
-
addArbitraryObjectCollectionAsContext
public OperationResult addArbitraryObjectCollectionAsContext(String paramName, Collection<?> paramValue)
- Specified by:
addArbitraryObjectCollectionAsContext
in interfaceOperationResultBuilder
-
getReturns
@NotNull public @NotNull Map<String,Collection<String>> getReturns()
-
getReturn
public Collection<String> getReturn(String name)
-
addReturn
public void addReturn(String name, PrismObject<? extends ObjectType> value)
-
addReturn
public void addReturn(String name, ObjectType value)
-
addReturn
public void addReturn(String name, boolean value)
-
addReturn
public void addReturn(String name, long value)
-
addReturn
public void addReturn(String name, int value)
-
addReturn
public void addReturn(String name, PolyString value)
-
addReturn
public void addReturn(String name, ObjectQuery value)
-
addReturn
public void addReturn(String name, ObjectDelta<?> value)
-
addArbitraryObjectCollectionAsReturn
public void addArbitraryObjectCollectionAsReturn(String paramName, Collection<?> paramValue)
-
getToken
public long getToken()
- Returns:
- Contains random long number, for better searching in logs.
-
getMessageCode
public String getMessageCode()
Contains message code based on module error catalog.- Returns:
- Can return null.
-
getMessage
public String getMessage()
- Returns:
- Method returns operation result message. Message is required. It will be key for translation in admin-gui.
-
setMessage
public void setMessage(String message)
-
getUserFriendlyMessage
public LocalizableMessage getUserFriendlyMessage()
-
setUserFriendlyMessage
public void setUserFriendlyMessage(LocalizableMessage userFriendlyMessage)
-
getCause
public Throwable getCause()
- Returns:
- Method returns operation result exception. Not required, can be null.
-
recordSuccess
public void recordSuccess()
-
recordInProgress
public void recordInProgress()
-
recordUnknown
public void recordUnknown()
-
recordFatalError
public void recordFatalError(Throwable cause)
-
recordFatalErrorNotFinish
public void recordFatalErrorNotFinish(Throwable cause)
-
muteError
public void muteError()
If the operation is an error then it will switch the status to EXPECTED_ERROR. This is used if the error is expected and properly handled.
-
muteLastSubresultError
public void muteLastSubresultError()
-
deleteLastSubresultIfError
public void deleteLastSubresultIfError()
-
recordPartialError
public void recordPartialError(Throwable cause)
-
recordWarning
public void recordWarning(Throwable cause)
-
recordStatus
public void recordStatus(OperationResultStatus status, Throwable cause)
-
recordHandledError
public void recordHandledError(String message)
-
recordHandledError
public void recordHandledError(Throwable cause)
-
recordStatus
public void recordStatus(OperationResultStatus status, String message, Throwable cause)
-
recordStatusNotFinish
public void recordStatusNotFinish(OperationResultStatus status, String message, Throwable cause)
-
recordFatalError
public void recordFatalError(String message)
-
recordPartialError
public void recordPartialError(String message)
-
recordWarning
public void recordWarning(String message)
-
record
public void record(CommonException exception)
Records result from a common exception type. This automatically determines status and also sets appropriate message.- Parameters:
exception
- common exception
-
recordStatus
public void recordStatus(OperationResultStatus status, String message)
-
hasUnknownStatus
public boolean hasUnknownStatus()
Returns true if result status is UNKNOWN or any of the subresult status is unknown (recursive). May come handy in tests to check if all the operations fill out the status as they should.
-
appendDetail
public void appendDetail(String detailLine)
-
createOperationResult
@Contract("null -> null; !null -> !null") public static OperationResult createOperationResult(OperationResultType result)
-
createOperationResultType
public OperationResultType createOperationResultType()
-
createOperationResultType
public OperationResultType createOperationResultType(Function<LocalizableMessage,String> resolveKeys)
-
summarize
public void summarize()
-
summarize
public void summarize(boolean alsoSubresults)
-
cleanupResultDeeply
public void cleanupResultDeeply()
-
cleanupResult
public void cleanupResult()
Removes all the successful minor results. Also checks if the result is roughly consistent and complete. (e.g. does not have unknown operation status, etc.)
-
cleanupResult
public void cleanupResult(Throwable e)
Removes all the successful minor results. Also checks if the result is roughly consistent and complete. (e.g. does not have unknown operation status, etc.) The argument "e" is for easier use of the cleanup in the exceptions handlers. The original exception is passed to the IAE that this method produces for easier debugging.
-
isLesserThan
public static boolean isLesserThan(OperationResultImportanceType x, @NotNull @NotNull OperationResultImportanceType y)
- Returns:
- true if x < y
-
debugDump
public String debugDump(int indent)
- Specified by:
debugDump
in interfaceDebugDumpable
-
dump
public String dump(boolean withStack)
-
shortDump
public void shortDump(StringBuilder sb)
Description copied from interface:ShortDumpable
Show the content of the object intended for diagnostics. This method is supposed to append a compact, human-readable output in a single line. Unlike toString() method, there is no requirement to identify the actual class or type of the object. It is assumed that the class/type will be obvious from the context in which the output is used.- Specified by:
shortDump
in interfaceShortDumpable
- Parameters:
sb
- StringBuilder to which to a compact one-line content of the object intended for diagnostics by system administrator should be appended.
-
setBackgroundTaskOid
public void setBackgroundTaskOid(String oid)
-
setCaseOid
public void setCaseOid(String oid)
-
getBackgroundTaskOid
@Deprecated public String getBackgroundTaskOid()
Deprecated.
-
setMinor
public OperationResultBuilder setMinor()
- Specified by:
setMinor
in interfaceOperationResultBuilder
-
getImportance
public OperationResultImportanceType getImportance()
-
setImportance
public OperationResult setImportance(OperationResultImportanceType value)
- Specified by:
setImportance
in interfaceOperationResultBuilder
-
recordThrowableIfNeeded
public void recordThrowableIfNeeded(Throwable t)
-
createSubResultOrNewResult
public static OperationResult createSubResultOrNewResult(OperationResult parentResult, String operation)
-
clone
public OperationResult clone()
-
clone
public OperationResult clone(Integer maxDepth, boolean full)
-
applyOperationResultHandlingStrategy
public static void applyOperationResultHandlingStrategy(@NotNull @NotNull List<OperationResultHandlingStrategyType> configuredStrategies, Integer stripThresholdDeprecated)
-
setThreadLocalHandlingStrategy
public static void setThreadLocalHandlingStrategy(@Nullable @Nullable String strategyName)
-
getStart
public Long getStart()
-
setStart
public void setStart(Long start)
-
getEnd
public Long getEnd()
-
setEnd
public void setEnd(Long end)
-
getMicroseconds
public Long getMicroseconds()
-
setMicroseconds
public void setMicroseconds(Long microseconds)
-
getInvocationId
public Long getInvocationId()
-
setInvocationId
public void setInvocationId(Long invocationId)
-
isTraced
public boolean isTraced()
-
getTracingProfile
public CompiledTracingProfile getTracingProfile()
-
getCallerReason
public String getCallerReason()
-
setCallerReason
public void setCallerReason(String callerReason)
-
getLogSegments
public List<LogSegmentType> getLogSegments()
-
getExtractedDictionary
public TraceDictionaryType getExtractedDictionary()
-
setExtractedDictionary
public void setExtractedDictionary(TraceDictionaryType extractedDictionary)
-
-