use of org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams in project dhis2-core by dhis2.
the class ObjectBundleServiceTest method testCreatePreheatValidationsInvalidObjects.
@Test
void testCreatePreheatValidationsInvalidObjects() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/de_validate2.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);
assertTrue(validate.hasErrorReports());
assertEquals(5, validate.getErrorReportsCountByCode(DataElement.class, ErrorCode.E5002));
assertEquals(3, validate.getErrorReportsCountByCode(DataElement.class, ErrorCode.E4000));
}
use of org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams in project dhis2-core by dhis2.
the class ObjectBundleServiceTest method testUpdateWithPersistedObjectsRequiresValidReferencesUID.
@Test
void testUpdateWithPersistedObjectsRequiresValidReferencesUID() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/de_validate7.json").getInputStream(), RenderFormat.JSON);
defaultSetup();
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.VALIDATE);
params.setPreheatIdentifier(PreheatIdentifier.UID);
params.setImportStrategy(ImportStrategy.UPDATE);
params.setAtomicMode(NONE);
params.setObjects(metadata);
ObjectBundle bundle = objectBundleService.create(params);
ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
assertEquals(1, validate.getErrorReportsCountByCode(DataElement.class, ErrorCode.E5001));
assertNotEquals(0, validate.getErrorReportsCountByCode(DataElement.class, ErrorCode.E4000));
assertEquals(0, bundle.getObjectsCount(DataElement.class));
}
use of org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams in project dhis2-core by dhis2.
the class OptionObjectBundleHookTest method preCreateOptionSetAvailable.
@Test
void preCreateOptionSetAvailable() {
OptionSet optionSet = new OptionSet();
optionSet.setUid("jadhjSHdhs");
Option option = new Option();
option.setOptionSet(optionSet);
OptionSet persistedOptionSet = new OptionSet();
persistedOptionSet.setUid("jadhjSHdhs");
preheat.put(PreheatIdentifier.UID, persistedOptionSet);
ObjectBundleParams objectBundleParams = new ObjectBundleParams();
objectBundleParams.setPreheatIdentifier(PreheatIdentifier.UID);
ObjectBundle bundle = new ObjectBundle(objectBundleParams, preheat, Collections.singletonMap(OptionSet.class, Collections.singletonList(optionSet)));
hook.preCreate(option, bundle);
Assertions.assertEquals(0, persistedOptionSet.getOptions().size());
}
use of org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams in project dhis2-core by dhis2.
the class OptionObjectBundleHookTest method preCreate.
@Test
void preCreate() {
OptionSet optionSet = new OptionSet();
optionSet.setUid("jadhjSHdhs");
Option option = new Option();
option.setOptionSet(optionSet);
OptionSet persistedOptionSet = new OptionSet();
persistedOptionSet.setUid("jadhjSHdhs");
preheat.put(PreheatIdentifier.UID, persistedOptionSet);
ObjectBundleParams objectBundleParams = new ObjectBundleParams();
objectBundleParams.setPreheatIdentifier(PreheatIdentifier.UID);
ObjectBundle bundle = new ObjectBundle(objectBundleParams, preheat, Collections.emptyMap());
hook.preCreate(option, bundle);
Assertions.assertEquals(1, persistedOptionSet.getOptions().size());
Assertions.assertSame(option, persistedOptionSet.getOptions().get(0));
}
use of org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams in project dhis2-core by dhis2.
the class ObjectBundleServiceTest method testCreateAndUpdateDataSetWithSections.
@Test
void testCreateAndUpdateDataSetWithSections() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_sections.json").getInputStream(), RenderFormat.JSON);
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.CREATE);
params.setObjects(metadata);
ObjectBundle bundle = objectBundleService.create(params);
ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
assertFalse(validate.hasErrorReports());
objectBundleService.commit(bundle);
metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_sections.json").getInputStream(), RenderFormat.JSON);
params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.UPDATE);
params.setObjects(metadata);
bundle = objectBundleService.create(params);
validate = objectBundleValidationService.validate(bundle);
assertFalse(validate.hasErrorReports());
objectBundleService.commit(bundle);
List<DataSet> dataSets = manager.getAll(DataSet.class);
List<Section> sections = manager.getAll(Section.class);
List<OrganisationUnit> organisationUnits = manager.getAll(OrganisationUnit.class);
List<DataElement> dataElements = manager.getAll(DataElement.class);
List<UserAuthorityGroup> userRoles = manager.getAll(UserAuthorityGroup.class);
List<User> users = manager.getAll(User.class);
assertFalse(organisationUnits.isEmpty());
assertFalse(dataElements.isEmpty());
assertFalse(dataSets.isEmpty());
assertFalse(users.isEmpty());
assertFalse(userRoles.isEmpty());
assertEquals(1, dataSets.size());
assertEquals(2, sections.size());
DataSet dataSet = dataSets.get(0);
assertNotNull(dataSet.getPeriodType());
assertEquals(2, dataSet.getSections().size());
Section section1 = sections.get(0);
Section section2 = sections.get(1);
assertEquals(1, section1.getDataElements().size());
assertEquals(1, section2.getDataElements().size());
assertNotNull(section1.getDataSet());
assertNotNull(section2.getDataSet());
}
Aggregations