Skip to content

Commit

Permalink
bug: 在工作台删除某个插件后,无法重复创建同名插件 TencentBlueKing#1334
Browse files Browse the repository at this point in the history
  • Loading branch information
carlyin0801 committed Aug 28, 2020
1 parent ba6f57a commit fece732
Show file tree
Hide file tree
Showing 30 changed files with 342 additions and 16 deletions.
Expand Up @@ -31,6 +31,7 @@ import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import io.swagger.annotations.ApiParam
import javax.ws.rs.Consumes
import javax.ws.rs.DELETE
import javax.ws.rs.GET
import javax.ws.rs.Path
import javax.ws.rs.Produces
Expand All @@ -51,4 +52,16 @@ interface ServiceArchiveAtomResource {
@QueryParam("filePath")
filePath: String
): Result<String>

@ApiOperation("删除插件包文件")
@DELETE
@Path("/atom/file/delete")
fun deleteAtomFile(
@ApiParam("项目编码", required = true)
@QueryParam("projectCode")
projectCode: String,
@ApiParam("插件代码", required = true)
@QueryParam("atomCode")
atomCode: String
): Result<Boolean>
}
Expand Up @@ -27,16 +27,24 @@
package com.tencent.devops.artifactory.resources

import com.tencent.devops.artifactory.api.ServiceArchiveAtomResource
import com.tencent.devops.artifactory.constant.BK_CI_ATOM_DIR
import com.tencent.devops.artifactory.service.ArchiveAtomService
import com.tencent.devops.artifactory.service.ArchiveFileService
import com.tencent.devops.common.api.pojo.Result
import com.tencent.devops.common.web.RestResource
import org.springframework.beans.factory.annotation.Autowired

@RestResource
class ServiceArchiveAtomResourceImpl @Autowired constructor(private val archiveAtomService: ArchiveAtomService) :
ServiceArchiveAtomResource {
class ServiceArchiveAtomResourceImpl @Autowired constructor(
private val archiveFileService: ArchiveFileService,
private val archiveAtomService: ArchiveAtomService
) : ServiceArchiveAtomResource {

override fun getAtomFileContent(filePath: String): Result<String> {
return archiveAtomService.getAtomFileContent(filePath)
}

override fun deleteAtomFile(projectCode: String, atomCode: String): Result<Boolean> {
return archiveFileService.deleteFile("$BK_CI_ATOM_DIR/$projectCode/$atomCode")
}
}
Expand Up @@ -63,7 +63,13 @@ class ArchiveAtomToLocalServiceImpl : ArchiveAtomServiceImpl() {
return Result(content)
}

override fun handleArchiveFile(disposition: FormDataContentDisposition, inputStream: InputStream, projectCode: String, atomCode: String, version: String) {
override fun handleArchiveFile(
disposition: FormDataContentDisposition,
inputStream: InputStream,
projectCode: String,
atomCode: String,
version: String
) {
unzipFile(disposition, inputStream, projectCode, atomCode, version)
}

Expand Down
Expand Up @@ -207,4 +207,11 @@ interface ArchiveFileService {
targetProjectId: String,
targetPath: String
): Result<Count>

/**
* 删除文件
*/
fun deleteFile(
filePath: String
): Result<Boolean>
}
Expand Up @@ -44,6 +44,7 @@ import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Service
import org.springframework.util.AntPathMatcher
import org.springframework.util.FileCopyUtils
import org.springframework.util.FileSystemUtils
import java.io.File
import java.io.FileInputStream
import java.io.InputStream
Expand Down Expand Up @@ -300,6 +301,11 @@ class DiskArchiveFileServiceImpl : ArchiveFileService, ArchiveFileServiceImpl()
return Result(Count(fileList.size))
}

override fun deleteFile(filePath: String): Result<Boolean> {
FileSystemUtils.deleteRecursively(File("$archiveLocalBasePath/$filePath"))
return Result(true)
}

companion object {
private val logger = LoggerFactory.getLogger(DiskArchiveFileServiceImpl::class.java)
}
Expand Down
Expand Up @@ -242,6 +242,11 @@ class JFrogArchiveFileServiceImpl : ArchiveFileService, ArchiveFileServiceImpl()
return Result(Count(0))
}

override fun deleteFile(filePath: String): Result<Boolean> {
jFrogService.delete(filePath)
return Result(true)
}

companion object {
private val logger = LoggerFactory.getLogger(JFrogArchiveFileServiceImpl::class.java)
}
Expand Down
Expand Up @@ -27,6 +27,7 @@
package com.tencent.devops.store.dao.atom

import com.tencent.devops.common.api.util.UUIDUtil
import com.tencent.devops.model.store.tables.TAtom
import com.tencent.devops.model.store.tables.TAtomLabelRel
import com.tencent.devops.model.store.tables.TLabel
import com.tencent.devops.store.pojo.common.KEY_CREATE_TIME
Expand Down Expand Up @@ -69,6 +70,16 @@ class AtomLabelRelDao {
}
}

fun deleteByAtomCode(dslContext: DSLContext, atomCode: String) {
val ta = TAtom.T_ATOM
val atomIds = dslContext.select(ta.ID).from(ta).fetch()
with(TAtomLabelRel.T_ATOM_LABEL_REL) {
dslContext.deleteFrom(this)
.where(ATOM_ID.`in`(atomIds))
.execute()
}
}

fun batchAdd(dslContext: DSLContext, userId: String, atomId: String, labelIdList: List<String>) {
with(TAtomLabelRel.T_ATOM_LABEL_REL) {
val addStep = labelIdList.map {
Expand Down
Expand Up @@ -216,4 +216,14 @@ class MarketAtomEnvInfoDao {
.execute()
}
}

fun deleteAtomEnvInfo(dslContext: DSLContext, atomCode: String) {
val ta = TAtom.T_ATOM
val atomIds = dslContext.select(ta.ID).from(ta).fetch()
with(TAtomEnvInfo.T_ATOM_ENV_INFO) {
dslContext.deleteFrom(this)
.where(ATOM_ID.`in`(atomIds))
.execute()
}
}
}
Expand Up @@ -101,4 +101,12 @@ class MarketAtomFeatureDao {
}
}
}

fun deleteAtomFeature(dslContext: DSLContext, atomCode: String) {
with(TAtomFeature.T_ATOM_FEATURE) {
dslContext.deleteFrom(this)
.where(ATOM_CODE.eq(atomCode))
.execute()
}
}
}
Expand Up @@ -80,7 +80,6 @@ class MarketAtomOfflineDao {
/**
* 设置状态
*/

fun setStatus(dslContext: DSLContext, id: String, status: Byte, userId: String) {
with(TAtomOffline.T_ATOM_OFFLINE) {
dslContext.update(this)
Expand All @@ -90,4 +89,15 @@ class MarketAtomOfflineDao {
.execute()
}
}

/**
* 删除插件下线记录
*/
fun deleteAtomOffline(dslContext: DSLContext, atomCode: String) {
with(TAtomOffline.T_ATOM_OFFLINE) {
dslContext.deleteFrom(this)
.where(ATOM_CODE.eq(atomCode))
.execute()
}
}
}
Expand Up @@ -27,6 +27,7 @@
package com.tencent.devops.store.dao.atom

import com.tencent.devops.common.api.util.UUIDUtil
import com.tencent.devops.model.store.tables.TAtom
import com.tencent.devops.model.store.tables.TAtomVersionLog
import com.tencent.devops.model.store.tables.records.TAtomVersionLogRecord
import org.jooq.DSLContext
Expand Down Expand Up @@ -70,4 +71,14 @@ class MarketAtomVersionLogDao {
.fetchOne()
}
}

fun deleteByAtomCode(dslContext: DSLContext, atomCode: String) {
val ta = TAtom.T_ATOM
val atomIds = dslContext.select(ta.ID).from(ta).fetch()
with(TAtomVersionLog.T_ATOM_VERSION_LOG) {
dslContext.deleteFrom(this)
.where(ATOM_ID.`in`(atomIds))
.execute()
}
}
}
Expand Up @@ -97,4 +97,12 @@ class OperationLogDao {
dslContext.batch(addStep).execute()
}
}

fun deleteOperationLog(dslContext: DSLContext, storeCode: String, storeType: Byte) {
with(TStoreOptLog.T_STORE_OPT_LOG) {
dslContext.deleteFrom(this)
.where(STORE_CODE.eq(storeCode).and(STORE_TYPE.eq(storeType)))
.execute()
}
}
}
Expand Up @@ -38,6 +38,7 @@ class ReasonRelDao {
id: String,
userId: String,
storeCode: String,
storeType: Byte,
reasonId: String,
note: String?,
type: String
Expand All @@ -49,6 +50,7 @@ class ReasonRelDao {
REASON_ID,
NOTE,
STORE_CODE,
STORE_TYPE,
TYPE,
CREATOR
)
Expand All @@ -57,6 +59,7 @@ class ReasonRelDao {
reasonId,
note,
storeCode,
storeType,
type,
userId
).execute()
Expand All @@ -74,4 +77,13 @@ class ReasonRelDao {
.fetchOne(0, Long::class.java) != 0L
}
}

fun deleteReasonRel(dslContext: DSLContext, storeCode: String, storeType: Byte) {
with(TReasonRel.T_REASON_REL) {
dslContext.deleteFrom(this)
.where(STORE_CODE.eq(storeCode))
.and(STORE_TYPE.eq(storeType))
.execute()
}
}
}
Expand Up @@ -168,4 +168,15 @@ class SensitiveConfDao {
.fetch()
}
}

/**
* 删除敏感信息配置
*/
fun deleteSensitiveConf(dslContext: DSLContext, storeCode: String, storeType: Byte) {
with(TStoreSensitiveConf.T_STORE_SENSITIVE_CONF) {
dslContext.deleteFrom(this)
.where(STORE_CODE.eq(storeCode).and(STORE_TYPE.eq(storeType)))
.execute()
}
}
}
Expand Up @@ -200,4 +200,12 @@ class StoreApproveDao {
.fetchOne()
}
}

fun deleteApproveInfo(dslContext: DSLContext, storeCode: String, storeType: Byte) {
with(TStoreApprove.T_STORE_APPROVE) {
dslContext.deleteFrom(this)
.where(STORE_CODE.eq(storeCode).and(STORE_TYPE.eq(storeType)))
.execute()
}
}
}
Expand Up @@ -168,4 +168,12 @@ class StoreCommentDao {
.fetch()
}
}

fun deleteStoreComment(dslContext: DSLContext, storeCode: String, storeType: Byte) {
with(TStoreComment.T_STORE_COMMENT) {
dslContext.deleteFrom(this)
.where(STORE_CODE.eq(storeCode).and(STORE_TYPE.eq(storeType)))
.execute()
}
}
}
Expand Up @@ -27,6 +27,7 @@
package com.tencent.devops.store.dao.common

import com.tencent.devops.common.api.util.UUIDUtil
import com.tencent.devops.model.store.tables.TStoreComment
import com.tencent.devops.model.store.tables.TStoreCommentPraise
import com.tencent.devops.model.store.tables.records.TStoreCommentPraiseRecord
import org.jooq.DSLContext
Expand Down Expand Up @@ -74,4 +75,16 @@ class StoreCommentPraiseDao {
dslContext.deleteFrom(this).where(COMMENT_ID.eq(commentId).and(CREATOR.eq(userId))).execute()
}
}

fun deleteStoreCommentPraise(dslContext: DSLContext, storeCode: String, storeType: Byte) {
val tsc = TStoreComment.T_STORE_COMMENT
val commentIds =
dslContext.select(tsc.ID).from(tsc).where(tsc.STORE_CODE.eq(storeCode).and(tsc.STORE_TYPE.eq(storeType)))
.fetch()
with(TStoreCommentPraise.T_STORE_COMMENT_PRAISE) {
dslContext.deleteFrom(this)
.where(COMMENT_ID.`in`(commentIds))
.execute()
}
}
}
Expand Up @@ -26,6 +26,7 @@

package com.tencent.devops.store.dao.common

import com.tencent.devops.model.store.tables.TStoreComment
import com.tencent.devops.model.store.tables.TStoreCommentReply
import com.tencent.devops.model.store.tables.records.TStoreCommentReplyRecord
import com.tencent.devops.store.pojo.common.StoreCommentReplyRequest
Expand Down Expand Up @@ -92,4 +93,16 @@ class StoreCommentReplyDao {
).execute()
}
}

fun deleteStoreCommentReply(dslContext: DSLContext, storeCode: String, storeType: Byte) {
val tsc = TStoreComment.T_STORE_COMMENT
val commentIds =
dslContext.select(tsc.ID).from(tsc).where(tsc.STORE_CODE.eq(storeCode).and(tsc.STORE_TYPE.eq(storeType)))
.fetch()
with(TStoreCommentReply.T_STORE_COMMENT_REPLY) {
dslContext.deleteFrom(this)
.where(COMMENT_ID.`in`(commentIds))
.execute()
}
}
}
Expand Up @@ -197,4 +197,13 @@ class StoreEnvVarDao {
return baseStep.fetch()
}
}

fun deleteEnvVar(dslContext: DSLContext, storeCode: String, storeType: Byte) {
with(TStoreEnvVar.T_STORE_ENV_VAR) {
dslContext.deleteFrom(this)
.where(STORE_CODE.eq(storeCode))
.and(STORE_TYPE.eq(storeType))
.execute()
}
}
}

0 comments on commit fece732

Please sign in to comment.