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(); }
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(); }
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()); } }
public void updateActivity(Experiment experiment) { experiment.updateActivity(); dao.update(experiment); }