use of org.hisp.dhis.dataelement.CategoryOptionGroupSet in project dhis2-core by dhis2.
the class JdbcEventAnalyticsTableManager method getDimensionColumns.
@Override
public List<AnalyticsTableColumn> getDimensionColumns(AnalyticsTable table) {
final String dbl = statementBuilder.getDoubleColumnType();
final String numericClause = " and value " + statementBuilder.getRegexpMatch() + " '" + NUMERIC_LENIENT_REGEXP + "'";
final String dateClause = " and value " + statementBuilder.getRegexpMatch() + " '" + DATE_REGEXP + "'";
//TODO dateClause regular expression
List<AnalyticsTableColumn> columns = new ArrayList<>();
if (table.getProgram().hasCategoryCombo()) {
List<DataElementCategory> categories = table.getProgram().getCategoryCombo().getCategories();
for (DataElementCategory category : categories) {
if (category.isDataDimension()) {
columns.add(new AnalyticsTableColumn(quote(category.getUid()), "character(11)", "acs." + quote(category.getUid()), category.getCreated()));
}
}
}
List<OrganisationUnitLevel> levels = organisationUnitService.getFilledOrganisationUnitLevels();
List<OrganisationUnitGroupSet> orgUnitGroupSets = idObjectManager.getDataDimensionsNoAcl(OrganisationUnitGroupSet.class);
List<CategoryOptionGroupSet> attributeCategoryOptionGroupSets = categoryService.getAttributeCategoryOptionGroupSetsNoAcl();
for (OrganisationUnitLevel level : levels) {
String column = quote(PREFIX_ORGUNITLEVEL + level.getLevel());
columns.add(new AnalyticsTableColumn(column, "character(11)", "ous." + column, level.getCreated()));
}
for (OrganisationUnitGroupSet groupSet : orgUnitGroupSets) {
columns.add(new AnalyticsTableColumn(quote(groupSet.getUid()), "character(11)", "ougs." + quote(groupSet.getUid()), groupSet.getCreated()));
}
for (CategoryOptionGroupSet groupSet : attributeCategoryOptionGroupSets) {
columns.add(new AnalyticsTableColumn(quote(groupSet.getUid()), "character(11)", "acs." + quote(groupSet.getUid()), groupSet.getCreated()));
}
for (PeriodType periodType : PeriodType.getAvailablePeriodTypes()) {
String column = quote(periodType.getName().toLowerCase());
columns.add(new AnalyticsTableColumn(column, "character varying(15)", "dps." + column));
}
for (DataElement dataElement : table.getProgram().getDataElements()) {
ValueType valueType = dataElement.getValueType();
String dataType = getColumnType(valueType);
String dataClause = dataElement.isNumericType() ? numericClause : dataElement.getValueType().isDate() ? dateClause : "";
String select = getSelectClause(valueType);
boolean skipIndex = NO_INDEX_VAL_TYPES.contains(dataElement.getValueType()) && !dataElement.hasOptionSet();
String sql = "(select " + select + " from trackedentitydatavalue where programstageinstanceid=psi.programstageinstanceid " + "and dataelementid=" + dataElement.getId() + dataClause + ") as " + quote(dataElement.getUid());
columns.add(new AnalyticsTableColumn(quote(dataElement.getUid()), dataType, sql, skipIndex));
}
for (DataElement dataElement : table.getProgram().getDataElementsWithLegendSet()) {
for (LegendSet legendSet : dataElement.getLegendSets()) {
String column = quote(dataElement.getUid() + PartitionUtils.SEP + legendSet.getUid());
String select = getSelectClause(dataElement.getValueType());
String sql = "(select l.uid from maplegend l " + "inner join trackedentitydatavalue dv on l.startvalue <= " + select + " " + "and l.endvalue > " + select + " " + "and l.maplegendsetid=" + legendSet.getId() + " " + "and dv.programstageinstanceid=psi.programstageinstanceid " + "and dv.dataelementid=" + dataElement.getId() + numericClause + ") as " + column;
columns.add(new AnalyticsTableColumn(column, "character(11)", sql));
}
}
for (TrackedEntityAttribute attribute : table.getProgram().getNonConfidentialTrackedEntityAttributes()) {
String dataType = getColumnType(attribute.getValueType());
String dataClause = attribute.isNumericType() ? numericClause : attribute.isDateType() ? dateClause : "";
String select = getSelectClause(attribute.getValueType());
boolean skipIndex = NO_INDEX_VAL_TYPES.contains(attribute.getValueType()) && !attribute.hasOptionSet();
String sql = "(select " + select + " from trackedentityattributevalue where trackedentityinstanceid=pi.trackedentityinstanceid " + "and trackedentityattributeid=" + attribute.getId() + dataClause + ") as " + quote(attribute.getUid());
columns.add(new AnalyticsTableColumn(quote(attribute.getUid()), dataType, sql, skipIndex));
}
for (TrackedEntityAttribute attribute : table.getProgram().getNonConfidentialTrackedEntityAttributesWithLegendSet()) {
for (LegendSet legendSet : attribute.getLegendSets()) {
String column = quote(attribute.getUid() + PartitionUtils.SEP + legendSet.getUid());
String select = getSelectClause(attribute.getValueType());
String sql = "(select l.uid from maplegend l " + "inner join trackedentityattributevalue av on l.startvalue <= " + select + " " + "and l.endvalue > " + select + " " + "and l.maplegendsetid=" + legendSet.getId() + " " + "and av.trackedentityinstanceid=pi.trackedentityinstanceid " + "and av.trackedentityattributeid=" + attribute.getId() + numericClause + ") as " + column;
columns.add(new AnalyticsTableColumn(column, "character(11)", sql));
}
}
AnalyticsTableColumn psi = new AnalyticsTableColumn(quote("psi"), "character(11) not null", "psi.uid");
AnalyticsTableColumn pi = new AnalyticsTableColumn(quote("pi"), "character(11) not null", "pi.uid");
AnalyticsTableColumn ps = new AnalyticsTableColumn(quote("ps"), "character(11) not null", "ps.uid");
AnalyticsTableColumn ao = new AnalyticsTableColumn(quote("ao"), "character(11) not null", "ao.uid");
AnalyticsTableColumn erd = new AnalyticsTableColumn(quote("enrollmentdate"), "timestamp", "pi.enrollmentdate");
AnalyticsTableColumn id = new AnalyticsTableColumn(quote("incidentdate"), "timestamp", "pi.incidentdate");
AnalyticsTableColumn ed = new AnalyticsTableColumn(quote("executiondate"), "timestamp", "psi.executiondate");
AnalyticsTableColumn dd = new AnalyticsTableColumn(quote("duedate"), "timestamp", "psi.duedate");
AnalyticsTableColumn cd = new AnalyticsTableColumn(quote("completeddate"), "timestamp", "psi.completeddate");
AnalyticsTableColumn pes = new AnalyticsTableColumn(quote("pistatus"), "character(25)", "pi.status");
AnalyticsTableColumn es = new AnalyticsTableColumn(quote("psistatus"), "character(25)", "psi.status");
AnalyticsTableColumn longitude = new AnalyticsTableColumn(quote("longitude"), dbl, "psi.longitude");
AnalyticsTableColumn latitude = new AnalyticsTableColumn(quote("latitude"), dbl, "psi.latitude");
AnalyticsTableColumn ou = new AnalyticsTableColumn(quote("ou"), "character(11) not null", "ou.uid");
AnalyticsTableColumn oun = new AnalyticsTableColumn(quote("ouname"), "character varying(230) not null", "ou.name");
AnalyticsTableColumn ouc = new AnalyticsTableColumn(quote("oucode"), "character varying(50)", "ou.code");
columns.addAll(Lists.newArrayList(psi, pi, ps, ao, erd, id, ed, dd, cd, pes, es, longitude, latitude, ou, oun, ouc));
if (databaseInfo.isSpatialSupport()) {
String alias = "(select ST_SetSRID(ST_MakePoint(psi.longitude, psi.latitude), 4326)) as geom";
columns.add(new AnalyticsTableColumn(quote("geom"), "geometry(Point, 4326)", alias, false, "gist"));
}
if (table.hasProgram() && table.getProgram().isRegistration()) {
columns.add(new AnalyticsTableColumn(quote("tei"), "character(11)", "tei.uid"));
}
return filterDimensionColumns(columns);
}
use of org.hisp.dhis.dataelement.CategoryOptionGroupSet in project dhis2-core by dhis2.
the class JdbcAnalyticsTableManager method getDimensionColumns.
@Override
public List<AnalyticsTableColumn> getDimensionColumns(AnalyticsTable table) {
List<AnalyticsTableColumn> columns = new ArrayList<>();
List<DataElementGroupSet> dataElementGroupSets = idObjectManager.getDataDimensionsNoAcl(DataElementGroupSet.class);
List<OrganisationUnitGroupSet> orgUnitGroupSets = idObjectManager.getDataDimensionsNoAcl(OrganisationUnitGroupSet.class);
List<CategoryOptionGroupSet> disaggregationCategoryOptionGroupSets = categoryService.getDisaggregationCategoryOptionGroupSetsNoAcl();
List<CategoryOptionGroupSet> attributeCategoryOptionGroupSets = categoryService.getAttributeCategoryOptionGroupSetsNoAcl();
List<DataElementCategory> disaggregationCategories = categoryService.getDisaggregationDataDimensionCategoriesNoAcl();
List<DataElementCategory> attributeCategories = categoryService.getAttributeDataDimensionCategoriesNoAcl();
List<OrganisationUnitLevel> levels = organisationUnitService.getFilledOrganisationUnitLevels();
for (DataElementGroupSet groupSet : dataElementGroupSets) {
columns.add(new AnalyticsTableColumn(quote(groupSet.getUid()), "character(11)", "degs." + quote(groupSet.getUid()), groupSet.getCreated()));
}
for (OrganisationUnitGroupSet groupSet : orgUnitGroupSets) {
columns.add(new AnalyticsTableColumn(quote(groupSet.getUid()), "character(11)", "ougs." + quote(groupSet.getUid()), groupSet.getCreated()));
}
for (CategoryOptionGroupSet groupSet : disaggregationCategoryOptionGroupSets) {
columns.add(new AnalyticsTableColumn(quote(groupSet.getUid()), "character(11)", "dcs." + quote(groupSet.getUid()), groupSet.getCreated()));
}
for (CategoryOptionGroupSet groupSet : attributeCategoryOptionGroupSets) {
columns.add(new AnalyticsTableColumn(quote(groupSet.getUid()), "character(11)", "acs." + quote(groupSet.getUid()), groupSet.getCreated()));
}
for (DataElementCategory category : disaggregationCategories) {
columns.add(new AnalyticsTableColumn(quote(category.getUid()), "character(11)", "dcs." + quote(category.getUid()), category.getCreated()));
}
for (DataElementCategory category : attributeCategories) {
columns.add(new AnalyticsTableColumn(quote(category.getUid()), "character(11)", "acs." + quote(category.getUid()), category.getCreated()));
}
for (OrganisationUnitLevel level : levels) {
String column = quote(PREFIX_ORGUNITLEVEL + level.getLevel());
columns.add(new AnalyticsTableColumn(column, "character(11)", "ous." + column, level.getCreated()));
}
List<PeriodType> periodTypes = PeriodType.getAvailablePeriodTypes();
for (PeriodType periodType : periodTypes) {
String column = quote(periodType.getName().toLowerCase());
columns.add(new AnalyticsTableColumn(column, "character varying(15)", "ps." + column));
}
AnalyticsTableColumn de = new AnalyticsTableColumn(quote("dx"), "character(11) not null", "de.uid");
AnalyticsTableColumn co = new AnalyticsTableColumn(quote("co"), "character(11) not null", "co.uid");
AnalyticsTableColumn ao = new AnalyticsTableColumn(quote("ao"), "character(11) not null", "ao.uid");
AnalyticsTableColumn startDate = new AnalyticsTableColumn(quote("pestartdate"), "timestamp", "pe.startdate");
AnalyticsTableColumn endDate = new AnalyticsTableColumn(quote("peenddate"), "timestamp", "pe.enddate");
AnalyticsTableColumn pe = new AnalyticsTableColumn(quote("pe"), "character varying(15) not null", "ps.iso");
AnalyticsTableColumn ou = new AnalyticsTableColumn(quote("ou"), "character(11) not null", "ou.uid");
AnalyticsTableColumn level = new AnalyticsTableColumn(quote("level"), "integer", "ous.level");
columns.addAll(Lists.newArrayList(de, co, ao, startDate, endDate, pe, ou, level));
if (isApprovalEnabled(table)) {
String col = "coalesce(des.datasetapprovallevel, aon.approvallevel, da.minlevel, " + APPROVAL_LEVEL_UNAPPROVED + ") as approvallevel ";
columns.add(new AnalyticsTableColumn(quote("approvallevel"), "integer", col));
} else {
String col = DataApprovalLevelService.APPROVAL_LEVEL_HIGHEST + " as approvallevel";
columns.add(new AnalyticsTableColumn(quote("approvallevel"), "integer", col));
}
return filterDimensionColumns(columns);
}
use of org.hisp.dhis.dataelement.CategoryOptionGroupSet in project dhis2-core by dhis2.
the class AnalyticalObjectEmbeddedDimensionUpgrader method executeInTransaction.
@Override
public void executeInTransaction() {
BiConsumer<BaseDimensionalEmbeddedObject, AnalyticalObject> dataElementGroupSetConsumer = (embeddedDimension, analyticalObject) -> {
DataElementGroupSetDimension dimension = new DataElementGroupSetDimension();
dimension.setDimension((DataElementGroupSet) embeddedDimension.getDimension());
dimension.setItems(DimensionalObjectUtils.asTypedList(embeddedDimension.getItems()));
analyticalObject.addDataElementGroupSetDimension(dimension);
};
BiConsumer<BaseDimensionalEmbeddedObject, AnalyticalObject> orgUnitGroupSetConsumer = (embeddedDimension, analyticalObject) -> {
OrganisationUnitGroupSetDimension dimension = new OrganisationUnitGroupSetDimension();
dimension.setDimension((OrganisationUnitGroupSet) embeddedDimension.getDimension());
dimension.setItems(DimensionalObjectUtils.asTypedList(embeddedDimension.getItems()));
analyticalObject.addOrganisationUnitGroupSetDimension(dimension);
};
BiConsumer<BaseDimensionalEmbeddedObject, AnalyticalObject> categoryOptionGroupSetConsumer = (embeddedDimension, analyticalObject) -> {
CategoryOptionGroupSetDimension dimension = new CategoryOptionGroupSetDimension();
dimension.setDimension((CategoryOptionGroupSet) embeddedDimension.getDimension());
dimension.setItems(DimensionalObjectUtils.asTypedList(embeddedDimension.getItems()));
analyticalObject.addCategoryOptionGroupSetDimension(dimension);
};
try {
upgradeGrupSetDimensions("reporttable", "orgunitgroupset", "orgunitgroup", ReportTable.class, OrganisationUnitGroupSet.class, OrganisationUnitGroup.class, orgUnitGroupSetConsumer);
upgradeGrupSetDimensions("reporttable", "dataelementgroupset", "dataelementgroup", ReportTable.class, DataElementGroupSet.class, DataElementGroup.class, dataElementGroupSetConsumer);
upgradeGrupSetDimensions("reporttable", "categoryoptiongroupset", "categoryoptiongroup", ReportTable.class, CategoryOptionGroupSet.class, CategoryOptionGroup.class, categoryOptionGroupSetConsumer);
upgradeGrupSetDimensions("chart", "orgunitgroupset", "orgunitgroup", Chart.class, OrganisationUnitGroupSet.class, OrganisationUnitGroup.class, orgUnitGroupSetConsumer);
upgradeGrupSetDimensions("chart", "dataelementgroupset", "dataelementgroup", Chart.class, DataElementGroupSet.class, DataElementGroup.class, dataElementGroupSetConsumer);
upgradeGrupSetDimensions("chart", "categoryoptiongroupset", "categoryoptiongroup", Chart.class, CategoryOptionGroupSet.class, CategoryOptionGroup.class, categoryOptionGroupSetConsumer);
upgradeGrupSetDimensions("eventreport", "orgunitgroupset", "orgunitgroup", EventReport.class, OrganisationUnitGroupSet.class, OrganisationUnitGroup.class, orgUnitGroupSetConsumer);
upgradeGrupSetDimensions("eventchart", "orgunitgroupset", "orgunitgroup", EventChart.class, OrganisationUnitGroupSet.class, OrganisationUnitGroup.class, orgUnitGroupSetConsumer);
} catch (Exception ex) {
log.debug("Error during group set dimensions upgrade of favorite, probably because upgrade was already done", ex);
return;
}
}
use of org.hisp.dhis.dataelement.CategoryOptionGroupSet in project dhis2-core by dhis2.
the class AddUserAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
if (!userService.canAddOrUpdateUser(ugSelected)) {
throw new AccessDeniedException("You cannot add this user");
}
User currentUser = currentUserService.getCurrentUser();
// ---------------------------------------------------------------------
// User credentials and user
// ---------------------------------------------------------------------
UserCredentials userCredentials = new UserCredentials();
User user = new User();
userCredentials.setUserInfo(user);
user.setUserCredentials(userCredentials);
userCredentials.setUsername(StringUtils.trimToNull(username));
userCredentials.setExternalAuth(externalAuth);
userCredentials.setOpenId(StringUtils.trimToNull(openId));
userCredentials.setLdapId(StringUtils.trimToNull(ldapId));
if (ACCOUNT_ACTION_INVITE.equals(accountAction)) {
userCredentials.setUsername(StringUtils.trimToNull(inviteUsername));
userCredentials.setInvitation(true);
user.setEmail(StringUtils.trimToNull(inviteEmail));
securityService.prepareUserForInvite(user);
} else {
user.setSurname(StringUtils.trimToNull(surname));
user.setFirstName(StringUtils.trimToNull(firstName));
user.setEmail(StringUtils.trimToNull(email));
user.setPhoneNumber(StringUtils.trimToNull(phoneNumber));
userService.encodeAndSetPassword(userCredentials, StringUtils.trimToNull(rawPassword));
}
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;
}
}
// ---------------------------------------------------------------------
// Add User
// ---------------------------------------------------------------------
userService.addUser(user);
userService.addUserCredentials(userCredentials);
// ---------------------------------------------------------------------
// User settings
// ---------------------------------------------------------------------
userSettingService.saveUserSetting(UserSettingKey.UI_LOCALE, LocaleUtils.getLocale(localeUi), user);
userSettingService.saveUserSetting(UserSettingKey.DB_LOCALE, LocaleUtils.getLocale(localeDb), user);
if (ACCOUNT_ACTION_INVITE.equals(accountAction)) {
RestoreOptions restoreOptions = inviteUsername == null || inviteUsername.isEmpty() ? RestoreOptions.INVITE_WITH_USERNAME_CHOICE : RestoreOptions.INVITE_WITH_DEFINED_USERNAME;
securityService.sendRestoreMessage(userCredentials, getRootPath(), restoreOptions);
}
for (String id : ugSelected) {
UserGroup userGroup = userGroupService.getUserGroup(id);
userGroup.addUser(user);
userGroupService.updateUserGroup(userGroup);
}
if (ouwtSelected != null && manager.search(OrganisationUnit.class, ouwtSelected) != null) {
selectionManager.setSelectedOrganisationUnits(Lists.newArrayList(manager.search(OrganisationUnit.class, ouwtSelected)));
} else {
selectionManager.setSelectedOrganisationUnits(currentUser.getOrganisationUnits());
}
return SUCCESS;
}
use of org.hisp.dhis.dataelement.CategoryOptionGroupSet in project dhis2-core by dhis2.
the class DefaultDataApprovalLevelService method subsetUserDataApprovalLevels.
/**
* Returns the subset of approval levels that the user is allowed to access.
*
* @param approvalLevels the approval levels to test.
* @return the subset of approval levels to which the user has access.
*/
private List<DataApprovalLevel> subsetUserDataApprovalLevels(List<DataApprovalLevel> approvalLevels) {
UserCredentials userCredentials = currentUserService.getCurrentUser().getUserCredentials();
int lowestNumberOrgUnitLevel = getCurrentUsersLowestNumberOrgUnitLevel();
boolean canSeeAllDimensions = CollectionUtils.isEmpty(categoryService.getCoDimensionConstraints(userCredentials)) && CollectionUtils.isEmpty(categoryService.getCogDimensionConstraints(userCredentials));
List<DataApprovalLevel> userDataApprovalLevels = new ArrayList<>();
boolean addLevel = false;
for (DataApprovalLevel approvalLevel : approvalLevels) {
if (!addLevel && approvalLevel.getOrgUnitLevel() >= lowestNumberOrgUnitLevel) {
CategoryOptionGroupSet cogs = approvalLevel.getCategoryOptionGroupSet();
addLevel = securityService.canRead(approvalLevel) && cogs == null ? canSeeAllDimensions : (securityService.canRead(cogs) && !CollectionUtils.isEmpty(categoryService.getCategoryOptionGroups(cogs)));
}
if (addLevel) {
userDataApprovalLevels.add(approvalLevel);
}
}
return userDataApprovalLevels;
}
Aggregations