Search in sources :

Example 31 with PeriodType

use of org.hisp.dhis.period.PeriodType 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)

Example 32 with PeriodType

use of org.hisp.dhis.period.PeriodType in project dhis2-core by dhis2.

the class DataApprovalWorkflowObjectBundleHook method preUpdate.

@Override
public <T extends IdentifiableObject> void preUpdate(T object, T persistedObject, ObjectBundle bundle) {
    if (!DataApprovalWorkflow.class.isInstance(object))
        return;
    DataApprovalWorkflow dataApprovalWorkflow = (DataApprovalWorkflow) object;
    if (dataApprovalWorkflow.getPeriodType() != null) {
        PeriodType periodType = bundle.getPreheat().getPeriodTypeMap().get(dataApprovalWorkflow.getPeriodType().getName());
        dataApprovalWorkflow.setPeriodType(periodType);
    }
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow)

Example 33 with PeriodType

use of org.hisp.dhis.period.PeriodType in project dhis2-core by dhis2.

the class PredictorObjectBundleHook method preCreate.

@Override
public void preCreate(IdentifiableObject object, ObjectBundle bundle) {
    if (!Predictor.class.isInstance(object)) {
        return;
    }
    Predictor predictor = (Predictor) object;
    Expression skipTest = predictor.getSampleSkipTest();
    preheatService.connectReferences(predictor.getGenerator(), bundle.getPreheat(), bundle.getPreheatIdentifier());
    if (skipTest != null) {
        preheatService.connectReferences(skipTest, bundle.getPreheat(), bundle.getPreheatIdentifier());
    }
    sessionFactory.getCurrentSession().save(predictor.getGenerator());
    if (skipTest != null) {
        sessionFactory.getCurrentSession().save(skipTest);
    }
    if (predictor.getPeriodType() != null) {
        PeriodType periodType = bundle.getPreheat().getPeriodTypeMap().get(predictor.getPeriodType().getName());
        predictor.setPeriodType(periodType);
    }
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) Predictor(org.hisp.dhis.predictor.Predictor) Expression(org.hisp.dhis.expression.Expression)

Example 34 with PeriodType

use of org.hisp.dhis.period.PeriodType in project dhis2-core by dhis2.

the class PredictorObjectBundleHook method preUpdate.

@Override
public void preUpdate(IdentifiableObject object, IdentifiableObject persistedObject, ObjectBundle bundle) {
    if (!Predictor.class.isInstance(object)) {
        return;
    }
    Predictor predictor = (Predictor) object;
    Expression skipTest = predictor.getSampleSkipTest();
    preheatService.connectReferences(predictor.getGenerator(), bundle.getPreheat(), bundle.getPreheatIdentifier());
    if (skipTest != null) {
        preheatService.connectReferences(skipTest, bundle.getPreheat(), bundle.getPreheatIdentifier());
    }
    sessionFactory.getCurrentSession().save(predictor.getGenerator());
    if (skipTest != null) {
        sessionFactory.getCurrentSession().save(skipTest);
    }
    if (predictor.getPeriodType() != null) {
        PeriodType periodType = bundle.getPreheat().getPeriodTypeMap().get(predictor.getPeriodType().getName());
        predictor.setPeriodType(periodType);
    }
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) Predictor(org.hisp.dhis.predictor.Predictor) Expression(org.hisp.dhis.expression.Expression)

Example 35 with PeriodType

use of org.hisp.dhis.period.PeriodType in project dhis2-core by dhis2.

the class DataApprovalController method getApproval.

@RequestMapping(value = STATUS_PATH, method = RequestMethod.GET, produces = ContextUtils.CONTENT_TYPE_JSON)
@ResponseBody
public RootNode getApproval(@RequestParam Set<String> ds, @RequestParam(required = false) String pe, @RequestParam Date startDate, @RequestParam Date endDate, @RequestParam Set<String> ou, @RequestParam(required = false) boolean children, HttpServletResponse response) throws IOException, WebMessageException {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
        List<String> defaults = new ArrayList<>();
        defaults.add("period[id,name,code],organisationUnit[id,name,created,lastUpdated],dataSet[code,name,created,lastUpdated,id]");
        fields.addAll(defaults);
    }
    Set<DataSet> dataSets = parseDataSetsWithWorkflow(ds);
    Set<Period> periods = new HashSet<>();
    PeriodType periodType = periodService.getPeriodTypeByName(pe);
    if (periodType != null) {
        periods.addAll(periodService.getPeriodsBetweenDates(periodType, startDate, endDate));
    } else {
        periods.addAll(periodService.getPeriodsBetweenDates(startDate, endDate));
    }
    Set<OrganisationUnit> organisationUnits = new HashSet<>();
    if (children) {
        organisationUnits.addAll(organisationUnitService.getOrganisationUnitsWithChildren(ou));
    } else {
        organisationUnits.addAll(organisationUnitService.getOrganisationUnitsByUid(ou));
    }
    DataApprovalStateResponses dataApprovalStateResponses = new DataApprovalStateResponses();
    for (DataSet dataSet : dataSets) {
        for (OrganisationUnit organisationUnit : organisationUnits) {
            for (Period period : periods) {
                dataApprovalStateResponses.add(getDataApprovalStateResponse(dataSet, organisationUnit, period));
            }
        }
    }
    response.setContentType(MediaType.APPLICATION_JSON_VALUE);
    RootNode rootNode = NodeUtils.createMetadata();
    rootNode.addChild(fieldFilterService.filter(DataApprovalStateResponse.class, dataApprovalStateResponses.getDataApprovalStateResponses(), fields));
    return rootNode;
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) RootNode(org.hisp.dhis.node.types.RootNode) DataSet(org.hisp.dhis.dataset.DataSet) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) DataApprovalStateResponses(org.hisp.dhis.dataapproval.DataApprovalStateResponses) Period(org.hisp.dhis.period.Period) DataApprovalStateResponse(org.hisp.dhis.dataapproval.DataApprovalStateResponse) HashSet(java.util.HashSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

PeriodType (org.hisp.dhis.period.PeriodType)67 Period (org.hisp.dhis.period.Period)21 MonthlyPeriodType (org.hisp.dhis.period.MonthlyPeriodType)13 ArrayList (java.util.ArrayList)12 DataSet (org.hisp.dhis.dataset.DataSet)12 DataElement (org.hisp.dhis.dataelement.DataElement)10 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)9 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)7 UniqueArrayList (org.hisp.dhis.commons.collection.UniqueArrayList)6 YearlyPeriodType (org.hisp.dhis.period.YearlyPeriodType)6 ProgramStage (org.hisp.dhis.program.ProgramStage)6 Test (org.junit.Test)6 Date (java.util.Date)5 HashSet (java.util.HashSet)5 QuarterlyPeriodType (org.hisp.dhis.period.QuarterlyPeriodType)5 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)5 CategoryOptionGroupSet (org.hisp.dhis.dataelement.CategoryOptionGroupSet)4 OrganisationUnitGroupSet (org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)4 OrganisationUnitLevel (org.hisp.dhis.organisationunit.OrganisationUnitLevel)4 DailyPeriodType (org.hisp.dhis.period.DailyPeriodType)4