-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
67 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
webapp/src/main/java/com/box/l10n/mojito/service/branch/DeleteBranchService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.box.l10n.mojito.service.branch; | ||
|
||
import static org.slf4j.LoggerFactory.getLogger; | ||
|
||
import com.box.l10n.mojito.entity.Branch; | ||
import com.box.l10n.mojito.service.asset.AssetService; | ||
import java.util.Set; | ||
import org.slf4j.Logger; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* Service to manage deletion of {@link Branch}es. | ||
* | ||
* @author jeanaurambault | ||
*/ | ||
@Service | ||
public class DeleteBranchService { | ||
|
||
/** logger */ | ||
static Logger logger = getLogger(DeleteBranchService.class); | ||
|
||
private final BranchRepository branchRepository; | ||
|
||
private final AssetService assetService; | ||
|
||
public DeleteBranchService(BranchRepository branchRepository, AssetService assetService) { | ||
this.branchRepository = branchRepository; | ||
this.assetService = assetService; | ||
} | ||
|
||
public void deleteBranch(Long repositoryId, Long branchId) { | ||
deleteBranchAsset(branchId, repositoryId); | ||
|
||
Branch branch = branchRepository.findById(branchId).orElse(null); | ||
logger.debug("Mark branch {} as deleted", branch.getName()); | ||
branch.setDeleted(true); | ||
branchRepository.save(branch); | ||
} | ||
|
||
public void deleteBranchAsset(Long branchId, Long repositoryId) { | ||
Set<Long> assetIds = assetService.findAllAssetIds(repositoryId, null, false, false, branchId); | ||
assetService.deleteAssetsOfBranch(assetIds, branchId); | ||
} | ||
} |