Search in sources :

Example 26 with CategoryOptionCombo

use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.

the class AttributeOptionComboCheck method check.

@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
    Program program = ctx.getProgramsMap().get(event.getProgram());
    CategoryOptionCombo coc = ctx.getCategoryOptionComboMap().get(event.getUid());
    if (coc != null && coc.isDefault() && program.getCategoryCombo() != null && !program.getCategoryCombo().isDefault()) {
        ImportSummary importSummary = new ImportSummary(event.getEvent());
        importSummary.addConflict("attributeOptionCombo", "Valid attribute option combo must be specified since program does not have the default category combo");
        importSummary.setStatus(ImportStatus.ERROR);
        return importSummary.incrementIgnored();
    }
    return success();
}
Also used : Program(org.hisp.dhis.program.Program) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 27 with CategoryOptionCombo

use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.

the class AttributeOptionComboAclCheck method check.

@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
    ImportSummary importSummary = new ImportSummary();
    TrackerAccessManager trackerAccessManager = ctx.getServiceDelegator().getTrackerAccessManager();
    ImportOptions importOptions = ctx.getImportOptions();
    CategoryOptionCombo categoryOptionCombo = ctx.getCategoryOptionComboMap().get(event.getUid());
    List<String> errors = trackerAccessManager.canWrite(importOptions.getUser(), categoryOptionCombo);
    if (!errors.isEmpty()) {
        importSummary.setStatus(ImportStatus.ERROR);
        errors.forEach(error -> importSummary.addConflict("CategoryOptionCombo", error));
        importSummary.incrementIgnored();
    }
    return importSummary;
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) TrackerAccessManager(org.hisp.dhis.trackedentity.TrackerAccessManager) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 28 with CategoryOptionCombo

use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.

the class DefaultAclService method checkOptionComboSharingPermission.

private boolean checkOptionComboSharingPermission(User user, IdentifiableObject object, Permission permission) {
    CategoryOptionCombo optionCombo = (CategoryOptionCombo) object;
    if (optionCombo.isDefault() || optionCombo.getCategoryOptions().isEmpty()) {
        return true;
    }
    List<Long> accessibleOptions = new ArrayList<>();
    for (CategoryOption option : optionCombo.getCategoryOptions()) {
        if (checkSharingPermission(user, option, permission)) {
            accessibleOptions.add(option.getId());
        }
    }
    return accessibleOptions.size() == optionCombo.getCategoryOptions().size();
}
Also used : ArrayList(java.util.ArrayList) CategoryOption(org.hisp.dhis.category.CategoryOption) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 29 with CategoryOptionCombo

use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.

the class DefaultAclService method canWrite.

private <T extends IdentifiableObject> boolean canWrite(User user, T object, Class<? extends T> objType) {
    if (readWriteCommonCheck(user, objType)) {
        return true;
    }
    Schema schema = schemaService.getSchema(objType);
    List<String> anyAuthorities = new ArrayList<>(schema.getAuthorityByType(AuthorityType.CREATE));
    if (anyAuthorities.isEmpty()) {
        anyAuthorities.addAll(schema.getAuthorityByType(AuthorityType.CREATE_PRIVATE));
        anyAuthorities.addAll(schema.getAuthorityByType(AuthorityType.CREATE_PUBLIC));
    }
    if (canAccess(user, anyAuthorities)) {
        if (object instanceof CategoryOptionCombo) {
            return checkOptionComboSharingPermission(user, object, Permission.WRITE);
        }
        return writeCommonCheck(schema, user, object, objType);
    } else if (schema.isImplicitPrivateAuthority() && checkSharingAccess(user, object, objType)) {
        return true;
    }
    return false;
}
Also used : Schema(org.hisp.dhis.schema.Schema) ArrayList(java.util.ArrayList) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 30 with CategoryOptionCombo

use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.

the class DataSetOrganisationUnitCategoryResourceTable method getPopulateTempTableContent.

/**
 * Iterate over data sets and associated organisation units. If data set has
 * a category combination and the organisation unit has category options,
 * find the intersection of the category option combinations linked to the
 * organisation unit through its category options, and the category option
 * combinations linked to the data set through its category combination. If
 * not, use the default category option combo.
 */
@Override
public Optional<List<Object[]>> getPopulateTempTableContent() {
    List<Object[]> batchArgs = new ArrayList<>();
    for (DataSet dataSet : objects) {
        CategoryCombo categoryCombo = dataSet.getCategoryCombo();
        for (OrganisationUnit orgUnit : dataSet.getSources()) {
            if (!categoryCombo.isDefault()) {
                if (orgUnit.hasCategoryOptions()) {
                    Set<CategoryOption> orgUnitOptions = orgUnit.getCategoryOptions();
                    for (CategoryOptionCombo optionCombo : categoryCombo.getOptionCombos()) {
                        Set<CategoryOption> optionComboOptions = optionCombo.getCategoryOptions();
                        if (orgUnitOptions.containsAll(optionComboOptions)) {
                            Date startDate = DateUtils.min(optionComboOptions.stream().map(co -> co.getStartDate()).collect(Collectors.toSet()));
                            Date endDate = DateUtils.max(optionComboOptions.stream().map(co -> co.getAdjustedEndDate(dataSet)).collect(Collectors.toSet()));
                            List<Object> values = Lists.newArrayList(dataSet.getId(), orgUnit.getId(), optionCombo.getId(), startDate, endDate);
                            batchArgs.add(values.toArray());
                        }
                    }
                }
            } else {
                List<Object> values = Lists.newArrayList(dataSet.getId(), orgUnit.getId(), defaultOptionCombo.getId(), null, null);
                batchArgs.add(values.toArray());
            }
        }
    }
    return Optional.of(batchArgs);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) CategoryCombo(org.hisp.dhis.category.CategoryCombo) ArrayList(java.util.ArrayList) CategoryOption(org.hisp.dhis.category.CategoryOption) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Date(java.util.Date)

Aggregations

CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)218 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)94 DataElement (org.hisp.dhis.dataelement.DataElement)68 Period (org.hisp.dhis.period.Period)67 Test (org.junit.jupiter.api.Test)58 CategoryCombo (org.hisp.dhis.category.CategoryCombo)52 CategoryOption (org.hisp.dhis.category.CategoryOption)51 ArrayList (java.util.ArrayList)39 Program (org.hisp.dhis.program.Program)31 DataValue (org.hisp.dhis.datavalue.DataValue)30 Collectors (java.util.stream.Collectors)26 Category (org.hisp.dhis.category.Category)26 Date (java.util.Date)25 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)25 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)23 CategoryService (org.hisp.dhis.category.CategoryService)20 DataSet (org.hisp.dhis.dataset.DataSet)20 ProgramStage (org.hisp.dhis.program.ProgramStage)20 Event (org.hisp.dhis.tracker.domain.Event)20 ProgramInstance (org.hisp.dhis.program.ProgramInstance)16