Skip to content

Commit

Permalink
fix: Sonar issues [DHIS2-18370]
Browse files Browse the repository at this point in the history
  • Loading branch information
maikelarabori committed Jan 20, 2025
1 parent 2f1b2c9 commit b88a484
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import com.google.common.collect.Lists;
import java.util.HashMap;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.hisp.dhis.dataelement.DataElement;
Expand Down Expand Up @@ -82,8 +81,8 @@ public class DataDimensionItem {
ProgramDataElementOptionDimensionItem.class,
ProgramTrackedEntityAttributeOptionDimensionItem.class);

public static final Map<DataDimensionItemType, Class<? extends DimensionalItemObject>>
DATA_DIM_TYPE_CLASS_MAP = new HashMap<>();
public static final EnumMap<DataDimensionItemType, Class<? extends DimensionalItemObject>>
DATA_DIM_TYPE_CLASS_MAP = new EnumMap<>(DataDimensionItemType.class);

private int id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
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.base.Objects;
import java.util.List;
import lombok.NoArgsConstructor;
import org.hisp.dhis.analytics.Aggregation;
Expand All @@ -60,7 +61,7 @@
import org.hisp.dhis.schema.annotation.Property;

@NoArgsConstructor
@JacksonXmlRootElement(localName = "programDataElement", namespace = DXF_2_0)
@JacksonXmlRootElement(localName = "programDataElementOptionDimension", namespace = DXF_2_0)
public class ProgramDataElementOptionDimensionItem extends BaseDimensionalItemObject
implements EmbeddedObject, ValueTypedDimensionalItemObject {
private Program program;
Expand Down Expand Up @@ -118,6 +119,24 @@ public String toString() {
.toString();
}

@Override
public int hashCode() {
return Objects.hashCode(program, dataElement, option, aggregation);
}

@Override
public boolean equals(Object obj) {
return this == obj
|| obj instanceof ProgramDataElementOptionDimensionItem item && objectEquals(item);
}

private boolean objectEquals(ProgramDataElementOptionDimensionItem other) {
return Objects.equal(program, other.program)
&& Objects.equal(dataElement, other.dataElement)
&& Objects.equal(option, other.option)
&& Objects.equal(aggregation, other.aggregation);
}

@Override
public String getDimensionItem() {
return joinWith(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
import org.hisp.dhis.trackedentity.TrackedEntityAttribute;

@NoArgsConstructor
@JacksonXmlRootElement(localName = "programAttributeDimension", namespace = DXF_2_0)
@JacksonXmlRootElement(localName = "programAttributeOptionDimension", namespace = DXF_2_0)
public class ProgramTrackedEntityAttributeOptionDimensionItem extends BaseDimensionalItemObject
implements EmbeddedObject {
private Program program;
Expand Down Expand Up @@ -120,6 +120,7 @@ public AggregationType getAggregationType() {
return attribute.getAggregationType();
}

@Override
public String toString() {
return toStringHelper(this)
.add("program", program)
Expand All @@ -131,18 +132,21 @@ public String toString() {

@Override
public int hashCode() {
return Objects.hashCode(program, attribute);
return Objects.hashCode(program, attribute, option, aggregation);
}

@Override
public boolean equals(Object obj) {
return this == obj
|| obj instanceof ProgramTrackedEntityAttributeOptionDimensionItem
&& objectEquals((ProgramTrackedEntityAttributeOptionDimensionItem) obj);
|| obj instanceof ProgramTrackedEntityAttributeOptionDimensionItem item
&& objectEquals(item);
}

private boolean objectEquals(ProgramTrackedEntityAttributeOptionDimensionItem other) {
return Objects.equal(attribute, other.attribute) && Objects.equal(program, other.program);
return Objects.equal(attribute, other.attribute)
&& Objects.equal(program, other.program)
&& Objects.equal(option, other.option)
&& Objects.equal(aggregation, other.aggregation);
}

@JsonProperty
Expand Down

0 comments on commit b88a484

Please sign in to comment.