Skip to content

Commit

Permalink
Merge branch 'master' into dependabot-maven-dhis-2-org.apache.maven.p…
Browse files Browse the repository at this point in the history
…lugins-maven-dependency-plugin-3.8.1
  • Loading branch information
teleivo authored Nov 15, 2024
2 parents cccbd3c + 2a3d3e9 commit 604b5d4
Show file tree
Hide file tree
Showing 110 changed files with 1,318 additions and 1,773 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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -89,33 +89,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
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
package org.hisp.dhis.merge;

import java.util.Set;
import javax.annotation.Nonnull;
import org.hisp.dhis.common.IdentifiableObject;
import org.hisp.dhis.common.UID;
import org.hisp.dhis.feedback.MergeReport;
Expand All @@ -37,18 +38,28 @@
*/
public interface MergeValidator {

/**
* Validates source & target {@link UID}s passed in the params. Validation used by all merges.
*
* @param params {@link MergeParams} that contain {@link UID}s to validate
* @param mergeReport {@link MergeReport} to update
* @param mergeType {@link MergeType}
* @return {@link MergeRequest} to process
*/
MergeRequest validateUIDs(
@Nonnull MergeParams params, @Nonnull MergeReport mergeReport, @Nonnull MergeType mergeType);

/**
* Verifies whether the source {@link UID}s map to valid {@link IdentifiableObject}s. <br>
* - If they are valid then they are added to verifiedSources param. <br>
* - If any are not valid then the {@link MergeReport} is updated with an error.
*
* @param paramSources {@link UID}s
* @param verifiedSources set to add verified source {@link UID}s
* @param mergeReport to update if any error
* @param clazz {@link IdentifiableObject} type
* @param mergeType {@link MergeType}
* @return verified source {@link UID}s
*/
<T extends IdentifiableObject> void verifySources(
Set<UID> paramSources, Set<UID> verifiedSources, MergeReport mergeReport, Class<T> clazz);
Set<UID> verifySources(Set<UID> paramSources, MergeReport mergeReport, MergeType mergeType);

/**
* Checks whether the target is referenced in the sources collection <br>
Expand All @@ -57,10 +68,10 @@ <T extends IdentifiableObject> void verifySources(
* @param sources to check
* @param target to check if in sources
* @param mergeReport to update if any error
* @param clazz {@link IdentifiableObject} type
* @param mergeType {@link MergeType}
*/
<T extends IdentifiableObject> void checkIsTargetInSources(
Set<UID> sources, UID target, MergeReport mergeReport, Class<T> clazz);
void checkIsTargetInSources(
Set<UID> sources, UID target, MergeReport mergeReport, MergeType mergeType);

/**
* Verifies whether the target {@link UID} maps to a valid {@link IdentifiableObject}. <br>
Expand All @@ -71,9 +82,9 @@ <T extends IdentifiableObject> void checkIsTargetInSources(
* @param mergeReport to update if any error
* @param sources to return in merge request
* @param params merge params with target to verify
* @param clazz {@link IdentifiableObject} type
* @param mergeType {@link MergeType}
* @return merge request
*/
<T extends IdentifiableObject> MergeRequest verifyTarget(
MergeReport mergeReport, Set<UID> sources, MergeParams params, Class<T> clazz);
MergeRequest verifyTarget(
MergeReport mergeReport, Set<UID> sources, MergeParams params, MergeType mergeType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,13 @@ default String getGlobalShellAppName() {
return asString("globalShellAppName", "global-app-shell");
}

/**
* @return true if email verification is enforced for all users.
*/
default boolean getEnforceVerifiedEmail() {
return asBoolean("enforceVerifiedEmail", false);
}

/** Combinators based on several settings. */
default boolean isEmailConfigured() {
return !getEmailHostName().isBlank() && !getEmailUsername().isBlank();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ public boolean isTwoFactorEnabled() {
return false;
}

@Override
public boolean isEmailVerified() {
return true;
}

@Override
public boolean hasAnyRestrictions(Collection<String> restrictions) {
return false;
Expand Down
Loading

0 comments on commit 604b5d4

Please sign in to comment.