forked from Gitlink/microservices
feat(制品库功能开发): 制品文件及制品文件夹删除接口开发(基于Nexus接口/service/extdirect进行改造)
1. 删除制品接口开发和删除制品文件接口开发: - 调用Nexus删除对应的制品或制品文件 - 获取Nexus删除接口返回的制品文件路径列表 - 根据制品文件路径遍历数据库中是否有对应的制品文件记录 - 若存在记录则删除数据库中的记录
This commit is contained in:
parent
eb79328192
commit
de31f1c563
|
|
@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 制品库-制品Controller
|
||||
|
|
@ -106,6 +107,32 @@ public class PmsProductLibraryComponentController extends BaseController {
|
|||
return success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除制品文件
|
||||
*/
|
||||
@DeleteMapping("/{repoName}/deleteAsset/{assetId}")
|
||||
@ApiOperation(value = "删除制品文件")
|
||||
public AjaxResult deleteAsset(@PathVariable String enterpriseIdentifier,
|
||||
@PathVariable("repoName") String repoName,
|
||||
@PathVariable("assetId") String assetId) {
|
||||
NexusComponentResultVo<List<String>> result =
|
||||
pmsProductLibraryComponentService.deleteAssetByAssetId(enterpriseIdentifier, repoName, assetId);
|
||||
return success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除制品
|
||||
*/
|
||||
@DeleteMapping("/{repoName}/deleteComponent/{componentId}")
|
||||
@ApiOperation(value = "删除制品")
|
||||
public AjaxResult deleteComponent(@PathVariable String enterpriseIdentifier,
|
||||
@PathVariable("repoName") String repoName,
|
||||
@PathVariable("componentId") String componentId) {
|
||||
NexusComponentResultVo<List<String>> result =
|
||||
pmsProductLibraryComponentService.deleteComponentByComponentId(enterpriseIdentifier, repoName, componentId);
|
||||
return success(result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 上传制品-maven制品
|
||||
|
|
|
|||
|
|
@ -120,4 +120,32 @@ public class NexusComponentSearchVo<T> {
|
|||
target.setData(data);
|
||||
return target;
|
||||
}
|
||||
|
||||
public static NexusComponentSearchVo<String> toDeleteAsset(String nexusRepoName, String assetId, Long tid) {
|
||||
NexusComponentSearchVo<String> target = new NexusComponentSearchVo<>();
|
||||
target.setAction("coreui_Component");
|
||||
target.setMethod("deleteAsset");
|
||||
target.setType("rpc");
|
||||
target.setTid(tid);
|
||||
List<String> data = new ArrayList<>();
|
||||
data.add(assetId);
|
||||
data.add(nexusRepoName);
|
||||
target.setData(data);
|
||||
return target;
|
||||
}
|
||||
|
||||
public static NexusComponentSearchVo<String> toDeleteComponent(String nexusRepoName, String componentId, Long tid) {
|
||||
NexusComponentSearchVo<String> target = new NexusComponentSearchVo<>();
|
||||
target.setAction("coreui_Component");
|
||||
target.setMethod("deleteComponent");
|
||||
target.setType("rpc");
|
||||
target.setTid(tid);
|
||||
List<String> data = new ArrayList<>();
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("id", componentId);
|
||||
jsonObject.put("repositoryName", nexusRepoName);
|
||||
data.add(jsonObject.toJSONString());
|
||||
target.setData(data);
|
||||
return target;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ package com.microservices.pms.productLibrary.service;
|
|||
import com.microservices.pms.productLibrary.domain.PmsProductLibraryComponent;
|
||||
import com.microservices.pms.productLibrary.domain.vo.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 制品库-制品Service接口
|
||||
*
|
||||
|
|
@ -111,4 +113,16 @@ public interface IPmsProductLibraryComponentService {
|
|||
NexusComponentResultVo<Boolean> getCanDeleteComponentByComponentId(String enterpriseIdentifier, String repoName, String componentId);
|
||||
|
||||
NexusComponentResultVo<Boolean> getCanDeleteAssetByAssetId(String enterpriseIdentifier, String repoName, String assetId);
|
||||
|
||||
/**
|
||||
* 删除制品
|
||||
*
|
||||
* @param enterpriseIdentifier 企业标识
|
||||
* @param repoName 制品库名称
|
||||
* @param assetId 制品文件
|
||||
* @return 删除文件列表
|
||||
*/
|
||||
NexusComponentResultVo<List<String>> deleteAssetByAssetId(String enterpriseIdentifier, String repoName, String assetId);
|
||||
|
||||
NexusComponentResultVo<List<String>> deleteComponentByComponentId(String enterpriseIdentifier, String repoName, String componentId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -209,6 +209,66 @@ public class PmsProductLibraryComponentServiceImpl implements IPmsProductLibrary
|
|||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NexusComponentResultVo<List<String>> deleteAssetByAssetId(String enterpriseIdentifier, String repoName, String assetId) {
|
||||
PmsProductLibraryRepositories pmsProductLibraryRepositories =
|
||||
pmsProductLibraryRepositoriesService.selectPmsProductLibraryRepositoriesByName(enterpriseIdentifier, repoName);
|
||||
NexusComponentSearchVo<String> nexusComponentSearchVo =
|
||||
NexusComponentSearchVo.toDeleteAsset(pmsProductLibraryRepositories.getNexusRepositoriesName(), assetId, nexusRequestHelper.getNexusTid());
|
||||
NexusComponentResultVo<List<String>> assetResultDataVo =
|
||||
nexusRequestHelper.doRequestToJavaObjectList(
|
||||
NexusRequestUrl.DO_OPERATION(),
|
||||
JSONObject.from(nexusComponentSearchVo),
|
||||
NexusComponentResultVo.class,
|
||||
String.class
|
||||
);
|
||||
deleteDatabaseAsset(pmsProductLibraryRepositories, assetResultDataVo);
|
||||
return assetResultDataVo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NexusComponentResultVo<List<String>> deleteComponentByComponentId(String enterpriseIdentifier, String repoName, String componentId) {
|
||||
PmsProductLibraryRepositories pmsProductLibraryRepositories =
|
||||
pmsProductLibraryRepositoriesService.selectPmsProductLibraryRepositoriesByName(enterpriseIdentifier, repoName);
|
||||
NexusComponentSearchVo<String> nexusComponentSearchVo =
|
||||
NexusComponentSearchVo.toDeleteComponent(pmsProductLibraryRepositories.getNexusRepositoriesName(), componentId, nexusRequestHelper.getNexusTid());
|
||||
NexusComponentResultVo<List<String>> assetResultDataVo =
|
||||
nexusRequestHelper.doRequestToJavaObjectList(
|
||||
NexusRequestUrl.DO_OPERATION(),
|
||||
JSONObject.from(nexusComponentSearchVo),
|
||||
NexusComponentResultVo.class,
|
||||
String.class
|
||||
);
|
||||
deleteDatabaseAsset(pmsProductLibraryRepositories, assetResultDataVo);
|
||||
return assetResultDataVo;
|
||||
}
|
||||
|
||||
private void deleteDatabaseAsset(PmsProductLibraryRepositories pmsProductLibraryRepositories, NexusComponentResultVo<List<String>> assetResultDataVo) {
|
||||
// 当制品库格式为RAW或者Maven时,需检查数据库中是否存在记录,存在记录则需要进行删除
|
||||
if (ProductLibraryRepositoriesFormatEnum.isNexusRaw(pmsProductLibraryRepositories.getFormat())
|
||||
|| ProductLibraryRepositoriesFormatEnum.MAVEN.getKey().equals(pmsProductLibraryRepositories.getFormat())) {
|
||||
|
||||
if (assetResultDataVo != null && assetResultDataVo.getResult() != null) {
|
||||
NexusComponentResultStateVo<List<String>> nexusComponentResultStateVo = assetResultDataVo.getResult();
|
||||
if (nexusComponentResultStateVo.getSuccess()) {
|
||||
List<String> deletePathList = nexusComponentResultStateVo.getData();
|
||||
for (String deletePath : deletePathList) {
|
||||
// 检查数据库中是否已存在该制品文件记录
|
||||
PmsProductLibraryComponent pmsProductLibraryComponent =
|
||||
pmsProductLibraryComponentMapper.selectPmsProductLibraryComponentByPath(
|
||||
deletePath,
|
||||
pmsProductLibraryRepositories.getName(),
|
||||
pmsProductLibraryRepositories.getPmsEnterpriseId()
|
||||
);
|
||||
if (pmsProductLibraryComponent != null) {
|
||||
pmsProductLibraryComponentMapper.deletePmsProductLibraryComponentById(pmsProductLibraryComponent.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增制品库-制品
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue