Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import lombok.Setter;
import lombok.experimental.Accessors;
import org.hisp.dhis.analytics.AggregationType;
import org.hisp.dhis.common.UID;

@Getter
@Setter
Expand All @@ -48,7 +49,7 @@ public class SourceRequest implements Serializable {
@JsonProperty private String name;

/** Optional UID reference to a visualization. */
@JsonProperty private String visualization;
@JsonProperty private UID visualization;

/** Data dimension item identifiers. */
@JsonProperty private List<String> dx = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.util.function.Consumer;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.hisp.dhis.common.CodeGenerator;
import org.hisp.dhis.dataexchange.aggregate.AggregateDataExchange;
import org.hisp.dhis.dataexchange.aggregate.Api;
import org.hisp.dhis.dataexchange.aggregate.SourceRequest;
Expand Down Expand Up @@ -109,16 +108,6 @@ private void validateSource(AggregateDataExchange exchange, Consumer<ErrorReport
request.getName().length()));
}

if (request.getVisualization() != null
&& !CodeGenerator.isValidUid(request.getVisualization())) {
addReports.accept(
new ErrorReport(
AggregateDataExchange.class,
ErrorCode.E4014,
"source.visualization",
request.getVisualization()));
}

if (isEmpty(request.getDx()) || isEmpty(request.getPe()) || isEmpty(request.getOu())) {
addReports.accept(new ErrorReport(AggregateDataExchange.class, ErrorCode.E6303));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,6 @@ void testSourceRequestNameTooLong() {
assertErrorCode(ErrorCode.E4001, objectBundleHook.validate(exchange, objectBundle));
}

@Test
void testSourceRequestVisualizationInvalidUid() {
AggregateDataExchange exchange = getAggregateDataExchange('A');
exchange.getSource().getRequests().get(0).setVisualization("1nvalidUid");

assertErrorCode(ErrorCode.E4014, objectBundleHook.validate(exchange, objectBundle));
}

@Test
void testMissingSourceDxItems() {
AggregateDataExchange exchange = getAggregateDataExchange('A');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
import org.hisp.dhis.common.IllegalQueryException;
import org.hisp.dhis.common.OrganisationUnitDescendants;
import org.hisp.dhis.common.OrganisationUnitSelectionMode;
import org.hisp.dhis.common.UID;
import org.hisp.dhis.common.UserOrgUnitType;
import org.hisp.dhis.common.ValueType;
import org.hisp.dhis.common.cache.CacheStrategy;
Expand Down Expand Up @@ -459,7 +460,7 @@ public static AggregateDataExchange getAggregateDataExchange(char uniqueCharacte
SourceRequest sourceRequest =
new SourceRequest()
.setName("RequestA")
.setVisualization("JHKuBWP20RO")
.setVisualization(UID.of("JHKuBWP20RO"))
.setDx(newArrayList("LrDpG50RAU9", "uR5HCiJhQ1w"))
.setPe(newArrayList("202201", "202202"))
.setOu(newArrayList("G9BuXqtNeeb", "jDgiLmYwPDm"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,21 @@ void testPatchAggregateDataExchange() {
assertEquals("External basic auth data exchange updated", object.getString("name").string());
}

@Test
@DisplayName("Should return conflict when source request visualization is not a valid UID")
void testSourceRequestVisualizationInvalidUid() {
JsonWebMessage message =
assertWebMessage(
HttpStatus.CONFLICT,
POST(
"/metadata/",
"{'aggregateDataExchanges': [{'id': 'iFOyIpQciyk', 'name': 'Test exchange',"
+ "'source': {'requests': [{'name': 'R1', 'visualization': '1nvalidUid',"
+ "'dx': ['fbfJHSPpUQD'], 'pe': ['202201'], 'ou': ['ImspTQPwCqd']}]},"
+ "'target': {'type': 'INTERNAL'}}]}"));
assertTrue(message.getMessage().contains("1nvalidUid"));
}

@Test
@DisplayName(
"Should return error E6305 if create a new AggregateDataExchange without authentication"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import static org.hisp.dhis.dxf2.webmessage.WebMessageUtils.unauthorized;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.RuntimeJsonMappingException;
import io.github.classgraph.ClassGraph;
import jakarta.persistence.PersistenceException;
Expand Down Expand Up @@ -400,6 +401,7 @@ public WebMessage dataApprovalExceptionHandler(Exception ex) {

@ExceptionHandler({
JsonParseException.class,
JsonMappingException.class,
MetadataImportException.class,
MetadataExportException.class
})
Expand Down