Search in sources :

Example 6 with CategoryOptionGroupSet

use of org.hisp.dhis.dataelement.CategoryOptionGroupSet in project dhis2-core by dhis2.

the class DefaultDataApprovalLevelService method getLowestDataApprovalLevel.

@Override
public DataApprovalLevel getLowestDataApprovalLevel(OrganisationUnit orgUnit, DataElementCategoryOptionCombo attributeOptionCombo) {
    Set<CategoryOptionGroupSet> cogSets = null;
    if (attributeOptionCombo != null && attributeOptionCombo != categoryService.getDefaultDataElementCategoryOptionCombo()) {
        cogSets = new HashSet<>();
        for (DataElementCategoryOption option : attributeOptionCombo.getCategoryOptions()) {
            if (option.getGroupSets() != null) {
                cogSets.addAll(option.getGroupSets());
            }
        }
    }
    int orgUnitLevel = orgUnit.getLevel();
    List<DataApprovalLevel> approvalLevels = getDataApprovalLevelsByOrgUnitLevel(orgUnitLevel);
    for (DataApprovalLevel level : Lists.reverse(approvalLevels)) {
        if (level.getCategoryOptionGroupSet() == null) {
            if (cogSets == null) {
                return level;
            }
        } else if (cogSets != null && cogSets.contains(level.getCategoryOptionGroupSet())) {
            return level;
        }
    }
    return null;
}
Also used : DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) CategoryOptionGroupSet(org.hisp.dhis.dataelement.CategoryOptionGroupSet)

Example 7 with CategoryOptionGroupSet

use of org.hisp.dhis.dataelement.CategoryOptionGroupSet in project dhis2-core by dhis2.

the class UpdateUserAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    if (!userService.canAddOrUpdateUser(ugSelected)) {
        throw new AccessDeniedException("You cannot edit this user");
    }
    User currentUser = currentUserService.getCurrentUser();
    // ---------------------------------------------------------------------
    // User credentials and user
    // ---------------------------------------------------------------------
    User user = userService.getUser(id);
    user.setSurname(StringUtils.trimToNull(surname));
    user.setFirstName(StringUtils.trimToNull(firstName));
    user.setEmail(StringUtils.trimToNull(email));
    user.setPhoneNumber(StringUtils.trimToNull(phoneNumber));
    UserCredentials userCredentials = user.getUserCredentials();
    userCredentials.setExternalAuth(externalAuth);
    userCredentials.setOpenId(StringUtils.trimToNull(openId));
    userCredentials.setLdapId(StringUtils.trimToNull(ldapId));
    if (jsonAttributeValues != null) {
        attributeService.updateAttributeValues(user, jsonAttributeValues);
    }
    // ---------------------------------------------------------------------
    // Organisation units
    // ---------------------------------------------------------------------
    Set<OrganisationUnit> dataCaptureOrgUnits = new HashSet<>(selectionManager.getSelectedOrganisationUnits());
    user.updateOrganisationUnits(dataCaptureOrgUnits);
    Set<OrganisationUnit> dataViewOrgUnits = new HashSet<>(selectionTreeManager.getReloadedSelectedOrganisationUnits());
    user.setDataViewOrganisationUnits(dataViewOrgUnits);
    if (dataViewOrgUnits.size() == 0 && currentUser.getDataViewOrganisationUnits().size() != 0) {
        user.setDataViewOrganisationUnits(new HashSet<>(currentUser.getDataViewOrganisationUnits()));
    }
    // ---------------------------------------------------------------------
    // User roles
    // ---------------------------------------------------------------------
    Set<UserAuthorityGroup> userAuthorityGroups = new HashSet<>();
    for (String id : urSelected) {
        userAuthorityGroups.add(userService.getUserAuthorityGroup(id));
    }
    userService.canIssueFilter(userAuthorityGroups);
    userCredentials.setUserAuthorityGroups(userAuthorityGroups);
    // ---------------------------------------------------------------------
    // Dimension constraints
    //
    // Note that any new user must inherit dimension constraints (if any)
    // from the current user.
    // ---------------------------------------------------------------------
    userCredentials.setCogsDimensionConstraints(new HashSet<>(currentUser.getUserCredentials().getCogsDimensionConstraints()));
    userCredentials.setCatDimensionConstraints(new HashSet<>(currentUser.getUserCredentials().getCatDimensionConstraints()));
    for (String id : dcSelected) {
        CategoryOptionGroupSet cogs = categoryService.getCategoryOptionGroupSet(id);
        if (cogs != null) {
            userCredentials.getCogsDimensionConstraints().add(cogs);
            continue;
        }
        DataElementCategory cat = categoryService.getDataElementCategory(id);
        if (cat != null) {
            userCredentials.getCatDimensionConstraints().add(cat);
            continue;
        }
    }
    // ---------------------------------------------------------------------
    // Set password and update user
    // ---------------------------------------------------------------------
    userService.encodeAndSetPassword(userCredentials, rawPassword);
    userService.updateUserCredentials(userCredentials);
    userService.updateUser(user);
    if (user.equals(currentUser) && !dataCaptureOrgUnits.isEmpty()) {
        selectionManager.setRootOrganisationUnits(dataCaptureOrgUnits);
        selectionManager.setSelectedOrganisationUnits(dataCaptureOrgUnits);
    } else {
        selectionManager.setRootOrganisationUnits(currentUser.getOrganisationUnits());
        if (ouwtSelected != null && manager.search(OrganisationUnit.class, ouwtSelected) != null) {
            selectionManager.setSelectedOrganisationUnits(Lists.newArrayList(manager.search(OrganisationUnit.class, ouwtSelected)));
        } else {
            selectionManager.setSelectedOrganisationUnits(currentUser.getOrganisationUnits());
        }
    }
    if (user.equals(currentUser) && !dataViewOrgUnits.isEmpty()) {
        selectionTreeManager.setRootOrganisationUnits(dataViewOrgUnits);
        selectionTreeManager.setSelectedOrganisationUnits(dataViewOrgUnits);
    }
    // ---------------------------------------------------------------------
    // User settings
    // ---------------------------------------------------------------------
    userSettingService.saveUserSetting(UserSettingKey.UI_LOCALE, LocaleUtils.getLocale(localeUi), user);
    userSettingService.saveUserSetting(UserSettingKey.DB_LOCALE, LocaleUtils.getLocale(localeDb), user);
    // ---------------------------------------------------------------------
    // User groups
    // ---------------------------------------------------------------------
    Set<UserGroup> userGroups = new HashSet<>();
    for (String id : ugSelected) {
        userGroups.add(userGroupService.getUserGroup(id));
    }
    for (UserGroup userGroup : new HashSet<>(user.getGroups())) {
        if (!userGroups.contains(userGroup)) {
            userGroup.removeUser(user);
            userGroupService.updateUserGroup(userGroup);
        }
    }
    for (UserGroup userGroup : userGroups) {
        userGroup.addUser(user);
        userGroupService.updateUserGroup(userGroup);
    }
    return SUCCESS;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) AccessDeniedException(org.springframework.security.access.AccessDeniedException) User(org.hisp.dhis.user.User) CategoryOptionGroupSet(org.hisp.dhis.dataelement.CategoryOptionGroupSet) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) UserGroup(org.hisp.dhis.user.UserGroup) UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) UserCredentials(org.hisp.dhis.user.UserCredentials) HashSet(java.util.HashSet)

Example 8 with CategoryOptionGroupSet

use of org.hisp.dhis.dataelement.CategoryOptionGroupSet in project dhis2-core by dhis2.

the class UserCredentials method getDimensionConstraints.

/**
     * Returns the dimensions to use as constrains (filters) in data analytics
     * aggregation.
     */
public Set<DimensionalObject> getDimensionConstraints() {
    Set<DimensionalObject> constraints = new HashSet<>();
    for (CategoryOptionGroupSet cogs : cogsDimensionConstraints) {
        cogs.setDimensionType(DimensionType.CATEGORY_OPTION_GROUP_SET);
        constraints.add(cogs);
    }
    for (DataElementCategory cat : catDimensionConstraints) {
        cat.setDimensionType(DimensionType.CATEGORY);
        constraints.add(cat);
    }
    return constraints;
}
Also used : CategoryOptionGroupSet(org.hisp.dhis.dataelement.CategoryOptionGroupSet) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) HashSet(java.util.HashSet) DimensionalObject(org.hisp.dhis.common.DimensionalObject)

Example 9 with CategoryOptionGroupSet

use of org.hisp.dhis.dataelement.CategoryOptionGroupSet in project dhis2-core by dhis2.

the class JdbcCompletenessTargetTableManager method getDimensionColumns.

@Override
public List<AnalyticsTableColumn> getDimensionColumns(AnalyticsTable table) {
    List<AnalyticsTableColumn> columns = new ArrayList<>();
    List<OrganisationUnitGroupSet> orgUnitGroupSets = idObjectManager.getDataDimensionsNoAcl(OrganisationUnitGroupSet.class);
    List<OrganisationUnitLevel> levels = organisationUnitService.getFilledOrganisationUnitLevels();
    List<CategoryOptionGroupSet> attributeCategoryOptionGroupSets = categoryService.getAttributeCategoryOptionGroupSetsNoAcl();
    List<DataElementCategory> attributeCategories = categoryService.getAttributeDataDimensionCategoriesNoAcl();
    for (OrganisationUnitGroupSet groupSet : orgUnitGroupSets) {
        columns.add(new AnalyticsTableColumn(quote(groupSet.getUid()), "character(11)", "ougs." + quote(groupSet.getUid()), groupSet.getCreated()));
    }
    for (OrganisationUnitLevel level : levels) {
        String column = quote(PREFIX_ORGUNITLEVEL + level.getLevel());
        columns.add(new AnalyticsTableColumn(column, "character(11)", "ous." + column, level.getCreated()));
    }
    for (CategoryOptionGroupSet groupSet : attributeCategoryOptionGroupSets) {
        columns.add(new AnalyticsTableColumn(quote(groupSet.getUid()), "character(11)", "acs." + quote(groupSet.getUid()), groupSet.getCreated()));
    }
    for (DataElementCategory category : attributeCategories) {
        columns.add(new AnalyticsTableColumn(quote(category.getUid()), "character(11)", "acs." + quote(category.getUid()), category.getCreated()));
    }
    AnalyticsTableColumn ouOpening = new AnalyticsTableColumn(quote("ouopeningdate"), "date", "ou.openingdate");
    AnalyticsTableColumn ouClosed = new AnalyticsTableColumn(quote("oucloseddate"), "date", "ou.closeddate");
    AnalyticsTableColumn coStart = new AnalyticsTableColumn(quote("costartdate"), "date", "doc.costartdate");
    AnalyticsTableColumn coEnd = new AnalyticsTableColumn(quote("coenddate"), "date", "doc.coenddate");
    AnalyticsTableColumn ds = new AnalyticsTableColumn(quote("dx"), "character(11) not null", "ds.uid");
    AnalyticsTableColumn ao = new AnalyticsTableColumn(quote("ao"), "character(11) not null", "ao.uid");
    columns.addAll(Lists.newArrayList(ouOpening, ouClosed, coStart, coEnd, ds, ao));
    return filterDimensionColumns(columns);
}
Also used : OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) ArrayList(java.util.ArrayList) CategoryOptionGroupSet(org.hisp.dhis.dataelement.CategoryOptionGroupSet) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) AnalyticsTableColumn(org.hisp.dhis.analytics.AnalyticsTableColumn) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)

Example 10 with CategoryOptionGroupSet

use of org.hisp.dhis.dataelement.CategoryOptionGroupSet in project dhis2-core by dhis2.

the class JdbcCompletenessTableManager method getDimensionColumns.

@Override
public List<AnalyticsTableColumn> getDimensionColumns(AnalyticsTable table) {
    List<AnalyticsTableColumn> columns = new ArrayList<>();
    List<OrganisationUnitGroupSet> orgUnitGroupSets = idObjectManager.getDataDimensionsNoAcl(OrganisationUnitGroupSet.class);
    List<OrganisationUnitLevel> levels = organisationUnitService.getFilledOrganisationUnitLevels();
    List<CategoryOptionGroupSet> attributeCategoryOptionGroupSets = categoryService.getAttributeCategoryOptionGroupSetsNoAcl();
    List<DataElementCategory> attributeCategories = categoryService.getAttributeDataDimensionCategoriesNoAcl();
    for (OrganisationUnitGroupSet groupSet : orgUnitGroupSets) {
        columns.add(new AnalyticsTableColumn(quote(groupSet.getUid()), "character(11)", "ougs." + quote(groupSet.getUid()), groupSet.getCreated()));
    }
    for (OrganisationUnitLevel level : levels) {
        String column = quote(PREFIX_ORGUNITLEVEL + level.getLevel());
        columns.add(new AnalyticsTableColumn(column, "character(11)", "ous." + column, level.getCreated()));
    }
    for (CategoryOptionGroupSet groupSet : attributeCategoryOptionGroupSets) {
        columns.add(new AnalyticsTableColumn(quote(groupSet.getUid()), "character(11)", "acs." + quote(groupSet.getUid()), groupSet.getCreated()));
    }
    for (DataElementCategory category : attributeCategories) {
        columns.add(new AnalyticsTableColumn(quote(category.getUid()), "character(11)", "acs." + quote(category.getUid()), category.getCreated()));
    }
    for (PeriodType periodType : PeriodType.getAvailablePeriodTypes()) {
        String column = quote(periodType.getName().toLowerCase());
        columns.add(new AnalyticsTableColumn(column, "character varying(15)", "ps." + column));
    }
    String timelyDateDiff = statementBuilder.getDaysBetweenDates("pe.enddate", statementBuilder.getCastToDate("cdr.date"));
    String timelyAlias = "(select (" + timelyDateDiff + ") <= ds.timelydays) as timely";
    AnalyticsTableColumn tm = new AnalyticsTableColumn(quote("timely"), "boolean", timelyAlias);
    AnalyticsTableColumn ds = new AnalyticsTableColumn(quote("dx"), "character(11) not null", "ds.uid");
    columns.addAll(Lists.newArrayList(ds, tm));
    return filterDimensionColumns(columns);
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) CategoryOptionGroupSet(org.hisp.dhis.dataelement.CategoryOptionGroupSet) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) AnalyticsTableColumn(org.hisp.dhis.analytics.AnalyticsTableColumn) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)

Aggregations

CategoryOptionGroupSet (org.hisp.dhis.dataelement.CategoryOptionGroupSet)10 DataElementCategory (org.hisp.dhis.dataelement.DataElementCategory)7 OrganisationUnitGroupSet (org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)5 OrganisationUnitLevel (org.hisp.dhis.organisationunit.OrganisationUnitLevel)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 AnalyticsTableColumn (org.hisp.dhis.analytics.AnalyticsTableColumn)3 PeriodType (org.hisp.dhis.period.PeriodType)3 UserCredentials (org.hisp.dhis.user.UserCredentials)3 DimensionalObject (org.hisp.dhis.common.DimensionalObject)2 DataElementGroupSet (org.hisp.dhis.dataelement.DataElementGroupSet)2 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)2 User (org.hisp.dhis.user.User)2 UserAuthorityGroup (org.hisp.dhis.user.UserAuthorityGroup)2 UserGroup (org.hisp.dhis.user.UserGroup)2 AccessDeniedException (org.springframework.security.access.AccessDeniedException)2 List (java.util.List)1 BiConsumer (java.util.function.BiConsumer)1 Log (org.apache.commons.logging.Log)1 LogFactory (org.apache.commons.logging.LogFactory)1