Skip to content

Commit

Permalink
Merge branch 'master' into DHIS2-18585/login-fallback-error
Browse files Browse the repository at this point in the history
  • Loading branch information
Chisomchima authored Dec 20, 2024
2 parents c1c3499 + 6cb0d1f commit bf8faee
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 30 deletions.
12 changes: 0 additions & 12 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ updates:
- dependency-name: "org.springframework.ldap:*" # Spring ldap 3.x requires Spring 6 (see above)
versions:
- ">= 3.0"
- dependency-name: "org.hisp.dhis.parser:*" # Antlr parser must be upgraded manually due to circular dependency with rule engine
versions:
- ">= 1.0"
- dependency-name: "org.hisp.dhis.rules:*" # Rule engine must be upgraded manually due to circular dependency with ANTLR parser
versions:
- ">= 2.0"
- dependency-name: "org.slf4j:slf4j-api" # will update in https://dhis2.atlassian.net/browse/DHIS2-16504
versions:
- ">= 2.0"
Expand Down Expand Up @@ -138,12 +132,6 @@ updates:
- dependency-name: "org.springframework.ldap:*" # Spring ldap 3.x requires Spring 6 (see above)
versions:
- ">= 3.0"
- dependency-name: "org.hisp.dhis.parser:*" # Antlr parser must be upgraded manually due to circular dependency with rule engine
versions:
- ">= 1.0"
- dependency-name: "org.hisp.dhis.rules:*" # Rule engine must be upgraded manually due to circular dependency with ANTLR parser
versions:
- ">= 2.0"
- dependency-name: "org.flywaydb:flyway-core" # It requires Postgres version to be >= 11
versions:
- "> 9.22.3"
Expand Down
51 changes: 51 additions & 0 deletions .github/workflows/generate-merge-boms.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Generate and Merge SBOMs and Upload them to DependencyTrack every night

on:
schedule:
- cron: "0 0 * * *" # Run every day at midnight

concurrency:
group: ${{ github.workflow}}-${{ github.ref }}
cancel-in-progress: true

jobs:
create-boms:
runs-on: ubuntu-latest
defaults:
run:
working-directory: dhis-2/

steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
cache: maven

- name: Install CycloneDX CLI
run: |
curl -s https://api.github.com/repos/CycloneDX/cyclonedx-cli/releases/latest | grep "browser_download_url.*linux.x64" | cut -d '"' -f 4 | wget -i -
sudo mv cyclonedx-linux-x64 /usr/local/bin/
sudo chmod +x /usr/local/bin/cyclonedx-linux-x64
- name: Generate BOMs
run: mvn cyclonedx:makeBom

- name: Merge BOMs
run: cyclonedx-linux-x64 merge --input-files $(find . -name 'dxbom.json') --input-format json --output-file target/merged-bom.json --output-format json

- name: Upload SBOM to DependencyTrack
env:
DEPENDENCY_TRACK_API: "https://dt.security.dhis2.org/api/v1/bom"
run: |
curl -X POST "$DEPENDENCY_TRACK_API" \
--fail-with-body \
-H "Content-Type: multipart/form-data" \
-H "X-Api-Key: ${{ secrets.DEPENDENCYTRACK_APIKEY }}" \
-F "project=56383704-d5a2-4a35-ad6a-081f80f5d6d3" \
-F "bom=@target/merged-bom.json"
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ private static String orderBy(List<Order> orders) {
orderJoiner.add(
order.getField() + " " + (order.getDirection().isAscending() ? "asc" : "desc"));
}
return " order by " + orderJoiner;
return " order by " + orderJoiner + ", " + DEFAULT_ORDER;
}

@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1612,7 +1612,7 @@ private String getOrderQuery(EventQueryParams params) {
}

if (!orderFields.isEmpty()) {
return "order by " + StringUtils.join(orderFields, ',') + " ";
return "order by " + StringUtils.join(orderFields, ',') + ", " + DEFAULT_ORDER + " ";
} else {
return "order by " + DEFAULT_ORDER + " ";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.Set;
import java.util.function.Function;
import java.util.function.LongSupplier;
import java.util.stream.Stream;
import javax.annotation.Nonnull;
import org.apache.commons.collections4.CollectionUtils;
import org.hisp.dhis.common.IdentifiableObject;
Expand Down Expand Up @@ -264,10 +265,13 @@ private <T extends IdentifiableObject> String getRelationshipEntityType(T entity

private List<Order> orderBy(
RelationshipQueryParams queryParams, CriteriaBuilder builder, Root<Relationship> root) {
List<Order> defaultOrder = orderBy(List.of(DEFAULT_ORDER), builder, root);
if (!queryParams.getOrder().isEmpty()) {
return orderBy(queryParams.getOrder(), builder, root);
return Stream.concat(
orderBy(queryParams.getOrder(), builder, root).stream(), defaultOrder.stream())
.toList();
} else {
return orderBy(List.of(DEFAULT_ORDER), builder, root);
return defaultOrder;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1007,10 +1007,10 @@ private String getQueryOrderBy(TrackedEntityQueryParams params, boolean innerOrd
}

if (!orderFields.isEmpty()) {
return "ORDER BY " + StringUtils.join(orderFields, ',') + SPACE;
return "ORDER BY " + StringUtils.join(orderFields, ',') + ", " + DEFAULT_ORDER + SPACE;
}

return "ORDER BY " + DEFAULT_ORDER + " ";
return "ORDER BY " + DEFAULT_ORDER + SPACE;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,32 @@ void shouldReturnPaginatedTrackedEntitiesGivenNonDefaultPageSizeAndTotalPages()
trackedEntityService.getTrackedEntities(params, new PageParams(3, 3, true)).getItems());
}

@Test
void shouldOrderTrackedEntitiesByInactiveAndByDefaultOrder()
throws ForbiddenException, BadRequestException, NotFoundException {
List<String> expected =
Stream.of(
get(TrackedEntity.class, "QesgJkTyTCk"),
get(TrackedEntity.class, "dUE514NMOlo"),
get(TrackedEntity.class, "mHWCacsGYYn"))
.sorted(Comparator.comparing(TrackedEntity::getId).reversed()) // reversed = desc
.map(TrackedEntity::getUid)
.toList();

TrackedEntityOperationParams params =
TrackedEntityOperationParams.builder()
.organisationUnits(orgUnit)
.orgUnitMode(SELECTED)
.trackedEntities(UID.of("mHWCacsGYYn", "QesgJkTyTCk", "dUE514NMOlo"))
.trackedEntityType(trackedEntityType)
.orderBy("inactive", SortDirection.ASC)
.build();

List<String> trackedEntities = getTrackedEntities(params);

assertEquals(expected, trackedEntities);
}

@Test
void shouldOrderTrackedEntitiesByPrimaryKeyDescByDefault()
throws ForbiddenException, BadRequestException, NotFoundException {
Expand Down Expand Up @@ -566,6 +592,28 @@ void shouldOrderTrackedEntitiesByInactiveAsc()
assertEquals(List.of("dUE514NMOlo", "QS6w44flWAf"), trackedEntities);
}

@Test
void shouldOrderEnrollmentsByStatusAndByDefaultOrder()
throws ForbiddenException, BadRequestException {
List<String> expected =
Stream.of(get(Enrollment.class, "HDWTYSYkICe"), get(Enrollment.class, "GYWSSZunTLk"))
.sorted(Comparator.comparing(Enrollment::getId).reversed()) // reversed = desc
.map(Enrollment::getUid)
.toList();

EnrollmentOperationParams operationParams =
EnrollmentOperationParams.builder()
.orgUnits(get(OrganisationUnit.class, "DiszpKrYNg8"))
.orgUnitMode(SELECTED)
.enrollments(UID.of("HDWTYSYkICe", "GYWSSZunTLk"))
.orderBy("status", SortDirection.DESC)
.build();

List<String> actual = getEnrollments(operationParams);

assertEquals(expected, actual);
}

@Test
void shouldReturnPaginatedEnrollmentsGivenNonDefaultPageSize()
throws ForbiddenException, BadRequestException {
Expand Down Expand Up @@ -677,6 +725,29 @@ void shouldOrderEnrollmentsByEnrolledAtDesc() throws ForbiddenException, BadRequ
assertEquals(List.of("TvctPPhpD8z", "nxP7UnKhomJ"), enrollments);
}

@Test
void shouldOrderEventsByStatusAndByDefaultOrder() throws ForbiddenException, BadRequestException {
List<String> expected =
Stream.of(
get(Event.class, "ck7DzdxqLqA"),
get(Event.class, "kWjSezkXHVp"),
get(Event.class, "OTmjvJDn0Fu"))
.sorted(Comparator.comparing(Event::getId).reversed()) // reversed = desc
.map(Event::getUid)
.toList();

EventOperationParams operationParams =
eventParamsBuilder
.orgUnit(get(OrganisationUnit.class, "DiszpKrYNg8"))
.events(UID.of("ck7DzdxqLqA", "kWjSezkXHVp", "OTmjvJDn0Fu"))
.orderBy("status", SortDirection.DESC)
.build();

List<String> actual = getEvents(operationParams);

assertEquals(expected, actual);
}

@Test
void shouldReturnPaginatedEventsWithNotesGivenNonDefaultPageSize()
throws ForbiddenException, BadRequestException {
Expand Down Expand Up @@ -1274,6 +1345,29 @@ void shouldOrderByFieldInAscendingOrderWhenModeDescendants(
assertEquals(List.of(firstEvent, secondEvent), events);
}

@Test
void shouldOrderRelationshipsByCreatedAtClientAndByDefaultOrder()
throws ForbiddenException, BadRequestException, NotFoundException {
Relationship oLT07jKRu9e = get(Relationship.class, "fHn74P5T3r1");
Relationship yZxjxJli9mO = get(Relationship.class, "yZxjxJli9mO");
List<String> expected =
Stream.of(oLT07jKRu9e, yZxjxJli9mO)
.sorted(Comparator.comparing(Relationship::getId).reversed()) // reversed = desc
.map(Relationship::getUid)
.toList();

RelationshipOperationParams params =
RelationshipOperationParams.builder()
.type(TrackerType.TRACKED_ENTITY)
.identifier(UID.of("dUE514NMOlo"))
.orderBy("createdAtClient", SortDirection.DESC)
.build();

List<String> relationships = getRelationships(params);

assertEquals(expected, relationships);
}

@Test
void shouldOrderRelationshipsByPrimaryKeyDescByDefault()
throws ForbiddenException, BadRequestException, NotFoundException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,22 @@
"to": {
"event": "pTzf9KYMk72"
}
},
{
"relationship": "fHn74P5T3r1",
"relationshipType": {
"idScheme": "UID",
"identifier": "TV9oB9LT3sh"
},
"createdAtClient": "2018-11-01T13:24:37.118",
"bidirectional": false,
"deleted": false,
"from": {
"trackedEntity": "dUE514NMOlo"
},
"to": {
"event": "D9PbzJY8bJM"
}
}
],
"username": "system-process"
Expand Down
36 changes: 24 additions & 12 deletions dhis-2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<!-- *Dependencies* -->

<!-- DHIS2 Rule Engine -->
<dhis2-rule-engine.version>3.1.0</dhis2-rule-engine.version>
<dhis2-rule-engine.version>3.2.1</dhis2-rule-engine.version>
<kotlinx-datetime.version>0.6.1</kotlinx-datetime.version>

<!-- HISP Quick and Staxwax -->
Expand All @@ -104,7 +104,7 @@

<!-- Spring -->
<spring.version>6.1.12</spring.version>
<spring-session-core.version>3.4.0</spring-session-core.version>
<spring-session-core.version>3.4.1</spring-session-core.version>
<spring-data-redis.version>2.7.18</spring-data-redis.version>
<spring-session-data-redis.version>2.7.4</spring-session-data-redis.version>
<spring-mobile-device.version>1.1.5.RELEASE</spring-mobile-device.version>
Expand Down Expand Up @@ -428,16 +428,6 @@
<groupId>org.hisp.dhis.rules</groupId>
<artifactId>rule-engine-jvm</artifactId>
<version>${dhis2-rule-engine.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- Spring -->
Expand Down Expand Up @@ -1882,6 +1872,28 @@
<artifactId>sonar-maven-plugin</artifactId>
<version>5.0.0.4389</version>
</plugin>
<plugin>
<groupId>org.cyclonedx</groupId>
<artifactId>cyclonedx-maven-plugin</artifactId>
<configuration>
<projectType>library</projectType>
<schemaVersion>1.6</schemaVersion>
<includeBomSerialNumber>true</includeBomSerialNumber>
<includeCompileScope>true</includeCompileScope>
<includeProvidedScope>true</includeProvidedScope>
<includeRuntimeScope>true</includeRuntimeScope>
<includeSystemScope>true</includeSystemScope>
<includeTestScope>false</includeTestScope>
<includeLicenseText>false</includeLicenseText>
<outputReactorProjects>true</outputReactorProjects>
<outputFormat>all</outputFormat>
<outputName>dxbom</outputName>
<outputDirectory>${project.build.directory}</outputDirectory>
<!-- usually target, if not redefined in pom.xml -->
<verbose>false</verbose>
<!-- = ${cyclonedx.verbose} -->
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
Expand Down

0 comments on commit bf8faee

Please sign in to comment.