From 68dac3a3ccfc3b02f3fd990ef0a8f70cca653dfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Wed, 8 Jan 2025 16:17:37 +0100 Subject: [PATCH] chore: Remove unused code (#19623) --- .../hisp/dhis/category/CategoryService.java | 25 ----- .../dhis/dataelement/DataElementService.java | 55 --------- .../dhis/dataelement/DataElementStore.java | 25 ----- .../org/hisp/dhis/dataset/DataSetService.java | 9 -- .../org/hisp/dhis/dataset/DataSetStore.java | 14 --- .../organisationunit/OrganisationUnit.java | 2 +- .../OrganisationUnitService.java | 15 --- .../OrganisationUnitStore.java | 35 +----- .../dhis/category/DefaultCategoryService.java | 39 ------- .../DefaultDataElementService.java | 68 ------------ .../hibernate/HibernateDataElementStore.java | 32 ------ .../dhis/dataset/DefaultDataSetService.java | 7 -- .../hibernate/HibernateDataSetStore.java | 15 --- .../DefaultOrganisationUnitService.java | 43 -------- .../HibernateOrganisationUnitStore.java | 104 ------------------ .../DefaultDataSetMetadataExportService.java | 3 - .../dhis/category/CategoryServiceTest.java | 28 ----- .../dataelement/DataElementServiceTest.java | 25 ----- .../dataelement/DataElementStoreTest.java | 38 ------- .../hisp/dhis/dataset/DataSetStoreTest.java | 11 -- 20 files changed, 5 insertions(+), 588 deletions(-) diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/category/CategoryService.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/category/CategoryService.java index 01286d776196..1e1609a6b141 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/category/CategoryService.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/category/CategoryService.java @@ -110,13 +110,6 @@ public interface CategoryService { */ Category getCategoryByName(String name, UserDetails userDetails); - /** - * Returns all DataElementCategories. - * - * @return a list of all DataElementCategories. - */ - List getAllDataElementCategories(); - /** * Retrieves all DataElementCategories of dimension type disaggregation. * @@ -330,24 +323,6 @@ SetValuedMap getCategoryOptionOrganisationUnitsAssociations( */ List getAttributeCategoryCombos(); - /** - * Validates the category combo. Possible return values are: - * - *

- * - *

    - *
  • category_combo_is_null - *
  • category_combo_must_have_at_least_one_category - *
  • category_combo_cannot_have_duplicate_categories - *
  • categories_must_have_at_least_one_category_option - *
  • categories_cannot_share_category_options - *
- * - * @param categoryCombo the category combo to validate. - * @return null if valid, non-empty string if invalid. - */ - String validateCategoryCombo(CategoryCombo categoryCombo); - // ------------------------------------------------------------------------- // CategoryOptionCombo // ------------------------------------------------------------------------- diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java index 9d05b329c1a5..7dd807f2bc38 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java @@ -30,12 +30,8 @@ import java.util.Collection; import java.util.List; import javax.annotation.Nonnull; -import org.hisp.dhis.category.CategoryCombo; import org.hisp.dhis.common.IllegalQueryException; -import org.hisp.dhis.common.UID; -import org.hisp.dhis.common.ValueType; import org.hisp.dhis.hierarchy.HierarchyViolationException; -import org.hisp.dhis.period.PeriodType; /** * Defines service functionality for DataElements and DataElementGroups. @@ -110,39 +106,6 @@ public interface DataElementService { */ List getAllDataElements(); - /** - * Returns all DataElements of a given type. - * - * @param valueType the value type restriction - * @return a list of all DataElements with the given value type, or an empty list if there are no - * DataElements. - */ - List getAllDataElementsByValueType(ValueType valueType); - - /** - * Returns all DataElements with the given domain type. - * - * @param domainType the DataElementDomainType. - * @return all DataElements with the given domainType. - */ - List getDataElementsByDomainType(DataElementDomain domainType); - - /** - * Returns the DataElements with the given PeriodType. - * - * @param periodType the PeriodType. - * @return a list of DataElements. - */ - List getDataElementsByPeriodType(PeriodType periodType); - - /** - * Returns all DataElements with the given category combo. - * - * @param categoryCombo the CategoryCombo. - * @return all DataElements with the given category combo. - */ - List getDataElementByCategoryCombo(CategoryCombo categoryCombo); - /** * Returns all DataElements which are not member of any DataElementGroups. * @@ -246,14 +209,6 @@ public interface DataElementService { */ List getAllDataElementGroups(); - /** - * Returns all DataElements which zeroIsSignificant property is true or false. - * - * @param zeroIsSignificant whether zero is significant is true for this query. - * @return a collection of DataElements. - */ - List getDataElementsByZeroIsSignificant(boolean zeroIsSignificant); - // ------------------------------------------------------------------------- // DataElementGroupSet // ------------------------------------------------------------------------- @@ -267,14 +222,4 @@ public interface DataElementService { DataElementGroupSet getDataElementGroupSet(long id); DataElementGroupSet getDataElementGroupSet(String uid); - - DataElementGroupSet getDataElementGroupSetByName(String name); - - List getAllDataElementGroupSets(); - - List getByAttributeAndValue(UID attribute, String value); - - List getByAttribute(UID attribute); - - DataElement getByUniqueAttributeValue(UID attribute, String value); } diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementStore.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementStore.java index d82afe928b27..8065ad0a3f81 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementStore.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementStore.java @@ -30,7 +30,6 @@ import java.util.List; import org.hisp.dhis.category.CategoryCombo; import org.hisp.dhis.common.GenericDimensionalObjectStore; -import org.hisp.dhis.common.ValueType; import org.hisp.dhis.user.User; /** @@ -53,30 +52,6 @@ public interface DataElementStore extends GenericDimensionalObjectStore getDataElementByCategoryCombo(CategoryCombo categoryCombo); - /** - * Returns all DataElement which zeroIsSignificant property is true or false - * - * @param zeroIsSignificant is zeroIsSignificant property - * @return a collection of all DataElement - */ - List getDataElementsByZeroIsSignificant(boolean zeroIsSignificant); - - /** - * Returns all DataElements of the given domain type. - * - * @param domainType the domain type. - * @return all DataElements of the given domain type. - */ - List getDataElementsByDomainType(DataElementDomain domainType); - - /** - * Returns all DataElements of the given value type. - * - * @param valueType the value type. - * @return all DataElements of the given value type. - */ - List getDataElementsByValueType(ValueType valueType); - /** * Returns all DataElements which are not member of any DataElementGroups. * diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetService.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetService.java index b79d9218cd38..9cc80d7be245 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetService.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetService.java @@ -35,7 +35,6 @@ import org.hisp.dhis.dataentryform.DataEntryForm; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.period.Period; -import org.hisp.dhis.period.PeriodType; import org.hisp.dhis.user.User; import org.hisp.dhis.user.UserDetails; @@ -108,14 +107,6 @@ public interface DataSetService extends DataSetDataIntegrityProvider { */ List getAllDataSets(); - /** - * Gets all DataSets associated with the given PeriodType. - * - * @param periodType the PeriodType. - * @return a list of DataSets. - */ - List getDataSetsByPeriodType(PeriodType periodType); - /** * Returns the data sets which given user have READ access. If the current user has the ALL * authority then all data sets are returned. diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetStore.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetStore.java index b2f4de66224d..c777c3d592c0 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetStore.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetStore.java @@ -32,26 +32,12 @@ import org.hisp.dhis.common.IdentifiableObjectStore; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.dataentryform.DataEntryForm; -import org.hisp.dhis.period.PeriodType; /** * @author Kristian Nordal */ public interface DataSetStore extends IdentifiableObjectStore, DataSetDataIntegrityProvider { - String ID = DataSetStore.class.getName(); - - // ------------------------------------------------------------------------- - // DataSet - // ------------------------------------------------------------------------- - - /** - * Gets all DataSets associated with the given PeriodType. - * - * @param periodType the PeriodType. - * @return a list of DataSets. - */ - List getDataSetsByPeriodType(PeriodType periodType); /** * Gets all DataSets associated with the given DataEntryForm. diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java index b64446845041..a15fa029b590 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java @@ -136,7 +136,7 @@ public class OrganisationUnit extends BaseDimensionalItemObject private Geometry geometry; - /** A reference to the Image file associated with this OrganisationUnit. */ + /** A reference to the image file resource associated with this {@link OrganisationUnit}. */ private FileResource image; // ------------------------------------------------------------------------- diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java index 5b3dde26e685..07a740575b23 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java @@ -307,8 +307,6 @@ List getOrganisationUnitsAtLevels( Long getOrganisationUnitHierarchyMemberCount( OrganisationUnit parent, Object member, String collectionName) throws BadRequestException; - OrganisationUnitDataSetAssociationSet getOrganisationUnitDataSetAssociationSet(User user); - /** * Returns the level of the given org unit level. The level parameter string can either represent * a numerical level, or a UID referring to an {@link OrganisationUnitLevel} object. @@ -385,19 +383,6 @@ List getOrganisationUnitByCoordinate( @Deprecated(forRemoval = true) boolean isInUserDataViewHierarchy(User user, OrganisationUnit organisationUnit); - /** - * Equal to {@link OrganisationUnitService#isInUserSearchHierarchy(User, OrganisationUnit)} except - * adds a caching layer on top. Use this method when performance is imperative and the risk of a - * stale result is tolerable. - * - * @param user the user to check for. - * @param organisationUnit the organisation unit. - * @return true if the given organisation unit is part of the hierarchy. - * @deprecated Use {@link org.hisp.dhis.user.UserDetails#isInUserSearchHierarchy(String)} instead - */ - @Deprecated(forRemoval = true) - boolean isInUserSearchHierarchyCached(User user, OrganisationUnit organisationUnit); - /** * @deprecated Use {@link org.hisp.dhis.user.UserDetails#isInUserSearchHierarchy(String)} instead */ diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitStore.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitStore.java index f35af4770f09..fa0df1fcecd5 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitStore.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitStore.java @@ -30,8 +30,6 @@ import java.util.Collection; import java.util.Date; import java.util.List; -import java.util.Map; -import java.util.Set; import org.hisp.dhis.common.IdentifiableObjectStore; import org.hisp.dhis.dataset.DataSet; import org.hisp.dhis.program.Program; @@ -130,18 +128,6 @@ Long getOrganisationUnitHierarchyMemberCount( */ List getOrganisationUnits(OrganisationUnitQueryParams params); - /** - * Creates a mapping between organisation unit UID and set of data set UIDs being assigned to the - * organisation unit. - * - * @param organisationUnits the parent organisation units of the hierarchy to include, ignored if - * null. - * @param dataSets the data set to include, ignored if null. - * @return a map of sets. - */ - Map> getOrganisationUnitDataSetAssocationMap( - Collection organisationUnits, Collection dataSets); - /** * Retrieves the objects where its coordinate is within the 4 area points. 4 area points are Index * 0: Maximum latitude (north edge of box shape) Index 1: Maxium longitude (east edge of box @@ -153,8 +139,10 @@ Map> getOrganisationUnitDataSetAssocationMap( */ List getWithinCoordinateArea(double[] box); + /** Updates the path property of all org units. */ void updatePaths(); + /** Explicitly updates the path property of all org units. */ void forceUpdatePaths(); /** @@ -166,25 +154,10 @@ Map> getOrganisationUnitDataSetAssocationMap( int getMaxLevel(); /** - * Check if the number of orgunits that satisfies the conditions in the queryParams is greater - * than the threshold provided. Note: groups, maxLevels and levels are not supported yet. + * Sets the geometry field for org units to null. * - * @param params The Org unit query params - * @param threshold the threshold count to check against - * @return true if the org units satisfying the params criteria is above the threshold, false - * otherwise. + * @return then number of affected org units. */ - boolean isOrgUnitCountAboveThreshold(OrganisationUnitQueryParams params, int threshold); - - /** - * Get list of organisation unit uids satisfying the query params. Note: groups, maxLevels and - * levels are not supported yet. - * - * @param params The Org unit query params - * @return the list of org unit uids satisfying the params criteria - */ - List getOrganisationUnitUids(OrganisationUnitQueryParams params); - int updateAllOrganisationUnitsGeometryToNull(); /** diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/category/DefaultCategoryService.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/category/DefaultCategoryService.java index 14a2873596f1..5de0e136c343 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/category/DefaultCategoryService.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/category/DefaultCategoryService.java @@ -28,7 +28,6 @@ package org.hisp.dhis.category; import com.google.common.collect.Lists; -import com.google.common.collect.Sets; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; @@ -132,12 +131,6 @@ public void deleteCategory(Category dataElementCategory) { categoryStore.delete(dataElementCategory); } - @Override - @Transactional(readOnly = true) - public List getAllDataElementCategories() { - return categoryStore.getAll(); - } - @Override @Transactional(readOnly = true) public Category getCategory(long id) { @@ -421,38 +414,6 @@ public List getAttributeCategoryCombos() { return categoryComboStore.getCategoryCombosByDimensionType(DataDimensionType.ATTRIBUTE); } - @Override - @Transactional(readOnly = true) - public String validateCategoryCombo(CategoryCombo categoryCombo) { - if (categoryCombo == null) { - return "category_combo_is_null"; - } - - if (categoryCombo.getCategories() == null || categoryCombo.getCategories().isEmpty()) { - return "category_combo_must_have_at_least_one_category"; - } - - if (Sets.newHashSet(categoryCombo.getCategories()).size() - < categoryCombo.getCategories().size()) { - return "category_combo_cannot_have_duplicate_categories"; - } - - Set categoryOptions = new HashSet<>(); - - for (Category category : categoryCombo.getCategories()) { - if (category == null || category.getCategoryOptions().isEmpty()) { - return "categories_must_have_at_least_one_category_option"; - } - - if (!Sets.intersection(categoryOptions, Sets.newHashSet(category.getCategoryOptions())) - .isEmpty()) { - return "categories_cannot_share_category_options"; - } - } - - return null; - } - // ------------------------------------------------------------------------- // CategoryOptionCombo // ------------------------------------------------------------------------- diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java index c37fa43fee1a..2894c1d670a9 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java @@ -29,20 +29,16 @@ import java.util.Collection; import java.util.List; -import java.util.stream.Collectors; import javax.annotation.Nonnull; import lombok.RequiredArgsConstructor; -import org.hisp.dhis.category.CategoryCombo; import org.hisp.dhis.common.GenericDimensionalObjectStore; import org.hisp.dhis.common.IdentifiableObjectStore; import org.hisp.dhis.common.IllegalQueryException; -import org.hisp.dhis.common.UID; import org.hisp.dhis.common.ValueType; import org.hisp.dhis.feedback.ErrorCode; import org.hisp.dhis.feedback.ErrorMessage; import org.hisp.dhis.option.Option; import org.hisp.dhis.option.OptionSet; -import org.hisp.dhis.period.PeriodType; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -142,38 +138,6 @@ public List getAllDataElements() { return dataElementStore.getAll(); } - @Override - @Transactional(readOnly = true) - public List getAllDataElementsByValueType(ValueType valueType) { - return dataElementStore.getDataElementsByValueType(valueType); - } - - @Override - @Transactional(readOnly = true) - public List getDataElementsByZeroIsSignificant(boolean zeroIsSignificant) { - return dataElementStore.getDataElementsByZeroIsSignificant(zeroIsSignificant); - } - - @Override - @Transactional(readOnly = true) - public List getDataElementsByPeriodType(final PeriodType periodType) { - return getAllDataElements().stream() - .filter(p -> p.getPeriodType() != null && p.getPeriodType().equals(periodType)) - .collect(Collectors.toList()); - } - - @Override - @Transactional(readOnly = true) - public List getDataElementsByDomainType(DataElementDomain domainType) { - return dataElementStore.getDataElementsByDomainType(domainType); - } - - @Override - @Transactional(readOnly = true) - public List getDataElementByCategoryCombo(CategoryCombo categoryCombo) { - return dataElementStore.getDataElementByCategoryCombo(categoryCombo); - } - @Override @Transactional(readOnly = true) public List getDataElementsWithoutGroups() { @@ -295,36 +259,4 @@ public DataElementGroupSet getDataElementGroupSet(long id) { public DataElementGroupSet getDataElementGroupSet(String uid) { return dataElementGroupSetStore.getByUid(uid); } - - @Override - @Transactional(readOnly = true) - public DataElementGroupSet getDataElementGroupSetByName(String name) { - List dataElementGroupSets = dataElementGroupSetStore.getAllEqName(name); - - return !dataElementGroupSets.isEmpty() ? dataElementGroupSets.get(0) : null; - } - - @Override - @Transactional(readOnly = true) - public List getAllDataElementGroupSets() { - return dataElementGroupSetStore.getAll(); - } - - @Override - @Transactional(readOnly = true) - public List getByAttributeAndValue(UID attribute, String value) { - return dataElementStore.getByAttributeAndValue(attribute, value); - } - - @Override - @Transactional(readOnly = true) - public List getByAttribute(UID attribute) { - return dataElementStore.getByAttribute(attribute); - } - - @Override - @Transactional(readOnly = true) - public DataElement getByUniqueAttributeValue(UID attribute, String value) { - return dataElementStore.getByUniqueAttributeValue(attribute, value); - } } diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java index d271ac4f22ee..0c29da27e7b2 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java @@ -33,9 +33,7 @@ import jakarta.persistence.criteria.Root; import java.util.List; import java.util.function.Function; -import lombok.extern.slf4j.Slf4j; import org.hisp.dhis.category.CategoryCombo; -import org.hisp.dhis.common.ValueType; import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.dataelement.DataElementDomain; @@ -51,7 +49,6 @@ /** * @author Torgeir Lorange Ostby */ -@Slf4j @Repository("org.hisp.dhis.dataelement.DataElementStore") public class HibernateDataElementStore extends HibernateIdentifiableObjectStore implements DataElementStore { @@ -67,24 +64,6 @@ public HibernateDataElementStore( // DataElement // ------------------------------------------------------------------------- - @Override - public List getDataElementsByDomainType(DataElementDomain domainType) { - CriteriaBuilder builder = getCriteriaBuilder(); - - return getList( - builder, - newJpaParameters().addPredicate(root -> builder.equal(root.get("domainType"), domainType))); - } - - @Override - public List getDataElementsByValueType(ValueType valueType) { - CriteriaBuilder builder = getCriteriaBuilder(); - - return getList( - builder, - newJpaParameters().addPredicate(root -> builder.equal(root.get("valueType"), valueType))); - } - @Override public List getDataElementByCategoryCombo(CategoryCombo categoryCombo) { CriteriaBuilder builder = getCriteriaBuilder(); @@ -95,17 +74,6 @@ public List getDataElementByCategoryCombo(CategoryCombo categoryCom .addPredicate(root -> builder.equal(root.get("categoryCombo"), categoryCombo))); } - @Override - public List getDataElementsByZeroIsSignificant(boolean zeroIsSignificant) { - CriteriaBuilder builder = getCriteriaBuilder(); - - return getList( - builder, - newJpaParameters() - .addPredicate(root -> builder.equal(root.get("zeroIsSignificant"), zeroIsSignificant)) - .addPredicate(root -> root.get("valueType").in(ValueType.NUMERIC_TYPES))); - } - @Override public List getDataElementsWithoutGroups() { String hql = "from DataElement d where size(d.groups) = 0"; diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java index 20254f48a893..63a1a22f9492 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java @@ -45,7 +45,6 @@ import org.hisp.dhis.dataentryform.DataEntryForm; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.period.Period; -import org.hisp.dhis.period.PeriodType; import org.hisp.dhis.query.QueryParserException; import org.hisp.dhis.security.Authorities; import org.hisp.dhis.user.CurrentUserUtil; @@ -123,12 +122,6 @@ public List getAllDataSets() { return dataSetStore.getAll(); } - @Override - @Transactional(readOnly = true) - public List getDataSetsByPeriodType(PeriodType periodType) { - return dataSetStore.getDataSetsByPeriodType(periodType); - } - @Override @Transactional(readOnly = true) public List getUserDataRead(@Nonnull UserDetails user) { diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateDataSetStore.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateDataSetStore.java index 74a1673a7303..09f1850576f4 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateDataSetStore.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateDataSetStore.java @@ -31,7 +31,6 @@ import com.google.common.collect.Lists; import jakarta.persistence.EntityManager; -import jakarta.persistence.criteria.CriteriaBuilder; import java.util.Collection; import java.util.List; import javax.annotation.Nonnull; @@ -42,7 +41,6 @@ import org.hisp.dhis.dataset.DataSet; import org.hisp.dhis.dataset.DataSetElement; import org.hisp.dhis.dataset.DataSetStore; -import org.hisp.dhis.hibernate.JpaQueryParameters; import org.hisp.dhis.period.PeriodService; import org.hisp.dhis.period.PeriodType; import org.hisp.dhis.security.acl.AclService; @@ -97,19 +95,6 @@ public void update(@Nonnull DataSet dataSet) { super.update(dataSet); } - @Override - public List getDataSetsByPeriodType(PeriodType periodType) { - PeriodType refreshedPeriodType = periodService.reloadPeriodType(periodType); - - CriteriaBuilder builder = getCriteriaBuilder(); - - JpaQueryParameters parameters = - newJpaParameters() - .addPredicate(root -> builder.equal(root.get("periodType"), refreshedPeriodType)); - - return getList(builder, parameters); - } - @Override public List getDataSetsByDataEntryForm(DataEntryForm dataEntryForm) { if (dataEntryForm == null) { diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java index 7a3bf1cc9eeb..4342ec0960ec 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java @@ -53,7 +53,6 @@ import org.hisp.dhis.commons.collection.ListUtils; import org.hisp.dhis.commons.filter.FilterUtils; import org.hisp.dhis.configuration.ConfigurationService; -import org.hisp.dhis.dataset.DataSet; import org.hisp.dhis.expression.ExpressionService; import org.hisp.dhis.feedback.BadRequestException; import org.hisp.dhis.hierarchy.HierarchyViolationException; @@ -73,12 +72,10 @@ public class DefaultOrganisationUnitService implements OrganisationUnitService { private static final String LEVEL_PREFIX = "Level "; private final OrganisationUnitStore organisationUnitStore; - private final IdentifiableObjectManager idObjectManager; private final OrganisationUnitLevelStore organisationUnitLevelStore; private final ConfigurationService configurationService; private final Cache inUserOrgUnitHierarchyCache; - private final Cache inUserOrgUnitSearchHierarchyCache; public DefaultOrganisationUnitService( OrganisationUnitStore organisationUnitStore, @@ -94,13 +91,10 @@ public DefaultOrganisationUnitService( checkNotNull(cacheProvider); this.organisationUnitStore = organisationUnitStore; - this.idObjectManager = idObjectManager; this.organisationUnitLevelStore = organisationUnitLevelStore; this.configurationService = configurationService; this.inUserOrgUnitHierarchyCache = cacheProvider.createInUserOrgUnitHierarchyCache(); - this.inUserOrgUnitSearchHierarchyCache = - cacheProvider.createInUserSearchOrgUnitHierarchyCache(); } // ------------------------------------------------------------------------- @@ -362,34 +356,6 @@ public Long getOrganisationUnitHierarchyMemberCount( parent, member, collectionName); } - @Override - @Transactional(readOnly = true) - public OrganisationUnitDataSetAssociationSet getOrganisationUnitDataSetAssociationSet(User user) { - - Set organisationUnits = user != null ? user.getOrganisationUnits() : null; - List dataSets = idObjectManager.getDataWriteAll(DataSet.class); - - Map> associationSet = - organisationUnitStore.getOrganisationUnitDataSetAssocationMap(organisationUnits, dataSets); - - OrganisationUnitDataSetAssociationSet set = new OrganisationUnitDataSetAssociationSet(); - - for (Map.Entry> entry : associationSet.entrySet()) { - int index = set.getDataSetAssociationSets().indexOf(entry.getValue()); - - if (index == -1) // Association set does not exist, add new - { - index = set.getDataSetAssociationSets().size(); - set.getDataSetAssociationSets().add(entry.getValue()); - } - - set.getOrganisationUnitAssociationSetMap().put(entry.getKey(), index); - set.getDistinctDataSets().addAll(entry.getValue()); - } - - return set; - } - @Override @Transactional(readOnly = true) public boolean isInUserHierarchyCached(User user, OrganisationUnit organisationUnit) { @@ -424,15 +390,6 @@ public boolean isInUserDataViewHierarchy(User user, OrganisationUnit organisatio return organisationUnit.isDescendant(user.getDataViewOrganisationUnitsWithFallback()); } - @Override - @Transactional(readOnly = true) - public boolean isInUserSearchHierarchyCached(User user, OrganisationUnit organisationUnit) { - String cacheKey = joinHyphen(user.getUsername(), organisationUnit.getUid()); - - return inUserOrgUnitSearchHierarchyCache.get( - cacheKey, ou -> isInUserSearchHierarchy(user, organisationUnit)); - } - @Override @Transactional(readOnly = true) public boolean isInUserSearchHierarchy(User user, OrganisationUnit organisationUnit) { diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java index d45785e0a15d..a7a39218a51c 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java @@ -29,42 +29,33 @@ import static com.google.common.base.Preconditions.checkNotNull; import static java.util.stream.Collectors.toSet; -import static org.hisp.dhis.system.util.SqlUtils.escape; import jakarta.persistence.EntityManager; import java.util.ArrayList; import java.util.Collection; import java.util.Date; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.Set; import javax.annotation.Nonnull; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.hibernate.Session; import org.hibernate.query.Query; import org.hisp.dhis.common.IdentifiableObjectUtils; import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore; import org.hisp.dhis.commons.util.SqlHelper; import org.hisp.dhis.commons.util.TextUtils; -import org.hisp.dhis.dataset.DataSet; import org.hisp.dhis.dbms.DbmsManager; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.organisationunit.OrganisationUnitQueryParams; import org.hisp.dhis.organisationunit.OrganisationUnitStore; import org.hisp.dhis.program.Program; import org.hisp.dhis.security.acl.AclService; -import org.hisp.dhis.system.util.SqlUtils; import org.springframework.context.ApplicationEventPublisher; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; -import org.springframework.util.Assert; /** * @author Kristian Nordal */ -@Slf4j @Repository("org.hisp.dhis.organisationunit.OrganisationUnitStore") public class HibernateOrganisationUnitStore extends HibernateIdentifiableObjectStore implements OrganisationUnitStore { @@ -281,57 +272,6 @@ public List getOrganisationUnits(OrganisationUnitQueryParams p return query.list(); } - @Override - public Map> getOrganisationUnitDataSetAssocationMap( - Collection organisationUnits, Collection dataSets) { - SqlHelper hlp = new SqlHelper(); - - String sql = - "select ou.uid as ou_uid, array_agg(ds.uid) as ds_uid " - + "from datasetsource d " - + "inner join organisationunit ou on ou.organisationunitid=d.sourceid " - + "inner join dataset ds on ds.datasetid=d.datasetid "; - - if (organisationUnits != null) { - Assert.notEmpty(organisationUnits, "Organisation units cannot be empty"); - - sql += hlp.whereAnd() + " ("; - - for (OrganisationUnit unit : organisationUnits) { - sql += "ou.path like '" + unit.getPath() + "%' or "; - } - - sql = TextUtils.removeLastOr(sql) + ") "; - } - - if (dataSets != null) { - Assert.notEmpty(dataSets, "Data sets cannot be empty"); - - sql += - hlp.whereAnd() - + " ds.datasetid in (" - + StringUtils.join(IdentifiableObjectUtils.getIdentifiers(dataSets), ",") - + ") "; - } - - sql += "group by ou_uid"; - - log.debug("Org unit data set association map SQL: " + sql); - - Map> map = new HashMap<>(); - - jdbcTemplate.query( - sql, - rs -> { - String organisationUnitId = rs.getString("ou_uid"); - Set dataSetIds = SqlUtils.getArrayAsSet(rs, "ds_uid"); - - map.put(organisationUnitId, dataSetIds); - }); - - return map; - } - @Override public List getWithinCoordinateArea(double[] box) { // can't use hibernate-spatial 'makeenvelope' function, because not @@ -384,26 +324,6 @@ public int getMaxLevel() { return maxLength != null ? maxLength : 0; } - @Override - public boolean isOrgUnitCountAboveThreshold(OrganisationUnitQueryParams params, int threshold) { - String sql = buildOrganisationUnitDistinctUidsSql(params); - - StringBuilder sb = new StringBuilder(); - sb.append("select count(*) from ("); - sb.append(sql); - sb.append(" limit "); - sb.append(threshold + 1); - sb.append(") as douid"); - - return (jdbcTemplate.queryForObject(sb.toString(), Integer.class) > threshold); - } - - @Override - public List getOrganisationUnitUids(OrganisationUnitQueryParams params) { - String sql = buildOrganisationUnitDistinctUidsSql(params); - return jdbcTemplate.queryForList(sql, String.class); - } - @Override public int updateAllOrganisationUnitsGeometryToNull() { return getQuery("update OrganisationUnit o set o.geometry = null").executeUpdate(); @@ -423,30 +343,6 @@ public List getByCategoryOption(@Nonnull Collection ca .getResultList(); } - private String buildOrganisationUnitDistinctUidsSql(OrganisationUnitQueryParams params) { - SqlHelper hlp = new SqlHelper(); - - String sql = "select distinct o.uid from organisationunit o "; - - if (params.isFetchChildren()) { - sql += " left outer join organisationunit c ON o.organisationunitid = c.parentid "; - } - - if (params.hasParents()) { - sql += hlp.whereAnd() + " ("; - - for (OrganisationUnit parent : params.getParents()) { - sql += "o.path like '" + escape(parent.getPath()) + "%'" + " or "; - } - - sql = TextUtils.removeLastOr(sql) + ") "; - } - - // TODO: Support Groups + Query + Hierarchy + MaxLevels in this sql - - return sql; - } - private void updatePaths(List organisationUnits) { Session session = getSession(); int counter = 0; diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultDataSetMetadataExportService.java b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultDataSetMetadataExportService.java index 35c5c26c27c9..8e60e6ff0b40 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultDataSetMetadataExportService.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultDataSetMetadataExportService.java @@ -72,7 +72,6 @@ import org.hisp.dhis.schema.descriptors.OptionSetSchemaDescriptor; import org.hisp.dhis.user.CurrentUserUtil; import org.hisp.dhis.user.UserDetails; -import org.hisp.dhis.user.UserService; import org.hisp.dhis.util.DateUtils; import org.springframework.stereotype.Service; @@ -136,8 +135,6 @@ public class DefaultDataSetMetadataExportService implements DataSetMetadataExpor private final ExpressionService expressionService; - private final UserService userService; - @Override public ObjectNode getDataSetMetadata() { UserDetails currentUserDetails = CurrentUserUtil.getCurrentUserDetails(); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/category/CategoryServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/category/CategoryServiceTest.java index f62af477abc7..fc2aba9673d3 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/category/CategoryServiceTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/category/CategoryServiceTest.java @@ -160,22 +160,6 @@ void testDeleteCategoryOption() { assertTrue(categoryService.getCategoryOption(optionIdA).getCategories().contains(categoryB)); } - @Test - void testGetAll() { - categoryA = createCategory('A'); - categoryB = createCategory('B'); - categoryC = createCategory('C'); - categoryService.addCategory(categoryA); - categoryService.addCategory(categoryB); - categoryService.addCategory(categoryC); - List categories = categoryService.getAllDataElementCategories(); - // Including default - assertEquals(4, categories.size()); - assertTrue(categories.contains(categoryA)); - assertTrue(categories.contains(categoryB)); - assertTrue(categories.contains(categoryC)); - } - @Test void testAddGetCategoryGroup() { CategoryOptionGroup groupA = createCategoryOptionGroup('A'); @@ -304,18 +288,6 @@ void testGetDisaggregationCategoryOptionGroupSetsNoAcl() { assertEquals(1, categoryService.getDisaggregationCategoryOptionGroupSetsNoAcl().size()); } - @Test - void testGetDisaggregationCategories() { - categoryA = createCategory('A', categoryOptionA, categoryOptionB, categoryOptionC); - categoryA.setDataDimensionType(DataDimensionType.DISAGGREGATION); - categoryService.addCategory(categoryA); - // Default Category is created so count should be equal 2 - assertEquals(2, categoryService.getDisaggregationCategories().size()); - assertEquals(1, categoryStore.getCategories(DataDimensionType.DISAGGREGATION, true).size()); - assertEquals( - 1, categoryStore.getCategoriesNoAcl(DataDimensionType.DISAGGREGATION, true).size()); - } - @Test void testAddAndPruneAllCategoryCombos() { categoryA = createCategory('A', categoryOptionA, categoryOptionB); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dataelement/DataElementServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dataelement/DataElementServiceTest.java index 6b1e40c9f922..eb5283bc8b2e 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dataelement/DataElementServiceTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dataelement/DataElementServiceTest.java @@ -251,31 +251,6 @@ void testGetAllDataElements() { assertTrue(dataElements.containsAll(dataElementsRef)); } - @Test - void testGetAllDataElementsByType() { - assertEquals(0, dataElementService.getAllDataElements().size()); - DataElement dataElementA = createDataElement('A'); - DataElement dataElementB = createDataElement('B'); - DataElement dataElementC = createDataElement('C'); - DataElement dataElementD = createDataElement('D'); - dataElementA.setValueType(ValueType.FILE_RESOURCE); - dataElementB.setValueType(ValueType.EMAIL); - dataElementC.setValueType(ValueType.BOOLEAN); - dataElementD.setValueType(ValueType.FILE_RESOURCE); - dataElementService.addDataElement(dataElementA); - dataElementService.addDataElement(dataElementB); - dataElementService.addDataElement(dataElementC); - dataElementService.addDataElement(dataElementD); - List dataElementsRef = new ArrayList<>(); - dataElementsRef.add(dataElementA); - dataElementsRef.add(dataElementD); - List dataElements = - dataElementService.getAllDataElementsByValueType(ValueType.FILE_RESOURCE); - assertNotNull(dataElements); - assertEquals(dataElementsRef.size(), dataElements.size()); - assertTrue(dataElements.containsAll(dataElementsRef)); - } - // ------------------------------------------------------------------------- // DataElementGroup // ------------------------------------------------------------------------- diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dataelement/DataElementStoreTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dataelement/DataElementStoreTest.java index 42313bcd8286..03013401fef8 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dataelement/DataElementStoreTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dataelement/DataElementStoreTest.java @@ -154,28 +154,6 @@ void testGetAllDataElements() { assertTrue(dataElements.containsAll(dataElementsRef)); } - @Test - void testGetDataElementsByDomainType() { - assertEquals( - 0, dataElementStore.getDataElementsByDomainType(DataElementDomain.AGGREGATE).size()); - assertEquals(0, dataElementStore.getDataElementsByDomainType(DataElementDomain.TRACKER).size()); - DataElement dataElementA = createDataElement('A'); - dataElementA.setDomainType(DataElementDomain.AGGREGATE); - DataElement dataElementB = createDataElement('B'); - dataElementB.setDomainType(DataElementDomain.TRACKER); - DataElement dataElementC = createDataElement('C'); - dataElementC.setDomainType(DataElementDomain.TRACKER); - DataElement dataElementD = createDataElement('D'); - dataElementD.setDomainType(DataElementDomain.TRACKER); - dataElementStore.save(dataElementA); - dataElementStore.save(dataElementB); - dataElementStore.save(dataElementC); - dataElementStore.save(dataElementD); - assertEquals( - 1, dataElementStore.getDataElementsByDomainType(DataElementDomain.AGGREGATE).size()); - assertEquals(3, dataElementStore.getDataElementsByDomainType(DataElementDomain.TRACKER).size()); - } - @Test void testGetDataElementAggregationLevels() { List aggregationLevels = Arrays.asList(3, 5); @@ -233,22 +211,6 @@ void testGetDataElementsByAggregationLevel() { assertTrue(dataElements.contains(dataElementB)); } - @Test - void testGetDataElementsZeroIsSignificant() { - DataElement dataElementA = createDataElement('A'); - DataElement dataElementB = createDataElement('B'); - DataElement dataElementC = createDataElement('C'); - DataElement dataElementD = createDataElement('D'); - dataElementA.setZeroIsSignificant(true); - dataElementB.setZeroIsSignificant(true); - dataElementStore.save(dataElementA); - dataElementStore.save(dataElementB); - dataElementStore.save(dataElementC); - dataElementStore.save(dataElementD); - List dataElements = dataElementStore.getDataElementsByZeroIsSignificant(true); - assertTrue(equals(dataElements, dataElementA, dataElementB)); - } - @Test void testDataElementByNonUniqueAttributeValue() throws NonUniqueAttributeValueException { Attribute attribute = new Attribute("cid", ValueType.TEXT); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dataset/DataSetStoreTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dataset/DataSetStoreTest.java index 5d5f97b31d6e..69785683fbdc 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dataset/DataSetStoreTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dataset/DataSetStoreTest.java @@ -127,17 +127,6 @@ void testGetAllDataSets() { assertContainsOnly(List.of(dataSetA, dataSetB), dataSetStore.getAll()); } - @Test - void testGetDataSetByPeriodType() { - List types = PeriodType.getAvailablePeriodTypes(); - PeriodType periodType1 = types.get(0); - PeriodType periodType2 = types.get(1); - DataSet dataSetA = addDataSet('A', periodType1); - DataSet dataSetB = addDataSet('B', periodType2); - assertContainsOnly(List.of(dataSetA), dataSetStore.getDataSetsByPeriodType(periodType1)); - assertContainsOnly(List.of(dataSetB), dataSetStore.getDataSetsByPeriodType(periodType2)); - } - @Test void testGetByDataEntryForm() { DataSet dataSetA = addDataSet('A');