diff --git a/crud/src/main/java/org/openmbee/mms/crud/services/DefaultBranchService.java b/crud/src/main/java/org/openmbee/mms/crud/services/DefaultBranchService.java index 72201fb06..365bc3379 100644 --- a/crud/src/main/java/org/openmbee/mms/crud/services/DefaultBranchService.java +++ b/crud/src/main/java/org/openmbee/mms/crud/services/DefaultBranchService.java @@ -114,7 +114,12 @@ public RefsResponse getBranch(String projectId, String id) { public RefJson createBranch(String projectId, RefJson branch) { Instant now = Instant.now(); ContextHolder.setContext(projectId); - Branch b = new Branch(); + + Optional branchesOption = this.branchRepository.findByBranchId(branch.getId()); + Branch b = branchesOption.orElseGet(Branch::new); + if (b.isDeleted()) { + throw new BadRequestException("Bad Request Error: Branch was previously deleted."); + } b.setBranchId(branch.getId()); b.setBranchName(branch.getName());