Search in sources :

Example 31 with CategoryOptionCombo

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

the class CategoryOptionComboNameResourceTable method getPopulateTempTableContent.

@Override
public Optional<List<Object[]>> getPopulateTempTableContent() {
    List<Object[]> batchArgs = new ArrayList<>();
    for (CategoryCombo combo : objects) {
        if (!combo.isValid()) {
            log.warn("Ignoring category combo, not valid: " + combo);
            continue;
        }
        for (CategoryOptionCombo coc : combo.getOptionCombos()) {
            List<Object> values = new ArrayList<>();
            values.add(coc.getId());
            values.add(coc.getName());
            values.add(coc.isIgnoreApproval() ? APPROVAL_LEVEL_HIGHEST : null);
            values.add(coc.getLatestStartDate());
            values.add(coc.getEarliestEndDate());
            batchArgs.add(values.toArray());
        }
    }
    return Optional.of(batchArgs);
}
Also used : CategoryCombo(org.hisp.dhis.category.CategoryCombo) ArrayList(java.util.ArrayList) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 32 with CategoryOptionCombo

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

the class HibernateDataApprovalStore method getDataApprovals.

@Override
public List<DataApproval> getDataApprovals(Collection<DataApprovalLevel> dataApprovalLevels, Collection<DataApprovalWorkflow> workflows, Collection<Period> periods, Collection<OrganisationUnit> organisationUnits, Collection<CategoryOptionCombo> attributeOptionCombos) {
    List<Period> storedPeriods = periods.stream().map(p -> periodService.reloadPeriod(p)).collect(Collectors.toList());
    CriteriaBuilder builder = getCriteriaBuilder();
    return getList(builder, newJpaParameters().addPredicate(root -> root.get("dataApprovalLevel").in(dataApprovalLevels)).addPredicate(root -> root.get("workflow").in(workflows)).addPredicate(root -> root.get("period").in(storedPeriods)).addPredicate(root -> root.get("organisationUnit").in(organisationUnits)).addPredicate(root -> root.get("attributeOptionCombo").in(attributeOptionCombos)));
}
Also used : CategoryService(org.hisp.dhis.category.CategoryService) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow) PeriodService(org.hisp.dhis.period.PeriodService) DataApprovalState(org.hisp.dhis.dataapproval.DataApprovalState) UNAPPROVED_READY(org.hisp.dhis.dataapproval.DataApprovalState.UNAPPROVED_READY) StringUtils(org.apache.commons.lang3.StringUtils) ACCEPTED_HERE(org.hisp.dhis.dataapproval.DataApprovalState.ACCEPTED_HERE) CurrentUserServiceTarget(org.hisp.dhis.user.CurrentUserServiceTarget) UNAPPROVABLE(org.hisp.dhis.dataapproval.DataApprovalState.UNAPPROVABLE) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) APPROVED_ABOVE(org.hisp.dhis.dataapproval.DataApprovalState.APPROVED_ABOVE) SqlRowSet(org.springframework.jdbc.support.rowset.SqlRowSet) Repository(org.springframework.stereotype.Repository) Period(org.hisp.dhis.period.Period) UNAPPROVED_WAITING(org.hisp.dhis.dataapproval.DataApprovalState.UNAPPROVED_WAITING) APPROVED_HERE(org.hisp.dhis.dataapproval.DataApprovalState.APPROVED_HERE) Collection(java.util.Collection) SessionFactory(org.hibernate.SessionFactory) Set(java.util.Set) Collectors(java.util.stream.Collectors) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Cache(org.hisp.dhis.cache.Cache) AclService(org.hisp.dhis.security.acl.AclService) CategoryCombo(org.hisp.dhis.category.CategoryCombo) DataApproval(org.hisp.dhis.dataapproval.DataApproval) DataApprovalLevel(org.hisp.dhis.dataapproval.DataApprovalLevel) DataApprovalStatus(org.hisp.dhis.dataapproval.DataApprovalStatus) HibernateGenericStore(org.hisp.dhis.hibernate.HibernateGenericStore) IdentifiableObjectUtils(org.hisp.dhis.common.IdentifiableObjectUtils) JsonbFunctions(org.hisp.dhis.hibernate.jsonb.type.JsonbFunctions) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) User(org.hisp.dhis.user.User) SystemSettingManager(org.hisp.dhis.setting.SystemSettingManager) UNAPPROVED_ABOVE(org.hisp.dhis.dataapproval.DataApprovalState.UNAPPROVED_ABOVE) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) StatementBuilder(org.hisp.dhis.jdbc.StatementBuilder) CacheProvider(org.hisp.dhis.cache.CacheProvider) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) CurrentUserService(org.hisp.dhis.user.CurrentUserService) PeriodStore(org.hisp.dhis.period.PeriodStore) DataApprovalStore(org.hisp.dhis.dataapproval.DataApprovalStore) SettingKey(org.hisp.dhis.setting.SettingKey) DateUtils(org.hisp.dhis.util.DateUtils) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Period(org.hisp.dhis.period.Period)

Example 33 with CategoryOptionCombo

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

the class HibernateCategoryOptionComboStore method updateNames.

@Override
public void updateNames() {
    List<CategoryOptionCombo> categoryOptionCombos = getQuery("from CategoryOptionCombo co where co.name is null").list();
    int counter = 0;
    Session session = getSession();
    for (CategoryOptionCombo coc : categoryOptionCombos) {
        session.update(coc);
        if ((counter % 400) == 0) {
            dbmsManager.clearSession();
        }
    }
}
Also used : CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Session(org.hibernate.Session)

Example 34 with CategoryOptionCombo

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

the class DefaultAdxDataService method convertAttributesToDxf.

private void convertAttributesToDxf(Map<String, String> attributes, String optionComboName, CategoryCombo catCombo, IdSchemes idSchemes) throws AdxException {
    log.debug("ADX attributes: " + attributes);
    if (catCombo.isDefault()) {
        return;
    }
    Map<String, Category> categoryMap = getCodeCategoryMap(catCombo, idSchemes.getCategoryIdScheme());
    Map<String, String> attributeOptions = new HashMap<>();
    for (String category : categoryMap.keySet()) {
        if (attributes.containsKey(category)) {
            attributeOptions.put(category, attributes.get(category));
            attributes.remove(category);
        } else {
            throw new AdxException("Category combo " + catCombo.getName() + " must have " + categoryMap.get(category).getName());
        }
    }
    CategoryOptionCombo catOptCombo = getCatOptComboFromAttributes(attributeOptions, catCombo, idSchemes);
    attributes.put(optionComboName, catOptCombo.getPropertyValue(idSchemes.getCategoryOptionComboIdScheme()));
    log.debug("DXF attributes: " + attributes);
}
Also used : Category(org.hisp.dhis.category.Category) HashMap(java.util.HashMap) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 35 with CategoryOptionCombo

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

the class DefaultCompleteDataSetRegistrationExchangeService method initMetaDataProperties.

private MetadataProperties initMetaDataProperties(org.hisp.dhis.dxf2.dataset.CompleteDataSetRegistration cdsr, MetadataCallables callables, MetadataCaches cache) {
    String ds = StringUtils.trimToNull(cdsr.getDataSet());
    String pe = StringUtils.trimToNull(cdsr.getPeriod());
    String ou = StringUtils.trimToNull(cdsr.getOrganisationUnit());
    String aoc = StringUtils.trimToNull(cdsr.getAttributeOptionCombo());
    if (aoc == null) {
        CategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(cdsr.getCc(), cdsr.getCp(), false);
        aoc = attributeOptionCombo != null ? attributeOptionCombo.getUid() : aoc;
    }
    return new MetadataProperties(cache.getDataSets().get(ds, callables.getDataSetCallable().setId(ds)), cache.getPeriods().get(pe, callables.getPeriodCallable().setId(pe)), cache.getOrgUnits().get(ou, callables.getOrgUnitCallable().setId(ou)), cache.getAttrOptionCombos().get(aoc, callables.getOptionComboCallable().setId(aoc)));
}
Also used : CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

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