Esempio n. 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;
  }
Esempio n. 2
0
 public void removeCurrentExperimentFromExperimentables(Experiment experiment) {
   String queryString = "from Experimentable where experiment.id=:experimentId";
   Query query = dao.getEntityManager().createQuery(queryString);
   query.setParameter("experimentId", experiment.getId());
   List<Experimentable> experimentables = query.getResultList();
   for (Experimentable e : experimentables) {
     e.setExperiment(null);
     dao.getEntityManager().merge(e);
   }
 }
Esempio n. 3
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());
    }
  }
Esempio n. 4
0
 public int getNumDataSets(Experiment experiment) {
   String queryString = "SELECT COUNT(ds.id) from DataSet ds where experiment.id=:id";
   Query query = dao.getEntityManager().createQuery(queryString);
   query.setParameter("id", experiment.getId());
   Number result = (Number) query.getSingleResult();
   return result.intValue();
 }
Esempio n. 5
0
 public void removeExperimentFromCopiedTo(Experiment experiment) {
   for (Experimentable experimentable : experiment.getExperimentable()) {
     List<Experiment> newCopiedToList = new ArrayList<Experiment>();
     for (Experiment experimentCopiedTo : experimentable.getCopiedTo()) {
       if (experiment.getId() != experimentCopiedTo.getId()) {
         newCopiedToList.add(experiment);
       }
     }
     experimentable.setCopiedTo(newCopiedToList);
     dao.update(experimentable);
     dao.getEntityManager().flush();
   }
   experiment.setExperimentable(new ArrayList<Experimentable>());
   dao.update(experiment);
   dao.getEntityManager().flush();
 }
Esempio n. 6
0
 public void removeCurrentExperimentFromUsers(Experiment experiment) {
   String queryString =
       "update User u set currentExperiment=null where currentExperiment.id=:experimentId";
   Query query = dao.getEntityManager().createQuery(queryString);
   query.setParameter("experimentId", experiment.getId());
   query.executeUpdate();
 }
Esempio n. 7
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();
 }
Esempio n. 8
0
 public void remove(Experiment experiment) {
   removeCurrentExperimentFromUsers(experiment);
   //    	Experiment result = (Experiment) dao.get(Experiment.class.getName(), "id",
   // experiment.getId());
   //    	dao.remove(result);
   String queryString = "delete from Experiment where id=:experimentId";
   Query query = dao.getEntityManager().createQuery(queryString);
   query.setParameter("experimentId", experiment.getId());
   query.executeUpdate();
 }
Esempio n. 9
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;
 }
Esempio n. 10
0
 public Experiment getExperiment(Integer id) {
   return (Experiment) dao.get(Experiment.class.getName(), "id", id);
 }
Esempio n. 11
0
 public void updateActivity(Experiment experiment) {
   experiment.updateActivity();
   dao.update(experiment);
 }