feat(产品库优化): 产品库应当区分文档与制品

1. 普通制品和Docker制品移入产品库时默认添加前缀Software
2. 文档制品移入产品库时默认添加前缀Document

关联Issue:https://pm.gitlink.org.cn/Gitlink/projects/228/demand/124517

Signed-off-by: OTTO <731554297@qq.com>
This commit is contained in:
OTTO 2025-01-23 11:19:17 +08:00
parent 9a1b5e0125
commit 0d63456fb9
4 changed files with 66 additions and 8 deletions

View File

@ -0,0 +1,42 @@
package com.microservices.pms.enums;
import com.microservices.common.core.exception.ServiceException;
import com.microservices.common.core.utils.html.EscapeUtil;
import io.swagger.annotations.ApiModel;
import lombok.Getter;
/**
* @author OTTO
*/
@Getter
@ApiModel("产品库制品路径前缀")
public enum ProductLibraryComponentPathEnum {
SOFTWARE("Software", "软件包"),
DOC("Document", "文档");
private final String key;
private final String name;
ProductLibraryComponentPathEnum(String key, String name) {
this.key = key;
this.name = name;
}
public static ProductLibraryComponentPathEnum getByKey(String key) {
for (ProductLibraryComponentPathEnum typeEnum : ProductLibraryComponentPathEnum.values()) {
if (typeEnum.key.equals(key)) {
return typeEnum;
}
}
throw new ServiceException("该产品库制品路径前缀不存在(产品库制品路径前缀[%s])", key);
}
public static String getSoftwareFixedPath(String directory) {
return EscapeUtil.removeExtraSlashOfUrl(SOFTWARE.key + "/" + directory);
}
public static String getDocFixedPath(String directory) {
return EscapeUtil.removeExtraSlashOfUrl(DOC.key + "/" + directory);
}
}

View File

@ -9,7 +9,7 @@ import lombok.Getter;
*/
@Getter
@ApiModel("来源类型")
public enum FromTypeEnum {
public enum ProductLibraryRepoFromTypeEnum {
COMMON("common", "普通类型"),
PIPELINE("pipeline", "流水线类型"),
DOC("doc", "文档类型");
@ -17,14 +17,14 @@ public enum FromTypeEnum {
private final String key;
private final String name;
FromTypeEnum(String key, String name) {
ProductLibraryRepoFromTypeEnum(String key, String name) {
this.key = key;
this.name = name;
}
public static FromTypeEnum getByKey(String key) {
for (FromTypeEnum typeEnum : FromTypeEnum.values()) {
public static ProductLibraryRepoFromTypeEnum getByKey(String key) {
for (ProductLibraryRepoFromTypeEnum typeEnum : ProductLibraryRepoFromTypeEnum.values()) {
if (typeEnum.key.equals(key)) {
return typeEnum;
}

View File

@ -1,7 +1,7 @@
package com.microservices.pms.productLibrary.domain.vo;
import com.microservices.common.core.utils.bean.BeanUtils;
import com.microservices.pms.enums.FromTypeEnum;
import com.microservices.pms.enums.ProductLibraryRepoFromTypeEnum;
import com.microservices.pms.productLibrary.domain.ProductLibraryRepositoriesFormatEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@ -44,7 +44,7 @@ public class ProductDocComponentInputVo {
BeanUtils.copyProperties(this, target);
target.setRepoName(productRepoName);
target.setAssetList(assetList);
target.setFromType(FromTypeEnum.DOC.getKey());
target.setFromType(ProductLibraryRepoFromTypeEnum.DOC.getKey());
return target;
}

View File

@ -15,7 +15,8 @@ import com.microservices.pms.document.domain.vo.PmsDocumentVo;
import com.microservices.pms.document.service.IPmsDocumentService;
import com.microservices.pms.enterprise.domain.PmsEnterprise;
import com.microservices.pms.enterprise.service.IPmsEnterpriseService;
import com.microservices.pms.enums.FromTypeEnum;
import com.microservices.pms.enums.ProductLibraryComponentPathEnum;
import com.microservices.pms.enums.ProductLibraryRepoFromTypeEnum;
import com.microservices.pms.product.domain.PmsProduct;
import com.microservices.pms.product.service.IPmsProductService;
import com.microservices.pms.productLibrary.domain.PmsProductLibraryComponent;
@ -83,6 +84,9 @@ public class PmsProductLibraryServiceImpl implements IPmsProductLibraryService {
@Autowired
private IPmsProductService pmsProductService;
public final static String DOC_TYPE_PATH = "Document";
public final static String SOFTWARE_TYPE_PATH = "Software";
@Override
public GenericsTableDataInfo<PmsProductLibraryComponentDataVo> selectComponentList(PmsProductLibraryComponentSearchVo search) {
List<PmsProductLibraryComponent> pmsProductLibraryComponentList =
@ -108,7 +112,7 @@ public class PmsProductLibraryServiceImpl implements IPmsProductLibraryService {
String.format("%s/%s", repo.getUrl(), component.getPath()))));
pmsCommonService.setBaseEntityVo(pmsProductLibraryComponentDataVo, component);
pmsProductLibraryComponentDataVo.setFromType(
FromTypeEnum.getByKey(component.getFromType()).getName()
ProductLibraryRepoFromTypeEnum.getByKey(component.getFromType()).getName()
);
return pmsProductLibraryComponentDataVo;
}
@ -210,6 +214,10 @@ public class PmsProductLibraryServiceImpl implements IPmsProductLibraryService {
PmsProductLibraryRepositories repo =
selectPmsProductLibraryByName(productDocComponentInputVo.getEnterpriseIdentifier(), productDocComponentInputVo.getProductRepoName());
// 产品库制品添加默认前缀
productDocComponentInputVo.setDirectory(ProductLibraryComponentPathEnum.getDocFixedPath(
productDocComponentInputVo.getDirectory()
));
List<AssetRawInputVo> assetList = new ArrayList<>();
PmsEnterprise pmsEnterprise = pmsEnterpriseService.selectPmsEnterpriseByIdentifier(productDocComponentInputVo.getEnterpriseIdentifier());
for (Long docId : productDocComponentInputVo.getDocList()) {
@ -342,6 +350,10 @@ public class PmsProductLibraryServiceImpl implements IPmsProductLibraryService {
if (ProductLibraryRepositoriesFormatEnum.DOCKER.getKey().equals(repo.getFormat())) {
throw new ServiceException("Docker制品移入不能使用该接口");
}
// 产品库制品添加默认前缀
commonAssetAddToProductRepoVo.setDirectory(ProductLibraryComponentPathEnum.getSoftwareFixedPath(
commonAssetAddToProductRepoVo.getDirectory()
));
List<NexusAssetResultDataVo> nexusAssetResultDataVoList = new ArrayList<>();
for (String assetId : commonAssetAddToProductRepoVo.getAssetIdList()) {
NexusComponentResultVo<NexusAssetResultDataVo> nexusAssetResultVo = pmsProductLibraryComponentService.getAssetDetailByAssetId(commonAssetAddToProductRepoVo.getEnterpriseIdentifier(), commonAssetAddToProductRepoVo.getRepoName(), null, assetId, false);
@ -438,6 +450,10 @@ public class PmsProductLibraryServiceImpl implements IPmsProductLibraryService {
if (!ProductLibraryRepositoriesFormatEnum.DOCKER.getKey().equals(repo.getFormat())) {
throw new ServiceException("当前接口仅允许进行Docker移入产品库操作");
}
// 产品库制品添加默认前缀
dockerComponentAddToProductRepoVo.setDirectory(ProductLibraryComponentPathEnum.getSoftwareFixedPath(
dockerComponentAddToProductRepoVo.getDirectory()
));
List<NexusComponentResultDataVo> nexusComponentResultDataVoList = new ArrayList<>();
for (String componentId : dockerComponentAddToProductRepoVo.getComponentIdList()) {
NexusComponentResultVo<NexusComponentResultDataVo> nexusAssetResultVo = pmsProductLibraryComponentService.getComponentDetailByComponentId(dockerComponentAddToProductRepoVo.getEnterpriseIdentifier(), dockerComponentAddToProductRepoVo.getRepoName(), null, componentId, false);