io.choerodon.core.iam.ResourceLevel Java Examples

The following examples show how to use io.choerodon.core.iam.ResourceLevel. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProductVersionServiceImpl.java    From agile-service-old with Apache License 2.0 6 votes vote down vote up
@Saga(code = "agile-delete-version", description = "删除版本", inputSchemaClass = VersionPayload.class)
private Boolean simpleDeleteVersion(Long projectId, Long versionId) {
    try {
        ProductVersionDTO version = new ProductVersionDTO();
        version.setProjectId(projectId);
        version.setVersionId(versionId);
        ProductVersionDTO versionDTO = productVersionMapper.selectOne(version);
        if (versionDTO == null) {
            throw new CommonException(NOT_FOUND);
        }
        Boolean deleteResult = iProductVersionService.delete(versionDTO);
        VersionPayload versionPayload = new VersionPayload();
        versionPayload.setVersionId(versionDTO.getVersionId());
        versionPayload.setProjectId(versionDTO.getProjectId());
        sagaClient.startSaga("agile-delete-version", new StartInstanceDTO(JSON.toJSONString(versionPayload), "", "", ResourceLevel.PROJECT.value(), projectId));
        return deleteResult;
    } catch (Exception e) {
        throw new CommonException(e.getMessage());
    }
}
 
Example #2
Source File: ProductVersionServiceImpl.java    From agile-service-old with Apache License 2.0 6 votes vote down vote up
@Override
@Saga(code = "agile-delete-version", description = "删除版本", inputSchemaClass = VersionPayload.class)
public Boolean mergeVersion(Long projectId, ProductVersionMergeVO productVersionMergeVO) {
    productVersionMergeVO.getSourceVersionIds().remove(productVersionMergeVO.getTargetVersionId());
    if (productVersionMergeVO.getSourceVersionIds().isEmpty()) {
        throw new CommonException(SOURCE_VERSION_ERROR);
    }
    CustomUserDetails customUserDetails = DetailsHelper.getUserDetails();
    List<VersionIssueDTO> versionIssues = productVersionMapper.queryIssueByVersionIds(projectId, productVersionMergeVO.getSourceVersionIds(), productVersionMergeVO.getTargetVersionId());
    versionIssueRelService.deleteByVersionIds(projectId, productVersionMergeVO.getSourceVersionIds());
    if (!versionIssues.isEmpty()) {
        iProductVersionService.batchIssueToDestination(projectId, productVersionMergeVO.getTargetVersionId(), versionIssues, new Date(), customUserDetails.getUserId());
    }
    //这里不用日志是因为deleteByVersionIds方法已经有删除的日志了
    deleteByVersionIds(projectId, productVersionMergeVO.getSourceVersionIds());
    productVersionMergeVO.getSourceVersionIds().forEach(versionId -> {
        VersionPayload versionPayload = new VersionPayload();
        versionPayload.setVersionId(versionId);
        versionPayload.setProjectId(projectId);
        sagaClient.startSaga("agile-delete-version", new StartInstanceDTO(JSON.toJSONString(versionPayload), "", "", ResourceLevel.PROJECT.value(), projectId));
    });
    return true;
}
 
Example #3
Source File: ProjectConfigServiceImpl.java    From agile-service-old with Apache License 2.0 6 votes vote down vote up
@Saga(code = "agile-remove-status", description = "移除状态", inputSchemaClass = StatusPayload.class)
@Override
public void removeStatusForAgile(Long projectId, Long statusId, String applyType) {
    Map<String, Object> result = checkCreateStatusForAgile(projectId, applyType);
    Boolean flag = (Boolean) result.get(FLAG);
    if (flag) {
        Long stateMachineId = (Long) result.get(STATEMACHINEID);
        Long organizationId = projectUtil.getOrganizationId(projectId);
        Long initStatusId = instanceService.queryInitStatusId(organizationId, stateMachineId);
        if (statusId.equals(initStatusId)) {
            throw new CommonException("error.initStatus.illegal");
        }
        try {
            statusService.removeStatusForAgile(organizationId, stateMachineId, statusId);
            StatusPayload statusPayload = new StatusPayload();
            statusPayload.setProjectId(projectId);
            statusPayload.setStatusId(statusId);
            sagaClient.startSaga("agile-remove-status", new StartInstanceDTO(JSON.toJSONString(statusPayload), "", "", ResourceLevel.PROJECT.value(), projectId));
        } catch (Exception e) {
            throw new RemoveStatusException("error.status.remove");
        }
    } else {
        throw new RemoveStatusException((String) result.get(MESSAGE));
    }
}
 
Example #4
Source File: ProductVersionServiceImpl.java    From agile-service-old with Apache License 2.0 5 votes vote down vote up
@Saga(code = "agile-create-version", description = "创建版本", inputSchemaClass = VersionPayload.class)
@Override
public synchronized ProductVersionDetailVO createVersion(Long projectId, ProductVersionCreateVO versionCreateVO) {
    try {
        if (!projectId.equals(versionCreateVO.getProjectId())) {
            throw new CommonException(NOT_EQUAL_ERROR);
        }
        ProductVersionDTO productVersionDTO = productVersionCreateAssembler.toTarget(versionCreateVO, ProductVersionDTO.class);
        productVersionValidator.checkDate(productVersionDTO);
        productVersionValidator.judgeName(productVersionDTO.getProjectId(), productVersionDTO.getVersionId(), productVersionDTO.getName());
        //设置状态
        productVersionDTO.setStatusCode(VERSION_PLANNING);
        //设置编号
        Integer sequence = productVersionMapper.queryMaxSequenceByProject(projectId);
        productVersionDTO.setSequence(sequence == null ? 0 : sequence + 1);
        ProductVersionDetailVO result = new ProductVersionDetailVO();
        ProductVersionDTO query = create(productVersionDTO);
        BeanUtils.copyProperties(query, result);
        VersionPayload versionPayload = new VersionPayload();
        versionPayload.setVersionId(query.getVersionId());
        versionPayload.setProjectId(query.getProjectId());
        sagaClient.startSaga("agile-create-version", new StartInstanceDTO(JSON.toJSONString(versionPayload), "", "", ResourceLevel.PROJECT.value(), projectId));
        return result;
    } catch (Exception e) {
        throw new CommonException(e.getMessage());
    }

}
 
Example #5
Source File: IssueServiceImpl.java    From agile-service-old with Apache License 2.0 5 votes vote down vote up
public void deleteIssueInfo(Long issueId, Long projectId) {
    //删除issue发送消息
    IssuePayload issuePayload = new IssuePayload();
    issuePayload.setIssueId(issueId);
    issuePayload.setProjectId(projectId);
    sagaClient.startSaga("agile-delete-issue", new StartInstanceDTO(JSON.toJSONString(issuePayload), "", "", ResourceLevel.PROJECT.value(), projectId));
}
 
Example #6
Source File: PropertyJobTask.java    From choerodon-starters with Apache License 2.0 5 votes vote down vote up
public PropertyJobTask(String method, int maxRetryCount, String code, String description, ResourceLevel level, JobParam[] params) {
    this.method = method;
    this.maxRetryCount = maxRetryCount;
    this.code = code;
    this.description = description;
    this.level = level.value();
    this.params = new ArrayList<>(params.length);
    for (JobParam jobParam : params) {
        this.params.add(new PropertyJobParam(jobParam));
    }
}
 
Example #7
Source File: StartSagaBuilder.java    From choerodon-starters with Apache License 2.0 5 votes vote down vote up
StartInstanceDTO preBuild() {
    if (StringUtils.isEmpty(startInstanceDTO.getSagaCode())) {
        throw new SagaProducerException("error.startSaga.sagaCodeIsEmpty");
    }
    if (startInstanceDTO.getLevel() == null) {
        startInstanceDTO.setLevel(ResourceLevel.SITE.value());
    }
    if (startInstanceDTO.getSourceId() == null) {
        startInstanceDTO.setSourceId(0L);
    }
    return startInstanceDTO;
}
 
Example #8
Source File: SourceCategoryCheckFilter.java    From api-gateway-old with Apache License 2.0 5 votes vote down vote up
@Override
public boolean run(RequestContext context) {
    PermissionDTO permission = context.getPermission();
    if (ResourceLevel.SITE.value().equalsIgnoreCase(permission.getResourceLevel()) ||
            ResourceLevel.USER.value().equalsIgnoreCase(permission.getResourceLevel())) {
        context.response.setStatus(CheckState.SUCCESS_PASS_SITE);
        context.response.setMessage("Have access to this 'site-level' interface, permission: " + context.getPermission());
        return true;
    }
    Long sourceId = ResourceLevel.ORGANIZATION.value().equalsIgnoreCase(permission.getResourceLevel()) ?
            SourceUtil.getSourceId(context.getTrueUri(), permission.getPath(), ORG_PATH_ID, matcher) :
            SourceUtil.getSourceId(context.getTrueUri(), permission.getPath(), PROJECT_PATH_ID, matcher);

    if (sourceId == null && ResourceLevel.PROJECT.value().equalsIgnoreCase(permission.getResourceLevel())) {
        context.response.setStatus(CheckState.API_ERROR_PROJECT_ID);
        context.response.setMessage("Project interface must have 'project_id' in path");
        return false;
    } else if (sourceId == null && ResourceLevel.ORGANIZATION.value().equalsIgnoreCase(permission.getResourceLevel())) {
        context.response.setStatus(CheckState.API_ERROR_ORG_ID);
        context.response.setMessage("Organization interface must have 'organization_id' in path");
        return false;
    } else if (sourceId != null) {
        List<String> categories = parseCategory(sourceId, permission.getResourceLevel());
        return checkCategoryMenu(context, permission.getCode(), categories, permission.getResourceLevel());
    }
    return true;
}
 
Example #9
Source File: SourceCategoryCheckFilter.java    From api-gateway-old with Apache License 2.0 5 votes vote down vote up
private Boolean checkCategoryMenu(final RequestContext context,
                                  final String permissionCode,
                                  final List<String> categories,
                                  final String level) {
    List<String> menuCodeList = permissionMapper.selectMenuCodeByPermissionCode(permissionCode);
    if (CollectionUtils.isEmpty(menuCodeList)) {
        return true;
    }
    List<CategoryMenuDTO> select = categoryMenuMapper.selectByMenuCodeList(level, categories, menuCodeList);
    if (CollectionUtils.isEmpty(select) && ResourceLevel.ORGANIZATION.value().equalsIgnoreCase(level)) {
        context.response.setStatus(CheckState.PERMISSION_NOT_PASS_ORG);
        context.response.setMessage("No access to this organization category,category:" + categories);
        return false;
    } else if (!CollectionUtils.isEmpty(select) && ResourceLevel.ORGANIZATION.value().equalsIgnoreCase(level)) {
        context.response.setStatus(CheckState.SUCCESS_PASS_ORG);
        context.response.setMessage("Have access to this 'organization-level' interface, permission: " + context.getPermission());
        return true;
    }

    if (CollectionUtils.isEmpty(select) && ResourceLevel.PROJECT.value().equalsIgnoreCase(level)) {
        context.response.setStatus(CheckState.PERMISSION_NOT_PASS_PROJECT);
        context.response.setMessage("No access to this project category,category:" + categories);
        return false;
    } else if (!CollectionUtils.isEmpty(select) && ResourceLevel.PROJECT.value().equalsIgnoreCase(level)) {
        context.response.setStatus(CheckState.SUCCESS_PASS_PROJECT);
        context.response.setMessage("Have access to this 'project-level' interface, permission: " + context.getPermission());
        return true;
    }
    return true;
}
 
Example #10
Source File: SourceCategoryCheckFilter.java    From api-gateway-old with Apache License 2.0 5 votes vote down vote up
private List<String> parseCategory(final Long sourceId, final String sourceType) {
    List<String> categories = new ArrayList<>();
    if (ResourceLevel.ORGANIZATION.value().equalsIgnoreCase(sourceType)) {
        categories.add(organizationMapper.getCategoryByOrgId(sourceId));
    } else {
        categories.addAll(projectMapper.getCategoriesByProjId(sourceId));
    }
    return categories;
}
 
Example #11
Source File: IssueServiceImpl.java    From agile-service-old with Apache License 2.0 4 votes vote down vote up
@Saga(code = "agile-delete-issue", description = "删除issue", inputSchemaClass = IssuePayload.class)
@Override
public void deleteIssue(Long projectId, Long issueId) {
    IssueConvertDTO issueConvertDTO = queryIssueByProjectIdAndIssueId(projectId, issueId);
    if (issueConvertDTO == null) {
        throw new CommonException(ERROR_ISSUE_NOT_FOUND);
    }
    //删除issueLink
    issueLinkService.deleteByIssueId(issueConvertDTO.getIssueId());
    //删除标签关联
    labelIssueRelService.deleteByIssueId(issueConvertDTO.getIssueId());
    //没有issue使用的标签进行垃圾回收
    issueLabelService.labelGarbageCollection(projectId);
    //删除模块关联
    componentIssueRelService.deleteByIssueId(issueConvertDTO.getIssueId());
    //删除版本关联
    versionIssueRelService.deleteByIssueId(issueConvertDTO.getIssueId());
    //删除冲刺关联
    issueAccessDataService.deleteIssueFromSprintByIssueId(projectId, issueId);
    //删除评论信息
    issueCommentService.deleteByIssueId(issueConvertDTO.getIssueId());
    //删除附件
    issueAttachmentService.deleteByIssueId(issueConvertDTO.getIssueId());
    //删除公告板特性及依赖
    boardFeatureService.deleteByFeatureId(projectId, issueId);

    if (ISSUE_TYPE_FEATURE.equals(issueConvertDTO.getTypeCode())) {
        featureService.delete(issueId);
    }
    //不是子任务的issue删除子任务
    if (!(SUB_TASK).equals(issueConvertDTO.getTypeCode())) {
        if ((ISSUE_EPIC).equals(issueConvertDTO.getTypeCode())) {
            //如果是epic,会把该epic下的issue的epicId置为0
            issueAccessDataService.batchUpdateIssueEpicId(projectId, issueConvertDTO.getIssueId());
        } else {
            redisUtil.deleteRedisCache(new String[]{"Agile:EpicChart" + projectId + ":" + issueConvertDTO.getEpicId() + ":" + "*"});
        }
        List<IssueDTO> issueDTOList = issueMapper.queryIssueSubList(projectId, issueConvertDTO.getIssueId());
        if (issueDTOList != null && !issueDTOList.isEmpty()) {
            issueDTOList.forEach(subIssue -> deleteIssue(subIssue.getProjectId(), subIssue.getIssueId()));
        }
    }
    // 如果是删除feature,将其下的issue的featureId置为0
    if ("feature".equals(issueConvertDTO.getTypeCode())) {
        issueAccessDataService.updateEpicIdOfStoryByFeature(issueConvertDTO.getIssueId(), 0L);
        issueMapper.updateFeatureIdOfStoryByFeature(issueConvertDTO.getIssueId(), 0L);
        // 删除故事地图扩列
        deleteStoryMapWidth(issueConvertDTO.getIssueId());
    }
    //删除日志信息
    dataLogDeleteByIssueId(projectId, issueId);
    issueAccessDataService.delete(projectId, issueConvertDTO.getIssueId());
    //删除rank数据
    rankMapper.deleteRankByIssueId(issueId);
    //删除issue发送消息
    IssuePayload issuePayload = new IssuePayload();
    issuePayload.setIssueId(issueId);
    issuePayload.setProjectId(projectId);
    sagaClient.startSaga("agile-delete-issue", new StartInstanceDTO(JSON.toJSONString(issuePayload), "", "", ResourceLevel.PROJECT.value(), projectId));
    //delete cache
    dataLogRedisUtil.handleDeleteRedisByDeleteIssue(projectId);
}
 
Example #12
Source File: StartSagaBuilder.java    From choerodon-starters with Apache License 2.0 4 votes vote down vote up
public StartSagaBuilder withLevel(ResourceLevel level) {
    startInstanceDTO.setLevel(level.value());
    return this;
}