Search in sources :

Example 11 with DataSet

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);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) Date(java.util.Date) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with DataSet

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());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) DataSet(org.hisp.dhis.dataset.DataSet) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) DataElement(org.hisp.dhis.dataelement.DataElement) List(java.util.List) Chart(org.hisp.dhis.chart.Chart) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 13 with DataSet

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;
}
Also used : Program(org.hisp.dhis.program.Program) UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) DataSet(org.hisp.dhis.dataset.DataSet)

Example 14 with DataSet

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;
}
Also used : Program(org.hisp.dhis.program.Program) UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) DataSet(org.hisp.dhis.dataset.DataSet)

Example 15 with DataSet

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);
}
Also used : Forms(org.hisp.dhis.webapi.webdomain.Forms) FormOrganisationUnit(org.hisp.dhis.webapi.webdomain.FormOrganisationUnit) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) DataSet(org.hisp.dhis.dataset.DataSet) FormDataSet(org.hisp.dhis.webapi.webdomain.FormDataSet) ArrayList(java.util.ArrayList) FormOrganisationUnit(org.hisp.dhis.webapi.webdomain.FormOrganisationUnit) FormDataSet(org.hisp.dhis.webapi.webdomain.FormDataSet) DataElement(org.hisp.dhis.dataelement.DataElement) NotAuthenticatedException(org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException) HashSet(java.util.HashSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DataSet (org.hisp.dhis.dataset.DataSet)199 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)82 Test (org.junit.jupiter.api.Test)69 DataElement (org.hisp.dhis.dataelement.DataElement)58 Period (org.hisp.dhis.period.Period)56 ArrayList (java.util.ArrayList)41 List (java.util.List)40 User (org.hisp.dhis.user.User)38 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)32 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)28 ClassPathResource (org.springframework.core.io.ClassPathResource)28 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)22 HashSet (java.util.HashSet)20 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)20 CategoryCombo (org.hisp.dhis.category.CategoryCombo)19 HashMap (java.util.HashMap)17 DhisSpringTest (org.hisp.dhis.DhisSpringTest)17 MonthlyPeriodType (org.hisp.dhis.period.MonthlyPeriodType)17 ReportingRate (org.hisp.dhis.common.ReportingRate)16 Section (org.hisp.dhis.dataset.Section)16