Skip to content
Browse files

BACKLOG-329 & BACKLOG-437 clean up before deleting team

- BACKLOG-329: delete links to external groups
- BACKLOG-437: accepted invitations were not deleted
  • Loading branch information...
1 parent 56b0e65 commit b4b40e4da8adfd1f089425b4b9e103d038c487e7 @jashaj jashaj committed May 3, 2012
View
8 coin-teams-war/src/main/java/nl/surfnet/coin/teams/control/DetailTeamController.java
@@ -162,7 +162,7 @@ public String start(ModelMap modelMap, HttpServletRequest request)
modelMap.addAttribute("onlyAdmin", onlyAdmin);
modelMap.addAttribute("invitations",
- teamInviteService.findInvitationsForTeam(team));
+ teamInviteService.findInvitationsForTeamExcludeAccepted(team));
int offset = getOffset(request);
Pager membersPager = new Pager(team.getMembers().size(), offset, PAGESIZE);
@@ -306,10 +306,14 @@ public RedirectView deleteTeam(ModelMap modelMap, HttpServletRequest request,
if (member.getRoles().contains(Role.Admin)) {
// Delete the team
Team team = grouperTeamService.findTeamById(teamId);
- final List<Invitation> invitationsForTeam = teamInviteService.findInvitationsForTeam(team);
+ final List<Invitation> invitationsForTeam = teamInviteService.findAllInvitationsForTeam(team);
for (Invitation invitation : invitationsForTeam) {
teamInviteService.delete(invitation);
}
+ final List<TeamExternalGroup> teamExternalGroups = teamExternalGroupDao.getByTeamIdentifier(teamId);
+ for (TeamExternalGroup teamExternalGroup : teamExternalGroups) {
+ teamExternalGroupDao.delete(teamExternalGroup);
+ }
grouperTeamService.deleteTeam(teamId);
status.setComplete();
View
12 coin-teams-war/src/main/java/nl/surfnet/coin/teams/service/TeamInviteService.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2011 SURFnet bv, The Netherlands
+ * Copyright 2012 SURFnet bv, The Netherlands
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -61,7 +61,15 @@
* @param team {@link Team}
* @return List of Invitation's, can be empty.
*/
- List<Invitation> findInvitationsForTeam(Team team);
+ List<Invitation> findAllInvitationsForTeam(Team team);
+
+ /**
+ * Searches for {@link Invitation}'s for a {@link Team}.
+ *
+ * @param team {@link Team}
+ * @return List of Invitation's, can be empty.
+ */
+ List<Invitation> findInvitationsForTeamExcludeAccepted(Team team);
/**
* Searches for pending {@link Invitation}'s by email address
View
15 ...-war/src/main/java/nl/surfnet/coin/teams/service/impl/TeamInviteServiceHibernateImpl.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2011 SURFnet bv, The Netherlands
+ * Copyright 2012 SURFnet bv, The Netherlands
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -97,7 +97,18 @@ public Invitation findAllInvitationById(final String invitationId) {
*/
@SuppressWarnings({"unchecked"})
@Override
- public List<Invitation> findInvitationsForTeam(Team team) {
+ public List<Invitation> findAllInvitationsForTeam(Team team) {
+ cleanupExpiredInvitations();
+ Criteria criteria = createCriteria();
+ criteria.add(Restrictions.eq("teamId", team.getId()));
+ criteria.addOrder(Order.asc("email"));
+ criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
+ return criteria.list();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public List<Invitation> findInvitationsForTeamExcludeAccepted(Team team) {
cleanupExpiredInvitations();
Criteria criteria = createCriteria();
criteria.add(Restrictions.eq("teamId", team.getId()));
View
7 coin-teams-war/src/test/java/nl/surfnet/coin/teams/control/DetailTeamControllerTest.java
@@ -354,7 +354,7 @@ public void testDeleteTeamHappyFlow() throws Exception {
team.setName("team-1");
TeamInviteService teamInviteService = mock(TeamInviteService.class);
- when(teamInviteService.findInvitationsForTeam(team)).thenReturn(Collections.<Invitation>emptyList());
+ when(teamInviteService.findAllInvitationsForTeam(team)).thenReturn(Collections.<Invitation>emptyList());
autoWireMock(detailTeamController, teamInviteService, TeamInviteService.class);
@@ -363,6 +363,11 @@ public void testDeleteTeamHappyFlow() throws Exception {
when(grouperTeamService.findTeamById("team-1")).thenReturn(team);
autoWireMock(detailTeamController, grouperTeamService, GrouperTeamService.class);
+
+ TeamExternalGroupDao teamExternalGroupDao = mock(TeamExternalGroupDao.class);
+ when(teamExternalGroupDao.getByTeamIdentifier("team-1")).thenReturn(Collections.<TeamExternalGroup>emptyList());
+ autoWireMock(detailTeamController, teamExternalGroupDao, TeamExternalGroupDao.class);
+
autoWireRemainingResources(detailTeamController);
RedirectView result = detailTeamController.deleteTeam(getModelMap(),
View
7 .../src/test/java/nl/surfnet/coin/teams/service/impl/TeamInviteServiceHibernateImplTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2011 SURFnet bv, The Netherlands
+ * Copyright 2012 SURFnet bv, The Netherlands
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,6 +29,7 @@
import nl.surfnet.coin.teams.domain.Invitation;
import nl.surfnet.coin.teams.domain.Team;
import nl.surfnet.coin.teams.service.TeamInviteService;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -127,11 +128,11 @@ public void testFindInvitationsForTeam() throws Exception {
"coincalendar@yahoo.com", team1.getId());
Invitation invitation3 = new Invitation(
"coincalendar@yahoo.com", team2.getId());
- assertEquals(0, teamInviteService.findInvitationsForTeam(team1).size());
+ assertEquals(0, teamInviteService.findAllInvitationsForTeam(team1).size());
teamInviteService.saveOrUpdate(invitation1);
teamInviteService.saveOrUpdate(invitation2);
teamInviteService.saveOrUpdate(invitation3);
- assertEquals(2, teamInviteService.findInvitationsForTeam(team1).size());
+ assertEquals(2, teamInviteService.findAllInvitationsForTeam(team1).size());
assertEquals(3, teamInviteService.findAll().size());
}

0 comments on commit b4b40e4

Please sign in to comment.
Something went wrong with that request. Please try again.