示例#1
0
  /**
   * Some unit tests delete all users. This is a way to restore them. This logic is very similar to
   * logic in HibernateTestSessionFactory afterPropertiesSet function
   */
  protected void restoreDefaultUsers() {

    try {
      // Create an admin user to test admin functions
      UserRole adminRole = new UserRole("admin");

      Set<UserRole.Permission> perms = new HashSet<UserRole.Permission>();
      perms.add(UserRole.Permission.ACCESS_ADMIN);
      perms.add(UserRole.Permission.INGEST_ARTICLE);
      perms.add(UserRole.Permission.MANAGE_FLAGS);
      perms.add(UserRole.Permission.MANAGE_ANNOTATIONS);
      perms.add(UserRole.Permission.MANAGE_USERS);
      perms.add(UserRole.Permission.MANAGE_ROLES);
      perms.add(UserRole.Permission.MANAGE_JOURNALS);
      perms.add(UserRole.Permission.MANAGE_SEARCH);
      perms.add(UserRole.Permission.MANAGE_CACHES);
      perms.add(UserRole.Permission.CROSS_PUB_ARTICLES);
      perms.add(UserRole.Permission.DELETE_ARTICLES);
      perms.add(UserRole.Permission.VIEW_UNPUBBED_ARTICLES);

      adminRole.setPermissions(perms);
      dummyDataStore.store(adminRole);

      UserProfile admin = new UserProfile();
      admin.setAuthId(BaseTest.DEFAULT_ADMIN_AUTHID);
      admin.setEmail("*****@*****.**");
      admin.setDisplayName("testAdmin");
      admin.setPassword("adminPass");
      admin.setRoles(new HashSet<UserRole>(1));
      admin.getRoles().add(adminRole);
      dummyDataStore.store(admin);

      UserRole editorialRole = new UserRole("editorial");
      perms = new HashSet<UserRole.Permission>();
      perms.add(UserRole.Permission.ACCESS_ADMIN);
      perms.add(UserRole.Permission.VIEW_UNPUBBED_ARTICLES);
      editorialRole.setPermissions(perms);
      dummyDataStore.store(editorialRole);

      UserProfile editorial = new UserProfile();
      editorial.setAuthId(BaseTest.DEFAULT_EDITORIAL_AUTHID);
      editorial.setEmail("*****@*****.**");
      editorial.setDisplayName("editorialAdmin");
      editorial.setPassword("pass");
      editorial.setRoles(new HashSet<UserRole>(1));
      editorial.getRoles().add(editorialRole);
      dummyDataStore.store(editorial);

      UserProfile nonAdmin = new UserProfile();
      nonAdmin.setAuthId(BaseTest.DEFAULT_USER_AUTHID);
      nonAdmin.setEmail("*****@*****.**");
      nonAdmin.setDisplayName("testNonAdmin");
      nonAdmin.setPassword("nonAdminPass");
      dummyDataStore.store(nonAdmin);

    } catch (DataAccessException ex) {
      // must've already inserted the users
    }
  }
示例#2
0
 /**
  * Copy fields for updating or display. Does <b>not</b> copy some fields:
  *
  * <ul>
  *   <li>ID: never overwrite IDs on hibernate objects
  *   <li>userAccountUri: these don't come down from display layer, so we don't want to overwrite
  *       with null
  *   <li>userProfileUri: these don't come down from display layer, so we don't want to overwrite
  *       with null
  *   <li>roles: don't want to overwrite a user's roles when updating their profile
  * </ul>
  *
  * @param source
  * @param destination
  */
 private void copyFields(UserProfile source, UserProfile destination) {
   destination.setAuthId(source.getAuthId());
   destination.setRealName(source.getRealName());
   destination.setGivenNames(source.getGivenNames());
   destination.setSurname(source.getSurname());
   destination.setTitle(source.getTitle());
   destination.setGender(source.getGender());
   destination.setEmail(source.getEmail());
   destination.setHomePage(source.getHomePage());
   destination.setWeblog(source.getWeblog());
   destination.setPublications(source.getPublications());
   destination.setDisplayName(source.getDisplayName());
   destination.setSuffix(source.getSuffix());
   destination.setPositionType(source.getPositionType());
   destination.setOrganizationName(source.getOrganizationName());
   destination.setOrganizationType(source.getOrganizationType());
   destination.setPostalAddress(source.getPostalAddress());
   destination.setCity(source.getCity());
   destination.setCountry(source.getCountry());
   destination.setBiography(source.getBiography());
   destination.setInterests(source.getInterests());
   destination.setResearchAreas(source.getResearchAreas());
   destination.setOrganizationVisibility(source.getOrganizationVisibility());
   destination.setAlertsJournals(source.getAlertsJournals());
 }