Skip to content

Commit

Permalink
Merge branch 'master' into master-transifex-ALL-20231028_224439
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-p-pickering authored Nov 14, 2023
2 parents 3d60857 + ebae39f commit 55c3afd
Show file tree
Hide file tree
Showing 342 changed files with 6,827 additions and 4,989 deletions.
27 changes: 19 additions & 8 deletions .github/workflows/deploy-instance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,27 @@ jobs:
if: contains(github.event.pull_request.labels.*.name, 'deploy')
runs-on: ubuntu-latest
env:
HTTP: https --check-status
USER_EMAIL: ${{ secrets.IM_BOT_EMAIL }}
PASSWORD: ${{ secrets.IM_BOT_PASSWORD }}
IM_HOST: 'https://api.im.dhis2.org'
INSTANCE_HOST: 'https://dev.im.dhis2.org'
INSTANCE_NAME: pr-${{ github.event.pull_request.number }}
steps:
- name: Dump context
uses: crazy-max/ghaction-dump-context@v2

- name: Wait for API tests
uses: lewagon/[email protected]
# Using this fork of the upstream https://github.com/lewagon/wait-on-check-action,
# as it will filter out and check only the latest run of a workflow when checking for the allowed conclusions,
# instead of checking all of the re-runs and possibly failing due to skipped or cancelled runs.
# See https://github.com/lewagon/wait-on-check-action/issues/85 for more info.
uses: t3chguy/wait-on-check-action@master
with:
ref: ${{ github.head_ref }}
check-name: 'api-test'
repo-token: ${{ secrets.GITHUB_TOKEN }}
allowed-conclusions: success

- uses: actions/checkout@v4
with:
Expand All @@ -35,20 +47,19 @@ jobs:
- name: Deploy DHIS2 instance
working-directory: scripts/instances
env:
HTTP: https --check-status
USER_EMAIL: ${{ secrets.IM_BOT_EMAIL }}
PASSWORD: ${{ secrets.IM_BOT_PASSWORD }}
IM_HOST: 'https://api.im.dhis2.org'
IMAGE_REPOSITORY: core-pr
IMAGE_TAG: ${{ github.event.pull_request.number }}
IMAGE_PULL_POLICY: Always
DATABASE_ID: sl-sierra-leone-dev-sql-gz
DATABASE_ID: test-dbs-sierra-leone-dev-sql-gz
run: ./findByName.sh dev $INSTANCE_NAME && ./restart.sh dev $INSTANCE_NAME || ./deploy-dhis2.sh dev $INSTANCE_NAME

- name: Wait for instance
run: timeout 300 bash -c 'while [[ "$(curl -fsSL -o /dev/null -w %{http_code} $INSTANCE_HOST/$INSTANCE_NAME)" != "200" ]]; do sleep 5; done'
working-directory: scripts/instances
env:
EXPECTED_STATUS: Running
run: timeout 600 bash -ex -c 'until [[ "$(./status.sh dev $INSTANCE_NAME | jq -r)" == "$EXPECTED_STATUS" ]]; do echo "Instance is not $EXPECTED_STATUS yet ..."; sleep 5; done'

- name: Generate analytics
- name: Start analytics generation
run: curl -X POST -u "${{ secrets.DHIS2_USERNAME }}:${{ secrets.DHIS2_PASSWORD }}" "$INSTANCE_HOST/$INSTANCE_NAME/api/resourceTables/analytics" -d 'executeTei=true'

- name: Comment instance URL
Expand Down
29 changes: 28 additions & 1 deletion .github/workflows/destroy-instance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,36 @@ name: Destroy instance

on:
pull_request:
types: [closed]
types: [closed, unlabeled]

# Cancel previous runs of the same workflow and PR number or branch/tag
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
check-deploy-label:
runs-on: ubuntu-latest
outputs:
removed: ${{ steps.check.outputs.removed }}
steps:
- name: Check if "deploy" was removed
id: check
env:
GH_TOKEN: ${{ github.token }}
run: |
last_removed_label=$(
gh api "repos/$GITHUB_REPOSITORY/issues/${{ github.event.pull_request.number }}/events" \
--jq 'map(select(.event == "unlabeled"))[-1].label.name'
)
if [[ "$last_removed_label" == 'deploy' ]]; then
echo "removed=true" >> "$GITHUB_OUTPUT"
fi
destroy-instance:
needs: check-deploy-label
if: (github.event.action == 'closed' && contains(github.event.pull_request.labels.*.name, 'deploy')) || needs.check-deploy-label.outputs.removed
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -30,3 +51,9 @@ jobs:
IM_HOST: 'https://api.im.dhis2.org'
INSTANCE_NAME: pr-${{ github.event.number }}
run: ./findByName.sh dev $INSTANCE_NAME && ./destroy.sh dev $INSTANCE_NAME

- name: Delete instance URL comment
uses: actions-cool/maintain-one-comment@v3
with:
body: "Instance deployed to https://dev.im.dhis2.org/pr-${{ github.event.pull_request.number }}"
delete: true
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@

/** Enum that maps database column names to their respective "business" names. */
public enum TimeField {
EVENT_DATE("executiondate"),
EVENT_DATE("occurreddate"),
ENROLLMENT_DATE("enrollmentdate"),
INCIDENT_DATE("incidentdate"),
// Not a typo, different naming convention between FE and database
SCHEDULED_DATE("duedate"),
SCHEDULED_DATE("scheduleddate"),
COMPLETED_DATE("completeddate"),
CREATED("created"),
LAST_UPDATED("lastupdated");
Expand Down
10 changes: 10 additions & 0 deletions dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/QueryItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ public class QueryItem implements GroupableItem {
// Constructors
// -------------------------------------------------------------------------

public QueryItem(TrackedEntityAttribute item, LegendSet legendSet) {
this(
item,
null,
legendSet,
legendSet != null ? ValueType.TEXT : item.getValueType(),
item.getAggregationType(),
item.getOptionSet());
}

public QueryItem(DimensionalItemObject item) {
this.item = item;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public interface DatastoreStore extends IdentifiableObjectStore<DatastoreEntry>

/**
* Retrieves a list of keys associated with a given namespace which are updated after lastUpdated
* time.
* time. A sharing check for Metadata Read access is performed on the User to see what entries
* they have permission to read.
*
* @param namespace the namespace to retrieve keys from
* @param lastUpdated the lastUpdated time to retrieve keys from
Expand All @@ -71,7 +72,8 @@ public interface DatastoreStore extends IdentifiableObjectStore<DatastoreEntry>
List<DatastoreEntry> getEntriesInNamespace(String namespace);

/**
* Stream the matching entries to a transformer or consumer function.
* Stream the matching entries to a transformer or consumer function. A sharing check for Metadata
* Read access is performed on the User to see what entries they have permission to read.
*
* <p>Note that this API cannot return the {@link Stream} since it has to be processed within the
* transaction bounds of the function call. For the same reason a transformer function has to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public enum Type {
ENROLLMENT_DATE("enrollmentDate", PERIOD),
INCIDENT_DATE("incidentDate", PERIOD),
SCHEDULE_DATE("scheduledDate", PERIOD),
LAST_UPDATE_DATE("lastUpdated", PERIOD),
LAST_UPDATED_DATE("lastUpdated", PERIOD),
CREATED_DATE("created", PERIOD),
EVENT_STATUS("eventStatus", DATA_X),
PROGRAM_STATUS("programStatus", DATA_X),
CREATED_BY("createdBy", DATA_X),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
118 changes: 26 additions & 92 deletions dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/ErrorReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Loading

0 comments on commit 55c3afd

Please sign in to comment.