Skip to content

Commit

Permalink
Merge branch 'pref-9366' into feat-4780
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/service/atom/impl/AtomReleaseServiceImpl.kt
#	src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/service/common/StoreI18nMessageService.kt
#	src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/service/common/impl/StoreI18nMessageServiceImpl.kt
  • Loading branch information
yjieliang committed Nov 6, 2023
2 parents df5851d + 0081e7c commit ea6fccb
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 82 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* BK-CI 蓝鲸持续集成平台 is licensed under the MIT license.
*
* A copy of the MIT License is included in this file.
*
*
* Terms of the MIT License:
* ---------------------------------------------------
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
* NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.tencent.devops.store.pojo.atom

import io.swagger.annotations.ApiModel
import io.swagger.annotations.ApiModelProperty

@ApiModel("研发商店组件国际化配置")
data class StoreI18nConfig(
@ApiModelProperty("项目标识")
val projectCode: String,
@ApiModelProperty("资源文件目录")
val fileDir: String,
@ApiModelProperty("国际化目录")
val i18nDir: String,
@ApiModelProperty("map字段在properties中key的前缀")
val propertiesKeyPrefix: String? = null,
@ApiModelProperty("map字段在db中key的前缀")
val dbKeyPrefix: String? = null,
@ApiModelProperty("代码库哈希ID")
val repositoryHashId: String? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ import com.tencent.devops.store.pojo.atom.GetAtomConfigResult
import com.tencent.devops.store.pojo.atom.GetAtomQualityConfigResult
import com.tencent.devops.store.pojo.atom.MarketAtomCreateRequest
import com.tencent.devops.store.pojo.atom.MarketAtomUpdateRequest
import com.tencent.devops.store.pojo.atom.StoreI18nConfig
import com.tencent.devops.store.pojo.atom.UpdateAtomInfo
import com.tencent.devops.store.pojo.atom.UpdateAtomPackageInfo
import com.tencent.devops.store.pojo.atom.enums.AtomStatusEnum
Expand Down Expand Up @@ -375,14 +376,16 @@ abstract class AtomReleaseServiceImpl @Autowired constructor() : AtomReleaseServ
val i18nDir = StoreUtils.getStoreI18nDir(atomLanguage, atomPackageSourceType)
val updateRequestDataMap = storeI18nMessageService.parseJsonMapI18nInfo(
userId = userId,
projectCode = projectCode,
jsonMap = jsonMap,
fileDir = "$atomCode/$version",
i18nDir = i18nDir,
propertiesKeyPrefix = KEY_RELEASE_INFO,
dbKeyPrefix = StoreUtils.getStoreFieldKeyPrefix(StoreTypeEnum.ATOM, atomCode, version),
repositoryHashId = atomRecord.repositoryHashId,
branch = branch,
storeI18nConfig = StoreI18nConfig(
projectCode = projectCode,
fileDir = "$atomCode/$version",
i18nDir = i18nDir,
propertiesKeyPrefix = KEY_RELEASE_INFO,
dbKeyPrefix = StoreUtils.getStoreFieldKeyPrefix(StoreTypeEnum.ATOM, atomCode, version),
repositoryHashId = atomRecord.repositoryHashId,
branch = branch,
),
version = version
).toMutableMap()
updateRequestDataMap[versionContentFieldName] =
Expand Down Expand Up @@ -413,13 +416,15 @@ abstract class AtomReleaseServiceImpl @Autowired constructor() : AtomReleaseServ
}
val taskDataMap = storeI18nMessageService.parseJsonMapI18nInfo(
userId = userId,
projectCode = projectCode,
jsonMap = getAtomConfResult.taskDataMap.toMutableMap(),
fileDir = "$atomCode/$version",
i18nDir = i18nDir,
dbKeyPrefix = StoreUtils.getStoreFieldKeyPrefix(StoreTypeEnum.ATOM, atomCode, version),
repositoryHashId = atomRecord.repositoryHashId,
branch = branch,
storeI18nConfig = StoreI18nConfig(
projectCode = projectCode,
fileDir = "$atomCode/$version",
i18nDir = i18nDir,
dbKeyPrefix = StoreUtils.getStoreFieldKeyPrefix(StoreTypeEnum.ATOM, atomCode, version),
repositoryHashId = atomRecord.repositoryHashId,
branch = branch,
),
version = version
)
// 校验插件发布类型
Expand Down Expand Up @@ -707,13 +712,15 @@ abstract class AtomReleaseServiceImpl @Autowired constructor() : AtomReleaseServ
return if (!qualityJsonStr.isNullOrBlank() && JsonSchemaUtil.validateJson(qualityJsonStr)) {
val qualityDataMap = storeI18nMessageService.parseJsonMapI18nInfo(
userId = userId,
projectCode = projectCode,
jsonMap = JsonUtil.toMutableMap(qualityJsonStr),
fileDir = "$atomCode/$atomVersion",
i18nDir = i18nDir,
dbKeyPrefix = StoreUtils.getStoreFieldKeyPrefix(StoreTypeEnum.ATOM, atomCode, atomVersion),
repositoryHashId = repositoryHashId,
branch = branch,
storeI18nConfig = StoreI18nConfig(
projectCode = projectCode,
fileDir = "$atomCode/$atomVersion",
i18nDir = i18nDir,
dbKeyPrefix = StoreUtils.getStoreFieldKeyPrefix(StoreTypeEnum.ATOM, atomCode, atomVersion),
repositoryHashId = repositoryHashId,
branch = branch,
),
version = atomVersion
)
val indicators = qualityDataMap["indicators"] as Map<String, Any>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import com.tencent.devops.store.pojo.atom.AtomConfigInfo
import com.tencent.devops.store.pojo.atom.AtomPkgInfoUpdateRequest
import com.tencent.devops.store.pojo.atom.GetAtomConfigResult
import com.tencent.devops.store.pojo.atom.ReleaseInfo
import com.tencent.devops.store.pojo.atom.StoreI18nConfig
import com.tencent.devops.store.pojo.common.KEY_CONFIG
import com.tencent.devops.store.pojo.common.KEY_EXECUTION
import com.tencent.devops.store.pojo.common.KEY_INPUT
Expand Down Expand Up @@ -266,11 +267,13 @@ class MarketAtomArchiveServiceImpl : MarketAtomArchiveService {
val version = atomPkgInfoUpdateRequest.version
taskDataMap = storeI18nMessageService.parseJsonMapI18nInfo(
userId = userId,
projectCode = projectCode,
jsonMap = taskDataMap.toMutableMap(),
fileDir = "$atomCode/$version",
i18nDir = i18nDir,
dbKeyPrefix = StoreUtils.getStoreFieldKeyPrefix(StoreTypeEnum.ATOM, atomCode, version),
storeI18nConfig = StoreI18nConfig(
projectCode = projectCode,
fileDir = "$atomCode/$version",
i18nDir = i18nDir,
dbKeyPrefix = StoreUtils.getStoreFieldKeyPrefix(StoreTypeEnum.ATOM, atomCode, version)
),
version = version
)
val propsMap = mutableMapOf<String, Any?>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

package com.tencent.devops.store.service.common

import com.tencent.devops.store.pojo.atom.StoreI18nConfig

@Suppress("LongParameterList")
interface StoreI18nMessageService {

Expand All @@ -44,14 +46,8 @@ interface StoreI18nMessageService {
*/
fun parseJsonMapI18nInfo(
userId: String,
projectCode: String,
storeI18nConfig: StoreI18nConfig,
jsonMap: MutableMap<String, Any>,
fileDir: String,
i18nDir: String,
propertiesKeyPrefix: String? = null,
dbKeyPrefix: String? = null,
repositoryHashId: String? = null,
branch: String? = null,
version: String
): Map<String, Any>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import com.tencent.devops.common.client.Client
import com.tencent.devops.common.service.config.CommonConfig
import com.tencent.devops.common.web.service.ServiceI18nMessageResource
import com.tencent.devops.common.web.utils.I18nUtil
import com.tencent.devops.store.pojo.atom.StoreI18nConfig
import com.tencent.devops.store.pojo.common.TextReferenceFileDownloadRequest
import com.tencent.devops.store.service.common.StoreFileService
import com.tencent.devops.store.service.common.StoreFileService.Companion.BK_CI_PATH_REGEX
Expand Down Expand Up @@ -81,16 +82,16 @@ abstract class StoreI18nMessageServiceImpl : StoreI18nMessageService {

override fun parseJsonMapI18nInfo(
userId: String,
projectCode: String,
storeI18nConfig: StoreI18nConfig,
jsonMap: MutableMap<String, Any>,
fileDir: String,
i18nDir: String,
propertiesKeyPrefix: String?,
dbKeyPrefix: String?,
repositoryHashId: String?,
branch: String?,
version: String
): Map<String, Any> {
val projectCode = storeI18nConfig.projectCode
val fileDir = storeI18nConfig.fileDir
val i18nDir = storeI18nConfig.i18nDir
val propertiesKeyPrefix = storeI18nConfig.propertiesKeyPrefix
val dbKeyPrefix = storeI18nConfig.dbKeyPrefix
val repositoryHashId = storeI18nConfig.repositoryHashId
logger.info(
"parseJsonMap params:[$userId|$projectCode|$fileDir|$i18nDir|$propertiesKeyPrefix|$dbKeyPrefix|" +
"$repositoryHashId]"
Expand Down Expand Up @@ -133,15 +134,17 @@ abstract class StoreI18nMessageServiceImpl : StoreI18nMessageService {
// 异步解析处理国际化资源文件信息
fieldLocaleInfos?.let {
asyncHandleI18nMessage(
projectCode = projectCode,
fileDir = fileDir,
i18nDir = i18nDir,
repositoryHashId = repositoryHashId,
fieldLocaleInfos = fieldLocaleInfos,
dbKeyPrefix = dbKeyPrefix,
userId = userId,
branch = branch,
version = version
version = version,
fieldLocaleInfos = fieldLocaleInfos,
storeI18nConfig = StoreI18nConfig(
projectCode = projectCode,
fileDir = fileDir,
i18nDir = i18nDir,
repositoryHashId = repositoryHashId,
dbKeyPrefix = dbKeyPrefix,
branch = branch,
)
)
}
return jsonMap
Expand All @@ -167,15 +170,17 @@ abstract class StoreI18nMessageServiceImpl : StoreI18nMessageService {
}
// 异步解析处理国际化资源文件信息
asyncHandleI18nMessage(
projectCode = projectCode,
fileDir = fileDir,
i18nDir = i18nDir,
repositoryHashId = repositoryHashId,
fieldLocaleInfos = fieldLocaleInfos,
dbKeyPrefix = keyPrefix,
userId = userId,
branch = branch,
version = version
fieldLocaleInfos = fieldLocaleInfos,
version = version,
storeI18nConfig = StoreI18nConfig(
projectCode = projectCode,
fileDir = fileDir,
i18nDir = i18nDir,
repositoryHashId = repositoryHashId,
dbKeyPrefix = keyPrefix,
branch = branch,
)
)
}

Expand Down Expand Up @@ -216,24 +221,19 @@ abstract class StoreI18nMessageServiceImpl : StoreI18nMessageService {
}

private fun asyncHandleI18nMessage(
projectCode: String,
fileDir: String,
i18nDir: String,
repositoryHashId: String?,
fieldLocaleInfos: MutableList<FieldLocaleInfo>,
dbKeyPrefix: String?,
userId: String,
branch: String?,
storeI18nConfig: StoreI18nConfig,
fieldLocaleInfos: MutableList<FieldLocaleInfo>,
version: String
) {
executors.submit {
// 获取资源文件名称列表
val propertiesFileNames = storeFileService.getFileNames(
projectCode = projectCode,
fileDir = fileDir,
i18nDir = i18nDir,
repositoryHashId = repositoryHashId,
branch = branch
projectCode = storeI18nConfig.projectCode,
fileDir = storeI18nConfig.fileDir,
i18nDir = storeI18nConfig.i18nDir,
repositoryHashId = storeI18nConfig.repositoryHashId,
branch = storeI18nConfig.branch
)
logger.info("parseJsonMap propertiesFileNames:$propertiesFileNames")
val regex = MESSAGE_NAME_TEMPLATE.format("(.*)").toRegex()
Expand All @@ -242,12 +242,12 @@ abstract class StoreI18nMessageServiceImpl : StoreI18nMessageService {
// 根据资源文件名称获取资源文件的语言信息
val language = matchResult?.groupValues?.get(1) ?: return@forEach
val fileProperties = getMessageProperties(
projectCode = projectCode,
fileDir = fileDir,
i18nDir = i18nDir,
projectCode = storeI18nConfig.projectCode,
fileDir = storeI18nConfig.fileDir,
i18nDir = storeI18nConfig.i18nDir,
fileName = propertiesFileName,
repositoryHashId = repositoryHashId,
branch = branch
repositoryHashId = storeI18nConfig.repositoryHashId,
branch = storeI18nConfig.branch
) ?: return@forEach
val textReferenceContentMap = getTextReferenceFileContent(fileProperties)
var textReferenceFileDirPath: String? = null
Expand All @@ -256,20 +256,20 @@ abstract class StoreI18nMessageServiceImpl : StoreI18nMessageService {
userId = userId,
version = version,
request = TextReferenceFileDownloadRequest(
projectCode = projectCode,
fileDir = fileDir,
repositoryHashId = repositoryHashId
projectCode = storeI18nConfig.projectCode,
fileDir = storeI18nConfig.fileDir,
repositoryHashId = storeI18nConfig.repositoryHashId
)
)
}
val isDirectoryNotEmpty = isDirectoryNotEmpty(textReferenceFileDirPath)
if (isDirectoryNotEmpty) {
try {
textReferenceContentMap.forEach { (k, v) ->
fileProperties[k] = getTextReferenceFileParsing(
textReferenceContentMap.forEach { (key, content) ->
fileProperties[key] = getTextReferenceFileParsing(
userId = userId,
fileDir = textReferenceFileDirPath!!,
content = v
content = content
)
}
} finally {
Expand All @@ -281,7 +281,7 @@ abstract class StoreI18nMessageServiceImpl : StoreI18nMessageService {
fieldLocaleInfos = fieldLocaleInfos,
fileProperties = fileProperties,
language = language,
dbKeyPrefix = dbKeyPrefix
dbKeyPrefix = storeI18nConfig.dbKeyPrefix
)
// 按批次保存字段的国际化信息
ListUtils.partition(i18nMessages, BATCH_HANDLE_NUM).forEach { partitionMessages ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,18 @@ object TextReferenceFileAnalysisUtil {
result: MutableMap<String, String>,
text: String
): String {
val fileSeparator = File.separator
var content = text
// 替换资源路径
result.forEach {
val analysisPattern: Pattern = Pattern.compile("(\\\$\\{\\{indexFile\\(\"${it.key}\"\\)}})")
for (entry in result.entries) {
val key = entry.key
val value = entry.value.replace(fileSeparator, "\\$fileSeparator")
val analysisPattern: Pattern = Pattern.compile("(\\\$\\{\\{indexFile\\(\"$key\"\\)}})")
val analysisMatcher: Matcher = analysisPattern.matcher(content)
content = analysisMatcher.replaceFirst(
"![${it.key}](${it.value.replace(fileSeparator, "\\$fileSeparator")})"
)
while (analysisMatcher.find()) {
val match = analysisMatcher.group()
content = content.replace(match, "![$key]($value)")
}
}
return content
}
Expand Down

0 comments on commit ea6fccb

Please sign in to comment.