mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-15 06:49:56 +00:00
changed removeRegatta to cause less issues due to sideeffects
This commit is contained in:
1 parent
f5ed139fb0
commit
db03b51bfa
5 files changed
+46
-41
No files matched your search
+26
-37
@@ -4630,45 +4630,34 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
|
||||
public void removeRegatta(RegattaIdentifier regattaIdentifier) {
|
||||
Regatta regatta = getService().getRegatta(regattaIdentifier);
|
||||
if (regatta != null) {
|
||||
getSecurityService().checkPermissionAndDeleteOwnershipForObjectRemoval(regatta, new Action() {
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
// if there were any tracked races, free all ownerships
|
||||
for (RaceDefinition race : regatta.getAllRaces()) {
|
||||
String typeRelativeObjectIdentifier = WildcardPermissionEncoder.encode(regatta.getName(),
|
||||
race.getName());
|
||||
QualifiedObjectIdentifier identifier = SecuredDomainType.TRACKED_RACE
|
||||
.getQualifiedObjectIdentifier(typeRelativeObjectIdentifier);
|
||||
getSecurityService().checkPermissionAndDeleteOwnershipForObjectRemoval(identifier,
|
||||
new ActionWithResult<Void>() {
|
||||
@Override
|
||||
public Void run() throws Exception {
|
||||
RegattaNameAndRaceName raceIdentifier = new RegattaNameAndRaceName(
|
||||
regatta.getName(), race.getName());
|
||||
ArrayList<RegattaAndRaceIdentifier> trackedRace = new ArrayList<>();
|
||||
trackedRace.add(raceIdentifier);
|
||||
removeAndUntrackRaces(trackedRace);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
// remove all leaderboards using the proper call that will clean and remove the owner as well
|
||||
Set<RegattaLeaderboard> leaderboardsToRemove = new HashSet<>();
|
||||
for (Leaderboard leaderboard : getService().getLeaderboards().values()) {
|
||||
if (leaderboard instanceof RegattaLeaderboard) {
|
||||
RegattaLeaderboard regattaLeaderboard = (RegattaLeaderboard) leaderboard;
|
||||
if (regattaLeaderboard.getRegatta() == regatta) {
|
||||
leaderboardsToRemove.add(regattaLeaderboard);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (RegattaLeaderboard regattaLeaderboardToRemove : leaderboardsToRemove) {
|
||||
removeLeaderboard(regattaLeaderboardToRemove.getName());
|
||||
}
|
||||
Set<QualifiedObjectIdentifier> objectsThatWillBeImplicitlyCleanedByRemoveRegatta = new HashSet<>();
|
||||
objectsThatWillBeImplicitlyCleanedByRemoveRegatta.add(regatta.getIdentifier());
|
||||
for (RaceDefinition race : regatta.getAllRaces()) {
|
||||
String typeRelativeObjectIdentifier = WildcardPermissionEncoder.encode(regatta.getName(),
|
||||
race.getName());
|
||||
QualifiedObjectIdentifier identifier = SecuredDomainType.TRACKED_RACE
|
||||
.getQualifiedObjectIdentifier(typeRelativeObjectIdentifier);
|
||||
objectsThatWillBeImplicitlyCleanedByRemoveRegatta.add(identifier);
|
||||
}
|
||||
for (Leaderboard leaderboard : getService().getLeaderboards().values()) {
|
||||
if (leaderboard instanceof RegattaLeaderboard) {
|
||||
RegattaLeaderboard regattaLeaderboard = (RegattaLeaderboard) leaderboard;
|
||||
if (regattaLeaderboard.getRegatta() == regatta) {
|
||||
objectsThatWillBeImplicitlyCleanedByRemoveRegatta.add(regattaLeaderboard.getIdentifier());
|
||||
}
|
||||
getService().apply(new RemoveRegatta(regattaIdentifier));
|
||||
}
|
||||
});
|
||||
}
|
||||
// check if we can delete everything RemoveRegatta will remove
|
||||
for (QualifiedObjectIdentifier toRemovePermissionObjects : objectsThatWillBeImplicitlyCleanedByRemoveRegatta) {
|
||||
getSecurityService().checkCurrentUserDeletePermission(toRemovePermissionObjects);
|
||||
}
|
||||
// we have all permissions, execute
|
||||
getService().apply(new RemoveRegatta(regattaIdentifier));
|
||||
// cleanup the Ownership and ACLs
|
||||
for (QualifiedObjectIdentifier toRemovePermissionObjects : objectsThatWillBeImplicitlyCleanedByRemoveRegatta) {
|
||||
getSecurityService().deleteOwnership(toRemovePermissionObjects);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-3
@@ -46,7 +46,6 @@ import com.sap.sailing.domain.tracking.TrackedRegatta;
|
||||
import com.sap.sailing.domain.tracking.impl.EmptyWindStore;
|
||||
import com.sap.sailing.server.impl.RacingEventServiceImpl;
|
||||
import com.sap.sailing.server.operationaltransformation.CreateFlexibleLeaderboard;
|
||||
import com.sap.sailing.server.operationaltransformation.RemoveAndUntrackRace;
|
||||
import com.sap.sailing.server.operationaltransformation.RemoveEvent;
|
||||
import com.sap.sailing.server.operationaltransformation.RemoveLeaderboard;
|
||||
import com.sap.sailing.server.operationaltransformation.RemoveLeaderboardGroup;
|
||||
@@ -120,8 +119,6 @@ public class RemoveLeaderboardTest {
|
||||
public void testRaceLogOfRaceColumnInSeriesDetachedWhenRegattaIsRemoved() {
|
||||
regatta.getRaceColumnByName(R1).setTrackedRace(defaultFleet, trackedRace);
|
||||
assertEquals(1, Util.size(trackedRace.getAttachedRaceLogs()));
|
||||
// removal of races is no longer done automatically, due to restrictions based on permission-vertical
|
||||
server.apply(new RemoveAndUntrackRace(trackedRace.getRaceIdentifier()));
|
||||
server.apply(new RemoveRegatta(new RegattaName(regatta.getName())));
|
||||
assertTrue(Util.isEmpty(trackedRace.getAttachedRaceLogs()));
|
||||
}
|
||||
|
||||
+13
-1
@@ -2503,11 +2503,23 @@ public class RacingEventServiceImpl implements RacingEventService, ClearStateTes
|
||||
|
||||
@Override
|
||||
public void removeRegatta(Regatta regatta) throws MalformedURLException, IOException, InterruptedException {
|
||||
Set<RegattaLeaderboard> leaderboardsToRemove = new HashSet<>();
|
||||
for (Leaderboard leaderboard : getLeaderboards().values()) {
|
||||
if (leaderboard instanceof RegattaLeaderboard) {
|
||||
RegattaLeaderboard regattaLeaderboard = (RegattaLeaderboard) leaderboard;
|
||||
if (regattaLeaderboard.getRegatta() == regatta) {
|
||||
leaderboardsToRemove.add(regattaLeaderboard);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (RegattaLeaderboard regattaLeaderboardToRemove : leaderboardsToRemove) {
|
||||
removeLeaderboard(regattaLeaderboardToRemove.getName());
|
||||
}
|
||||
// avoid ConcurrentModificationException by copying the races to remove:
|
||||
Set<RaceDefinition> racesToRemove = new HashSet<>();
|
||||
Util.addAll(regatta.getAllRaces(), racesToRemove);
|
||||
for (RaceDefinition race : racesToRemove) {
|
||||
// FIXME can this be removed//moved to the removeRace part?
|
||||
removeRace(regatta, race);
|
||||
mongoObjectFactory.removeRegattaForRaceID(race.getName(), regatta);
|
||||
persistentRegattasForRaceIDs.remove(race.getId().toString());
|
||||
}
|
||||
|
||||
@@ -375,6 +375,8 @@ public interface SecurityService extends ReplicableWithObjectInputStream<Replica
|
||||
|
||||
void checkCurrentUserDeletePermission(WithQualifiedObjectIdentifier object);
|
||||
|
||||
void checkCurrentUserDeletePermission(QualifiedObjectIdentifier object);
|
||||
|
||||
void checkCurrentUserExplicitPermissions(WithQualifiedObjectIdentifier object, HasPermissions.Action... actions);
|
||||
|
||||
/**
|
||||
|
||||
@@ -1898,6 +1898,11 @@ public class SecurityServiceImpl implements ReplicableSecurityService, ClearStat
|
||||
object.getIdentifier().getTypeRelativeObjectIdentifier()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkCurrentUserDeletePermission(QualifiedObjectIdentifier identifier) {
|
||||
SecurityUtils.getSubject().checkPermission(identifier.getStringPermission(DefaultActions.DELETE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkCurrentUserExplicitPermissions(WithQualifiedObjectIdentifier object, HasPermissions.Action... actions) {
|
||||
if (object == null || actions.length == 0) {
|
||||
|
||||
Reference in new issue
Block a user