Search in sources :

Example 36 with PeriodType

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

the class ConfigurationController method setInfrastructuralPeriodType.

@PreAuthorize("hasRole('ALL') or hasRole('F_SYSTEM_SETTING')")
@RequestMapping(value = "/infrastructuralPeriodType", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void setInfrastructuralPeriodType(@RequestBody String name) throws NotFoundException {
    PeriodType periodType = PeriodType.getPeriodTypeByName(name);
    if (periodType == null) {
        throw new NotFoundException("Period type", name);
    }
    Configuration config = configurationService.getConfiguration();
    periodType = periodService.reloadPeriodType(periodType);
    config.setInfrastructuralPeriodType(periodType);
    configurationService.setConfiguration(config);
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) Configuration(org.hisp.dhis.configuration.Configuration) NotFoundException(org.hisp.dhis.webapi.controller.exception.NotFoundException) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 37 with PeriodType

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

the class CompleteDataSetRegistrationController method getCompleteDataSetRegistrations.

private CompleteDataSetRegistrations getCompleteDataSetRegistrations(Set<String> dataSet, String period, Date startDate, Date endDate, Set<String> orgUnit, boolean children) {
    Set<Period> periods = new HashSet<>();
    Set<DataSet> dataSets = new HashSet<>();
    Set<OrganisationUnit> organisationUnits = new HashSet<>();
    PeriodType periodType = periodService.getPeriodTypeByName(period);
    if (periodType != null) {
        periods.addAll(periodService.getPeriodsBetweenDates(periodType, startDate, endDate));
    } else {
        periods.addAll(periodService.getPeriodsBetweenDates(startDate, endDate));
    }
    if (periods.isEmpty()) {
        return new CompleteDataSetRegistrations();
    }
    if (children) {
        organisationUnits.addAll(organisationUnitService.getOrganisationUnitsWithChildren(orgUnit));
    } else {
        organisationUnits.addAll(organisationUnitService.getOrganisationUnitsByUid(orgUnit));
    }
    dataSets.addAll(manager.getByUid(DataSet.class, dataSet));
    CompleteDataSetRegistrations completeDataSetRegistrations = new CompleteDataSetRegistrations();
    completeDataSetRegistrations.setCompleteDataSetRegistrations(new ArrayList<>(registrationService.getCompleteDataSetRegistrations(dataSets, organisationUnits, periods)));
    return completeDataSetRegistrations;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) PeriodType(org.hisp.dhis.period.PeriodType) DataSet(org.hisp.dhis.dataset.DataSet) Period(org.hisp.dhis.period.Period) CompleteDataSetRegistrations(org.hisp.dhis.dataset.CompleteDataSetRegistrations) HashSet(java.util.HashSet)

Example 38 with PeriodType

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

the class HibernateValidationRuleStore method save.

// -------------------------------------------------------------------------
// Implementation
// -------------------------------------------------------------------------
@Override
public void save(ValidationRule validationRule) {
    PeriodType periodType = periodService.reloadPeriodType(validationRule.getPeriodType());
    validationRule.setPeriodType(periodType);
    super.save(validationRule);
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType)

Example 39 with PeriodType

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

the class HibernateValidationRuleStore method update.

@Override
public void update(ValidationRule validationRule) {
    PeriodType periodType = periodService.reloadPeriodType(validationRule.getPeriodType());
    validationRule.setPeriodType(periodType);
    super.save(validationRule);
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType)

Example 40 with PeriodType

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

the class LockExceptionControllerDocumentation method testGetLockException.

@Test
public void testGetLockException() throws Exception {
    MockHttpSession session = getSession("ALL");
    PeriodType periodType = periodService.getPeriodTypeByName("Monthly");
    Period period = createPeriod(periodType, getDate(2016, 12, 1), getDate(2016, 12, 31));
    manager.save(period);
    OrganisationUnit orgUnit = createOrganisationUnit('B');
    manager.save(orgUnit);
    DataSet dataSet = createDataSet('A', periodType);
    dataSet.addOrganisationUnit(orgUnit);
    manager.save(dataSet);
    LockException lockException = new LockException(period, orgUnit, dataSet);
    dataSetService.addLockException(lockException);
    String getUrl = "/lockExceptions?filter=organisationUnit.id:eq:" + orgUnit.getUid() + "&filter=period:eq:201612&filter=dataSet.id:eq:" + dataSet.getUid();
    Lists.newArrayList(fieldWithPath("period").description("Property"), fieldWithPath("organisationUnit").description("Property"), fieldWithPath("dataSet").description("Property"));
    mvc.perform(get(getUrl).session(session).accept(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().is(200)).andDo(documentPrettyPrint("lockExceptions/get")).andReturn();
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) LockException(org.hisp.dhis.dataset.LockException) MockHttpSession(org.springframework.mock.web.MockHttpSession) Period(org.hisp.dhis.period.Period) Test(org.junit.Test) DhisWebSpringTest(org.hisp.dhis.webapi.DhisWebSpringTest)

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