Search in sources :

Example 1 with StateMachineSchemeDTO

use of io.choerodon.agile.infra.dto.StateMachineSchemeDTO in project agile-service by open-hand.

the class StateMachineSchemeServiceImpl method activeSchemeWithRefProjectConfig.

@Override
public void activeSchemeWithRefProjectConfig(Long schemeId) {
    StateMachineSchemeDTO scheme = schemeMapper.selectByPrimaryKey(schemeId);
    // 活跃状态机方案
    if (scheme.getStatus().equals(StateMachineSchemeStatus.CREATE)) {
        scheme.setStatus(StateMachineSchemeStatus.ACTIVE);
        // Criteria criteria = new Criteria();
        // criteria.update("status");
        // int result = schemeMapper.updateByPrimaryKeyOptions(scheme, criteria);
        int result = schemeMapper.updateOptional(scheme, "status");
        if (result != 1) {
            throw new CommonException("error.stateMachineScheme.activeScheme");
        }
    }
    // 复制草稿配置到发布
    configService.copyDraftToDeploy(false, scheme.getOrganizationId(), schemeId);
    // 活跃方案下的所有新建状态机
    List<StatusMachineSchemeConfigVO> configs = configService.queryBySchemeId(false, scheme.getOrganizationId(), schemeId);
    stateMachineService.activeStateMachines(scheme.getOrganizationId(), configs.stream().map(StatusMachineSchemeConfigVO::getStateMachineId).distinct().collect(Collectors.toList()));
}
Also used : StateMachineSchemeDTO(io.choerodon.agile.infra.dto.StateMachineSchemeDTO) CommonException(io.choerodon.core.exception.CommonException)

Example 2 with StateMachineSchemeDTO

use of io.choerodon.agile.infra.dto.StateMachineSchemeDTO in project agile-service by open-hand.

the class StateMachineSchemeServiceImpl method checkName.

@Override
public Boolean checkName(Long organizationId, String name) {
    StateMachineSchemeDTO scheme = new StateMachineSchemeDTO();
    scheme.setOrganizationId(organizationId);
    scheme.setName(name);
    StateMachineSchemeDTO res = schemeMapper.selectOne(scheme);
    return res != null;
}
Also used : StateMachineSchemeDTO(io.choerodon.agile.infra.dto.StateMachineSchemeDTO)

Example 3 with StateMachineSchemeDTO

use of io.choerodon.agile.infra.dto.StateMachineSchemeDTO in project agile-service by open-hand.

the class StateMachineSchemeServiceImpl method create.

@Override
public StateMachineSchemeVO create(Long organizationId, StateMachineSchemeVO schemeVO) {
    if (checkName(organizationId, schemeVO.getName())) {
        throw new CommonException("error.stateMachineName.exist");
    }
    schemeVO.setStatus(StateMachineSchemeStatus.CREATE);
    StateMachineSchemeDTO scheme = modelMapper.map(schemeVO, StateMachineSchemeDTO.class);
    scheme.setOrganizationId(organizationId);
    int isInsert = schemeMapper.insert(scheme);
    if (isInsert != 1) {
        throw new CommonException("error.stateMachineScheme.create");
    }
    // 创建一个defaultConfig
    StatusMachineVO statusMachineVO = stateMachineService.queryDefaultStateMachine(organizationId);
    configService.createDefaultConfig(organizationId, scheme.getId(), statusMachineVO.getId());
    scheme = schemeMapper.selectByPrimaryKey(scheme);
    return modelMapper.map(scheme, StateMachineSchemeVO.class);
}
Also used : StateMachineSchemeDTO(io.choerodon.agile.infra.dto.StateMachineSchemeDTO) CommonException(io.choerodon.core.exception.CommonException)

Example 4 with StateMachineSchemeDTO

use of io.choerodon.agile.infra.dto.StateMachineSchemeDTO in project agile-service by open-hand.

the class StateMachineSchemeServiceImpl method pageQuery.

@Override
public Page<StateMachineSchemeVO> pageQuery(Long organizationId, PageRequest pageRequest, StateMachineSchemeVO schemeVO, String params) {
    // 查询出组织下的所有项目
    List<ProjectVO> projectVOS = baseFeignClient.listProjectsByOrgId(organizationId).getBody();
    Map<Long, ProjectVO> projectMap = projectVOS.stream().collect(Collectors.toMap(ProjectVO::getId, x -> x));
    // 查询组织下的所有问题类型
    Map<Long, IssueTypeDTO> issueTypeMap = new HashMap<>();
    issueTypeMapper.selectByOptions(organizationId, 0L, null).forEach(x -> {
        IssueTypeDTO dto = modelMapper.map(x, IssueTypeDTO.class);
        issueTypeMap.put(x.getId(), dto);
    });
    // 查询组织下的所有状态机
    List<StatusMachineVO> statusMachineVOS = stateMachineService.queryByOrgId(organizationId);
    Map<Long, StatusMachineVO> stateMachineVOMap = statusMachineVOS.stream().collect(Collectors.toMap(StatusMachineVO::getId, x -> x));
    StateMachineSchemeDTO scheme = modelMapper.map(schemeVO, StateMachineSchemeDTO.class);
    Page<StateMachineSchemeDTO> page = PageHelper.doPageAndSort(pageRequest, () -> schemeMapper.fulltextSearch(scheme, params));
    List<StateMachineSchemeDTO> schemes = page.getContent();
    List<StateMachineSchemeDTO> schemesWithConfigs = new ArrayList<>();
    if (!schemes.isEmpty()) {
        schemesWithConfigs = schemeMapper.queryByIdsWithConfig(organizationId, schemes.stream().map(StateMachineSchemeDTO::getId).collect(Collectors.toList()));
    }
    List<StateMachineSchemeVO> schemeVOS = ConvertUtils.convertStateMachineSchemesToVOS(schemesWithConfigs, projectMap);
    if (schemeVOS != null) {
        handleSchemeConfig(schemeVOS, issueTypeMap, stateMachineVOMap);
    }
    return PageUtil.buildPageInfoWithPageInfoList(page, schemeVOS);
}
Also used : java.util(java.util) TypeToken(org.modelmapper.TypeToken) IssueTypeMapper(io.choerodon.agile.infra.mapper.IssueTypeMapper) Autowired(org.springframework.beans.factory.annotation.Autowired) ModelMapper(org.modelmapper.ModelMapper) io.choerodon.agile.infra.utils(io.choerodon.agile.infra.utils) Service(org.springframework.stereotype.Service) io.choerodon.agile.app.service(io.choerodon.agile.app.service) CommonException(io.choerodon.core.exception.CommonException) StateMachineSchemeDTO(io.choerodon.agile.infra.dto.StateMachineSchemeDTO) SchemeType(io.choerodon.agile.infra.enums.SchemeType) ProjectEvent(io.choerodon.agile.api.vo.event.ProjectEvent) BaseFeignClient(io.choerodon.agile.infra.feign.BaseFeignClient) PageHelper(io.choerodon.mybatis.pagehelper.PageHelper) io.choerodon.agile.api.vo(io.choerodon.agile.api.vo) IssueTypeDTO(io.choerodon.agile.infra.dto.IssueTypeDTO) StateMachineSchemeMapper(io.choerodon.agile.infra.mapper.StateMachineSchemeMapper) Collectors(java.util.stream.Collectors) SchemeApplyType(io.choerodon.agile.infra.enums.SchemeApplyType) StateMachineSchemeDeployStatus(io.choerodon.agile.infra.enums.StateMachineSchemeDeployStatus) CollectionUtils(org.springframework.util.CollectionUtils) StateMachineSchemeStatus(io.choerodon.agile.infra.enums.StateMachineSchemeStatus) Page(io.choerodon.core.domain.Page) PageRequest(io.choerodon.mybatis.pagehelper.domain.PageRequest) Transactional(org.springframework.transaction.annotation.Transactional) StateMachineSchemeDTO(io.choerodon.agile.infra.dto.StateMachineSchemeDTO) IssueTypeDTO(io.choerodon.agile.infra.dto.IssueTypeDTO)

Example 5 with StateMachineSchemeDTO

use of io.choerodon.agile.infra.dto.StateMachineSchemeDTO in project agile-service by open-hand.

the class ChangeSchemeStatusAspect method interceptor.

@Around("updateStatusPointcut()")
public Object interceptor(ProceedingJoinPoint pjp) {
    // 下面两个数组中,参数值和参数名的个数和位置是一一对应的。
    Object[] args = pjp.getArgs();
    String[] argNames = ((MethodSignature) pjp.getSignature()).getParameterNames();
    Long schemeId = null;
    for (int i = 0; i < argNames.length; i++) {
        if (argNames[i].equals("schemeId")) {
            schemeId = Long.valueOf(args[i] + "");
        }
    }
    logger.info("schemeId:{}", schemeId);
    StateMachineSchemeDTO scheme = schemeMapper.selectByPrimaryKey(schemeId);
    if (scheme == null) {
        throw new CommonException("error.scheme.notFound");
    }
    if (scheme.getStatus().equals(StateMachineSchemeStatus.ACTIVE)) {
        scheme.setStatus(StateMachineSchemeStatus.DRAFT);
        schemeMapper.updateOptional(scheme, "status");
    }
    try {
        return pjp.proceed();
    } catch (Throwable e) {
        throw new CommonException("error.changeSchemeStatusAspect.proceed", e);
    }
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) StateMachineSchemeDTO(io.choerodon.agile.infra.dto.StateMachineSchemeDTO) CommonException(io.choerodon.core.exception.CommonException) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Around(org.aspectj.lang.annotation.Around)

Aggregations

StateMachineSchemeDTO (io.choerodon.agile.infra.dto.StateMachineSchemeDTO)12 CommonException (io.choerodon.core.exception.CommonException)9 IssueTypeDTO (io.choerodon.agile.infra.dto.IssueTypeDTO)2 TypeToken (org.modelmapper.TypeToken)2 Transactional (org.springframework.transaction.annotation.Transactional)2 io.choerodon.agile.api.vo (io.choerodon.agile.api.vo)1 StateMachineSchemeVO (io.choerodon.agile.api.vo.StateMachineSchemeVO)1 ProjectEvent (io.choerodon.agile.api.vo.event.ProjectEvent)1 io.choerodon.agile.app.service (io.choerodon.agile.app.service)1 SchemeApplyType (io.choerodon.agile.infra.enums.SchemeApplyType)1 SchemeType (io.choerodon.agile.infra.enums.SchemeType)1 StateMachineSchemeDeployStatus (io.choerodon.agile.infra.enums.StateMachineSchemeDeployStatus)1 StateMachineSchemeStatus (io.choerodon.agile.infra.enums.StateMachineSchemeStatus)1 BaseFeignClient (io.choerodon.agile.infra.feign.BaseFeignClient)1 IssueTypeMapper (io.choerodon.agile.infra.mapper.IssueTypeMapper)1 StateMachineSchemeMapper (io.choerodon.agile.infra.mapper.StateMachineSchemeMapper)1 io.choerodon.agile.infra.utils (io.choerodon.agile.infra.utils)1 Page (io.choerodon.core.domain.Page)1 PageHelper (io.choerodon.mybatis.pagehelper.PageHelper)1 PageRequest (io.choerodon.mybatis.pagehelper.domain.PageRequest)1