-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: persistent errors for job processing [DHIS2-15276] (#15575)
* fix: pickup manually run jobs that have been executed before [DHIS2-15027] * feat: persistent errors for job processing [DHIS2-15276] * fix: message arguments from array [DHIS2-15276] * fix: NPE in error messages [DHIS2-15276] * fix: OpenAPI name conflict [DHIS2-15276] * fix: sonar issues [DHIS2-15276] * fix: send emails async to not fail TX in case email is not configured [DHIS2-15276] * chore: rename asny method [DHIS2-15276] * fix: catch errors when adding errors, use empty string for undefined UID [DHIS2-15276] * fix: require auth to cancel jobs [DHIS2-15276]
- Loading branch information
Showing
29 changed files
with
361 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,41 +30,40 @@ | |
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import java.text.MessageFormat; | ||
import java.util.List; | ||
import java.util.stream.Stream; | ||
import javax.annotation.CheckForNull; | ||
import javax.annotation.Nonnull; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
|
||
/** | ||
* @author Morten Olav Hansen <[email protected]> | ||
*/ | ||
@Getter | ||
@ToString | ||
public class ErrorMessage { | ||
private final ErrorCode errorCode; | ||
|
||
private final Object[] args; | ||
|
||
private final String message; | ||
@JsonProperty private final ErrorCode errorCode; | ||
@JsonProperty private final List<String> args; | ||
@JsonProperty private String message; | ||
|
||
public ErrorMessage(ErrorCode errorCode, Object... args) { | ||
this.errorCode = errorCode; | ||
this.args = args; | ||
this.message = MessageFormat.format(errorCode.getMessage(), this.args); | ||
this.args = | ||
Stream.of(args) | ||
.map(obj -> obj == null ? null : obj.toString()) | ||
.toList(); // OBS! Must support null values! | ||
this.message = MessageFormat.format(errorCode.getMessage(), args); | ||
} | ||
|
||
@JsonCreator | ||
public ErrorMessage( | ||
@JsonProperty("message") String message, @JsonProperty("errorCode") ErrorCode errorCode) { | ||
@Nonnull @JsonProperty("message") String message, | ||
@Nonnull @JsonProperty("errorCode") ErrorCode errorCode, | ||
@CheckForNull @JsonProperty("args") List<String> args) { | ||
this.errorCode = errorCode; | ||
this.args = null; | ||
this.args = args == null ? List.of() : args; | ||
this.message = message; | ||
} | ||
|
||
public ErrorCode getErrorCode() { | ||
return errorCode; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("[%s: '%s']", errorCode.name(), message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,133 +29,67 @@ | |
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; | ||
import com.google.common.base.MoreObjects; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import org.hisp.dhis.common.DxfNamespaces; | ||
import javax.annotation.CheckForNull; | ||
import javax.annotation.Nonnull; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
import lombok.experimental.Accessors; | ||
|
||
/** | ||
* @author Morten Olav Hansen <[email protected]> | ||
*/ | ||
@JacksonXmlRootElement(localName = "errorReport", namespace = DxfNamespaces.DXF_2_0) | ||
@ToString | ||
@Getter | ||
@Setter | ||
@Accessors(chain = true) | ||
public class ErrorReport { | ||
protected final ErrorMessage message; | ||
|
||
protected final Class<?> mainKlass; | ||
private final ErrorMessage message; | ||
@JsonProperty private final Class<?> mainKlass; | ||
@JsonProperty private String mainId; | ||
@JsonProperty private Class<?> errorKlass; | ||
@JsonProperty private String errorProperty; | ||
@Nonnull @JsonProperty private List<?> errorProperties; | ||
@JsonProperty private Object value; | ||
|
||
protected String mainId; | ||
|
||
protected Class<?> errorKlass; | ||
|
||
protected String errorProperty; | ||
|
||
protected List<Object> errorProperties = new ArrayList<>(); | ||
|
||
protected Object value; | ||
|
||
public ErrorReport(Class<?> mainKlass, ErrorCode errorCode, Object... args) { | ||
public ErrorReport(@Nonnull Class<?> mainKlass, @Nonnull ErrorCode errorCode, Object... args) { | ||
this.mainKlass = mainKlass; | ||
this.message = new ErrorMessage(errorCode, args); | ||
this.errorProperties.addAll(Arrays.asList(args)); | ||
this.errorProperties = Arrays.asList(args); // OBS! Must support null values! | ||
} | ||
|
||
public ErrorReport(Class<?> mainKlass, ErrorMessage message) { | ||
public ErrorReport(@Nonnull Class<?> mainKlass, @Nonnull ErrorMessage message) { | ||
this.mainKlass = mainKlass; | ||
this.message = message; | ||
this.errorProperties = message.getArgs(); | ||
} | ||
|
||
@JsonCreator | ||
public ErrorReport( | ||
@JsonProperty("message") String message, | ||
@CheckForNull @JsonProperty("args") List<String> args, | ||
@JsonProperty("mainKlass") Class<?> mainKlass, | ||
@JsonProperty("errorCode") ErrorCode errorCode) { | ||
this.mainKlass = mainKlass; | ||
this.message = new ErrorMessage(message, errorCode); | ||
this.message = new ErrorMessage(message, errorCode, args); | ||
this.errorProperties = args == null ? List.of() : args; | ||
} | ||
|
||
@JsonProperty | ||
@JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) | ||
public ErrorCode getErrorCode() { | ||
return message.getErrorCode(); | ||
} | ||
|
||
@JsonProperty | ||
@JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) | ||
public String getMessage() { | ||
return message.getMessage(); | ||
} | ||
|
||
@JsonProperty | ||
@JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) | ||
public Class<?> getMainKlass() { | ||
return mainKlass; | ||
} | ||
|
||
@JsonProperty | ||
@JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) | ||
public String getMainId() { | ||
return mainId; | ||
} | ||
|
||
public ErrorReport setMainId(String mainId) { | ||
this.mainId = mainId; | ||
return this; | ||
} | ||
|
||
@JsonProperty | ||
@JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) | ||
public Class<?> getErrorKlass() { | ||
return errorKlass; | ||
} | ||
|
||
public ErrorReport setErrorKlass(Class<?> errorKlass) { | ||
this.errorKlass = errorKlass; | ||
return this; | ||
} | ||
|
||
@JsonProperty | ||
@JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) | ||
public String getErrorProperty() { | ||
return errorProperty; | ||
} | ||
|
||
public ErrorReport setErrorProperty(String errorProperty) { | ||
this.errorProperty = errorProperty; | ||
return this; | ||
} | ||
|
||
@JsonProperty | ||
@JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) | ||
public List<Object> getErrorProperties() { | ||
return errorProperties; | ||
} | ||
|
||
public void setErrorProperties(List<Object> errorProperties) { | ||
this.errorProperties = errorProperties; | ||
} | ||
|
||
@JsonProperty | ||
@JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) | ||
public Object getValue() { | ||
return value; | ||
} | ||
|
||
public ErrorReport setValue(Object value) { | ||
this.value = value; | ||
return this; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return MoreObjects.toStringHelper(this) | ||
.add("message", getMessage()) | ||
.add("errorCode", message.getErrorCode()) | ||
.add("mainKlass", mainKlass) | ||
.add("errorKlass", errorKlass) | ||
.add("value", value) | ||
.toString(); | ||
public List<String> getArgs() { | ||
return message.getArgs(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.