|
| 1 | +/* |
| 2 | + * Copyright (c) 2024, FusionAuth, All Rights Reserved |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, |
| 11 | + * software distributed under the License is distributed on an |
| 12 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
| 13 | + * either express or implied. See the License for the specific |
| 14 | + * language governing permissions and limitations under the License. |
| 15 | + */ |
| 16 | +package io.fusionauth.domain; |
| 17 | + |
| 18 | +import java.time.ZonedDateTime; |
| 19 | +import java.util.ArrayList; |
| 20 | +import java.util.LinkedHashMap; |
| 21 | +import java.util.List; |
| 22 | +import java.util.Map; |
| 23 | +import java.util.Objects; |
| 24 | +import java.util.UUID; |
| 25 | + |
| 26 | +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
| 27 | +import com.inversoft.json.ToString; |
| 28 | +import io.fusionauth.domain.event.EventRequest; |
| 29 | +import io.fusionauth.domain.event.EventType; |
| 30 | + |
| 31 | +/** |
| 32 | + * An instance of a webhook event log. |
| 33 | + * |
| 34 | + * @author Spencer Witt |
| 35 | + */ |
| 36 | + |
| 37 | +@JsonIgnoreProperties(value = {"successfulAttempts", "failedAttempts"}, allowGetters = true) |
| 38 | +public class WebhookEventLog implements Buildable<WebhookEventLog> { |
| 39 | + // Do not include the webhook event log Id for individual attempts when returning as part of the full event |
| 40 | + @JsonIgnoreProperties("webhookEventLogId") |
| 41 | + public List<WebhookAttemptLog> attempts = new ArrayList<>(); |
| 42 | + |
| 43 | + public Map<String, Object> data = new LinkedHashMap<>(); |
| 44 | + |
| 45 | + public EventRequest event; |
| 46 | + |
| 47 | + public WebhookEventResult eventResult = WebhookEventResult.Running; |
| 48 | + |
| 49 | + public EventType eventType; |
| 50 | + |
| 51 | + public UUID id; |
| 52 | + |
| 53 | + public ZonedDateTime insertInstant; |
| 54 | + |
| 55 | + public ZonedDateTime lastAttemptInstant; |
| 56 | + |
| 57 | + public ZonedDateTime lastUpdateInstant; |
| 58 | + |
| 59 | + public UUID linkedObjectId; |
| 60 | + |
| 61 | + public Long sequence; |
| 62 | + |
| 63 | + @Override |
| 64 | + public boolean equals(Object o) { |
| 65 | + if (this == o) { |
| 66 | + return true; |
| 67 | + } |
| 68 | + if (o == null || getClass() != o.getClass()) { |
| 69 | + return false; |
| 70 | + } |
| 71 | + WebhookEventLog that = (WebhookEventLog) o; |
| 72 | + return Objects.equals(attempts, that.attempts) && |
| 73 | + Objects.equals(data, that.data) && |
| 74 | + Objects.equals(event, that.event) && |
| 75 | + eventResult == that.eventResult && |
| 76 | + eventType == that.eventType && |
| 77 | + Objects.equals(id, that.id) && |
| 78 | + Objects.equals(insertInstant, that.insertInstant) && |
| 79 | + Objects.equals(lastAttemptInstant, that.lastAttemptInstant) && |
| 80 | + Objects.equals(lastUpdateInstant, that.lastUpdateInstant) && |
| 81 | + Objects.equals(linkedObjectId, that.linkedObjectId) && |
| 82 | + Objects.equals(sequence, that.sequence); |
| 83 | + } |
| 84 | + |
| 85 | + public Integer getFailedAttempts() { |
| 86 | + return Math.toIntExact(attempts.stream() |
| 87 | + .filter(attempt -> attempt.getAttemptResult().equals(WebhookAttemptResult.Failure)) |
| 88 | + .count()); |
| 89 | + } |
| 90 | + |
| 91 | + public Integer getSuccessfulAttempts() { |
| 92 | + return Math.toIntExact(attempts.stream() |
| 93 | + .filter(attempt -> attempt.getAttemptResult().equals(WebhookAttemptResult.Success)) |
| 94 | + .count()); |
| 95 | + } |
| 96 | + |
| 97 | + @Override |
| 98 | + public int hashCode() { |
| 99 | + return Objects.hash(attempts, data, event, eventResult, eventType, id, insertInstant, lastAttemptInstant, lastUpdateInstant, linkedObjectId, sequence); |
| 100 | + } |
| 101 | + |
| 102 | + public String toString() { |
| 103 | + return ToString.toString(this); |
| 104 | + } |
| 105 | +} |
0 commit comments