Search in sources :

Example 6 with DataApprovalWorkflow

use of org.hisp.dhis.dataapproval.DataApprovalWorkflow in project dhis2-core by dhis2.

the class HibernateDataApprovalStore method getDataApprovals.

@Override
public List<DataApproval> getDataApprovals(Collection<DataApprovalLevel> dataApprovalLevels, Collection<DataApprovalWorkflow> workflows, Collection<Period> periods, Collection<OrganisationUnit> organisationUnits, Collection<CategoryOptionCombo> attributeOptionCombos) {
    List<Period> storedPeriods = periods.stream().map(p -> periodService.reloadPeriod(p)).collect(Collectors.toList());
    CriteriaBuilder builder = getCriteriaBuilder();
    return getList(builder, newJpaParameters().addPredicate(root -> root.get("dataApprovalLevel").in(dataApprovalLevels)).addPredicate(root -> root.get("workflow").in(workflows)).addPredicate(root -> root.get("period").in(storedPeriods)).addPredicate(root -> root.get("organisationUnit").in(organisationUnits)).addPredicate(root -> root.get("attributeOptionCombo").in(attributeOptionCombos)));
}
Also used : CategoryService(org.hisp.dhis.category.CategoryService) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow) PeriodService(org.hisp.dhis.period.PeriodService) DataApprovalState(org.hisp.dhis.dataapproval.DataApprovalState) UNAPPROVED_READY(org.hisp.dhis.dataapproval.DataApprovalState.UNAPPROVED_READY) StringUtils(org.apache.commons.lang3.StringUtils) ACCEPTED_HERE(org.hisp.dhis.dataapproval.DataApprovalState.ACCEPTED_HERE) CurrentUserServiceTarget(org.hisp.dhis.user.CurrentUserServiceTarget) UNAPPROVABLE(org.hisp.dhis.dataapproval.DataApprovalState.UNAPPROVABLE) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) APPROVED_ABOVE(org.hisp.dhis.dataapproval.DataApprovalState.APPROVED_ABOVE) SqlRowSet(org.springframework.jdbc.support.rowset.SqlRowSet) Repository(org.springframework.stereotype.Repository) Period(org.hisp.dhis.period.Period) UNAPPROVED_WAITING(org.hisp.dhis.dataapproval.DataApprovalState.UNAPPROVED_WAITING) APPROVED_HERE(org.hisp.dhis.dataapproval.DataApprovalState.APPROVED_HERE) Collection(java.util.Collection) SessionFactory(org.hibernate.SessionFactory) Set(java.util.Set) Collectors(java.util.stream.Collectors) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Cache(org.hisp.dhis.cache.Cache) AclService(org.hisp.dhis.security.acl.AclService) CategoryCombo(org.hisp.dhis.category.CategoryCombo) DataApproval(org.hisp.dhis.dataapproval.DataApproval) DataApprovalLevel(org.hisp.dhis.dataapproval.DataApprovalLevel) DataApprovalStatus(org.hisp.dhis.dataapproval.DataApprovalStatus) HibernateGenericStore(org.hisp.dhis.hibernate.HibernateGenericStore) IdentifiableObjectUtils(org.hisp.dhis.common.IdentifiableObjectUtils) JsonbFunctions(org.hisp.dhis.hibernate.jsonb.type.JsonbFunctions) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) User(org.hisp.dhis.user.User) SystemSettingManager(org.hisp.dhis.setting.SystemSettingManager) UNAPPROVED_ABOVE(org.hisp.dhis.dataapproval.DataApprovalState.UNAPPROVED_ABOVE) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) StatementBuilder(org.hisp.dhis.jdbc.StatementBuilder) CacheProvider(org.hisp.dhis.cache.CacheProvider) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) CurrentUserService(org.hisp.dhis.user.CurrentUserService) PeriodStore(org.hisp.dhis.period.PeriodStore) DataApprovalStore(org.hisp.dhis.dataapproval.DataApprovalStore) SettingKey(org.hisp.dhis.setting.SettingKey) DateUtils(org.hisp.dhis.util.DateUtils) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Period(org.hisp.dhis.period.Period)

Example 7 with DataApprovalWorkflow

use of org.hisp.dhis.dataapproval.DataApprovalWorkflow in project dhis2-core by dhis2.

the class DataApprovalWorkflowTest method testGetWorkflowSqlCoEnddateExtension.

/**
 * Note that as part of the following test, we are checking to be sure that
 * the longest extension to the category option end date is returned from
 * data sets that are successively added to the workflow. The total
 * extension length (period length times number of periods) is always
 * increasing as we add data sets to the workflow. The most recently-added
 * data set always has the longest total extension so far.
 */
@Test
void testGetWorkflowSqlCoEnddateExtension() {
    DataSet noPeriodsAfterCoEndDate = createDataSet("noPeriodsAfterCoEndDate", new MonthlyPeriodType(), 0);
    DataSet dailyDs = createDataSet("dailyDs", new DailyPeriodType(), 3);
    DataSet weeklyDs = createDataSet("weeklyDs", new WeeklyPeriodType(), 3);
    DataSet weeklyWedDs = createDataSet("weeklyWedDs", new WeeklyWednesdayPeriodType(), 4);
    DataSet weeklyThuDs = createDataSet("weeklyThuDs", new WeeklyThursdayPeriodType(), 5);
    DataSet weeklySatDs = createDataSet("weeklySatDs", new WeeklySaturdayPeriodType(), 6);
    DataSet weeklySunDs = createDataSet("weeklySunDs", new WeeklySundayPeriodType(), 7);
    DataSet biWeeklyDs = createDataSet("biWeeklyDs", new BiWeeklyPeriodType(), 4);
    DataSet monthlyDs = createDataSet("monthlyDs", new MonthlyPeriodType(), 3);
    DataSet biMonthlyDs = createDataSet("biMonthlyDs", new BiMonthlyPeriodType(), 3);
    DataSet querterlyDs = createDataSet("querterlyDs", new QuarterlyPeriodType(), 3);
    DataSet sixMonthlyDs = createDataSet("sixMonthlyDs", new SixMonthlyPeriodType(), 3);
    DataSet sixMonthlyAprDs = createDataSet("sixMonthlyAprDs", new SixMonthlyAprilPeriodType(), 4);
    DataSet sixMonthlyNovDs = createDataSet("sixMonthlyNovDs", new SixMonthlyNovemberPeriodType(), 5);
    DataSet yearlyDs = createDataSet("yearlyDs", new YearlyPeriodType(), 3);
    DataSet financialAprDs = createDataSet("financialAprDs", new FinancialAprilPeriodType(), 4);
    DataSet financialJulDs = createDataSet("financialJulDs", new FinancialJulyPeriodType(), 5);
    DataSet financialOctDs = createDataSet("financialOctDs", new FinancialOctoberPeriodType(), 6);
    DataSet financialNovDs = createDataSet("financialNovDs", new FinancialNovemberPeriodType(), 7);
    DataSet twoYearlyDs = createDataSet("twoYearlyDs", new TwoYearlyPeriodType(), 4);
    DataApprovalWorkflow workflow = new DataApprovalWorkflow("test workflow", new DailyPeriodType(), newHashSet());
    assertEquals("", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(noPeriodsAfterCoEndDate);
    assertEquals("", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(dailyDs);
    assertEquals(" + 3 * INTERVAL '+ 1 day'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(weeklyDs);
    assertEquals(" + 3 * INTERVAL '+ 1 week'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(weeklyWedDs);
    assertEquals(" + 4 * INTERVAL '+ 1 week'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(weeklyThuDs);
    assertEquals(" + 5 * INTERVAL '+ 1 week'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(weeklySatDs);
    assertEquals(" + 6 * INTERVAL '+ 1 week'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(weeklySunDs);
    assertEquals(" + 7 * INTERVAL '+ 1 week'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(biWeeklyDs);
    assertEquals(" + 4 * INTERVAL '+ 2 weeks'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(monthlyDs);
    assertEquals(" + 3 * INTERVAL '+ 1 month'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(biMonthlyDs);
    assertEquals(" + 3 * INTERVAL '+ 2 months'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(querterlyDs);
    assertEquals(" + 3 * INTERVAL '+ 3 months'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(sixMonthlyDs);
    assertEquals(" + 3 * INTERVAL '+ 6 months'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(sixMonthlyAprDs);
    assertEquals(" + 4 * INTERVAL '+ 6 months'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(sixMonthlyNovDs);
    assertEquals(" + 5 * INTERVAL '+ 6 months'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(yearlyDs);
    assertEquals(" + 3 * INTERVAL '+ 1 year'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(financialAprDs);
    assertEquals(" + 4 * INTERVAL '+ 1 year'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(financialJulDs);
    assertEquals(" + 5 * INTERVAL '+ 1 year'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(financialOctDs);
    assertEquals(" + 6 * INTERVAL '+ 1 year'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(financialNovDs);
    assertEquals(" + 7 * INTERVAL '+ 1 year'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(twoYearlyDs);
    assertEquals(" + 4 * INTERVAL '+ 2 years'", workflow.getSqlCoEndDateExtension());
}
Also used : DailyPeriodType(org.hisp.dhis.period.DailyPeriodType) BiMonthlyPeriodType(org.hisp.dhis.period.BiMonthlyPeriodType) WeeklySaturdayPeriodType(org.hisp.dhis.period.WeeklySaturdayPeriodType) SixMonthlyNovemberPeriodType(org.hisp.dhis.period.SixMonthlyNovemberPeriodType) DataSet(org.hisp.dhis.dataset.DataSet) QuarterlyPeriodType(org.hisp.dhis.period.QuarterlyPeriodType) FinancialJulyPeriodType(org.hisp.dhis.period.FinancialJulyPeriodType) SixMonthlyAprilPeriodType(org.hisp.dhis.period.SixMonthlyAprilPeriodType) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) TwoYearlyPeriodType(org.hisp.dhis.period.TwoYearlyPeriodType) WeeklySundayPeriodType(org.hisp.dhis.period.WeeklySundayPeriodType) WeeklyPeriodType(org.hisp.dhis.period.WeeklyPeriodType) BiWeeklyPeriodType(org.hisp.dhis.period.BiWeeklyPeriodType) FinancialNovemberPeriodType(org.hisp.dhis.period.FinancialNovemberPeriodType) BiMonthlyPeriodType(org.hisp.dhis.period.BiMonthlyPeriodType) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) SixMonthlyPeriodType(org.hisp.dhis.period.SixMonthlyPeriodType) WeeklyWednesdayPeriodType(org.hisp.dhis.period.WeeklyWednesdayPeriodType) FinancialOctoberPeriodType(org.hisp.dhis.period.FinancialOctoberPeriodType) BiWeeklyPeriodType(org.hisp.dhis.period.BiWeeklyPeriodType) SixMonthlyPeriodType(org.hisp.dhis.period.SixMonthlyPeriodType) FinancialAprilPeriodType(org.hisp.dhis.period.FinancialAprilPeriodType) TwoYearlyPeriodType(org.hisp.dhis.period.TwoYearlyPeriodType) WeeklyThursdayPeriodType(org.hisp.dhis.period.WeeklyThursdayPeriodType) Test(org.junit.jupiter.api.Test)

Example 8 with DataApprovalWorkflow

use of org.hisp.dhis.dataapproval.DataApprovalWorkflow in project dhis2-core by dhis2.

the class DataApprovalWorkflowTest method testGetSortedLevels.

@Test
void testGetSortedLevels() {
    DataApprovalLevel level1 = new DataApprovalLevel("level1", 1, null);
    level1.setLevel(1);
    DataApprovalLevel level2 = new DataApprovalLevel("level2", 2, null);
    level2.setLevel(2);
    DataApprovalLevel level3 = new DataApprovalLevel("level3", 3, null);
    level3.setLevel(3);
    DataApprovalWorkflow workflow = new DataApprovalWorkflow("test workflow", new DailyPeriodType(), newHashSet(level3, level2, level1));
    List<DataApprovalLevel> levels = workflow.getSortedLevels();
    assertEquals(1, levels.get(0).getLevel());
    assertEquals(2, levels.get(1).getLevel());
    assertEquals(3, levels.get(2).getLevel());
}
Also used : DailyPeriodType(org.hisp.dhis.period.DailyPeriodType) DataApprovalLevel(org.hisp.dhis.dataapproval.DataApprovalLevel) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow) Test(org.junit.jupiter.api.Test)

Example 9 with DataApprovalWorkflow

use of org.hisp.dhis.dataapproval.DataApprovalWorkflow in project dhis2-core by dhis2.

the class DataSetApprovalFrequencyComparatorTest method testB.

@Test
void testB() {
    DataSet dsA = new DataSet("EA: Expenditures Site Level", new QuarterlyPeriodType());
    DataSet dsB = new DataSet("MER Results: Facility Based", new QuarterlyPeriodType());
    DataSet dsC = new DataSet("MER Results: Facility Based - DoD ONLY", new QuarterlyPeriodType());
    DataApprovalWorkflow workflow = new DataApprovalWorkflow("Workflow A", new QuarterlyPeriodType(), null);
    dsB.assignWorkflow(workflow);
    List<DataSet> list = Lists.newArrayList(dsB, dsC, dsA);
    Collections.sort(list, DataSetApprovalFrequencyComparator.INSTANCE);
    assertEquals(dsB, list.get(0));
    assertEquals(dsA, list.get(1));
    assertEquals(dsC, list.get(2));
}
Also used : DataSet(org.hisp.dhis.dataset.DataSet) QuarterlyPeriodType(org.hisp.dhis.period.QuarterlyPeriodType) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow) Test(org.junit.jupiter.api.Test)

Example 10 with DataApprovalWorkflow

use of org.hisp.dhis.dataapproval.DataApprovalWorkflow in project dhis2-core by dhis2.

the class DataSetApprovalFrequencyComparatorTest method testC.

@Test
void testC() {
    DataSet dsA = new DataSet("DataSetA", new YearlyPeriodType());
    DataSet dsB = new DataSet("DataSetB", new YearlyPeriodType());
    DataSet dsC = new DataSet("DataSetC", new MonthlyPeriodType());
    DataSet dsD = new DataSet("DataSetD", new QuarterlyPeriodType());
    DataApprovalWorkflow workflow = new DataApprovalWorkflow("Workflow A", new QuarterlyPeriodType(), null);
    dsA.assignWorkflow(workflow);
    dsD.assignWorkflow(workflow);
    DataElement deA = new DataElement();
    dsA.addDataSetElement(deA);
    dsB.addDataSetElement(deA);
    dsC.addDataSetElement(deA);
    dsD.addDataSetElement(deA);
    assertEquals(dsD, deA.getApprovalDataSet());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataSet(org.hisp.dhis.dataset.DataSet) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) QuarterlyPeriodType(org.hisp.dhis.period.QuarterlyPeriodType) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) Test(org.junit.jupiter.api.Test)

Aggregations

DataApprovalWorkflow (org.hisp.dhis.dataapproval.DataApprovalWorkflow)32 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)20 Period (org.hisp.dhis.period.Period)19 DataApprovalLevel (org.hisp.dhis.dataapproval.DataApprovalLevel)18 DataApproval (org.hisp.dhis.dataapproval.DataApproval)16 User (org.hisp.dhis.user.User)15 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)13 Date (java.util.Date)11 ArrayList (java.util.ArrayList)10 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)10 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)10 DataSet (org.hisp.dhis.dataset.DataSet)9 DataApprovalStatus (org.hisp.dhis.dataapproval.DataApprovalStatus)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 Map (java.util.Map)6 Set (java.util.Set)5 CategoryCombo (org.hisp.dhis.category.CategoryCombo)5 Test (org.junit.jupiter.api.Test)5 Collection (java.util.Collection)4 List (java.util.List)4