Skip to content

Commit

Permalink
BranchService circular dependencies fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hylstonnb committed Jul 31, 2023
1 parent 98b6029 commit 8c096c8
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.box.l10n.mojito.entity.security.user.User;
import com.box.l10n.mojito.quartz.QuartzJobInfo;
import com.box.l10n.mojito.quartz.QuartzPollableTaskScheduler;
import com.box.l10n.mojito.service.asset.AssetService;
import com.box.l10n.mojito.service.pollableTask.PollableFuture;
import java.text.MessageFormat;
import java.util.Set;
Expand All @@ -30,8 +29,6 @@ public class BranchService {

@Autowired BranchRepository branchRepository;

@Autowired AssetService assetService;

@Autowired QuartzPollableTaskScheduler quartzPollableTaskScheduler;

public Branch createBranch(
Expand Down Expand Up @@ -84,18 +81,4 @@ public PollableFuture<Void> asyncDeleteBranch(Long repositoryId, Long branchId)
.build();
return quartzPollableTaskScheduler.scheduleJob(quartzJobInfo);
}

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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.box.l10n.mojito.quartz.QuartzPollableJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/** @author jaurambault */
Expand All @@ -13,12 +12,16 @@ public class DeleteBranchJob extends QuartzPollableJob<DeleteBranchJobInput, Voi
/** logger */
static Logger logger = LoggerFactory.getLogger(DeleteBranchJob.class);

@Autowired BranchService branchService;
private final DeleteBranchService deleteBranchService;

public DeleteBranchJob(DeleteBranchService deleteBranchService) {
this.deleteBranchService = deleteBranchService;
}

@Override
public Void call(DeleteBranchJobInput input) throws Exception {
logger.debug("DeleteAssetsOfBranchJob");
branchService.deleteBranch(input.getRepositoryId(), input.getBranchId());
deleteBranchService.deleteBranch(input.getRepositoryId(), input.getBranchId());
return null;
}
}
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);
}
}

0 comments on commit 8c096c8

Please sign in to comment.