use of org.hisp.dhis.dataelement.DataElementCategoryOption in project dhis2-core by dhis2.
the class AnalyticalObjectObjectBundleHook method handleCategoryDimensions.
private void handleCategoryDimensions(Session session, Schema schema, BaseAnalyticalObject analyticalObject, ObjectBundle bundle) {
if (!schema.havePersistedProperty("categoryDimensions"))
return;
for (CategoryDimension categoryDimension : analyticalObject.getCategoryDimensions()) {
if (categoryDimension == null) {
continue;
}
categoryDimension.setDimension(bundle.getPreheat().get(bundle.getPreheatIdentifier(), categoryDimension.getDimension()));
List<DataElementCategoryOption> categoryOptions = new ArrayList<>(categoryDimension.getItems());
categoryDimension.getItems().clear();
categoryOptions.forEach(co -> {
DataElementCategoryOption categoryOption = bundle.getPreheat().get(bundle.getPreheatIdentifier(), co);
if (categoryOption != null)
categoryDimension.getItems().add(categoryOption);
});
preheatService.connectReferences(categoryDimension, bundle.getPreheat(), bundle.getPreheatIdentifier());
session.save(categoryDimension);
}
}
use of org.hisp.dhis.dataelement.DataElementCategoryOption in project dhis2-core by dhis2.
the class AclServiceTest method testCategoryOptionSharingPrivateRW.
@Test
public void testCategoryOptionSharingPrivateRW() {
User user1 = createUser("user1", "F_CATEGORY_OPTION_PRIVATE_ADD");
User user2 = createUser("user2", "F_CATEGORY_OPTION_PRIVATE_ADD");
DataElementCategoryOption categoryOption = createCategoryOption('A');
categoryOption.setUser(user1);
manager.save(categoryOption);
assertFalse(aclService.canUpdate(user2, categoryOption));
assertEquals(AccessStringHelper.DEFAULT, categoryOption.getPublicAccess());
UserGroup userGroup = createUserGroup('A', new HashSet<>());
userGroup.getMembers().add(user1);
userGroup.getMembers().add(user2);
manager.save(userGroup);
categoryOption.getUserGroupAccesses().add(new UserGroupAccess(userGroup, "rw------"));
manager.update(categoryOption);
assertTrue(aclService.canUpdate(user2, categoryOption));
}
use of org.hisp.dhis.dataelement.DataElementCategoryOption in project dhis2-core by dhis2.
the class DataElementCategoryControllerDocumentation method testCreate.
@Test
@Override
public void testCreate() throws Exception {
MockHttpSession session = getSession("F_CATEGORY_PUBLIC_ADD");
DataElementCategoryOption categoryOptionA = createCategoryOption('A');
DataElementCategoryOption categoryOptionB = createCategoryOption('B');
DataElementCategoryOption categoryOptionC = createCategoryOption('C');
DataElementCategory cat = createDataElementCategory('A', categoryOptionA, categoryOptionB, categoryOptionC);
Schema schema = schemaService.getSchema(DataElementCategory.class);
Set<FieldDescriptor> fieldDescriptors = TestUtils.getFieldDescriptors(schema);
mvc.perform(post("/" + ENDPOINT).session(session).contentType(TestUtils.APPLICATION_JSON_UTF8).content(TestUtils.convertObjectToJsonBytes(cat))).andExpect(status().is(createdStatus)).andDo(documentPrettyPrint("categories/create", requestFields(fieldDescriptors.toArray(new FieldDescriptor[fieldDescriptors.size()]))));
cat = manager.getByName(DataElementCategory.class, "DataElementCategoryA");
assertNotNull(cat);
}
use of org.hisp.dhis.dataelement.DataElementCategoryOption in project dhis2-core by dhis2.
the class DataApprovalAuditServiceTest method setUpTest.
// -------------------------------------------------------------------------
// Set up/tear down
// -------------------------------------------------------------------------
@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()));
optionA = new DataElementCategoryOption("CategoryOptionA");
optionB = new DataElementCategoryOption("CategoryOptionB");
categoryService.addDataElementCategoryOption(optionA);
categoryService.addDataElementCategoryOption(optionB);
categoryA = createDataElementCategory('A', optionA, optionB);
categoryService.addDataElementCategory(categoryA);
categoryComboA = createCategoryCombo('A', categoryA);
categoryService.addDataElementCategoryCombo(categoryComboA);
optionComboA = createCategoryOptionCombo('A', categoryComboA, optionA);
optionComboB = createCategoryOptionCombo('B', categoryComboA, optionB);
optionComboC = createCategoryOptionCombo('C', categoryComboA, optionA, optionB);
categoryService.addDataElementCategoryOptionCombo(optionComboA);
categoryService.addDataElementCategoryOptionCombo(optionComboB);
categoryService.addDataElementCategoryOptionCombo(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().getUserCredentials().getCatDimensionConstraints().add(categoryA);
userDService.getCurrentUser().getUserCredentials().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.dataelement.DataElementCategoryOption in project dhis2-core by dhis2.
the class DataApprovalServiceTest method setUpCategories.
// -------------------------------------------------------------------------
// Categories supportive methods
// -------------------------------------------------------------------------
private void setUpCategories() {
optionA = new DataElementCategoryOption("CategoryOptionA");
optionB = new DataElementCategoryOption("CategoryOptionB");
optionC = new DataElementCategoryOption("CategoryOptionC");
optionD = new DataElementCategoryOption("CategoryOptionD");
optionE = new DataElementCategoryOption("CategoryOptionE");
optionF = new DataElementCategoryOption("CategoryOptionF");
optionG = new DataElementCategoryOption("CategoryOptionG");
optionH = new DataElementCategoryOption("CategoryOptionH");
categoryService.addDataElementCategoryOption(optionA);
categoryService.addDataElementCategoryOption(optionB);
categoryService.addDataElementCategoryOption(optionC);
categoryService.addDataElementCategoryOption(optionD);
categoryService.addDataElementCategoryOption(optionE);
categoryService.addDataElementCategoryOption(optionF);
categoryService.addDataElementCategoryOption(optionG);
categoryService.addDataElementCategoryOption(optionH);
categoryA = createDataElementCategory('A', optionA, optionB, optionC, optionD);
categoryB = createDataElementCategory('B', optionE, optionF, optionG, optionH);
categoryService.addDataElementCategory(categoryA);
categoryService.addDataElementCategory(categoryB);
categoryComboA = createCategoryCombo('A', categoryA, categoryB);
categoryService.addDataElementCategoryCombo(categoryComboA);
optionComboAE = createCategoryOptionCombo('A', categoryComboA, optionA, optionE);
optionComboAF = createCategoryOptionCombo('B', categoryComboA, optionA, optionF);
optionComboAG = createCategoryOptionCombo('C', categoryComboA, optionA, optionG);
optionComboAH = createCategoryOptionCombo('D', categoryComboA, optionA, optionH);
optionComboBE = createCategoryOptionCombo('E', categoryComboA, optionB, optionE);
optionComboBF = createCategoryOptionCombo('F', categoryComboA, optionB, optionF);
optionComboBG = createCategoryOptionCombo('G', categoryComboA, optionB, optionG);
optionComboBH = createCategoryOptionCombo('H', categoryComboA, optionB, optionH);
optionComboCE = createCategoryOptionCombo('I', categoryComboA, optionC, optionE);
optionComboCF = createCategoryOptionCombo('J', categoryComboA, optionC, optionF);
optionComboCG = createCategoryOptionCombo('K', categoryComboA, optionC, optionG);
optionComboCH = createCategoryOptionCombo('L', categoryComboA, optionC, optionH);
optionComboDE = createCategoryOptionCombo('M', categoryComboA, optionD, optionE);
optionComboDF = createCategoryOptionCombo('N', categoryComboA, optionD, optionF);
optionComboDG = createCategoryOptionCombo('O', categoryComboA, optionD, optionG);
optionComboDH = createCategoryOptionCombo('P', categoryComboA, optionD, optionH);
categoryService.addDataElementCategoryOptionCombo(optionComboAE);
categoryService.addDataElementCategoryOptionCombo(optionComboAF);
categoryService.addDataElementCategoryOptionCombo(optionComboAG);
categoryService.addDataElementCategoryOptionCombo(optionComboAH);
categoryService.addDataElementCategoryOptionCombo(optionComboBE);
categoryService.addDataElementCategoryOptionCombo(optionComboBF);
categoryService.addDataElementCategoryOptionCombo(optionComboBG);
categoryService.addDataElementCategoryOptionCombo(optionComboBH);
categoryService.addDataElementCategoryOptionCombo(optionComboCE);
categoryService.addDataElementCategoryOptionCombo(optionComboCF);
categoryService.addDataElementCategoryOptionCombo(optionComboCG);
categoryService.addDataElementCategoryOptionCombo(optionComboCH);
categoryService.addDataElementCategoryOptionCombo(optionComboDE);
categoryService.addDataElementCategoryOptionCombo(optionComboDF);
categoryService.addDataElementCategoryOptionCombo(optionComboDG);
categoryService.addDataElementCategoryOptionCombo(optionComboDH);
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));
dataApprovalService.addWorkflow(workflow12A_H);
}
Aggregations