use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.
the class GetLockExceptionFormAction method getPeriodsForDataSet.
private List<Period> getPeriodsForDataSet(int id) {
DataSet dataSet = dataSetService.getDataSet(id);
if (dataSet == null) {
return new ArrayList<>();
}
CalendarPeriodType periodType = (CalendarPeriodType) dataSet.getPeriodType();
List<Period> periods = periodType.generateLast5Years(new Date());
FilterUtils.filter(periods, new PastAndCurrentPeriodFilter());
Collections.reverse(periods);
if (periods.size() > 10) {
periods = periods.subList(0, 10);
}
return periods;
}
use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.
the class GetLockExceptionFormAction method getDataSetsForCurrentUser.
private List<DataSet> getDataSetsForCurrentUser(int id) {
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(id);
if (organisationUnit == null) {
return new ArrayList<>();
}
List<DataSet> dataSets = new ArrayList<>();
if (organisationUnit.getDataSets() != null) {
dataSets.addAll(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 GenerateMinMaxValuesAction method execute.
// -------------------------------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------------------------------
@Override
public String execute() throws Exception {
OrganisationUnit unit = selectionTreeManager.getReloadedSelectedOrganisationUnit();
if (unit == null) {
message = i18n.getString("not_choose_organisation");
return INPUT;
}
Collection<OrganisationUnit> orgUnits = organisationUnitService.getOrganisationUnitWithChildren(unit.getId());
Double factor = (Double) systemSettingManager.getSystemSetting(SettingKey.FACTOR_OF_DEVIATION);
Collection<DataElement> dataElements = new HashSet<>();
for (Integer dataSetId : dataSets) {
DataSet dataSet = dataSetService.getDataSet(dataSetId);
dataElements.addAll(dataSet.getDataElements());
}
if (remove) {
minMaxDataElementService.removeMinMaxDataElements(dataElements, orgUnits);
} else {
dataAnalysisService.generateMinMaxValues(orgUnits, dataElements, factor);
}
message = i18n.getString("done");
return SUCCESS;
}
use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.
the class ObjectBundleServiceTest method testUpdateDataSetWithSectionsAndGreyedFields.
@Test
public void testUpdateDataSetWithSectionsAndGreyedFields() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_sections_gf.json").getInputStream(), RenderFormat.JSON);
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.CREATE);
params.setObjects(metadata);
ObjectBundle bundle = objectBundleService.create(params);
ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
assertTrue(validate.getErrorReports().isEmpty());
objectBundleService.commit(bundle);
Section section1 = manager.get(Section.class, "JwcV2ZifEQf");
assertNotNull(section1.getDataSet());
assertEquals(1, section1.getCategoryCombos().size());
assertTrue(section1.getGreyedFields().isEmpty());
assertEquals(1, section1.getDataElements().size());
assertNotNull(section1.getDataSet());
Section section2 = manager.get(Section.class, "C50M0WxaI7y");
assertNotNull(section2.getDataSet());
assertEquals(1, section2.getCategoryCombos().size());
assertEquals(1, section2.getGreyedFields().size());
assertEquals(1, section2.getDataElements().size());
assertNotNull(section2.getDataSet());
metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_sections_gf_update.json").getInputStream(), RenderFormat.JSON);
params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.UPDATE);
params.setObjects(metadata);
bundle = objectBundleService.create(params);
validate = objectBundleValidationService.validate(bundle);
assertTrue(validate.getErrorReports().isEmpty());
objectBundleService.commit(bundle);
List<DataSet> dataSets = manager.getAll(DataSet.class);
List<Section> sections = manager.getAll(Section.class);
List<OrganisationUnit> organisationUnits = manager.getAll(OrganisationUnit.class);
List<DataElement> dataElements = manager.getAll(DataElement.class);
List<UserAuthorityGroup> userRoles = manager.getAll(UserAuthorityGroup.class);
List<User> users = manager.getAll(User.class);
List<DataElementOperand> dataElementOperands = manager.getAll(DataElementOperand.class);
assertFalse(organisationUnits.isEmpty());
assertFalse(dataElements.isEmpty());
assertFalse(users.isEmpty());
assertFalse(userRoles.isEmpty());
assertEquals(1, dataSets.size());
assertEquals(2, sections.size());
assertEquals(1, dataElementOperands.size());
DataSet dataSet = dataSets.get(0);
assertEquals("Updated Data Set", dataSet.getName());
assertEquals(2, dataSet.getSections().size());
assertNotNull(dataSet.getUser());
section1 = manager.get(Section.class, "JwcV2ZifEQf");
assertNotNull(section1.getDataSet());
assertEquals(1, section1.getCategoryCombos().size());
assertEquals(1, section1.getGreyedFields().size());
assertEquals(1, section1.getDataElements().size());
assertNotNull(section1.getDataSet());
section2 = manager.get(Section.class, "C50M0WxaI7y");
assertNotNull(section2.getDataSet());
assertEquals(1, section2.getCategoryCombos().size());
assertTrue(section2.getGreyedFields().isEmpty());
assertEquals(1, section2.getDataElements().size());
assertNotNull(section2.getDataSet());
}
use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.
the class AuditController method getDataElementsByDataSet.
private List<DataElement> getDataElementsByDataSet(List<String> dsIdentifiers) throws WebMessageException {
List<DataElement> dataElements = new ArrayList<>();
for (String ds : dsIdentifiers) {
DataSet dataSet = manager.get(DataSet.class, ds);
if (dataSet == null) {
throw new WebMessageException(WebMessageUtils.conflict("Illegal dataSet identifier: " + ds));
}
dataElements.addAll(dataSet.getDataElements());
}
return dataElements;
}
Aggregations