List of usage examples for org.hibernate.criterion Restrictions and
public static LogicalExpression and(Criterion lhs, Criterion rhs)
From source file:models.db.acentera.impl.ProjectImpl.java
License:Open Source License
public static UserProjects getUserProject(Long projectId, User u) { Session s = (Session) HibernateSessionFactory.getSession(); Criteria criteria = s.createCriteria(UserProjects.class); UserProjects userProject = (UserProjects) criteria .add(Restrictions.and(Restrictions.eq("user", u), Restrictions.eq("project.id", projectId))) .uniqueResult();/*from w ww. j a v a 2s.com*/ return userProject; }
From source file:models.db.acentera.impl.ProjectImpl.java
License:Open Source License
public static UserProjects getUserProject(Long projectId, Long userId) { Session s = (Session) HibernateSessionFactory.getSession(); Criteria criteria = s.createCriteria(UserProjects.class); Logger.debug("USER PROJECT AAA"); /* need to investigate*/ UserProjects userProject = (UserProjects) criteria .add(Restrictions.and(Restrictions.eq("user.id", userId), Restrictions.eq("project.id", projectId))) .uniqueResult();// ww w . j av a 2s. co m Logger.debug("USER PROJECT BB"); /* List<UserProjects> userProject = (List<UserProjects>) criteria.add(Restrictions.and( Restrictions.eq("project.id", projectId) )).list(); UserProjects up = null; Iterator<UserProjects> itr = userProject.iterator(); while(itr.hasNext() && up == null) { UserProjects tmpUp = itr.next(); if (tmpUp.getUser().getId().longValue() == userId) { up = tmpUp; } } */ return userProject; }
From source file:models.db.acentera.impl.ProjectImpl.java
License:Open Source License
public static ProjectQuota createProjectQuota(Long projectId, User u, JSONObject data) { Session s = (Session) HibernateSessionFactory.getSession(); Criteria criteria = s.createCriteria(UserProjects.class); UserProjects userProject = (UserProjects) criteria .add(Restrictions.and(Restrictions.eq("user", u), Restrictions.eq("project.id", projectId))) .uniqueResult();// w ww . j a va2s .c o m //TODO: Check that the end-user have proper role to execute this operation... if (userProject != null) { //Ok great we have access to this project lets add the new quota.. ProjectQuota quota = new ProjectQuota(); ProjectTags projectTags = ProjectTagsImpl.getOrCreateTags(userProject.getProject(), data.getString("name"), TagConstants.QUOTA); quota.setProjectTags(projectTags); quota.setComputeLimit(data.getInt("compute")); quota.setProjects(userProject.getProject()); if (userProject.getProject().addQuota(quota)) { s.saveOrUpdate(userProject); s.saveOrUpdate(quota); return quota; } } //p.getProviders(); return null; }
From source file:models.db.acentera.impl.ProjectImpl.java
License:Open Source License
public static ProjectQuota createProjectUser(Long projectId, User u, JSONObject data) { Session s = (Session) HibernateSessionFactory.getSession(); Criteria criteria = s.createCriteria(UserProjects.class); UserProjects userProject = (UserProjects) criteria .add(Restrictions.and(Restrictions.eq("user", u), Restrictions.eq("project.id", projectId))) .uniqueResult();//ww w. j a va2s . c om //TODO: Check that the end-user have proper role to execute this operation... if (userProject != null) { //Ok great we have access to this project lets add the new quota.. ProjectQuota quota = new ProjectQuota(); ProjectTags projectTags = ProjectTagsImpl.getOrCreateTags(userProject.getProject(), data.getString("name"), TagConstants.QUOTA); quota.setProjectTags(projectTags); quota.setComputeLimit(data.getInt("compute")); quota.setProjects(userProject.getProject()); if (userProject.getProject().addQuota(quota)) { s.saveOrUpdate(userProject); s.saveOrUpdate(quota); return quota; } } //p.getProviders(); return null; }
From source file:models.db.acentera.impl.ProjectImpl.java
License:Open Source License
public static ProjectProviders getCloudProvider(Long projectId, Long providerId) { Session s = (Session) HibernateSessionFactory.getSession(); Criteria criteria = s.createCriteria(ProjectProviders.class); ProjectProviders provider = (ProjectProviders) criteria .add(Restrictions.and(Restrictions.eq("id", providerId), Restrictions.eq("project.id", projectId))) .uniqueResult();// w w w .j a v a2 s .co m return provider; }
From source file:models.db.acentera.impl.ProjectImpl.java
License:Open Source License
public static ProjectSshKey getProjectSshKey(Long projectId, Long sshKeyId) { Session s = (Session) HibernateSessionFactory.getSession(); Criteria criteria = s.createCriteria(ProjectSshKey.class); ProjectSshKey sshKey = (ProjectSshKey) criteria .add(Restrictions.and(Restrictions.eq("projects.id", projectId), Restrictions.eq("id", sshKeyId))) .uniqueResult();// w w w . j av a 2 s . c o m return sshKey; }
From source file:models.db.acentera.impl.ProjectImpl.java
License:Open Source License
public static boolean deleteProjectSSHKey(Long projectId, Long sshKeyId) { Session s = (Session) HibernateSessionFactory.getSession(); Criteria criteria = s.createCriteria(ProjectSshKey.class); ProjectSshKey sshKey = (ProjectSshKey) criteria .add(Restrictions.and(Restrictions.eq("projects.id", projectId), Restrictions.eq("id", sshKeyId))) .uniqueResult();//www . jav a 2s . com sshKey.disable(); s.update(sshKey); return true; }
From source file:models.db.acentera.impl.ProjectImpl.java
License:Open Source License
public static ProjectSshKey updateProjectSSHKey(Long projectId, Long sshKeyId, JSONObject jsonData) { Session s = (Session) HibernateSessionFactory.getSession(); Criteria criteria = s.createCriteria(ProjectSshKey.class); ProjectSshKey sshKey = (ProjectSshKey) criteria .add(Restrictions.and(Restrictions.eq("projects.id", projectId), Restrictions.eq("id", sshKeyId))) .uniqueResult();/*w ww. ja v a 2s. c om*/ sshKey.setName(jsonData.getString("name")); sshKey.setProjectTags( ProjectTagsImpl.getOrCreateTags(sshKey.getProjects(), jsonData.getString("tag"), TagConstants.KEY)); sshKey.setPublicKey(jsonData.getString("publickey")); s.update(sshKey); return sshKey; }
From source file:models.db.acentera.impl.ProjectImpl.java
License:Open Source License
public static ProjectTasks getProjectTaskById(Long projectId, Long taskId) { Session s = (Session) HibernateSessionFactory.getSession(); Criteria criteria = s.createCriteria(ProjectTasks.class); Logger.debug("get projects.id of : " + projectId); Logger.debug("get task.id of : " + taskId); ProjectTasks task = (ProjectTasks) criteria .add(Restrictions.and(Restrictions.eq("projects.id", projectId), Restrictions.eq("id", taskId))) .uniqueResult();//from w w w.j av a2 s .com Logger.debug("got : " + task); return task; }
From source file:models.db.acentera.impl.ProjectImpl.java
License:Open Source License
public static ProjectProviders getServerCloudProvider(Long projectId, Long serverId, User u) { Session s = (Session) HibernateSessionFactory.getSession(); UserProjects up = getUserProject(projectId, u); Criteria criteria = s.createCriteria(ProjectDevices.class); ProjectDevices projectDevice = (ProjectDevices) criteria .add(Restrictions.and(Restrictions.eq("project", up.getProject()), Restrictions.eq("id", serverId))) .uniqueResult();/*w w w.ja va 2s .c o m*/ return projectDevice.getProviders(); }