Search in sources :

Example 1 with DataElementCategory

use of org.hisp.dhis.dataelement.DataElementCategory in project dhis2-core by dhis2.

the class GetMetaDataAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() {
    User user = currentUserService.getCurrentUser();
    Date lastUpdated = DateUtils.max(Sets.newHashSet(identifiableObjectManager.getLastUpdated(DataElement.class), identifiableObjectManager.getLastUpdated(OptionSet.class), identifiableObjectManager.getLastUpdated(Indicator.class), identifiableObjectManager.getLastUpdated(DataSet.class), identifiableObjectManager.getLastUpdated(DataElementCategoryCombo.class), identifiableObjectManager.getLastUpdated(DataElementCategory.class), identifiableObjectManager.getLastUpdated(DataElementCategoryOption.class)));
    String tag = lastUpdated != null && user != null ? (DateUtils.getLongDateString(lastUpdated) + SEP + user.getUid()) : null;
    if (ContextUtils.isNotModified(ServletActionContext.getRequest(), ServletActionContext.getResponse(), tag)) {
        return SUCCESS;
    }
    if (user != null && user.getOrganisationUnits().isEmpty()) {
        emptyOrganisationUnits = true;
        return SUCCESS;
    }
    significantZeros = dataElementService.getDataElementsByZeroIsSignificant(true);
    dataElements = dataElementService.getDataElementsWithDataSets();
    for (DataElement dataElement : dataElements) {
        if (dataElement != null && dataElement.getOptionSet() != null) {
            dataElementsWithOptionSet.add(dataElement);
        }
    }
    indicators = indicatorService.getIndicatorsWithDataSets();
    expressionService.substituteExpressions(indicators, null);
    dataSets = dataSetService.getCurrentUserDataSets();
    Set<DataElementCategoryCombo> categoryComboSet = new HashSet<>();
    Set<DataElementCategory> categorySet = new HashSet<>();
    for (DataSet dataSet : dataSets) {
        if (dataSet.getCategoryCombo() != null) {
            categoryComboSet.add(dataSet.getCategoryCombo());
        }
    }
    for (DataElementCategoryCombo categoryCombo : categoryComboSet) {
        if (categoryCombo.getCategories() != null) {
            categorySet.addAll(categoryCombo.getCategories());
        }
    }
    categoryCombos = new ArrayList<>(categoryComboSet);
    categories = new ArrayList<>(categorySet);
    for (DataElementCategory category : categories) {
        List<DataElementCategoryOption> categoryOptions = new ArrayList<>(categoryService.getDataElementCategoryOptions(category));
        Collections.sort(categoryOptions);
        categoryOptionMap.put(category.getUid(), categoryOptions);
    }
    Collections.sort(dataSets);
    Collections.sort(categoryCombos);
    Collections.sort(categories);
    defaultCategoryCombo = categoryService.getDefaultDataElementCategoryCombo();
    return SUCCESS;
}
Also used : User(org.hisp.dhis.user.User) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) DataSet(org.hisp.dhis.dataset.DataSet) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) ArrayList(java.util.ArrayList) Date(java.util.Date) DataElement(org.hisp.dhis.dataelement.DataElement) DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) HashSet(java.util.HashSet)

Example 2 with DataElementCategory

use of org.hisp.dhis.dataelement.DataElementCategory in project dhis2-core by dhis2.

the class DataElementCategoryControllerDocumentation method testAddDeleteCollectionItem.

@Test
public void testAddDeleteCollectionItem() throws Exception {
    MockHttpSession session = getSession("ALL");
    DataElementCategory category = createDataElementCategory('A');
    manager.save(category);
    Schema schema = schemaService.getSchema(DataElementCategory.class);
    List<Property> properties = schema.getProperties();
    for (Property property : properties) {
        if (property.isCollection()) {
            String collectionName = property.getCollectionName();
            IdentifiableObject item = createTestObject(property.getItemKlass(), 'A', category);
            if (item == null) {
                continue;
            } else {
                manager.save(item);
            }
            mvc.perform(post("/" + ENDPOINT + "/" + category.getUid() + "/" + collectionName + "/" + item.getUid()).session(session).contentType(TestUtils.APPLICATION_JSON_UTF8)).andDo(documentPrettyPrint(ENDPOINT + "/add" + collectionName)).andExpect(status().isNoContent());
            mvc.perform(delete("/" + ENDPOINT + "/" + category.getUid() + "/" + collectionName + "/" + item.getUid()).session(session).contentType(TestUtils.APPLICATION_JSON_UTF8)).andDo(documentPrettyPrint(ENDPOINT + "/delete" + collectionName)).andExpect(status().isNoContent());
        }
    }
}
Also used : Schema(org.hisp.dhis.schema.Schema) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) MockHttpSession(org.springframework.mock.web.MockHttpSession) Property(org.hisp.dhis.schema.Property) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Test(org.junit.Test) AbstractWebApiTest(org.hisp.dhis.webapi.documentation.controller.AbstractWebApiTest)

Example 3 with DataElementCategory

use of org.hisp.dhis.dataelement.DataElementCategory in project dhis2-core by dhis2.

the class DataElementCategoryControllerDocumentation method testDeleteByIdOk.

@Test
@Override
public void testDeleteByIdOk() throws Exception {
    DataElementCategory cat = createDataElementCategory('A');
    manager.save(cat);
    MockHttpSession session = getSession("ALL");
    mvc.perform(delete("/" + ENDPOINT + "/{id}", cat.getUid()).session(session).accept(MediaType.APPLICATION_JSON)).andExpect(status().is(deleteStatus)).andDo(documentPrettyPrint("categories/delete"));
}
Also used : DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) MockHttpSession(org.springframework.mock.web.MockHttpSession) Test(org.junit.Test) AbstractWebApiTest(org.hisp.dhis.webapi.documentation.controller.AbstractWebApiTest)

Example 4 with DataElementCategory

use of org.hisp.dhis.dataelement.DataElementCategory in project dhis2-core by dhis2.

the class DataElementCategoryControllerDocumentation method testGetByIdOk.

@Test
@Override
public void testGetByIdOk() throws Exception {
    DataElementCategory cat = createDataElementCategory('A');
    manager.save(cat);
    MockHttpSession session = getSession("ALL");
    Schema schema = schemaService.getSchema(DataElementCategory.class);
    Set<FieldDescriptor> fieldDescriptors = TestUtils.getFieldDescriptors(schema);
    mvc.perform(get("/" + CategorySchemaDescriptor.PLURAL + "/{id}", cat.getUid()).session(session).accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)).andExpect(jsonPath("$.name").value("DataElementCategoryA")).andExpect(jsonPath("$.shortName").value("DataElementCategoryA")).andDo(documentPrettyPrint(ENDPOINT + "/id", responseFields(fieldDescriptors.toArray(new FieldDescriptor[fieldDescriptors.size()]))));
}
Also used : Schema(org.hisp.dhis.schema.Schema) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) MockHttpSession(org.springframework.mock.web.MockHttpSession) FieldDescriptor(org.springframework.restdocs.payload.FieldDescriptor) Test(org.junit.Test) AbstractWebApiTest(org.hisp.dhis.webapi.documentation.controller.AbstractWebApiTest)

Example 5 with DataElementCategory

use of org.hisp.dhis.dataelement.DataElementCategory in project dhis2-core by dhis2.

the class DataValueDimensionTest method setUpTest.

@Override
public void setUpTest() {
    male = new DataElementCategoryOption("Male");
    female = new DataElementCategoryOption("Female");
    under15 = new DataElementCategoryOption("<15");
    over15 = new DataElementCategoryOption(">15");
    categoryService.addDataElementCategoryOption(male);
    categoryService.addDataElementCategoryOption(female);
    categoryService.addDataElementCategoryOption(under15);
    categoryService.addDataElementCategoryOption(over15);
    gender = new DataElementCategory("Gender", DataDimensionType.DISAGGREGATION);
    gender.getCategoryOptions().add(male);
    gender.getCategoryOptions().add(female);
    ageGroup = new DataElementCategory("Agegroup", DataDimensionType.DISAGGREGATION);
    ageGroup.getCategoryOptions().add(under15);
    ageGroup.getCategoryOptions().add(over15);
    categoryService.addDataElementCategory(gender);
    categoryService.addDataElementCategory(ageGroup);
    genderAndAgeGroup = new DataElementCategoryCombo("Gender and Agegroup", DataDimensionType.DISAGGREGATION);
    genderAndAgeGroup.getCategories().add(gender);
    genderAndAgeGroup.getCategories().add(ageGroup);
    categoryService.addDataElementCategoryCombo(genderAndAgeGroup);
    categoryService.generateOptionCombos(genderAndAgeGroup);
    dataElementA = createDataElement('A', genderAndAgeGroup);
    dataElementService.addDataElement(dataElementA);
    periodA = createPeriod(getDate(2000, 1, 1), getDate(2000, 2, 1));
    periodService.addPeriod(periodA);
    sourceA = createOrganisationUnit('A');
    organisationUnitService.addOrganisationUnit(sourceA);
    defaultOptionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
    for (DataElementCategoryOptionCombo categoryOptionCombo : genderAndAgeGroup.getOptionCombos()) {
        dataValueService.addDataValue(createDataValue(dataElementA, periodA, sourceA, "10", categoryOptionCombo, defaultOptionCombo));
    }
}
Also used : DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Aggregations

DataElementCategory (org.hisp.dhis.dataelement.DataElementCategory)29 CategoryOptionGroupSet (org.hisp.dhis.dataelement.CategoryOptionGroupSet)12 HashMap (java.util.HashMap)8 DataElementCategoryCombo (org.hisp.dhis.dataelement.DataElementCategoryCombo)8 HashSet (java.util.HashSet)7 DataElement (org.hisp.dhis.dataelement.DataElement)7 DataElementCategoryOption (org.hisp.dhis.dataelement.DataElementCategoryOption)7 ArrayList (java.util.ArrayList)6 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)6 OrganisationUnitGroupSet (org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)6 Test (org.junit.Test)6 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)5 OrganisationUnitLevel (org.hisp.dhis.organisationunit.OrganisationUnitLevel)5 User (org.hisp.dhis.user.User)5 DataSet (org.hisp.dhis.dataset.DataSet)4 Section (org.hisp.dhis.dataset.Section)4 List (java.util.List)3 AnalyticsTableColumn (org.hisp.dhis.analytics.AnalyticsTableColumn)3 DataElementGroupSet (org.hisp.dhis.dataelement.DataElementGroupSet)3 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)3