diff --git a/bwreg-entities/src/main/java/edu/kit/scc/webreg/entity/project/AttributeSourceProjectEntity.java b/bwreg-entities/src/main/java/edu/kit/scc/webreg/entity/project/AttributeSourceProjectEntity.java new file mode 100644 index 0000000000000000000000000000000000000000..c08c2c8bb3a6ed3c8ae6ff5302e0f20a6216cf00 --- /dev/null +++ b/bwreg-entities/src/main/java/edu/kit/scc/webreg/entity/project/AttributeSourceProjectEntity.java @@ -0,0 +1,23 @@ +package edu.kit.scc.webreg.entity.project; + +import javax.persistence.Entity; +import javax.persistence.ManyToOne; + +import edu.kit.scc.webreg.entity.as.AttributeSourceEntity; + +@Entity(name = "AttributeSourceProjectEntity") +public class AttributeSourceProjectEntity extends ExternalProjectEntity { + + private static final long serialVersionUID = 1L; + + @ManyToOne(targetEntity = AttributeSourceEntity.class) + private AttributeSourceEntity attributeSource; + + public AttributeSourceEntity getAttributeSource() { + return attributeSource; + } + + public void setAttributeSource(AttributeSourceEntity attributeSource) { + this.attributeSource = attributeSource; + } +} diff --git a/bwreg-service/src/main/java/edu/kit/scc/webreg/service/project/AttributeSourceProjectService.java b/bwreg-service/src/main/java/edu/kit/scc/webreg/service/project/AttributeSourceProjectService.java new file mode 100644 index 0000000000000000000000000000000000000000..0fb80ba69f0d933320a9fc8bd10e4639e532c44b --- /dev/null +++ b/bwreg-service/src/main/java/edu/kit/scc/webreg/service/project/AttributeSourceProjectService.java @@ -0,0 +1,19 @@ +/* + * ***************************************************************************** + * 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 edu.kit.scc.webreg.entity.project.AttributeSourceProjectEntity; +import edu.kit.scc.webreg.service.BaseService; + +public interface AttributeSourceProjectService extends BaseService<AttributeSourceProjectEntity> { + +} diff --git a/bwreg-service/src/main/java/edu/kit/scc/webreg/service/project/AttributeSourceProjectServiceImpl.java b/bwreg-service/src/main/java/edu/kit/scc/webreg/service/project/AttributeSourceProjectServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..66b7ccd6757c95341c2b9d4604c7dc1f68e65585 --- /dev/null +++ b/bwreg-service/src/main/java/edu/kit/scc/webreg/service/project/AttributeSourceProjectServiceImpl.java @@ -0,0 +1,36 @@ +/* + * ***************************************************************************** + * 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 javax.ejb.Stateless; +import javax.inject.Inject; + +import edu.kit.scc.webreg.dao.BaseDao; +import edu.kit.scc.webreg.dao.project.AttributeSourceProjectDao; +import edu.kit.scc.webreg.entity.project.AttributeSourceProjectEntity; +import edu.kit.scc.webreg.service.impl.BaseServiceImpl; + +@Stateless +public class AttributeSourceProjectServiceImpl extends BaseServiceImpl<AttributeSourceProjectEntity> + implements AttributeSourceProjectService { + + private static final long serialVersionUID = 1L; + + @Inject + private AttributeSourceProjectDao dao; + + @Override + protected BaseDao<AttributeSourceProjectEntity> getDao() { + return dao; + } + +} diff --git a/bwreg-webapp/src/main/java/edu/kit/scc/webreg/bean/admin/as/EditAttributeSourceBean.java b/bwreg-webapp/src/main/java/edu/kit/scc/webreg/bean/admin/as/EditAttributeSourceBean.java index 3ff1224ac522f09d5ebbf85c77384ab20c9d8e59..daa1cfa711eeaae746d531b183450a8b491be4e0 100644 --- a/bwreg-webapp/src/main/java/edu/kit/scc/webreg/bean/admin/as/EditAttributeSourceBean.java +++ b/bwreg-webapp/src/main/java/edu/kit/scc/webreg/bean/admin/as/EditAttributeSourceBean.java @@ -12,16 +12,24 @@ package edu.kit.scc.webreg.bean.admin.as; import java.io.Serializable; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import javax.faces.event.ComponentSystemEvent; import javax.faces.view.ViewScoped; import javax.inject.Inject; import javax.inject.Named; +import org.primefaces.model.DualListModel; +import org.slf4j.Logger; + +import edu.kit.scc.webreg.entity.ServiceEntity; import edu.kit.scc.webreg.entity.as.AttributeSourceEntity; import edu.kit.scc.webreg.entity.as.AttributeSourceEntity_; import edu.kit.scc.webreg.service.AttributeSourceService; +import edu.kit.scc.webreg.service.AttributeSourceServiceService; +import edu.kit.scc.webreg.service.ServiceService; import edu.kit.scc.webreg.util.ViewIds; @Named @@ -30,12 +38,22 @@ public class EditAttributeSourceBean implements Serializable { private static final long serialVersionUID = 1L; + @Inject + private Logger logger; + @Inject private AttributeSourceService service; + @Inject + private AttributeSourceServiceService asseService; + + @Inject + private ServiceService serviceService; + private AttributeSourceEntity entity; private Map<String, String> propertyMap; + private DualListModel<ServiceEntity> serviceList; private String newKey, newValue; @@ -43,14 +61,37 @@ public class EditAttributeSourceBean implements Serializable { public void preRenderView(ComponentSystemEvent ev) { if (entity == null) { - entity = service.findByIdWithAttrs(id, AttributeSourceEntity_.asProps); + entity = service.findByIdWithAttrs(id, AttributeSourceEntity_.asProps, + AttributeSourceEntity_.attributeSourceServices); propertyMap = new HashMap<String, String>(entity.getAsProps()); + + serviceList = new DualListModel<ServiceEntity>(); + serviceList.setSource(entity.getAttributeSourceServices().stream().map(asse -> asse.getService()) + .collect(Collectors.toList())); + serviceList.setTarget(serviceService.findAll().stream().filter(s -> !serviceList.getSource().contains(s)) + .collect(Collectors.toList())); } } public String save() { + List<ServiceEntity> oldList = entity.getAttributeSourceServices().stream().map(asse -> asse.getService()) + .collect(Collectors.toList()); + entity.setAsProps(propertyMap); entity = service.save(entity); + + serviceList.getSource().stream().filter(s -> !oldList.contains(s)).forEach(s -> { + if (logger.isTraceEnabled()) + logger.trace("new on list {}", s.getName()); + asseService.connectService(entity, s); + }); + + oldList.stream().filter(s -> !serviceList.getSource().contains(s)).forEach(s -> { + if (logger.isTraceEnabled()) + logger.trace("remove from list {}", s.getName()); + asseService.disconnectService(entity, s); + }); + return ViewIds.SHOW_ATTRIBUTE_SOURCE + "?faces-redirect=true&id=" + entity.getId(); } @@ -111,4 +152,12 @@ public class EditAttributeSourceBean implements Serializable { public void setEntity(AttributeSourceEntity entity) { this.entity = entity; } + + public DualListModel<ServiceEntity> getServiceList() { + return serviceList; + } + + public void setServiceList(DualListModel<ServiceEntity> serviceList) { + this.serviceList = serviceList; + } } diff --git a/bwreg-webapp/src/main/java/edu/kit/scc/webreg/bean/admin/as/ShowAttributeSourceBean.java b/bwreg-webapp/src/main/java/edu/kit/scc/webreg/bean/admin/as/ShowAttributeSourceBean.java index bb9cfa022979f155de62db18424bc0d708869d07..3b278230aa7cd51aeac99dc5303c44dedd24f824 100644 --- a/bwreg-webapp/src/main/java/edu/kit/scc/webreg/bean/admin/as/ShowAttributeSourceBean.java +++ b/bwreg-webapp/src/main/java/edu/kit/scc/webreg/bean/admin/as/ShowAttributeSourceBean.java @@ -54,7 +54,7 @@ public class ShowAttributeSourceBean implements Serializable { public void preRenderView(ComponentSystemEvent ev) { if (entity == null) { - entity = service.findByIdWithAttrs(id, AttributeSourceEntity_.asProps); + entity = service.findByIdWithAttrs(id, AttributeSourceEntity_.asProps, AttributeSourceEntity_.attributeSourceServices); } } diff --git a/bwreg-webapp/src/main/java/edu/kit/scc/webreg/bean/project/InviteToProjectBean.java b/bwreg-webapp/src/main/java/edu/kit/scc/webreg/bean/project/InviteToProjectBean.java index ec3a753d1713ba7b5f68e3a3fbe2b6bb9a3a44d4..7699a62b1eae31a3b44ffff25428bb0620572687 100644 --- a/bwreg-webapp/src/main/java/edu/kit/scc/webreg/bean/project/InviteToProjectBean.java +++ b/bwreg-webapp/src/main/java/edu/kit/scc/webreg/bean/project/InviteToProjectBean.java @@ -24,14 +24,15 @@ import javax.validation.constraints.NotNull; import edu.kit.scc.webreg.entity.UserEntity; import edu.kit.scc.webreg.entity.identity.IdentityEntity; +import edu.kit.scc.webreg.entity.project.AttributeSourceProjectEntity; import edu.kit.scc.webreg.entity.project.LocalProjectEntity; 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.ProjectInvitationTokenEntity; import edu.kit.scc.webreg.exc.NotAuthorizedException; import edu.kit.scc.webreg.service.UserService; import edu.kit.scc.webreg.service.identity.IdentityService; -import edu.kit.scc.webreg.service.project.LocalProjectService; import edu.kit.scc.webreg.service.project.ProjectInvitationTokenService; import edu.kit.scc.webreg.service.project.ProjectService; import edu.kit.scc.webreg.session.SessionManager; @@ -45,88 +46,88 @@ public class InviteToProjectBean implements Serializable { @Inject private SessionManager session; - - @Inject - private LocalProjectService service; @Inject - private ProjectService projectService; + private ProjectService service; @Inject private ProjectInvitationTokenService tokenService; - + @Inject private FacesMessageGenerator messageGenerator; - + @Inject private IdentityService identityService; - + @Inject private UserService userService; - - private LocalProjectEntity entity; + + private ProjectEntity entity; private List<ProjectInvitationTokenEntity> tokenList; - + private Long id; private List<ProjectIdentityAdminEntity> adminList; private ProjectIdentityAdminEntity adminIdentity; private IdentityEntity identity; - + @Email @NotNull private String rcptMail; - + private String rcptName; private String senderName; private String senderMail; private String customMessage; - + private Set<String> senderEmailList; private Set<String> senderNameList; - + public void preRenderView(ComponentSystemEvent ev) { - + for (ProjectIdentityAdminEntity a : getAdminList()) { if (a.getIdentity().getId().equals(getIdentity().getId())) { adminIdentity = a; break; } } - + if (adminIdentity == null) { throw new NotAuthorizedException("Nicht autorisiert"); - } - else { - if (! (ProjectAdminType.ADMIN.equals(adminIdentity.getType()) || ProjectAdminType.OWNER.equals(adminIdentity.getType()))) { + } else { + if (!(ProjectAdminType.ADMIN.equals(adminIdentity.getType()) + || ProjectAdminType.OWNER.equals(adminIdentity.getType()))) { throw new NotAuthorizedException("Nicht autorisiert"); } } } public void sendToken() { - tokenService.sendEmailToken(getEntity(), getIdentity(), rcptMail, rcptName, senderName, customMessage, "idty-" + session.getIdentityId()); - messageGenerator.addResolvedInfoMessage("project.invite_project.token_send", "project.invite_project.token_send_detail", true); + tokenService.sendEmailToken(getEntity(), getIdentity(), rcptMail, rcptName, senderName, customMessage, + "idty-" + session.getIdentityId()); + messageGenerator.addResolvedInfoMessage("project.invite_project.token_send", + "project.invite_project.token_send_detail", true); tokenList = null; } - + public void deleteToken(ProjectInvitationTokenEntity token) { tokenService.delete(token); - messageGenerator.addResolvedInfoMessage("project.invite_project.token_deleted", "project.invite_project.token_deleted_detail", true); + messageGenerator.addResolvedInfoMessage("project.invite_project.token_deleted", + "project.invite_project.token_deleted_detail", true); tokenList = null; } - + public void resendToken(ProjectInvitationTokenEntity token) { - + } - + public List<ProjectIdentityAdminEntity> getAdminList() { if (adminList == null) { - adminList = projectService.findAdminsForProject(getEntity()); + adminList = service.findAdminsForProject(getEntity()); } return adminList; } - + public Long getId() { return id; } @@ -135,9 +136,13 @@ public class InviteToProjectBean implements Serializable { this.id = id; } - public LocalProjectEntity getEntity() { + public ProjectEntity getEntity() { if (entity == null) { entity = service.findByIdWithAttrs(id); + + if (!(entity instanceof LocalProjectEntity || entity instanceof AttributeSourceProjectEntity)) { + throw new NotAuthorizedException("Nicht autorisiert"); + } } return entity; @@ -151,7 +156,7 @@ public class InviteToProjectBean implements Serializable { if (tokenList == null) { tokenList = tokenService.findAllByAttr("project", getEntity()); } - + return tokenList; } @@ -207,21 +212,21 @@ public class InviteToProjectBean implements Serializable { } return senderNameList; } - + private void fillSenderLists() { List<UserEntity> userList = userService.findByIdentity(getIdentity()); senderEmailList = new HashSet<String>(); senderNameList = new HashSet<String>(); - + for (UserEntity user : userList) { if (user.getEmail() != null) { senderEmailList.add(user.getEmail()); } - + if (user.getEmailAddresses() != null) { senderEmailList.addAll(user.getEmailAddresses()); } - + if (user.getGivenName() != null && user.getSurName() != null) { senderNameList.add(user.getGivenName() + " " + user.getSurName()); } diff --git a/bwreg-webapp/src/main/java/edu/kit/scc/webreg/bean/project/UserShowASProjectBean.java b/bwreg-webapp/src/main/java/edu/kit/scc/webreg/bean/project/UserShowASProjectBean.java new file mode 100644 index 0000000000000000000000000000000000000000..08524ebe1dab110065f9b252a0df52ed02732f68 --- /dev/null +++ b/bwreg-webapp/src/main/java/edu/kit/scc/webreg/bean/project/UserShowASProjectBean.java @@ -0,0 +1,141 @@ +/******************************************************************************* + * 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.bean.project; + +import java.io.Serializable; +import java.util.List; + +import javax.faces.event.ComponentSystemEvent; +import javax.faces.view.ViewScoped; +import javax.inject.Inject; +import javax.inject.Named; + +import edu.kit.scc.webreg.entity.project.AttributeSourceProjectEntity; +import edu.kit.scc.webreg.entity.project.LocalProjectEntity_; +import edu.kit.scc.webreg.entity.project.ProjectAdminType; +import edu.kit.scc.webreg.entity.project.ProjectIdentityAdminEntity; +import edu.kit.scc.webreg.entity.project.ProjectMembershipEntity; +import edu.kit.scc.webreg.entity.project.ProjectServiceEntity; +import edu.kit.scc.webreg.exc.NotAuthorizedException; +import edu.kit.scc.webreg.service.project.AttributeSourceProjectService; +import edu.kit.scc.webreg.service.project.ProjectService; +import edu.kit.scc.webreg.session.SessionManager; + +@Named +@ViewScoped +public class UserShowASProjectBean implements Serializable { + + private static final long serialVersionUID = 1L; + + @Inject + private SessionManager session; + + @Inject + private AttributeSourceProjectService service; + + @Inject + private ProjectService projectService; + + private AttributeSourceProjectEntity entity; + + private List<ProjectMembershipEntity> memberList; + private List<ProjectMembershipEntity> effectiveMemberList; + private List<ProjectIdentityAdminEntity> adminList; + private List<ProjectServiceEntity> serviceList; + private List<ProjectServiceEntity> serviceFromParentsList; + + private ProjectIdentityAdminEntity adminIdentity; + + private Long id; + + public void preRenderView(ComponentSystemEvent ev) { + for (ProjectIdentityAdminEntity a : getAdminList()) { + if (a.getIdentity().getId().equals(session.getIdentityId())) { + adminIdentity = a; + break; + } + } + + if (adminIdentity == null) { + throw new NotAuthorizedException("Nicht autorisiert"); + } else { + if (!(ProjectAdminType.ADMIN.equals(adminIdentity.getType()) + || ProjectAdminType.OWNER.equals(adminIdentity.getType()))) { + throw new NotAuthorizedException("Nicht autorisiert"); + } + } + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public AttributeSourceProjectEntity getEntity() { + if (entity == null) { + entity = service.findByIdWithAttrs(id, LocalProjectEntity_.projectServices); + } + + return entity; + } + + public void deleteMember(ProjectMembershipEntity pme) { + projectService.removeProjectMember(pme, "idty-" + session.getIdentityId()); + memberList = null; + effectiveMemberList = null; + } + + public void setEntity(AttributeSourceProjectEntity entity) { + this.entity = entity; + } + + public List<ProjectMembershipEntity> getMemberList() { + if (memberList == null) { + memberList = projectService.findMembersForProject(getEntity()); + } + return memberList; + } + + public List<ProjectIdentityAdminEntity> getAdminList() { + if (adminList == null) { + adminList = projectService.findAdminsForProject(getEntity()); + } + return adminList; + } + + public List<ProjectServiceEntity> getServiceList() { + if (serviceList == null) { + serviceList = projectService.findServicesForProject(getEntity()); + } + return serviceList; + } + + public ProjectIdentityAdminEntity getAdminIdentity() { + return adminIdentity; + } + + public List<ProjectServiceEntity> getServiceFromParentsList() { + if (serviceFromParentsList == null) { + serviceFromParentsList = projectService.findServicesFromParentsForProject(getEntity()); + } + return serviceFromParentsList; + } + + public List<ProjectMembershipEntity> getEffectiveMemberList() { + if (effectiveMemberList == null) { + effectiveMemberList = projectService.findMembersForProject(getEntity(), true); + } + return effectiveMemberList; + } +} diff --git a/bwreg-webapp/src/main/webapp/admin/as/edit-attribute-source.xhtml b/bwreg-webapp/src/main/webapp/admin/as/edit-attribute-source.xhtml index 0588ce7d27cca7b483de63ea760015fc5a16467c..d2f9b4b63510841ad9de2830855de414c217e8f5 100644 --- a/bwreg-webapp/src/main/webapp/admin/as/edit-attribute-source.xhtml +++ b/bwreg-webapp/src/main/webapp/admin/as/edit-attribute-source.xhtml @@ -66,7 +66,7 @@ </h:commandLink> </p:column> </p:dataTable> - + <h:outputText value="#{messages.new_property}:"/> <h:panelGrid id="newPropTable" columns="3" columnClasses="labelColumn, elementColumn"> <h:inputText id="key_input" value="#{editAttributeSourceBean.newKey}"/> @@ -76,6 +76,11 @@ </h:commandLink> </h:panelGrid> + <h:outputText value="#{messages.connected_services}:"/> + <p:pickList var="s" value="#{editAttributeSourceBean.serviceList}" itemLabel="#{s.name}" + itemValue="#{s}" converter="#{serviceConverter}" + showSourceFilter="true" showTargetFilter="true" filterMatchMode="contains"> + </p:pickList> </p:panelGrid> <p:commandButton id="save" action="#{editAttributeSourceBean.save}" value="#{messages.save}"/> diff --git a/bwreg-webapp/src/main/webapp/admin/as/show-attribute-source.xhtml b/bwreg-webapp/src/main/webapp/admin/as/show-attribute-source.xhtml index 13a9d0f767093845d039aa82f5d099b863f69e66..9c9313ad80dc514277d328a57fdf53a3441e1e30 100644 --- a/bwreg-webapp/src/main/webapp/admin/as/show-attribute-source.xhtml +++ b/bwreg-webapp/src/main/webapp/admin/as/show-attribute-source.xhtml @@ -61,6 +61,22 @@ </p:column> </p:dataTable> + <h:outputText value="#{messages.connected_services}:"/> + <p:dataTable id="servicesTable" var="s" style="min-width: 400px;" + value="#{showAttributeSourceBean.entity.attributeSourceServices.toArray()}"> + <p:column> + <f:facet name="header"> + <h:outputText value="#{messages.short_name}" /> + </f:facet> + <h:outputText value="#{s.service.shortName}" /> + </p:column> + <p:column> + <f:facet name="header"> + <h:outputText value="#{messages.name}" /> + </f:facet> + <h:outputText value="#{s.service.name}" /> + </p:column> + </p:dataTable> </p:panelGrid> <h:link outcome="edit-attribute-source.xhtml" value="#{messages.edit}"> diff --git a/bwreg-webapp/src/main/webapp/project/index.xhtml b/bwreg-webapp/src/main/webapp/project/index.xhtml index c9aa0f5e559c45bee56359e0d3953710148019bd..43baed9a7c322c6edcb709309c0955433c1c7eb9 100644 --- a/bwreg-webapp/src/main/webapp/project/index.xhtml +++ b/bwreg-webapp/src/main/webapp/project/index.xhtml @@ -36,6 +36,12 @@ <h:outputText value="#{p.project.name}" /> (<h:outputText value="#{p.project.rpConfig.displayName}" />) <h:outputText value="#{p.project.externalName}" /> </p:outputPanel> + <p:outputPanel rendered="#{p.project.class.simpleName == 'AttributeSourceProjectEntity'}"> + <h:link outcome="show-as-project.xhtml" value="#{p.project.name}"> + <f:param name="id" value="#{p.project.id}"/> + </h:link> + (<h:outputText value="#{p.project.attributeSource.name}" /> - <h:outputText value="#{p.project.externalName}" />) + </p:outputPanel> <p:outputPanel rendered="#{p.project.class.simpleName == 'LocalProjectEntity'}"> <h:link outcome="show-local-project.xhtml" value="#{p.project.name}"> <f:param name="id" value="#{p.project.id}"/> diff --git a/bwreg-webapp/src/main/webapp/project/invite-to-project.xhtml b/bwreg-webapp/src/main/webapp/project/invite-to-project.xhtml index d2dcb83696dc34454619ea687abcee6ba7c30ac3..c9ca6869d7b7f18d91c5ea5b5450eaf652e4ac36 100644 --- a/bwreg-webapp/src/main/webapp/project/invite-to-project.xhtml +++ b/bwreg-webapp/src/main/webapp/project/invite-to-project.xhtml @@ -93,7 +93,12 @@ </p:panel> <div class="text full" style="margin-top: 0.4em;"> - <a href="show-local-project.xhtml?id=#{inviteToProjectBean.entity.id}"><h:outputText value="#{messages.back}"/></a> + <p:outputPanel rendered="#{inviteToProjectBean.entity.class.simpleName == 'LocalProjectEntity'}"> + <a href="show-local-project.xhtml?id=#{inviteToProjectBean.entity.id}"><h:outputText value="#{messages.back}"/></a> + </p:outputPanel> + <p:outputPanel rendered="#{inviteToProjectBean.entity.class.simpleName == 'AttributeSourceProjectEntity'}"> + <a href="show-as-project.xhtml?id=#{inviteToProjectBean.entity.id}"><h:outputText value="#{messages.back}"/></a> + </p:outputPanel> </div> <p:confirmDialog global="true" showEffect="fade" hideEffect="fade" closable="false" diff --git a/bwreg-webapp/src/main/webapp/project/show-as-project.xhtml b/bwreg-webapp/src/main/webapp/project/show-as-project.xhtml new file mode 100644 index 0000000000000000000000000000000000000000..9aa7e91bdbfbbe51422f7847818824dcc84b7cd8 --- /dev/null +++ b/bwreg-webapp/src/main/webapp/project/show-as-project.xhtml @@ -0,0 +1,143 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" + xmlns:f="http://java.sun.com/jsf/core" + xmlns:h="http://java.sun.com/jsf/html" + xmlns:ui="http://java.sun.com/jsf/facelets" + xmlns:p="http://primefaces.org/ui"> +<head> +<title></title> +</head> +<body> +<f:view> + <f:metadata> + <f:viewParam name="id" value="#{userShowASProjectBean.id}"/> + <f:event type="javax.faces.event.PreRenderViewEvent" + listener="#{userShowASProjectBean.preRenderView}" /> + </f:metadata> + +<ui:composition template="/template/default.xhtml"> + <ui:param name="title" value="#{messages.title}"/> + + <ui:define name="content"> + <h:form id="form" class="full form"> + + <h2><h:outputText value="#{messages['project.local_project']}: #{userShowASProjectBean.entity.name}"/></h2> + + <p:messages id="messageBox" showDetail="true" /> + + <p:panel header="#{messages.properties}"> + <p:panelGrid id="baseData" columns="2"> + + <h:outputText value="#{messages.id}:"/> + <h:outputText value="#{userShowASProjectBean.entity.id}"/> + + <h:outputText value="#{messages.name}:"/> + <h:outputText value="#{userShowASProjectBean.entity.name}"/> + + <h:outputText value="#{messages.group_name}:"/> + <h:outputText value="#{userShowASProjectBean.entity.groupName}"/> + + <h:outputText value="#{messages.parent_vo}:" rendered="#{userShowASProjectBean.entity.parentProject != null}"/> + <h:outputText value="#{userShowASProjectBean.entity.parentProject}" rendered="#{userShowASProjectBean.entity.parentProject != null}"/> + + <h:outputText value="#{messages.services}:"/> + <p:repeat value="#{userShowASProjectBean.entity.projectServices}" var="s"> + <div><h:outputText value="#{s.service.name} (#{s.status})"/></div> + </p:repeat> + </p:panelGrid> + </p:panel> + + <p:panel> + <p:panelGrid columns="2"> + <p:linkButton href="invite-to-project.xhtml" value="#{messages['project.show_local_project.invite_to_project_link']}"> + <f:param name="id" value="#{userShowASProjectBean.entity.id}"/> + </p:linkButton> + <h:outputText value="#{messages['project.show_local_project.invite_to_project_link_text']}" /> + </p:panelGrid> + </p:panel> + + <div class="text full" style="margin-top: 0.4em;"> + <a href="index.xhtml"><h:outputText value="#{messages.back}"/></a> + </div> + + <h5 style="margin-top: 1em;"><h:outputText value="#{messages['project.members']}" /></h5> + <p:dataTable id="dataTableMember" var="member" value="#{userShowASProjectBean.memberList}"> + <p:column sortBy="#{member.identity.prefUser.eppn}" filterBy="#{member.identity.prefUser.eppn}" filterMatchMode="contains"> + <f:facet name="header"> + <h:outputText value="#{messages.name}" /> + </f:facet> + <h:outputText value="#{member.identity.prefUser.eppn}" /> + </p:column> + <p:column sortBy="#{member.identity.prefUser.surName}" filterBy="#{member.identity.prefUser.surName}" filterMatchMode="contains"> + <f:facet name="header"> + <h:outputText value="#{messages.sur_name}" /> + </f:facet> + <h:outputText value="#{member.identity.prefUser.surName}" /> + </p:column> + <p:column sortBy="#{member.identity.prefUser.givenName}" filterBy="#{member.identity.prefUser.givenName}" filterMatchMode="contains"> + <f:facet name="header"> + <h:outputText value="#{messages.given_name}" /> + </f:facet> + <h:outputText value="#{member.identity.prefUser.givenName}" /> + </p:column> + <p:column> + <f:facet name="header"> + <h:outputText value="#{messages.type}" /> + </f:facet> + <h:outputText value="#{member.membershipType}" /> + </p:column> + <p:column width="12%"> + <p:tooltip for="@next" value="#{messages.delete}" position="top"/> + <p:commandButton action="#{userShowASProjectBean.deleteMember(member)}" immediate="true" update="@form" + icon="fa fa-fw fa-trash" style="font-size: 0.6em;"> + <p:confirm header="#{messages.confirm_header}" escape="false" + message="#{messages['project.show_local_project.delete_member_confirm']}" /> + </p:commandButton> + </p:column> + </p:dataTable> + + <h5 style="margin-top: 1em;"><h:outputText value="#{messages['project.admins']}" /></h5> + <p:dataTable id="dataTableAdmin" var="admin" value="#{userShowASProjectBean.adminList}"> + <p:column> + <f:facet name="header"> + <h:outputText value="#{messages.id}" /> + </f:facet> + <h:outputText value="#{admin.identity.id}" /> + </p:column> + <p:column sortBy="#{admin.identity.prefUser.eppn}" filterBy="#{admin.identity.prefUser.eppn}" filterMatchMode="contains"> + <f:facet name="header"> + <h:outputText value="#{messages.name}" /> + </f:facet> + <h:outputText value="#{admin.identity.prefUser.eppn}" /> + </p:column> + <p:column> + <f:facet name="header"> + <h:outputText value="#{messages.type}" /> + </f:facet> + <h:outputText value="#{admin.type}" /> + </p:column> + </p:dataTable> + + <h5 style="margin-top: 1em;"><h:outputText value="#{messages['more_properties']}" /></h5> + <p:panelGrid id="descData" columns="2"> + <h:outputText value="#{messages['project.short_description']}:"/> + <h:outputText value="#{userShowASProjectBean.entity.shortDescription}" /> + + <h:outputText value="#{messages['project.long_description']}:"/> + <h:outputText value="#{userShowASProjectBean.entity.description}" /> + </p:panelGrid> + + <p:confirmDialog global="true" showEffect="fade" hideEffect="fade" closable="false" + closeOnEscape="true" width="320"> + <p:commandButton value="#{messages.yes}" type="button" styleClass="ui-confirmdialog-yes"/> + <p:commandButton value="#{messages.no}" type="button" styleClass="ui-confirmdialog-no"/> + </p:confirmDialog> + + </h:form> + + </ui:define> +</ui:composition> +</f:view> +</body> +</html> diff --git a/pom.xml b/pom.xml index 8aed5f2af27421def926fe3023bab6bd582624c9..188563c99b4433eb15ca94a5e0a575523c8f04d3 100644 --- a/pom.xml +++ b/pom.xml @@ -81,6 +81,7 @@ <module>regapp-twofa</module> <module>regapp-sshkey</module> <module>regapp-ejb-service</module> + <module>regapp-project</module> <module>bwreg-lib</module> <module>bwreg-jpa</module> <module>bwreg-service</module> diff --git a/regapp-as/pom.xml b/regapp-as/pom.xml index 53829bcb05ef4cd5eb7f5786efb304e05c580cf7..f1e10af4334f9dd9ae53b9a91cf141bf759c1e9c 100644 --- a/regapp-as/pom.xml +++ b/regapp-as/pom.xml @@ -69,7 +69,11 @@ <artifactId>regapp-event-api</artifactId> <version>${project.version}</version> </dependency> - + <dependency> + <groupId>edu.kit.scc</groupId> + <artifactId>regapp-project</artifactId> + <version>${project.version}</version> + </dependency> <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> diff --git a/regapp-as/src/main/java/edu/kit/scc/webreg/as/AbstractAttributeSourceWorkflow.java b/regapp-as/src/main/java/edu/kit/scc/webreg/as/AbstractAttributeSourceWorkflow.java index 35ecc9bf1ae202796a16a6382090a51eba77ef36..6bfd14de4e99b8b6a2dcddbf3ffcfdd746f6ede0 100644 --- a/regapp-as/src/main/java/edu/kit/scc/webreg/as/AbstractAttributeSourceWorkflow.java +++ b/regapp-as/src/main/java/edu/kit/scc/webreg/as/AbstractAttributeSourceWorkflow.java @@ -3,6 +3,7 @@ package edu.kit.scc.webreg.as; import static edu.kit.scc.webreg.dao.ops.RqlExpressions.and; import static edu.kit.scc.webreg.dao.ops.RqlExpressions.equal; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; @@ -11,6 +12,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import javax.enterprise.inject.spi.CDI; import javax.naming.InitialContext; import javax.naming.NamingException; @@ -41,6 +43,7 @@ import edu.kit.scc.webreg.event.MultipleGroupEvent; import edu.kit.scc.webreg.event.exc.EventSubmitException; import edu.kit.scc.webreg.exc.PropertyReaderException; import edu.kit.scc.webreg.exc.UserUpdateException; +import edu.kit.scc.webreg.service.project.AttributeSourceProjectUpdater; import edu.kit.scc.webreg.tools.PropertyReader; public abstract class AbstractAttributeSourceWorkflow implements AttributeSourceWorkflow { @@ -54,6 +57,9 @@ public abstract class AbstractAttributeSourceWorkflow implements AttributeSource protected String groupKey; protected String groupSeparator; + protected String piKey; + protected String piSeparator; + private ASUserAttrEntity asUserAttr; private ASUserAttrValueDao asValueDao; private GroupDao groupDao; @@ -72,16 +78,18 @@ public abstract class AbstractAttributeSourceWorkflow implements AttributeSource try { prop = new PropertyReader(asUserAttr.getAttributeSource().getAsProps()); - if (prop.readPropOrNull("group_key") != null) - groupKey = prop.readPropOrNull("group_key"); - else - groupKey = null; - + groupKey = prop.readPropOrNull("group_key"); if (prop.readPropOrNull("group_separator") != null) groupSeparator = prop.readPropOrNull("group_separator"); else groupSeparator = ";"; + piKey = prop.readPropOrNull("pi_key"); + if (prop.readPropOrNull("pi_separator") != null) + piSeparator = prop.readPropOrNull("pi_separator"); + else + piSeparator = ";"; + } catch (PropertyReaderException e) { throw new UserUpdateException(e); } @@ -146,6 +154,10 @@ public abstract class AbstractAttributeSourceWorkflow implements AttributeSource if (groupKey != null && key.equals(groupKey)) { processGroups(asValue); } + + if (piKey != null && key.equals(piKey)) { + processProjects(asValue); + } } else { logger.warn("Cannot process value of type {}", o.getClass()); return false; @@ -163,6 +175,10 @@ public abstract class AbstractAttributeSourceWorkflow implements AttributeSource if (groupKey != null && key.equals(groupKey)) { processGroups(null); } + + if (piKey != null && key.equals(piKey)) { + processProjects(null); + } return true; } @@ -187,6 +203,10 @@ public abstract class AbstractAttributeSourceWorkflow implements AttributeSource if (groupKey != null && key.equals(groupKey)) { changed |= processGroups(asStringValue); } + + if (piKey != null && key.equals(piKey)) { + changed |= processProjects(asStringValue); + } } else { logger.warn("Value change for key {} from {} to ASUserAttrValueStringEntity not supported yet", key, o.getClass()); @@ -195,6 +215,25 @@ public abstract class AbstractAttributeSourceWorkflow implements AttributeSource return changed; } + private Boolean processProjects(ASUserAttrValueStringEntity asValue) { + Boolean changed = false; + + UserEntity user = asUserAttr.getUser(); + AttributeSourceEntity attributeSource = asUserAttr.getAttributeSource(); + + AttributeSourceProjectUpdater asUpdater = CDI.current().select(AttributeSourceProjectUpdater.class).get(); + + List<String> projectList = new ArrayList<String>(); + if (asValue != null) { + String[] projects = asValue.getValueString().toLowerCase().split(piSeparator); + projectList.addAll(Arrays.asList(projects)); + } + + changed |= asUpdater.syncAttributeSourceProjects(projectList, user, attributeSource); + + return changed; + } + private Boolean processGroups(ASUserAttrValueStringEntity asValue) { Boolean changed = false; diff --git a/regapp-as/src/main/java/edu/kit/scc/webreg/as/AttributeSourceUpdater.java b/regapp-as/src/main/java/edu/kit/scc/webreg/as/AttributeSourceUpdater.java index 4ebc5964d21d19375baa2bf4acdd1e784cdb63f1..889c0e13bfc50841658596fdaf802e23532409c3 100644 --- a/regapp-as/src/main/java/edu/kit/scc/webreg/as/AttributeSourceUpdater.java +++ b/regapp-as/src/main/java/edu/kit/scc/webreg/as/AttributeSourceUpdater.java @@ -83,7 +83,7 @@ public class AttributeSourceUpdater implements Serializable { if (asUserAttr != null && asUserAttr.getLastQuery() != null && (System.currentTimeMillis() - asUserAttr.getLastQuery().getTime()) < expireTime) { logger.info("Skipping attribute source query {} for user {}. Data not expired.", attributeSource.getName(), - user.getEppn()); + user.getId()); return changed; } diff --git a/regapp-ejb-service/src/main/java/edu/kit/scc/webreg/service/AttributeSourceServiceService.java b/regapp-ejb-service/src/main/java/edu/kit/scc/webreg/service/AttributeSourceServiceService.java new file mode 100644 index 0000000000000000000000000000000000000000..f0a83a5092bbe081ccf8570b0af1fbba7c72cdb6 --- /dev/null +++ b/regapp-ejb-service/src/main/java/edu/kit/scc/webreg/service/AttributeSourceServiceService.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * 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; + +import edu.kit.scc.webreg.entity.ServiceEntity; +import edu.kit.scc.webreg.entity.as.AttributeSourceEntity; +import edu.kit.scc.webreg.entity.as.AttributeSourceServiceEntity; + +public interface AttributeSourceServiceService extends BaseService<AttributeSourceServiceEntity> { + + AttributeSourceServiceEntity connectService(AttributeSourceEntity as, ServiceEntity service); + + void disconnectService(AttributeSourceEntity as, ServiceEntity service); + +} diff --git a/regapp-ejb-service/src/main/java/edu/kit/scc/webreg/service/impl/AttributeSourceServiceServiceImpl.java b/regapp-ejb-service/src/main/java/edu/kit/scc/webreg/service/impl/AttributeSourceServiceServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..9edcd29924462c531a01d496e14dd486133a0ad5 --- /dev/null +++ b/regapp-ejb-service/src/main/java/edu/kit/scc/webreg/service/impl/AttributeSourceServiceServiceImpl.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * 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.impl; + +import javax.ejb.Stateless; +import javax.inject.Inject; + +import edu.kit.scc.webreg.dao.BaseDao; +import edu.kit.scc.webreg.dao.as.AttributeSourceServiceDao; +import edu.kit.scc.webreg.entity.ServiceEntity; +import edu.kit.scc.webreg.entity.as.AttributeSourceEntity; +import edu.kit.scc.webreg.entity.as.AttributeSourceServiceEntity; +import edu.kit.scc.webreg.service.AttributeSourceServiceService; + +@Stateless +public class AttributeSourceServiceServiceImpl extends BaseServiceImpl<AttributeSourceServiceEntity> + implements AttributeSourceServiceService { + + private static final long serialVersionUID = 1L; + + @Inject + private AttributeSourceServiceDao dao; + + @Override + public AttributeSourceServiceEntity connectService(AttributeSourceEntity as, ServiceEntity service) { + return dao.connectService(as, service); + } + + @Override + public void disconnectService(AttributeSourceEntity as, ServiceEntity service) { + dao.disconnectService(as, service); + } + + @Override + protected BaseDao<AttributeSourceServiceEntity> getDao() { + return dao; + } +} diff --git a/regapp-jpa-api/src/main/java/edu/kit/scc/webreg/dao/as/AttributeSourceServiceDao.java b/regapp-jpa-api/src/main/java/edu/kit/scc/webreg/dao/as/AttributeSourceServiceDao.java new file mode 100644 index 0000000000000000000000000000000000000000..094c389fc5433647786db8d523d8206573319c6e --- /dev/null +++ b/regapp-jpa-api/src/main/java/edu/kit/scc/webreg/dao/as/AttributeSourceServiceDao.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * 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.as; + +import edu.kit.scc.webreg.dao.BaseDao; +import edu.kit.scc.webreg.entity.ServiceEntity; +import edu.kit.scc.webreg.entity.as.AttributeSourceEntity; +import edu.kit.scc.webreg.entity.as.AttributeSourceServiceEntity; + +public interface AttributeSourceServiceDao extends BaseDao<AttributeSourceServiceEntity> { + + AttributeSourceServiceEntity connectService(AttributeSourceEntity as, ServiceEntity service); + + void disconnectService(AttributeSourceEntity as, ServiceEntity service); + +} \ No newline at end of file diff --git a/regapp-jpa-api/src/main/java/edu/kit/scc/webreg/dao/project/AttributeSourceProjectDao.java b/regapp-jpa-api/src/main/java/edu/kit/scc/webreg/dao/project/AttributeSourceProjectDao.java new file mode 100644 index 0000000000000000000000000000000000000000..875c6eb2daf7645d192075b0e7a8c99af69e790b --- /dev/null +++ b/regapp-jpa-api/src/main/java/edu/kit/scc/webreg/dao/project/AttributeSourceProjectDao.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * 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 edu.kit.scc.webreg.entity.as.AttributeSourceEntity; +import edu.kit.scc.webreg.entity.project.AttributeSourceProjectEntity; + +public interface AttributeSourceProjectDao extends BaseProjectDao<AttributeSourceProjectEntity> { + + AttributeSourceProjectEntity findByExternalNameAttributeSource(String externalName, + AttributeSourceEntity attributeSource); + +} diff --git a/regapp-jpa-impl/src/main/java/edu/kit/scc/webreg/dao/jpa/as/JpaAttributeSourceServiceDao.java b/regapp-jpa-impl/src/main/java/edu/kit/scc/webreg/dao/jpa/as/JpaAttributeSourceServiceDao.java new file mode 100644 index 0000000000000000000000000000000000000000..27f529decb09d2bbf907f0f89588b451ad32b9a0 --- /dev/null +++ b/regapp-jpa-impl/src/main/java/edu/kit/scc/webreg/dao/jpa/as/JpaAttributeSourceServiceDao.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * 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.as; + +import static edu.kit.scc.webreg.dao.ops.RqlExpressions.and; +import static edu.kit.scc.webreg.dao.ops.RqlExpressions.equal; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Named; + +import edu.kit.scc.webreg.dao.as.AttributeSourceServiceDao; +import edu.kit.scc.webreg.dao.jpa.JpaBaseDao; +import edu.kit.scc.webreg.entity.ServiceEntity; +import edu.kit.scc.webreg.entity.as.AttributeSourceEntity; +import edu.kit.scc.webreg.entity.as.AttributeSourceServiceEntity; +import edu.kit.scc.webreg.entity.as.AttributeSourceServiceEntity_; + +@Named +@ApplicationScoped +public class JpaAttributeSourceServiceDao extends JpaBaseDao<AttributeSourceServiceEntity> + implements AttributeSourceServiceDao { + + @Override + public Class<AttributeSourceServiceEntity> getEntityClass() { + return AttributeSourceServiceEntity.class; + } + + @Override + public AttributeSourceServiceEntity connectService(AttributeSourceEntity as, ServiceEntity service) { + AttributeSourceServiceEntity entity = createNew(); + entity.setAttributeSource(as); + entity.setService(service); + return persist(entity); + } + + @Override + public void disconnectService(AttributeSourceEntity as, ServiceEntity service) { + AttributeSourceServiceEntity entity = find(and(equal(AttributeSourceServiceEntity_.attributeSource, as), + equal(AttributeSourceServiceEntity_.service, service))); + delete(entity); + } + +} diff --git a/regapp-jpa-impl/src/main/java/edu/kit/scc/webreg/dao/jpa/project/JpaAttributeSourceProjectDao.java b/regapp-jpa-impl/src/main/java/edu/kit/scc/webreg/dao/jpa/project/JpaAttributeSourceProjectDao.java new file mode 100644 index 0000000000000000000000000000000000000000..3037c657a748d213b9296050ec41c80230e56b9f --- /dev/null +++ b/regapp-jpa-impl/src/main/java/edu/kit/scc/webreg/dao/jpa/project/JpaAttributeSourceProjectDao.java @@ -0,0 +1,43 @@ +/* + * ***************************************************************************** + * 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 static edu.kit.scc.webreg.dao.ops.RqlExpressions.and; +import static edu.kit.scc.webreg.dao.ops.RqlExpressions.equal; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Named; + +import edu.kit.scc.webreg.dao.project.AttributeSourceProjectDao; +import edu.kit.scc.webreg.entity.as.AttributeSourceEntity; +import edu.kit.scc.webreg.entity.project.AttributeSourceProjectEntity; +import edu.kit.scc.webreg.entity.project.AttributeSourceProjectEntity_; +import edu.kit.scc.webreg.entity.project.ExternalProjectEntity_; + +@Named +@ApplicationScoped +public class JpaAttributeSourceProjectDao extends JpaExternalProjectDao<AttributeSourceProjectEntity> + implements AttributeSourceProjectDao { + + @Override + public AttributeSourceProjectEntity findByExternalNameAttributeSource(String externalName, + AttributeSourceEntity attributeSource) { + return find(and(equal(ExternalProjectEntity_.externalName, externalName), + equal(AttributeSourceProjectEntity_.attributeSource, attributeSource))); + } + + @Override + public Class<AttributeSourceProjectEntity> getEntityClass() { + return AttributeSourceProjectEntity.class; + } + +} diff --git a/regapp-project/pom.xml b/regapp-project/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..a2baaa1ed353620fd8b9614126782f0266827d88 --- /dev/null +++ b/regapp-project/pom.xml @@ -0,0 +1,106 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>edu.kit.scc</groupId> + <artifactId>bwreg</artifactId> + <version>${revision}</version> + </parent> + <packaging>jar</packaging> + <artifactId>regapp-project</artifactId> + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.wildfly.bom</groupId> + <artifactId>wildfly-javaee8-with-tools</artifactId> + <version>17.0.1.Final</version> + <type>pom</type> + <scope>import</scope> + <optional>false</optional> + </dependency> + </dependencies> + </dependencyManagement> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> + </properties> + + <dependencies> + <dependency> + <groupId>edu.kit.scc</groupId> + <artifactId>bwreg-entities</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>edu.kit.scc</groupId> + <artifactId>regapp-exc</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>edu.kit.scc</groupId> + <artifactId>regapp-tools</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>edu.kit.scc</groupId> + <artifactId>regapp-jpa-api</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>edu.kit.scc</groupId> + <artifactId>regapp-jpa-impl</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>edu.kit.scc</groupId> + <artifactId>regapp-config</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>edu.kit.scc</groupId> + <artifactId>regapp-audit</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>edu.kit.scc</groupId> + <artifactId>regapp-event-api</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>edu.kit.scc</groupId> + <artifactId>regapp-reg-api</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>javax</groupId> + <artifactId>javaee-api</artifactId> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </dependency> + <dependency> + <groupId>org.apache.velocity</groupId> + <artifactId>velocity</artifactId> + </dependency> + <dependency> + <groupId>edu.vt.middleware</groupId> + <artifactId>vt-ldap</artifactId> + </dependency> + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient</artifactId> + </dependency> + <dependency> + <groupId>commons-beanutils</groupId> + <artifactId>commons-beanutils</artifactId> + </dependency> + + </dependencies> +</project> diff --git a/regapp-idty/src/main/java/edu/kit/scc/webreg/service/project/AbstractProjectCreater.java b/regapp-project/src/main/java/edu/kit/scc/webreg/service/project/AbstractProjectCreater.java similarity index 79% rename from regapp-idty/src/main/java/edu/kit/scc/webreg/service/project/AbstractProjectCreater.java rename to regapp-project/src/main/java/edu/kit/scc/webreg/service/project/AbstractProjectCreater.java index 9f671e36cbf8e7cfd0b122ca7ad7fac5bb53db91..316b82bc8d9230f73823eaeaab173d6d789b398d 100644 --- a/regapp-idty/src/main/java/edu/kit/scc/webreg/service/project/AbstractProjectCreater.java +++ b/regapp-project/src/main/java/edu/kit/scc/webreg/service/project/AbstractProjectCreater.java @@ -8,7 +8,6 @@ import org.slf4j.Logger; import edu.kit.scc.webreg.entity.project.ProjectEntity; import edu.kit.scc.webreg.event.EventSubmitter; -import edu.kit.scc.webreg.service.identity.IdentityScriptingEnv; public class AbstractProjectCreater<T extends ProjectEntity> implements Serializable { @@ -17,9 +16,6 @@ public class AbstractProjectCreater<T extends ProjectEntity> implements Serializ @Inject private Logger logger; - @Inject - private IdentityScriptingEnv scriptingEnv; - @Inject private EventSubmitter eventSubmitter; diff --git a/regapp-idty/src/main/java/edu/kit/scc/webreg/service/project/AbstractProjectUpdater.java b/regapp-project/src/main/java/edu/kit/scc/webreg/service/project/AbstractProjectUpdater.java similarity index 100% rename from regapp-idty/src/main/java/edu/kit/scc/webreg/service/project/AbstractProjectUpdater.java rename to regapp-project/src/main/java/edu/kit/scc/webreg/service/project/AbstractProjectUpdater.java diff --git a/regapp-project/src/main/java/edu/kit/scc/webreg/service/project/AttributeSourceProjectCreater.java b/regapp-project/src/main/java/edu/kit/scc/webreg/service/project/AttributeSourceProjectCreater.java new file mode 100644 index 0000000000000000000000000000000000000000..8ee1f28e6f790cf57a11cca05fff4ccf80cca005 --- /dev/null +++ b/regapp-project/src/main/java/edu/kit/scc/webreg/service/project/AttributeSourceProjectCreater.java @@ -0,0 +1,51 @@ +package edu.kit.scc.webreg.service.project; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; + +import org.slf4j.Logger; + +import edu.kit.scc.webreg.dao.GroupDao; +import edu.kit.scc.webreg.dao.project.AttributeSourceProjectDao; +import edu.kit.scc.webreg.dao.project.LocalProjectGroupDao; +import edu.kit.scc.webreg.entity.as.AttributeSourceEntity; +import edu.kit.scc.webreg.entity.project.AttributeSourceProjectEntity; +import edu.kit.scc.webreg.entity.project.LocalProjectGroupEntity; + +@ApplicationScoped +public class AttributeSourceProjectCreater extends AbstractProjectCreater<AttributeSourceProjectEntity> { + + private static final long serialVersionUID = 1L; + + @Inject + private Logger logger; + + @Inject + private AttributeSourceProjectDao dao; + + @Inject + private LocalProjectGroupDao projectGroupDao; + + @Inject + private GroupDao groupDao; + + public AttributeSourceProjectEntity create(String projectName, String externalName, String groupName, String shortName, AttributeSourceEntity attributeSource) { + AttributeSourceProjectEntity project = new AttributeSourceProjectEntity(); + + LocalProjectGroupEntity projectGroup = projectGroupDao.createNew(); + projectGroup.setName(groupName); + projectGroup.setGidNumber(groupDao.getNextGID().intValue()); + projectGroup = projectGroupDao.persist(projectGroup); + project.setProjectGroup(projectGroup); + + project.setName(projectName); + project.setGroupName(groupName); + project.setExternalName(externalName); + project.setShortName(shortName); + project.setAttributeSource(attributeSource); + + project = (AttributeSourceProjectEntity) dao.persist(project); + + return project; + } +} diff --git a/regapp-project/src/main/java/edu/kit/scc/webreg/service/project/AttributeSourceProjectUpdater.java b/regapp-project/src/main/java/edu/kit/scc/webreg/service/project/AttributeSourceProjectUpdater.java new file mode 100644 index 0000000000000000000000000000000000000000..8866a40345332dce8f9507bbb2e7160d10741df4 --- /dev/null +++ b/regapp-project/src/main/java/edu/kit/scc/webreg/service/project/AttributeSourceProjectUpdater.java @@ -0,0 +1,111 @@ +package edu.kit.scc.webreg.service.project; + +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; + +import org.slf4j.Logger; + +import edu.kit.scc.webreg.dao.project.AttributeSourceProjectDao; +import edu.kit.scc.webreg.dao.project.BaseProjectDao; +import edu.kit.scc.webreg.entity.ServiceEntity; +import edu.kit.scc.webreg.entity.UserEntity; +import edu.kit.scc.webreg.entity.as.AttributeSourceEntity; +import edu.kit.scc.webreg.entity.identity.IdentityEntity; +import edu.kit.scc.webreg.entity.project.AttributeSourceProjectEntity; +import edu.kit.scc.webreg.entity.project.ProjectAdminType; +import edu.kit.scc.webreg.entity.project.ProjectIdentityAdminEntity; +import edu.kit.scc.webreg.entity.project.ProjectServiceStatusType; +import edu.kit.scc.webreg.entity.project.ProjectServiceType; + +@ApplicationScoped +public class AttributeSourceProjectUpdater extends AbstractProjectUpdater<AttributeSourceProjectEntity> { + + private static final long serialVersionUID = 1L; + + @Inject + private Logger logger; + + @Inject + private AttributeSourceProjectDao dao; + + @Inject + private AttributeSourceProjectCreater projectCreater; + + @Inject + private AttributeSourceProjectUpdater projectUpdater; + + public boolean syncAttributeSourceProjects(List<String> externalNamesList, UserEntity user, + AttributeSourceEntity attributeSource) { + boolean changed = false; + + IdentityEntity identity = user.getIdentity(); + + List<ProjectIdentityAdminEntity> adminList = dao.findAdminByIdentity(identity); + // TODO move this logic to dao query + List<ProjectIdentityAdminEntity> filteredAdminList = adminList.stream() + .filter(pia -> (pia.getProject() instanceof AttributeSourceProjectEntity) + && (((AttributeSourceProjectEntity) pia.getProject()).getAttributeSource() + .equals(attributeSource))) + .collect(Collectors.toList()); + + logger.debug("Identity {} is admin in {} projects and {} in attribute sourced proects", identity.getId(), + adminList.size(), filteredAdminList.size()); + + for (ProjectIdentityAdminEntity pia : filteredAdminList) { + if (!externalNamesList.contains(((AttributeSourceProjectEntity) pia.getProject()).getExternalName())) { + logger.debug("Project {} no longer in external attribute source. Removing ProjectIdentityAdminEntity", + pia.getProject().getId()); + dao.removeAdminFromProject(pia); + changed = true; + } + } + + for (String name : externalNamesList) { + AttributeSourceProjectEntity project = dao.findByExternalNameAttributeSource(name, attributeSource); + + if (filteredAdminList.stream() + .filter(pia -> ((AttributeSourceProjectEntity) pia.getProject()).getExternalName().equals(name)) + .findFirst().isEmpty()) { + logger.debug("Project {} not in ProjectIdentityAdminEntity for identity {}", name, identity.getId()); + + if (project == null) { + project = projectCreater.create(name, name, name, name, attributeSource); + } + + dao.addAdminToProject(project, identity, ProjectAdminType.OWNER); + } + + logger.debug("Checking if service connections are correct for {}", project.getName()); + Set<ServiceEntity> serviceList = attributeSource.getAttributeSourceServices().stream().map(asse -> asse.getService()).collect(Collectors.toSet()); + projectUpdater.updateServices(project, serviceList, ProjectServiceType.PASSIVE_GROUP,ProjectServiceStatusType.ACTIVE, "attribute-srouce-" + attributeSource.getId()); + + // Add missing connections to service +// for (AttributeSourceServiceEntity asse : attributeSource.getAttributeSourceServices()) { +// if (project.getProjectServices().stream() +// .noneMatch(ps -> ps.getService().equals(asse.getService()))) { +// logger.debug("Connecting project {} with service {}", project.getName(), asse.getService().getName()); +// projectUpdater.addOrChangeService(project, asse.getService(), ProjectServiceType.PASSIVE_GROUP, +// ProjectServiceStatusType.ACTIVE, "attribute-srouce-" + attributeSource.getId()); +// } +// } +// +// for (ProjectServiceEntity ps : project.getProjectServices()) { +// if (attributeSource.getAttributeSourceServices().stream().noneMatch(asse -> asse.getService().equals(ps.getService()))) { +// logger.debug("Removing connectiion: project {} with service {}", project.getName(), ps.getService().getName()); +// . +// } +// } + } + + return changed; + } + + @Override + protected BaseProjectDao<AttributeSourceProjectEntity> getDao() { + return dao; + } +} diff --git a/regapp-idty/src/main/java/edu/kit/scc/webreg/service/project/ExternalOidcProjectCreater.java b/regapp-project/src/main/java/edu/kit/scc/webreg/service/project/ExternalOidcProjectCreater.java similarity index 88% rename from regapp-idty/src/main/java/edu/kit/scc/webreg/service/project/ExternalOidcProjectCreater.java rename to regapp-project/src/main/java/edu/kit/scc/webreg/service/project/ExternalOidcProjectCreater.java index b3a0ffefcb3723a77b07cd37986e242d3203b416..eb8847de8e2db89e7b2676658c360a56eca84b06 100644 --- a/regapp-idty/src/main/java/edu/kit/scc/webreg/service/project/ExternalOidcProjectCreater.java +++ b/regapp-project/src/main/java/edu/kit/scc/webreg/service/project/ExternalOidcProjectCreater.java @@ -8,6 +8,7 @@ import org.slf4j.Logger; import edu.kit.scc.webreg.dao.GroupDao; import edu.kit.scc.webreg.dao.project.ExternalOidcProjectDao; import edu.kit.scc.webreg.dao.project.LocalProjectGroupDao; +import edu.kit.scc.webreg.entity.oidc.OidcRpConfigurationEntity; import edu.kit.scc.webreg.entity.project.ExternalOidcProjectEntity; import edu.kit.scc.webreg.entity.project.LocalProjectGroupEntity; @@ -28,7 +29,7 @@ public class ExternalOidcProjectCreater extends AbstractProjectCreater<ExternalO @Inject private GroupDao groupDao; - public ExternalOidcProjectEntity create(String projectName, String externalName, String groupName, String shortName) { + public ExternalOidcProjectEntity create(String projectName, String externalName, String groupName, String shortName, OidcRpConfigurationEntity rpConfig) { ExternalOidcProjectEntity project = new ExternalOidcProjectEntity(); LocalProjectGroupEntity projectGroup = projectGroupDao.createNew(); @@ -41,6 +42,7 @@ public class ExternalOidcProjectCreater extends AbstractProjectCreater<ExternalO project.setGroupName(groupName); project.setExternalName(externalName); project.setShortName(shortName); + project.setRpConfig(rpConfig); project = (ExternalOidcProjectEntity) dao.persist(project); diff --git a/regapp-idty/src/main/java/edu/kit/scc/webreg/service/project/ExternalOidcProjectUpdater.java b/regapp-project/src/main/java/edu/kit/scc/webreg/service/project/ExternalOidcProjectUpdater.java similarity index 98% rename from regapp-idty/src/main/java/edu/kit/scc/webreg/service/project/ExternalOidcProjectUpdater.java rename to regapp-project/src/main/java/edu/kit/scc/webreg/service/project/ExternalOidcProjectUpdater.java index 2856780a9ff089d50d7d6dba1a40259a250d25dc..64b8e6cf565f025396850db3532fa16744d4417c 100644 --- a/regapp-idty/src/main/java/edu/kit/scc/webreg/service/project/ExternalOidcProjectUpdater.java +++ b/regapp-project/src/main/java/edu/kit/scc/webreg/service/project/ExternalOidcProjectUpdater.java @@ -40,7 +40,7 @@ public class ExternalOidcProjectUpdater extends AbstractProjectUpdater<ExternalO } if (project == null) { - project = projectCreater.create(projectName, externalName, groupName, shortName); + project = projectCreater.create(projectName, externalName, groupName, shortName, rpConfig); } project.setName(projectName); diff --git a/regapp-idty/src/main/java/edu/kit/scc/webreg/service/project/LocalProjectCreater.java b/regapp-project/src/main/java/edu/kit/scc/webreg/service/project/LocalProjectCreater.java similarity index 100% rename from regapp-idty/src/main/java/edu/kit/scc/webreg/service/project/LocalProjectCreater.java rename to regapp-project/src/main/java/edu/kit/scc/webreg/service/project/LocalProjectCreater.java diff --git a/regapp-idty/src/main/java/edu/kit/scc/webreg/service/project/LocalProjectUpdater.java b/regapp-project/src/main/java/edu/kit/scc/webreg/service/project/LocalProjectUpdater.java similarity index 100% rename from regapp-idty/src/main/java/edu/kit/scc/webreg/service/project/LocalProjectUpdater.java rename to regapp-project/src/main/java/edu/kit/scc/webreg/service/project/LocalProjectUpdater.java diff --git a/regapp-project/src/main/resources/META-INF/beans.xml b/regapp-project/src/main/resources/META-INF/beans.xml new file mode 100644 index 0000000000000000000000000000000000000000..dd88dc2a853b9104efc4cfc1321a8fa1d26a30b0 --- /dev/null +++ b/regapp-project/src/main/resources/META-INF/beans.xml @@ -0,0 +1,5 @@ +<beans xmlns="http://java.sun.com/xml/ns/javaee" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee + http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> +</beans> \ No newline at end of file