Skip to content

Commit

Permalink
fixing circular dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
hylstonnb committed Jul 28, 2023
1 parent cdbe42a commit 3d1e098
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
package com.box.l10n.mojito.boxsdk;

import com.box.l10n.mojito.service.boxsdk.BoxSDKServiceConfigEntityService;
import org.springframework.beans.factory.annotation.Autowired;
import com.box.l10n.mojito.service.boxsdk.BoxSDKServiceConfigEntityRepository;
import org.springframework.stereotype.Component;

/** @author wyau */
/**
* @author wyau
*/
@Component
public class BoxSDKServiceConfigProvider {

@Autowired BoxSDKServiceConfigFromProperties boxSDKServiceConfigFromProperties;
private final BoxSDKServiceConfigFromProperties boxSDKServiceConfigFromProperties;

@Autowired BoxSDKServiceConfigEntityService boxSDKServiceConfigEntityService;
private final BoxSDKServiceConfigEntityRepository boxSDKServiceConfigEntityRepository;

public BoxSDKServiceConfigProvider(
BoxSDKServiceConfigFromProperties boxSDKServiceConfigFromProperties,
BoxSDKServiceConfigEntityRepository boxSDKServiceConfigEntityRepository) {
this.boxSDKServiceConfigFromProperties = boxSDKServiceConfigFromProperties;
this.boxSDKServiceConfigEntityRepository = boxSDKServiceConfigEntityRepository;
}

/**
* @return The config to be used
Expand All @@ -22,7 +30,7 @@ public BoxSDKServiceConfig getConfig() throws BoxSDKServiceException {
if (boxSDKServiceConfigFromProperties.isUseConfigsFromProperties()) {
result = boxSDKServiceConfigFromProperties;
} else {
result = boxSDKServiceConfigEntityService.getBoxSDKServiceConfigEntity();
result = boxSDKServiceConfigEntityRepository.findFirstByOrderByIdAsc();

if (result == null) {
throw new BoxSDKServiceException(
Expand Down
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 @@ -6,19 +6,25 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/** @author jaurambault */
/**
* @author jaurambault
*/
@Component
public class DeleteBranchJob extends QuartzPollableJob<DeleteBranchJobInput, Void> {

/** 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 3d1e098

Please sign in to comment.