Search in sources :

Example 66 with DataElement

use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.

the class ObjectBundleServiceAttributesTest method defaultSetupWithAttributes.

private void defaultSetupWithAttributes() {
    Attribute attribute = new Attribute("AttributeA", ValueType.TEXT);
    attribute.setUid("d9vw7V9Mw8W");
    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 67 with DataElement

use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.

the class ObjectBundleServiceTest method testUpdateDataElementsUID.

@Test
public void testUpdateDataElementsUID() throws IOException {
    defaultSetup();
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/de_update1.json").getInputStream(), RenderFormat.JSON);
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.COMMIT);
    params.setPreheatMode(PreheatMode.REFERENCE);
    params.setImportStrategy(ImportStrategy.UPDATE);
    params.setObjects(metadata);
    Map<String, DataElement> dataElementMap = manager.getIdMap(DataElement.class, IdScheme.UID);
    UserGroup userGroup = manager.get(UserGroup.class, "ugabcdefghA");
    assertEquals(4, dataElementMap.size());
    assertNotNull(userGroup);
    ObjectBundle bundle = objectBundleService.create(params);
    objectBundleValidationService.validate(bundle);
    objectBundleService.commit(bundle);
    DataElement dataElementA = dataElementMap.get("deabcdefghA");
    DataElement dataElementB = dataElementMap.get("deabcdefghB");
    DataElement dataElementC = dataElementMap.get("deabcdefghC");
    DataElement dataElementD = dataElementMap.get("deabcdefghD");
    assertNotNull(dataElementA);
    assertNotNull(dataElementB);
    assertNotNull(dataElementC);
    assertNotNull(dataElementD);
    assertEquals("DEA", dataElementA.getName());
    assertEquals("DEB", dataElementB.getName());
    assertEquals("DEC", dataElementC.getName());
    assertEquals("DED", dataElementD.getName());
    assertEquals("DECA", dataElementA.getCode());
    assertEquals("DECB", dataElementB.getCode());
    assertEquals("DECC", dataElementC.getCode());
    assertEquals("DECD", dataElementD.getCode());
    assertEquals("DESA", dataElementA.getShortName());
    assertEquals("DESB", dataElementB.getShortName());
    assertEquals("DESC", dataElementC.getShortName());
    assertEquals("DESD", dataElementD.getShortName());
    assertEquals("DEDA", dataElementA.getDescription());
    assertEquals("DEDB", dataElementB.getDescription());
    assertEquals("DEDC", dataElementC.getDescription());
    assertEquals("DEDD", dataElementD.getDescription());
    assertEquals(1, dataElementA.getUserGroupAccesses().size());
    assertEquals(0, dataElementB.getUserGroupAccesses().size());
    assertEquals(1, dataElementC.getUserGroupAccesses().size());
    assertEquals(0, dataElementD.getUserGroupAccesses().size());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) UserGroup(org.hisp.dhis.user.UserGroup) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 68 with DataElement

use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.

the class ObjectBundleServiceTest method testSetDefaultCategoryCombo.

@Test
public void testSetDefaultCategoryCombo() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/de_no_cc.json").getInputStream(), RenderFormat.JSON);
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.COMMIT);
    params.setImportStrategy(ImportStrategy.CREATE);
    params.setAtomicMode(AtomicMode.ALL);
    params.setObjects(metadata);
    ObjectBundle bundle = objectBundleService.create(params);
    assertTrue(objectBundleValidationService.validate(bundle).getErrorReports().isEmpty());
    objectBundleService.commit(bundle);
    List<DataElement> dataElements = manager.getAll(DataElement.class);
    assertEquals(1, dataElements.size());
    DataElement dataElement = dataElements.get(0);
    assertEquals("CCCC", dataElement.getName());
    assertEquals("CCCC", dataElement.getShortName());
    assertNotNull(dataElement.getDataElementCategoryCombo());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 69 with DataElement

use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.

the class ObjectBundleServiceTest method testUpdateDataElementsCODE.

@Test
public void testUpdateDataElementsCODE() throws IOException {
    defaultSetup();
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/de_update2.json").getInputStream(), RenderFormat.JSON);
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.COMMIT);
    params.setPreheatIdentifier(PreheatIdentifier.CODE);
    params.setImportStrategy(ImportStrategy.UPDATE);
    params.setObjects(metadata);
    Map<String, DataElement> dataElementMap = manager.getIdMap(DataElement.class, IdScheme.UID);
    UserGroup userGroup = manager.get(UserGroup.class, "ugabcdefghA");
    assertEquals(4, dataElementMap.size());
    assertNotNull(userGroup);
    ObjectBundle bundle = objectBundleService.create(params);
    objectBundleValidationService.validate(bundle);
    objectBundleService.commit(bundle);
    DataElement dataElementA = dataElementMap.get("deabcdefghA");
    DataElement dataElementB = dataElementMap.get("deabcdefghB");
    DataElement dataElementC = dataElementMap.get("deabcdefghC");
    DataElement dataElementD = dataElementMap.get("deabcdefghD");
    assertNotNull(dataElementA);
    assertNotNull(dataElementB);
    assertNotNull(dataElementC);
    assertNotNull(dataElementD);
    assertEquals("DEA", dataElementA.getName());
    assertEquals("DEB", dataElementB.getName());
    assertEquals("DEC", dataElementC.getName());
    assertEquals("DED", dataElementD.getName());
    assertEquals("DataElementCodeA", dataElementA.getCode());
    assertEquals("DataElementCodeB", dataElementB.getCode());
    assertEquals("DataElementCodeC", dataElementC.getCode());
    assertEquals("DataElementCodeD", dataElementD.getCode());
    assertEquals("DESA", dataElementA.getShortName());
    assertEquals("DESB", dataElementB.getShortName());
    assertEquals("DESC", dataElementC.getShortName());
    assertEquals("DESD", dataElementD.getShortName());
    assertEquals("DEDA", dataElementA.getDescription());
    assertEquals("DEDB", dataElementB.getDescription());
    assertEquals("DEDC", dataElementC.getDescription());
    assertEquals("DEDD", dataElementD.getDescription());
    assertEquals(1, dataElementA.getUserGroupAccesses().size());
    assertEquals(0, dataElementB.getUserGroupAccesses().size());
    assertEquals(1, dataElementC.getUserGroupAccesses().size());
    assertEquals(0, dataElementD.getUserGroupAccesses().size());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) UserGroup(org.hisp.dhis.user.UserGroup) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 70 with DataElement

use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.

the class ObjectBundleServiceTest method testCreateMetadataWithDuplicateDataElementUid.

@Test
public void testCreateMetadataWithDuplicateDataElementUid() throws IOException {
    createUserAndInjectSecurityContext(true);
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/de_duplicate_uid.json").getInputStream(), RenderFormat.JSON);
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.COMMIT);
    params.setImportStrategy(ImportStrategy.CREATE_AND_UPDATE);
    params.setAtomicMode(AtomicMode.NONE);
    params.setObjects(metadata);
    ObjectBundle bundle = objectBundleService.create(params);
    objectBundleValidationService.validate(bundle);
    objectBundleService.commit(bundle);
    assertEquals(1, manager.getAll(DataElement.class).size());
    DataElement dataElement = manager.get(DataElement.class, "CCwk5Yx440o");
    assertEquals("CCwk5Yx440o", dataElement.getUid());
    assertEquals("DataElementB", dataElement.getName());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

DataElement (org.hisp.dhis.dataelement.DataElement)254 Test (org.junit.Test)137 DhisSpringTest (org.hisp.dhis.DhisSpringTest)99 User (org.hisp.dhis.user.User)51 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)47 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)44 DataSet (org.hisp.dhis.dataset.DataSet)39 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)36 ArrayList (java.util.ArrayList)31 List (java.util.List)31 ClassPathResource (org.springframework.core.io.ClassPathResource)26 HashSet (java.util.HashSet)23 Period (org.hisp.dhis.period.Period)20 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)19 DataElementGroup (org.hisp.dhis.dataelement.DataElementGroup)18 DataElementCategoryCombo (org.hisp.dhis.dataelement.DataElementCategoryCombo)16 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)15 DataValue (org.hisp.dhis.datavalue.DataValue)15 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)14 Matcher (java.util.regex.Matcher)13