Search in sources :

Example 6 with CustomUserDetails

use of io.choerodon.core.oauth.CustomUserDetails in project test-manager-service by open-hand.

the class TestCycleCaseAttachmentRelServiceImpl method snycByCase.

@Override
public void snycByCase(TestCycleCaseDTO testCycleCaseDTO, TestCaseDTO testCaseDTO) {
    CustomUserDetails userDetails = DetailsHelper.getUserDetails();
    testCycleCaseDTO.setLastUpdatedBy(userDetails.getUserId());
    testCycleCaseDTO.setCreatedBy(userDetails.getUserId());
    testCycleCaseAttachmentRelMapper.batchDeleteByLinkIdsAndType(Arrays.asList(testCycleCaseDTO.getExecuteId()), TestAttachmentCode.ATTACHMENT_CYCLE_CASE);
    List<TestCaseAttachmentDTO> attachmentDTOS = testAttachmentMapper.listByCaseIds(Arrays.asList(testCaseDTO.getCaseId()));
    Map<Long, List<TestCaseAttachmentDTO>> attachMap = attachmentDTOS.stream().collect(Collectors.groupingBy(TestCaseAttachmentDTO::getCaseId));
    batchInsert(Arrays.asList(testCycleCaseDTO), attachMap);
}
Also used : CustomUserDetails(io.choerodon.core.oauth.CustomUserDetails) TestCaseAttachmentDTO(io.choerodon.test.manager.infra.dto.TestCaseAttachmentDTO)

Example 7 with CustomUserDetails

use of io.choerodon.core.oauth.CustomUserDetails in project test-manager-service by open-hand.

the class TestPriorityServiceImpl method delete.

@Override
public void delete(Long organizationId, TestPriorityDTO testPriorityDTO) {
    Long priorityId = testPriorityDTO.getId();
    Long changePriorityId = testPriorityDTO.getChangePriorityId();
    if (priorityId.equals(changePriorityId)) {
        throw new CommonException(DELETE_ILLEGAL);
    }
    checkLastPriority(organizationId, priorityId);
    TestPriorityDTO priority = testPriorityMapper.selectByPrimaryKey(priorityId);
    Long count = checkDelete(organizationId, priorityId);
    List<ProjectDTO> projectVOS = baseFeignClient.listProjectsByOrgId(organizationId).getBody();
    List<Long> projectIds = projectVOS.stream().map(ProjectDTO::getId).collect(Collectors.toList());
    // 执行优先级转换
    if (!count.equals(0L)) {
        if (changePriorityId == null) {
            throw new CommonException(DELETE_ILLEGAL);
        }
        CustomUserDetails customUserDetails = DetailsHelper.getUserDetails();
        this.batchChangeIssuePriority(organizationId, priorityId, changePriorityId, customUserDetails.getUserId(), projectIds);
    }
    int isDelete = testPriorityMapper.deleteByPrimaryKey(priorityId);
    if (isDelete != 1) {
        throw new CommonException("error.priority.delete");
    }
    if (priority.getDefaultFlag()) {
        updateOtherDefault(organizationId);
    }
}
Also used : ProjectDTO(io.choerodon.test.manager.api.vo.agile.ProjectDTO) TestPriorityDTO(io.choerodon.test.manager.infra.dto.TestPriorityDTO) CustomUserDetails(io.choerodon.core.oauth.CustomUserDetails) CommonException(io.choerodon.core.exception.CommonException)

Example 8 with CustomUserDetails

use of io.choerodon.core.oauth.CustomUserDetails in project test-manager-service by open-hand.

the class TestCycleCaseServiceImpl method cloneCycleCase.

@Override
public void cloneCycleCase(Map<Long, Long> cycleMapping, List<Long> cycIds) {
    Long defaultStatusId = testStatusService.getDefaultStatusId(TestStatusType.STATUS_TYPE_CASE);
    Integer count = testCycleCaseMapper.countByCycleIds(cycIds);
    int ceil = (int) Math.ceil(count / AVG_NUM == 0 ? 0 : count / AVG_NUM);
    for (int page = 0; page < ceil; page++) {
        Page<TestCycleCaseDTO> testCyclePageInfo = PageHelper.doPageAndSort(new PageRequest(page, 500), () -> testCycleCaseMapper.listByCycleIds(cycIds));
        if (CollectionUtils.isEmpty(testCyclePageInfo.getContent())) {
            return;
        }
        List<TestCycleCaseDTO> testCycleCaseDTOS = testCyclePageInfo.getContent();
        CustomUserDetails userDetails = DetailsHelper.getUserDetails();
        List<Long> olderExecuteIds = new ArrayList<>();
        testCycleCaseDTOS.forEach(v -> {
            olderExecuteIds.add(v.getExecuteId());
            v.setLastExecuteId(v.getExecuteId());
            v.setCycleId(cycleMapping.get(v.getCycleId()));
            v.setCreatedBy(userDetails.getUserId());
            v.setLastUpdatedBy(userDetails.getUserId());
            v.setExecuteId(null);
            v.setExecutionStatus(defaultStatusId);
        });
        bathcInsert(testCycleCaseDTOS);
        Map<Long, Long> caseIdMap = new HashMap<>();
        testCycleCaseDTOS.forEach(v -> caseIdMap.put(v.getLastExecuteId(), v.getExecuteId()));
        // 复制步骤
        testCycleCaseStepService.cloneStep(caseIdMap, olderExecuteIds);
        // 复制附件
        testCycleCaseAttachmentRelService.cloneAttach(caseIdMap, olderExecuteIds, "CYCLE_CASE");
    }
}
Also used : CustomUserDetails(io.choerodon.core.oauth.CustomUserDetails) PageRequest(io.choerodon.mybatis.pagehelper.domain.PageRequest)

Example 9 with CustomUserDetails

use of io.choerodon.core.oauth.CustomUserDetails in project test-manager-service by open-hand.

the class TestCycleCaseStepServiceImpl method cloneStep.

@Override
public void cloneStep(Map<Long, Long> caseIdMap, List<Long> olderExecuteIds) {
    CustomUserDetails userDetails = DetailsHelper.getUserDetails();
    Long defaultStatusId = testStatusService.getDefaultStatusId(TestStatusType.STATUS_TYPE_CASE_STEP);
    int count = testCycleCaseStepMapper.countByExecuteIds(olderExecuteIds);
    int ceil = (int) Math.ceil(count / AVG_NUM == 0 ? 0 : count / AVG_NUM);
    for (int page = 0; page < ceil; page++) {
        Page<TestCycleCaseStepDTO> stepDTOPageInfo = PageHelper.doPageAndSort(new PageRequest(page, (int) AVG_NUM), () -> testCycleCaseStepMapper.listByexecuteIds(olderExecuteIds));
        List<TestCycleCaseStepDTO> list = stepDTOPageInfo.getContent();
        if (CollectionUtils.isEmpty(list)) {
            return;
        }
        List<Long> stepIds = new ArrayList<>();
        list.forEach(v -> {
            v.setExecuteId(caseIdMap.get(v.getExecuteId()));
            v.setExecuteStepId(null);
            v.setCreatedBy(userDetails.getUserId());
            v.setLastUpdatedBy(userDetails.getUserId());
            v.setCaseId(v.getExecuteStepId());
            v.setStepStatus(defaultStatusId);
            stepIds.add(v.getExecuteStepId());
        });
        testCycleCaseStepMapper.batchInsertTestCycleCaseSteps(list);
        Map<Long, Long> valueMapping = new HashMap<>();
        list.forEach(v -> valueMapping.put(v.getCaseId(), v.getExecuteStepId()));
        // 克隆步骤关联的附件
        testCycleCaseAttachmentRelService.cloneAttach(valueMapping, stepIds, "CASE_STEP");
        // 克隆步骤的缺陷
        testCycleCaseDefectRelService.cloneDefect(valueMapping, stepIds, "CASE_STEP");
    }
}
Also used : CustomUserDetails(io.choerodon.core.oauth.CustomUserDetails) PageRequest(io.choerodon.mybatis.pagehelper.domain.PageRequest)

Example 10 with CustomUserDetails

use of io.choerodon.core.oauth.CustomUserDetails in project test-manager-service by open-hand.

the class DataMigrationServiceImpl method migrateAttachment.

private void migrateAttachment() {
    List<TestCaseAttachmentDTO> attachmentDTOS = dataFixFeignClient.migrateAttachment().getBody();
    CustomUserDetails userDetails = DetailsHelper.getUserDetails();
    if (!CollectionUtils.isEmpty(attachmentDTOS)) {
        for (TestCaseAttachmentDTO testCaseAttachmentDTO : attachmentDTOS) {
            if (testCaseAttachmentDTO != null) {
                logger.info("==========>>>>>>>>SET Test Case Attachment caseId:{} <<<<<<<<=======", testCaseAttachmentDTO.getCaseId());
                testCaseAttachmentDTO.setUrl("/agile-service/" + testCaseAttachmentDTO.getUrl());
                testCaseAttachmentDTO.setCreatedBy(userDetails.getUserId());
                testCaseAttachmentDTO.setLastUpdatedBy(userDetails.getUserId());
            }
        }
        testAttachmentMapper.batchInsert(attachmentDTOS);
    }
    logger.info("===========attachment=============> copy successed");
}
Also used : CustomUserDetails(io.choerodon.core.oauth.CustomUserDetails)

Aggregations

CustomUserDetails (io.choerodon.core.oauth.CustomUserDetails)53 CommonException (io.choerodon.core.exception.CommonException)17 DetailsHelper (io.choerodon.core.oauth.DetailsHelper)7 Collectors (java.util.stream.Collectors)7 Autowired (org.springframework.beans.factory.annotation.Autowired)7 PageRequest (io.choerodon.mybatis.pagehelper.domain.PageRequest)6 java.util (java.util)6 Transactional (org.springframework.transaction.annotation.Transactional)6 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 MockHttpServletRequest (io.choerodon.asgard.saga.consumer.MockHttpServletRequest)4 Value (org.springframework.beans.factory.annotation.Value)4 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)4 Authentication (org.springframework.security.core.Authentication)4 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)4 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)4 Service (org.springframework.stereotype.Service)4 CollectionUtils (org.springframework.util.CollectionUtils)4 IssueDetailDTO (io.choerodon.agile.infra.dto.business.IssueDetailDTO)3 Page (io.choerodon.core.domain.Page)3