Search in sources :

Example 61 with DataSet

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;
}
Also used : DataSet(org.hisp.dhis.dataset.DataSet) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) CalendarPeriodType(org.hisp.dhis.period.CalendarPeriodType) PastAndCurrentPeriodFilter(org.hisp.dhis.system.filter.PastAndCurrentPeriodFilter) Date(java.util.Date)

Example 62 with DataSet

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;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) ArrayList(java.util.ArrayList) UserCredentials(org.hisp.dhis.user.UserCredentials)

Example 63 with DataSet

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;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElement(org.hisp.dhis.dataelement.DataElement) DataSet(org.hisp.dhis.dataset.DataSet) HashSet(java.util.HashSet)

Example 64 with DataSet

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

Example 65 with DataSet

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;
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataSet(org.hisp.dhis.dataset.DataSet) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) ArrayList(java.util.ArrayList)

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