Skip to content

Commit fb3efba

Browse files
authored
Merge pull request #4117 from sarkapalkovicova/block_destination
fix(core): ignore already blocked destinations
2 parents dd7500e + ad1774d commit fb3efba

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

perun-core/src/main/java/cz/metacentrum/perun/core/api/ServicesManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public interface ServicesManager {
8989
* @param richDestinations the list of rich destinations
9090
*
9191
*/
92-
void blockServicesOnDestinations(PerunSession perunSession, List<RichDestination> richDestinations) throws PrivilegeException, DestinationNotExistsException, ServiceAlreadyBannedException, FacilityNotExistsException;
92+
void blockServicesOnDestinations(PerunSession perunSession, List<RichDestination> richDestinations) throws PrivilegeException, DestinationNotExistsException, FacilityNotExistsException;
9393

9494
/**
9595
* Block all services currently assigned on this facility.

perun-core/src/main/java/cz/metacentrum/perun/core/entry/ServicesManagerEntry.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,12 @@ public void blockServiceOnDestination(PerunSession sess, Service service, int de
9898
}
9999

100100
@Override
101-
public void blockServicesOnDestinations(PerunSession sess, List<RichDestination> richDestinations) throws PrivilegeException, DestinationNotExistsException, ServiceAlreadyBannedException, FacilityNotExistsException {
101+
public void blockServicesOnDestinations(PerunSession sess, List<RichDestination> richDestinations) throws PrivilegeException, DestinationNotExistsException, FacilityNotExistsException {
102102
for (RichDestination richDestination : richDestinations) {
103-
blockServiceOnDestination(sess, richDestination.getService(), richDestination.getId());
103+
try {
104+
blockServiceOnDestination(sess, richDestination.getService(), richDestination.getId());
105+
} catch (ServiceAlreadyBannedException ignored) {
106+
}
104107
}
105108
}
106109

perun-core/src/test/java/cz/metacentrum/perun/core/entry/ServicesManagerEntryIntegrationTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,31 @@ public void blockAndUnblockServiceOnDestinations() throws Exception {
11921192
assertFalse("Service should NOT be blocked on the richDestination3", perun.getServicesManager().isServiceBlockedOnDestination(sess, service2, destination3.getId()));
11931193
}
11941194

1195+
@Test
1196+
public void blockServiceOnDestinationsAndIgnoreAlreadyBlocked() throws Exception {
1197+
System.out.println(CLASS_NAME + "blockServiceOnDestinationsAndIgnoreAlreadyBlocked");
1198+
1199+
facility = setUpFacility();
1200+
service = setUpService();
1201+
List<Destination> destinations = setUpDestinations();
1202+
1203+
Destination destination1 = perun.getServicesManager().addDestination(sess, service, facility, destinations.get(0));
1204+
RichDestination richDestination1 = new RichDestination(destination1, facility, service);
1205+
Destination destination2 = perun.getServicesManager().addDestination(sess, service, facility, destinations.get(1));
1206+
RichDestination richDestination2 = new RichDestination(destination2, facility, service);
1207+
1208+
List<RichDestination> serviceDestinations = perun.getServicesManagerBl().getAllRichDestinations(sess, facility);
1209+
assertTrue(serviceDestinations.contains(richDestination1));
1210+
assertTrue( serviceDestinations.contains(richDestination2));
1211+
1212+
perun.getServicesManager().blockServiceOnDestination(sess, service, richDestination1.getId());
1213+
assertTrue(perun.getServicesManager().isServiceBlockedOnDestination(sess, service, richDestination1.getId()));
1214+
1215+
List<RichDestination> destinationsToBlock = Arrays.asList(richDestination1, richDestination2);
1216+
perun.getServicesManager().blockServicesOnDestinations(sess, destinationsToBlock);
1217+
assertTrue(perun.getServicesManager().isServiceBlockedOnDestination(sess, service, richDestination2.getId()));
1218+
}
1219+
11951220
@Test
11961221
public void blockAndUnblockServicesOnFacility() throws Exception {
11971222
System.out.println(CLASS_NAME + "blockAndUnblockServicesOnFacility");

0 commit comments

Comments
 (0)