use of org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams in project dhis2-core by dhis2.
the class ObjectBundleServiceProgramTest method testValidateTrackedEntityAttributeSecurityShared.
@Test
void testValidateTrackedEntityAttributeSecurityShared() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/program_tea_not_shared.json").getInputStream(), RenderFormat.JSON);
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.CREATE_AND_UPDATE);
params.setObjects(metadata);
ObjectBundle bundle = objectBundleService.create(params);
ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
validate.forEachErrorReport(System.out::println);
assertFalse(validate.hasErrorReports());
objectBundleService.commit(bundle);
String[] testAuths = { "F_DATAELEMENT_PUBLIC_ADD", "F_PROGRAM_PUBLIC_ADD", "F_ORGANISATIONUNIT_ADD", "F_ORGANISATIONUNITLEVEL_UPDATE", "F_TRACKED_ENTITY_ATTRIBUTE_PUBLIC_ADD", "F_USER_ADD", "F_PROGRAMSTAGE_ADD", "F_TRACKED_ENTITY_ADD", "F_TRACKED_ENTITY_UPDATE", "F_USER_ADD_WITHIN_MANAGED_GROUP" };
User testUser = createUser("A", testAuths);
TrackedEntityAttribute tea1 = manager.get(TrackedEntityAttribute.class, "cpaMZredRXb");
TrackedEntityAttribute tea2 = manager.get(TrackedEntityAttribute.class, "QhEcRpLZwMb");
UserAccess userAccess1 = new UserAccess(testUser, "rw------");
tea1.getSharing().addUserAccess(userAccess1);
UserAccess userAccess2 = new UserAccess(testUser, "rw------");
tea2.getSharing().addUserAccess(userAccess2);
manager.update(tea1);
manager.update(tea2);
metadata = renderService.fromMetadata(new ClassPathResource("dxf2/program_tea_update.json").getInputStream(), RenderFormat.JSON);
params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.CREATE_AND_UPDATE);
params.setObjects(metadata);
params.setUser(testUser);
bundle = objectBundleService.create(params);
validate = objectBundleValidationService.validate(bundle);
validate.forEachErrorReport(System.out::println);
assertFalse(validate.hasErrorReports());
}
use of org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams in project dhis2-core by dhis2.
the class ObjectBundleServiceProgramTest method createProgramRuleMetadata.
private void createProgramRuleMetadata() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/metadata_with_program_and_programrules.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);
validate.forEachErrorReport(System.out::println);
assertFalse(validate.hasErrorReports());
objectBundleService.commit(bundle);
}
use of org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams in project dhis2-core by dhis2.
the class ObjectBundleServiceUserTest method testUpdateUsers.
@Test
void testUpdateUsers() throws IOException {
createUserAndInjectSecurityContext(true);
ObjectBundleParams params = createBundleParams(ObjectBundleMode.COMMIT, ImportStrategy.CREATE, AtomicMode.NONE, "dxf2/users.json");
ObjectBundle bundle = objectBundleService.create(params);
ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
assertEquals(1, validate.getErrorReportsCountByCode(UserAuthorityGroup.class, ErrorCode.E5003));
objectBundleService.commit(bundle);
params = createBundleParams(ObjectBundleMode.COMMIT, ImportStrategy.UPDATE, AtomicMode.NONE, "dxf2/users_update.json");
bundle = objectBundleService.create(params);
validate = objectBundleValidationService.validate(bundle);
assertEquals(1, validate.getErrorReportsCountByCode(UserAuthorityGroup.class, ErrorCode.E5001));
objectBundleService.commit(bundle);
List<User> users = manager.getAll(User.class);
assertEquals(4, users.size());
User userA = manager.get(User.class, "sPWjoHSY03y");
User userB = manager.get(User.class, "MwhEJUnTHkn");
assertEquals("UserAA", userA.getUsername());
assertEquals("admin", userA.getCreatedBy().getUsername());
assertEquals("UserBB", userB.getUsername());
assertEquals("admin", userB.getCreatedBy().getUsername());
}
use of org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams in project dhis2-core by dhis2.
the class ObjectBundleServiceUserTest method testCreateUsersWithInvalidPasswords.
@Test
void testCreateUsersWithInvalidPasswords() throws IOException {
createUserAndInjectSecurityContext(true);
ObjectBundleParams params = createBundleParams(ObjectBundleMode.VALIDATE, ImportStrategy.CREATE, AtomicMode.ALL, "dxf2/users_passwords.json");
ObjectBundle bundle = objectBundleService.create(params);
ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
assertEquals(1, validate.getErrorReportsCountByCode(User.class, ErrorCode.E4005));
}
use of org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams in project dhis2-core by dhis2.
the class ObjectBundleServiceUserTest method testCreateUsers.
@Test
void testCreateUsers() throws IOException {
createUserAndInjectSecurityContext(true);
ObjectBundleParams params = createBundleParams(ObjectBundleMode.COMMIT, ImportStrategy.CREATE, AtomicMode.NONE, "dxf2/users.json");
ObjectBundle bundle = objectBundleService.create(params);
ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
assertEquals(1, validate.getErrorReportsCountByCode(UserAuthorityGroup.class, ErrorCode.E5003));
objectBundleService.commit(bundle);
List<User> users = manager.getAll(User.class);
assertEquals(4, users.size());
User userA = userService.getUser("sPWjoHSY03y");
User userB = userService.getUser("MwhEJUnTHkn");
assertEquals("usera", userA.getUsername());
assertEquals("admin", userA.getCreatedBy().getUsername());
assertEquals("user@a.org", userA.getEmail());
assertEquals(Integer.valueOf(3), userA.getDataViewMaxOrganisationUnitLevel());
assertEquals(1, userA.getOrganisationUnits().size());
assertEquals("userb", userB.getUsername());
assertEquals("admin", userB.getCreatedBy().getUsername());
assertEquals("user@b.org", userB.getEmail());
assertEquals(Integer.valueOf(4), userB.getDataViewMaxOrganisationUnitLevel());
assertEquals(1, userB.getOrganisationUnits().size());
}
Aggregations