SHA256
85 lines
3.9 KiB
Java
85 lines
3.9 KiB
Java
package shine.db.entities;
|
|
|
|
public class DmDeliveryStateEntry {
|
|
public static final int ACCEPTED = 0;
|
|
public static final int DELIVERED = 1;
|
|
public static final int FAILED = 3;
|
|
|
|
// Совместимость со строками БД, созданными ранней экспериментальной миграцией.
|
|
public static final int PENDING_NONE = ACCEPTED;
|
|
public static final int DELIVERED_ONE = DELIVERED;
|
|
public static final int DELIVERED_ALL = 2;
|
|
public static final int FAILED_FINAL = FAILED;
|
|
|
|
private String outgoingMessageKey;
|
|
private String eventId;
|
|
private String baseKey;
|
|
private String fromLogin;
|
|
private String toLogin;
|
|
private String incomingMessageKey;
|
|
private long createdAtMs;
|
|
private long deliveryExpiresAtMs;
|
|
private int deliveryState;
|
|
private String deliveredServerLogin;
|
|
private String recipientRoutesHash;
|
|
private int attemptIndex;
|
|
private Long nextAttemptAtMs;
|
|
private Long lastAttemptAtMs;
|
|
private String lastError;
|
|
private long updatedAtMs;
|
|
|
|
public String getOutgoingMessageKey() { return outgoingMessageKey; }
|
|
public void setOutgoingMessageKey(String value) { this.outgoingMessageKey = value; }
|
|
public String getEventId() { return eventId; }
|
|
public void setEventId(String value) { this.eventId = value; }
|
|
public String getBaseKey() { return baseKey; }
|
|
public void setBaseKey(String value) { this.baseKey = value; }
|
|
public String getFromLogin() { return fromLogin; }
|
|
public void setFromLogin(String value) { this.fromLogin = value; }
|
|
public String getToLogin() { return toLogin; }
|
|
public void setToLogin(String value) { this.toLogin = value; }
|
|
public String getIncomingMessageKey() { return incomingMessageKey; }
|
|
public void setIncomingMessageKey(String value) { this.incomingMessageKey = value; }
|
|
public long getCreatedAtMs() { return createdAtMs; }
|
|
public void setCreatedAtMs(long value) { this.createdAtMs = value; }
|
|
public long getDeliveryExpiresAtMs() { return deliveryExpiresAtMs; }
|
|
public void setDeliveryExpiresAtMs(long value) { this.deliveryExpiresAtMs = value; }
|
|
public int getDeliveryState() { return deliveryState; }
|
|
public void setDeliveryState(int value) { this.deliveryState = value; }
|
|
public String getDeliveredServerLogin() { return deliveredServerLogin; }
|
|
public void setDeliveredServerLogin(String value) { this.deliveredServerLogin = value; }
|
|
public String getRecipientRoutesHash() { return recipientRoutesHash; }
|
|
public void setRecipientRoutesHash(String value) { this.recipientRoutesHash = value; }
|
|
public int getAttemptIndex() { return attemptIndex; }
|
|
public void setAttemptIndex(int value) { this.attemptIndex = value; }
|
|
public Long getNextAttemptAtMs() { return nextAttemptAtMs; }
|
|
public void setNextAttemptAtMs(Long value) { this.nextAttemptAtMs = value; }
|
|
public Long getLastAttemptAtMs() { return lastAttemptAtMs; }
|
|
public void setLastAttemptAtMs(Long value) { this.lastAttemptAtMs = value; }
|
|
public String getLastError() { return lastError; }
|
|
public void setLastError(String value) { this.lastError = value; }
|
|
public long getUpdatedAtMs() { return updatedAtMs; }
|
|
public void setUpdatedAtMs(long value) { this.updatedAtMs = value; }
|
|
|
|
public String deliveryStateCode() {
|
|
return switch (deliveryState) {
|
|
case DELIVERED_ONE, DELIVERED_ALL -> "delivered";
|
|
case FAILED_FINAL -> "failed";
|
|
default -> "accepted";
|
|
};
|
|
}
|
|
|
|
public static int parseStateCode(String value) {
|
|
if (value == null) return ACCEPTED;
|
|
return switch (value.trim().toLowerCase()) {
|
|
case "delivered", "delivered_one", "delivered_all" -> DELIVERED;
|
|
case "failed", "failed_final" -> FAILED;
|
|
default -> ACCEPTED;
|
|
};
|
|
}
|
|
|
|
public boolean isDelivered() {
|
|
return deliveryState == DELIVERED_ONE || deliveryState == DELIVERED_ALL;
|
|
}
|
|
}
|