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;
}
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());
}
}
}
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"));
}
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()]))));
}
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));
}
}
Aggregations