Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor code #534

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,8 @@ public ResponseEntity<Map<UUID, UUID>> duplicateModifications(@Parameter(descrip
@ApiResponse(responseCode = "200", description = "The network modifications were stashed")
public ResponseEntity<Void> stashNetworkModifications(
@Parameter(description = "Network modification UUIDs") @RequestParam("uuids") List<UUID> networkModificationUuids,
@Parameter(description = "Group UUID") @RequestParam("groupUuid") UUID groupUuid,
@Parameter(description = "stash or unstash network modifications") @RequestParam(name = "stashed", defaultValue = "true") Boolean stashed) {
if (Boolean.TRUE.equals(stashed)) {
networkModificationService.stashNetworkModifications(networkModificationUuids);
} else {
networkModificationService.restoreNetworkModifications(networkModificationUuids);
}
@Parameter(description = "stash or restore network modifications") @RequestParam(name = "stashed", defaultValue = "true") Boolean stashed) {
networkModificationService.stashNetworkModifications(networkModificationUuids, stashed);
return ResponseEntity.ok().build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,23 +388,12 @@ public List<ModificationInfos> getActiveModificationsInfos(@NonNull UUID groupUu
}

@Transactional
public void stashNetworkModifications(@NonNull List<UUID> modificationUuids) {
public void stashNetworkModifications(@NonNull List<UUID> modificationUuids, Boolean stashed) {
for (UUID modificationUuid : modificationUuids) {
ModificationEntity modificationEntity = this.modificationRepository
.findById(modificationUuid)
.orElseThrow(() -> new NetworkModificationException(MODIFICATION_NOT_FOUND, String.format(MODIFICATION_NOT_FOUND_MESSAGE, modificationUuid)));
modificationEntity.setStashed(true);
this.modificationRepository.save(modificationEntity);
}
}

@Transactional
public void restoreNetworkModifications(@NonNull List<UUID> modificationUuids) {
for (UUID modificationUuid : modificationUuids) {
ModificationEntity modificationEntity = this.modificationRepository
.findById(modificationUuid)
.orElseThrow(() -> new NetworkModificationException(MODIFICATION_NOT_FOUND, String.format(MODIFICATION_NOT_FOUND_MESSAGE, modificationUuid)));
modificationEntity.setStashed(false);
modificationEntity.setStashed(stashed);
this.modificationRepository.save(modificationEntity);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,8 @@ public void updateNetworkModification(@NonNull UUID modificationUuid, @NonNull M
}

@Transactional
public void stashNetworkModifications(@NonNull List<UUID> modificationUuids) {
networkModificationRepository.stashNetworkModifications(modificationUuids);
}

@Transactional
public void restoreNetworkModifications(@NonNull List<UUID> modificationUuids) {
networkModificationRepository.restoreNetworkModifications(modificationUuids);
public void stashNetworkModifications(@NonNull List<UUID> modificationUuids, boolean stashed) {
networkModificationRepository.stashNetworkModifications(modificationUuids, stashed);
}

// No transactional because we need to save modification in DB also in case of error
Expand Down
Loading