From 044ec8c1b2ab347cb98e4693c36ae94e7d622914 Mon Sep 17 00:00:00 2001 From: zwjsec Date: Tue, 25 Jun 2024 21:13:55 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90feature=E3=80=91oepkg=E6=A6=82?= =?UTF-8?q?=E8=A7=88=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FieldApplicationServiceImpl.java | 34 +++ .../oepackage/OEPackageService.java | 36 +++ .../oepackage/OEPackageServiceImpl.java | 69 +++++ .../dto/OEPackageSearchCondition.java | 116 ++++++++ .../oepackage/vo/OEPackageDetailVo.java | 187 +++++++++++++ .../oepackage/vo/OEPackageMenuVo.java | 85 ++++++ .../oepackage/gateway/OEPackageGateway.java | 61 +++++ .../converter/FieldApplicationConverter.java | 15 + .../mapper/OEPackageDOMapper.java | 17 ++ .../gatewalmpl/OEPackageGatewayImpl.java | 189 +++++++++++++ .../coverter/OEPackageConverter.java | 109 ++++++++ .../oepkg/gatewalmpl/dataobject/OepkgDO.java | 257 ++++++++++++++++++ 12 files changed, 1175 insertions(+) create mode 100644 src/main/java/com/easysoftware/application/oepackage/OEPackageService.java create mode 100644 src/main/java/com/easysoftware/application/oepackage/OEPackageServiceImpl.java create mode 100644 src/main/java/com/easysoftware/application/oepackage/dto/OEPackageSearchCondition.java create mode 100644 src/main/java/com/easysoftware/application/oepackage/vo/OEPackageDetailVo.java create mode 100644 src/main/java/com/easysoftware/application/oepackage/vo/OEPackageMenuVo.java create mode 100644 src/main/java/com/easysoftware/domain/oepackage/gateway/OEPackageGateway.java create mode 100644 src/main/java/com/easysoftware/infrastructure/mapper/OEPackageDOMapper.java create mode 100644 src/main/java/com/easysoftware/infrastructure/oepkg/gatewalmpl/OEPackageGatewayImpl.java create mode 100644 src/main/java/com/easysoftware/infrastructure/oepkg/gatewalmpl/coverter/OEPackageConverter.java create mode 100644 src/main/java/com/easysoftware/infrastructure/oepkg/gatewalmpl/dataobject/OepkgDO.java diff --git a/src/main/java/com/easysoftware/application/filedapplication/FieldApplicationServiceImpl.java b/src/main/java/com/easysoftware/application/filedapplication/FieldApplicationServiceImpl.java index da09077..f031537 100644 --- a/src/main/java/com/easysoftware/application/filedapplication/FieldApplicationServiceImpl.java +++ b/src/main/java/com/easysoftware/application/filedapplication/FieldApplicationServiceImpl.java @@ -25,6 +25,7 @@ import com.easysoftware.application.filedapplication.dto.FieldDetailSearchCondit import com.easysoftware.application.filedapplication.dto.FiledApplicationSerachCondition; import com.easysoftware.application.filedapplication.vo.EulerLifeCycleVo; import com.easysoftware.application.filedapplication.vo.FiledApplicationVo; +import com.easysoftware.application.oepackage.dto.OEPackageSearchCondition; import com.easysoftware.application.rpmpackage.RPMPackageService; import com.easysoftware.application.rpmpackage.dto.RPMPackageSearchCondition; import com.easysoftware.application.rpmpackage.vo.RPMPackageDetailVo; @@ -41,6 +42,7 @@ import com.easysoftware.domain.epkgpackage.gateway.EPKGPackageGateway; import com.easysoftware.domain.eulerlifecycle.gateway.EulerLifeCycleGateway; import com.easysoftware.domain.fieldapplication.gateway.FieldapplicationGateway; import com.easysoftware.domain.fieldpkg.gateway.FieldPkgGateway; +import com.easysoftware.domain.oepackage.gateway.OEPackageGateway; import com.easysoftware.domain.rpmpackage.gateway.RPMPackageGateway; import com.easysoftware.infrastructure.fieldapplication.gatewayimpl.converter.FieldApplicationConverter; import com.easysoftware.ranking.Ranker; @@ -111,6 +113,11 @@ public class FieldApplicationServiceImpl implements FieldApplicationService { @Resource private FieldPkgGateway fieldPkgGateway; + /** + * OEPkgGateway Package Gateway. + */ + @Resource + private OEPackageGateway oePkgGateway; /** * eulerLifecycleGateway Package Gateway. */ @@ -141,6 +148,9 @@ public class FieldApplicationServiceImpl implements FieldApplicationService { } else if ("epkgpkg".equals(name)) { Map res = searchEpkgMenu(condition); return ResultUtil.success(HttpStatus.OK, res); + } else if ("oepkg".equals(name)) { + Map res = searchOEPkgMenu(condition); + return ResultUtil.success(HttpStatus.OK, res); } else if ("domain".equals(name)) { Map res = searchDomainMenu(condition); return ResultUtil.success(HttpStatus.OK, res); @@ -280,6 +290,27 @@ public class FieldApplicationServiceImpl implements FieldApplicationService { return map; } + /** + * Search OEPkg menu based on the specified search condition. + * + * @param condition The search condition for OEPkg menu search. + * @return A map containing the search results with string keys and object + * values. + */ + private Map searchOEPkgMenu(final FiledApplicationSerachCondition condition) { + + OEPackageSearchCondition oep = FieldApplicationConverter.toOep(condition); + Map map = oePkgGateway.queryMenuByName(oep); + + Long total = (Long) map.get("total"); + List list = (List) map.get("list"); + + if (total == 0 || list.size() == 0) { + throw new NoneResException("the rpm package does not exist"); + } + return map; + } + /** * Search Application menu based on the specified search condition. * @@ -322,6 +353,9 @@ public class FieldApplicationServiceImpl implements FieldApplicationService { } else if ("domain".equals(name)) { Map> res = fieldPkgGateway.queryColumn(columns); return ResultUtil.success(HttpStatus.OK, res); + } else if ("oepkg".equals(name)) { + Map> res = oePkgGateway.queryColumn(columns); + return ResultUtil.success(HttpStatus.OK, res); } else { throw new ParamErrorException("the value of parameter name: apppkg, rpmpkg, epkgpkg, all"); } diff --git a/src/main/java/com/easysoftware/application/oepackage/OEPackageService.java b/src/main/java/com/easysoftware/application/oepackage/OEPackageService.java new file mode 100644 index 0000000..2261310 --- /dev/null +++ b/src/main/java/com/easysoftware/application/oepackage/OEPackageService.java @@ -0,0 +1,36 @@ +/* Copyright (c) 2024 openEuler Community + EasySoftware is licensed under the Mulan PSL v2. + You can use this software according to the terms and conditions of the Mulan PSL v2. + You may obtain a copy of Mulan PSL v2 at: + http://license.coscl.org.cn/MulanPSL2 + THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + See the Mulan PSL v2 for more details. +*/ +package com.easysoftware.application.oepackage; + +import java.util.Map; + +import org.springframework.http.ResponseEntity; + +import com.easysoftware.application.oepackage.dto.OEPackageSearchCondition; + +public interface OEPackageService { + /** + * Searches for OEpackages. + * + * @param condition The search condition. + * @return ResponseEntity with the search results. + */ + ResponseEntity searchOEPkg(OEPackageSearchCondition condition); + + /** + * Queries all OEpackages menus. + * + * @param condition The search condition. + * @return Map containing the OEpackages menu. + */ + Map queryAllOEPkgMenu(OEPackageSearchCondition condition); + +} diff --git a/src/main/java/com/easysoftware/application/oepackage/OEPackageServiceImpl.java b/src/main/java/com/easysoftware/application/oepackage/OEPackageServiceImpl.java new file mode 100644 index 0000000..498cf83 --- /dev/null +++ b/src/main/java/com/easysoftware/application/oepackage/OEPackageServiceImpl.java @@ -0,0 +1,69 @@ +/* Copyright (c) 2024 openEuler Community + EasySoftware is licensed under the Mulan PSL v2. + You can use this software according to the terms and conditions of the Mulan PSL v2. + You may obtain a copy of Mulan PSL v2 at: + http://license.coscl.org.cn/MulanPSL2 + THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + See the Mulan PSL v2 for more details. +*/ +package com.easysoftware.application.oepackage; + +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang3.StringUtils; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import com.easysoftware.application.oepackage.dto.OEPackageSearchCondition; +import com.easysoftware.application.oepackage.vo.OEPackageDetailVo; +import com.easysoftware.common.exception.NoneResException; +import com.easysoftware.common.exception.ParamErrorException; +import com.easysoftware.common.utils.ResultUtil; +import com.easysoftware.domain.oepackage.gateway.OEPackageGateway; + +import jakarta.annotation.Resource; + +public class OEPackageServiceImpl implements OEPackageService { + + /** + * Resource for OEPackage Gateway. + */ + @Resource + private OEPackageGateway oEPkgGateway; + + /** + * Searches for OEpackages. + * + * @param condition The search condition. + * @return ResponseEntity with the search results. + */ + @Override + public ResponseEntity searchOEPkg(final OEPackageSearchCondition condition) { + if (StringUtils.isBlank(condition.getPkgId())) { + throw new ParamErrorException("the pkgid can not be null"); + } + + List rpmList = oEPkgGateway.queryDetailByPkgId(condition.getPkgId()); + if (rpmList.isEmpty()) { + throw new NoneResException("the oe package does not exist"); + } + Map res = Map.ofEntries( + Map.entry("total", rpmList.size()), + Map.entry("list", rpmList)); + return ResultUtil.success(HttpStatus.OK, res); + } + + /** + * Queries all OEpackage menus. + * + * @param condition The search condition. + * @return Map containing the OEpackage menu. + */ + @Override + public Map queryAllOEPkgMenu(final OEPackageSearchCondition condition) { + return oEPkgGateway.queryMenuByName(condition); + } +} diff --git a/src/main/java/com/easysoftware/application/oepackage/dto/OEPackageSearchCondition.java b/src/main/java/com/easysoftware/application/oepackage/dto/OEPackageSearchCondition.java new file mode 100644 index 0000000..2a78555 --- /dev/null +++ b/src/main/java/com/easysoftware/application/oepackage/dto/OEPackageSearchCondition.java @@ -0,0 +1,116 @@ +/* Copyright (c) 2024 openEuler Community + EasySoftware is licensed under the Mulan PSL v2. + You can use this software according to the terms and conditions of the Mulan PSL v2. + You may obtain a copy of Mulan PSL v2 at: + http://license.coscl.org.cn/MulanPSL2 + THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + See the Mulan PSL v2 for more details. +*/ +package com.easysoftware.application.oepackage.dto; + +import org.hibernate.validator.constraints.Range; + +import com.easysoftware.common.constant.PackageConstant; + +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Pattern; +import jakarta.validation.constraints.Size; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class OEPackageSearchCondition { + /** + * Field for name with a maximum length of PackageConstant.MAX_FIELD_LENGTH. + */ + @Size(max = PackageConstant.MAX_FIELD_LENGTH) + @Pattern(regexp = PackageConstant.VALID_STR_REG, message = PackageConstant.VALID_MESSAGE) + private String name; + + /** + * Field for pkgId with a maximum length of PackageConstant.MAX_FIELD_LENGTH. + */ + @Size(max = PackageConstant.MAX_FIELD_LENGTH) + @Pattern(regexp = PackageConstant.VALID_STR_REG, message = PackageConstant.VALID_MESSAGE) + private String pkgId; + + /** + * Field for subPath with a maximum length of PackageConstant.MAX_FIELD_LENGTH. + */ + @Size(max = PackageConstant.MAX_FIELD_LENGTH) + @Pattern(regexp = PackageConstant.VALID_STR_REG, message = PackageConstant.VALID_MESSAGE) + private String subPath; + + /** + * Field for pageNum within the range defined by PackageConstant.MIN_PAGE_NUM + * and PackageConstant.MAX_PAGE_NUM. + * Default value is 1. + */ + @Range(min = PackageConstant.MIN_PAGE_NUM, max = PackageConstant.MAX_PAGE_NUM) + @NotNull + private Integer pageNum = 1; + + /** + * Field for pageSize within the range defined by PackageConstant.MIN_PAGE_SIZE + * and PackageConstant.MAX_PAGE_SIZE. + * Default value is 10. + */ + @Range(min = PackageConstant.MIN_PAGE_SIZE, max = PackageConstant.MAX_PAGE_SIZE) + @NotNull + private Integer pageSize = 10; + + /** + * Field for version with a maximum length of PackageConstant.MAX_FIELD_LENGTH. + */ + @Size(max = PackageConstant.MAX_FIELD_LENGTH) + @Pattern(regexp = PackageConstant.VALID_STR_REG, message = PackageConstant.VALID_MESSAGE) + private String version; + + /** + * Field for os with a maximum length of PackageConstant.MAX_FIELD_LENGTH. + */ + @Size(max = PackageConstant.MAX_FIELD_LENGTH) + @Pattern(regexp = PackageConstant.VALID_STR_REG, message = PackageConstant.VALID_MESSAGE) + private String os; + + /** + * Field for arch with a maximum length of PackageConstant.MAX_FIELD_LENGTH. + */ + @Size(max = PackageConstant.MAX_FIELD_LENGTH) + @Pattern(regexp = PackageConstant.VALID_STR_REG, message = PackageConstant.VALID_MESSAGE) + private String arch; + + /** + * Field for category with a maximum length of PackageConstant.MAX_FIELD_LENGTH. + */ + @Size(max = PackageConstant.MAX_FIELD_LENGTH) + @Pattern(regexp = PackageConstant.VALID_STR_REG, message = PackageConstant.VALID_MESSAGE) + private String category; + + /** + * Field for rpmUpdateAt with a maximum length of + * PackageConstant.MAX_FIELD_LENGTH. + */ + @Size(max = PackageConstant.MAX_FIELD_LENGTH) + @Pattern(regexp = PackageConstant.VALID_STR_REG, message = PackageConstant.VALID_MESSAGE) + private String rpmUpdateAt; + + /** + * Time order. + */ + @Size(max = PackageConstant.MAX_FIELD_LENGTH) + @Pattern(regexp = PackageConstant.VALID_STR_REG, message = PackageConstant.VALID_MESSAGE) + private String timeOrder; + + /** + * Name order. + */ + @Size(max = PackageConstant.MAX_FIELD_LENGTH) + @Pattern(regexp = PackageConstant.VALID_STR_REG, message = PackageConstant.VALID_MESSAGE) + private String nameOrder; +} diff --git a/src/main/java/com/easysoftware/application/oepackage/vo/OEPackageDetailVo.java b/src/main/java/com/easysoftware/application/oepackage/vo/OEPackageDetailVo.java new file mode 100644 index 0000000..b829a81 --- /dev/null +++ b/src/main/java/com/easysoftware/application/oepackage/vo/OEPackageDetailVo.java @@ -0,0 +1,187 @@ +/* Copyright (c) 2024 openEuler Community + EasySoftware is licensed under the Mulan PSL v2. + You can use this software according to the terms and conditions of the Mulan PSL v2. + You may obtain a copy of Mulan PSL v2 at: + http://license.coscl.org.cn/MulanPSL2 + THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + See the Mulan PSL v2 for more details. +*/ + +package com.easysoftware.application.oepackage.vo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class OEPackageDetailVo { + /** + * Name of the OEpackage. + */ + private String name; + + /** + * ID of the OEpackage. + */ + private String id; + + /** + * Version of the OEpackage. + */ + private String version; + + /** + * Operating system for which the package is intended. + */ + private String os; + + /** + * Architecture of the package. + */ + private String arch; + + /** + * Category to which the package belongs. + */ + private String category; + + /** + * Timestamp of the last OEpackage update. + */ + private String rpmUpdateAt; + + /** + * Source repository for the package. + */ + private String srcRepo; + + /** + * Size of the RPM package. + */ + private String rpmSize; + + /** + * Binary download URL for the package. + */ + private String binDownloadUrl; + + /** + * Source code download URL for the package. + */ + private String srcDownloadUrl; + + /** + * Summary description of the package. + */ + private String summary; + + /** + * Operating system support information. + */ + private String osSupport; + + /** + * Repository information. + */ + private String repo; + + /** + * Type of repository. + */ + private String repoType; + + /** + * Installation instructions for the package. + */ + private String installation; + + /** + * Detailed description of the package. + */ + private String description; + + /** + * Dependencies required by the package. + */ + private String requires; + + /** + * Functionalities provided by the package. + */ + private String provides; + + /** + * Conflicting packages. + */ + private String conflicts; + + /** + * Changelog of the package. + */ + private String changeLog; + + /** + * ID of the maintainer. + */ + private String maintainerId; + + /** + * Email of the maintainer. + */ + private String maintainerEmail; + + /** + * Gitee ID of the maintainer. + */ + private String maintainerGiteeId; + + /** + * Timestamp of last maintainer update. + */ + private String maintainerUpdateAt; + + /** + * Status of the maintainer. + */ + private String maintainerStatus; + + /** + * Upstream source of the package. + */ + private String upStream; + + /** + * Security information related to the package. + */ + private String security; + + /** + * Similar packages available. + */ + private String similarPkgs; + + /** + * Download count of the package. + */ + private String downloadCount; + + /** + * Package ID. + */ + private String pkgId; + + /** + * Subpath of the package. + */ + private String subPath; + + /** + * License. + */ + private String license; + +} diff --git a/src/main/java/com/easysoftware/application/oepackage/vo/OEPackageMenuVo.java b/src/main/java/com/easysoftware/application/oepackage/vo/OEPackageMenuVo.java new file mode 100644 index 0000000..a27af00 --- /dev/null +++ b/src/main/java/com/easysoftware/application/oepackage/vo/OEPackageMenuVo.java @@ -0,0 +1,85 @@ +/* Copyright (c) 2024 openEuler Community + EasySoftware is licensed under the Mulan PSL v2. + You can use this software according to the terms and conditions of the Mulan PSL v2. + You may obtain a copy of Mulan PSL v2 at: + http://license.coscl.org.cn/MulanPSL2 + THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + See the Mulan PSL v2 for more details. +*/ +package com.easysoftware.application.oepackage.vo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class OEPackageMenuVo { + /** + * Name of the OEpackage. + */ + private String name; + + /** + * ID of the OEpackage. + */ + private String id; + + /** + * Version of the OEpackage. + */ + private String version; + + /** + * Operating system for which the package is intended. + */ + private String os; + + /** + * Architecture of the package. + */ + private String arch; + + /** + * Category to which the package belongs. + */ + private String category; + + /** + * Timestamp of the last OEpackage update. + */ + private String rpmUpdateAt; + + /** + * Source repository for the package. + */ + private String srcRepo; + + /** + * Size of the OEpackage package. + */ + private String rpmSize; + + /** + * Binary download URL for the package. + */ + private String binDownloadUrl; + + /** + * Package ID. + */ + private String pkgId; + + /** + * Subpath of the package. + */ + private String subPath; + + /** + * License. + */ + private String license; +} diff --git a/src/main/java/com/easysoftware/domain/oepackage/gateway/OEPackageGateway.java b/src/main/java/com/easysoftware/domain/oepackage/gateway/OEPackageGateway.java new file mode 100644 index 0000000..aa5f063 --- /dev/null +++ b/src/main/java/com/easysoftware/domain/oepackage/gateway/OEPackageGateway.java @@ -0,0 +1,61 @@ +/* Copyright (c) 2024 openEuler Community + EasySoftware is licensed under the Mulan PSL v2. + You can use this software according to the terms and conditions of the Mulan PSL v2. + You may obtain a copy of Mulan PSL v2 at: + http://license.coscl.org.cn/MulanPSL2 + THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + See the Mulan PSL v2 for more details. +*/ + +package com.easysoftware.domain.oepackage.gateway; + +import java.util.List; +import java.util.Map; + +import com.easysoftware.application.oepackage.dto.OEPackageSearchCondition; +import com.easysoftware.application.oepackage.vo.OEPackageDetailVo; + +public interface OEPackageGateway { + /** + * Query detailed information based on the provided search condition for + * OEpackages. + * + * @param condition The search condition for querying OEpackage details + * @return A map containing detailed information + */ + Map queryDetailByName(OEPackageSearchCondition condition); + + /** + * Query detailed information by package ID for OEpackages. + * + * @param pkgId The package ID to query detailed information + * @return A list of RPMPackageDetailVo objects + */ + List queryDetailByPkgId(String pkgId); + + /** + * Query menu items based on the provided search condition for OEpackages. + * + * @param condition The search condition for querying menu items + * @return A map containing menu items + */ + Map queryMenuByName(OEPackageSearchCondition condition); + + /** + * Query columns based on the provided list of columns for OEpackages. + * + * @param columns The list of columns to query + * @return A map containing column data + */ + Map> queryColumn(List columns); + + /** + * Get the total number of records in the RPM package table. + * + * @return The total number of records in the table + */ + long queryTableLength(); + +} diff --git a/src/main/java/com/easysoftware/infrastructure/fieldapplication/gatewayimpl/converter/FieldApplicationConverter.java b/src/main/java/com/easysoftware/infrastructure/fieldapplication/gatewayimpl/converter/FieldApplicationConverter.java index 1d21c16..5410db7 100644 --- a/src/main/java/com/easysoftware/infrastructure/fieldapplication/gatewayimpl/converter/FieldApplicationConverter.java +++ b/src/main/java/com/easysoftware/infrastructure/fieldapplication/gatewayimpl/converter/FieldApplicationConverter.java @@ -16,6 +16,7 @@ import com.easysoftware.application.epkgpackage.dto.EPKGPackageSearchCondition; import com.easysoftware.application.fieldpkg.dto.FieldPkgSearchCondition; import com.easysoftware.application.filedapplication.dto.FiledApplicationSerachCondition; import com.easysoftware.application.filedapplication.vo.FiledApplicationVo; +import com.easysoftware.application.oepackage.dto.OEPackageSearchCondition; import com.easysoftware.application.rpmpackage.dto.RPMPackageSearchCondition; import com.easysoftware.common.entity.MessageCode; import com.easysoftware.common.utils.ObjectMapperUtil; @@ -150,6 +151,20 @@ public final class FieldApplicationConverter { return rPMCon; } + /** + * Converts a FieldApplicationSearchCondition object to an + * OEPackageSearchCondition object. + * + * @param con The FieldApplicationSearchCondition object to convert. + * @return The converted OEPackageSearchCondition object. + */ + public static OEPackageSearchCondition toOep(final FiledApplicationSerachCondition con) { + OEPackageSearchCondition oepCon = new OEPackageSearchCondition(); + BeanUtils.copyProperties(con, oepCon); + oepCon.setName(""); + return oepCon; + } + /** * Converts a FieldApplicationSearchCondition object to an * EPKGPackageSearchCondition object. diff --git a/src/main/java/com/easysoftware/infrastructure/mapper/OEPackageDOMapper.java b/src/main/java/com/easysoftware/infrastructure/mapper/OEPackageDOMapper.java new file mode 100644 index 0000000..b144e5a --- /dev/null +++ b/src/main/java/com/easysoftware/infrastructure/mapper/OEPackageDOMapper.java @@ -0,0 +1,17 @@ +/* Copyright (c) 2024 openEuler Community + EasySoftware is licensed under the Mulan PSL v2. + You can use this software according to the terms and conditions of the Mulan PSL v2. + You may obtain a copy of Mulan PSL v2 at: + http://license.coscl.org.cn/MulanPSL2 + THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + See the Mulan PSL v2 for more details. +*/ +package com.easysoftware.infrastructure.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.easysoftware.infrastructure.oepkg.gatewalmpl.dataobject.OepkgDO; + +public interface OEPackageDOMapper extends BaseMapper { +} diff --git a/src/main/java/com/easysoftware/infrastructure/oepkg/gatewalmpl/OEPackageGatewayImpl.java b/src/main/java/com/easysoftware/infrastructure/oepkg/gatewalmpl/OEPackageGatewayImpl.java new file mode 100644 index 0000000..2baf391 --- /dev/null +++ b/src/main/java/com/easysoftware/infrastructure/oepkg/gatewalmpl/OEPackageGatewayImpl.java @@ -0,0 +1,189 @@ +/* Copyright (c) 2024 openEuler Community + EasySoftware is licensed under the Mulan PSL v2. + You can use this software according to the terms and conditions of the Mulan PSL v2. + You may obtain a copy of Mulan PSL v2 at: + http://license.coscl.org.cn/MulanPSL2 + THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + See the Mulan PSL v2 for more details. +*/ + +package com.easysoftware.infrastructure.oepkg.gatewalmpl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.easysoftware.application.oepackage.dto.OEPackageSearchCondition; +import com.easysoftware.application.oepackage.vo.OEPackageDetailVo; +import com.easysoftware.application.oepackage.vo.OEPackageMenuVo; +import com.easysoftware.common.exception.ParamErrorException; +import com.easysoftware.common.utils.ClassField; +import com.easysoftware.common.utils.QueryWrapperUtil; +import com.easysoftware.domain.oepackage.gateway.OEPackageGateway; +import com.easysoftware.infrastructure.mapper.OEPackageDOMapper; +import com.easysoftware.infrastructure.oepkg.gatewalmpl.coverter.OEPackageConverter; +import com.easysoftware.infrastructure.oepkg.gatewalmpl.dataobject.OepkgDO; +import com.power.common.util.StringUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.BadSqlGrammarException; +import org.springframework.stereotype.Component; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Component +public class OEPackageGatewayImpl implements OEPackageGateway { + + /** + * Autowired RPMPackageDOMapper for database operations. + */ + @Autowired + private OEPackageDOMapper oEPkgMapper; + + /** + * Query detailed information based on the provided search condition for + * OEpackages. + * + * @param condition The search condition for querying OEpackage details + * @return A map containing detailed information + */ + @Override + public Map queryDetailByName(final OEPackageSearchCondition condition) { + Page page = createPage(condition); + QueryWrapper wrapper = QueryWrapperUtil.createQueryWrapper(new OepkgDO(), + condition, "rpm_update_at"); + IPage resPage = oEPkgMapper.selectPage(page, wrapper); + List oepkgDOs = resPage.getRecords(); + + List oeDetails = OEPackageConverter.toDetail(oepkgDOs); + long total = resPage.getTotal(); + + Map res = Map.ofEntries( + Map.entry("total", total), + Map.entry("list", oeDetails)); + + return res; + } + + /** + * Query menu items based on the provided search condition for OEpackages. + * + * @param condition The search condition for querying menu items + * @return A map containing menu items + */ + @Override + public Map queryMenuByName(final OEPackageSearchCondition condition) { + Page page = createPage(condition); + QueryWrapper wrapper = QueryWrapperUtil.createQueryWrapper(new OepkgDO(), + condition, "rpm_update_at"); + OEPackageMenuVo pkgVo = new OEPackageMenuVo(); + List columns = ClassField.getFieldNames(pkgVo); + wrapper.select(columns); + IPage resPage = oEPkgMapper.selectPage(page, wrapper); + List oepkgDOs = resPage.getRecords(); + + List oeMenus = OEPackageConverter.toMenu(oepkgDOs); + long total = resPage.getTotal(); + + Map res = Map.ofEntries( + Map.entry("total", total), + Map.entry("list", oeMenus)); + return res; + } + + /** + * Creates a Page of OEPackageDO based on the provided search condition. + * + * @param condition The OEPackageSearchCondition object to create the page + * from. + * @return A Page of OEPackageDO entities. + */ + private Page createPage(final OEPackageSearchCondition condition) { + int pageNum = condition.getPageNum(); + int pageSize = condition.getPageSize(); + return new Page<>(pageNum, pageSize); + } + + /** + * Query columns based on the provided list of columns for OEpackages. + * + * @param columns The list of columns to query + * @return A map containing column data + */ + @Override + public Map> queryColumn(final List columns) { + Map> res = new HashMap<>(); + for (String column : columns) { + List colList = queryColumn(column); + if ("os".equals(column)) { + colList = QueryWrapperUtil.sortOsColumn(colList); + } + if ("category".equals(column)) { + colList = QueryWrapperUtil.sortCategoryColumn(colList); + } + res.put(column, colList); + } + return res; + } + + /** + * Query a specific column and return the results as a list of strings. + * + * @param column The name of the column to query. + * @return A list of strings representing the queried column. + */ + public List queryColumn(final String column) { + // 白名单列 + List allowedColumns = Arrays.asList("category", "os", "arch"); + + if (!allowedColumns.contains(column)) { + throw new ParamErrorException("the value of parameter column: category, os, arch"); + } + + QueryWrapper wrapper = new QueryWrapper<>(); + // 安全地选择列,列名已经通过白名单验证 + wrapper.select("distinct " + column); + List oepkgColumn; + try { + oepkgColumn = oEPkgMapper.selectList(wrapper); + } catch (BadSqlGrammarException e) { + throw new ParamErrorException("the value of parameter column: category, os, arch"); + } + + String underlineToCamelColumn = StringUtil.underlineToCamel(column); + + return OEPackageConverter.toColumn(oepkgColumn, underlineToCamelColumn); + } + + /** + * Get the total number of records in the OEpkg package table. + * + * @return The total number of records in the table + */ + @Override + public long queryTableLength() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.select("distinct name"); + return oEPkgMapper.selectCount(wrapper); + } + + /** + * Query detailed information by package ID for OEpackages. + * + * @param pkgId The package ID to query detailed information + * @return A list of OEPackageDetailVo objects + */ + @Override + public List queryDetailByPkgId(final String pkgId) { + QueryWrapper wrapper = new QueryWrapper<>(); + if (pkgId != null) { + wrapper.eq("pkg_id", pkgId); + } + List rpmList = oEPkgMapper.selectList(wrapper); + + return OEPackageConverter.toDetail(rpmList); + } +} diff --git a/src/main/java/com/easysoftware/infrastructure/oepkg/gatewalmpl/coverter/OEPackageConverter.java b/src/main/java/com/easysoftware/infrastructure/oepkg/gatewalmpl/coverter/OEPackageConverter.java new file mode 100644 index 0000000..788735c --- /dev/null +++ b/src/main/java/com/easysoftware/infrastructure/oepkg/gatewalmpl/coverter/OEPackageConverter.java @@ -0,0 +1,109 @@ +/* Copyright (c) 2024 openEuler Community + EasySoftware is licensed under the Mulan PSL v2. + You can use this software according to the terms and conditions of the Mulan PSL v2. + You may obtain a copy of Mulan PSL v2 at: + http://license.coscl.org.cn/MulanPSL2 + THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + See the Mulan PSL v2 for more details. +*/ +package com.easysoftware.infrastructure.oepkg.gatewalmpl.coverter; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeanUtils; + +import com.easysoftware.application.oepackage.vo.OEPackageDetailVo; +import com.easysoftware.application.oepackage.vo.OEPackageMenuVo; +import com.easysoftware.common.entity.MessageCode; +import com.easysoftware.infrastructure.oepkg.gatewalmpl.dataobject.OepkgDO; +import com.easysoftware.infrastructure.rpmpackage.gatewayimpl.converter.RPMPackageConverter; + +public final class OEPackageConverter { + /** + * Logger instance for RPMPackageConverter. + */ + private static final Logger LOGGER = LoggerFactory.getLogger(RPMPackageConverter.class); + + // Private constructor to prevent instantiation of the PackageConstant class + private OEPackageConverter() { + // private constructor to hide the implicit public one + throw new AssertionError("RPMPackageConverter class cannot be instantiated."); + } + + /** + * Converts a list of OEpkgDOs objects to a list of OEPackageDetailVo view + * objects. + * + * @param OEpkgDOs The list of OepkgDO objects to convert. + * @return A list of OEPackageDetailVo view objects. + */ + public static List toDetail(final List OEpkgDOs) { + List res = new ArrayList<>(); + for (OepkgDO rpm : OEpkgDOs) { + OEPackageDetailVo detail = new OEPackageDetailVo(); + BeanUtils.copyProperties(rpm, detail); + + res.add(detail); + } + return res; + } + + /** + * Extracts a specific column from a list of OEpkgDOs objects and returns it + * as a list of strings. + * + * @param OepkgDOs The list of OEPackageDO objects. + * @param column The name of the column to extract. + * @return A list of strings representing the extracted column values. + */ + public static List toColumn(final List OepkgDOs, final String column) { + List res = new ArrayList<>(); + try { + Field field = OepkgDO.class.getDeclaredField(column); + field.setAccessible(true); + for (OepkgDO oekgDO : OepkgDOs) { + if (oekgDO == null) { + continue; + } + Object obj = field.get(oekgDO); + + if (obj == null) { + LOGGER.warn("Field value is null for pkg: {}", oekgDO); + continue; + } + + if (!(obj instanceof String)) { + continue; + } + String value = (String) field.get(oekgDO); + res.add(value); + } + } catch (Exception e) { + LOGGER.error(MessageCode.EC00011.getMsgEn(), e.getMessage()); + } + return res; + } + + /** + * Converts a list of OepkgDO objects to a list of OEPackageMenuVo view + * objects. + * + * @param oekgDOs The list of OepkgDO objects to convert. + * @return A list of OEPackageMenuVo view objects. + */ + public static List toMenu(final List oekgDOs) { + List res = new ArrayList<>(); + for (OepkgDO oepkgDO : oekgDOs) { + OEPackageMenuVo menu = new OEPackageMenuVo(); + BeanUtils.copyProperties(oepkgDO, menu); + res.add(menu); + } + return res; + } +} diff --git a/src/main/java/com/easysoftware/infrastructure/oepkg/gatewalmpl/dataobject/OepkgDO.java b/src/main/java/com/easysoftware/infrastructure/oepkg/gatewalmpl/dataobject/OepkgDO.java new file mode 100644 index 0000000..873dce1 --- /dev/null +++ b/src/main/java/com/easysoftware/infrastructure/oepkg/gatewalmpl/dataobject/OepkgDO.java @@ -0,0 +1,257 @@ +/* Copyright (c) 2024 openEuler Community + EasySoftware is licensed under the Mulan PSL v2. + You can use this software according to the terms and conditions of the Mulan PSL v2. + You may obtain a copy of Mulan PSL v2 at: + http://license.coscl.org.cn/MulanPSL2 + THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + See the Mulan PSL v2 for more details. +*/ + +package com.easysoftware.infrastructure.oepkg.gatewalmpl.dataobject; + +import java.io.Serial; +import java.sql.Timestamp; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@TableName("oepkg") +public class OepkgDO { + /** + * Serializable class with a defined serial version UID. + */ + @Serial + private String id; + + /** + * Timestamp for creation. + */ + private Timestamp createAt; + + /** + * Timestamp for update. + */ + private Timestamp updateAt; + + /** + * Name of the entity. + */ + private String name; + + /** + * Version information. + */ + private String version; + + /** + * Operating system information. + */ + private String os; + + /** + * Architecture information. + */ + private String arch; + + /** + * Category of the entity. + */ + private String category; + + /** + * Timestamp for RPM package update. + */ + private String rpmUpdateAt; + + /** + * Source repository information. + */ + private String srcRepo; + + /** + * Size of the RPM package. + */ + private String rpmSize; + + /** + * Binary download URL. + */ + private String binDownloadUrl; + + /** + * Source download URL. + */ + private String srcDownloadUrl; + + /** + * Summary of the entity. + */ + private String summary; + + /** + * Operating system support information. + */ + private String osSupport; + + /** + * Repository information. + */ + private String repo; + + /** + * Type of the repository. + */ + private String repoType; + + /** + * Installation instructions. + */ + private String installation; + + /** + * Description of the entity. + */ + private String description; + + /** + * Requirements information. + */ + private String requires; + + /** + * Provides information. + */ + private String provides; + + /** + * Conflicts information. + */ + private String conflicts; + + /** + * Change log information. + */ + private String changeLog; + + /** + * Maintainer ID. + */ + private String maintainerId; + + /** + * Maintainer email. + */ + private String maintainerEmail; + + /** + * Maintainer Gitee ID. + */ + private String maintainerGiteeId; + + /** + * Timestamp for maintainer update. + */ + private String maintainerUpdateAt; + + /** + * Maintainer status information. + */ + private String maintainerStatus; + + /** + * Upstream information. + */ + private String upStream; + + /** + * Security information. + */ + private String security; + + /** + * Similar packages information. + */ + private String similarPkgs; + + /** + * Download count information. + */ + private String downloadCount; + + /** + * Package ID. + */ + @TableId + private String pkgId; + + /** + * Sub-path information. + */ + private String subPath; + + /** + * License. + */ + private String license; + + /** + * get an OepkgDO entity createAt field value. + * + * @return An Timestamp entity + */ + public Timestamp getCreateAt() { + if (this.createAt != null) { + return (Timestamp) this.createAt.clone(); + } else { + return null; + } + } + + /** + * get an OepkgDO entity updateAt field value. + * + * @return An Timestamp entity + */ + public Timestamp getUpdateAt() { + if (this.updateAt != null) { + return (Timestamp) this.updateAt.clone(); + } else { + return null; + } + } + + /** + * set an OepkgDO entity createAt field value. + * + * @param createAt The OepkgDO entity createAt field for set + */ + public void setCreateAt(Timestamp createAt) { + if (this.createAt != null) { + this.createAt = (Timestamp) createAt.clone(); + } else { + this.createAt = null; + } + } + + /** + * set an OepkgDO entity updateAt field value. + * + * @param updateAt The OepkgDO entity updateAt field for set + */ + public void setUpdateAt(Timestamp updateAt) { + if (this.updateAt != null) { + this.updateAt = (Timestamp) updateAt.clone(); + } else { + this.updateAt = null; + } + } +} -- Gitee