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);
}
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());
}
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());
}
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());
}
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());
}
Aggregations