Example #1
0
  public List<Experiment> getSharedExperiments(User user) {
    String queryString = "from User u inner join fetch u.experiments where u.username=:username";
    Query query = dao.getEntityManager().createQuery(queryString);
    query.setParameter("username", user.getUsername());
    @SuppressWarnings("unchecked")
    List<User> users = query.getResultList();
    List<Experiment> experiments = new ArrayList<Experiment>();
    for (User userSingleE : users) {
      Object[] userExperiments = userSingleE.getExperiments().toArray();
      for (Object o : userExperiments) {
        Experiment e = (Experiment) o;
        boolean have = false;
        for (Experiment currentE : experiments) {
          if (currentE.getId() == e.getId()) have = true;
        }
        if (!have) experiments.add(e);
      }
    }

    // get experiments shared with all
    queryString = "from Experiment where shareWithAll=:shareWithAll";
    query = dao.getEntityManager().createQuery(queryString);
    query.setParameter("shareWithAll", true);
    @SuppressWarnings("unchecked")
    List<Object> experimentsSharedWithAll = query.getResultList();
    for (Object o : experimentsSharedWithAll) {
      experiments.add((Experiment) o);
    }

    for (Experiment experiment : experiments) {
      experiment.setNumDataSets(getNumDataSets(experiment));
    }

    return experiments;
  }
Example #2
0
  public void permitted(User user, Integer experimentId) throws SecurityException {
    Experiment experiment = (Experiment) dao.get(Experiment.class.getName(), "id", experimentId);

    if (experiment.getOwner().equals(user) || experiment.userAllowed(user)) {
      user.setCurrentExperiment(experiment);
      User loadedUser = (User) dao.get(User.class.getName(), "username", user.getUsername());
      loadedUser.setCurrentExperiment(experiment);
      dao.update(loadedUser);
    } else {
      throw new SecurityException(
          "You do not have permission to view the experiment: " + experiment.getName());
    }
  }
Example #3
0
 public void clearSharedList(Experiment experiment) {
   List<User> userList = new ArrayList<User>();
   for (User user : experiment.getSharedList()) {
     userList.add(user);
   }
   for (User user : userList) {
     if (user.getExperiments() != null) {
       user.getExperiments().remove(experiment);
       dao.update(user);
       dao.getEntityManager().flush();
     }
   }
   experiment.getSharedList().clear();
   dao.update(experiment);
   updateActivity(experiment);
   dao.getEntityManager().flush();
 }
Example #4
0
 @SuppressWarnings("unchecked")
 public List<Experiment> getMyExperiments(User user) {
   String queryString = "from Experiment e where e.owner.username=:username";
   Query query = dao.getEntityManager().createQuery(queryString);
   query.setParameter("username", user.getUsername());
   List<Experiment> experiments = query.getResultList();
   for (Experiment experiment : experiments) {
     experiment.setNumDataSets(getNumDataSets(experiment));
   }
   return experiments;
 }
Example #5
0
  public String execute() {
    getUser().setFullName(userToEdit.getFullName());
    getUser().setEmail(userToEdit.getEmail());
    getUser().setInstitution(userToEdit.getInstitution());
    getUser().setResearchInterest(userToEdit.getResearchInterest());
    getUser().setShowEmail(userToEdit.getShowEmail());
    if (file != null && filename != null) {
      if (contentType.equals("image/jpeg")
          || contentType.equals("image/gif")
          || contentType.equals("image/png")) {
        try {
          Photo photo = photoService.createPhoto(file);
          getUser().setPhoto(photo);
          System.out.println("Set photo");
        } catch (IOException e) {
          log.info(e);
          addFieldError("uploadFile", "Oops, the photo upload failed for some reason");
        }
      } else {
        addFieldError("uploadFile", "Photo must be a jpeg, png, or gif");
        log.info("Uploaded invalid photo file: " + filename);
      }
    }
    if (userToEdit.getPassword() != null && userToEdit.getPassword().trim().length() > 0) {
      if (!userToEdit.getPassword().equals(passwordConfirm)) {
        addFieldError("userToEdit.password", "Passwords do not match");
        log.debug("Mismatched passwords");
        return ERROR;
      }
      getUser().setPassword(getUserToEdit().getPassword().trim());
      try {
        getUser().encryptPassword();
      } catch (NoSuchAlgorithmException e) {
        log.error(e.getMessage());
        addFieldError("userToEdit.password", "Failed to encrypt password");
        return ERROR;
      }
    }

    userDAO.update(getUser());
    return SUCCESS;
  }