use of org.hisp.dhis.dataelement.DataElementCategoryOption in project dhis2-core by dhis2.
the class PredictorServiceTest method setUpTest.
// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
orgUnitLevel1 = new OrganisationUnitLevel(1, "Level1");
organisationUnitService.addOrganisationUnitLevel(orgUnitLevel1);
dataElementA = createDataElement('A');
dataElementB = createDataElement('B');
dataElementC = createDataElement('C');
dataElementD = createDataElement('D');
dataElementX = createDataElement('X', ValueType.NUMBER, AggregationType.NONE);
dataElementService.addDataElement(dataElementA);
dataElementService.addDataElement(dataElementB);
dataElementService.addDataElement(dataElementC);
dataElementService.addDataElement(dataElementD);
dataElementService.addDataElement(dataElementX);
dataElements = new HashSet<>();
dataElements.add(dataElementA);
dataElements.add(dataElementB);
dataElements.add(dataElementC);
dataElements.add(dataElementD);
sourceA = createOrganisationUnit('A');
sourceB = createOrganisationUnit('B');
sourceC = createOrganisationUnit('C', sourceB);
sourceD = createOrganisationUnit('D', sourceB);
sourceE = createOrganisationUnit('E', sourceD);
sourceF = createOrganisationUnit('F', sourceD);
sourceG = createOrganisationUnit('G');
organisationUnitService.addOrganisationUnit(sourceA);
organisationUnitService.addOrganisationUnit(sourceB);
organisationUnitService.addOrganisationUnit(sourceC);
organisationUnitService.addOrganisationUnit(sourceD);
organisationUnitService.addOrganisationUnit(sourceE);
organisationUnitService.addOrganisationUnit(sourceF);
organisationUnitService.addOrganisationUnit(sourceG);
periodTypeMonthly = PeriodType.getPeriodTypeByName("Monthly");
dataSetMonthly = createDataSet('M', periodTypeMonthly);
dataSetMonthly.addDataSetElement(dataElementA);
dataSetMonthly.addDataSetElement(dataElementB);
dataSetMonthly.addDataSetElement(dataElementC);
dataSetMonthly.addDataSetElement(dataElementD);
dataSetMonthly.addDataSetElement(dataElementX);
dataSetMonthly.addOrganisationUnit(sourceA);
dataSetMonthly.addOrganisationUnit(sourceB);
dataSetMonthly.addOrganisationUnit(sourceC);
dataSetMonthly.addOrganisationUnit(sourceD);
dataSetMonthly.addOrganisationUnit(sourceE);
dataSetMonthly.addOrganisationUnit(sourceG);
dataSetService.addDataSet(dataSetMonthly);
DataElementCategoryOptionCombo categoryOptionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
defaultCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
altCategoryOption = new DataElementCategoryOption("AltCategoryOption");
categoryService.addDataElementCategoryOption(altCategoryOption);
altDataElementCategory = createDataElementCategory('A', altCategoryOption);
categoryService.addDataElementCategory(altDataElementCategory);
altDataElementCategoryCombo = createCategoryCombo('Y', altDataElementCategory);
categoryService.addDataElementCategoryCombo(altDataElementCategoryCombo);
altCombo = createCategoryOptionCombo('Z', altDataElementCategoryCombo, altCategoryOption);
optionCombos = new HashSet<>();
optionCombos.add(categoryOptionCombo);
optionCombos.add(altCombo);
categoryService.addDataElementCategoryOptionCombo(altCombo);
expressionA = new Expression("AVG(#{" + dataElementA.getUid() + "})+1.5*STDDEV(#{" + dataElementA.getUid() + "})", "descriptionA");
expressionB = new Expression("AVG(#{" + dataElementB.getUid() + "." + defaultCombo.getUid() + "})", "descriptionB");
expressionC = new Expression("1234", "descriptionC");
expressionD = new Expression(SYMBOL_DAYS, "descriptionD");
expressionService.addExpression(expressionA);
expressionService.addExpression(expressionB);
expressionService.addExpression(expressionC);
expressionService.addExpression(expressionD);
Set<OrganisationUnit> units = newHashSet(sourceA, sourceB, sourceG);
CurrentUserService mockCurrentUserService = new MockCurrentUserService(true, units, units);
setDependency(predictorService, "currentUserService", mockCurrentUserService, CurrentUserService.class);
}
use of org.hisp.dhis.dataelement.DataElementCategoryOption in project dhis2-core by dhis2.
the class CsvImportServiceTest method testCategoryOptionImport.
@Test
public void testCategoryOptionImport() throws IOException {
Metadata metadata = csvImportService.fromCsv(inputBasicObjects, DataElementCategoryOption.class);
assertEquals(3, metadata.getCategoryOptions().size());
for (DataElementCategoryOption categoryOption : metadata.getCategoryOptions()) {
assertNotNull(categoryOption.getUid());
assertNotNull(categoryOption.getName());
assertNotNull(categoryOption.getShortName());
}
}
use of org.hisp.dhis.dataelement.DataElementCategoryOption in project dhis2-core by dhis2.
the class InputUtils method getAttributeOptionCombo.
/**
* Validates and retrieves the attribute option combo. 409 conflict as
* status code along with a textual message will be set on the response in
* case of invalid input.
*
* @param categoryCombo the category combo.
* @param opts list of category option uid.
* @param attributeOptionCombo the explicit attribute option combo
* identifier.
* @return the attribute option combo identified from the given input, or
* null if the input was invalid.
*/
public DataElementCategoryOptionCombo getAttributeOptionCombo(DataElementCategoryCombo categoryCombo, Set<String> opts, String attributeOptionCombo, IdScheme idScheme) {
if (categoryCombo == null) {
throw new IllegalQueryException("Illegal category combo");
}
// ---------------------------------------------------------------------
// Attribute category options validation
// ---------------------------------------------------------------------
DataElementCategoryOptionCombo attrOptCombo = null;
if (opts != null) {
Set<DataElementCategoryOption> categoryOptions = new HashSet<>();
for (String uid : opts) {
DataElementCategoryOption categoryOption = idObjectManager.getObject(DataElementCategoryOption.class, idScheme, uid);
if (categoryOption == null) {
throw new IllegalQueryException("Illegal category option identifier: " + uid);
}
categoryOptions.add(categoryOption);
}
attrOptCombo = categoryService.getDataElementCategoryOptionCombo(categoryCombo, categoryOptions);
if (attrOptCombo == null) {
throw new IllegalQueryException("Attribute option combo does not exist for given category combo and category options");
}
} else if (attributeOptionCombo != null) {
attrOptCombo = categoryService.getDataElementCategoryOptionCombo(attributeOptionCombo);
}
if (attrOptCombo == null) {
attrOptCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
}
if (attrOptCombo == null) {
throw new IllegalQueryException("Default attribute option combo does not exist");
}
return attrOptCombo;
}
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);
}
Aggregations