use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.
the class ProgramDeletionHandler method deleteCategoryCombo.
private void deleteCategoryCombo(CategoryCombo categoryCombo) {
CategoryCombo defaultCategoryCombo = categoryService.getCategoryComboByName(DEFAULT_CATEGORY_COMBO_NAME);
Collection<Program> programs = idObjectManager.getAllNoAcl(Program.class);
for (Program program : programs) {
if (program != null && categoryCombo.equals(program.getCategoryCombo())) {
program.setCategoryCombo(defaultCategoryCombo);
idObjectManager.updateNoAcl(program);
}
}
}
use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.
the class ProgramStageSectionIntegrationTest method setUpTest.
@Override
public void setUpTest() {
OrganisationUnit organisationUnit = createOrganisationUnit('A');
organisationUnitService.addOrganisationUnit(organisationUnit);
sectionA = createProgramStageSection('A', 1);
programStageSectionService.saveProgramStageSection(sectionA);
CategoryCombo categoryCombo = createCategoryCombo('A');
categoryService.addCategoryCombo(categoryCombo);
DataElement dataElementA = createDataElement('A', categoryCombo);
dataElementService.addDataElement(dataElementA);
programStageDataElementA = createProgramStageDataElement(stageA, dataElementA, 1);
program = createProgram('A', new HashSet<>(), organisationUnit);
programService.addProgram(program);
stageA = new ProgramStage("A", program);
stageA.setUid("UID-A");
stageA.setProgramStageSections(Sets.newHashSet(sectionA));
stageA.setProgramStageDataElements(Sets.newHashSet(programStageDataElementA));
}
use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.
the class ProgramMapperTest method testCategoryComboIsSetForDefaultCategoryCombos.
@Test
void testCategoryComboIsSetForDefaultCategoryCombos() {
Program program = new Program();
CategoryCombo cc = createCategoryCombo('A');
cc.setName(CategoryCombo.DEFAULT_CATEGORY_COMBO_NAME);
assertTrue(cc.isDefault(), "tests rely on this CC being the default one");
program.setCategoryCombo(cc);
Program mappedProgram = ProgramMapper.INSTANCE.map(program);
assertEquals(cc, mappedProgram.getCategoryCombo());
}
use of org.hisp.dhis.category.CategoryCombo 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(CategoryCombo.class), identifiableObjectManager.getLastUpdated(Category.class), identifiableObjectManager.getLastUpdated(CategoryOption.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.substituteIndicatorExpressions(indicators);
dataSets = dataSetService.getUserDataWrite(user);
Set<CategoryCombo> categoryComboSet = new HashSet<>();
Set<Category> categorySet = new HashSet<>();
for (DataSet dataSet : dataSets) {
if (dataSet.getCategoryCombo() != null) {
categoryComboSet.add(dataSet.getCategoryCombo());
}
}
for (CategoryCombo categoryCombo : categoryComboSet) {
if (categoryCombo.getCategories() != null) {
categorySet.addAll(categoryCombo.getCategories());
}
}
categoryCombos = new ArrayList<>(categoryComboSet);
categories = new ArrayList<>(categorySet);
for (Category category : categories) {
List<CategoryOption> categoryOptions = new ArrayList<>(categoryService.getDataWriteCategoryOptions(category, user));
Collections.sort(categoryOptions);
categoryOptionMap.put(category.getUid(), categoryOptions);
}
Set<String> nonAccessibleDataSetIds = new HashSet<>();
for (DataSet dataSet : dataSets) {
CategoryCombo categoryCombo = dataSet.getCategoryCombo();
if (categoryCombo != null && categoryCombo.getCategories() != null) {
for (Category category : categoryCombo.getCategories()) {
if (!categoryOptionMap.containsKey(category.getUid()) || categoryOptionMap.get(category.getUid()).isEmpty()) {
nonAccessibleDataSetIds.add(dataSet.getUid());
break;
}
}
}
}
dataSets = dataSets.stream().filter(dataSet -> !nonAccessibleDataSetIds.contains(dataSet.getUid())).collect(Collectors.toList());
lockExceptions = dataSetService.getAllLockExceptions();
Collections.sort(dataSets);
Collections.sort(categoryCombos);
Collections.sort(categories);
defaultCategoryCombo = categoryService.getDefaultCategoryCombo();
return SUCCESS;
}
use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.
the class LoadFormAction method processSectionForAutoOrdering.
private void processSectionForAutoOrdering(Section section) {
List<CategoryCombo> sortedCategoryCombos = getSortedCategoryCombos(section.getCategoryCombos());
for (CategoryCombo categoryCombo : sortedCategoryCombos) {
sectionCategoryComboDataElements.put(section.getId() + "-" + categoryCombo.getId(), section.getDataElementsByCategoryCombo(categoryCombo));
orderedSectionCategoryCombos.put(String.valueOf(categoryCombo.getId()), categoryCombo.getId());
}
sectionCombos.put(section.getId(), sortedCategoryCombos.stream().map(ca -> String.valueOf(ca.getId())).collect(Collectors.toList()));
}
Aggregations