Commit ea7577b4 authored by michael.simon's avatar michael.simon
Browse files

Merge remote-tracking branch 'origin/68-add-projects' into branch-2.7

parents c286baf8 bbc0cde5
......@@ -41,4 +41,5 @@ public interface BaseDao<T extends BaseEntity<PK>, PK extends Serializable> {
void refresh(T entity);
List<T> findByMultipleId(List<PK> ids);
}
......@@ -42,6 +42,8 @@ public interface ServiceDao extends BaseDao<ServiceEntity, Long> {
List<ServiceEntity> findByParentService(ServiceEntity service);
List<ServiceEntity> findByProjectAdminRole(RoleEntity role);
List<ServiceEntity> findBySshPubKeyApproverRole(RoleEntity role);
}
......@@ -22,6 +22,7 @@ import javax.persistence.NoResultException;
import javax.persistence.Query;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaBuilder.In;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.JoinType;
import javax.persistence.criteria.Order;
......@@ -143,6 +144,24 @@ public abstract class JpaBaseDao<T extends BaseEntity<PK>, PK extends Serializab
return em.contains(entity);
}
@Override
public List<T> findByMultipleId(List<PK> ids) {
if (ids.size() == 0)
return new ArrayList<T>();
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<T> criteria = builder.createQuery(getEntityClass());
Root<T> entity = criteria.from(getEntityClass());
In<Object> inClause = builder.in(entity.get("id"));
for (Object id : ids) {
inClause.value(id);
}
criteria.where(inClause);
criteria.select(entity);
return em.createQuery(criteria).getResultList();
}
@Override
public T findByIdWithAttrs(PK id, String... attrs) {
CriteriaBuilder builder = em.getCriteriaBuilder();
......
......@@ -94,6 +94,13 @@ public class JpaServiceDao extends JpaBaseDao<ServiceEntity, Long> implements Se
return em.createQuery("select e from ServiceEntity e where e.groupAdminRole = :role")
.setParameter("role", role).getResultList();
}
@Override
@SuppressWarnings({"unchecked"})
public List<ServiceEntity> findByProjectAdminRole(RoleEntity role) {
return em.createQuery("select e from ServiceEntity e where e.projectAdminRole = :role")
.setParameter("role", role).getResultList();
}
@Override
@SuppressWarnings({"unchecked"})
......
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.dao.jpa.project;
import java.util.List;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.JoinType;
import javax.persistence.criteria.Root;
import edu.kit.scc.webreg.dao.jpa.JpaBaseDao;
import edu.kit.scc.webreg.dao.project.ProjectAdminRoleDao;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.project.ProjectAdminRoleEntity;
@Named
@ApplicationScoped
public class JpaProjectAdminRoleDao extends JpaBaseDao<ProjectAdminRoleEntity, Long> implements ProjectAdminRoleDao {
@Override
public List<ProjectAdminRoleEntity> findWithServices(UserEntity user) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<ProjectAdminRoleEntity> criteria = builder.createQuery(ProjectAdminRoleEntity.class);
Root<ProjectAdminRoleEntity> root = criteria.from(ProjectAdminRoleEntity.class);
Root<UserEntity> userRoot = criteria.from(UserEntity.class);
CriteriaQuery<ProjectAdminRoleEntity> select = criteria.select(root);
select.where(builder.equal(userRoot.get("id"), user.getId())).distinct(true);
root.fetch("adminForServices", JoinType.LEFT);
return em.createQuery(select).getResultList();
}
@Override
public ProjectAdminRoleEntity findWithUsers(Long id) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<ProjectAdminRoleEntity> criteria = builder.createQuery(ProjectAdminRoleEntity.class);
Root<ProjectAdminRoleEntity> root = criteria.from(ProjectAdminRoleEntity.class);
criteria.where(
builder.equal(root.get("id"), id));
criteria.select(root);
root.fetch("users", JoinType.LEFT);
return em.createQuery(criteria).getSingleResult();
}
@Override
public ProjectAdminRoleEntity findByName(String name) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<ProjectAdminRoleEntity> criteria = builder.createQuery(ProjectAdminRoleEntity.class);
Root<ProjectAdminRoleEntity> role = criteria.from(ProjectAdminRoleEntity.class);
criteria.where(
builder.equal(role.get("name"), name));
criteria.select(role);
return em.createQuery(criteria).getSingleResult();
}
@Override
public Class<ProjectAdminRoleEntity> getEntityClass() {
return ProjectAdminRoleEntity.class;
}
}
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.dao.jpa.project;
import java.util.List;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;
import edu.kit.scc.webreg.dao.jpa.JpaBaseDao;
import edu.kit.scc.webreg.dao.project.ProjectDao;
import edu.kit.scc.webreg.entity.ServiceEntity;
import edu.kit.scc.webreg.entity.project.ProjectEntity;
import edu.kit.scc.webreg.entity.project.ProjectServiceEntity;
import edu.kit.scc.webreg.entity.project.ProjectServiceType;
@Named
@ApplicationScoped
public class JpaProjectDao extends JpaBaseDao<ProjectEntity, Long> implements ProjectDao {
@SuppressWarnings("unchecked")
@Override
public List<ProjectEntity> findByService(ServiceEntity service) {
return em.createQuery("select r.project from ProjectServiceEntity r where r.service = :service order by r.project.name")
.setParameter("service", service).getResultList();
}
@Override
public ProjectServiceEntity addServiceToProject(ProjectEntity project, ServiceEntity service, ProjectServiceType type) {
ProjectServiceEntity entity = new ProjectServiceEntity();
entity.setProject(project);
entity.setService(service);
entity.setType(type);
em.persist(entity);
return entity;
}
@Override
public Class<ProjectEntity> getEntityClass() {
return ProjectEntity.class;
}
}
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.dao.project;
import java.util.List;
import edu.kit.scc.webreg.dao.BaseDao;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.project.ProjectAdminRoleEntity;
public interface ProjectAdminRoleDao extends BaseDao<ProjectAdminRoleEntity, Long> {
ProjectAdminRoleEntity findByName(String name);
ProjectAdminRoleEntity findWithUsers(Long id);
List<ProjectAdminRoleEntity> findWithServices(UserEntity user);
}
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.dao.project;
import java.util.List;
import edu.kit.scc.webreg.dao.BaseDao;
import edu.kit.scc.webreg.entity.ServiceEntity;
import edu.kit.scc.webreg.entity.project.ProjectEntity;
import edu.kit.scc.webreg.entity.project.ProjectServiceEntity;
import edu.kit.scc.webreg.entity.project.ProjectServiceType;
public interface ProjectDao extends BaseDao<ProjectEntity, Long> {
List<ProjectEntity> findByService(ServiceEntity service);
ProjectServiceEntity addServiceToProject(ProjectEntity project, ServiceEntity service, ProjectServiceType type);
}
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.dao.project;
import java.util.List;
import edu.kit.scc.webreg.dao.BaseDao;
import edu.kit.scc.webreg.entity.ServiceEntity;
import edu.kit.scc.webreg.entity.project.ProjectEntity;
public interface ProjectServiceDao extends BaseDao<ProjectEntity, Long> {
List<ProjectEntity> findByService(ServiceEntity service);
}
......@@ -30,6 +30,7 @@ import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.Type;
import edu.kit.scc.webreg.entity.as.AttributeSourceServiceEntity;
import edu.kit.scc.webreg.entity.project.ProjectAdminRoleEntity;
@Entity(name = "ServiceEntity")
@Table(name = "service")
......@@ -314,5 +315,4 @@ public class ServiceEntity extends AbstractBaseEntity {
public void setSshPubKeyApproverRole(SshPubKeyApproverRoleEntity sshPubKeyApproverRole) {
this.sshPubKeyApproverRole = sshPubKeyApproverRole;
}
}
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.entity.project;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import edu.kit.scc.webreg.entity.ServiceEntity;
@Entity(name = "ProjectServiceEntity")
@Table(name = "project_service")
public class ProjectServiceEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@ManyToOne(targetEntity = ServiceEntity.class)
@JoinColumn(name = "service_id", nullable = false)
private ServiceEntity service;
@Id
@ManyToOne(targetEntity = ProjectEntity.class)
@JoinColumn(name = "project_id", nullable = false)
private ProjectEntity project;
@Enumerated(EnumType.STRING)
private ProjectServiceType type;
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((project == null) ? 0 : project.hashCode());
result = prime * result + ((service == null) ? 0 : service.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ProjectServiceEntity other = (ProjectServiceEntity) obj;
if (project == null) {
if (other.project != null)
return false;
} else if (!project.equals(other.project))
return false;
if (service == null) {
if (other.service != null)
return false;
} else if (!service.equals(other.service))
return false;
return true;
}
public ProjectEntity getProject() {
return project;
}
public void setProject(ProjectEntity project) {
this.project = project;
}
public ServiceEntity getService() {
return service;
}
public void setService(ServiceEntity service) {
this.service = service;
}
public ProjectServiceType getType() {
return type;
}
public void setType(ProjectServiceType type) {
this.type = type;
}
}
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.entity.project;
public enum ProjectServiceType {
ADMIN,
READ_WRITE,
READ_ONLY
}
......@@ -38,4 +38,5 @@ public interface BaseService<T extends BaseEntity<PK>, PK extends Serializable>
Number countAll(Map<String, Object> filterMap);
List<T> findByMultipleId(List<PK> ids);
}
......@@ -44,4 +44,5 @@ public interface ServiceService extends BaseService<ServiceEntity, Long> {
List<ServiceEntity> findBySshPubKeyApproverRole(RoleEntity role);
List<ServiceEntity> findByProjectAdminRole(RoleEntity role);
}
......@@ -66,6 +66,11 @@ public abstract class BaseServiceImpl<T extends BaseEntity<PK>, PK extends Seria
return getDao().findById(id);
}
@Override
public List<T> findByMultipleId(List<PK> ids) {
return getDao().findByMultipleId(ids);
}
@Override
public T findByIdWithAttrs(PK id, String...attrs) {
return getDao().findByIdWithAttrs(id, attrs);
......
......@@ -94,6 +94,11 @@ public class ServiceServiceImpl extends BaseServiceImpl<ServiceEntity, Long> imp
return dao.findByGroupAdminRole(role);
}
@Override
public List<ServiceEntity> findByProjectAdminRole(RoleEntity role) {
return dao.findByProjectAdminRole(role);
}
@Override
public List<ServiceEntity> findAllWithPolicies() {
return dao.findAllWithPolicies();
......
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.service.project;
import java.util.List;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.project.ProjectAdminRoleEntity;
import edu.kit.scc.webreg.service.BaseService;
public interface ProjectAdminRoleService extends BaseService<ProjectAdminRoleEntity, Long> {
ProjectAdminRoleEntity findByName(String name);
ProjectAdminRoleEntity findWithUsers(Long id);
List<ProjectAdminRoleEntity> findWithServices(UserEntity user);
}
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.service.project;
import java.util.List;
import javax.ejb.Stateless;
import javax.inject.Inject;
import edu.kit.scc.webreg.dao.BaseDao;
import edu.kit.scc.webreg.dao.project.ProjectAdminRoleDao;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.project.ProjectAdminRoleEntity;
import edu.kit.scc.webreg.service.impl.BaseServiceImpl;
@Stateless
public class ProjectAdminRoleServiceImpl extends BaseServiceImpl<ProjectAdminRoleEntity, Long> implements ProjectAdminRoleService {
private static final long serialVersionUID = 1L;
@Inject
private ProjectAdminRoleDao dao;
@Override
public List<ProjectAdminRoleEntity> findWithServices(UserEntity user) {
return dao.findWithServices(user);
}
@Override
public ProjectAdminRoleEntity findWithUsers(Long id) {
return dao.findWithUsers(id);
}
@Override
public ProjectAdminRoleEntity findByName(String name) {
return dao.findByName(name);
}
@Override
protected BaseDao<ProjectAdminRoleEntity, Long> getDao() {
return dao;
}
}
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.service.project;
import java.util.List;
import edu.kit.scc.webreg.entity.ServiceEntity;
import edu.kit.scc.webreg.entity.project.ProjectEntity;
import edu.kit.scc.webreg.service.BaseService;
public interface ProjectService extends BaseService<ProjectEntity, Long> {
List<ProjectEntity> findByService(ServiceEntity service);
ProjectEntity save(ProjectEntity project, ServiceEntity... services);
}
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.service.project;
import java.util.List;
import javax.ejb.Stateless;
import javax.inject.Inject;
import edu.kit.scc.webreg.dao.BaseDao;
import edu.kit.scc.webreg.dao.project.ProjectDao;
import edu.kit.scc.webreg.entity.ServiceEntity;
import edu.kit.scc.webreg.entity.project.ProjectEntity;
import edu.kit.scc.webreg.entity.project.ProjectServiceType;