Search in sources :

Example 1 with GitUser

use of com.qlangtech.tis.git.GitUtils.GitUser in project tis by qlangtech.

the class OfflineManager method deleteDatasourceTableById.

public void deleteDatasourceTableById(int tableId, BasicModule action, Context context) {
    // 1 检查表是否存在
    DatasourceTable datasourceTable = this.workflowDAOFacade.getDatasourceTableDAO().selectByPrimaryKey(tableId);
    if (datasourceTable == null) {
        action.addErrorMessage(context, "找不到该表,table id = " + tableId);
        return;
    }
    // 2 检查对应的db是否存在
    Integer dbId = datasourceTable.getDbId();
    DatasourceDb datasourceDb = this.workflowDAOFacade.getDatasourceDbDAO().selectByPrimaryKey(dbId);
    if (datasourceDb == null) {
        action.addErrorMessage(context, "找不到该表对应的数据库,db id = " + dbId);
        return;
    }
    // 3 检查是否有工作流用到了该table
    WorkFlowCriteria workFlowCriteria = new WorkFlowCriteria();
    workFlowCriteria.createCriteria();
    List<WorkFlow> workFlows = this.workflowDAOFacade.getWorkFlowDAO().selectByExample(workFlowCriteria);
    for (WorkFlow workFlow : workFlows) {
    // WorkflowPojo workflowPojo = getWorkflowConfig(workFlow.getName(), true);
    // if (!CollectionUtils.isEmpty(workflowPojo.getDependTableIds())
    // && workflowPojo.getDependTableIds().contains(datasourceTable.getId())) {
    // action.addErrorMessage(context,
    // "数据库下面的表" + datasourceTable.getTableLogicName() + "仍然被工作流" +
    // workflowPojo.getName() + "占用");
    // return;
    // }
    }
    // 4 删除git
    try {
        GitUser user = GitUser.dft();
        RunEnvironment runEnvironment = action.getAppDomain().getRunEnvironment();
        if (RunEnvironment.DAILY.equals(runEnvironment)) {
            GitUtils.$().deleteTableDaily(datasourceDb.getName(), datasourceTable.getName(), user);
        } else if (RunEnvironment.ONLINE.equals(runEnvironment)) {
            GitUtils.$().deleteTableOnline(datasourceDb.getName(), datasourceTable.getName(), user);
        } else {
            action.addErrorMessage(context, "当前运行环境" + runEnvironment + "既不是daily也不是online");
            return;
        }
    } catch (Exception e) {
        action.addErrorMessage(context, "删除数据库失败");
        action.addErrorMessage(context, e.getMessage());
        return;
    }
    // 5 删除db
    this.workflowDAOFacade.getDatasourceTableDAO().deleteByPrimaryKey(tableId);
    action.addActionMessage(context, "成功删除table");
}
Also used : RunEnvironment(com.qlangtech.tis.pubhook.common.RunEnvironment) SQLException(java.sql.SQLException) GitUser(com.qlangtech.tis.git.GitUtils.GitUser)

Example 2 with GitUser

use of com.qlangtech.tis.git.GitUtils.GitUser in project tis by qlangtech.

the class OfflineManager method deleteWorkflow.

// public WorkflowPojo getWorkflowConfig(String name, boolean isMaster) {
// return
// }
// public WorkflowPojo getWorkflowConfig(String name, String sha) {
// return GitUtils.$().getWorkflowSha(GitUtils.WORKFLOW_GIT_PROJECT_ID, sha,
// name);
// }
public void deleteWorkflow(int id, BasicModule action, Context context) {
    WorkFlow workFlow = workflowDAOFacade.getWorkFlowDAO().selectByPrimaryKey(id);
    if (workFlow == null) {
        action.addErrorMessage(context, "数据库没有这条记录");
        return;
    }
    if (workFlow.getInChange().intValue() != 0) {
        action.addErrorMessage(context, "该工作流在变更中,无法删除");
        return;
    }
    ApplicationCriteria applicationCriteria = new ApplicationCriteria();
    applicationCriteria.createCriteria().andWorkFlowIdEqualTo(id);
    List<Application> applications = action.getApplicationDAO().selectByExample(applicationCriteria);
    if (!CollectionUtils.isEmpty(applications)) {
        StringBuilder stringBuilder = new StringBuilder();
        for (Application application : applications) {
            stringBuilder.append(application.getProjectName()).append(", ");
        }
        action.addErrorMessage(context, "请先删除与该工作流相关的索引,相关索引为" + stringBuilder.toString());
        return;
    }
    try {
        GitUser user = GitUser.dft();
        // delete git
        GitUtils.$().deleteWorkflow(workFlow.getName(), user);
        // delete db
        workflowDAOFacade.getWorkFlowDAO().deleteByPrimaryKey(id);
        // TODO 删除线上db的数据,发送一个http请求
        action.addActionMessage(context, "工作流删除成功");
    } catch (Exception e) {
        action.addErrorMessage(context, "工作流删除失败");
        action.addErrorMessage(context, e.getMessage());
    }
}
Also used : ApplicationCriteria(com.qlangtech.tis.manage.biz.dal.pojo.ApplicationCriteria) Application(com.qlangtech.tis.manage.biz.dal.pojo.Application) SQLException(java.sql.SQLException) GitUser(com.qlangtech.tis.git.GitUtils.GitUser)

Aggregations

GitUser (com.qlangtech.tis.git.GitUtils.GitUser)2 SQLException (java.sql.SQLException)2 Application (com.qlangtech.tis.manage.biz.dal.pojo.Application)1 ApplicationCriteria (com.qlangtech.tis.manage.biz.dal.pojo.ApplicationCriteria)1 RunEnvironment (com.qlangtech.tis.pubhook.common.RunEnvironment)1