Search in sources :

Example 11 with Attribute

use of org.hisp.dhis.attribute.Attribute in project dhis2-core by dhis2.

the class PreheatServiceTest method defaultSetupWithAttributes.

private void defaultSetupWithAttributes() {
    Attribute attribute = new Attribute("AttributeA", ValueType.TEXT);
    attribute.setUnique(true);
    attribute.setMandatory(true);
    attribute.setDataElementAttribute(true);
    manager.save(attribute);
    AttributeValue attributeValue1 = new AttributeValue("Value1", attribute);
    AttributeValue attributeValue2 = new AttributeValue("Value2", attribute);
    AttributeValue attributeValue3 = new AttributeValue("Value3", attribute);
    DataElement de1 = createDataElement('A');
    DataElement de2 = createDataElement('B');
    DataElement de3 = createDataElement('C');
    attributeService.addAttributeValue(de1, attributeValue1);
    attributeService.addAttributeValue(de2, attributeValue2);
    attributeService.addAttributeValue(de3, attributeValue3);
    manager.save(de1);
    manager.save(de2);
    manager.save(de3);
    User user = createUser('A');
    manager.save(user);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) AttributeValue(org.hisp.dhis.attribute.AttributeValue) User(org.hisp.dhis.user.User) Attribute(org.hisp.dhis.attribute.Attribute)

Example 12 with Attribute

use of org.hisp.dhis.attribute.Attribute in project dhis2-core by dhis2.

the class ObjectBundleServiceAttributesTest method testCreateSimpleMetadataAttributeValuesUID.

@Test
public void testCreateSimpleMetadataAttributeValuesUID() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/simple_metadata_with_av.json").getInputStream(), RenderFormat.JSON);
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.COMMIT);
    params.setImportStrategy(ImportStrategy.CREATE);
    params.setObjects(metadata);
    ObjectBundle bundle = objectBundleService.create(params);
    objectBundleValidationService.validate(bundle);
    objectBundleService.commit(bundle);
    List<OrganisationUnit> organisationUnits = manager.getAll(OrganisationUnit.class);
    List<DataElement> dataElements = manager.getAll(DataElement.class);
    List<DataSet> dataSets = manager.getAll(DataSet.class);
    List<UserAuthorityGroup> userRoles = manager.getAll(UserAuthorityGroup.class);
    List<User> users = manager.getAll(User.class);
    List<Option> options = manager.getAll(Option.class);
    List<OptionSet> optionSets = manager.getAll(OptionSet.class);
    List<Attribute> attributes = manager.getAll(Attribute.class);
    assertFalse(organisationUnits.isEmpty());
    assertFalse(dataElements.isEmpty());
    assertFalse(dataSets.isEmpty());
    assertFalse(users.isEmpty());
    assertFalse(userRoles.isEmpty());
    assertEquals(2, attributes.size());
    assertEquals(2, options.size());
    assertEquals(1, optionSets.size());
    Map<Class<? extends IdentifiableObject>, IdentifiableObject> defaults = manager.getDefaults();
    DataSet dataSet = dataSets.get(0);
    User user = users.get(0);
    OptionSet optionSet = optionSets.get(0);
    for (DataElement dataElement : dataElements) {
        assertNotNull(dataElement.getDataElementCategoryCombo());
        assertEquals(defaults.get(DataElementCategoryCombo.class), dataElement.getDataElementCategoryCombo());
    }
    assertFalse(dataSet.getSources().isEmpty());
    assertFalse(dataSet.getDataSetElements().isEmpty());
    assertEquals(1, dataSet.getSources().size());
    assertEquals(2, dataSet.getDataSetElements().size());
    assertEquals(PeriodType.getPeriodTypeByName("Monthly"), dataSet.getPeriodType());
    assertNotNull(user.getUserCredentials());
    assertEquals("admin", user.getUserCredentials().getUsername());
    assertFalse(user.getUserCredentials().getUserAuthorityGroups().isEmpty());
    assertFalse(user.getOrganisationUnits().isEmpty());
    assertEquals("PdWlltZnVZe", user.getOrganisationUnit().getUid());
    assertEquals(2, optionSet.getOptions().size());
    // attribute value check
    DataElement dataElementA = manager.get(DataElement.class, "SG4HuKlNEFH");
    DataElement dataElementB = manager.get(DataElement.class, "CCwk5Yx440o");
    DataElement dataElementC = manager.get(DataElement.class, "j5PneRdU7WT");
    DataElement dataElementD = manager.get(DataElement.class, "k90AVpBahO4");
    assertNotNull(dataElementA);
    assertNotNull(dataElementB);
    assertNotNull(dataElementC);
    assertNotNull(dataElementD);
    assertTrue(dataElementA.getAttributeValues().isEmpty());
    assertTrue(dataElementB.getAttributeValues().isEmpty());
    assertFalse(dataElementC.getAttributeValues().isEmpty());
    assertFalse(dataElementD.getAttributeValues().isEmpty());
}
Also used : User(org.hisp.dhis.user.User) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) DataSet(org.hisp.dhis.dataset.DataSet) Attribute(org.hisp.dhis.attribute.Attribute) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) DataElement(org.hisp.dhis.dataelement.DataElement) List(java.util.List) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ClassPathResource(org.springframework.core.io.ClassPathResource) UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) Option(org.hisp.dhis.option.Option) OptionSet(org.hisp.dhis.option.OptionSet) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 13 with Attribute

use of org.hisp.dhis.attribute.Attribute in project dhis2-core by dhis2.

the class DataValueSetServiceTest method setUpTest.

@Override
public void setUpTest() {
    mockDataValueBatchHandler = new MockBatchHandler<>();
    mockDataValueAuditBatchHandler = new MockBatchHandler<>();
    mockBatchHandlerFactory = new MockBatchHandlerFactory();
    mockBatchHandlerFactory.registerBatchHandler(DataValueBatchHandler.class, mockDataValueBatchHandler);
    mockBatchHandlerFactory.registerBatchHandler(DataValueAuditBatchHandler.class, mockDataValueAuditBatchHandler);
    setDependency(dataValueSetService, "batchHandlerFactory", mockBatchHandlerFactory);
    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 = createDataElementCategory('A', categoryOptionA, categoryOptionB);
    categoryComboA = createCategoryCombo('A', categoryA);
    categoryComboDef = categoryService.getDefaultDataElementCategoryCombo();
    ocDef = categoryService.getDefaultDataElementCategoryOptionCombo();
    ocDef.setCode("OC_DEF_CODE");
    categoryService.updateDataElementCategoryOptionCombo(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);
    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.addDataElementCategoryOption(categoryOptionA);
    categoryService.addDataElementCategoryOption(categoryOptionB);
    categoryService.addDataElementCategory(categoryA);
    categoryService.addDataElementCategoryCombo(categoryComboA);
    categoryService.addDataElementCategoryOptionCombo(ocA);
    categoryService.addDataElementCategoryOptionCombo(ocB);
    attributeService.addAttributeValue(deA, createAttributeValue(attribute, "DE1"));
    dataElementService.addDataElement(deA);
    attributeService.addAttributeValue(deB, createAttributeValue(attribute, "DE2"));
    dataElementService.addDataElement(deB);
    attributeService.addAttributeValue(deC, createAttributeValue(attribute, "DE3"));
    dataElementService.addDataElement(deC);
    attributeService.addAttributeValue(deD, createAttributeValue(attribute, "DE4"));
    dataElementService.addDataElement(deD);
    dataElementService.addDataElement(deF);
    dataElementService.addDataElement(deG);
    idObjectManager.save(osA);
    dsA.addDataSetElement(deA);
    dsA.addDataSetElement(deB);
    dsA.addDataSetElement(deC);
    dsA.addDataSetElement(deD);
    attributeService.addAttributeValue(ouA, createAttributeValue(attribute, "OU1"));
    organisationUnitService.addOrganisationUnit(ouA);
    attributeService.addAttributeValue(ouB, createAttributeValue(attribute, "OU2"));
    organisationUnitService.addOrganisationUnit(ouB);
    attributeService.addAttributeValue(ouC, createAttributeValue(attribute, "OU3"));
    organisationUnitService.addOrganisationUnit(ouC);
    dsA.addOrganisationUnit(ouA);
    dsA.addOrganisationUnit(ouC);
    dataSetService.addDataSet(dsA);
    periodService.addPeriod(peA);
    periodService.addPeriod(peB);
    periodService.addPeriod(peC);
    user = createUser('A');
    user.setOrganisationUnits(Sets.newHashSet(ouA, ouB));
    CurrentUserService currentUserService = new MockCurrentUserService(user);
    setDependency(dataValueSetService, "currentUserService", currentUserService);
}
Also used : MockBatchHandlerFactory(org.hisp.dhis.mock.batchhandler.MockBatchHandlerFactory) Attribute(org.hisp.dhis.attribute.Attribute) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) CurrentUserService(org.hisp.dhis.user.CurrentUserService) Option(org.hisp.dhis.option.Option) OptionSet(org.hisp.dhis.option.OptionSet)

Example 14 with Attribute

use of org.hisp.dhis.attribute.Attribute in project dhis2-core by dhis2.

the class DataElementStoreTest method testDataElementByUniqueAttributeValue.

@Test
public void testDataElementByUniqueAttributeValue() throws NonUniqueAttributeValueException {
    Attribute attribute = new Attribute("cid", ValueType.TEXT);
    attribute.setDataElementAttribute(true);
    attribute.setUnique(true);
    attributeService.addAttribute(attribute);
    DataElement dataElementA = createDataElement('A');
    DataElement dataElementB = createDataElement('B');
    DataElement dataElementC = createDataElement('C');
    dataElementStore.save(dataElementA);
    dataElementStore.save(dataElementB);
    dataElementStore.save(dataElementC);
    AttributeValue attributeValueA = new AttributeValue("CID1", attribute);
    AttributeValue attributeValueB = new AttributeValue("CID2", attribute);
    AttributeValue attributeValueC = new AttributeValue("CID3", attribute);
    attributeService.addAttributeValue(dataElementA, attributeValueA);
    attributeService.addAttributeValue(dataElementB, attributeValueB);
    attributeService.addAttributeValue(dataElementC, attributeValueC);
    dataElementStore.update(dataElementA);
    dataElementStore.update(dataElementB);
    dataElementStore.update(dataElementC);
    assertNotNull(dataElementStore.getByUniqueAttributeValue(attribute, "CID1"));
    assertNotNull(dataElementStore.getByUniqueAttributeValue(attribute, "CID2"));
    assertNotNull(dataElementStore.getByUniqueAttributeValue(attribute, "CID3"));
    assertNull(dataElementStore.getByUniqueAttributeValue(attribute, "CID4"));
    assertNull(dataElementStore.getByUniqueAttributeValue(attribute, "CID5"));
    assertEquals("DataElementA", dataElementStore.getByUniqueAttributeValue(attribute, "CID1").getName());
    assertEquals("DataElementB", dataElementStore.getByUniqueAttributeValue(attribute, "CID2").getName());
    assertEquals("DataElementC", dataElementStore.getByUniqueAttributeValue(attribute, "CID3").getName());
}
Also used : AttributeValue(org.hisp.dhis.attribute.AttributeValue) Attribute(org.hisp.dhis.attribute.Attribute) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 15 with Attribute

use of org.hisp.dhis.attribute.Attribute in project dhis2-core by dhis2.

the class DataElementStoreTest method testAttributeValueFromAttribute.

@Test
public void testAttributeValueFromAttribute() throws NonUniqueAttributeValueException {
    Attribute attribute = new Attribute("test", ValueType.TEXT);
    attribute.setDataElementAttribute(true);
    attributeService.addAttribute(attribute);
    DataElement dataElementA = createDataElement('A');
    DataElement dataElementB = createDataElement('B');
    DataElement dataElementC = createDataElement('C');
    dataElementStore.save(dataElementA);
    dataElementStore.save(dataElementB);
    dataElementStore.save(dataElementC);
    AttributeValue attributeValueA = new AttributeValue("SOME VALUE", attribute);
    AttributeValue attributeValueB = new AttributeValue("SOME VALUE", attribute);
    AttributeValue attributeValueC = new AttributeValue("ANOTHER VALUE", attribute);
    attributeService.addAttributeValue(dataElementA, attributeValueA);
    attributeService.addAttributeValue(dataElementB, attributeValueB);
    attributeService.addAttributeValue(dataElementC, attributeValueC);
    dataElementStore.update(dataElementA);
    dataElementStore.update(dataElementB);
    dataElementStore.update(dataElementC);
    List<AttributeValue> values = dataElementStore.getAttributeValueByAttribute(attribute);
    assertEquals(3, values.size());
}
Also used : AttributeValue(org.hisp.dhis.attribute.AttributeValue) Attribute(org.hisp.dhis.attribute.Attribute) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

Attribute (org.hisp.dhis.attribute.Attribute)16 AttributeValue (org.hisp.dhis.attribute.AttributeValue)12 Test (org.junit.Test)8 DhisSpringTest (org.hisp.dhis.DhisSpringTest)7 DataElement (org.hisp.dhis.dataelement.DataElement)4 User (org.hisp.dhis.user.User)3 ArrayList (java.util.ArrayList)2 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)2 Option (org.hisp.dhis.option.Option)2 OptionSet (org.hisp.dhis.option.OptionSet)2 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Session (org.hibernate.Session)1 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)1 DataElementCategoryCombo (org.hisp.dhis.dataelement.DataElementCategoryCombo)1 DataSet (org.hisp.dhis.dataset.DataSet)1 ErrorReport (org.hisp.dhis.feedback.ErrorReport)1