Skip to content

Commit

Permalink
Merge branch 'master' into DHIS2-16960_2.42
Browse files Browse the repository at this point in the history
  • Loading branch information
netroms authored Dec 26, 2024
2 parents 6341342 + a7dc1d0 commit c3e476d
Show file tree
Hide file tree
Showing 39 changed files with 1,044 additions and 354 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 @@ -27,6 +27,8 @@
*/
package org.hisp.dhis.common;

import static org.hisp.dhis.analytics.Aggregation.AGGREGATED;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
Expand All @@ -40,6 +42,7 @@
import java.util.stream.Collectors;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import org.hisp.dhis.analytics.Aggregation;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementOperand;
import org.hisp.dhis.expressiondimensionitem.ExpressionDimensionItem;
Expand Down Expand Up @@ -113,16 +116,31 @@ public class DataDimensionItem {
@AllArgsConstructor
public static class Attributes implements Serializable {
/** The option item for this dimension item. * */
private OptionSetItem optionItem;
private OptionSetItem optionSetItem;

@JsonProperty
@JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public OptionSetItem getOptionSetItem() {
return optionItem;
return optionSetItem;
}

/**
* This method ensure that existing persisted items will return default values, case the current
* {@link OptionSetItem} is null or does not have an {@link Aggregation} defined.
*
* @return the correct version of an {@link OptionSetItem}.
*/
public OptionSetItem getOptionSetItemOrDefault() {
if (optionSetItem != null) {
return new OptionSetItem(
optionSetItem.getOptions(), optionSetItem.getAggregationOrDefault());
}

return new OptionSetItem(Set.of(), AGGREGATED);
}

public void setOptionSetItem(OptionSetItem optionItem) {
this.optionItem = optionItem;
public void setOptionSetItem(OptionSetItem optionSetItem) {
this.optionSetItem = optionSetItem;
}
}

Expand Down Expand Up @@ -232,14 +250,17 @@ public DimensionalItemObject getDimensionalItemObject() {
}

/**
* Simply loads the internal attributes into the given item object.
* Simply loads the internal attributes into the given item object. Some objects, when null, will
* be loaded with their respective defaults.
*
* @param itemObject the {@link BaseDimensionalItemObject}.
*/
private void loadAttributes(BaseDimensionalItemObject itemObject) {
if (attributes != null) {
itemObject.setOptionSetItem(attributes.getOptionSetItem());
if (attributes == null) {
attributes = new Attributes();
}

itemObject.setOptionSetItem(attributes.getOptionSetItemOrDefault());
}

@JsonProperty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/
package org.hisp.dhis.common;

import static org.hisp.dhis.analytics.Aggregation.AGGREGATED;
import static org.hisp.dhis.common.DxfNamespaces.DXF_2_0;

import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down Expand Up @@ -71,4 +72,17 @@ public Aggregation getAggregation() {
public void setAggregation(Aggregation aggregation) {
this.aggregation = aggregation;
}

/**
* Returns the current {@link Aggregation} or default.
*
* @return the respective {@link Aggregation} object.
*/
public Aggregation getAggregationOrDefault() {
if (aggregation == null) {
return AGGREGATED;
}

return aggregation;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ public class DataItem implements Serializable {
@JacksonXmlProperty(namespace = DXF_2_0)
private String expression;

@JsonProperty
@JacksonXmlProperty(namespace = DXF_2_0)
private String optionSetId;

public ValueType getSimplifiedValueType() {
return valueType != null ? valueType.toSimplifiedValueType() : null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/
package org.hisp.dhis.dataitem.query;

import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toSet;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.hisp.dhis.common.ValueType.getAggregatables;
Expand All @@ -37,6 +38,7 @@
import static org.hisp.dhis.dataitem.query.shared.FilteringStatement.ifAny;
import static org.hisp.dhis.dataitem.query.shared.FilteringStatement.ifSet;
import static org.hisp.dhis.dataitem.query.shared.FilteringStatement.nameFiltering;
import static org.hisp.dhis.dataitem.query.shared.FilteringStatement.optionSetIdFiltering;
import static org.hisp.dhis.dataitem.query.shared.FilteringStatement.rootJunction;
import static org.hisp.dhis.dataitem.query.shared.FilteringStatement.shortNameFiltering;
import static org.hisp.dhis.dataitem.query.shared.FilteringStatement.uidFiltering;
Expand All @@ -54,8 +56,10 @@
import static org.hisp.dhis.dataitem.query.shared.UserAccessStatement.READ_ACCESS;
import static org.hisp.dhis.dataitem.query.shared.UserAccessStatement.sharingConditions;

import java.util.List;
import java.util.Set;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.tuple.Pair;
import org.hisp.dhis.common.BaseIdentifiableObject;
import org.hisp.dhis.dataitem.query.shared.OptionalFilterBuilder;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
Expand All @@ -70,12 +74,28 @@
@Component
public class DataElementQuery implements DataItemQuery {
private static final String COMMON_COLUMNS =
"cast (null as text) as program_name, cast (null as text) as program_uid,"
+ " cast (null as text) as program_shortname, dataelement.uid as item_uid, dataelement.name as item_name,"
+ " dataelement.shortname as item_shortname, dataelement.valuetype as item_valuetype,"
+ " dataelement.code as item_code, dataelement.sharing as item_sharing, dataelement.domaintype as item_domaintype,"
+ " cast ('DATA_ELEMENT' as text) as item_type,"
+ " cast (null as text) as expression";
List.of(
Pair.of("program_name", CAST_NULL_AS_TEXT),
Pair.of("program_uid", CAST_NULL_AS_TEXT),
Pair.of("program_shortname", CAST_NULL_AS_TEXT),
Pair.of("item_uid", "dataelement.uid"),
Pair.of("item_name", "dataelement.name"),
Pair.of("item_shortname", "dataelement.shortname"),
Pair.of("item_valuetype", "dataelement.valuetype"),
Pair.of("item_code", "dataelement.code"),
Pair.of("item_sharing", "dataelement.sharing"),
Pair.of("item_domaintype", "dataelement.domaintype"),
Pair.of("item_type", "cast ('DATA_ELEMENT' as text)"),
Pair.of("expression", CAST_NULL_AS_TEXT),
Pair.of("optionset_uid", "optionset.uid"))
.stream()
.map(pair -> pair.getRight() + " as " + pair.getLeft())
.collect(joining(", "));

private static final String JOINS =
"left join optionset on dataelement.optionsetid = optionset.optionsetid";

private static final String SPACED_FROM_DATA_ELEMENT = " from dataelement ";

@Override
public String getStatement(MapSqlParameterSource paramsMap) {
Expand All @@ -95,7 +115,7 @@ public String getStatement(MapSqlParameterSource paramsMap) {
}

sql.append(
" group by item_name, item_uid, item_valuetype, item_code, item_domaintype, item_sharing, item_shortname,"
" group by optionset.uid, item_name, item_uid, item_valuetype, item_code, item_domaintype, item_sharing, item_shortname,"
+ " i18n_first_name, i18n_first_shortname, i18n_second_name, i18n_second_shortname");

// Closing the temp table.
Expand Down Expand Up @@ -131,6 +151,7 @@ public String getStatement(MapSqlParameterSource paramsMap) {
optionalFilters.append(ifSet(nameFiltering("t.item_name", paramsMap)));
optionalFilters.append(ifSet(shortNameFiltering("t.item_shortname", paramsMap)));
optionalFilters.append(ifSet(uidFiltering("t.item_uid", paramsMap)));
optionalFilters.append(ifSet(optionSetIdFiltering("t.optionset_uid", paramsMap)));
sql.append(ifAny(optionalFilters.toString()));

String identifiableStatement =
Expand Down Expand Up @@ -180,9 +201,11 @@ public Class<? extends BaseIdentifiableObject> getRootEntity() {
private String selectRowsContainingTranslatedName() {
StringBuilder sql = new StringBuilder();

sql.append(SPACED_SELECT + COMMON_COLUMNS).append(translationNamesColumnsFor("dataelement"));

sql.append(" from dataelement ").append(translationNamesJoinsOn("dataelement"));
sql.append(SPACED_SELECT + COMMON_COLUMNS)
.append(translationNamesColumnsFor("dataelement"))
.append(SPACED_FROM_DATA_ELEMENT)
.append(JOINS)
.append(translationNamesJoinsOn("dataelement"));

return sql.toString();
}
Expand All @@ -193,7 +216,8 @@ private String selectAllRowsIgnoringAnyTranslation() {
.append(", dataelement.name as i18n_first_name, cast (null as text) as i18n_second_name")
.append(
", dataelement.shortname as i18n_first_shortname, cast (null as text) as i18n_second_shortname")
.append(" from dataelement ")
.append(SPACED_FROM_DATA_ELEMENT)
.append(JOINS)
.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
* @author maikel arabori
*/
public interface DataItemQuery {
String CAST_NULL_AS_TEXT = "cast (null as text)";

/**
* Builds and returns the SQL statement required by the implementation.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/
package org.hisp.dhis.dataitem.query;

import static java.util.stream.Collectors.joining;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.hisp.dhis.dataitem.query.shared.FilteringStatement.always;
import static org.hisp.dhis.dataitem.query.shared.FilteringStatement.displayNameFiltering;
Expand All @@ -50,7 +51,9 @@
import static org.hisp.dhis.dataitem.query.shared.UserAccessStatement.READ_ACCESS;
import static org.hisp.dhis.dataitem.query.shared.UserAccessStatement.sharingConditions;

import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.tuple.Pair;
import org.hisp.dhis.common.BaseIdentifiableObject;
import org.hisp.dhis.dataitem.query.shared.OptionalFilterBuilder;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
Expand All @@ -65,12 +68,23 @@
@Component
public class DataSetQuery implements DataItemQuery {
private static final String COMMON_COLUMNS =
"cast (null as text) as program_name, cast (null as text) as program_uid,"
+ " cast (null as text) as program_shortname, dataset.uid as item_uid, dataset.name as item_name,"
+ " dataset.shortname as item_shortname, cast (null as text) as item_valuetype, dataset.code as item_code,"
+ " dataset.sharing as item_sharing, cast (null as text) as item_domaintype,"
+ " cast('REPORTING_RATE' as text) as item_type,"
+ " cast (null as text) as expression";
List.of(
Pair.of("program_name", CAST_NULL_AS_TEXT),
Pair.of("program_uid", CAST_NULL_AS_TEXT),
Pair.of("program_shortname", CAST_NULL_AS_TEXT),
Pair.of("item_uid", "dataset.uid"),
Pair.of("item_name", "dataset.name"),
Pair.of("item_shortname", "dataset.shortname"),
Pair.of("item_valuetype", CAST_NULL_AS_TEXT),
Pair.of("item_code", "dataset.code"),
Pair.of("item_sharing", "dataset.sharing"),
Pair.of("item_domaintype", CAST_NULL_AS_TEXT),
Pair.of("item_type", "cast ('REPORTING_RATE' as text)"),
Pair.of("expression", CAST_NULL_AS_TEXT),
Pair.of("optionset_uid", CAST_NULL_AS_TEXT))
.stream()
.map(pair -> pair.getRight() + " as " + pair.getLeft())
.collect(joining(", "));

@Override
public String getStatement(MapSqlParameterSource paramsMap) {
Expand Down
Loading

0 comments on commit c3e476d

Please sign in to comment.