Skip to content

Commit

Permalink
Merge branch 'master' of github.com:dhis2/dhis2-core into duplicate-c…
Browse files Browse the repository at this point in the history
…ocs-prevent-import
  • Loading branch information
jason-p-pickering committed Nov 19, 2024
2 parents 04d06e7 + ddeb2bb commit 169b266
Show file tree
Hide file tree
Showing 178 changed files with 3,773 additions and 2,558 deletions.
4 changes: 0 additions & 4 deletions dhis-2/dhis-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,6 @@
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>org.locationtech.jts</groupId>
<artifactId>jts-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.hisp.dhis.common.HashUtils;

/**
* @author Lars Helge Overland
Expand Down Expand Up @@ -110,7 +110,7 @@ public String asPlainKey() {

/** Returns a 40-character unique key. The key is a SHA-1 hash of the components of this key. */
public String build() {
return DigestUtils.sha1Hex(asPlainKey());
return HashUtils.hashSHA1(asPlainKey().getBytes());
}

/** Equal to {@link QueryKey#build()}. */
Expand Down
20 changes: 20 additions & 0 deletions dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/HashUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@ private HashUtils() {
throw new IllegalStateException("Utility class");
}

/**
* Calculates a MD5 hash for the given input string.
*
* @param bytes the input string.
* @return the hash.
*/
public static String hashMD5(@Nonnull byte[] bytes) {
return Hashing.md5().hashBytes(bytes).toString();
}

/**
* Calculates a SHA1 hash for the given input string.
*
* @param bytes the input string.
* @return the hash.
*/
public static String hashSHA1(@Nonnull byte[] bytes) {
return Hashing.sha1().hashBytes(bytes).toString();
}

/**
* Calculates a SHA256 hash for the given input string.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,4 @@ public class EmbeddedOptions implements Serializable {

/** Filter options. Applies to Superset. */
@JsonProperty private FilterOptions filters;

/** Show the filters panel. Applies to Superset. */
@JsonProperty private boolean showFilters;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.hisp.dhis.category.CategoryCombo;
import org.hisp.dhis.category.CategoryOptionCombo;
import org.hisp.dhis.common.IllegalQueryException;
import org.hisp.dhis.common.UID;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.period.Period;
Expand Down Expand Up @@ -212,4 +213,12 @@ DataValue getDataValue(
* @return true, if any value exist, otherwise false
*/
boolean dataValueExists(CategoryCombo combo);

/**
* Checks if any data values exist for the provided {@link DataElement} {@link UID}.
*
* @param uid the {@link DataElement} {@link UID} to check
* @return true, if any values exist, otherwise false
*/
boolean dataValueExistsForDataElement(UID uid);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.concurrent.TimeUnit;
import org.hisp.dhis.category.CategoryCombo;
import org.hisp.dhis.category.CategoryOptionCombo;
import org.hisp.dhis.common.UID;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.period.Period;
Expand Down Expand Up @@ -184,4 +185,12 @@ DataValue getDataValue(
* @return true, if any value exist, otherwise false
*/
boolean dataValueExists(CategoryCombo combo);

/**
* Checks if any data values exist for the provided {@link DataElement} {@link UID}.
*
* @param uid the {@link DataElement} {@link UID} to check
* @return true, if any values exist, otherwise false
*/
boolean dataValueExistsForDataElement(String uid);
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public MergeWebResponse(@Nonnull MergeReport mergeReport) {
MergeType mergeType = mergeReport.getMergeType();
this.mergeReport.setMessage(
mergeReport.hasErrorMessages()
? "%s merge has errors".formatted(mergeType)
: "%s merge complete".formatted(mergeType));
? "%s merge has errors".formatted(mergeType.getName())
: "%s merge complete".formatted(mergeType.getName()));
}

@Nonnull
Expand Down
34 changes: 10 additions & 24 deletions dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public enum ErrorCode {
"Option set `{0}` of value type multi-text cannot have option codes with the separator character: `{1}`"),
E1119("{0} already exists: `{1}`"),
E1120("Update cannot be applied as it would make existing data values inaccessible"),
E1121("Data element `{0}` value type cannot be changed as it has associated data values"),

E1122("Category option combo {0} already exists for category combo {1}"),
E1123("Category option combo {0} must be associated with a category combo"),
Expand Down Expand Up @@ -93,33 +94,17 @@ public enum ErrorCode {
E1522("User `{0}` is not allowed to move organisation `{1}` unit from parent `{2}`"),
E1523("User `{0}` is not allowed to move organisation `{1}` unit to parent `{2}`"),

/* Indicator Type merge */
E1530("At least one source indicator type must be specified"),
E1531("Target indicator type must be specified"),
E1532("Target indicator type cannot be a source indicator type"),
E1533("{0} indicator type does not exist: `{1}`"),

/* Indicator merge */
E1540("At least one source indicator must be specified"),
E1541("Target indicator must be specified"),
E1542("Target indicator cannot be a source indicator"),
E1543("{0} indicator does not exist: `{1}`"),
/* Generic merge errors */
E1530("At least one source {0} must be specified"),
E1531("Target {0} must be specified"),
E1532("Target {0} cannot be a source {1}"),
E1533("{0} {1} does not exist: `{2}`"),
E1534("dataMergeStrategy field must be specified. With value `DISCARD` or `LAST_UPDATED`"),

/* DataElement merge */
E1550("At least one source data element must be specified"),
E1551("Target data element must be specified"),
E1552("Target data element cannot be a source data element"),
E1553("{0} data element does not exist: `{1}`"),
E1554("All source ValueTypes must match target ValueType: `{0}`. Other ValueTypes found: `{1}`"),
E1555(
E1550("All source ValueTypes must match target ValueType: `{0}`. Other ValueTypes found: `{1}`"),
E1551(
"All source DataElementDomains must match target DataElementDomain: `{0}`. Other DataElementDomains found: `{1}`"),
E1556("dataMergeStrategy field must be specified. With value `DISCARD` or `LAST_UPDATED`"),

/* CategoryOption merge */
E1650("At least one source category option must be specified"),
E1651("Target category option must be specified"),
E1652("Target category option cannot be a source category option"),
E1653("{0} category option does not exist: `{1}`"),

/* Data */
E2000("Query parameters cannot be null"),
Expand Down Expand Up @@ -471,6 +456,7 @@ public enum ErrorCode {
"Query failed because a referenced table does not exist. Please ensure analytics job was run"),
E7145("Query failed because of a syntax error"),
E7146("A {0} date was not specified in periods, dimensions, filters"),
E7147("Query failed because of a missing column: `{0}`"),

/* Analytics outliers */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ public class MergeReport implements ErrorMessageContainer {
@JsonProperty private Set<String> sourcesDeleted = new HashSet<>();
@JsonProperty private String message;

public MergeReport(MergeType mergeType) {
this.mergeType = mergeType;
}

@Override
public boolean hasErrorMessages() {
return !mergeErrors.isEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,4 @@ public class MergeParams {
@JsonProperty private boolean deleteSources;

@JsonProperty private DataMergeStrategy dataMergeStrategy;

private MergeType mergeType;
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import javax.annotation.Nonnull;
import org.hisp.dhis.common.IdentifiableObject;
import org.hisp.dhis.feedback.ConflictException;
import org.hisp.dhis.feedback.MergeReport;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -39,6 +40,27 @@
*/
public interface MergeService {

/**
* Processes a merge in full.
*
* @param mergeParams {@link MergeParams} to process
* @return updated {@link MergeReport} with any errors
*/
@Transactional
default MergeReport processMerge(@Nonnull MergeParams mergeParams) throws ConflictException {
MergeReport mergeReport = new MergeReport();

MergeRequest mergeRequest = validate(mergeParams, mergeReport);
if (mergeReport.hasErrorMessages())
throw new ConflictException("Merge validation error").setMergeReport(mergeReport);

merge(mergeRequest, mergeReport);
if (mergeReport.hasErrorMessages())
throw new ConflictException("Merge error").setMergeReport(mergeReport);

return mergeReport;
}

/**
* This method transforms a {@link MergeParams} to a {@link MergeRequest}. If there are any
* errors/issues with the params then the {@link MergeReport} should be updated.
Expand All @@ -57,6 +79,5 @@ public interface MergeService {
* @param mergeReport report to be updated if any issues/errors with the {@link MergeRequest}
* @return {@link MergeReport}
*/
@Transactional
MergeReport merge(@Nonnull MergeRequest request, @Nonnull MergeReport mergeReport);
}
32 changes: 27 additions & 5 deletions dhis-2/dhis-api/src/main/java/org/hisp/dhis/merge/MergeType.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,38 @@
*/
package org.hisp.dhis.merge;

import com.fasterxml.jackson.annotation.JsonValue;
import org.hisp.dhis.category.CategoryOption;
import org.hisp.dhis.common.IdentifiableObject;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.indicator.Indicator;
import org.hisp.dhis.indicator.IndicatorType;

/**
* Enum for merge type.
*
* @author david mackessy
*/
public enum MergeType {
ORG_UNIT,
INDICATOR_TYPE(IndicatorType.class),
INDICATOR(Indicator.class),
DATA_ELEMENT(DataElement.class),
CATEGORY_OPTION(CategoryOption.class);

private final Class<? extends IdentifiableObject> clazz;
private final String name;

MergeType(Class<? extends IdentifiableObject> clazz) {
this.clazz = clazz;
this.name = clazz.getSimpleName();
}

public Class<? extends IdentifiableObject> getClazz() {
return this.clazz;
}

INDICATOR_TYPE,
INDICATOR,
DATA_ELEMENT,
CATEGORY_OPTION,
@JsonValue
public String getName() {
return this.name;
}
}
Loading

0 comments on commit 169b266

Please sign in to comment.