예제 #1
0
  /**
   * Tests the default group of an experimenter.
   *
   * @throws Exception Thrown if an error occurred.
   */
  @Test
  public void testChangeDefaultGroup() throws Exception {
    // Create 2 groups and add a user
    String uuid1 = UUID.randomUUID().toString();
    ExperimenterGroup g1 = new ExperimenterGroupI();
    g1.setName(omero.rtypes.rstring(uuid1));
    g1.getDetails().setPermissions(new PermissionsI("rw----"));

    String uuid2 = UUID.randomUUID().toString();
    ExperimenterGroup g2 = new ExperimenterGroupI();
    g2.setName(omero.rtypes.rstring(uuid2));
    g2.getDetails().setPermissions(new PermissionsI("rw----"));

    IAdminPrx svc = root.getSession().getAdminService();
    IQueryPrx query = root.getSession().getQueryService();
    long id1 = svc.createGroup(g1);
    long id2 = svc.createGroup(g2);

    ParametersI p = new ParametersI();
    p.addId(id1);

    ExperimenterGroup eg1 =
        (ExperimenterGroup)
            query.findByQuery("select distinct g from ExperimenterGroup g where g.id = :id", p);
    p = new ParametersI();
    p.addId(id2);

    ExperimenterGroup eg2 =
        (ExperimenterGroup)
            query.findByQuery("select distinct g from ExperimenterGroup g where g.id = :id", p);
    Experimenter e = new ExperimenterI();
    e.setOmeName(omero.rtypes.rstring(uuid1));
    e.setFirstName(omero.rtypes.rstring("user"));
    e.setLastName(omero.rtypes.rstring("user"));

    List<ExperimenterGroup> groups = new ArrayList<ExperimenterGroup>();
    // method tested elsewhere
    ExperimenterGroup userGroup = svc.lookupGroup(USER_GROUP);
    groups.add(eg1);
    groups.add(eg2);
    groups.add(userGroup);

    long id = svc.createExperimenter(e, eg1, groups);
    e = svc.lookupExperimenter(uuid1);
    List<GroupExperimenterMap> links = e.copyGroupExperimenterMap();
    assertTrue(groups.get(0).getId().getValue() == eg1.getId().getValue());
    svc.setDefaultGroup(e, eg2);

    e = svc.lookupExperimenter(uuid1);
    links = e.copyGroupExperimenterMap();
    groups = new ArrayList<ExperimenterGroup>();
    for (GroupExperimenterMap link : links) {
      groups.add(link.getParent());
    }
    assertTrue(groups.get(0).getId().getValue() == eg2.getId().getValue());
  }
예제 #2
0
  /**
   * Tests the deletion of an experimenter.
   *
   * @throws Exception Thrown if an error occurred.
   */
  @Test
  public void testDeleteExperimenter() throws Exception {
    // First create a new user.
    String uuid = UUID.randomUUID().toString();
    Experimenter e = new ExperimenterI();
    e.setOmeName(omero.rtypes.rstring(uuid));
    e.setFirstName(omero.rtypes.rstring("user"));
    e.setLastName(omero.rtypes.rstring("user"));
    IAdminPrx svc = root.getSession().getAdminService();

    // already tested
    ExperimenterGroup g = new ExperimenterGroupI();
    g.setName(omero.rtypes.rstring(uuid));
    g.getDetails().setPermissions(new PermissionsI("rw----"));

    // create group.
    svc.createGroup(g);
    long id = svc.createUser(e, uuid);
    e = svc.lookupExperimenter(uuid);
    svc.deleteExperimenter(e);
    ParametersI p = new ParametersI();
    p.addId(id);
    IQueryPrx query = root.getSession().getQueryService();
    e =
        (Experimenter)
            query.findByQuery("select distinct e from Experimenter e where e.id = :id", p);
    assertNull(e);
  }
예제 #3
0
 /**
  * Tests the creation of a group with permission <code>rwrw--</code>.
  *
  * @throws Exception Thrown if an error occurred.
  */
 @Test
 public void testCreateGroupRWRW() throws Exception {
   String uuid = UUID.randomUUID().toString();
   ExperimenterGroup g = new ExperimenterGroupI();
   g.setName(omero.rtypes.rstring(uuid));
   g.getDetails().setPermissions(new PermissionsI("rwrw--"));
   IAdminPrx svc = root.getSession().getAdminService();
   long id = svc.createGroup(g);
   // Load the group
   IQueryPrx query = root.getSession().getQueryService();
   ParametersI p = new ParametersI();
   p.addId(id);
   ExperimenterGroup eg =
       (ExperimenterGroup)
           query.findByQuery("select distinct g from ExperimenterGroup g where g.id = :id", p);
   assertNotNull(eg);
   assertTrue(eg.getName().getValue().equals(uuid));
   // test permissions
   Permissions perms = eg.getDetails().getPermissions();
   assertTrue(perms.isUserRead());
   assertTrue(perms.isUserWrite());
   assertTrue(perms.isGroupRead());
   assertTrue(perms.isGroupWrite());
   assertFalse(perms.isWorldRead());
   assertFalse(perms.isWorldWrite());
 }
예제 #4
0
  /**
   * Tests the update of the details of the user currently logged in using the <code>
   * updateExperimenter</code> method.
   *
   * @throws Exception Thrown if an error occurred.
   */
  @Test(enabled = true)
  public void testUpdateExperimenterByUserUsingUpdateExperimenter() throws Exception {
    // First create a new user.
    String uuid = UUID.randomUUID().toString();
    Experimenter e = new ExperimenterI();
    e.setOmeName(omero.rtypes.rstring(uuid));
    e.setFirstName(omero.rtypes.rstring("user"));
    e.setLastName(omero.rtypes.rstring("user"));
    IAdminPrx svc = root.getSession().getAdminService();

    // already tested
    ExperimenterGroup g = new ExperimenterGroupI();
    g.setName(omero.rtypes.rstring(uuid));
    g.getDetails().setPermissions(new PermissionsI("rw----"));

    // create group.
    svc.createGroup(g);

    long id = svc.createUser(e, uuid);
    IQueryPrx query = root.getSession().getQueryService();
    ParametersI p = new ParametersI();
    p.addId(id);
    e =
        (Experimenter)
            query.findByQuery("select distinct e from Experimenter e where e.id = :id", p);
    assertNotNull(e);

    String name = "userModified";
    // uuid = UUID.randomUUID().toString();
    e.setOmeName(omero.rtypes.rstring(uuid));
    e.setFirstName(omero.rtypes.rstring(name));
    e.setLastName(omero.rtypes.rstring(name));
    //
    // owner logs in.
    omero.client client = newOmeroClient();
    client.createSession(uuid, uuid);
    init(client);
    iAdmin.updateExperimenter(e);
    e =
        (Experimenter)
            query.findByQuery("select distinct e from Experimenter e where e.id = :id", p);
    assertNotNull(e);
    assertTrue(e.getOmeName().getValue().equals(uuid));
    assertTrue(e.getFirstName().getValue().equals(name));
    assertTrue(e.getLastName().getValue().equals(name));
  }
예제 #5
0
  /**
   * Tests the creation of a user using the <code>createUser</code> method.
   *
   * @throws Exception Thrown if an error occurred.
   */
  @Test
  public void testCreateUser() throws Exception {
    String uuid = UUID.randomUUID().toString();
    Experimenter e = new ExperimenterI();
    e.setOmeName(omero.rtypes.rstring(uuid));
    e.setFirstName(omero.rtypes.rstring("user"));
    e.setLastName(omero.rtypes.rstring("user"));
    IAdminPrx svc = root.getSession().getAdminService();

    // already tested
    ExperimenterGroup g = new ExperimenterGroupI();
    g.setName(omero.rtypes.rstring(uuid));
    g.getDetails().setPermissions(new PermissionsI("rw----"));
    long groupId = svc.createGroup(g);

    long id = svc.createUser(e, uuid);
    IQueryPrx query = root.getSession().getQueryService();

    // Check if we have a user
    ParametersI p = new ParametersI();
    p.addId(id);
    e =
        (Experimenter)
            query.findByQuery("select distinct e from Experimenter e where e.id = :id", p);
    assertNotNull(e);
    assertTrue(e.getOmeName().getValue().equals(uuid));
    // check if we are in the correct group i.e. user and uuid
    // now check if the user is in correct groups.
    ExperimenterGroup userGroup = svc.lookupGroup(USER_GROUP);
    List<Long> ids = new ArrayList<Long>();
    ids.add(groupId);
    ids.add(userGroup.getId().getValue());
    p = new ParametersI();
    p.addLongs("gids", ids);
    List list =
        (List)
            query.findAllByQuery(
                "select m "
                    + "from GroupExperimenterMap as m "
                    + "left outer join fetch m.child "
                    + "left outer join fetch m.parent"
                    + " where m.parent.id in (:gids)",
                p);
    assertNotNull(list);
    Iterator i = list.iterator();
    GroupExperimenterMap geMap;
    int count = 0;
    while (i.hasNext()) {
      geMap = (GroupExperimenterMap) i.next();
      if (geMap.getChild().getId().getValue() == id) count++;
    }
    assertTrue(count == 2);
  }
예제 #6
0
  /**
   * Retrieve the log file.
   *
   * @param id The id of the file to load.
   * @param session The OMERO session.
   * @return See above.
   * @throws Throwable Thrown if an error occurred while loading file.
   */
  private File retrieveLogFile(Long id, ServiceFactoryPrx session) throws Throwable {
    if (id == null) return null;
    // dowload the file
    StringBuffer buf = new StringBuffer();
    buf.append("importLog_");
    buf.append(id);
    File logfile = File.createTempFile(buf.toString(), ".log");
    logfile.deleteOnExit();
    IQueryPrx svc = session.getQueryService();
    ParametersI param = new ParametersI();
    param.map.put("id", omero.rtypes.rlong(id));
    OriginalFile of =
        (OriginalFile) svc.findByQuery("select p from OriginalFile as p where p.id = :id", param);
    if (of == null) return null;

    final String path = logfile.getAbsolutePath();

    RawFileStorePrx store = null;
    try {
      store = session.createRawFileStore();
      store.setFileId(id);
    } catch (Throwable e) {
      store.close();
      return null; // Never reached.
    }
    try {
      long size = -1;
      long offset = 0;
      int INC = 262144;
      FileOutputStream stream = new FileOutputStream(logfile);
      try {
        try {
          size = store.size();
          for (offset = 0; (offset + INC) < size; ) {
            stream.write(store.read(offset, INC));
            offset += INC;
          }
        } finally {
          stream.write(store.read(offset, (int) (size - offset)));
          stream.close();
        }
      } catch (Exception e) {
        log.error("Cannot write log file", e);
        if (stream != null) stream.close();
      }
    } catch (IOException e) {
      log.error("Cannot write log file", e);
    } finally {
      store.close();
    }
    return logfile;
  }