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;
}
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;
}
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;
}
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);
}
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);
}
Aggregations