Search in sources :

Example 56 with CategoryCombo

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;
}
Also used : CategoryCombo(org.hisp.dhis.category.CategoryCombo) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 57 with CategoryCombo

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());
}
Also used : CategoryCombo(org.hisp.dhis.category.CategoryCombo) InputStream(java.io.InputStream) Metadata(org.hisp.dhis.dxf2.metadata.Metadata) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 58 with CategoryCombo

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());
}
Also used : DataValue(org.hisp.dhis.dxf2.datavalue.DataValue) CategoryCombo(org.hisp.dhis.category.CategoryCombo) DataSetContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext) DataValueContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext) Test(org.junit.jupiter.api.Test)

Example 59 with CategoryCombo

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);
}
Also used : User(org.hisp.dhis.user.User) CategoryCombo(org.hisp.dhis.category.CategoryCombo) CategoryOption(org.hisp.dhis.category.CategoryOption) Event(org.hisp.dhis.tracker.domain.Event) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 60 with CategoryCombo

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;
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) User(org.hisp.dhis.user.User) CategoryCombo(org.hisp.dhis.category.CategoryCombo)

Aggregations

CategoryCombo (org.hisp.dhis.category.CategoryCombo)114 Test (org.junit.jupiter.api.Test)66 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)53 CategoryOption (org.hisp.dhis.category.CategoryOption)47 Category (org.hisp.dhis.category.Category)41 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)39 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)36 Program (org.hisp.dhis.program.Program)31 Event (org.hisp.dhis.tracker.domain.Event)27 TrackedEntityType (org.hisp.dhis.trackedentity.TrackedEntityType)23 BeforeEach (org.junit.jupiter.api.BeforeEach)23 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)22 Collectors (java.util.stream.Collectors)21 ProgramInstance (org.hisp.dhis.program.ProgramInstance)21 Collections (java.util.Collections)20 CategoryService (org.hisp.dhis.category.CategoryService)20 CodeGenerator (org.hisp.dhis.common.CodeGenerator)20 ProgramStage (org.hisp.dhis.program.ProgramStage)20 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)20 Sets (com.google.common.collect.Sets)19