From 3e102703f97529ec3b4f59645f21044aa8941009 Mon Sep 17 00:00:00 2001
From: Michael Simon <simon@kit.edu>
Date: Wed, 4 Aug 2021 10:13:59 +0200
Subject: [PATCH] edit saml sp service configuration page

---
 .../admin/saml/EditSamlServiceSpBean.java     |  11 +-
 .../admin/saml/ListIdpConfigurationBean.java  |   4 +
 .../webapp/admin/saml/list-idp-configs.xhtml  | 114 ++++++++++--------
 3 files changed, 79 insertions(+), 50 deletions(-)

diff --git a/bwreg-webapp/src/main/java/edu/kit/scc/webreg/bean/admin/saml/EditSamlServiceSpBean.java b/bwreg-webapp/src/main/java/edu/kit/scc/webreg/bean/admin/saml/EditSamlServiceSpBean.java
index 1ebe49488..ea56e8030 100644
--- a/bwreg-webapp/src/main/java/edu/kit/scc/webreg/bean/admin/saml/EditSamlServiceSpBean.java
+++ b/bwreg-webapp/src/main/java/edu/kit/scc/webreg/bean/admin/saml/EditSamlServiceSpBean.java
@@ -57,16 +57,21 @@ public class EditSamlServiceSpBean implements Serializable {
 	
 	public String save() {
 		entity = service.save(entity);
-		return "list-idp-configs.xhtml";
+		return "list-idp-configs.xhtml?faces-redirect=true";
 	}
 
 	public String cancel() {
-		return "list-idp-configs.xhtml";
+		return "list-idp-configs.xhtml?faces-redirect=true";
 	}
 
 	public ServiceSamlSpEntity getEntity() {
 		if (entity == null) {
-			entity = service.findById(id);
+			if (getId() == null) {
+				entity = service.createNew();
+			}
+			else {
+				entity = service.findById(id);
+			}
 		}
 		return entity;
 	}
diff --git a/bwreg-webapp/src/main/java/edu/kit/scc/webreg/bean/admin/saml/ListIdpConfigurationBean.java b/bwreg-webapp/src/main/java/edu/kit/scc/webreg/bean/admin/saml/ListIdpConfigurationBean.java
index c4679e2a5..5e65bcd92 100644
--- a/bwreg-webapp/src/main/java/edu/kit/scc/webreg/bean/admin/saml/ListIdpConfigurationBean.java
+++ b/bwreg-webapp/src/main/java/edu/kit/scc/webreg/bean/admin/saml/ListIdpConfigurationBean.java
@@ -51,4 +51,8 @@ public class ListIdpConfigurationBean implements Serializable {
 		return serviceSpList;
 	}
 
+	public void delete(ServiceSamlSpEntity serviceSamlSpEntity) {
+		serviceSamlSpService.delete(serviceSamlSpEntity);
+		serviceSpList = null;
+	}	
 }
diff --git a/bwreg-webapp/src/main/webapp/admin/saml/list-idp-configs.xhtml b/bwreg-webapp/src/main/webapp/admin/saml/list-idp-configs.xhtml
index 66b689048..9f5c78e43 100644
--- a/bwreg-webapp/src/main/webapp/admin/saml/list-idp-configs.xhtml
+++ b/bwreg-webapp/src/main/webapp/admin/saml/list-idp-configs.xhtml
@@ -17,55 +17,75 @@
 	<ui:define name="content">
 	
 	<h:form id="form">
+		<p:panel header="#{messages.saml_idp_configuration}">
+			<p:dataTable id="idpDataTable" var="entity" value="#{listIdpConfigurationBean.idpList}">
+				<p:column>
+					<f:facet name="header">
+						<h:outputText value="#{messages.id}" />
+					</f:facet>
+					<h:outputText value="#{entity.id}" />
+				</p:column>
+				<p:column>
+					<f:facet name="header">
+						<h:outputText value="#{messages.entity_id}" />
+					</f:facet>
+					<h:link outcome="show-idp-config.xhtml" value="#{entity.entityId}">
+	      				<f:param name="id" value="#{entity.id}"/>
+	    			</h:link>
+				</p:column>		
+			</p:dataTable>
+	
+	        <h:link outcome="add-idp-config.xhtml" value="#{messages.add_idp_config}"/>
+		</p:panel>
 
-		<p:dataTable id="idpDataTable" var="entity" value="#{listIdpConfigurationBean.idpList}">
-			<p:column>
-				<f:facet name="header">
-					<h:outputText value="#{messages.id}" />
-				</f:facet>
-				<h:outputText value="#{entity.id}" />
-			</p:column>
-			<p:column>
-				<f:facet name="header">
-					<h:outputText value="#{messages.entity_id}" />
-				</f:facet>
-				<h:link outcome="show-idp-config.xhtml" value="#{entity.entityId}">
-      				<f:param name="id" value="#{entity.id}"/>
-    			</h:link>
-			</p:column>		
-		</p:dataTable>
-
-        <h:link outcome="add-idp-config.xhtml" value="#{messages.add_idp_config}"/>
-
-		<p:dataTable id="spDataTable" var="entity" value="#{listIdpConfigurationBean.serviceSpList}">
-			<p:column>
-				<f:facet name="header">
-					<h:outputText value="#{messages.id}" />
-				</f:facet>
-				<h:link outcome="edit-saml-service-sp.xhtml" value="#{entity.id}">
-      				<f:param name="id" value="#{entity.id}"/>
-    			</h:link>
-			</p:column>
-			<p:column>
-				<f:facet name="header">
-					<h:outputText value="#{messages.idp}" />
-				</f:facet>
-				<h:outputText value="#{(empty entity.idp.entityId ? 'All IDPs' : entity.idp.entityId)}" />
-			</p:column>		
-			<p:column>
-				<f:facet name="header">
-					<h:outputText value="#{messages.service}" />
-				</f:facet>
-				<h:outputText value="#{entity.service.name}" />
-			</p:column>		
-			<p:column>
-				<f:facet name="header">
-					<h:outputText value="#{messages.script}" />
-				</f:facet>
-				<h:outputText value="#{entity.script.name}" />
-			</p:column>		
-		</p:dataTable>
+		<p:panel header="#{messages.saml_sp_service_configuration}">
+			<p:dataTable id="spDataTable" var="entity" value="#{listIdpConfigurationBean.serviceSpList}">
+				<p:column width="5%">
+					<f:facet name="header">
+						<h:outputText value="#{messages.id}" />
+					</f:facet>
+					<h:link outcome="edit-saml-service-sp.xhtml" value="#{entity.id}">
+	      				<f:param name="id" value="#{entity.id}"/>
+	    			</h:link>
+				</p:column>
+				<p:column>
+					<f:facet name="header">
+						<h:outputText value="#{messages.idp}" />
+					</f:facet>
+					<h:outputText value="#{(empty entity.idp.entityId ? 'All IDPs' : entity.idp.entityId)}" />
+				</p:column>		
+				<p:column>
+					<f:facet name="header">
+						<h:outputText value="#{messages.service}" />
+					</f:facet>
+					<h:outputText value="#{entity.service.name}" />
+				</p:column>		
+				<p:column>
+					<f:facet name="header">
+						<h:outputText value="#{messages.script}" />
+					</f:facet>
+					<h:outputText value="#{entity.script.name}" />
+				</p:column>		
+				<p:column>
+	       			<p:commandButton action="#{listIdpConfigurationBean.delete(entity)}" immediate="true" update="@form"
+	       				value="#{messages.delete}">
+	       				<p:confirm header="#{messages.confirm_header}" escape="false"
+	       					message="#{messages.delete_entry_confirm}" />
+	       			</p:commandButton>
+	       			<p:linkButton value="#{messages.edit}" outcome="edit-saml-service-sp.xhtml">
+	      				<f:param name="id" value="#{entity.id}"/>
+	       			</p:linkButton>
+	       		</p:column>
+			</p:dataTable>
+	
+	        <h:link outcome="edit-saml-service-sp.xhtml" value="#{messages.add_sp_service_config}"/>
 	
+		    <p:confirmDialog global="true" showEffect="fade" hideEffect="fade" closable="false" 
+		    	closeOnEscape="true" width="250">
+		        <p:commandButton value="#{messages.yes}" type="button" styleClass="ui-confirmdialog-yes"/>
+		        <p:commandButton value="#{messages.no}" type="button" styleClass="ui-confirmdialog-no"/>
+		    </p:confirmDialog>    
+		</p:panel>
 	</h:form>
 
 	</ui:define>
-- 
GitLab