Skip to content

Commit

Permalink
Merge branch 'master' into master-transifex-ALL-20241214_224248
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-p-pickering authored Jan 15, 2025
2 parents e522f8f + d0eddf2 commit 57efed9
Show file tree
Hide file tree
Showing 250 changed files with 8,333 additions and 2,358 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.hisp.dhis.jsontree.JsonArray;
import org.hisp.dhis.jsontree.JsonMixed;
import org.hisp.dhis.jsontree.JsonObject;
import org.hisp.dhis.jsontree.JsonString;
import org.hisp.dhis.jsontree.JsonValue;
import org.intellij.lang.annotations.Language;

Expand Down Expand Up @@ -148,7 +149,7 @@ private static TreeMap<String, String> parseObjectJson(JsonObject map) {
.collect(
Collectors.toMap(
Map.Entry::getKey,
e -> e.getValue().asObject().getString("value").string(),
e -> parseValue(e.getValue().asObject().get("value")),
(a, b) -> a,
TreeMap::new));
}
Expand All @@ -160,11 +161,21 @@ private static TreeMap<String, String> parseArrayJson(JsonArray arr) {
.collect(
Collectors.toMap(
obj -> obj.getObject("attribute").getString("id").string(),
obj -> obj.getString("value").string(),
obj -> parseValue(obj.get("value")),
(a, b) -> a,
TreeMap::new));
}

@Nonnull
private static String parseValue(JsonValue value) {
if (value.isUndefined()) return "";
return switch (value.type()) {
case NULL -> "";
case STRING -> value.as(JsonString.class).string();
default -> value.toJson();
};
}

private void init(TreeMap<String, String> from) {
keys = new String[from.size()];
values = new String[keys.length];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import org.hisp.dhis.common.BaseIdentifiableObject;
import org.hisp.dhis.common.CombinationGenerator;
import org.hisp.dhis.common.DataDimensionType;
Expand Down Expand Up @@ -223,6 +225,18 @@ public void removeAllCategories() {
categories.clear();
}

public void addCategoryOptionCombo(@Nonnull CategoryOptionCombo coc) {
this.getOptionCombos().add(coc);
}

public void removeCategoryOptionCombo(@Nonnull CategoryOptionCombo coc) {
this.getOptionCombos().remove(coc);
}

public void removeCategoryOptionCombos(@Nonnull Collection<CategoryOptionCombo> cocs) {
cocs.forEach(this::removeCategoryOptionCombo);
}

// -------------------------------------------------------------------------
// Getters and setters
// -------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,25 @@
*/
package org.hisp.dhis.category;

import java.util.Collection;
import java.util.List;
import javax.annotation.Nonnull;
import org.hisp.dhis.common.DataDimensionType;
import org.hisp.dhis.common.IdentifiableObjectStore;
import org.hisp.dhis.common.UID;

/**
* @author Lars Helge Overland
*/
public interface CategoryComboStore extends IdentifiableObjectStore<CategoryCombo> {
List<CategoryCombo> getCategoryCombosByDimensionType(DataDimensionType dataDimensionType);

/**
* Retrieve all {@link CategoryCombo}s with {@link CategoryOptionCombo} {@link UID}s
*
* @param uids {@link CategoryOptionCombo} {@link UID}s
* @return {@link CategoryCombo}s with references to {@link CategoryOptionCombo} {@link UID}s
* passed in
*/
List<CategoryCombo> getByCategoryOptionCombo(@Nonnull Collection<UID> uids);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
*/
package org.hisp.dhis.category;

import java.util.Collection;
import java.util.List;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import org.hisp.dhis.common.IdentifiableObjectStore;
import org.hisp.dhis.common.UID;
import org.hisp.dhis.user.UserDetails;
Expand All @@ -47,4 +49,13 @@ public interface CategoryOptionStore extends IdentifiableObjectStore<CategoryOpt
List<CategoryOption> getCategoryOptions(Category category);

List<CategoryOption> getDataWriteCategoryOptions(Category category, UserDetails userDetails);

/**
* Retrieve all {@link CategoryOption}s with {@link CategoryOptionCombo} {@link UID}s
*
* @param uids {@link CategoryOptionCombo} {@link UID}s
* @return {@link CategoryOption}s with references to {@link CategoryOptionCombo} {@link UID}s
* passed in
*/
List<CategoryOption> getByCategoryOptionCombo(@Nonnull Collection<UID> uids);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.Collection;
import java.util.List;
import java.util.Set;
import javax.annotation.Nonnull;
import org.apache.commons.collections4.SetValuedMap;
import org.hisp.dhis.common.IdScheme;
import org.hisp.dhis.common.UID;
Expand Down Expand Up @@ -110,13 +111,6 @@ public interface CategoryService {
*/
Category getCategoryByName(String name, UserDetails userDetails);

/**
* Returns all DataElementCategories.
*
* @return a list of all DataElementCategories.
*/
List<Category> getAllDataElementCategories();

/**
* Retrieves all DataElementCategories of dimension type disaggregation.
*
Expand Down Expand Up @@ -330,24 +324,6 @@ SetValuedMap<String, String> getCategoryOptionOrganisationUnitsAssociations(
*/
List<CategoryCombo> getAttributeCategoryCombos();

/**
* Validates the category combo. Possible return values are:
*
* <p>
*
* <ul>
* <li>category_combo_is_null
* <li>category_combo_must_have_at_least_one_category
* <li>category_combo_cannot_have_duplicate_categories
* <li>categories_must_have_at_least_one_category_option
* <li>categories_cannot_share_category_options
* </ul>
*
* @param categoryCombo the category combo to validate.
* @return null if valid, non-empty string if invalid.
*/
String validateCategoryCombo(CategoryCombo categoryCombo);

// -------------------------------------------------------------------------
// CategoryOptionCombo
// -------------------------------------------------------------------------
Expand Down Expand Up @@ -478,7 +454,15 @@ CategoryOptionCombo getCategoryOptionCombo(
* @return categoryOptionCombos with refs to categoryOptions
*/
List<CategoryOptionCombo> getCategoryOptionCombosByCategoryOption(
Collection<UID> categoryOptions);
@Nonnull Collection<UID> categoryOptions);

/**
* Retrieves all CategoryOptionCombos by {@link UID}.
*
* @param uids {@link UID}s to search for
* @return categoryOptionCombos with refs to {@link UID}s
*/
List<CategoryOptionCombo> getCategoryOptionCombosByUid(@Nonnull Collection<UID> uids);

// -------------------------------------------------------------------------
// DataElementOperand
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.BiFunction;
import java.util.stream.Stream;
import javax.annotation.Nonnull;
import lombok.Setter;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.Immutable;
Expand Down Expand Up @@ -83,22 +85,22 @@
@JacksonXmlRootElement(localName = "identifiableObject", namespace = DxfNamespaces.DXF_2_0)
public class BaseIdentifiableObject extends BaseLinkableObject implements IdentifiableObject {
/** The database internal identifier for this Object. */
protected long id;
@Setter protected long id;

/** The unique identifier for this object. */
@AuditAttribute protected String uid;
@Setter @AuditAttribute protected String uid;

/** The unique code for this object. */
@AuditAttribute protected String code;
@Setter @AuditAttribute protected String code;

/** The name of this object. Required and unique. */
protected String name;
@Setter protected String name;

/** The date this object was created. */
protected Date created;
@Setter protected Date created;

/** The date this object was last updated. */
protected Date lastUpdated;
@Setter protected Date lastUpdated;

/** Set of the dynamic attributes values that belong to this data element. */
@AuditAttribute private AttributeValues attributeValues = AttributeValues.empty();
Expand All @@ -110,7 +112,7 @@ public class BaseIdentifiableObject extends BaseLinkableObject implements Identi
* Cache for object translations, where the cache key is a combination of locale and translation
* property, and value is the translated value.
*/
private Map<String, String> translationCache = new ConcurrentHashMap<>();
private final Map<String, String> translationCache = new ConcurrentHashMap<>();

/** User who created this object. This field is immutable and must not be updated. */
@Immutable protected User createdBy;
Expand All @@ -119,13 +121,13 @@ public class BaseIdentifiableObject extends BaseLinkableObject implements Identi
protected transient Access access;

/** Users who have marked this object as a favorite. */
protected Set<String> favorites = new HashSet<>();
@Setter protected Set<String> favorites = new HashSet<>();

/** Last user updated this object. */
protected User lastUpdatedBy;
@Setter protected User lastUpdatedBy;

/** Object sharing (JSONB). */
protected Sharing sharing = new Sharing();
@Setter protected Sharing sharing = new Sharing();

// -------------------------------------------------------------------------
// Constructors
Expand Down Expand Up @@ -162,7 +164,7 @@ public BaseIdentifiableObject(IdentifiableObject identifiableObject) {
* name.
*/
@Override
public int compareTo(IdentifiableObject object) {
public int compareTo(@Nonnull IdentifiableObject object) {
if (this.getDisplayName() == null) {
return object.getDisplayName() == null ? 0 : 1;
}
Expand All @@ -182,10 +184,6 @@ public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

@Override
@JsonProperty(value = "id")
@JacksonXmlProperty(localName = "id", isAttribute = true)
Expand All @@ -196,10 +194,6 @@ public String getUid() {
return uid;
}

public void setUid(String uid) {
this.uid = uid;
}

@Override
@JsonProperty
@JacksonXmlProperty(isAttribute = true)
Expand All @@ -209,10 +203,6 @@ public String getCode() {
return code;
}

public void setCode(String code) {
this.code = code;
}

@Override
@JsonProperty
@JacksonXmlProperty(isAttribute = true)
Expand All @@ -222,11 +212,8 @@ public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

@Override
@Sortable(whenPersisted = false)
@JsonProperty
@JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
@Translatable(propertyName = "name", key = "NAME")
Expand All @@ -243,10 +230,6 @@ public Date getCreated() {
return created;
}

public void setCreated(Date created) {
this.created = created;
}

@Override
@OpenApi.Property(UserPropertyTransformer.UserDto.class)
@JsonProperty
Expand All @@ -258,10 +241,6 @@ public User getLastUpdatedBy() {
return lastUpdatedBy;
}

public void setLastUpdatedBy(User lastUpdatedBy) {
this.lastUpdatedBy = lastUpdatedBy;
}

@Override
@JsonProperty
@JacksonXmlProperty(isAttribute = true)
Expand All @@ -271,10 +250,6 @@ public Date getLastUpdated() {
return lastUpdated;
}

public void setLastUpdated(Date lastUpdated) {
this.lastUpdated = lastUpdated;
}

public record AttributeValue(@JsonProperty Attribute attribute, @JsonProperty String value) {}

@Override
Expand Down Expand Up @@ -308,6 +283,7 @@ public String getAttributeValue(String attributeUid) {

@Gist(included = Include.FALSE)
@Override
@Sortable(value = false)
@JsonProperty
@JacksonXmlElementWrapper(localName = "translations", namespace = DxfNamespaces.DXF_2_0)
@JacksonXmlProperty(localName = "translation", namespace = DxfNamespaces.DXF_2_0)
Expand Down Expand Up @@ -387,8 +363,9 @@ public void setOwner(String userId) {
}

@Override
@Sortable(value = false)
@Gist(included = Include.FALSE)
@JsonProperty
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@JacksonXmlProperty(localName = "access", namespace = DxfNamespaces.DXF_2_0)
public Access getAccess() {
return access;
Expand All @@ -407,10 +384,6 @@ public Set<String> getFavorites() {
return favorites;
}

public void setFavorites(Set<String> favorites) {
this.favorites = favorites;
}

@Override
@JsonProperty
@JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
Expand All @@ -422,6 +395,7 @@ public boolean isFavorite() {
}

@Override
@Sortable(value = false)
@Gist(included = Include.FALSE)
@JsonProperty
@JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
Expand All @@ -433,10 +407,6 @@ public Sharing getSharing() {
return sharing;
}

public void setSharing(Sharing sharing) {
this.sharing = sharing;
}

@Override
public boolean setAsFavorite(UserDetails user) {
if (this.favorites == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public class BaseLinkableObject implements LinkableObject {
private transient String href;

@Override
@JsonProperty
@Sortable(value = false)
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@JacksonXmlProperty(isAttribute = true)
@Property(PropertyType.URL)
public String getHref() {
Expand Down
Loading

0 comments on commit 57efed9

Please sign in to comment.