Search in sources :

Example 86 with IdentifiableObject

use of org.hisp.dhis.common.IdentifiableObject in project dhis2-core by dhis2.

the class ObjectBundleServiceUserTest method testCreateUserRoleWithDataSetProgramAssignment.

@Test
public void testCreateUserRoleWithDataSetProgramAssignment() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/userrole_program_dataset_assignment.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);
    List<UserAuthorityGroup> userRoles = manager.getAll(UserAuthorityGroup.class);
    assertEquals(1, userRoles.size());
    UserAuthorityGroup userRole = userRoles.get(0);
    assertNotNull(userRole);
    assertEquals(1, userRole.getDataSets().size());
    assertEquals(1, userRole.getPrograms().size());
}
Also used : UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 87 with IdentifiableObject

use of org.hisp.dhis.common.IdentifiableObject in project dhis2-core by dhis2.

the class ObjectBundleServiceUserTest method testUpdateUsers.

@Test
public void testUpdateUsers() throws IOException {
    createUserAndInjectSecurityContext(true);
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/users.json").getInputStream(), RenderFormat.JSON);
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.COMMIT);
    params.setImportStrategy(ImportStrategy.CREATE);
    params.setAtomicMode(AtomicMode.NONE);
    params.setObjects(metadata);
    ObjectBundle bundle = objectBundleService.create(params);
    ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
    assertEquals(1, validate.getErrorReportsByCode(UserAuthorityGroup.class, ErrorCode.E5003).size());
    objectBundleService.commit(bundle);
    metadata = renderService.fromMetadata(new ClassPathResource("dxf2/users_update.json").getInputStream(), RenderFormat.JSON);
    params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.COMMIT);
    params.setImportStrategy(ImportStrategy.UPDATE);
    params.setAtomicMode(AtomicMode.NONE);
    params.setObjects(metadata);
    bundle = objectBundleService.create(params);
    validate = objectBundleValidationService.validate(bundle);
    assertEquals(1, validate.getErrorReportsByCode(UserAuthorityGroup.class, ErrorCode.E5001).size());
    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");
    assertNotNull(userA);
    assertNotNull(userB);
    assertNotNull(userA.getUserCredentials().getUserInfo());
    assertNotNull(userB.getUserCredentials().getUserInfo());
    assertNotNull(userA.getUserCredentials().getUserInfo().getUserCredentials());
    assertNotNull(userB.getUserCredentials().getUserInfo().getUserCredentials());
    assertEquals("UserAA", userA.getUserCredentials().getUserInfo().getUserCredentials().getUsername());
    assertEquals("UserBB", userB.getUserCredentials().getUserInfo().getUserCredentials().getUsername());
    assertNotNull(userA.getUserCredentials().getUser());
    assertNotNull(userB.getUserCredentials().getUser());
    assertNotNull(userA.getUserCredentials().getUser().getUserCredentials());
    assertNotNull(userB.getUserCredentials().getUser().getUserCredentials());
    assertEquals("admin", userA.getUserCredentials().getUser().getUserCredentials().getUsername());
    assertEquals("admin", userB.getUserCredentials().getUser().getUserCredentials().getUsername());
}
Also used : User(org.hisp.dhis.user.User) 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) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 88 with IdentifiableObject

use of org.hisp.dhis.common.IdentifiableObject in project dhis2-core by dhis2.

the class ObjectBundleServiceUserTest method testCreateUsers.

@Test
public void testCreateUsers() throws IOException {
    createUserAndInjectSecurityContext(true);
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/users.json").getInputStream(), RenderFormat.JSON);
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.COMMIT);
    params.setImportStrategy(ImportStrategy.CREATE);
    params.setAtomicMode(AtomicMode.NONE);
    params.setObjects(metadata);
    ObjectBundle bundle = objectBundleService.create(params);
    ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
    assertEquals(1, validate.getErrorReportsByCode(UserAuthorityGroup.class, ErrorCode.E5003).size());
    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");
    assertNotNull(userA);
    assertNotNull(userB);
    assertNotNull(userA.getUserCredentials().getUserInfo());
    assertNotNull(userB.getUserCredentials().getUserInfo());
    assertNotNull(userA.getUserCredentials().getUserInfo().getUserCredentials());
    assertNotNull(userB.getUserCredentials().getUserInfo().getUserCredentials());
    assertEquals("UserA", userA.getUserCredentials().getUserInfo().getUserCredentials().getUsername());
    assertEquals("UserB", userB.getUserCredentials().getUserInfo().getUserCredentials().getUsername());
    assertNotNull(userA.getUserCredentials().getUser());
    assertNotNull(userB.getUserCredentials().getUser());
    assertNotNull(userA.getUserCredentials().getUser().getUserCredentials());
    assertNotNull(userB.getUserCredentials().getUser().getUserCredentials());
    assertEquals("admin", userA.getUserCredentials().getUser().getUserCredentials().getUsername());
    assertEquals("admin", userB.getUserCredentials().getUser().getUserCredentials().getUsername());
    assertEquals(1, userA.getOrganisationUnits().size());
    assertEquals(1, userB.getOrganisationUnits().size());
}
Also used : User(org.hisp.dhis.user.User) 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) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 89 with IdentifiableObject

use of org.hisp.dhis.common.IdentifiableObject in project dhis2-core by dhis2.

the class ObjectBundleServiceUserTest method testCreateUsersWithInvalidPasswords.

@Test
public void testCreateUsersWithInvalidPasswords() throws IOException {
    createUserAndInjectSecurityContext(true);
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/users_passwords.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);
    assertEquals(1, validate.getErrorReportsByCode(User.class, ErrorCode.E4005).size());
}
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) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 90 with IdentifiableObject

use of org.hisp.dhis.common.IdentifiableObject in project dhis2-core by dhis2.

the class I18nAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    className = className != null && CLASS_ALIAS.containsKey(className) ? CLASS_ALIAS.get(className) : className;
    currentLocale = (Locale) userSettingService.getUserSetting(UserSettingKey.DB_LOCALE);
    availableLocales = i18nLocaleService.getAllLocales();
    IdentifiableObject object = identifiableObjectManager.getObject(uid, className);
    translations = TranslationUtils.convertTranslations(object.getTranslations(), currentLocale);
    referenceTranslations = TranslationUtils.getObjectPropertyValues(object);
    propertyNames = TranslationUtils.getObjectPropertyNames(object);
    return SUCCESS;
}
Also used : IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

Aggregations

IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)124 List (java.util.List)76 Test (org.junit.Test)67 DhisSpringTest (org.hisp.dhis.DhisSpringTest)64 ClassPathResource (org.springframework.core.io.ClassPathResource)54 DataElement (org.hisp.dhis.dataelement.DataElement)44 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)39 User (org.hisp.dhis.user.User)37 DataSet (org.hisp.dhis.dataset.DataSet)24 ArrayList (java.util.ArrayList)22 ObjectReport (org.hisp.dhis.feedback.ObjectReport)22 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)22 Schema (org.hisp.dhis.schema.Schema)19 HashMap (java.util.HashMap)18 TypeReport (org.hisp.dhis.feedback.TypeReport)18 Set (java.util.Set)15 ErrorReport (org.hisp.dhis.feedback.ErrorReport)15 PreheatErrorReport (org.hisp.dhis.preheat.PreheatErrorReport)15 Map (java.util.Map)14 Property (org.hisp.dhis.schema.Property)13