Search in sources :

Example 1 with BatchHandlerFactoryTarget

use of org.hisp.dhis.common.BatchHandlerFactoryTarget in project dhis2-core by dhis2.

the class DataValueSetServiceTest method setUpTest.

@Override
public void setUpTest() {
    CategoryOptionCombo categoryOptionCombo = categoryService.getDefaultCategoryOptionCombo();
    userService = _userService;
    mockDataValueBatchHandler = new MockBatchHandler<>();
    mockDataValueAuditBatchHandler = new MockBatchHandler<>();
    mockBatchHandlerFactory = new MockBatchHandlerFactory();
    mockBatchHandlerFactory.registerBatchHandler(DataValueBatchHandler.class, mockDataValueBatchHandler);
    mockBatchHandlerFactory.registerBatchHandler(DataValueAuditBatchHandler.class, mockDataValueAuditBatchHandler);
    setDependency(BatchHandlerFactoryTarget.class, BatchHandlerFactoryTarget::setBatchHandlerFactory, mockBatchHandlerFactory, dataValueSetService);
    attribute = new Attribute("CUSTOM_ID", ValueType.TEXT);
    attribute.setUid(ATTRIBUTE_UID);
    attribute.setUnique(true);
    attribute.setOrganisationUnitAttribute(true);
    attribute.setDataElementAttribute(true);
    idObjectManager.save(attribute);
    categoryOptionA = createCategoryOption('A');
    categoryOptionB = createCategoryOption('B');
    categoryA = createCategory('A');
    categoryService.addCategory(categoryA);
    categoryOptionA.getCategories().add(categoryA);
    categoryOptionB.getCategories().add(categoryA);
    categoryService.addCategoryOption(categoryOptionB);
    categoryService.addCategoryOption(categoryOptionA);
    categoryComboA = createCategoryCombo('A', categoryA);
    categoryComboDef = categoryService.getDefaultCategoryCombo();
    ocDef = categoryService.getDefaultCategoryOptionCombo();
    ocDef.setCode("OC_DEF_CODE");
    categoryService.updateCategoryOptionCombo(ocDef);
    osA = new OptionSet("OptionSetA", ValueType.INTEGER);
    osA.getOptions().add(new Option("Blue", "1"));
    osA.getOptions().add(new Option("Green", "2"));
    osA.getOptions().add(new Option("Yellow", "3"));
    ocA = createCategoryOptionCombo(categoryComboA, categoryOptionA);
    ocB = createCategoryOptionCombo(categoryComboA, categoryOptionB);
    deA = createDataElement('A', categoryComboDef);
    deB = createDataElement('B', categoryComboDef);
    deC = createDataElement('C', categoryComboDef);
    deD = createDataElement('D', categoryComboDef);
    deE = createDataElement('E');
    deE.setOptionSet(osA);
    deF = createDataElement('F', categoryComboDef);
    deF.setValueType(ValueType.BOOLEAN);
    deG = createDataElement('G', categoryComboDef);
    deG.setValueType(ValueType.TRUE_ONLY);
    dsA = createDataSet('A', new MonthlyPeriodType());
    dsA.setCategoryCombo(categoryComboDef);
    dsB = createDataSet('B');
    dsB.setCategoryCombo(categoryComboDef);
    ouA = createOrganisationUnit('A');
    ouB = createOrganisationUnit('B');
    ouC = createOrganisationUnit('C');
    peA = createPeriod(PeriodType.getByNameIgnoreCase(MonthlyPeriodType.NAME), getDate(2012, 1, 1), getDate(2012, 1, 31));
    peB = createPeriod(PeriodType.getByNameIgnoreCase(MonthlyPeriodType.NAME), getDate(2012, 2, 1), getDate(2012, 2, 29));
    peC = createPeriod(PeriodType.getByNameIgnoreCase(MonthlyPeriodType.NAME), getDate(2012, 3, 1), getDate(2012, 3, 31));
    ocA.setUid("kjuiHgy67hg");
    ocB.setUid("Gad33qy67g5");
    deA.setUid("f7n9E0hX8qk");
    deB.setUid("Ix2HsbDMLea");
    deC.setUid("eY5ehpbEsB7");
    deE.setUid("jH26dja2f28");
    deF.setUid("jH26dja2f30");
    deG.setUid("jH26dja2f31");
    dsA.setUid("pBOMPrpg1QX");
    ouA.setUid("DiszpKrYNg8");
    ouB.setUid("BdfsJfj87js");
    ouC.setUid("j7Hg26FpoIa");
    ocA.setCode("OC_A");
    ocB.setCode("OC_B");
    deA.setCode("DE_A");
    deB.setCode("DE_B");
    deC.setCode("DE_C");
    deD.setCode("DE_D");
    dsA.setCode("DS_A");
    ouA.setCode("OU_A");
    ouB.setCode("OU_B");
    ouC.setCode("OU_C");
    categoryService.addCategoryCombo(categoryComboA);
    categoryService.addCategoryOptionCombo(ocA);
    categoryService.addCategoryOptionCombo(ocB);
    AttributeValue av1 = createAttributeValue(attribute, "DE1");
    dataElementService.addDataElement(deA);
    dataElementService.addDataElement(deB);
    dataElementService.addDataElement(deC);
    dataElementService.addDataElement(deD);
    dataElementService.addDataElement(deF);
    dataElementService.addDataElement(deG);
    attributeService.addAttributeValue(deA, av1);
    attributeService.addAttributeValue(deB, createAttributeValue(attribute, "DE2"));
    attributeService.addAttributeValue(deC, createAttributeValue(attribute, "DE3"));
    attributeService.addAttributeValue(deD, createAttributeValue(attribute, "DE4"));
    idObjectManager.save(osA);
    dsA.addDataSetElement(deA);
    dsA.addDataSetElement(deB);
    dsA.addDataSetElement(deC);
    dsA.addDataSetElement(deD);
    organisationUnitService.addOrganisationUnit(ouA);
    organisationUnitService.addOrganisationUnit(ouB);
    organisationUnitService.addOrganisationUnit(ouC);
    attributeService.addAttributeValue(ouA, createAttributeValue(attribute, "OU1"));
    attributeService.addAttributeValue(ouB, createAttributeValue(attribute, "OU2"));
    attributeService.addAttributeValue(ouC, createAttributeValue(attribute, "OU3"));
    dsA.addOrganisationUnit(ouA);
    dsA.addOrganisationUnit(ouC);
    periodService.addPeriod(peA);
    periodService.addPeriod(peB);
    periodService.addPeriod(peC);
    dataSetService.addDataSet(dsA);
    user = createUser('A', Lists.newArrayList(Authorities.F_SKIP_DATA_IMPORT_AUDIT.getAuthority()));
    user.setOrganisationUnits(Sets.newHashSet(ouA, ouB));
    userService.addUser(user);
    injectSecurityContext(user);
    CurrentUserService currentUserService = new MockCurrentUserService(user);
    setDependency(CurrentUserServiceTarget.class, CurrentUserServiceTarget::setCurrentUserService, currentUserService, dataValueSetService);
    enableDataSharing(user, dsA, AccessStringHelper.DATA_READ_WRITE);
    enableDataSharing(user, categoryOptionA, AccessStringHelper.DATA_READ_WRITE);
    enableDataSharing(user, categoryOptionB, AccessStringHelper.DATA_READ_WRITE);
    _userService.addUser(user);
    CompleteDataSetRegistration completeDataSetRegistration = new CompleteDataSetRegistration(dsA, peA, ouA, categoryOptionCombo, getDate(2012, 1, 9), "userA", new Date(), "userA", true);
    registrationService.saveCompleteDataSetRegistration(completeDataSetRegistration);
}
Also used : AttributeValue(org.hisp.dhis.attribute.AttributeValue) Attribute(org.hisp.dhis.attribute.Attribute) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) CurrentUserService(org.hisp.dhis.user.CurrentUserService) CurrentUserServiceTarget(org.hisp.dhis.user.CurrentUserServiceTarget) Date(java.util.Date) MockBatchHandlerFactory(org.hisp.dhis.mock.batchhandler.MockBatchHandlerFactory) BatchHandlerFactoryTarget(org.hisp.dhis.common.BatchHandlerFactoryTarget) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) CategoryOption(org.hisp.dhis.category.CategoryOption) Option(org.hisp.dhis.option.Option) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) OptionSet(org.hisp.dhis.option.OptionSet) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Aggregations

Date (java.util.Date)1 Attribute (org.hisp.dhis.attribute.Attribute)1 AttributeValue (org.hisp.dhis.attribute.AttributeValue)1 CategoryOption (org.hisp.dhis.category.CategoryOption)1 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)1 BatchHandlerFactoryTarget (org.hisp.dhis.common.BatchHandlerFactoryTarget)1 CompleteDataSetRegistration (org.hisp.dhis.dataset.CompleteDataSetRegistration)1 MockCurrentUserService (org.hisp.dhis.mock.MockCurrentUserService)1 MockBatchHandlerFactory (org.hisp.dhis.mock.batchhandler.MockBatchHandlerFactory)1 Option (org.hisp.dhis.option.Option)1 OptionSet (org.hisp.dhis.option.OptionSet)1 MonthlyPeriodType (org.hisp.dhis.period.MonthlyPeriodType)1 CurrentUserService (org.hisp.dhis.user.CurrentUserService)1 CurrentUserServiceTarget (org.hisp.dhis.user.CurrentUserServiceTarget)1