Search in sources :

Example 6 with CategoryOptionCombo

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

the class DataDimensionExtractor method getBaseDimensionalItemObject.

private BaseDimensionalItemObject getBaseDimensionalItemObject(final MapMap<Class<? extends IdentifiableObject>, String, IdentifiableObject> atomicObjects, final DimensionalItemId id) {
    BaseDimensionalItemObject dimensionalItemObject = null;
    switch(id.getDimensionItemType()) {
        case DATA_ELEMENT:
            DataElement dataElement = (DataElement) atomicObjects.getValue(DataElement.class, id.getId0());
            if (dataElement != null) {
                dimensionalItemObject = cloneIfNeeded(dataElement, id);
            }
            break;
        case INDICATOR:
            final Indicator indicator = (Indicator) atomicObjects.getValue(Indicator.class, id.getId0());
            if (indicator != null) {
                dimensionalItemObject = cloneIfNeeded(indicator, id);
            }
            break;
        case DATA_ELEMENT_OPERAND:
            dataElement = (DataElement) atomicObjects.getValue(DataElement.class, id.getId0());
            final CategoryOptionCombo categoryOptionCombo = id.getId1() == null ? null : (CategoryOptionCombo) atomicObjects.getValue(CategoryOptionCombo.class, id.getId1());
            final CategoryOptionCombo attributeOptionCombo = id.getId2() == null ? null : (CategoryOptionCombo) atomicObjects.getValue(CategoryOptionCombo.class, id.getId2());
            if (dataElement != null && (id.getId1() != null) == (categoryOptionCombo != null) && (id.getId2() != null) == (attributeOptionCombo != null)) {
                dimensionalItemObject = new DataElementOperand(dataElement, categoryOptionCombo, attributeOptionCombo);
            }
            break;
        case REPORTING_RATE:
            final DataSet dataSet = (DataSet) atomicObjects.getValue(DataSet.class, id.getId0());
            if (dataSet != null) {
                dimensionalItemObject = new ReportingRate(dataSet, ReportingRateMetric.valueOf(id.getId1()));
            }
            break;
        case PROGRAM_DATA_ELEMENT:
            Program program = (Program) atomicObjects.getValue(Program.class, id.getId0());
            dataElement = (DataElement) atomicObjects.getValue(DataElement.class, id.getId1());
            if (program != null && dataElement != null) {
                dimensionalItemObject = new ProgramDataElementDimensionItem(program, dataElement);
            }
            break;
        case PROGRAM_ATTRIBUTE:
            program = (Program) atomicObjects.getValue(Program.class, id.getId0());
            final TrackedEntityAttribute attribute = (TrackedEntityAttribute) atomicObjects.getValue(TrackedEntityAttribute.class, id.getId1());
            if (program != null && attribute != null) {
                dimensionalItemObject = new ProgramTrackedEntityAttributeDimensionItem(program, attribute);
            }
            break;
        case PROGRAM_INDICATOR:
            final ProgramIndicator programIndicator = (ProgramIndicator) atomicObjects.getValue(ProgramIndicator.class, id.getId0());
            if (programIndicator != null) {
                dimensionalItemObject = cloneIfNeeded(programIndicator, id);
            }
            break;
        default:
            log.warn("Unrecognized DimensionItemType " + id.getDimensionItemType().name() + " in getItemObjectMap");
            break;
    }
    return dimensionalItemObject;
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) Program(org.hisp.dhis.program.Program) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) DataSet(org.hisp.dhis.dataset.DataSet) ReportingRate(org.hisp.dhis.common.ReportingRate) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) ProgramTrackedEntityAttributeDimensionItem(org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Indicator(org.hisp.dhis.indicator.Indicator) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) BaseDimensionalItemObject(org.hisp.dhis.common.BaseDimensionalItemObject)

Example 7 with CategoryOptionCombo

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

the class DefaultDimensionService method getDataElementOperand.

/**
 * Returns a {@link DataElementOperand}. For identifier wild cards
 * {@link ExpressionService#SYMBOL_WILDCARD}, the relevant property will be
 * null.
 *
 * @param idScheme the identifier scheme.
 * @param dataElementId the data element identifier.
 * @param categoryOptionComboId the category option combo identifier.
 */
private DataElementOperand getDataElementOperand(IdScheme idScheme, String dataElementId, String categoryOptionComboId, String attributeOptionComboId) {
    DataElement dataElement = idObjectManager.getObject(DataElement.class, idScheme, dataElementId);
    CategoryOptionCombo categoryOptionCombo = idObjectManager.getObject(CategoryOptionCombo.class, idScheme, categoryOptionComboId);
    CategoryOptionCombo attributeOptionCombo = idObjectManager.getObject(CategoryOptionCombo.class, idScheme, attributeOptionComboId);
    if (dataElement == null || (categoryOptionCombo == null && !SYMBOL_WILDCARD.equals(categoryOptionComboId))) {
        return null;
    }
    return new DataElementOperand(dataElement, categoryOptionCombo, attributeOptionCombo);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 8 with CategoryOptionCombo

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

the class HibernateDataValueAuditStore method getDataValueAudits.

@Override
public List<DataValueAudit> getDataValueAudits(List<DataElement> dataElements, List<Period> periods, List<OrganisationUnit> organisationUnits, CategoryOptionCombo categoryOptionCombo, CategoryOptionCombo attributeOptionCombo, AuditType auditType) {
    CriteriaBuilder builder = getSession().getCriteriaBuilder();
    List<Function<Root<DataValueAudit>, Predicate>> predicates = getDataValueAuditPredicates(builder, dataElements, periods, organisationUnits, categoryOptionCombo, attributeOptionCombo, auditType);
    if (!predicates.isEmpty()) {
        return getList(builder, newJpaParameters().addPredicate(root -> builder.and(predicates.stream().map(p -> p.apply(root)).collect(Collectors.toList()).toArray(new Predicate[predicates.size()]))).addOrder(root -> builder.desc(root.get("created"))));
    } else {
        return new ArrayList<>();
    }
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) HibernateGenericStore(org.hisp.dhis.hibernate.HibernateGenericStore) DataValueAuditStore(org.hisp.dhis.datavalue.DataValueAuditStore) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) SessionFactory(org.hibernate.SessionFactory) DataValueAudit(org.hisp.dhis.datavalue.DataValueAudit) AuditType(org.hisp.dhis.common.AuditType) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) DataElement(org.hisp.dhis.dataelement.DataElement) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) List(java.util.List) Lists(com.google.common.collect.Lists) Predicate(javax.persistence.criteria.Predicate) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) PeriodStore(org.hisp.dhis.period.PeriodStore) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) DataValue(org.hisp.dhis.datavalue.DataValue) Repository(org.springframework.stereotype.Repository) Root(javax.persistence.criteria.Root) Period(org.hisp.dhis.period.Period) Transactional(org.springframework.transaction.annotation.Transactional) Function(java.util.function.Function) ArrayList(java.util.ArrayList) DataValueAudit(org.hisp.dhis.datavalue.DataValueAudit)

Example 9 with CategoryOptionCombo

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

the class DefaultAggregateAccessManager method canRead.

// ---------------------------------------------------------------------
// AggregateAccessManager implementation
// ---------------------------------------------------------------------
@Override
public List<String> canRead(User user, DataValue dataValue) {
    List<String> errors = new ArrayList<>();
    if (user == null || user.isSuper()) {
        return errors;
    }
    Set<CategoryOption> options = new HashSet<>();
    CategoryOptionCombo categoryOptionCombo = dataValue.getCategoryOptionCombo();
    if (categoryOptionCombo != null) {
        options.addAll(categoryOptionCombo.getCategoryOptions());
    }
    CategoryOptionCombo attributeOptionCombo = dataValue.getAttributeOptionCombo();
    if (attributeOptionCombo != null) {
        options.addAll(attributeOptionCombo.getCategoryOptions());
    }
    options.forEach(option -> {
        if (!aclService.canDataRead(user, option)) {
            errors.add("User has no data read access for CategoryOption: " + option.getUid());
        }
    });
    return errors;
}
Also used : ArrayList(java.util.ArrayList) CategoryOption(org.hisp.dhis.category.CategoryOption) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) HashSet(java.util.HashSet)

Example 10 with CategoryOptionCombo

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

the class HibernateCompleteDataSetRegistrationStore method getCompleteDataSetRegistration.

@Override
public CompleteDataSetRegistration getCompleteDataSetRegistration(DataSet dataSet, Period period, OrganisationUnit source, CategoryOptionCombo attributeOptionCombo) {
    Period storedPeriod = periodStore.reloadPeriod(period);
    if (storedPeriod == null) {
        return null;
    }
    CriteriaBuilder builder = getCriteriaBuilder();
    return getSingleResult(builder, newJpaParameters().addPredicate(root -> builder.equal(root, new CompleteDataSetRegistration(dataSet, storedPeriod, source, attributeOptionCombo))));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) HibernateGenericStore(org.hisp.dhis.hibernate.HibernateGenericStore) Criteria(org.hibernate.Criteria) Restrictions(org.hibernate.criterion.Restrictions) Date(java.util.Date) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) DataSet(org.hisp.dhis.dataset.DataSet) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) SessionFactory(org.hibernate.SessionFactory) Projections(org.hibernate.criterion.Projections) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) List(java.util.List) CompleteDataSetRegistrationStore(org.hisp.dhis.dataset.CompleteDataSetRegistrationStore) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) PeriodStore(org.hisp.dhis.period.PeriodStore) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) Repository(org.springframework.stereotype.Repository) Period(org.hisp.dhis.period.Period) Period(org.hisp.dhis.period.Period) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration)

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