use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.
the class CompleteDataSetRegistrationController method saveCompleteDataSetRegistration.
// Legacy (<= V25)
@ApiVersion({ DhisApiVersion.V23, DhisApiVersion.V24, DhisApiVersion.V25 })
@RequestMapping(method = RequestMethod.POST, produces = "text/plain")
public void saveCompleteDataSetRegistration(@RequestParam String ds, @RequestParam String pe, @RequestParam String ou, @RequestParam(required = false) String cc, @RequestParam(required = false) String cp, @RequestParam(required = false) Date cd, @RequestParam(required = false) String sb, @RequestParam(required = false) boolean multiOu, HttpServletResponse response) throws WebMessageException {
DataSet dataSet = dataSetService.getDataSet(ds);
if (dataSet == null) {
throw new WebMessageException(WebMessageUtils.conflict("Illegal data set identifier: " + ds));
}
Period period = PeriodType.getPeriodFromIsoString(pe);
if (period == null) {
throw new WebMessageException(WebMessageUtils.conflict("Illegal period identifier: " + pe));
}
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(ou);
if (organisationUnit == null) {
throw new WebMessageException(WebMessageUtils.conflict("Illegal organisation unit identifier: " + ou));
}
DataElementCategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(cc, cp, false);
if (attributeOptionCombo == null) {
return;
}
if (dataSetService.isLocked(dataSet, period, organisationUnit, attributeOptionCombo, null, multiOu)) {
throw new WebMessageException(WebMessageUtils.conflict("Data set is locked: " + ds));
}
// ---------------------------------------------------------------------
// Register as completed data set
// ---------------------------------------------------------------------
Set<OrganisationUnit> children = organisationUnit.getChildren();
String storedBy = (sb == null) ? currentUserService.getCurrentUsername() : sb;
Date completionDate = (cd == null) ? new Date() : cd;
List<CompleteDataSetRegistration> registrations = new ArrayList<>();
if (!multiOu) {
CompleteDataSetRegistration completeDataSetRegistration = registerCompleteDataSet(dataSet, period, organisationUnit, attributeOptionCombo, storedBy, completionDate);
if (completeDataSetRegistration != null) {
registrations.add(completeDataSetRegistration);
}
} else {
addRegistrationsForOrgUnits(registrations, Sets.union(children, Sets.newHashSet(organisationUnit)), dataSet, period, attributeOptionCombo, storedBy, completionDate);
}
registrationService.saveCompleteDataSetRegistrations(registrations, true);
}
use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.
the class ObjectBundleServiceFavoritesTest method testCreateMetadataWithChartsWithPeriods1.
@Test
public void testCreateMetadataWithChartsWithPeriods1() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/favorites/metadata_with_chart_periods1.json").getInputStream(), RenderFormat.JSON);
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.CREATE_AND_UPDATE);
params.setObjects(metadata);
ObjectBundle bundle = objectBundleService.create(params);
ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
assertTrue(validate.getErrorReports().isEmpty());
objectBundleService.commit(bundle);
List<DataSet> dataSets = manager.getAll(DataSet.class);
List<OrganisationUnit> organisationUnits = manager.getAll(OrganisationUnit.class);
List<DataElement> dataElements = manager.getAll(DataElement.class);
List<Chart> charts = manager.getAll(Chart.class);
assertEquals(1, dataSets.size());
assertEquals(1, organisationUnits.size());
assertEquals(4, dataElements.size());
assertEquals(4, charts.size());
Chart chart = manager.get(Chart.class, "ziCoxdcXRQz");
assertNotNull(chart);
assertEquals(5, chart.getPeriods().size());
}
use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.
the class AddRoleAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
UserAuthorityGroup group = new UserAuthorityGroup();
group.setName(StringUtils.trimToNull(name));
group.setDescription(StringUtils.trimToNull(description));
for (String id : selectedList) {
DataSet dataSet = dataSetService.getDataSet(id);
group.getDataSets().add(dataSet);
}
for (String id : selectedProgramList) {
Program program = programService.getProgram(id);
group.getPrograms().add(program);
}
group.getAuthorities().addAll(selectedListAuthority);
userService.addUserAuthorityGroup(group);
return SUCCESS;
}
use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.
the class UpdateRoleAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
UserAuthorityGroup group = userService.getUserAuthorityGroup(id);
group.setName(StringUtils.trimToNull(name));
group.setDescription(StringUtils.trimToNull(description));
group.getDataSets().clear();
group.getPrograms().clear();
group.getAuthorities().clear();
for (String id : selectedList) {
DataSet dataSet = dataSetService.getDataSet(id);
group.getDataSets().add(dataSet);
}
for (String id : selectedProgramList) {
Program program = programService.getProgram(id);
group.getPrograms().add(program);
}
group.getAuthorities().addAll(selectedListAuthority);
userService.updateUserAuthorityGroup(group);
return SUCCESS;
}
use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.
the class CurrentUserController method getDataSets.
@RequestMapping(value = { "/assignedDataSets", "/dataSets" }, produces = { "application/json", "text/*" })
public void getDataSets(@RequestParam(defaultValue = "false") boolean optionSets, @RequestParam(defaultValue = "50") int maxOptions, HttpServletResponse response, @RequestParam Map<String, String> parameters) throws IOException, NotAuthenticatedException {
User currentUser = currentUserService.getCurrentUser();
if (currentUser == null) {
throw new NotAuthenticatedException();
}
Forms forms = new Forms();
Set<OrganisationUnit> organisationUnits = new HashSet<>();
Set<DataSet> userDataSets;
Set<OrganisationUnit> userOrganisationUnits = new HashSet<>(currentUser.getOrganisationUnits());
if (currentUser.getUserCredentials().getAllAuthorities().contains("ALL")) {
userDataSets = new HashSet<>(dataSetService.getAllDataSets());
if (userOrganisationUnits.isEmpty()) {
userOrganisationUnits = new HashSet<>(organisationUnitService.getRootOrganisationUnits());
}
} else {
userDataSets = currentUser.getUserCredentials().getAllDataSets();
}
if (parameters.containsKey("includeDescendants") && Boolean.parseBoolean(parameters.get("includeDescendants"))) {
List<OrganisationUnit> children = new ArrayList<>();
for (OrganisationUnit organisationUnit : userOrganisationUnits) {
children.addAll(organisationUnitService.getOrganisationUnitWithChildren(organisationUnit.getUid()));
}
userOrganisationUnits.addAll(children);
} else {
List<OrganisationUnit> children = new ArrayList<>();
for (OrganisationUnit organisationUnit : userOrganisationUnits) {
children.addAll(organisationUnit.getChildren());
}
userOrganisationUnits.addAll(children);
}
for (OrganisationUnit ou : userOrganisationUnits) {
Set<DataSet> dataSets = new HashSet<>(Sets.intersection(ou.getDataSets(), userDataSets));
if (dataSets.size() > 0) {
organisationUnits.add(ou);
}
}
for (OrganisationUnit organisationUnit : organisationUnits) {
FormOrganisationUnit formOrganisationUnit = new FormOrganisationUnit();
formOrganisationUnit.setId(organisationUnit.getUid());
formOrganisationUnit.setLabel(organisationUnit.getDisplayName());
formOrganisationUnit.setLevel(organisationUnit.getLevel());
if (organisationUnit.getParent() != null) {
formOrganisationUnit.setParent(organisationUnit.getParent().getUid());
}
Set<DataSet> dataSets = new HashSet<>(Sets.intersection(organisationUnit.getDataSets(), userDataSets));
for (DataSet dataSet : dataSets) {
String uid = dataSet.getUid();
FormDataSet formDataSet = new FormDataSet();
formDataSet.setId(uid);
formDataSet.setLabel(dataSet.getDisplayName());
dataSet.getCategoryCombo().getCategories().forEach(cat -> {
cat.setAccess(aclService.getAccess(cat, currentUser));
cat.getCategoryOptions().forEach(catOpts -> catOpts.setAccess(aclService.getAccess(catOpts, currentUser)));
});
forms.getForms().put(uid, FormUtils.fromDataSet(dataSet, false, userOrganisationUnits));
formOrganisationUnit.getDataSets().add(formDataSet);
if (optionSets) {
for (DataElement dataElement : dataSet.getDataElements()) {
if (dataElement.hasOptionSet()) {
int size = maxOptions;
if (size >= dataElement.getOptionSet().getOptions().size()) {
size = dataElement.getOptionSet().getOptions().size();
}
forms.getOptionSets().put(dataElement.getOptionSet().getUid(), dataElement.getOptionSet().getOptionValues().subList(0, size - 1));
}
}
}
}
forms.getOrganisationUnits().put(formOrganisationUnit.getId(), formOrganisationUnit);
}
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
renderService.toJson(response.getOutputStream(), forms);
}
Aggregations