Search in sources :

Example 56 with DataSet

use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.

the class FormUtilsImpl method getPeriodsForDataSet.

@Override
public List<Period> getPeriodsForDataSet(Integer dataSetId, int first, int max) {
    Validate.notNull(dataSetId);
    DataSet dataSet = dataSetService.getDataSet(dataSetId);
    CalendarPeriodType periodType;
    if (dataSet.getPeriodType().getName().equalsIgnoreCase("Yearly")) {
        periodType = new YearlyPeriodType();
    } else {
        periodType = (CalendarPeriodType) dataSet.getPeriodType();
    }
    if (dataSet.getOpenFuturePeriods() > 0) {
        List<Period> periods = periodType.generatePeriods(new Date());
        Collections.reverse(periods);
        return periods;
    } else {
        List<Period> periods = periodType.generateLast5Years(new Date());
        FilterUtils.filter(periods, new PastAndCurrentPeriodFilter());
        Collections.reverse(periods);
        if (periods.size() > (first + max)) {
            periods = periods.subList(first, max);
        }
        return periods;
    }
}
Also used : DataSet(org.hisp.dhis.dataset.DataSet) Period(org.hisp.dhis.period.Period) CalendarPeriodType(org.hisp.dhis.period.CalendarPeriodType) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) PastAndCurrentPeriodFilter(org.hisp.dhis.system.filter.PastAndCurrentPeriodFilter)

Example 57 with DataSet

use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.

the class FormUtilsImpl method getDataSetsForCurrentUser.

@Override
public List<DataSet> getDataSetsForCurrentUser(Integer organisationUnitId) {
    Validate.notNull(organisationUnitId);
    OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(organisationUnitId);
    List<DataSet> dataSets = new ArrayList<>(organisationUnit.getDataSets());
    UserCredentials userCredentials = currentUserService.getCurrentUser().getUserCredentials();
    if (!userCredentials.isSuper()) {
        dataSets.retainAll(userCredentials.getAllDataSets());
    }
    return dataSets;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) UserCredentials(org.hisp.dhis.user.UserCredentials)

Example 58 with DataSet

use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.

the class AddLockExceptionAction method execute.

// -------------------------------------------------------------------------
// Action Implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    if (organisationUnitId.length() == 0) {
        return INPUT;
    }
    DataSet dataSet = dataSetService.getDataSet(dataSetId);
    Period period = periodService.reloadPeriod(PeriodType.getPeriodFromIsoString(periodId));
    if (dataSet == null || period == null) {
        return ERROR;
    }
    for (String id : organisationUnitId.split(",")) {
        OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(id);
        if (organisationUnit == null) {
            return ERROR;
        }
        if (organisationUnit.getDataSets().contains(dataSet)) {
            LockException lockException = new LockException();
            lockException.setOrganisationUnit(organisationUnit);
            lockException.setDataSet(dataSet);
            lockException.setPeriod(period);
            dataSetService.addLockException(lockException);
        } else {
            if (log.isDebugEnabled()) {
                log.debug("OrganisationUnit " + organisationUnit.getName() + " does not contain DataSet " + dataSet.getName() + ", ignoring.");
            }
        }
    }
    return SUCCESS;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) LockException(org.hisp.dhis.dataset.LockException) Period(org.hisp.dhis.period.Period)

Example 59 with DataSet

use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.

the class BatchRemoveLockExceptionsAction method execute.

// -------------------------------------------------------------------------
// Action Implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    DataSet dataSet = dataSetService.getDataSet(dataSetId);
    Period period = periodService.getPeriod(periodId);
    if (dataSet == null || period == null) {
        return ERROR;
    }
    dataSetService.deleteLockExceptionCombination(dataSet, period);
    return SUCCESS;
}
Also used : DataSet(org.hisp.dhis.dataset.DataSet) Period(org.hisp.dhis.period.Period)

Example 60 with DataSet

use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.

the class GetDataSetsAction method getDataSetsForCurrentUser.

private List<DataSet> getDataSetsForCurrentUser(String ids) {
    Set<DataSet> dataSets = new HashSet<>();
    if (ids.length() == 0) {
        return new ArrayList<>();
    }
    for (String id : ids.split(",")) {
        OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(id);
        if (organisationUnit == null) {
            continue;
        }
        if (organisationUnit.getDataSets() != null) {
            dataSets.addAll(organisationUnit.getDataSets());
        }
    }
    UserCredentials userCredentials = currentUserService.getCurrentUser().getUserCredentials();
    if (!userCredentials.isSuper()) {
        dataSets.retainAll(userCredentials.getAllDataSets());
    }
    return new ArrayList<>(dataSets);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) ArrayList(java.util.ArrayList) UserCredentials(org.hisp.dhis.user.UserCredentials) HashSet(java.util.HashSet)

Aggregations

DataSet (org.hisp.dhis.dataset.DataSet)118 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)52 Period (org.hisp.dhis.period.Period)40 Test (org.junit.Test)39 DataElement (org.hisp.dhis.dataelement.DataElement)34 ArrayList (java.util.ArrayList)29 DhisSpringTest (org.hisp.dhis.DhisSpringTest)21 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)21 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)21 List (java.util.List)20 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)17 User (org.hisp.dhis.user.User)17 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)16 HashSet (java.util.HashSet)14 DataElementCategoryCombo (org.hisp.dhis.dataelement.DataElementCategoryCombo)14 ClassPathResource (org.springframework.core.io.ClassPathResource)14 UserAuthorityGroup (org.hisp.dhis.user.UserAuthorityGroup)13 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)11 PeriodType (org.hisp.dhis.period.PeriodType)11 Date (java.util.Date)9