use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.
the class PreCheckDataRelationsValidationHook method fetchAttributeOptionCombo.
private CategoryOptionCombo fetchAttributeOptionCombo(ValidationErrorReporter reporter, Event event, Program program) {
CategoryCombo categoryCombo = program.getCategoryCombo();
String cacheKey = event.getAttributeCategoryOptions() + categoryCombo.getUid();
Optional<String> cachedAOCId = reporter.getValidationContext().getCachedEventAOCProgramCC(cacheKey);
TrackerPreheat preheat = reporter.getValidationContext().getBundle().getPreheat();
if (cachedAOCId.isPresent()) {
return preheat.getCategoryOptionCombo(cachedAOCId.get());
}
CategoryOptionCombo aoc = categoryService.getCategoryOptionCombo(categoryCombo, getCategoryOptions(preheat, event));
reporter.getValidationContext().putCachedEventAOCProgramCC(cacheKey, aoc != null ? aoc.getUid() : null);
return aoc;
}
use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.
the class CsvImportServiceTest method testImportCategoryCombos.
@Test
void testImportCategoryCombos() throws IOException {
InputStream in = new ClassPathResource("csv/category_combos.csv").getInputStream();
Metadata metadata = csvImportService.fromCsv(in, new CsvImportOptions().setImportClass(CsvImportClass.CATEGORY_COMBO).setFirstRowIsHeader(true));
assertEquals(2, metadata.getCategoryCombos().size());
CategoryCombo genderAge = metadata.getCategoryCombos().get(0);
CategoryCombo partner = metadata.getCategoryCombos().get(1);
assertEquals("Gender and Age", genderAge.getName());
assertEquals(DataDimensionType.DISAGGREGATION, genderAge.getDataDimensionType());
assertEquals(DataDimensionType.ATTRIBUTE, partner.getDataDimensionType());
}
use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.
the class DataValueSetImportValidatorTest method testCheckDataValueStrictCategoryOptionCombos.
@Test
void testCheckDataValueStrictCategoryOptionCombos() {
DataValue dataValue = createRandomDataValue();
DataValueContext valueContext = createDataValueContext(dataValue).build();
valueContext.getDataElement().setCategoryCombo(new CategoryCombo());
DataSetContext dataSetContext = createMinimalDataSetContext().build();
ImportContext context = createMinimalImportContext(valueContext).strictCategoryOptionCombos(true).build();
assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
assertConflict(ErrorCode.E7634, "Category option combo: `<object1>` must be part of category combo of data element: `<object2>`", context, dataValue.getCategoryOptionCombo(), dataValue.getDataElement());
}
use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.
the class EventCategoryOptValidationHookTest method setUp.
@BeforeEach
public void setUp() {
initServices();
hook = new EventCategoryOptValidationHook(i18nManager);
catOption = createCategoryOption('A');
category = createCategory('A', catOption);
catCombo = createCategoryCombo('A', category);
attOptionCombo = createCategoryOptionCombo(catCombo, catOption);
defaultCatCombo = new CategoryCombo();
defaultCatCombo.setName(DEFAULT_CATEGORY_COMBO_NAME);
defaultCatOption = new CategoryOption();
defaultCatOption.setName(DEFAULT_NAME);
defaultCatOptionCombo = createCategoryOptionCombo(defaultCatCombo, defaultCatOption);
program = createProgram('A');
program.setCategoryCombo(catCombo);
event = new Event();
event.setEvent(CodeGenerator.generateUid());
event.setProgram(program.getUid());
event.setOccurredAt(EVENT_INSTANT);
User user = createUser('A');
TrackerBundle bundle = TrackerBundle.builder().user(user).build();
when(validationContext.getBundle()).thenReturn(bundle);
when(validationContext.getProgram(program.getUid())).thenReturn(program);
reporter = new ValidationErrorReporter(validationContext);
}
use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.
the class GetCategoryOptionCombosAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() {
canReadType(CategoryOptionCombo.class);
if (id != null) {
DataElement dataElement = dataElementService.getDataElement(id);
if (dataElement != null) {
categoryOptionCombos = dataElement.getCategoryOptionCombos();
}
} else if (categoryComboId != null) {
CategoryCombo categoryCombo = categoryService.getCategoryCombo(categoryComboId);
if (categoryCombo != null) {
categoryOptionCombos = categoryCombo.getOptionCombos();
}
} else if (categoryComboUid != null) {
CategoryCombo categoryCombo = categoryService.getCategoryCombo(categoryComboUid);
if (categoryCombo != null) {
categoryOptionCombos = categoryCombo.getOptionCombos();
}
}
User currentUser = currentUserService.getCurrentUser();
categoryOptionCombos.forEach(instance -> canReadInstance(instance, currentUser));
return SUCCESS;
}
Aggregations