Commit 39866b33 authored by michael.simon's avatar michael.simon
Browse files

Transition from user to identity for projects

parent fddc0921
......@@ -15,4 +15,6 @@ import edu.kit.scc.webreg.entity.identity.IdentityEntity;
public interface IdentityDao extends BaseDao<IdentityEntity, Long> {
IdentityEntity findByUserId(Long userId);
}
......@@ -11,15 +11,30 @@
package edu.kit.scc.webreg.dao.identity;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Named;
import edu.kit.scc.webreg.dao.UserDao;
import edu.kit.scc.webreg.dao.jpa.JpaBaseDao;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.identity.IdentityEntity;
@Named
@ApplicationScoped
public class JpaIdentityDao extends JpaBaseDao<IdentityEntity, Long> implements IdentityDao {
@Inject
private UserDao userDao;
@Override
public IdentityEntity findByUserId(Long userId) {
UserEntity user = userDao.findById(userId);
if (user == null)
return null;
else
return user.getIdentity();
}
@Override
public Class<IdentityEntity> getEntityClass() {
return IdentityEntity.class;
......
......@@ -18,7 +18,10 @@ 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.identity.IdentityEntity;
import edu.kit.scc.webreg.entity.project.ProjectAdminType;
import edu.kit.scc.webreg.entity.project.ProjectEntity;
import edu.kit.scc.webreg.entity.project.ProjectIdentityAdminEntity;
import edu.kit.scc.webreg.entity.project.ProjectServiceEntity;
import edu.kit.scc.webreg.entity.project.ProjectServiceType;
......@@ -33,6 +36,23 @@ public class JpaProjectDao extends JpaBaseDao<ProjectEntity, Long> implements Pr
.setParameter("service", service).getResultList();
}
@SuppressWarnings("unchecked")
@Override
public List<ProjectEntity> findAdminByIdentity(IdentityEntity identity) {
return em.createQuery("select r.project from ProjectIdentityAdminEntity r where r.identity = :identity order by r.project.name")
.setParameter("identity", identity).getResultList();
}
@Override
public ProjectIdentityAdminEntity addAdminToProject(ProjectEntity project, IdentityEntity identity, ProjectAdminType type) {
ProjectIdentityAdminEntity entity = new ProjectIdentityAdminEntity();
entity.setProject(project);
entity.setIdentity(identity);
entity.setType(type);
em.persist(entity);
return entity;
}
@Override
public ProjectServiceEntity addServiceToProject(ProjectEntity project, ServiceEntity service, ProjectServiceType type) {
ProjectServiceEntity entity = new ProjectServiceEntity();
......
......@@ -14,7 +14,10 @@ import java.util.List;
import edu.kit.scc.webreg.dao.BaseDao;
import edu.kit.scc.webreg.entity.ServiceEntity;
import edu.kit.scc.webreg.entity.identity.IdentityEntity;
import edu.kit.scc.webreg.entity.project.ProjectAdminType;
import edu.kit.scc.webreg.entity.project.ProjectEntity;
import edu.kit.scc.webreg.entity.project.ProjectIdentityAdminEntity;
import edu.kit.scc.webreg.entity.project.ProjectServiceEntity;
import edu.kit.scc.webreg.entity.project.ProjectServiceType;
......@@ -24,4 +27,8 @@ public interface ProjectDao extends BaseDao<ProjectEntity, Long> {
ProjectServiceEntity addServiceToProject(ProjectEntity project, ServiceEntity service, ProjectServiceType type);
ProjectIdentityAdminEntity addAdminToProject(ProjectEntity project, IdentityEntity identity, ProjectAdminType type);
List<ProjectEntity> findAdminByIdentity(IdentityEntity identity);
}
/*******************************************************************************
* 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 ProjectAdminType {
OWNER,
ADMIN,
READ_WRITE,
READ,
}
......@@ -12,6 +12,8 @@ package edu.kit.scc.webreg.entity.project;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
......@@ -49,6 +51,12 @@ public class ProjectEntity extends AbstractBaseEntity {
@Column(name = "short_description", length = 2048)
private String shortDescription;
@Column(name = "sub_projects_allowed")
private Boolean subProjectsAllowed;
@Enumerated(EnumType.STRING)
private ProjectStatus projectStatus;
public String getName() {
return name;
}
......@@ -96,4 +104,20 @@ public class ProjectEntity extends AbstractBaseEntity {
public void setShortDescription(String shortDescription) {
this.shortDescription = shortDescription;
}
public Boolean getSubProjectsAllowed() {
return subProjectsAllowed;
}
public void setSubProjectsAllowed(Boolean subProjectsAllowed) {
this.subProjectsAllowed = subProjectsAllowed;
}
public ProjectStatus getProjectStatus() {
return projectStatus;
}
public void setProjectStatus(ProjectStatus projectStatus) {
this.projectStatus = projectStatus;
}
}
/*******************************************************************************
* 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.identity.IdentityEntity;
@Entity(name = "ProjectIdentityAdminEntity")
@Table(name = "project_admin_identity")
public class ProjectIdentityAdminEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@ManyToOne(targetEntity = IdentityEntity.class)
@JoinColumn(name = "identity_id", nullable = false)
private IdentityEntity identity;
@Id
@ManyToOne(targetEntity = ProjectEntity.class)
@JoinColumn(name = "project_id", nullable = false)
private ProjectEntity project;
@Enumerated(EnumType.STRING)
private ProjectAdminType type;
public ProjectEntity getProject() {
return project;
}
public void setProject(ProjectEntity project) {
this.project = project;
}
public IdentityEntity getIdentity() {
return identity;
}
public void setIdentity(IdentityEntity identity) {
this.identity = identity;
}
public ProjectAdminType getType() {
return type;
}
public void setType(ProjectAdminType type) {
this.type = type;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((identity == null) ? 0 : identity.hashCode());
result = prime * result + ((project == null) ? 0 : project.hashCode());
result = prime * result + ((type == null) ? 0 : type.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;
ProjectIdentityAdminEntity other = (ProjectIdentityAdminEntity) obj;
if (identity == null) {
if (other.identity != null)
return false;
} else if (!identity.equals(other.identity))
return false;
if (project == null) {
if (other.project != null)
return false;
} else if (!project.equals(other.project))
return false;
if (type != other.type)
return false;
return true;
}
}
......@@ -21,6 +21,7 @@ import javax.persistence.ManyToOne;
import javax.persistence.Table;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.identity.IdentityEntity;
@Entity(name = "ProjectMembershipEntity")
@Table(name = "project_membership")
......@@ -31,7 +32,7 @@ public class ProjectMembershipEntity implements Serializable {
@Id
@ManyToOne(targetEntity = UserEntity.class)
@JoinColumn(name = "user_id", nullable = false)
private UserEntity user;
private IdentityEntity identity;
@Id
@ManyToOne(targetEntity = ProjectEntity.class)
......@@ -41,20 +42,29 @@ public class ProjectMembershipEntity implements Serializable {
@Enumerated(EnumType.STRING)
private ProjectMembershipType membershipType;
public UserEntity getUser() {
return user;
public ProjectEntity getProject() {
return project;
}
public void setUser(UserEntity user) {
this.user = user;
public void setProject(ProjectEntity project) {
this.project = project;
}
public ProjectMembershipType getMembershipType() {
return membershipType;
}
public void setMembershipType(ProjectMembershipType membershipType) {
this.membershipType = membershipType;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((identity == null) ? 0 : identity.hashCode());
result = prime * result + ((membershipType == null) ? 0 : membershipType.hashCode());
result = prime * result + ((project == null) ? 0 : project.hashCode());
result = prime * result + ((user == null) ? 0 : user.hashCode());
return result;
}
......@@ -67,32 +77,18 @@ public class ProjectMembershipEntity implements Serializable {
if (getClass() != obj.getClass())
return false;
ProjectMembershipEntity other = (ProjectMembershipEntity) obj;
if (identity == null) {
if (other.identity != null)
return false;
} else if (!identity.equals(other.identity))
return false;
if (membershipType != other.membershipType)
return false;
if (project == null) {
if (other.project != null)
return false;
} else if (!project.equals(other.project))
return false;
if (user == null) {
if (other.user != null)
return false;
} else if (!user.equals(other.user))
return false;
return true;
}
public ProjectEntity getProject() {
return project;
}
public void setProject(ProjectEntity project) {
this.project = project;
}
public ProjectMembershipType getMembershipType() {
return membershipType;
}
public void setMembershipType(ProjectMembershipType membershipType) {
this.membershipType = membershipType;
}
}
......@@ -12,6 +12,5 @@ package edu.kit.scc.webreg.entity.project;
public enum ProjectMembershipType {
OWNER,
MEMBER
}
......@@ -12,7 +12,5 @@ package edu.kit.scc.webreg.entity.project;
public enum ProjectServiceType {
ADMIN,
READ_WRITE,
READ_ONLY
AUTO_REGISTER,
}
/*******************************************************************************
* 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 ProjectStatus {
ACTIVE,
PENDING,
DELETED,
}
......@@ -20,6 +20,8 @@ public interface ProjectService extends BaseService<ProjectEntity, Long> {
List<ProjectEntity> findByService(ServiceEntity service);
ProjectEntity save(ProjectEntity project, ServiceEntity... services);
ProjectEntity save(ProjectEntity project, Long userId);
List<ProjectEntity> findAdminByUserId(Long userId);
}
......@@ -16,10 +16,12 @@ import javax.ejb.Stateless;
import javax.inject.Inject;
import edu.kit.scc.webreg.dao.BaseDao;
import edu.kit.scc.webreg.dao.identity.IdentityDao;
import edu.kit.scc.webreg.dao.project.ProjectDao;
import edu.kit.scc.webreg.entity.ServiceEntity;
import edu.kit.scc.webreg.entity.identity.IdentityEntity;
import edu.kit.scc.webreg.entity.project.ProjectAdminType;
import edu.kit.scc.webreg.entity.project.ProjectEntity;
import edu.kit.scc.webreg.entity.project.ProjectServiceType;
import edu.kit.scc.webreg.service.impl.BaseServiceImpl;
@Stateless
......@@ -27,6 +29,9 @@ public class ProjectServiceImpl extends BaseServiceImpl<ProjectEntity, Long> imp
private static final long serialVersionUID = 1L;
@Inject
private IdentityDao identityDao;
@Inject
private ProjectDao dao;
......@@ -34,13 +39,19 @@ public class ProjectServiceImpl extends BaseServiceImpl<ProjectEntity, Long> imp
public List<ProjectEntity> findByService(ServiceEntity service) {
return dao.findByService(service);
}
@Override
public List<ProjectEntity> findAdminByUserId(Long userId) {
IdentityEntity identity = identityDao.findByUserId(userId);
return dao.findAdminByIdentity(identity);
}
@Override
public ProjectEntity save(ProjectEntity project, ServiceEntity... services) {
public ProjectEntity save(ProjectEntity project, Long userId) {
IdentityEntity identity = identityDao.findByUserId(userId);
project = dao.persist(project);
for (ServiceEntity service : services) {
dao.addServiceToProject(project, service, ProjectServiceType.ADMIN);
}
dao.addAdminToProject(project, identity, ProjectAdminType.OWNER);
return project;
}
......
......@@ -19,10 +19,8 @@ import javax.inject.Inject;
import edu.kit.scc.webreg.entity.ServiceEntity;
import edu.kit.scc.webreg.entity.project.ProjectEntity;
import edu.kit.scc.webreg.exc.NotAuthorizedException;
import edu.kit.scc.webreg.sec.AuthorizationBean;
import edu.kit.scc.webreg.service.ServiceService;
import edu.kit.scc.webreg.service.project.ProjectService;
import edu.kit.scc.webreg.session.SessionManager;
import edu.kit.scc.webreg.util.ViewIds;
@ManagedBean
......@@ -32,40 +30,27 @@ public class ProjectAdminAddProjectBean implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private ProjectService service;
private SessionManager session;
@Inject
private ServiceService serviceService;
@Inject
private AuthorizationBean authBean;
private ProjectService service;
private ProjectEntity entity;
private ServiceEntity serviceEntity;
private Long serviceId;
public void preRenderView(ComponentSystemEvent ev) {
if (serviceEntity == null)
serviceEntity = serviceService.findById(serviceId);
if (! authBean.isUserServiceGroupAdmin(serviceEntity))
throw new NotAuthorizedException("Nicht autorisiert");
if (entity == null)
entity = service.createNew();
}
public String save() {
entity = service.save(entity, serviceEntity);
entity = service.save(entity, session.getUserId());
return ViewIds.PROJECT_ADMIN_INDEX + "?serviceId=" + serviceEntity.getId() + "&faces-redirect=true";
return ViewIds.PROJECT_INDEX + "&faces-redirect=true";
}
public String cancel() {
return ViewIds.PROJECT_ADMIN_INDEX + "?serviceId=" + serviceEntity.getId() + "&faces-redirect=true";
return ViewIds.PROJECT_INDEX + "&faces-redirect=true";
}
public ProjectEntity getEntity() {
......@@ -75,12 +60,4 @@ public class ProjectAdminAddProjectBean implements Serializable {
public void setEntity(ProjectEntity entity) {
this.entity = entity;
}
public Long getServiceId() {
return serviceId;
}
public void setServiceId(Long serviceId) {
this.serviceId = serviceId;
}
}
......@@ -18,12 +18,9 @@ import javax.faces.bean.ViewScoped;
import javax.faces.event.ComponentSystemEvent;
import javax.inject.Inject;
import edu.kit.scc.webreg.entity.ServiceEntity;
import edu.kit.scc.webreg.entity.project.ProjectEntity;
import edu.kit.scc.webreg.exc.NotAuthorizedException;
import edu.kit.scc.webreg.sec.AuthorizationBean;
import edu.kit.scc.webreg.service.ServiceService;
import edu.kit.scc.webreg.service.project.ProjectService;
import edu.kit.scc.webreg.session.SessionManager;
@ManagedBean
@ViewScoped
......@@ -31,47 +28,22 @@ public class ProjectAdminListProjectBean implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private ServiceService serviceService;
@Inject
private ProjectService projectService;
@Inject
private AuthorizationBean authBean;
private ServiceEntity serviceEntity;
private Long serviceId;
@Inject
private SessionManager session;
@Inject
private ProjectService projectService;
private List<ProjectEntity> projectList;
public void preRenderView(ComponentSystemEvent ev) {
if (serviceEntity == null) {
serviceEntity = serviceService.findById(serviceId);
}
}
public List<ProjectEntity> getProjectList() {
if (projectList == null)
projectList = projectService.findByService(serviceEntity);
if (projectList == null) {
projectList = projectService.findAdminByUserId(session.getUserId());
}
return projectList;
}
public ServiceEntity getServiceEntity() {
return serviceEntity;
}