use of org.hisp.dhis.user.UserAuthorityGroup in project dhis2-core by dhis2.
the class ObjectBundleServiceTest method testCreateDataSetWithSections.
@Test
void testCreateDataSetWithSections() 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);
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);
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());
}
use of org.hisp.dhis.user.UserAuthorityGroup in project dhis2-core by dhis2.
the class ObjectBundleServiceTest method testCreateMetadataWithValidationRules.
@Test
void testCreateMetadataWithValidationRules() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/metadata_with_vr.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);
List<DataSet> dataSets = manager.getAll(DataSet.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);
List<ValidationRule> validationRules = manager.getAll(ValidationRule.class);
assertFalse(dataSets.isEmpty());
assertFalse(organisationUnits.isEmpty());
assertFalse(dataElements.isEmpty());
assertFalse(users.isEmpty());
assertFalse(userRoles.isEmpty());
assertEquals(2, validationRules.size());
ValidationRule validationRule1 = manager.get(ValidationRule.class, "ztzsVjSIWg7");
assertNotNull(validationRule1.getLeftSide());
assertNotNull(validationRule1.getRightSide());
ValidationRule validationRule2 = manager.get(ValidationRule.class, "TGvH4Hiyduc");
assertNotNull(validationRule2.getLeftSide());
assertNotNull(validationRule2.getRightSide());
}
use of org.hisp.dhis.user.UserAuthorityGroup in project dhis2-core by dhis2.
the class ObjectBundleServiceTest method testUpdateDataSetWithSectionsAndGreyedFields.
@Test
void testUpdateDataSetWithSectionsAndGreyedFields() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_sections_gf.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);
dbmsManager.clearSession();
Section section1 = manager.get(Section.class, "JwcV2ZifEQf");
assertNotNull(section1.getDataSet());
assertEquals(1, section1.getCategoryCombos().size());
assertTrue(section1.getGreyedFields().isEmpty());
assertEquals(1, section1.getDataElements().size());
assertNotNull(section1.getDataSet());
Section section2 = manager.get(Section.class, "C50M0WxaI7y");
assertNotNull(section2.getDataSet());
assertEquals(1, section2.getCategoryCombos().size());
assertEquals(1, section2.getGreyedFields().size());
assertEquals(1, section2.getDataElements().size());
assertNotNull(section2.getDataSet());
metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_sections_gf_update.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);
manager.flush();
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);
List<DataElementOperand> dataElementOperands = manager.getAll(DataElementOperand.class);
assertFalse(organisationUnits.isEmpty());
assertFalse(dataElements.isEmpty());
assertFalse(users.isEmpty());
assertFalse(userRoles.isEmpty());
assertEquals(1, dataSets.size());
assertEquals(2, sections.size());
assertEquals(1, dataElementOperands.size());
DataSet dataSet = dataSets.get(0);
assertEquals("Updated Data Set", dataSet.getName());
assertEquals(2, dataSet.getSections().size());
assertNotNull(dataSet.getCreatedBy());
section1 = manager.get(Section.class, "JwcV2ZifEQf");
assertNotNull(section1.getDataSet());
assertEquals(1, section1.getCategoryCombos().size());
assertEquals(1, section1.getGreyedFields().size());
assertEquals(1, section1.getDataElements().size());
assertNotNull(section1.getDataSet());
section2 = manager.get(Section.class, "C50M0WxaI7y");
assertNotNull(section2.getDataSet());
assertEquals(1, section2.getCategoryCombos().size());
assertTrue(section2.getGreyedFields().isEmpty());
assertEquals(1, section2.getDataElements().size());
assertNotNull(section2.getDataSet());
}
use of org.hisp.dhis.user.UserAuthorityGroup in project dhis2-core by dhis2.
the class ObjectBundleServiceTest method testCreateAndUpdateDataSetsWithUgaUID.
@Test
void testCreateAndUpdateDataSetsWithUgaUID() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/simple_metadata_uga.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/simple_metadata_uga.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<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);
List<UserGroup> userGroups = manager.getAll(UserGroup.class);
assertEquals(1, organisationUnits.size());
assertEquals(2, dataElements.size());
assertEquals(1, userRoles.size());
assertEquals(1, users.size());
assertEquals(2, userGroups.size());
assertEquals(1, dataElements.get(0).getUserGroupAccesses().size());
assertEquals(1, dataElements.get(1).getUserGroupAccesses().size());
}
use of org.hisp.dhis.user.UserAuthorityGroup in project dhis2-core by dhis2.
the class ObjectBundleServiceAttributesTest method testCreateSimpleMetadataAttributeValuesUID.
@Test
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);
ObjectBundleValidationReport validationReport = objectBundleValidationService.validate(bundle);
assertFalse(validationReport.hasErrorReports());
transactionTemplate.execute(status -> {
objectBundleService.commit(bundle);
return null;
});
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.getCategoryCombo());
assertEquals(defaults.get(CategoryCombo.class), dataElement.getCategoryCombo());
}
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);
assertEquals("admin", user.getUsername());
assertFalse(user.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());
}
Aggregations