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

make groups deletable for group admin

parent 8293b410
......@@ -19,6 +19,7 @@ import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import edu.kit.scc.webreg.dao.ServiceGroupFlagDao;
import edu.kit.scc.webreg.entity.GroupStatus;
import edu.kit.scc.webreg.entity.ServiceBasedGroupEntity;
import edu.kit.scc.webreg.entity.ServiceEntity;
import edu.kit.scc.webreg.entity.ServiceGroupFlagEntity;
......@@ -63,8 +64,10 @@ public class JpaServiceGroupFlagDao extends JpaBaseDao<ServiceGroupFlagEntity, L
public List<ServiceGroupFlagEntity> findLocalGroupsForService(ServiceEntity service) {
return em.createQuery("select gf from ServiceGroupFlagEntity gf, LocalGroupEntity g "
+ "where gf.group = g"
+ " and gf.service = :service")
.setParameter("service", service).getResultList();
+ " and gf.service = :service and (g.groupStatus = :groupStatus or g.groupStatus is null)")
.setParameter("service", service)
.setParameter("groupStatus", GroupStatus.ACTIVE)
.getResultList();
}
@Override
......
......@@ -24,6 +24,7 @@ import org.slf4j.Logger;
import edu.kit.scc.webreg.entity.EventType;
import edu.kit.scc.webreg.entity.GroupEntity;
import edu.kit.scc.webreg.entity.GroupStatus;
import edu.kit.scc.webreg.entity.LocalGroupEntity;
import edu.kit.scc.webreg.entity.ServiceEntity;
import edu.kit.scc.webreg.entity.ServiceGroupFlagEntity;
......@@ -128,14 +129,7 @@ public class GroupAdminShowLocalGroupBean implements Serializable {
flag = groupFlagService.save(flag);
}
HashSet<GroupEntity> gl = new HashSet<GroupEntity>();
gl.add(entity);
MultipleGroupEvent mge = new MultipleGroupEvent(gl);
try {
eventSubmitter.submit(mge, EventType.GROUP_UPDATE, "user-" + sessionManager.getUserId());
} catch (EventSubmitException e) {
logger.warn("Exeption", e);
}
fireGroupChangeEvent();
messageGenerator.addResolvedInfoMessage("item_saved", "item_saved_long", true);
......@@ -146,6 +140,36 @@ public class GroupAdminShowLocalGroupBean implements Serializable {
return ViewIds.GROUP_ADMIN_EDIT_LOCAL_GROUP + "?faces-redirect=true&serviceId=" + serviceId + "&groupId=" + groupId;
}
public String deleteGroup() {
if (editable == false) {
return "";
}
entity.setGroupStatus(GroupStatus.DELETED);
for (ServiceGroupFlagEntity flag : groupFlagList) {
flag.setStatus(ServiceGroupStatus.TO_DELETE);
groupFlagService.save(flag);
}
entity = service.save(entity);
fireGroupChangeEvent();
return ViewIds.GROUP_ADMIN_INDEX + "?faces-redirect=true&serviceId=" + serviceId;
}
public void fireGroupChangeEvent() {
HashSet<GroupEntity> gl = new HashSet<GroupEntity>();
gl.add(entity);
MultipleGroupEvent mge = new MultipleGroupEvent(gl);
try {
eventSubmitter.submit(mge, EventType.GROUP_UPDATE, "user-" + sessionManager.getUserId());
} catch (EventSubmitException e) {
logger.warn("Exeption", e);
}
}
public LocalGroupEntity getEntity() {
return entity;
}
......
......@@ -40,6 +40,9 @@
<h:outputText value="#{messages.gid_number}:"/>
<h:outputText value="#{groupAdminShowLocalGroupBean.entity.gidNumber}"/>
<h:outputText value="#{messages.status}:"/>
<h:outputText value="#{groupAdminShowLocalGroupBean.entity.groupStatus}"/>
<h:outputText value="#{messages.services}:"/>
<p:dataList var="flag" value="#{groupAdminShowLocalGroupBean.groupFlagList}">
<h:outputText value="#{flag.service.name}" />
......@@ -88,6 +91,14 @@
</p:panel>
</div>
<br/>
<div id="panelInline">
<p:panel header="#{messages.tools}">
<p:commandButton id="delGrp" action="#{groupAdminShowLocalGroupBean.deleteGroup()}" value="#{messages.delete_group}"
style="color: red;" ajax="false" disabled="#{not groupAdminShowLocalGroupBean.editable}" />
</p:panel>
</div>
</h:form>
</ui:define>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment