001package com.identityworksllc.iiq.common; 002 003import com.fasterxml.jackson.annotation.JsonAutoDetect; 004import com.fasterxml.jackson.annotation.JsonIgnore; 005import com.identityworksllc.iiq.common.vo.Outcome; 006import com.identityworksllc.iiq.common.vo.OutcomeType; 007import sailpoint.api.SailPointContext; 008import sailpoint.object.TaskResult; 009import sailpoint.tools.GeneralException; 010import sailpoint.tools.Message; 011import sailpoint.tools.Util; 012import sailpoint.tools.xml.AbstractXmlObject; 013 014import java.util.StringJoiner; 015 016/** 017 * A data class for returning the outcome of the aggregation event 018 */ 019@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY) 020public class AggregationOutcome extends Outcome { 021 /** 022 * An optional error message (can be null); 023 */ 024 private String errorMessage; 025 026 /** 027 * Aggregator TaskResults outputs 028 */ 029 @JsonIgnore 030 private String serializedTaskResult; 031 032 /** 033 * Default construct, to be used by Jackson to determine field defaults 034 */ 035 @Deprecated 036 public AggregationOutcome() { 037 this(null, null); 038 } 039 040 /** 041 * @param appl The application 042 * @param ni The native Identity 043 */ 044 public AggregationOutcome(String appl, String ni) { 045 this(appl, ni, null, null); 046 } 047 048 /** 049 * @param appl The application 050 * @param ni The native Identity 051 * @param o The aggregation outcome 052 */ 053 public AggregationOutcome(String appl, String ni, OutcomeType o) { 054 this(appl, ni, o, null); 055 } 056 057 /** 058 * @param appl The application 059 * @param ni The native Identity 060 * @param o The aggregation outcome 061 * @param errorMessage The error message, if any 062 */ 063 public AggregationOutcome(String appl, String ni, OutcomeType o, String errorMessage) { 064 setApplicationName(appl); 065 setNativeIdentity(ni); 066 if (o != null) { 067 setStatus(o); 068 } 069 if (Util.isNotNullOrEmpty(errorMessage)) { 070 addMessage(Message.error(errorMessage)); 071 this.errorMessage = errorMessage; 072 } 073 } 074 075 /** 076 * @return The error message 077 */ 078 public String getErrorMessage() { 079 return errorMessage; 080 } 081 082 /** 083 * Gets the serialized TaskResult object 084 * @return The serialized TaskResult XML 085 */ 086 @JsonIgnore 087 public String getSerializedTaskResult() { 088 return serializedTaskResult; 089 } 090 091 /** 092 * Gets the aggregation outputs, if any 093 * @param context The IIQ contxt 094 * @return the aggregator's TaskResult object, possibly null 095 */ 096 @JsonIgnore 097 public TaskResult getTaskResult(SailPointContext context) throws GeneralException { 098 if (Util.isNullOrEmpty(serializedTaskResult)) { 099 return null; 100 } 101 return (TaskResult) AbstractXmlObject.parseXml(context, this.serializedTaskResult); 102 } 103 104 /** 105 * @param taskResult The outputs from the aggregation job 106 */ 107 public void setTaskResult(TaskResult taskResult) throws GeneralException { 108 this.serializedTaskResult = taskResult.toXml(); 109 } 110 111 @Override 112 public String toString() { 113 StringJoiner joiner = new StringJoiner(", ", AggregationOutcome.class.getSimpleName() + "[", "]"); 114 if ((errorMessage) != null) { 115 joiner.add("errorMessage='" + errorMessage + "'"); 116 } 117 if ((serializedTaskResult) != null) { 118 joiner.add("serializedTaskResult='" + serializedTaskResult + "'"); 119 } 120 joiner.add(super.toString()); 121 return joiner.toString(); 122 } 123}