Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-p-pickering authored Nov 26, 2024
2 parents 864833b + 56a870d commit fa66926
Show file tree
Hide file tree
Showing 808 changed files with 20,886 additions and 11,888 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/run-api-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ jobs:
# build and publish multi-arch images using Jib. Image is used for api tests in
# this workflow and can be pulled from Dockerhub by devs to run locally, ...
mvn clean verify --threads 2C --batch-mode --no-transfer-progress \
-DskipTests --update-snapshots --file dhis-2/pom.xml \
-DskipTests -Dmdep.analyze.skip --update-snapshots --file dhis-2/pom.xml \
--projects dhis-web-server --also-make --activate-profiles jibBuild \
-Djib.to.image=$CORE_IMAGE_NAME -Djib.container.labels=DHIS2_BUILD_REVISION=${{github.event.pull_request.head.sha}},DHIS2_BUILD_BRANCH=${{github.head_ref}}
else
# only build image for running api tests in this workflow i.e. master, 2.39, ...
mvn clean verify --threads 2C --batch-mode --no-transfer-progress \
-DskipTests --update-snapshots --file dhis-2/pom.xml \
-DskipTests -Dmdep.analyze.skip --update-snapshots --file dhis-2/pom.xml \
--projects dhis-web-server --also-make --activate-profiles jibDockerBuild \
-Djib.to.image=$CORE_IMAGE_NAME
fi
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ jobs:
- name: Run unit tests
run: mvn clean test --threads 2C --batch-mode --no-transfer-progress --update-snapshots --file ./dhis-2/pom.xml --activate-profiles unit-test
timeout-minutes: 30
- name: Run dependency analysis
run: mvn dependency:analyze --file ./dhis-2/pom.xml
timeout-minutes: 2
- name: Report coverage to codecov
uses: codecov/codecov-action@v3
with:
Expand Down
4 changes: 0 additions & 4 deletions dhis-2/dhis-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,6 @@
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>org.locationtech.jts</groupId>
<artifactId>jts-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,24 @@
* (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.merge.indicator;
package org.hisp.dhis.analytics;

import lombok.RequiredArgsConstructor;
import org.hisp.dhis.merge.MergeProcessor;
import org.hisp.dhis.merge.MergeService;
import org.springframework.stereotype.Component;
import java.util.Collection;
import java.util.List;
import org.hisp.dhis.category.CategoryDimension;
import org.hisp.dhis.category.CategoryOption;
import org.hisp.dhis.common.GenericStore;

/**
* Implementation of {@link MergeProcessor} that currently only uses its default method.
*
* @author david mackessy
*/
@Component
@RequiredArgsConstructor
public class IndicatorMergeProcessor implements MergeProcessor {
public interface CategoryDimensionStore extends GenericStore<CategoryDimension> {

/**
* Spring injects the correct service based on the variable name (when there are multiple
* implementations to choose from). So The {@link IndicatorMergeService} gets injected here.
* Gets all {@link CategoryDimension}s that reference any of the supplied {@link CategoryOption}s
*
* @param categoryOptions to search for
* @return matching {@link CategoryDimension}s
*/
private final MergeService indicatorMergeService;

@Override
public MergeService getMergeService() {
return indicatorMergeService;
}
List<CategoryDimension> getByCategoryOption(Collection<String> categoryOptions);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.hisp.dhis.common.HashUtils;

/**
* @author Lars Helge Overland
Expand Down Expand Up @@ -110,7 +110,7 @@ public String asPlainKey() {

/** Returns a 40-character unique key. The key is a SHA-1 hash of the components of this key. */
public String build() {
return DigestUtils.sha1Hex(asPlainKey());
return HashUtils.hashSHA1(asPlainKey().getBytes());
}

/** Equal to {@link QueryKey#build()}. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ public boolean isAttribute(ObjectType type) {
return objectTypes.contains(type);
}

private void setAttribute(ObjectType type, Boolean isAttribute) {
if (isAttribute != null && isAttribute) {
private void setAttribute(ObjectType type, boolean isAttribute) {
if (isAttribute) {
objectTypes.add(type);
} else {
objectTypes.remove(type);
Expand Down Expand Up @@ -305,7 +305,7 @@ public boolean isDataElementGroupAttribute() {
return isAttribute(ObjectType.DATA_ELEMENT_GROUP);
}

public void setDataElementGroupAttribute(Boolean dataElementGroupAttribute) {
public void setDataElementGroupAttribute(boolean dataElementGroupAttribute) {
setAttribute(ObjectType.DATA_ELEMENT_GROUP, dataElementGroupAttribute);
}

Expand All @@ -327,7 +327,7 @@ public boolean isIndicatorGroupAttribute() {
return isAttribute(ObjectType.INDICATOR_GROUP);
}

public void setIndicatorGroupAttribute(Boolean indicatorGroupAttribute) {
public void setIndicatorGroupAttribute(boolean indicatorGroupAttribute) {
setAttribute(ObjectType.INDICATOR_GROUP, indicatorGroupAttribute);
}

Expand All @@ -338,7 +338,7 @@ public boolean isDataSetAttribute() {
return isAttribute(ObjectType.DATA_SET);
}

public void setDataSetAttribute(Boolean dataSetAttribute) {
public void setDataSetAttribute(boolean dataSetAttribute) {
setAttribute(ObjectType.DATA_SET, dataSetAttribute);
}

Expand All @@ -360,7 +360,7 @@ public boolean isOrganisationUnitGroupAttribute() {
return isAttribute(ObjectType.ORGANISATION_UNIT_GROUP);
}

public void setOrganisationUnitGroupAttribute(Boolean organisationUnitGroupAttribute) {
public void setOrganisationUnitGroupAttribute(boolean organisationUnitGroupAttribute) {
setAttribute(ObjectType.ORGANISATION_UNIT_GROUP, organisationUnitGroupAttribute);
}

Expand All @@ -371,7 +371,7 @@ public boolean isOrganisationUnitGroupSetAttribute() {
return isAttribute(ObjectType.ORGANISATION_UNIT_GROUP_SET);
}

public void setOrganisationUnitGroupSetAttribute(Boolean organisationUnitGroupSetAttribute) {
public void setOrganisationUnitGroupSetAttribute(boolean organisationUnitGroupSetAttribute) {
setAttribute(ObjectType.ORGANISATION_UNIT_GROUP_SET, organisationUnitGroupSetAttribute);
}

Expand All @@ -393,7 +393,7 @@ public boolean isUserGroupAttribute() {
return isAttribute(ObjectType.USER_GROUP);
}

public void setUserGroupAttribute(Boolean userGroupAttribute) {
public void setUserGroupAttribute(boolean userGroupAttribute) {
setAttribute(ObjectType.USER_GROUP, userGroupAttribute);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
*/
package org.hisp.dhis.cache;

import java.time.Duration;
import org.hisp.dhis.common.event.ApplicationCacheClearedEvent;
import org.hisp.dhis.common.event.CacheInvalidationEvent;

/**
* The {@link CacheProvider} has a factory method for each {@link Cache} use case in DHIS2.
Expand All @@ -41,7 +41,6 @@
* @author Jan Bernitt
*/
public interface CacheProvider {
<V> Cache<V> createAnalyticsResponseCache(Duration initialExpirationTime);

<V> Cache<V> createAnalyticsCache();

Expand All @@ -55,12 +54,8 @@ public interface CacheProvider {

<V> Cache<V> createInUserOrgUnitHierarchyCache();

<V> Cache<V> createInUserViewOrgUnitHierarchyCache();

<V> Cache<V> createInUserSearchOrgUnitHierarchyCache();

<V> Cache<V> createUserCaptureOrgUnitThresholdCache();

<V> Cache<V> createPeriodIdCache();

<V> Cache<V> createUserFailedLoginAttemptCache(V defaultValue);
Expand All @@ -73,8 +68,6 @@ public interface CacheProvider {

<V> Cache<V> createProgramTempOwnerCache();

<V> Cache<V> createUserIdCache();

<V> Cache<V> createCurrentUserGroupInfoCache();

<V> Cache<V> createAttrOptionComboIdCache();
Expand All @@ -89,8 +82,6 @@ public interface CacheProvider {

<V> Cache<V> createAnalyticsSqlCache();

<V> Cache<V> createDataElementCache();

<V> Cache<V> createPropertyTransformerCache();

<V> Cache<V> createProgramHasRulesCache();
Expand All @@ -101,9 +92,7 @@ public interface CacheProvider {

void handleApplicationCachesCleared(ApplicationCacheClearedEvent event);

<V> Cache<V> createProgramWebHookNotificationTemplateCache();

<V> Cache<V> createProgramStageWebHookNotificationTemplateCache();
void handleCacheInvalidationEvent(CacheInvalidationEvent event);

<V> Cache<V> createProgramOrgUnitAssociationCache();

Expand All @@ -113,8 +102,6 @@ public interface CacheProvider {

<V> Cache<V> createApiKeyCache();

<V> Cache<V> createProgramCache();

<V> Cache<V> createTeAttributesCache();

<V> Cache<V> createProgramTeAttributesCache();
Expand Down
95 changes: 95 additions & 0 deletions dhis-2/dhis-api/src/main/java/org/hisp/dhis/cache/SoftCache.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* 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.cache;

import java.lang.ref.SoftReference;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.function.Supplier;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

/**
* A soft cache uses a concurrent map with {@link java.lang.ref.SoftReference} boxed values.
*
* <p>This means the values might get GC-ed if the JVM needs memory. Therefore, when accessing a
* value by key, a {@link java.util.function.Supplier} needs to be passed in case the value needs
* re-computing.
*
* @author Jan Bernitt
* @since 2.42
*/
public final class SoftCache<T> {

private final ConcurrentMap<String, SoftReference<T>> cache = new ConcurrentHashMap<>();

/**
* Access a cached value by key.
*
* @param key the key to get from the cache, when null the value is computed and not cached
* @param onMiss a function to compute the value on a cache miss; the function must not return
* null
* @return the cached or computed value
*/
@Nonnull
public T get(@CheckForNull String key, @Nonnull Supplier<T> onMiss) {
if (key == null) return onMiss.get();
Supplier<T> memOnMiss = memorize(onMiss);
T res =
cache
.compute(
key,
(k, v) -> {
if (v == null) return new SoftReference<>(memOnMiss.get());
if (v.get() != null) return v;
return new SoftReference<>(memOnMiss.get());
})
.get();
// in theory the get() of the SoftReference can become null
// just when it is returned from the map
// in which case the res is taken directly from the supplier
// since this should mean the JVM is low on memory
return res == null ? memOnMiss.get() : res;
}

/**
* @param onMiss assumed expensive to compute
* @return a supplier that will memorize the result once it has been computed
*/
private Supplier<T> memorize(Supplier<T> onMiss) {
Object[] memorize = new Object[1];
return () -> {
@SuppressWarnings("unchecked")
T v = (T) memorize[0];
if (v != null) return v;
v = onMiss.get();
memorize[0] = v;
return v;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -92,6 +93,10 @@ public void removeCategoryOption(CategoryOption categoryOption) {
categoryOption.getCategories().remove(this);
}

public void removeCategoryOptions(Collection<CategoryOption> categoryOptions) {
categoryOptions.forEach(this::removeCategoryOption);
}

public void removeAllCategoryOptions() {
for (CategoryOption categoryOption : categoryOptions) {
categoryOption.getCategories().remove(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
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.List;
import javax.annotation.Nonnull;
import org.hisp.dhis.common.BaseIdentifiableObject;
import org.hisp.dhis.common.DimensionalEmbeddedObject;
import org.hisp.dhis.common.DxfNamespaces;
Expand Down Expand Up @@ -83,6 +85,18 @@ public void setItems(List<CategoryOption> items) {
this.items = items;
}

public void addItem(CategoryOption item) {
this.getItems().add(item);
}

public void removeItem(CategoryOption item) {
this.getItems().remove(item);
}

public void removeItems(@Nonnull Collection<CategoryOption> items) {
items.forEach(this::removeItem);
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("CategoryDimension{");
Expand Down
Loading

0 comments on commit fa66926

Please sign in to comment.