Search in sources :

Example 1 with UniqueArrayList

use of org.hisp.dhis.commons.collection.UniqueArrayList in project dhis2-core by dhis2.

the class AnalyticsTableTest method testEquals.

@Test
public void testEquals() {
    Period periodA = new YearlyPeriodType().createPeriod(new DateTime(2014, 1, 1, 0, 0).toDate());
    Period periodB = new YearlyPeriodType().createPeriod(new DateTime(2015, 1, 1, 0, 0).toDate());
    AnalyticsTable tableA = new AnalyticsTable("analytics", null, periodA);
    AnalyticsTable tableB = new AnalyticsTable("analytics", null, periodA);
    AnalyticsTable tableC = new AnalyticsTable("analytics", null, periodB);
    List<AnalyticsTable> uniqueList = new UniqueArrayList<>();
    uniqueList.add(tableA);
    uniqueList.add(tableB);
    uniqueList.add(tableC);
    assertEquals(2, uniqueList.size());
}
Also used : AnalyticsTable(org.hisp.dhis.analytics.AnalyticsTable) Period(org.hisp.dhis.period.Period) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) UniqueArrayList(org.hisp.dhis.commons.collection.UniqueArrayList) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 2 with UniqueArrayList

use of org.hisp.dhis.commons.collection.UniqueArrayList in project dhis2-core by dhis2.

the class DatePeriodResourceTable method getPopulateTempTableContent.

@Override
public Optional<List<Object[]>> getPopulateTempTableContent() {
    List<PeriodType> periodTypes = PeriodType.getAvailablePeriodTypes();
    List<Object[]> batchArgs = new ArrayList<>();
    //TODO
    Date startDate = new Cal(1975, 1, 1, true).time();
    Date endDate = new Cal(2025, 1, 1, true).time();
    List<Period> days = new UniqueArrayList<>(new DailyPeriodType().generatePeriods(startDate, endDate));
    Calendar calendar = PeriodType.getCalendar();
    for (Period day : days) {
        List<Object> values = new ArrayList<>();
        values.add(day.getStartDate());
        for (PeriodType periodType : periodTypes) {
            values.add(periodType.createPeriod(day.getStartDate(), calendar).getIsoDate());
        }
        batchArgs.add(values.toArray());
    }
    return Optional.of(batchArgs);
}
Also used : DailyPeriodType(org.hisp.dhis.period.DailyPeriodType) DailyPeriodType(org.hisp.dhis.period.DailyPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) Calendar(org.hisp.dhis.calendar.Calendar) UniqueArrayList(org.hisp.dhis.commons.collection.UniqueArrayList) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) UniqueArrayList(org.hisp.dhis.commons.collection.UniqueArrayList) Date(java.util.Date) Cal(org.hisp.dhis.period.Cal)

Example 3 with UniqueArrayList

use of org.hisp.dhis.commons.collection.UniqueArrayList in project dhis2-core by dhis2.

the class JdbcEventAnalyticsTableManager method getTables.

@Override
@Transactional
public List<AnalyticsTable> getTables(Date earliest) {
    log.info(String.format("Get tables using earliest: %s, spatial support: %b", earliest, databaseInfo.isSpatialSupport()));
    List<AnalyticsTable> tables = new UniqueArrayList<>();
    Calendar calendar = PeriodType.getCalendar();
    String baseName = getTableName();
    List<Program> programs = idObjectManager.getAllNoAcl(Program.class);
    for (Program program : programs) {
        List<Integer> dataYears = getDataYears(program, earliest);
        Collections.sort(dataYears);
        for (Integer year : dataYears) {
            Period period = PartitionUtils.getPeriod(calendar, year);
            AnalyticsTable table = new AnalyticsTable(baseName, null, period, program);
            List<AnalyticsTableColumn> dimensionColumns = getDimensionColumns(table);
            table.setDimensionColumns(dimensionColumns);
            tables.add(table);
        }
    }
    return tables;
}
Also used : Program(org.hisp.dhis.program.Program) AnalyticsTable(org.hisp.dhis.analytics.AnalyticsTable) Calendar(org.hisp.dhis.calendar.Calendar) Period(org.hisp.dhis.period.Period) UniqueArrayList(org.hisp.dhis.commons.collection.UniqueArrayList) AnalyticsTableColumn(org.hisp.dhis.analytics.AnalyticsTableColumn) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with UniqueArrayList

use of org.hisp.dhis.commons.collection.UniqueArrayList in project dhis2-core by dhis2.

the class UniqueArrayListTest method testAdd.

@Test
public void testAdd() {
    List<Period> list = new UniqueArrayList<>();
    PeriodType periodType = new MonthlyPeriodType();
    Period peA = periodType.createPeriod(new DateTime(2000, 1, 1, 0, 0).toDate());
    // Duplicate
    Period peB = periodType.createPeriod(new DateTime(2000, 1, 1, 0, 0).toDate());
    Period peC = periodType.createPeriod(new DateTime(2000, 2, 1, 0, 0).toDate());
    list.add(peA);
    list.add(peB);
    list.add(peC);
    assertEquals(2, list.size());
    assertTrue(list.contains(peA));
    assertTrue(list.contains(peB));
    assertTrue(list.contains(peC));
}
Also used : MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) Period(org.hisp.dhis.period.Period) UniqueArrayList(org.hisp.dhis.commons.collection.UniqueArrayList) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 5 with UniqueArrayList

use of org.hisp.dhis.commons.collection.UniqueArrayList in project dhis2-core by dhis2.

the class UniqueArrayListTest method testAddAll.

@Test
public void testAddAll() {
    List<Period> list = new ArrayList<>();
    PeriodType periodType = new MonthlyPeriodType();
    Period peA = periodType.createPeriod(new DateTime(2000, 1, 1, 0, 0).toDate());
    // Duplicate
    Period peB = periodType.createPeriod(new DateTime(2000, 1, 1, 0, 0).toDate());
    Period peC = periodType.createPeriod(new DateTime(2000, 2, 1, 0, 0).toDate());
    list.add(peA);
    list.add(peB);
    list.add(peC);
    assertEquals(3, list.size());
    List<Period> uniqueList = new UniqueArrayList<>();
    uniqueList.addAll(list);
    assertEquals(2, uniqueList.size());
    assertTrue(uniqueList.contains(peA));
    assertTrue(uniqueList.contains(peB));
    assertTrue(uniqueList.contains(peC));
}
Also used : MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) UniqueArrayList(org.hisp.dhis.commons.collection.UniqueArrayList) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) UniqueArrayList(org.hisp.dhis.commons.collection.UniqueArrayList) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

UniqueArrayList (org.hisp.dhis.commons.collection.UniqueArrayList)9 Period (org.hisp.dhis.period.Period)8 ArrayList (java.util.ArrayList)4 AnalyticsTable (org.hisp.dhis.analytics.AnalyticsTable)4 PeriodType (org.hisp.dhis.period.PeriodType)4 DateTime (org.joda.time.DateTime)4 Test (org.junit.Test)4 Calendar (org.hisp.dhis.calendar.Calendar)3 MonthlyPeriodType (org.hisp.dhis.period.MonthlyPeriodType)3 AnalyticsTableColumn (org.hisp.dhis.analytics.AnalyticsTableColumn)2 Program (org.hisp.dhis.program.Program)2 Date (java.util.Date)1 List (java.util.List)1 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)1 DataDimensionItem (org.hisp.dhis.common.DataDimensionItem)1 DimensionType (org.hisp.dhis.common.DimensionType)1 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)1 DimensionalObject (org.hisp.dhis.common.DimensionalObject)1 CategoryDimension (org.hisp.dhis.dataelement.CategoryDimension)1 CategoryOptionGroup (org.hisp.dhis.dataelement.CategoryOptionGroup)1