use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.
the class DataIntegrityCategoriesControllerTest method updateDefaultCategoryOptionToUid.
private String updateDefaultCategoryOptionToUid(String uid) {
transactionTemplate.execute(status -> {
CategoryOption option = categoryService.getDefaultCategoryOption();
option.setUid(uid);
categoryOptionStore.save(option);
return null;
});
// OBS! we need to read this to force the TX to be applied
return categoryService.getDefaultCategoryOption().getUid();
}
use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.
the class LoadFormAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
dataSet = dataSetService.getDataSet(dataSetId);
if (dataSet == null) {
return INPUT;
}
FormType formType = dataSet.getFormType();
if (formType.isCustom() && dataSet.hasDataEntryForm()) {
dataEntryForm = dataSet.getDataEntryForm();
customDataEntryFormCode = dataEntryFormService.prepareDataEntryFormForEntry(dataEntryForm, dataSet, i18n);
return formType.toString();
}
// ---------------------------------------------------------------------
// Section / default form
// ---------------------------------------------------------------------
List<DataElement> dataElements = new ArrayList<>(dataSet.getDataElements());
if (dataElements.isEmpty()) {
return INPUT;
}
Collections.sort(dataElements);
orderedDataElements = ListMap.getListMap(dataElements, de -> de.getDataElementCategoryCombo(dataSet));
orderedCategoryCombos = getCategoryCombos(dataElements, dataSet);
User currentUser = currentUserService.getCurrentUser();
for (CategoryCombo categoryCombo : orderedCategoryCombos) {
List<CategoryOptionCombo> optionCombos = categoryCombo.getSortedOptionCombos();
orderedCategoryOptionCombos.put(categoryCombo.getId(), optionCombos);
addOptionAccess(currentUser, optionComboAccessMap, optionCombos);
// -----------------------------------------------------------------
// Perform ordering of categories and their options so that they
// could be displayed as in the paper form. Note that the total
// number of entry cells to be generated are the multiple of options
// from each category.
// -----------------------------------------------------------------
numberOfTotalColumns.put(categoryCombo.getId(), optionCombos.size());
orderedCategories.put(categoryCombo.getId(), categoryCombo.getCategories());
Map<Long, List<CategoryOption>> optionsMap = new HashMap<>();
for (Category category : categoryCombo.getCategories()) {
optionsMap.put(category.getId(), category.getCategoryOptions());
}
orderedOptionsMap.put(categoryCombo.getId(), optionsMap);
// -----------------------------------------------------------------
// Calculating the number of times each category should be repeated
// -----------------------------------------------------------------
Map<Long, Integer> catRepeat = new HashMap<>();
Map<Long, Collection<Integer>> colRepeat = new HashMap<>();
int catColSpan = optionCombos.size();
for (Category cat : categoryCombo.getCategories()) {
int categoryOptionSize = cat.getCategoryOptions().size();
if (categoryOptionSize > 0 && catColSpan >= categoryOptionSize) {
catColSpan = catColSpan / categoryOptionSize;
int total = optionCombos.size() / (catColSpan * categoryOptionSize);
Collection<Integer> cols = new ArrayList<>(total);
for (int i = 0; i < total; i++) {
cols.add(i);
}
colRepeat.put(cat.getId(), cols);
catRepeat.put(cat.getId(), catColSpan);
}
}
catColRepeat.put(categoryCombo.getId(), colRepeat);
}
// ---------------------------------------------------------------------
// Get data entry form
// ---------------------------------------------------------------------
DataSet dsOriginal = dataSet;
if (dataSet.getFormType().isDefault()) {
DataSet dataSetCopy = new DataSet();
dataSetCopy.setUid(dataSet.getUid());
dataSetCopy.setCode(dataSet.getCode());
dataSetCopy.setName(dataSet.getName());
dataSetCopy.setShortName(dataSet.getShortName());
dataSetCopy.setRenderAsTabs(dataSet.isRenderAsTabs());
dataSetCopy.setRenderHorizontally(dataSet.isRenderHorizontally());
dataSetCopy.setDataElementDecoration(dataSet.isDataElementDecoration());
dataSetCopy.setCompulsoryDataElementOperands(dataSet.getCompulsoryDataElementOperands());
for (int i = 0; i < orderedCategoryCombos.size(); i++) {
CategoryCombo categoryCombo = orderedCategoryCombos.get(i);
String name = !categoryCombo.isDefault() ? categoryCombo.getName() : dataSetCopy.getName();
Section section = new Section();
section.setUid(CodeGenerator.generateUid());
section.setId(i);
section.setName(name);
section.setSortOrder(i);
section.setDataSet(dataSetCopy);
dataSetCopy.getSections().add(section);
section.getDataElements().addAll(orderedDataElements.get(categoryCombo));
if (i == 0) {
section.setIndicators(new ArrayList<>(dataSet.getIndicators()));
}
}
dataSet = dataSetCopy;
formType = FormType.SECTION;
}
if (CodeGenerator.isValidUid(multiOrganisationUnit)) {
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(multiOrganisationUnit);
List<OrganisationUnit> organisationUnitChildren = new ArrayList<>();
for (OrganisationUnit child : organisationUnit.getChildren()) {
if (child.getDataSets().contains(dsOriginal)) {
organisationUnitChildren.add(child);
}
}
Collections.sort(organisationUnitChildren);
organisationUnits.addAll(organisationUnitChildren);
getSectionForm(dataSet);
formType = FormType.SECTION_MULTIORG;
}
getSectionForm(dataSet);
return formType.toString();
}
use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.
the class HibernateIdentifiableObjectStoreTest method testDataRead.
@Test
void testDataRead() {
User user1 = createUser("user1", "DATA_READ");
User user2 = createUser("user2", "DATA_READ");
User user3 = createUser("user3", "DATA_READ");
User user4 = createUser("user4", "DATA_READ");
UserGroup userGroup1 = createUserGroup('A', Sets.newHashSet(user1));
manager.save(userGroup1);
UserGroup userGroup2 = createUserGroup('B', Sets.newHashSet(user1, user4));
manager.save(userGroup2);
user1.getGroups().add(userGroup1);
user1.getGroups().add(userGroup2);
user4.getGroups().add(userGroup2);
Map<String, UserAccess> userSharing = new HashMap<>();
userSharing.put(user1.getUid(), new UserAccess(user1, AccessStringHelper.DEFAULT));
userSharing.put(user2.getUid(), new UserAccess(user2, AccessStringHelper.DATA_READ));
userSharing.put(user3.getUid(), new UserAccess(user3, AccessStringHelper.DEFAULT));
userSharing.put(user4.getUid(), new UserAccess(user4, AccessStringHelper.DEFAULT));
Map<String, UserGroupAccess> userGroupSharing = new HashMap<>();
userGroupSharing.put(userGroup1.getUid(), new UserGroupAccess(userGroup1, AccessStringHelper.DATA_READ_WRITE));
userGroupSharing.put(userGroup2.getUid(), new UserGroupAccess(userGroup2, AccessStringHelper.DEFAULT));
Sharing sharing = Sharing.builder().external(false).publicAccess(AccessStringHelper.DEFAULT).owner("testOwner").userGroups(userGroupSharing).users(userSharing).build();
DataElement dataElement = createDataElement('A');
dataElement.setValueType(ValueType.TEXT);
CategoryOptionCombo defaultCategoryOptionCombo = createCategoryOptionCombo('D');
OrganisationUnit organisationUnitA = createOrganisationUnit('A');
Period period = createPeriod(new Date(), new Date());
period.setPeriodType(PeriodType.getPeriodTypeByName(MonthlyPeriodType.NAME));
manager.save(dataElement);
manager.save(organisationUnitA);
manager.save(period);
manager.save(defaultCategoryOptionCombo);
CategoryOption categoryOption = createCategoryOption('A');
categoryOption.setSharing(sharing);
categoryOption.setCategoryOptionCombos(Sets.newHashSet(defaultCategoryOptionCombo));
manager.save(categoryOption, false);
defaultCategoryOptionCombo.getCategoryOptions().add(categoryOption);
DataValue dataValue = createDataValue(dataElement, period, organisationUnitA, "test", defaultCategoryOptionCombo);
dataValueStore.addDataValue(dataValue);
// User1 can't access but it belongs to UserGroup1 which has access
assertEquals(0, accessManager.canRead(user1, dataValue).size());
// User2 has access to DEA
assertEquals(0, accessManager.canRead(user2, dataValue).size());
// User3 doesn't have access and also doesn't belong to any groups
assertEquals(1, accessManager.canRead(user3, dataValue).size());
// User4 doesn't have access and it belong to UserGroup2 which also
// doesn't have access
assertEquals(1, accessManager.canRead(user4, dataValue).size());
}
use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.
the class DataApprovalAuditServiceTest method setUpTest.
@Override
public void setUpTest() throws Exception {
// ---------------------------------------------------------------------
// Add supporting data
// ---------------------------------------------------------------------
PeriodType periodType = PeriodType.getPeriodTypeByName("Monthly");
periodA = createPeriod(new MonthlyPeriodType(), getDate(2017, 1, 1), getDate(2017, 1, 31));
periodB = createPeriod(new MonthlyPeriodType(), getDate(2018, 1, 1), getDate(2018, 1, 31));
periodService.addPeriod(periodA);
periodService.addPeriod(periodB);
sourceA = createOrganisationUnit('A');
sourceB = createOrganisationUnit('B', sourceA);
organisationUnitService.addOrganisationUnit(sourceA);
organisationUnitService.addOrganisationUnit(sourceB);
superUserService = getMockCurrentUserService("SuperUser", true, sourceA, UserAuthorityGroup.AUTHORITY_ALL);
userAService = getMockCurrentUserService("UserA", false, sourceA);
userBService = getMockCurrentUserService("UserB", false, sourceB);
userCService = getMockCurrentUserService("UserC", false, sourceB);
userDService = getMockCurrentUserService("UserD", false, sourceB);
userZ = createUser('Z');
userService.addUser(userZ);
UserGroup userGroupC = getUserGroup("UserGroupA", Sets.newHashSet(userCService.getCurrentUser()));
UserGroup userGroupD = getUserGroup("UserGroupB", Sets.newHashSet(userDService.getCurrentUser()));
userCService.getCurrentUser().getGroups().add(userGroupC);
userDService.getCurrentUser().getGroups().add(userGroupD);
optionA = new CategoryOption("CategoryOptionA");
optionB = new CategoryOption("CategoryOptionB");
categoryService.addCategoryOption(optionA);
categoryService.addCategoryOption(optionB);
categoryA = createCategory('A', optionA, optionB);
categoryService.addCategory(categoryA);
categoryComboA = createCategoryCombo('A', categoryA);
categoryService.addCategoryCombo(categoryComboA);
optionComboA = createCategoryOptionCombo(categoryComboA, optionA);
optionComboB = createCategoryOptionCombo(categoryComboA, optionB);
optionComboC = createCategoryOptionCombo(categoryComboA, optionA, optionB);
categoryService.addCategoryOptionCombo(optionComboA);
categoryService.addCategoryOptionCombo(optionComboB);
categoryService.addCategoryOptionCombo(optionComboC);
optionGroupA = createCategoryOptionGroup('A', optionA);
optionGroupB = createCategoryOptionGroup('B', optionB);
categoryService.saveCategoryOptionGroup(optionGroupA);
categoryService.saveCategoryOptionGroup(optionGroupB);
optionGroupSetB = new CategoryOptionGroupSet("OptionGroupSetB");
categoryService.saveCategoryOptionGroupSet(optionGroupSetB);
optionGroupSetB.addCategoryOptionGroup(optionGroupA);
optionGroupSetB.addCategoryOptionGroup(optionGroupB);
optionGroupA.getGroupSets().add(optionGroupSetB);
optionGroupB.getGroupSets().add(optionGroupSetB);
setPrivateAccess(optionA, userGroupC);
setPrivateAccess(optionB);
setPrivateAccess(optionGroupA);
setPrivateAccess(optionGroupB, userGroupD);
categoryService.updateCategoryOptionGroupSet(optionGroupSetB);
categoryService.updateCategoryOptionGroup(optionGroupA);
categoryService.updateCategoryOptionGroup(optionGroupB);
userCService.getCurrentUser().getCatDimensionConstraints().add(categoryA);
userDService.getCurrentUser().getCogsDimensionConstraints().add(optionGroupSetB);
dateA = getDate(2017, 1, 1);
dateB = getDate(2018, 1, 1);
level1 = new DataApprovalLevel("01", 1, null);
level2 = new DataApprovalLevel("02", 2, null);
level3 = new DataApprovalLevel("03", 2, optionGroupSetB);
dataApprovalLevelService.addDataApprovalLevel(level1);
dataApprovalLevelService.addDataApprovalLevel(level2);
dataApprovalLevelService.addDataApprovalLevel(level3);
workflowA = new DataApprovalWorkflow("workflowA", periodType, newHashSet(level1));
workflowB = new DataApprovalWorkflow("workflowB", periodType, newHashSet(level1, level2, level3));
dataApprovalService.addWorkflow(workflowA);
dataApprovalService.addWorkflow(workflowB);
DataApproval approvalAA1 = new DataApproval(level1, workflowA, periodA, sourceA, optionComboA, false, dateA, userZ);
DataApproval approvalAB1 = new DataApproval(level1, workflowA, periodA, sourceA, optionComboB, false, dateA, userZ);
DataApproval approvalAC1 = new DataApproval(level1, workflowA, periodA, sourceA, optionComboC, false, dateA, userZ);
DataApproval approvalBA2 = new DataApproval(level2, workflowB, periodB, sourceB, optionComboA, false, dateB, userZ);
DataApproval approvalBB2 = new DataApproval(level2, workflowB, periodB, sourceB, optionComboB, false, dateB, userZ);
DataApproval approvalBC2 = new DataApproval(level2, workflowB, periodB, sourceB, optionComboC, false, dateB, userZ);
DataApproval approvalBA3 = new DataApproval(level3, workflowB, periodB, sourceB, optionComboA, false, dateB, userZ);
DataApproval approvalBB3 = new DataApproval(level3, workflowB, periodB, sourceB, optionComboB, false, dateB, userZ);
DataApproval approvalBC3 = new DataApproval(level3, workflowB, periodB, sourceB, optionComboC, false, dateB, userZ);
auditAA1 = new DataApprovalAudit(approvalAA1, APPROVE);
auditAB1 = new DataApprovalAudit(approvalAB1, UNAPPROVE);
auditAC1 = new DataApprovalAudit(approvalAC1, ACCEPT);
auditBA2 = new DataApprovalAudit(approvalBA2, UNACCEPT);
auditBB2 = new DataApprovalAudit(approvalBB2, APPROVE);
auditBC2 = new DataApprovalAudit(approvalBC2, UNAPPROVE);
auditBA3 = new DataApprovalAudit(approvalBA3, ACCEPT);
auditBB3 = new DataApprovalAudit(approvalBB3, UNACCEPT);
auditBC3 = new DataApprovalAudit(approvalBC3, APPROVE);
dataApprovalAuditStore.save(auditAA1);
dataApprovalAuditStore.save(auditAB1);
dataApprovalAuditStore.save(auditAC1);
dataApprovalAuditStore.save(auditBA2);
dataApprovalAuditStore.save(auditBB2);
dataApprovalAuditStore.save(auditBC2);
dataApprovalAuditStore.save(auditBA3);
dataApprovalAuditStore.save(auditBB3);
dataApprovalAuditStore.save(auditBC3);
}
use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.
the class DataApprovalServiceTest method setUpCategories.
// -------------------------------------------------------------------------
// Categories supportive methods
// -------------------------------------------------------------------------
private void setUpCategories() {
optionA = new CategoryOption("CategoryOptionA");
optionB = new CategoryOption("CategoryOptionB");
optionC = new CategoryOption("CategoryOptionC");
optionD = new CategoryOption("CategoryOptionD");
optionE = new CategoryOption("CategoryOptionE");
optionF = new CategoryOption("CategoryOptionF");
optionG = new CategoryOption("CategoryOptionG");
optionH = new CategoryOption("CategoryOptionH");
categoryService.addCategoryOption(optionA);
categoryService.addCategoryOption(optionB);
categoryService.addCategoryOption(optionC);
categoryService.addCategoryOption(optionD);
categoryService.addCategoryOption(optionE);
categoryService.addCategoryOption(optionF);
categoryService.addCategoryOption(optionG);
categoryService.addCategoryOption(optionH);
optionA.setPublicAccess(CATEGORY_OPTION_DEFAULT);
optionB.setPublicAccess(CATEGORY_OPTION_DEFAULT);
optionC.setPublicAccess(CATEGORY_OPTION_DEFAULT);
optionD.setPublicAccess(CATEGORY_OPTION_DEFAULT);
optionE.setPublicAccess(CATEGORY_OPTION_DEFAULT);
optionF.setPublicAccess(CATEGORY_OPTION_DEFAULT);
optionG.setPublicAccess(CATEGORY_OPTION_DEFAULT);
optionH.setPublicAccess(CATEGORY_OPTION_DEFAULT);
categoryService.updateCategoryOption(optionA);
categoryService.updateCategoryOption(optionB);
categoryService.updateCategoryOption(optionC);
categoryService.updateCategoryOption(optionD);
categoryService.updateCategoryOption(optionE);
categoryService.updateCategoryOption(optionF);
categoryService.updateCategoryOption(optionG);
categoryService.updateCategoryOption(optionH);
categoryA = createCategory('A', optionA, optionB, optionC, optionD);
categoryB = createCategory('B', optionE, optionF, optionG, optionH);
categoryService.addCategory(categoryA);
categoryService.addCategory(categoryB);
categoryComboA = createCategoryCombo('A', categoryA, categoryB);
categoryService.addCategoryCombo(categoryComboA);
optionComboAE = createCategoryOptionCombo(categoryComboA, optionA, optionE);
optionComboAF = createCategoryOptionCombo(categoryComboA, optionA, optionF);
optionComboAG = createCategoryOptionCombo(categoryComboA, optionA, optionG);
optionComboAH = createCategoryOptionCombo(categoryComboA, optionA, optionH);
optionComboBE = createCategoryOptionCombo(categoryComboA, optionB, optionE);
optionComboBF = createCategoryOptionCombo(categoryComboA, optionB, optionF);
optionComboBG = createCategoryOptionCombo(categoryComboA, optionB, optionG);
optionComboBH = createCategoryOptionCombo(categoryComboA, optionB, optionH);
optionComboCE = createCategoryOptionCombo(categoryComboA, optionC, optionE);
optionComboCF = createCategoryOptionCombo(categoryComboA, optionC, optionF);
optionComboCG = createCategoryOptionCombo(categoryComboA, optionC, optionG);
optionComboCH = createCategoryOptionCombo(categoryComboA, optionC, optionH);
optionComboDE = createCategoryOptionCombo(categoryComboA, optionD, optionE);
optionComboDF = createCategoryOptionCombo(categoryComboA, optionD, optionF);
optionComboDG = createCategoryOptionCombo(categoryComboA, optionD, optionG);
optionComboDH = createCategoryOptionCombo(categoryComboA, optionD, optionH);
optionComboAE.setUid("optionComAE");
optionComboAF.setUid("optionComAF");
optionComboAG.setUid("optionComAG");
optionComboAH.setUid("optionComAH");
optionComboBE.setUid("optionComBE");
optionComboBF.setUid("optionComBF");
optionComboBG.setUid("optionComBG");
optionComboBH.setUid("optionComBH");
optionComboCE.setUid("optionComCE");
optionComboCF.setUid("optionComCF");
optionComboCG.setUid("optionComCG");
optionComboCH.setUid("optionComCH");
optionComboDE.setUid("optionComDE");
optionComboDF.setUid("optionComDF");
optionComboDG.setUid("optionComDG");
optionComboDH.setUid("optionComDH");
categoryService.addCategoryOptionCombo(optionComboAE);
categoryService.addCategoryOptionCombo(optionComboAF);
categoryService.addCategoryOptionCombo(optionComboAG);
categoryService.addCategoryOptionCombo(optionComboAH);
categoryService.addCategoryOptionCombo(optionComboBE);
categoryService.addCategoryOptionCombo(optionComboBF);
categoryService.addCategoryOptionCombo(optionComboBG);
categoryService.addCategoryOptionCombo(optionComboBH);
categoryService.addCategoryOptionCombo(optionComboCE);
categoryService.addCategoryOptionCombo(optionComboCF);
categoryService.addCategoryOptionCombo(optionComboCG);
categoryService.addCategoryOptionCombo(optionComboCH);
categoryService.addCategoryOptionCombo(optionComboDE);
categoryService.addCategoryOptionCombo(optionComboDF);
categoryService.addCategoryOptionCombo(optionComboDG);
categoryService.addCategoryOptionCombo(optionComboDH);
categoryComboA.getOptionCombos().add(optionComboAE);
categoryComboA.getOptionCombos().add(optionComboAF);
categoryComboA.getOptionCombos().add(optionComboAG);
categoryComboA.getOptionCombos().add(optionComboAH);
categoryComboA.getOptionCombos().add(optionComboBE);
categoryComboA.getOptionCombos().add(optionComboBF);
categoryComboA.getOptionCombos().add(optionComboBG);
categoryComboA.getOptionCombos().add(optionComboBH);
categoryComboA.getOptionCombos().add(optionComboCF);
categoryComboA.getOptionCombos().add(optionComboCG);
categoryComboA.getOptionCombos().add(optionComboCH);
categoryComboA.getOptionCombos().add(optionComboDE);
categoryComboA.getOptionCombos().add(optionComboDF);
categoryComboA.getOptionCombos().add(optionComboDG);
categoryComboA.getOptionCombos().add(optionComboDH);
categoryService.updateCategoryCombo(categoryComboA);
groupAB = createCategoryOptionGroup('A', optionA, optionB);
groupCD = createCategoryOptionGroup('C', optionC, optionD);
groupEF = createCategoryOptionGroup('E', optionE, optionF);
groupGH = createCategoryOptionGroup('G', optionG, optionH);
categoryService.saveCategoryOptionGroup(groupAB);
categoryService.saveCategoryOptionGroup(groupCD);
categoryService.saveCategoryOptionGroup(groupEF);
categoryService.saveCategoryOptionGroup(groupGH);
groupSetABCD = new CategoryOptionGroupSet("GroupSetABCD");
groupSetEFGH = new CategoryOptionGroupSet("GroupSetEFGH");
categoryService.saveCategoryOptionGroupSet(groupSetABCD);
categoryService.saveCategoryOptionGroupSet(groupSetEFGH);
groupSetABCD.addCategoryOptionGroup(groupAB);
groupSetABCD.addCategoryOptionGroup(groupCD);
groupSetEFGH.addCategoryOptionGroup(groupAB);
groupSetEFGH.addCategoryOptionGroup(groupEF);
groupAB.getGroupSets().add(groupSetABCD);
groupCD.getGroupSets().add(groupSetABCD);
groupEF.getGroupSets().add(groupSetEFGH);
groupGH.getGroupSets().add(groupSetEFGH);
level2ABCD = new DataApprovalLevel("level2ABCD", 2, groupSetABCD);
level2EFGH = new DataApprovalLevel("level2EFGH", 2, groupSetEFGH);
dataApprovalLevelService.addDataApprovalLevel(level2EFGH);
dataApprovalLevelService.addDataApprovalLevel(level2ABCD);
workflow12A_H = new DataApprovalWorkflow("workflow12A_H", periodType, newHashSet(level1, level2, level2ABCD, level2EFGH));
workflow12A_H.setUid("workflo12AH");
dataApprovalService.addWorkflow(workflow12A_H);
dataSetH = createDataSet('H', periodType, categoryComboA);
dataSetH.assignWorkflow(workflow12A_H);
dataSetH.addOrganisationUnit(organisationUnitA);
dataSetH.addOrganisationUnit(organisationUnitB);
dataSetService.addDataSet(dataSetH);
workflow12A_H.getDataSets().add(dataSetH);
dataApprovalService.updateWorkflow(workflow12A_H);
}
Aggregations