Search in sources :

Example 61 with ObjectBundleParams

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());
}
Also used : User(org.hisp.dhis.user.User) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) UserAccess(org.hisp.dhis.user.sharing.UserAccess) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) List(java.util.List) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 62 with ObjectBundleParams

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);
}
Also used : ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

Example 63 with ObjectBundleParams

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());
}
Also used : User(org.hisp.dhis.user.User) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 64 with ObjectBundleParams

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));
}
Also used : User(org.hisp.dhis.user.User) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 65 with ObjectBundleParams

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());
}
Also used : User(org.hisp.dhis.user.User) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)65 List (java.util.List)62 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)62 ClassPathResource (org.springframework.core.io.ClassPathResource)61 Test (org.junit.jupiter.api.Test)52 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)39 DataElement (org.hisp.dhis.dataelement.DataElement)32 User (org.hisp.dhis.user.User)25 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)20 DataSet (org.hisp.dhis.dataset.DataSet)18 ObjectBundleParams (org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams)18 UserAuthorityGroup (org.hisp.dhis.user.UserAuthorityGroup)18 ObjectBundle (org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundle)17 DhisSpringTest (org.hisp.dhis.DhisSpringTest)9 OptionSet (org.hisp.dhis.option.OptionSet)9 ValidationRule (org.hisp.dhis.validation.ValidationRule)7 CategoryCombo (org.hisp.dhis.category.CategoryCombo)6 Section (org.hisp.dhis.dataset.Section)5 Test (org.junit.Test)5 IOException (java.io.IOException)4