From 4b581cc09595f50decfea50a7718567f1868009e Mon Sep 17 00:00:00 2001 From: David Mackessy Date: Mon, 16 Dec 2024 14:51:10 +0000 Subject: [PATCH] feat: Add javadoc and clean up [DHIS2-18321] --- .../dhis/category/CategoryComboStore.java | 7 ++++++ .../dhis/category/CategoryOptionStore.java | 10 +++++++- .../hisp/dhis/category/CategoryService.java | 5 ++-- .../dhis/dataapproval/DataApprovalStore.java | 11 +++++++++ .../dataelement/DataElementOperandStore.java | 14 +++++++++++ .../CompleteDataSetRegistrationStore.java | 12 ++++++++++ .../dhis/datavalue/DataValueAuditStore.java | 3 ++- .../hisp/dhis/datavalue/DataValueStore.java | 21 +++++++++++++++++ .../dhis/minmax/MinMaxDataElementStore.java | 9 ++++++++ .../hisp/dhis/predictor/PredictorStore.java | 8 +++++++ .../org/hisp/dhis/program/EventStore.java | 12 ++++++++++ .../dhis/merge/CommonDataMergeHandler.java | 18 +++++++++++---- .../DataCategoryOptionComboMergeHandler.java | 23 +++++++++++++++---- .../dhis/category/DefaultCategoryService.java | 4 ++-- .../hibernate/HibernateDataValueStore.java | 8 +++---- 15 files changed, 146 insertions(+), 19 deletions(-) diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/category/CategoryComboStore.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/category/CategoryComboStore.java index 7bb06207543b..1eb0aa76c45d 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/category/CategoryComboStore.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/category/CategoryComboStore.java @@ -40,5 +40,12 @@ public interface CategoryComboStore extends IdentifiableObjectStore { List 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 getByCategoryOptionCombo(@Nonnull Collection uids); } diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/category/CategoryOptionStore.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/category/CategoryOptionStore.java index 7d8776ac8cb6..63097c630f88 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/category/CategoryOptionStore.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/category/CategoryOptionStore.java @@ -30,6 +30,7 @@ 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; @@ -49,5 +50,12 @@ public interface CategoryOptionStore extends IdentifiableObjectStore getDataWriteCategoryOptions(Category category, UserDetails userDetails); - List getByCategoryOptionCombo(Collection uids); + /** + * 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 getByCategoryOptionCombo(@Nonnull Collection uids); } 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 2b283e56050a..d1b5090a61a6 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 @@ -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; @@ -478,7 +479,7 @@ CategoryOptionCombo getCategoryOptionCombo( * @return categoryOptionCombos with refs to categoryOptions */ List getCategoryOptionCombosByCategoryOption( - Collection categoryOptions); + @Nonnull Collection categoryOptions); /** * Retrieves all CategoryOptionCombos by {@link UID}. @@ -486,7 +487,7 @@ List getCategoryOptionCombosByCategoryOption( * @param uids {@link UID}s to search for * @return categoryOptionCombos with refs to {@link UID}s */ - List getCategoryOptionCombosByUid(Collection uids); + List getCategoryOptionCombosByUid(@Nonnull Collection uids); // ------------------------------------------------------------------------- // DataElementOperand diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalStore.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalStore.java index 2972596f20c2..3e77756e6e2b 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalStore.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalStore.java @@ -165,7 +165,18 @@ List getDataApprovalStatuses( List userApprovalLevels, Map levelMap); + /** + * Retrieve all {@link DataApproval}s with {@link CategoryOptionCombo} {@link UID}s + * + * @param uids {@link CategoryOptionCombo} {@link UID}s + * @return {@link DataApproval}s with {@link CategoryOptionCombo} {@link UID}s passed in + */ List getByCategoryOptionCombo(@Nonnull Collection uid); + /** + * Delete all {@link DataApproval}s with references to {@link CategoryOptionCombo} {@link UID}s + * + * @param uids {@link CategoryOptionCombo} {@link UID}s + */ void deleteByCategoryOptionCombo(@Nonnull Collection uids); } diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementOperandStore.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementOperandStore.java index 7fe3c17a4d66..1014f8139676 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementOperandStore.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementOperandStore.java @@ -30,6 +30,7 @@ import java.util.Collection; import java.util.List; import javax.annotation.Nonnull; +import org.hisp.dhis.category.CategoryOptionCombo; import org.hisp.dhis.common.IdentifiableObjectStore; import org.hisp.dhis.common.UID; @@ -39,7 +40,20 @@ public interface DataElementOperandStore extends IdentifiableObjectStore { String ID = DataElementOperand.class.getName(); + /** + * Retrieve all {@link DataElementOperand}s with {@link DataElement}s + * + * @param dataElements {@link DataElement}s + * @return {@link DataElementOperand}s with references to {@link DataElement}s passed in + */ List getByDataElement(Collection dataElements); + /** + * Retrieve all {@link DataElementOperand}s with {@link CategoryOptionCombo} {@link UID}s + * + * @param uids {@link CategoryOptionCombo} {@link UID}s + * @return {@link DataElementOperand}s with references to {@link CategoryOptionCombo} {@link UID}s + * passed in + */ List getByCategoryOptionCombo(@Nonnull Collection uids); } diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/CompleteDataSetRegistrationStore.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/CompleteDataSetRegistrationStore.java index f1e570a74e24..d7b72adbf917 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/CompleteDataSetRegistrationStore.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/CompleteDataSetRegistrationStore.java @@ -113,7 +113,19 @@ CompleteDataSetRegistration getCompleteDataSetRegistration( */ int getCompleteDataSetCountLastUpdatedAfter(Date lastUpdated); + /** + * Retrieve all {@link CompleteDataSetRegistration}s with {@link CategoryOptionCombo} {@link UID}s + * + * @param uids {@link CategoryOptionCombo} {@link UID}s + * @return {@link CompleteDataSetRegistration}s with references to {@link CategoryOptionCombo} + * {@link UID}s passed in + */ List getAllByCategoryOptionCombo(@Nonnull Collection uids); + /** + * Delete all {@link CompleteDataSetRegistration}s with references to {@link CategoryOptionCombo}s + * + * @param cocs {@link CategoryOptionCombo}s + */ void deleteByCategoryOptionCombo(@Nonnull Collection cocs); } diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueAuditStore.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueAuditStore.java index e82ba19c2e25..7761b4af5990 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueAuditStore.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueAuditStore.java @@ -28,6 +28,7 @@ package org.hisp.dhis.datavalue; import java.util.List; +import javax.annotation.Nonnull; import org.hisp.dhis.category.CategoryOptionCombo; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.organisationunit.OrganisationUnit; @@ -75,7 +76,7 @@ public interface DataValueAuditStore { * * @param categoryOptionCombo the categoryOptionCombo. */ - void deleteDataValueAudits(CategoryOptionCombo categoryOptionCombo); + void deleteDataValueAudits(@Nonnull CategoryOptionCombo categoryOptionCombo); /** * Returns data value audits for the given query. diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueStore.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueStore.java index b062b8d0eaef..0131a30af7d7 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueStore.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueStore.java @@ -94,11 +94,26 @@ public interface DataValueStore { */ void deleteDataValues(DataElement dataElement); + /** + * Deletes all data values for the given data element. + * + * @param dataElement the dataElement. + */ void deleteDataValues(@Nonnull Collection dataElement); + /** + * Deletes all data values for the given category option combos. + * + * @param categoryOptionCombos the categoryOptionCombos. + */ void deleteDataValuesByCategoryOptionCombo( @Nonnull Collection categoryOptionCombos); + /** + * Deletes all data values for the given attribute option combos. + * + * @param attributeOptionCombos the attributeOptionCombos. + */ void deleteDataValuesByAttributeOptionCombo( @Nonnull Collection attributeOptionCombos); @@ -175,6 +190,12 @@ DataValue getDataValue( */ List getDeflatedDataValues(DataExportParams params); + /** + * Retrieve all {@link DataValue}s with references to {@link DataElement}s + * + * @param dataElements {@link DataElement}s + * @return {@link DataValue}s with references to {@link DataElement}s passed in + */ List getAllDataValuesByDataElement(List dataElements); /** diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/minmax/MinMaxDataElementStore.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/minmax/MinMaxDataElementStore.java index 1d3f2d5a66a6..05f0a6d46a92 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/minmax/MinMaxDataElementStore.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/minmax/MinMaxDataElementStore.java @@ -34,6 +34,7 @@ import org.hisp.dhis.common.GenericStore; import org.hisp.dhis.common.UID; import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.datavalue.DataValue; import org.hisp.dhis.organisationunit.OrganisationUnit; /** @@ -61,5 +62,13 @@ MinMaxDataElement get( List getByDataElement(Collection dataElements); + /** + * Retrieve all {@link MinMaxDataElement}s with references to {@link CategoryOptionCombo} {@link + * UID}s + * + * @param uids {@link CategoryOptionCombo} {@link UID}s + * @return {@link MinMaxDataElement}s with references to {@link CategoryOptionCombo} {@link UID} + * passed in + */ List getByCategoryOptionCombo(@Nonnull Collection uids); } diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/predictor/PredictorStore.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/predictor/PredictorStore.java index 8b5fb42f54bb..00be942de03b 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/predictor/PredictorStore.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/predictor/PredictorStore.java @@ -30,9 +30,11 @@ import java.util.Collection; import java.util.List; import javax.annotation.Nonnull; +import org.hisp.dhis.category.CategoryOptionCombo; import org.hisp.dhis.common.IdentifiableObjectStore; import org.hisp.dhis.common.UID; import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.minmax.MinMaxDataElement; /** * @author Ken Haase @@ -47,5 +49,11 @@ public interface PredictorStore extends IdentifiableObjectStore { List getAllWithSampleSkipTestContainingDataElement( @Nonnull List dataElementUids); + /** + * Retrieve all {@link Predictor}s with references to {@link CategoryOptionCombo} {@link UID}s + * + * @param uids {@link CategoryOptionCombo} {@link UID}s + * @return {@link Predictor}s with references to {@link CategoryOptionCombo} {@link UID} passed in + */ List getByCategoryOptionCombo(@Nonnull Collection uids); } diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/EventStore.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/EventStore.java index dbe47a86fc75..71a714f28c9f 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/EventStore.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/EventStore.java @@ -29,6 +29,7 @@ import java.util.Collection; import java.util.List; +import org.hisp.dhis.category.CategoryOptionCombo; import org.hisp.dhis.common.IdentifiableObjectStore; import org.hisp.dhis.common.UID; @@ -39,7 +40,18 @@ public interface EventStore extends IdentifiableObjectStore { List getAllWithEventDataValuesRootKeysContainingAnyOf(List searchStrings); + /** + * Retrieve all {@link Event}s with references to {@link CategoryOptionCombo} {@link UID}s + * + * @param uids {@link CategoryOptionCombo} {@link UID}s + * @return {@link Event}s with references to {@link CategoryOptionCombo} {@link UID} passed in + */ List getAllByAttributeOptionCombo(Collection uids); + /** + * Delete all {@link Event}s with references to {@link CategoryOptionCombo} {@link UID}s + * + * @param uids {@link CategoryOptionCombo} {@link UID}s + */ void deleteAllByAttributeOptionCombo(Collection uids); } diff --git a/dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/merge/CommonDataMergeHandler.java b/dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/merge/CommonDataMergeHandler.java index bcbeeb1583bd..300dd41f62db 100644 --- a/dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/merge/CommonDataMergeHandler.java +++ b/dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/merge/CommonDataMergeHandler.java @@ -63,6 +63,14 @@ public class CommonDataMergeHandler { private final DataValueStore dataValueStore; private final EntityManager entityManager; + /** + * Groups {@link DataValue}s into duplicates & non-duplicates. It uses the duplicate predicate + * param value to decide whether the {@link DataValue} is considered a duplicate or not. Once + * grouped, they are then passed on to be handled accordingly. + * + * @param merge {@link DataValueMergeParams} to perform merge + * @param {@link BaseIdentifiableObject} type + */ public void handleDataValues( @Nonnull DataValueMergeParams merge) { Map> sourceDuplicateList = @@ -78,11 +86,11 @@ public void handleDataValues( } /** - * Method to handle merging duplicate {@link DataValue}s. There may be multiple potential {@link - * DataValue} duplicates. The {@link DataValue} with the latest `lastUpdated` value is filtered - * out, the rest are then deleted at the end of the process (We can only have one of these entries - * due to the composite key constraint). The filtered-out {@link DataValue} will be compared with - * the target {@link DataValue} lastUpdated date. + * Handle merging duplicate {@link DataValue}s. There may be multiple potential {@link DataValue} + * duplicates. The {@link DataValue} with the latest `lastUpdated` value is filtered out, the rest + * are then deleted at the end of the process (We can only have one of these entries due to the + * composite key constraint). The filtered-out {@link DataValue} will be compared with the target + * {@link DataValue} lastUpdated date. * *

If the target date is later, no action is required. * diff --git a/dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/merge/category/optioncombo/DataCategoryOptionComboMergeHandler.java b/dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/merge/category/optioncombo/DataCategoryOptionComboMergeHandler.java index 3b9aa0919a8d..2cb0b6897b7f 100644 --- a/dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/merge/category/optioncombo/DataCategoryOptionComboMergeHandler.java +++ b/dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/merge/category/optioncombo/DataCategoryOptionComboMergeHandler.java @@ -48,6 +48,7 @@ import org.hisp.dhis.common.BaseIdentifiableObject; import org.hisp.dhis.common.UID; import org.hisp.dhis.dataapproval.DataApproval; +import org.hisp.dhis.dataapproval.DataApprovalAudit; import org.hisp.dhis.dataapproval.DataApprovalAuditStore; import org.hisp.dhis.dataapproval.DataApprovalStore; import org.hisp.dhis.dataset.CompleteDataSetRegistration; @@ -58,6 +59,7 @@ import org.hisp.dhis.datavalue.DataValueStore; import org.hisp.dhis.merge.CommonDataMergeHandler; import org.hisp.dhis.merge.CommonDataMergeHandler.DataValueMergeParams; +import org.hisp.dhis.merge.DataMergeStrategy; import org.hisp.dhis.merge.MergeRequest; import org.hisp.dhis.program.Event; import org.hisp.dhis.program.EventStore; @@ -198,7 +200,10 @@ public void handleDataApprovals( } } - /** */ + /** + * Deletes {@link DataApprovalAudit}s if the source {@link CategoryOptionCombo}s are being + * deleted. Otherwise, no other action taken. + */ public void handleDataApprovalAudits( @Nonnull List sources, @Nonnull MergeRequest mergeRequest) { if (mergeRequest.isDeleteSources()) { @@ -211,7 +216,12 @@ public void handleDataApprovalAudits( } } - /** */ + /** + * Deletes {@link Event}s if the {@link DataMergeStrategy}s is {@link DataMergeStrategy#DISCARD}. + * Otherwise, reassigns source {@link Event}s attributeOptionCombos to the target {@link + * CategoryOptionCombo} if the {@link DataMergeStrategy}s is {@link + * DataMergeStrategy#LAST_UPDATED}. + */ public void handleEvents( @Nonnull List sources, @Nonnull CategoryOptionCombo target, @@ -228,7 +238,12 @@ public void handleEvents( } } - /** */ + /** + * Deletes {@link CompleteDataSetRegistration}s if the {@link DataMergeStrategy}s is {@link + * DataMergeStrategy#DISCARD}. Otherwise, if the {@link DataMergeStrategy}s is {@link + * DataMergeStrategy#LAST_UPDATED}, it groups source {@link CompleteDataSetRegistration}s into + * duplicates and non-duplicates for further processing. + */ public void handleCompleteDataSetRegistrations( @Nonnull List sources, @Nonnull CategoryOptionCombo target, @@ -236,7 +251,7 @@ public void handleCompleteDataSetRegistrations( if (DISCARD == mergeRequest.getDataMergeStrategy()) { completeDataSetRegistrationStore.deleteByCategoryOptionCombo(sources); } else if (LAST_UPDATED == mergeRequest.getDataMergeStrategy()) { - // get DVs from sources + // get CDSRs from sources List sourceCdsr = completeDataSetRegistrationStore.getAllByCategoryOptionCombo( UID.of(sources.stream().map(BaseIdentifiableObject::getUid).toList())); 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 bb9735c15df6..663aa0c155b9 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 @@ -701,13 +701,13 @@ public void updateCategoryOptionComboNames() { @Override public List getCategoryOptionCombosByCategoryOption( - Collection categoryOptionsUids) { + @Nonnull Collection categoryOptionsUids) { return categoryOptionComboStore.getCategoryOptionCombosByCategoryOption( UID.toValueList(categoryOptionsUids)); } @Override - public List getCategoryOptionCombosByUid(Collection uids) { + public List getCategoryOptionCombosByUid(@Nonnull Collection uids) { return categoryOptionComboStore.getByUid(UID.toValueList(uids)); } diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/hibernate/HibernateDataValueStore.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/hibernate/HibernateDataValueStore.java index 79ee7e35c9fe..48190fc6f1ca 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/hibernate/HibernateDataValueStore.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/hibernate/HibernateDataValueStore.java @@ -325,10 +325,10 @@ public List getAllDataValuesByAttrOptCombo(@Nonnull Collection u if (uids.isEmpty()) return List.of(); return getQuery( """ - select dv from DataValue dv - join dv.attributeOptionCombo aoc - where aoc.uid in :uids - """) + select dv from DataValue dv + join dv.attributeOptionCombo aoc + where aoc.uid in :uids + """) .setParameter("uids", UID.toValueList(uids)) .getResultList(); }