Search in sources :

Example 1 with CommonException

use of io.choerodon.core.exception.CommonException in project knowledgebase-service by open-hand.

the class WorkSpaceServiceImpl method fillAttribute.

private void fillAttribute(Map<Long, UserDO> userDOMap, Map<String, FileVO> finalLongFileVOMap, WorkSpaceInfoVO workSpaceInfoVO) {
    UserDO userDO = userDOMap.get(workSpaceInfoVO.getCreatedBy());
    UserDO updateUser = userDOMap.get(workSpaceInfoVO.getLastUpdatedBy());
    workSpaceInfoVO.setCreateUser(userDO);
    workSpaceInfoVO.setLastUpdatedUser(updateUser);
    // 填充属性
    switch(WorkSpaceType.valueOf(workSpaceInfoVO.getType().toUpperCase())) {
        case FILE:
            // 文件计算大小
            if (finalLongFileVOMap != null) {
                FileVO fileVO = finalLongFileVOMap.get(workSpaceInfoVO.getFileKey());
                if (fileVO != null) {
                    workSpaceInfoVO.setFileSize(fileVO.getFileSize());
                }
            } else {
                workSpaceInfoVO.setFileSize(0L);
            }
            break;
        case DOCUMENT:
        case FOLDER:
            // 计算子项  这里也只管直接子项
            // 查询该工作空间的直接子项
            WorkSpaceDTO workSpaceDTO = new WorkSpaceDTO();
            workSpaceDTO.setParentId(workSpaceInfoVO.getId());
            List<WorkSpaceDTO> spaceDTOS = workSpaceMapper.select(workSpaceDTO);
            if (CollectionUtils.isEmpty(spaceDTOS)) {
                workSpaceInfoVO.setSubFiles(0L);
            } else {
                List<WorkSpaceDTO> files = spaceDTOS.stream().filter(spaceDTO1 -> StringUtils.equalsIgnoreCase(spaceDTO1.getType(), WorkSpaceType.FILE.getValue())).collect(Collectors.toList());
                List<WorkSpaceDTO> documents = spaceDTOS.stream().filter(spaceDTO1 -> StringUtils.equalsIgnoreCase(spaceDTO1.getType(), WorkSpaceType.DOCUMENT.getValue())).collect(Collectors.toList());
                List<WorkSpaceDTO> folders = spaceDTOS.stream().filter(spaceDTO1 -> StringUtils.equalsIgnoreCase(spaceDTO1.getType(), WorkSpaceType.FOLDER.getValue())).collect(Collectors.toList());
                workSpaceInfoVO.setSubFiles(Long.valueOf(files.size()));
                workSpaceInfoVO.setSubDocuments(Long.valueOf(documents.size()));
                workSpaceInfoVO.setSubFolders(Long.valueOf(folders.size()));
            }
            break;
        default:
            throw new CommonException("Unsupported knowledge space type");
    }
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) LoggerFactory(org.slf4j.LoggerFactory) BaseFeignClient(io.choerodon.kb.infra.feign.BaseFeignClient) Autowired(org.springframework.beans.factory.annotation.Autowired) PageCommentRepository(io.choerodon.kb.infra.repository.PageCommentRepository) CustomUserDetails(io.choerodon.core.oauth.CustomUserDetails) IEncryptionService(org.hzero.starter.keyencrypt.core.IEncryptionService) AgileFeignOperator(io.choerodon.kb.infra.feign.operator.AgileFeignOperator) Pair(org.apache.commons.lang3.tuple.Pair) WorkSpaceAssembler(io.choerodon.kb.app.service.assembler.WorkSpaceAssembler) WorkSpaceType(io.choerodon.kb.infra.enums.WorkSpaceType) DetailsHelper(io.choerodon.core.oauth.DetailsHelper) PageHelper(io.choerodon.mybatis.pagehelper.PageHelper) Collectors(java.util.stream.Collectors) BaseStage(io.choerodon.kb.infra.common.BaseStage) Stream(java.util.stream.Stream) io.choerodon.kb.app.service(io.choerodon.kb.app.service) UserDO(io.choerodon.kb.infra.feign.vo.UserDO) FileVO(io.choerodon.kb.infra.feign.vo.FileVO) Page(io.choerodon.core.domain.Page) io.choerodon.kb.infra.utils(io.choerodon.kb.infra.utils) FileSimpleDTO(org.hzero.boot.file.dto.FileSimpleDTO) BeanUtils(org.springframework.beans.BeanUtils) PageRepository(io.choerodon.kb.infra.repository.PageRepository) java.util(java.util) io.choerodon.kb.infra.dto(io.choerodon.kb.infra.dto) SimpleDateFormat(java.text.SimpleDateFormat) TypeToken(com.google.common.reflect.TypeToken) Function(java.util.function.Function) CollectionUtils(org.apache.commons.collections4.CollectionUtils) PageAttachmentRepository(io.choerodon.kb.infra.repository.PageAttachmentRepository) ModelMapper(org.modelmapper.ModelMapper) Service(org.springframework.stereotype.Service) CommonException(io.choerodon.core.exception.CommonException) OpenRangeType(io.choerodon.kb.infra.enums.OpenRangeType) EncryptContext(org.hzero.starter.keyencrypt.core.EncryptContext) Logger(org.slf4j.Logger) OrganizationDTO(io.choerodon.kb.infra.feign.vo.OrganizationDTO) ObjectUtils(org.springframework.util.ObjectUtils) io.choerodon.kb.api.vo(io.choerodon.kb.api.vo) ReferenceType(io.choerodon.kb.infra.enums.ReferenceType) DateUtils(org.apache.commons.lang3.time.DateUtils) BaseConstants(org.hzero.core.base.BaseConstants) MultipartFile(org.springframework.web.multipart.MultipartFile) io.choerodon.kb.infra.mapper(io.choerodon.kb.infra.mapper) ResponseEntity(org.springframework.http.ResponseEntity) ConvertUtils(io.choerodon.core.utils.ConvertUtils) PageUtils(io.choerodon.core.utils.PageUtils) PageRequest(io.choerodon.mybatis.pagehelper.domain.PageRequest) ArrayUtils(org.apache.commons.lang.ArrayUtils) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) UserDO(io.choerodon.kb.infra.feign.vo.UserDO) FileVO(io.choerodon.kb.infra.feign.vo.FileVO) CommonException(io.choerodon.core.exception.CommonException)

Example 2 with CommonException

use of io.choerodon.core.exception.CommonException in project knowledgebase-service by open-hand.

the class WorkSpaceServiceImpl method queryWorkSpaceInfo.

@Override
public WorkSpaceInfoVO queryWorkSpaceInfo(Long organizationId, Long projectId, Long workSpaceId, String searchStr) {
    WorkSpaceDTO workSpaceDTO = this.baseQueryByIdWithOrg(organizationId, projectId, workSpaceId);
    // 根据WorkSpace的类型返回相应的值
    switch(WorkSpaceType.valueOf(workSpaceDTO.getType().toUpperCase())) {
        case FOLDER:
            // todo  前端点击文件夹的时候应该不会发送请求???? 就展开下面的结构就行了???
            // 查询文件夹下子项
            WorkSpaceInfoVO workSpaceInfoVO = new WorkSpaceInfoVO();
            workSpaceInfoVO.setWorkSpace(buildTreeVO(workSpaceDTO, Collections.emptyList()));
            workSpaceInfoVO.setDelete(workSpaceDTO.getDelete());
            return workSpaceInfoVO;
        case DOCUMENT:
            return getWorkSpaceInfoVO(organizationId, projectId, workSpaceId, searchStr, workSpaceDTO);
        case FILE:
            WorkSpaceInfoVO file = new WorkSpaceInfoVO();
            FileVO fileDTOByFileKey = expandFileClient.getFileDTOByFileKey(organizationId, workSpaceDTO.getFileKey());
            file.setFileType(CommonUtil.getFileType(fileDTOByFileKey.getFileKey()));
            file.setTitle(CommonUtil.getFileName(fileDTOByFileKey.getFileKey()));
            file.setUrl(fileDTOByFileKey.getFileUrl());
            file.setKey(CommonUtil.getFileId(fileDTOByFileKey.getFileKey()));
            BeanUtils.copyProperties(file, workSpaceDTO);
            file.setWorkSpace(buildTreeVO(workSpaceDTO, Collections.emptyList()));
            file.setDelete(workSpaceDTO.getDelete());
            return file;
        default:
            throw new CommonException("Unsupported knowledge space type");
    }
}
Also used : FileVO(io.choerodon.kb.infra.feign.vo.FileVO) CommonException(io.choerodon.core.exception.CommonException)

Example 3 with CommonException

use of io.choerodon.core.exception.CommonException in project knowledgebase-service by open-hand.

the class WorkSpaceServiceImpl method removeWorkSpaceAndPage.

@Override
public void removeWorkSpaceAndPage(Long organizationId, Long projectId, Long workspaceId, Boolean isAdmin) {
    WorkSpaceDTO workSpaceDTO = this.baseQueryById(organizationId, projectId, workspaceId);
    if (StringUtils.equalsIgnoreCase(workSpaceDTO.getType(), WorkSpaceType.FILE.getValue()) || StringUtils.equalsIgnoreCase(workSpaceDTO.getType(), WorkSpaceType.FOLDER.getValue())) {
        workSpaceDTO.setDelete(true);
        this.baseUpdate(workSpaceDTO);
    } else if (StringUtils.equalsIgnoreCase(workSpaceDTO.getType(), WorkSpaceType.DOCUMENT.getValue())) {
        WorkSpacePageDTO workSpacePageDTO = workSpacePageService.selectByWorkSpaceId(workspaceId);
        if (Boolean.FALSE.equals(isAdmin)) {
            Long currentUserId = DetailsHelper.getUserDetails().getUserId();
            PageDTO pageDTO = pageRepository.baseQueryById(organizationId, projectId, workSpacePageDTO.getPageId());
            if (!workSpacePageDTO.getCreatedBy().equals(currentUserId) && !pageDTO.getCreatedBy().equals(currentUserId)) {
                throw new CommonException(ERROR_WORKSPACE_ILLEGAL);
            }
        }
        workSpaceDTO.setDelete(true);
        this.baseUpdate(workSpaceDTO);
        // 删除agile关联的workspace
        agileFeignOperator.deleteByworkSpaceId(projectId == null ? organizationId : projectId, workspaceId);
    } else {
        throw new CommonException("Unsupported knowledge space type");
    }
}
Also used : CommonException(io.choerodon.core.exception.CommonException)

Example 4 with CommonException

use of io.choerodon.core.exception.CommonException in project knowledgebase-service by open-hand.

the class DataFixServiceImpl method buildInitData.

private List<InitKnowledgeBaseTemplateVO> buildInitData() {
    List<InitKnowledgeBaseTemplateVO> list = new ArrayList<>();
    try {
        String template = HtmlUtil.loadHtmlTemplate("/htmlTemplate/InitTemplate.html");
        String[] split = template.split("<div/>");
        InitKnowledgeBaseTemplateVO knowledgeBaseTemplateA = new InitKnowledgeBaseTemplateVO();
        knowledgeBaseTemplateA.setName("会议记录");
        List<PageCreateVO> pageCreateVOSA = new ArrayList<>();
        String meetingMinutes = "记录重大会议的参会情况狂,以及会议内容、会议讨论输出的内容。";
        String productPlan = "产品规划会产出当前迭代的完成任务项,以及下个迭代预计进行的任务项。";
        String reviewConference = "敏捷过程中的一个重要会议,总结陈述迭代进行的优缺点,以及对应的整改方案。";
        pageCreateVOSA.add(new PageCreateVO(0L, "会议纪要", meetingMinutes, split[2], WorkSpaceType.DOCUMENT.getValue()));
        pageCreateVOSA.add(new PageCreateVO(0L, "产品规划会", productPlan, split[4], WorkSpaceType.DOCUMENT.getValue()));
        pageCreateVOSA.add(new PageCreateVO(0L, "敏捷迭代回顾会议", reviewConference, split[5], WorkSpaceType.DOCUMENT.getValue()));
        knowledgeBaseTemplateA.setTemplatePage(pageCreateVOSA);
        list.add(knowledgeBaseTemplateA);
        InitKnowledgeBaseTemplateVO knowledgeBaseTemplateB = new InitKnowledgeBaseTemplateVO();
        knowledgeBaseTemplateB.setName("产品研发");
        List<PageCreateVO> pageCreateVOSB = new ArrayList<>();
        String prdDescription = "PRD可以将产品设计思路清晰的展现给团队人员,便于他们快速理解产品,同时可以记录需求的变更历史,以便于快速了解功能的变化。";
        String technicalDocuments = "产品开发过程中所用框架的说明,接口设计说明,帮助前后端开发人员快速了解技术相关的设计。";
        String competitiveAnalysis = "包含对市场的分析,竞品情况的了解,分析出自己产品的优劣势,产出分析结果和应对建议。";
        pageCreateVOSB.add(new PageCreateVO(0L, "技术文档", technicalDocuments, split[1], WorkSpaceType.DOCUMENT.getValue()));
        pageCreateVOSB.add(new PageCreateVO(0L, "竞品分析", competitiveAnalysis, split[3], WorkSpaceType.DOCUMENT.getValue()));
        pageCreateVOSB.add(new PageCreateVO(0L, "产品需求文档PRD", prdDescription, split[0], WorkSpaceType.DOCUMENT.getValue()));
        knowledgeBaseTemplateB.setTemplatePage(pageCreateVOSB);
        list.add(knowledgeBaseTemplateB);
        InitKnowledgeBaseTemplateVO knowledgeBaseTemplateC = new InitKnowledgeBaseTemplateVO();
        knowledgeBaseTemplateC.setName("产品测试");
        List<PageCreateVO> pageCreateVOSC = new ArrayList<>();
        String testPlan = "根据产品质量等级结合产品研发现状,确定测试范围、确定测试需求、制定测试策略、确定测试方法、确定测试资源、制定测试风险应对方案、评估测试交付件,预估迭代功能测试和SIT/UAT测试的工作量,进行人员和进度的安排。";
        pageCreateVOSC.add(new PageCreateVO(0L, "产品测试计划", testPlan, split[6], WorkSpaceType.DOCUMENT.getValue()));
        knowledgeBaseTemplateC.setTemplatePage(pageCreateVOSC);
        list.add(knowledgeBaseTemplateC);
    } catch (IOException e) {
        throw new CommonException(e);
    }
    return list;
}
Also used : InitKnowledgeBaseTemplateVO(io.choerodon.kb.api.vo.InitKnowledgeBaseTemplateVO) PageCreateVO(io.choerodon.kb.api.vo.PageCreateVO) ArrayList(java.util.ArrayList) CommonException(io.choerodon.core.exception.CommonException) IOException(java.io.IOException)

Example 5 with CommonException

use of io.choerodon.core.exception.CommonException in project knowledgebase-service by open-hand.

the class PageCommentServiceImpl method delete.

@Override
public void delete(Long organizationId, Long projectId, Long id, Boolean isAdmin) {
    PageCommentDTO comment = pageCommentRepository.baseQueryById(id);
    pageRepository.checkById(organizationId, projectId, comment.getPageId());
    if (Boolean.FALSE.equals(isAdmin)) {
        Long currentUserId = DetailsHelper.getUserDetails().getUserId();
        if (!comment.getCreatedBy().equals(currentUserId)) {
            throw new CommonException(ERROR_ILLEGAL);
        }
    }
    pageCommentRepository.baseDelete(id);
}
Also used : CommonException(io.choerodon.core.exception.CommonException) PageCommentDTO(io.choerodon.kb.infra.dto.PageCommentDTO)

Aggregations

CommonException (io.choerodon.core.exception.CommonException)739 Transactional (org.springframework.transaction.annotation.Transactional)93 IOException (java.io.IOException)90 Autowired (org.springframework.beans.factory.annotation.Autowired)53 ProjectDTO (io.choerodon.devops.infra.dto.iam.ProjectDTO)50 JSONObject (com.alibaba.fastjson.JSONObject)44 IssueDTO (io.choerodon.agile.infra.dto.business.IssueDTO)44 Collectors (java.util.stream.Collectors)40 Page (io.choerodon.core.domain.Page)39 Service (org.springframework.stereotype.Service)38 PageRequest (io.choerodon.mybatis.pagehelper.domain.PageRequest)36 File (java.io.File)33 RetryableException (feign.RetryableException)32 GitOpsExplainException (io.choerodon.devops.infra.exception.GitOpsExplainException)32 java.util (java.util)32 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)31 ResourceLevel (io.choerodon.core.iam.ResourceLevel)30 MultipartFile (org.springframework.web.multipart.MultipartFile)30 CollectionUtils (org.springframework.util.CollectionUtils)29 List (java.util.List)28