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;
}
}
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;
}
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;
}
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;
}
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);
}
Aggregations