use of org.hisp.dhis.common.IdentifiableObject in project dhis2-core by dhis2.
the class ObjectBundleServiceTest method testPreheatValidationsIncludingMerge.
@Test
public void testPreheatValidationsIncludingMerge() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/de_validate3.json").getInputStream(), RenderFormat.JSON);
defaultSetup();
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.VALIDATE);
params.setMergeMode(MergeMode.REPLACE);
params.setObjects(metadata);
ObjectBundle bundle = objectBundleService.create(params);
ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
assertNotNull(validate);
}
use of org.hisp.dhis.common.IdentifiableObject in project dhis2-core by dhis2.
the class ObjectBundleServiceTest method testCreateOrgUnitWithLevels.
@Test
public void testCreateOrgUnitWithLevels() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/ou_with_levels.json").getInputStream(), RenderFormat.JSON);
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.CREATE_AND_UPDATE);
params.setAtomicMode(AtomicMode.ALL);
params.setObjects(metadata);
ObjectBundle bundle = objectBundleService.create(params);
assertTrue(objectBundleValidationService.validate(bundle).getErrorReports().isEmpty());
objectBundleService.commit(bundle);
OrganisationUnit root = manager.get(OrganisationUnit.class, "inVD5SdytkT");
assertNull(root.getParent());
assertEquals(3, root.getChildren().size());
}
use of org.hisp.dhis.common.IdentifiableObject in project dhis2-core by dhis2.
the class ObjectBundleServiceTest method testPreheatValidations.
@Test
public void testPreheatValidations() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/de_validate1.json").getInputStream(), RenderFormat.JSON);
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.VALIDATE);
params.setImportStrategy(ImportStrategy.CREATE);
params.setObjects(metadata);
ObjectBundle bundle = objectBundleService.create(params);
ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
assertFalse(validate.isEmpty());
List<ObjectReport> objectReports = validate.getObjectReports(DataElement.class);
assertFalse(objectReports.isEmpty());
for (ObjectReport objectReport : objectReports) {
for (ErrorCode errorCode : objectReport.getErrorCodes()) {
List<ErrorReport> errorReports = objectReport.getErrorReportsByCode().get(errorCode);
assertFalse(errorReports.isEmpty());
for (ErrorReport errorReport : errorReports) {
assertTrue(PreheatErrorReport.class.isInstance(errorReport));
PreheatErrorReport preheatErrorReport = (PreheatErrorReport) errorReport;
assertEquals(PreheatIdentifier.UID, preheatErrorReport.getPreheatIdentifier());
if (DataElementCategoryCombo.class.isInstance(preheatErrorReport.getValue())) {
assertEquals("p0KPaWEg3cf", preheatErrorReport.getObjectReference().getUid());
} else if (User.class.isInstance(preheatErrorReport.getValue())) {
assertEquals("GOLswS44mh8", preheatErrorReport.getObjectReference().getUid());
} else if (OptionSet.class.isInstance(preheatErrorReport.getValue())) {
assertEquals("pQYCiuosBnZ", preheatErrorReport.getObjectReference().getUid());
}
}
}
}
}
use of org.hisp.dhis.common.IdentifiableObject in project dhis2-core by dhis2.
the class ObjectBundleServiceTest method testDeleteRequiresValidReferencesCODE.
@Test
public void testDeleteRequiresValidReferencesCODE() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/de_validate5.json").getInputStream(), RenderFormat.JSON);
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.VALIDATE);
params.setPreheatIdentifier(PreheatIdentifier.CODE);
params.setImportStrategy(ImportStrategy.DELETE);
params.setObjects(metadata);
ObjectBundle bundle = objectBundleService.create(params);
ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
assertFalse(validate.getTypeReportMap(DataElement.class).getObjectReports().isEmpty());
assertEquals(3, validate.getErrorReportsByCode(DataElement.class, ErrorCode.E5001).size());
}
use of org.hisp.dhis.common.IdentifiableObject 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());
}
Aggregations