Skip to content

Commit

Permalink
fix: sonar issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jbee committed Dec 4, 2024
1 parent 5ac26b9 commit 6477534
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ public class DefaultCategoryService implements CategoryService {
public void validate(Category category) throws ConflictException {
int maxOptions = configuration.getIntProperty(ConfigurationKey.METADATA_CATEGORIES_MAX_OPTIONS);
int actualOptions = category.getCategoryOptions().size();
if (actualOptions == 0) // assume a transient object that does not have options set
actualOptions = categoryOptionStore.getCategoryOptionsCount(UID.of(category.getUid()));
if (actualOptions == 0)
// assume a transient object that does not have options set
actualOptions = categoryOptionStore.getCategoryOptionsCount(UID.of(category.getUid()));
if (actualOptions > maxOptions)
throw new ConflictException(ErrorCode.E1127, category.getUid(), maxOptions, actualOptions);
}
Expand Down Expand Up @@ -334,8 +335,9 @@ public void validate(CategoryCombo combo) throws ConflictException {
int actualCombinations = 1;
for (Category c : combo.getCategories()) {
int options = c.getCategoryOptions().size();
if (options == 0) // assume c is a transient object that has no options set
options = categoryOptionStore.getCategoryOptionsCount(UID.of(c.getUid()));
if (options == 0)
// assume c is a transient object that has no options set
options = categoryOptionStore.getCategoryOptionsCount(UID.of(c.getUid()));
actualCombinations *= options;
}
if (actualCombinations > maxCombinations)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
package org.hisp.dhis.test.webapi;

import static java.util.stream.Collectors.joining;
import static org.hisp.dhis.common.DataDimensionType.DISAGGREGATION;
import static org.hisp.dhis.http.HttpAssertions.assertStatus;
import static org.hisp.dhis.http.HttpStatus.CREATED;

Expand Down Expand Up @@ -77,10 +76,10 @@ protected final List<String> postCategoryOptions(List<String> names) {

protected final HttpResponse postCategoryCombo(
String name, DataDimensionType type, List<String> categories) {
String catIdsArray = categories.stream().map("{'id': '%s'}"::formatted).collect(joining(","));
String catObjects = categories.stream().map("{'id': '%s'}"::formatted).collect(joining(","));
String body =
"{'name': '%s', 'dataDimensionType': '%s', 'categories': [%s]}"
.formatted("maxCat", DISAGGREGATION, catIdsArray);
.formatted(name, type, catObjects);
return POST("/categoryCombos", body);
}
}

0 comments on commit 6477534

Please sign in to comment.