Skip to content

Commit

Permalink
Merge branch 'master' of github-chisom:dhis2/dhis2-core into DHIS2-18…
Browse files Browse the repository at this point in the history
…585/login-fallback-error
  • Loading branch information
Chisomchima committed Dec 19, 2024
2 parents 5f472f1 + 0c43892 commit 8e7f1ce
Show file tree
Hide file tree
Showing 39 changed files with 812 additions and 185 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2004-2024, University of Oslo
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* Neither the name of the HISP project nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.hisp.dhis.analytics;

public enum Aggregation {
AGGREGATED,
DISAGGREGATED
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@
@JacksonXmlRootElement(localName = "analyticalObject", namespace = DxfNamespaces.DXF_2_0)
public abstract class BaseAnalyticalObject extends BaseNameableObject implements AnalyticalObject {

private static final BaseDimensionalItemObject USER_OU_ITEM_OBJ =
buildDimItemObj(KEY_USER_ORGUNIT, "User organisation unit");

private static final BaseDimensionalItemObject USER_OU_CHILDREN_ITEM_OBJ =
buildDimItemObj(KEY_USER_ORGUNIT_CHILDREN, "User organisation unit children");

private static final BaseDimensionalItemObject USER_OU_GRANDCHILDREN_ITEM_OBJ =
buildDimItemObj(KEY_USER_ORGUNIT_GRANDCHILDREN, "User organisation unit grand children");

public static final String NOT_A_VALID_DIMENSION = "Not a valid dimension: %s";

/** Line and axis labels. */
Expand Down Expand Up @@ -320,6 +329,19 @@ public abstract void init(
List<OrganisationUnit> organisationUnitsInGroups,
I18nFormat format);

/**
* Returns the dimensional item object for the given dimension and name.
*
* @param uid the dimension uid.
* @param name the dimension name.
* @return the DimensionalObject.
*/
private static BaseDimensionalItemObject buildDimItemObj(String uid, String name) {
BaseDimensionalItemObject itemObj = new BaseDimensionalItemObject(uid);
itemObj.setName(name);
return itemObj;
}

@Override
public abstract void populateAnalyticalProperties();

Expand Down Expand Up @@ -700,15 +722,15 @@ protected Optional<DimensionalObject> getDimensionalObject(String dimension) {
ouList.addAll(transientOrganisationUnits);

if (userOrganisationUnit) {
ouList.add(new BaseDimensionalItemObject(KEY_USER_ORGUNIT));
ouList.add(USER_OU_ITEM_OBJ);
}

if (userOrganisationUnitChildren) {
ouList.add(new BaseDimensionalItemObject(KEY_USER_ORGUNIT_CHILDREN));
ouList.add(USER_OU_CHILDREN_ITEM_OBJ);
}

if (userOrganisationUnitGrandChildren) {
ouList.add(new BaseDimensionalItemObject(KEY_USER_ORGUNIT_GRANDCHILDREN));
ouList.add(USER_OU_GRANDCHILDREN_ITEM_OBJ);
}

if (organisationUnitLevels != null && !organisationUnitLevels.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public class BaseDimensionalItemObject extends BaseNameableObject implements Dim
/** The aggregation type for this dimension. */
protected AggregationType aggregationType;

/** The client's OptionSet for this dimension item. */
protected OptionSetItem optionSetItem;

/** Query modifiers for this object. */
protected transient QueryModifiers queryMods;

Expand Down Expand Up @@ -92,6 +95,17 @@ public AggregationType getAggregationType() {
: aggregationType;
}

@Override
@JsonProperty
@JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public OptionSetItem getOptionSetItem() {
return optionSetItem;
}

public void setOptionSetItem(OptionSetItem optionSetItem) {
this.optionSetItem = optionSetItem;
}

// -------------------------------------------------------------------------
// DimensionalItemObject
// -------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,22 @@
*/
package org.hisp.dhis.common;

import static org.hisp.dhis.analytics.Aggregation.AGGREGATED;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import com.google.common.collect.Lists;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import org.hisp.dhis.analytics.Aggregation;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementOperand;
import org.hisp.dhis.expressiondimensionitem.ExpressionDimensionItem;
Expand Down Expand Up @@ -104,6 +110,40 @@ public class DataDimensionItem {

private SubexpressionDimensionItem subexpressionDimensionItem;

private Attributes attributes;

@NoArgsConstructor
@AllArgsConstructor
public static class Attributes implements Serializable {
/** The option item for this dimension item. * */
private OptionSetItem optionSetItem;

@JsonProperty
@JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public OptionSetItem getOptionSetItem() {
return optionSetItem;
}

/**
* This method ensure that existing persisted items will return default values, case the current
* {@link OptionSetItem} is null or does not have an {@link Aggregation} defined.
*
* @return the correct version of an {@link OptionSetItem}.
*/
public OptionSetItem getOptionSetItemOrDefault() {
if (optionSetItem != null) {
return new OptionSetItem(
optionSetItem.getOptions(), optionSetItem.getAggregationOrDefault());
}

return new OptionSetItem(Set.of(), AGGREGATED);
}

public void setOptionSetItem(OptionSetItem optionSetItem) {
this.optionSetItem = optionSetItem;
}
}

// -------------------------------------------------------------------------
// Constructor
// -------------------------------------------------------------------------
Expand All @@ -112,7 +152,6 @@ public DataDimensionItem() {}

public static List<DataDimensionItem> createWithDependencies(
DimensionalItemObject object, List<DataDimensionItem> items) {

if (DataElement.class.isAssignableFrom(object.getClass())) {
DataDimensionItem dimension = new DataDimensionItem();
DataElement dataElement = (DataElement) object;
Expand Down Expand Up @@ -187,6 +226,7 @@ public DimensionalItemObject getDimensionalItemObject() {
if (indicator != null) {
return indicator;
} else if (dataElement != null) {
loadAttributes(dataElement);
return dataElement;
} else if (dataElementOperand != null) {
return dataElementOperand;
Expand All @@ -195,18 +235,34 @@ public DimensionalItemObject getDimensionalItemObject() {
} else if (programIndicator != null) {
return programIndicator;
} else if (programDataElement != null) {
loadAttributes(programDataElement);
return programDataElement;
} else if (programAttribute != null) {
loadAttributes(programAttribute);
return programAttribute;
} else if (expressionDimensionItem != null) {
return expressionDimensionItem;
} else if (subexpressionDimensionItem != null) {
return expressionDimensionItem;
return subexpressionDimensionItem;
}

return null;
}

/**
* Simply loads the internal attributes into the given item object. Some objects, when null, will
* be loaded with their respective defaults.
*
* @param itemObject the {@link BaseDimensionalItemObject}.
*/
private void loadAttributes(BaseDimensionalItemObject itemObject) {
if (attributes == null) {
attributes = new Attributes();
}

itemObject.setOptionSetItem(attributes.getOptionSetItemOrDefault());
}

@JsonProperty
@JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public DataDimensionItemType getDataDimensionItemType() {
Expand Down Expand Up @@ -287,6 +343,14 @@ public void setId(int id) {
this.id = id;
}

public Attributes getAttributes() {
return attributes;
}

public void setAttributes(Attributes attributes) {
this.attributes = attributes;
}

@JsonProperty
@JsonSerialize(as = BaseNameableObject.class)
@JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
Expand All @@ -298,9 +362,6 @@ public void setIndicator(Indicator indicator) {
this.indicator = indicator;
}

@JsonProperty
@JsonSerialize(as = BaseNameableObject.class)
@JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public DataElement getDataElement() {
return dataElement;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public enum DimensionType {
ORGANISATION_UNIT_GROUP,
CATEGORY,
OPTION_GROUP_SET,
OPTION_SET,
VALIDATION_RULE,
STATIC,
ORGANISATION_UNIT_LEVEL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public interface DimensionalItemObject extends NameableObject {
/** Gets the legend sets. */
List<LegendSet> getLegendSets();

/** Option set saved for client usage. */
OptionSetItem getOptionSetItem();

/**
* Gets the first legend set in the legend set list. This field is derived from {@link
* DimensionalObject#getLegendSet()} and is not persisted.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright (c) 2004-2024, University of Oslo
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* Neither the name of the HISP project nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.hisp.dhis.common;

import static org.hisp.dhis.analytics.Aggregation.AGGREGATED;
import static org.hisp.dhis.common.DxfNamespaces.DXF_2_0;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import java.io.Serializable;
import java.util.LinkedHashSet;
import java.util.Set;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hisp.dhis.analytics.Aggregation;

/** Encapsulates {@link org.hisp.dhis.option.Option}s uids and the {@link Aggregation} type. */
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
@JacksonXmlRootElement(localName = "optionSetItem", namespace = DXF_2_0)
public class OptionSetItem implements Serializable {
/** The uids of the options. */
private Set<String> options = new LinkedHashSet<>();

/** The aggregation for this option item. */
private Aggregation aggregation;

@JsonProperty
@JacksonXmlProperty(namespace = DXF_2_0)
public Set<String> getOptions() {
return options;
}

public void setOptions(Set<String> options) {
this.options = options;
}

@JsonProperty
@JacksonXmlProperty(namespace = DXF_2_0)
public Aggregation getAggregation() {
return aggregation;
}

public void setAggregation(Aggregation aggregation) {
this.aggregation = aggregation;
}

/**
* Returns the current {@link Aggregation} or default.
*
* @return the respective {@link Aggregation} object.
*/
public Aggregation getAggregationOrDefault() {
if (aggregation == null) {
return AGGREGATED;
}

return aggregation;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
*/
package org.hisp.dhis.analytics.data;

import static java.util.stream.Collectors.toList;
import static org.apache.commons.collections4.CollectionUtils.addIgnoreNull;
import static org.apache.commons.collections4.CollectionUtils.isNotEmpty;
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
Expand Down Expand Up @@ -64,6 +63,7 @@
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.hisp.dhis.analytics.AnalyticsSecurityManager;
import org.hisp.dhis.analytics.DataQueryParams;
Expand Down Expand Up @@ -290,7 +290,7 @@ public List<OrganisationUnit> getUserOrgUnits(DataQueryParams params, String use
getItemsFromParam(userOrgUnit).stream()
.map(ou -> idObjectManager.get(OrganisationUnit.class, ou))
.filter(Objects::nonNull)
.collect(toList()));
.toList());
} else if (currentUser != null && params != null && params.getUserOrgUnitType() != null) {
switch (params.getUserOrgUnitType()) {
case DATA_CAPTURE:
Expand Down Expand Up @@ -441,6 +441,6 @@ private List<DimensionalItemObject> getCategoryOptionComboList(
return items.stream()
.map(item -> idObjectManager.getObject(CategoryOptionCombo.class, inputIdScheme, item))
.filter(Objects::nonNull)
.collect(toList());
.collect(Collectors.toList());
}
}
Loading

0 comments on commit 8e7f1ce

Please sign in to comment.