package de.thedevstack.conversationsplus.services.filetransfer; /** * */ public final class FileTransferFailureReason { private final FileTransferFailureType type; private int attempt; private Exception causedByException; private String failureMessage; public static FileTransferFailureReason createRecoverableFailureReason(Exception e) { return createFailureReason(FileTransferFailureType.RECOVERABLE, e.getMessage(), e); } public static FileTransferFailureReason createRecoverableFailureReason(String reason) { return createFailureReason(FileTransferFailureType.RECOVERABLE, reason, null); } public static FileTransferFailureReason createRecoverableFailureReason(Exception e, String failureMessage) { return createFailureReason(FileTransferFailureType.RECOVERABLE, failureMessage, e); } public static FileTransferFailureReason createLimitedRecoverableFailureReason(Exception e) { return createFailureReason(FileTransferFailureType.LIMITEDRECOVERABLE, e.getMessage(), e); } public static FileTransferFailureReason createLimitedRecoverableFailureReason(String reason) { return createFailureReason(FileTransferFailureType.LIMITEDRECOVERABLE, reason, null); } public static FileTransferFailureReason createLimitedRecoverableFailureReason(Exception e, String failureMessage) { return createFailureReason(FileTransferFailureType.LIMITEDRECOVERABLE, failureMessage, e); } public static FileTransferFailureReason createNonRecoverableFailureReason(Exception e) { return createFailureReason(FileTransferFailureType.NONRECOVERABLE, e.getMessage(), e); } public static FileTransferFailureReason createNonRecoverableFailureReason(String reason) { return createFailureReason(FileTransferFailureType.NONRECOVERABLE, reason, null); } public static FileTransferFailureReason createNonRecoverableFailureReason(Exception e, String failureMessage) { return createFailureReason(FileTransferFailureType.NONRECOVERABLE, failureMessage, e); } private static FileTransferFailureReason createFailureReason(FileTransferFailureType type, String message, Exception e) { FileTransferFailureReason ftfr = new FileTransferFailureReason(type); ftfr.setCausedByException(e); if (null != e && (null == message || message.isEmpty())) { message = e.getMessage(); } ftfr.setFailureMessage(message); return ftfr; } private FileTransferFailureReason(FileTransferFailureType type) { this.type = type; } public void setFailureMessage(String failureMessage) { this.failureMessage = failureMessage; } public String getFailureMessage() { return failureMessage; } public FileTransferFailureType getType() { return type; } public void setCausedByException(Exception causedByException) { this.causedByException = causedByException; } public Exception getCausedByException() { return causedByException; } public void setAttempt(int attempt) { this.attempt = attempt; } public boolean isRecoverable() { return this.type.isRetryPossible(this.attempt); } }