@ -117,18 +117,7 @@ import java.io.BufferedReader;
import java.io.IOException ;
import java.io.IOException ;
import java.io.InputStreamReader ;
import java.io.InputStreamReader ;
import java.nio.charset.StandardCharsets ;
import java.nio.charset.StandardCharsets ;
import java.util.ArrayList ;
import java.util.* ;
import java.util.Arrays ;
import java.util.Collection ;
import java.util.Collections ;
import java.util.Date ;
import java.util.HashMap ;
import java.util.HashSet ;
import java.util.List ;
import java.util.Map ;
import java.util.Objects ;
import java.util.Optional ;
import java.util.Set ;
import java.util.concurrent.ConcurrentHashMap ;
import java.util.concurrent.ConcurrentHashMap ;
import java.util.function.Function ;
import java.util.function.Function ;
import java.util.stream.Collectors ;
import java.util.stream.Collectors ;
@ -261,11 +250,14 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
return result ;
return result ;
}
}
if ( checkDescriptionLength ( description ) ) {
if ( checkDescriptionLength ( description ) ) {
logger . warn ( "Parameter description is too long." ) ;
throw new ServiceException ( Status . DESCRIPTION_TOO_LONG_ERROR ) ;
throw new ServiceException ( Status . DESCRIPTION_TOO_LONG_ERROR ) ;
}
}
// check whether the new process define name exist
// check whether the new process define name exist
ProcessDefinition definition = processDefinitionMapper . verifyByDefineName ( project . getCode ( ) , name ) ;
ProcessDefinition definition = processDefinitionMapper . verifyByDefineName ( project . getCode ( ) , name ) ;
if ( definition ! = null ) {
if ( definition ! = null ) {
logger . warn ( "Process definition with the same name {} already exists, processDefinitionCode:{}." ,
definition . getName ( ) , definition . getCode ( ) ) ;
throw new ServiceException ( Status . PROCESS_DEFINITION_NAME_EXIST , name ) ;
throw new ServiceException ( Status . PROCESS_DEFINITION_NAME_EXIST , name ) ;
}
}
List < TaskDefinitionLog > taskDefinitionLogs = generateTaskDefinitionList ( taskDefinitionJson ) ;
List < TaskDefinitionLog > taskDefinitionLogs = generateTaskDefinitionList ( taskDefinitionJson ) ;
@ -274,6 +266,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
if ( ! Constants . DEFAULT . equals ( tenantCode ) ) {
if ( ! Constants . DEFAULT . equals ( tenantCode ) ) {
Tenant tenant = tenantMapper . queryByTenantCode ( tenantCode ) ;
Tenant tenant = tenantMapper . queryByTenantCode ( tenantCode ) ;
if ( tenant = = null ) {
if ( tenant = = null ) {
logger . error ( "Tenant does not exist." ) ;
throw new ServiceException ( Status . TENANT_NOT_EXIST ) ;
throw new ServiceException ( Status . TENANT_NOT_EXIST ) ;
}
}
tenantId = tenant . getId ( ) ;
tenantId = tenant . getId ( ) ;
@ -298,18 +291,26 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
logger . info ( "The task has not changed, so skip" ) ;
logger . info ( "The task has not changed, so skip" ) ;
}
}
if ( saveTaskResult = = Constants . DEFINITION_FAILURE ) {
if ( saveTaskResult = = Constants . DEFINITION_FAILURE ) {
logger . error ( "Save task definition error." ) ;
throw new ServiceException ( Status . CREATE_TASK_DEFINITION_ERROR ) ;
throw new ServiceException ( Status . CREATE_TASK_DEFINITION_ERROR ) ;
}
}
int insertVersion = processService . saveProcessDefine ( loginUser , processDefinition , Boolean . TRUE , Boolean . TRUE ) ;
int insertVersion = processService . saveProcessDefine ( loginUser , processDefinition , Boolean . TRUE , Boolean . TRUE ) ;
if ( insertVersion = = 0 ) {
if ( insertVersion = = 0 ) {
logger . error ( "Save process definition error, processCode:{}." , processDefinition . getCode ( ) ) ;
throw new ServiceException ( Status . CREATE_PROCESS_DEFINITION_ERROR ) ;
throw new ServiceException ( Status . CREATE_PROCESS_DEFINITION_ERROR ) ;
}
} else
logger . info ( "Save process definition complete, processCode:{}, processVersion:{}." , processDefinition . getCode ( ) , insertVersion ) ;
int insertResult = processService . saveTaskRelation ( loginUser , processDefinition . getProjectCode ( ) ,
int insertResult = processService . saveTaskRelation ( loginUser , processDefinition . getProjectCode ( ) ,
processDefinition . getCode ( ) ,
processDefinition . getCode ( ) ,
insertVersion , taskRelationList , taskDefinitionLogs , Boolean . TRUE ) ;
insertVersion , taskRelationList , taskDefinitionLogs , Boolean . TRUE ) ;
if ( insertResult ! = Constants . EXIT_CODE_SUCCESS ) {
if ( insertResult ! = Constants . EXIT_CODE_SUCCESS ) {
logger . error ( "Save process task relations error, projectCode:{}, processCode:{}, processVersion:{}." ,
processDefinition . getProjectCode ( ) , processDefinition . getCode ( ) , insertVersion ) ;
throw new ServiceException ( Status . CREATE_PROCESS_TASK_RELATION_ERROR ) ;
throw new ServiceException ( Status . CREATE_PROCESS_TASK_RELATION_ERROR ) ;
}
} else
logger . info ( "Save process task relations complete, projectCode:{}, processCode:{}, processVersion:{}." ,
processDefinition . getProjectCode ( ) , processDefinition . getCode ( ) , insertVersion ) ;
saveOtherRelation ( loginUser , processDefinition , result , otherParamsJson ) ;
saveOtherRelation ( loginUser , processDefinition , result , otherParamsJson ) ;
putMsg ( result , Status . SUCCESS ) ;
putMsg ( result , Status . SUCCESS ) ;
@ -367,19 +368,21 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
Set < Long > taskNodeCodes = taskNodeList . stream ( ) . map ( TaskNode : : getCode ) . collect ( Collectors . toSet ( ) ) ;
Set < Long > taskNodeCodes = taskNodeList . stream ( ) . map ( TaskNode : : getCode ) . collect ( Collectors . toSet ( ) ) ;
Collection < Long > codes = CollectionUtils . subtract ( postTaskCodes , taskNodeCodes ) ;
Collection < Long > codes = CollectionUtils . subtract ( postTaskCodes , taskNodeCodes ) ;
if ( CollectionUtils . isNotEmpty ( codes ) ) {
if ( CollectionUtils . isNotEmpty ( codes ) ) {
logger . error ( "the task code is not exist" ) ;
String taskCodes = StringUtils . join ( codes , Constants . COMMA ) ;
throw new ServiceException ( Status . TASK_DEFINE_NOT_EXIST , StringUtils . join ( codes , Constants . COMMA ) ) ;
logger . error ( "Task definitions do not exist, taskCodes:{}." , taskCodes ) ;
throw new ServiceException ( Status . TASK_DEFINE_NOT_EXIST , taskCodes ) ;
}
}
}
}
if ( graphHasCycle ( taskNodeList ) ) {
if ( graphHasCycle ( taskNodeList ) ) {
logger . error ( "process DAG has cycle " ) ;
logger . error ( "Process DAG has cycle. " ) ;
throw new ServiceException ( Status . PROCESS_NODE_HAS_CYCLE ) ;
throw new ServiceException ( Status . PROCESS_NODE_HAS_CYCLE ) ;
}
}
// check whether the task relation json is normal
// check whether the task relation json is normal
for ( ProcessTaskRelationLog processTaskRelationLog : taskRelationList ) {
for ( ProcessTaskRelationLog processTaskRelationLog : taskRelationList ) {
if ( processTaskRelationLog . getPostTaskCode ( ) = = 0 ) {
if ( processTaskRelationLog . getPostTaskCode ( ) = = 0 ) {
logger . error ( "the post_task_code or post_task_version can't be zero" ) ;
logger . error ( "The post_task_code or post_task_version of processTaskRelationLog can not be zero, " +
"processTaskRelationLogId:{}." , processTaskRelationLog . getId ( ) ) ;
throw new ServiceException ( Status . CHECK_PROCESS_TASK_RELATION_ERROR ) ;
throw new ServiceException ( Status . CHECK_PROCESS_TASK_RELATION_ERROR ) ;
}
}
}
}
@ -519,6 +522,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
ProcessDefinition processDefinition = processDefinitionMapper . queryByCode ( code ) ;
ProcessDefinition processDefinition = processDefinitionMapper . queryByCode ( code ) ;
if ( processDefinition = = null | | projectCode ! = processDefinition . getProjectCode ( ) ) {
if ( processDefinition = = null | | projectCode ! = processDefinition . getProjectCode ( ) ) {
logger . error ( "Process definition does not exist, processCode:{}." , code ) ;
putMsg ( result , Status . PROCESS_DEFINE_NOT_EXIST , String . valueOf ( code ) ) ;
putMsg ( result , Status . PROCESS_DEFINE_NOT_EXIST , String . valueOf ( code ) ) ;
} else {
} else {
Tenant tenant = tenantMapper . queryById ( processDefinition . getTenantId ( ) ) ;
Tenant tenant = tenantMapper . queryById ( processDefinition . getTenantId ( ) ) ;
@ -544,6 +548,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
ProcessDefinition processDefinition = processDefinitionMapper . queryByDefineName ( projectCode , name ) ;
ProcessDefinition processDefinition = processDefinitionMapper . queryByDefineName ( projectCode , name ) ;
if ( processDefinition = = null ) {
if ( processDefinition = = null ) {
logger . error ( "Process definition does not exist, projectCode:{}." , projectCode ) ;
putMsg ( result , Status . PROCESS_DEFINE_NOT_EXIST , name ) ;
putMsg ( result , Status . PROCESS_DEFINE_NOT_EXIST , name ) ;
} else {
} else {
DagData dagData = processService . genDagData ( processDefinition ) ;
DagData dagData = processService . genDagData ( processDefinition ) ;
@ -593,6 +598,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
return result ;
return result ;
}
}
if ( checkDescriptionLength ( description ) ) {
if ( checkDescriptionLength ( description ) ) {
logger . warn ( "Parameter description is too long." ) ;
putMsg ( result , Status . DESCRIPTION_TOO_LONG_ERROR ) ;
putMsg ( result , Status . DESCRIPTION_TOO_LONG_ERROR ) ;
return result ;
return result ;
}
}
@ -603,6 +609,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
if ( ! Constants . DEFAULT . equals ( tenantCode ) ) {
if ( ! Constants . DEFAULT . equals ( tenantCode ) ) {
Tenant tenant = tenantMapper . queryByTenantCode ( tenantCode ) ;
Tenant tenant = tenantMapper . queryByTenantCode ( tenantCode ) ;
if ( tenant = = null ) {
if ( tenant = = null ) {
logger . error ( "Tenant does not exist." ) ;
putMsg ( result , Status . TENANT_NOT_EXIST ) ;
putMsg ( result , Status . TENANT_NOT_EXIST ) ;
return result ;
return result ;
}
}
@ -612,11 +619,14 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
ProcessDefinition processDefinition = processDefinitionMapper . queryByCode ( code ) ;
ProcessDefinition processDefinition = processDefinitionMapper . queryByCode ( code ) ;
// check process definition exists
// check process definition exists
if ( processDefinition = = null | | projectCode ! = processDefinition . getProjectCode ( ) ) {
if ( processDefinition = = null | | projectCode ! = processDefinition . getProjectCode ( ) ) {
logger . error ( "Process definition does not exist, processCode:{}." , code ) ;
putMsg ( result , Status . PROCESS_DEFINE_NOT_EXIST , String . valueOf ( code ) ) ;
putMsg ( result , Status . PROCESS_DEFINE_NOT_EXIST , String . valueOf ( code ) ) ;
return result ;
return result ;
}
}
if ( processDefinition . getReleaseState ( ) = = ReleaseState . ONLINE ) {
if ( processDefinition . getReleaseState ( ) = = ReleaseState . ONLINE ) {
// online can not permit edit
// online can not permit edit
logger . warn ( "Process definition is not allowed to be modified due to {}, processDefinitionCode:{}." ,
ReleaseState . ONLINE . getDescp ( ) , processDefinition . getCode ( ) ) ;
putMsg ( result , Status . PROCESS_DEFINE_NOT_ALLOWED_EDIT , processDefinition . getName ( ) ) ;
putMsg ( result , Status . PROCESS_DEFINE_NOT_ALLOWED_EDIT , processDefinition . getName ( ) ) ;
return result ;
return result ;
}
}
@ -624,6 +634,8 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
// check whether the new process define name exist
// check whether the new process define name exist
ProcessDefinition definition = processDefinitionMapper . verifyByDefineName ( project . getCode ( ) , name ) ;
ProcessDefinition definition = processDefinitionMapper . verifyByDefineName ( project . getCode ( ) , name ) ;
if ( definition ! = null ) {
if ( definition ! = null ) {
logger . warn ( "Process definition with the same name already exists, processDefinitionCode:{}." ,
definition . getCode ( ) ) ;
putMsg ( result , Status . PROCESS_DEFINITION_NAME_EXIST , name ) ;
putMsg ( result , Status . PROCESS_DEFINITION_NAME_EXIST , name ) ;
return result ;
return result ;
}
}
@ -661,6 +673,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
taskDepMsg . ifPresent ( sb : : append ) ;
taskDepMsg . ifPresent ( sb : : append ) ;
}
}
if ( sb . length ( ) ! = 0 ) {
if ( sb . length ( ) ! = 0 ) {
logger . error ( "Task cannot be deleted because it is dependent" ) ;
throw new ServiceException ( sb . toString ( ) ) ;
throw new ServiceException ( sb . toString ( ) ) ;
}
}
}
}
@ -679,6 +692,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
logger . info ( "The task has not changed, so skip" ) ;
logger . info ( "The task has not changed, so skip" ) ;
}
}
if ( saveTaskResult = = Constants . DEFINITION_FAILURE ) {
if ( saveTaskResult = = Constants . DEFINITION_FAILURE ) {
logger . error ( "Update task definitions error, projectCode:{}, processCode:{}." , processDefinition . getProjectCode ( ) , processDefinition . getCode ( ) ) ;
putMsg ( result , Status . UPDATE_TASK_DEFINITION_ERROR ) ;
putMsg ( result , Status . UPDATE_TASK_DEFINITION_ERROR ) ;
throw new ServiceException ( Status . UPDATE_TASK_DEFINITION_ERROR ) ;
throw new ServiceException ( Status . UPDATE_TASK_DEFINITION_ERROR ) ;
}
}
@ -704,26 +718,36 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
isChange = true ;
isChange = true ;
}
}
if ( isChange ) {
if ( isChange ) {
logger . info ( "Process definition needs to be updated, projectCode:{}, processCode:{}, processVersion:{}." ,
processDefinition . getProjectCode ( ) , processDefinition . getCode ( ) , processDefinition . getVersion ( ) ) ;
processDefinition . setUpdateTime ( new Date ( ) ) ;
processDefinition . setUpdateTime ( new Date ( ) ) ;
int insertVersion =
int insertVersion =
processService . saveProcessDefine ( loginUser , processDefinition , Boolean . TRUE , Boolean . TRUE ) ;
processService . saveProcessDefine ( loginUser , processDefinition , Boolean . TRUE , Boolean . TRUE ) ;
if ( insertVersion < = 0 ) {
if ( insertVersion < = 0 ) {
logger . error ( "Update process definition error, processCode:{}." , processDefinition . getCode ( ) ) ;
putMsg ( result , Status . UPDATE_PROCESS_DEFINITION_ERROR ) ;
putMsg ( result , Status . UPDATE_PROCESS_DEFINITION_ERROR ) ;
throw new ServiceException ( Status . UPDATE_PROCESS_DEFINITION_ERROR ) ;
throw new ServiceException ( Status . UPDATE_PROCESS_DEFINITION_ERROR ) ;
}
} else
logger . info ( "Update process definition complete, processCode:{}, processVersion:{}." , processDefinition . getCode ( ) , insertVersion ) ;
taskUsedInOtherTaskValid ( processDefinition , taskRelationList ) ;
taskUsedInOtherTaskValid ( processDefinition , taskRelationList ) ;
int insertResult = processService . saveTaskRelation ( loginUser , processDefinition . getProjectCode ( ) ,
int insertResult = processService . saveTaskRelation ( loginUser , processDefinition . getProjectCode ( ) ,
processDefinition . getCode ( ) , insertVersion , taskRelationList , taskDefinitionLogs , Boolean . TRUE ) ;
processDefinition . getCode ( ) , insertVersion , taskRelationList , taskDefinitionLogs , Boolean . TRUE ) ;
if ( insertResult = = Constants . EXIT_CODE_SUCCESS ) {
if ( insertResult = = Constants . EXIT_CODE_SUCCESS ) {
logger . info ( "Update process task relations complete, projectCode:{}, processCode:{}, processVersion:{}." ,
processDefinition . getProjectCode ( ) , processDefinition . getCode ( ) , insertVersion ) ;
putMsg ( result , Status . SUCCESS ) ;
putMsg ( result , Status . SUCCESS ) ;
result . put ( Constants . DATA_LIST , processDefinition ) ;
result . put ( Constants . DATA_LIST , processDefinition ) ;
} else {
} else {
logger . error ( "Update process task relations error, projectCode:{}, processCode:{}, processVersion:{}." ,
processDefinition . getProjectCode ( ) , processDefinition . getCode ( ) , insertVersion ) ;
putMsg ( result , Status . UPDATE_PROCESS_DEFINITION_ERROR ) ;
putMsg ( result , Status . UPDATE_PROCESS_DEFINITION_ERROR ) ;
throw new ServiceException ( Status . UPDATE_PROCESS_DEFINITION_ERROR ) ;
throw new ServiceException ( Status . UPDATE_PROCESS_DEFINITION_ERROR ) ;
}
}
saveOtherRelation ( loginUser , processDefinition , result , otherParamsJson ) ;
saveOtherRelation ( loginUser , processDefinition , result , otherParamsJson ) ;
} else {
} else {
logger . info ( "Process definition does not need to be updated because there is no change, projectCode:{}, processCode:{}, processVersion:{}." ,
processDefinition . getProjectCode ( ) , processDefinition . getCode ( ) , processDefinition . getVersion ( ) ) ;
putMsg ( result , Status . SUCCESS ) ;
putMsg ( result , Status . SUCCESS ) ;
result . put ( Constants . DATA_LIST , processDefinition ) ;
result . put ( Constants . DATA_LIST , processDefinition ) ;
}
}
@ -739,8 +763,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
* @return true if process definition name not exists , otherwise false
* @return true if process definition name not exists , otherwise false
* /
* /
@Override
@Override
public Map < String , Object > verifyProcessDefinitionName ( User loginUser , long projectCode , String name ,
public Map < String , Object > verifyProcessDefinitionName ( User loginUser , long projectCode , String name , long processDefinitionCode ) {
long processDefinitionCode ) {
Project project = projectMapper . queryByCode ( projectCode ) ;
Project project = projectMapper . queryByCode ( projectCode ) ;
// check user access for project
// check user access for project
Map < String , Object > result =
Map < String , Object > result =
@ -758,6 +781,8 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
putMsg ( result , Status . SUCCESS ) ;
putMsg ( result , Status . SUCCESS ) ;
return result ;
return result ;
}
}
logger . warn ( "Process definition with the same name {} already exists, processDefinitionCode:{}." ,
processDefinition . getName ( ) , processDefinition . getCode ( ) ) ;
putMsg ( result , Status . PROCESS_DEFINITION_NAME_EXIST , name . trim ( ) ) ;
putMsg ( result , Status . PROCESS_DEFINITION_NAME_EXIST , name . trim ( ) ) ;
return result ;
return result ;
}
}
@ -772,6 +797,8 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
private void processDefinitionUsedInOtherTaskValid ( ProcessDefinition processDefinition ) {
private void processDefinitionUsedInOtherTaskValid ( ProcessDefinition processDefinition ) {
// check process definition is already online
// check process definition is already online
if ( processDefinition . getReleaseState ( ) = = ReleaseState . ONLINE ) {
if ( processDefinition . getReleaseState ( ) = = ReleaseState . ONLINE ) {
logger . warn ( "Process definition can not be deleted due to {}, processDefinitionCode:{}." ,
ReleaseState . ONLINE . getDescp ( ) , processDefinition . getCode ( ) ) ;
throw new ServiceException ( Status . PROCESS_DEFINE_STATE_ONLINE , processDefinition . getName ( ) ) ;
throw new ServiceException ( Status . PROCESS_DEFINE_STATE_ONLINE , processDefinition . getName ( ) ) ;
}
}
@ -779,6 +806,8 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
List < ProcessInstance > processInstances = processInstanceService
List < ProcessInstance > processInstances = processInstanceService
. queryByProcessDefineCodeAndStatus ( processDefinition . getCode ( ) , Constants . NOT_TERMINATED_STATES ) ;
. queryByProcessDefineCodeAndStatus ( processDefinition . getCode ( ) , Constants . NOT_TERMINATED_STATES ) ;
if ( CollectionUtils . isNotEmpty ( processInstances ) ) {
if ( CollectionUtils . isNotEmpty ( processInstances ) ) {
logger . warn ( "Process definition can not be deleted because there are {} executing process instances, processDefinitionCode:{}" ,
processInstances . size ( ) , processDefinition . getCode ( ) ) ;
throw new ServiceException ( Status . DELETE_PROCESS_DEFINITION_EXECUTING_FAIL , processInstances . size ( ) ) ;
throw new ServiceException ( Status . DELETE_PROCESS_DEFINITION_EXECUTING_FAIL , processInstances . size ( ) ) ;
}
}
@ -790,6 +819,8 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
. map ( task - > String . format ( Constants . FORMAT_S_S_COLON , task . getProcessDefinitionName ( ) ,
. map ( task - > String . format ( Constants . FORMAT_S_S_COLON , task . getProcessDefinitionName ( ) ,
task . getTaskName ( ) ) )
task . getTaskName ( ) ) )
. collect ( Collectors . joining ( Constants . COMMA ) ) ;
. collect ( Collectors . joining ( Constants . COMMA ) ) ;
logger . warn ( "Process definition can not be deleted due to being referenced by other tasks:{}, processDefinitionCode:{}" ,
taskDepDetail , processDefinition . getCode ( ) ) ;
throw new ServiceException ( Status . DELETE_PROCESS_DEFINITION_USE_BY_OTHER_FAIL , taskDepDetail ) ;
throw new ServiceException ( Status . DELETE_PROCESS_DEFINITION_USE_BY_OTHER_FAIL , taskDepDetail ) ;
}
}
}
}
@ -814,12 +845,14 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
}
}
ProcessDefinition processDefinition = processDefinitionMapper . queryByCode ( code ) ;
ProcessDefinition processDefinition = processDefinitionMapper . queryByCode ( code ) ;
if ( processDefinition = = null | | projectCode ! = processDefinition . getProjectCode ( ) ) {
if ( processDefinition = = null | | projectCode ! = processDefinition . getProjectCode ( ) ) {
logger . error ( "Process definition does not exist, processCode:{}." , code ) ;
putMsg ( result , Status . PROCESS_DEFINE_NOT_EXIST , String . valueOf ( code ) ) ;
putMsg ( result , Status . PROCESS_DEFINE_NOT_EXIST , String . valueOf ( code ) ) ;
return result ;
return result ;
}
}
// Determine if the login user is the owner of the process definition
// Determine if the login user is the owner of the process definition
if ( loginUser . getId ( ) ! = processDefinition . getUserId ( ) & & loginUser . getUserType ( ) ! = UserType . ADMIN_USER ) {
if ( loginUser . getId ( ) ! = processDefinition . getUserId ( ) & & loginUser . getUserType ( ) ! = UserType . ADMIN_USER ) {
logger . warn ( "User does not have permission for process definition, userId:{}, processDefinitionCode:{}." , loginUser . getId ( ) , code ) ;
putMsg ( result , Status . USER_NO_OPERATION_PERM ) ;
putMsg ( result , Status . USER_NO_OPERATION_PERM ) ;
return result ;
return result ;
}
}
@ -832,23 +865,27 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
if ( scheduleObj . getReleaseState ( ) = = ReleaseState . OFFLINE ) {
if ( scheduleObj . getReleaseState ( ) = = ReleaseState . OFFLINE ) {
int delete = scheduleMapper . deleteById ( scheduleObj . getId ( ) ) ;
int delete = scheduleMapper . deleteById ( scheduleObj . getId ( ) ) ;
if ( delete = = 0 ) {
if ( delete = = 0 ) {
logger . error ( "Delete schedule of process definition error, processDefinitionCode:{}, scheduleId:{}." , code , scheduleObj . getId ( ) ) ;
putMsg ( result , Status . DELETE_SCHEDULE_CRON_BY_ID_ERROR ) ;
putMsg ( result , Status . DELETE_SCHEDULE_CRON_BY_ID_ERROR ) ;
throw new ServiceException ( Status . DELETE_SCHEDULE_CRON_BY_ID_ERROR ) ;
throw new ServiceException ( Status . DELETE_SCHEDULE_CRON_BY_ID_ERROR ) ;
}
}
}
}
if ( scheduleObj . getReleaseState ( ) = = ReleaseState . ONLINE ) {
if ( scheduleObj . getReleaseState ( ) = = ReleaseState . ONLINE ) {
logger . warn ( "Process definition can not be deleted due to schedule {}, processDefinitionCode:{}, scheduleId:{}." ,
ReleaseState . ONLINE . getDescp ( ) , processDefinition . getCode ( ) , scheduleObj . getId ( ) ) ;
putMsg ( result , Status . SCHEDULE_CRON_STATE_ONLINE , scheduleObj . getId ( ) ) ;
putMsg ( result , Status . SCHEDULE_CRON_STATE_ONLINE , scheduleObj . getId ( ) ) ;
return result ;
return result ;
}
}
}
}
int delete = processDefinitionMapper . deleteById ( processDefinition . getId ( ) ) ;
int delete = processDefinitionMapper . deleteById ( processDefinition . getId ( ) ) ;
if ( delete = = 0 ) {
if ( delete = = 0 ) {
logger . error ( "Delete process definition error, processDefinitionCode:{}." , code ) ;
putMsg ( result , Status . DELETE_PROCESS_DEFINE_BY_CODE_ERROR ) ;
putMsg ( result , Status . DELETE_PROCESS_DEFINE_BY_CODE_ERROR ) ;
throw new ServiceException ( Status . DELETE_PROCESS_DEFINE_BY_CODE_ERROR ) ;
throw new ServiceException ( Status . DELETE_PROCESS_DEFINE_BY_CODE_ERROR ) ;
}
}
int deleteRelation = processTaskRelationMapper . deleteByCode ( project . getCode ( ) , processDefinition . getCode ( ) ) ;
int deleteRelation = processTaskRelationMapper . deleteByCode ( project . getCode ( ) , processDefinition . getCode ( ) ) ;
if ( deleteRelation = = 0 ) {
if ( deleteRelation = = 0 ) {
logger . warn ( "The process definition has not relation, it will be delete successfully" ) ;
logger . warn ( "The process definition has not relation, it will be delete successfully, processDefinitionCode:{}. " , code ) ;
}
}
deleteOtherRelation ( project , result , processDefinition ) ;
deleteOtherRelation ( project , result , processDefinition ) ;
putMsg ( result , Status . SUCCESS ) ;
putMsg ( result , Status . SUCCESS ) ;
@ -884,6 +921,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
ProcessDefinition processDefinition = processDefinitionMapper . queryByCode ( code ) ;
ProcessDefinition processDefinition = processDefinitionMapper . queryByCode ( code ) ;
if ( processDefinition = = null | | projectCode ! = processDefinition . getProjectCode ( ) ) {
if ( processDefinition = = null | | projectCode ! = processDefinition . getProjectCode ( ) ) {
logger . error ( "Process definition does not exist, processDefinitionCode:{}." , code ) ;
putMsg ( result , Status . PROCESS_DEFINE_NOT_EXIST , String . valueOf ( code ) ) ;
putMsg ( result , Status . PROCESS_DEFINE_NOT_EXIST , String . valueOf ( code ) ) ;
return result ;
return result ;
}
}
@ -892,27 +930,32 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
List < ProcessTaskRelation > relationList =
List < ProcessTaskRelation > relationList =
processService . findRelationByCode ( code , processDefinition . getVersion ( ) ) ;
processService . findRelationByCode ( code , processDefinition . getVersion ( ) ) ;
if ( CollectionUtils . isEmpty ( relationList ) ) {
if ( CollectionUtils . isEmpty ( relationList ) ) {
logger . warn ( "Process definition has no task relation, processDefinitionCode:{}." , code ) ;
putMsg ( result , Status . PROCESS_DAG_IS_EMPTY ) ;
putMsg ( result , Status . PROCESS_DAG_IS_EMPTY ) ;
return result ;
return result ;
}
}
processDefinition . setReleaseState ( releaseState ) ;
processDefinition . setReleaseState ( releaseState ) ;
processDefinitionMapper . updateById ( processDefinition ) ;
processDefinitionMapper . updateById ( processDefinition ) ;
logger . info ( "Set process definition online, projectCode:{}, processDefinitionCode:{}." , projectCode , code ) ;
break ;
break ;
case OFFLINE :
case OFFLINE :
processDefinition . setReleaseState ( releaseState ) ;
processDefinition . setReleaseState ( releaseState ) ;
int updateProcess = processDefinitionMapper . updateById ( processDefinition ) ;
int updateProcess = processDefinitionMapper . updateById ( processDefinition ) ;
Schedule schedule = scheduleMapper . queryByProcessDefinitionCode ( code ) ;
Schedule schedule = scheduleMapper . queryByProcessDefinitionCode ( code ) ;
if ( updateProcess > 0 & & schedule ! = null ) {
if ( updateProcess > 0 ) {
logger . info ( "set schedule offline, project code: {}, schedule id: {}, process definition code: {}" ,
logger . info ( "Set process definition offline, projectCode:{}, processDefinitionCode:{}." , projectCode , code ) ;
projectCode , schedule . getId ( ) , code ) ;
if ( schedule ! = null ) {
// set status
// set status
schedule . setReleaseState ( releaseState ) ;
schedule . setReleaseState ( releaseState ) ;
int updateSchedule = scheduleMapper . updateById ( schedule ) ;
int updateSchedule = scheduleMapper . updateById ( schedule ) ;
if ( updateSchedule = = 0 ) {
if ( updateSchedule = = 0 ) {
putMsg ( result , Status . OFFLINE_SCHEDULE_ERROR ) ;
logger . error ( "Set schedule offline error, projectCode:{}, processDefinitionCode:{}, scheduleId:{}" , projectCode , code , schedule . getId ( ) ) ;
throw new ServiceException ( Status . OFFLINE_SCHEDULE_ERROR ) ;
putMsg ( result , Status . OFFLINE_SCHEDULE_ERROR ) ;
throw new ServiceException ( Status . OFFLINE_SCHEDULE_ERROR ) ;
} else
logger . info ( "Set schedule offline, projectCode:{}, processDefinitionCode:{}, scheduleId:{}" , projectCode , code , schedule . getId ( ) ) ;
schedulerService . deleteSchedule ( project . getId ( ) , schedule . getId ( ) ) ;
}
}
schedulerService . deleteSchedule ( project . getId ( ) , schedule . getId ( ) ) ;
}
}
break ;
break ;
default :
default :
@ -931,6 +974,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
public void batchExportProcessDefinitionByCodes ( User loginUser , long projectCode , String codes ,
public void batchExportProcessDefinitionByCodes ( User loginUser , long projectCode , String codes ,
HttpServletResponse response ) {
HttpServletResponse response ) {
if ( StringUtils . isEmpty ( codes ) ) {
if ( StringUtils . isEmpty ( codes ) ) {
logger . warn ( "Process definition codes to be exported is empty." ) ;
return ;
return ;
}
}
Project project = projectMapper . queryByCode ( projectCode ) ;
Project project = projectMapper . queryByCode ( projectCode ) ;
@ -944,6 +988,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
. collect ( Collectors . toSet ( ) ) ;
. collect ( Collectors . toSet ( ) ) ;
List < ProcessDefinition > processDefinitionList = processDefinitionMapper . queryByCodes ( defineCodeSet ) ;
List < ProcessDefinition > processDefinitionList = processDefinitionMapper . queryByCodes ( defineCodeSet ) ;
if ( CollectionUtils . isEmpty ( processDefinitionList ) ) {
if ( CollectionUtils . isEmpty ( processDefinitionList ) ) {
logger . error ( "Process definitions to be exported do not exist, processDefinitionCodes:{}." , defineCodeSet ) ;
return ;
return ;
}
}
// check processDefinition exist in project
// check processDefinition exist in project
@ -952,8 +997,10 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
List < DagDataSchedule > dagDataSchedules =
List < DagDataSchedule > dagDataSchedules =
processDefinitionListInProject . stream ( ) . map ( this : : exportProcessDagData ) . collect ( Collectors . toList ( ) ) ;
processDefinitionListInProject . stream ( ) . map ( this : : exportProcessDagData ) . collect ( Collectors . toList ( ) ) ;
if ( CollectionUtils . isNotEmpty ( dagDataSchedules ) ) {
if ( CollectionUtils . isNotEmpty ( dagDataSchedules ) ) {
logger . info ( "Start download process definition file, processDefinitionCodes:{}." , defineCodeSet ) ;
downloadProcessDefinitionFile ( response , dagDataSchedules ) ;
downloadProcessDefinitionFile ( response , dagDataSchedules ) ;
}
} else
logger . error ( "There is no exported process dag data." ) ;
}
}
/ * *
/ * *
@ -970,20 +1017,20 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
buff . flush ( ) ;
buff . flush ( ) ;
buff . close ( ) ;
buff . close ( ) ;
} catch ( IOException e ) {
} catch ( IOException e ) {
logger . warn ( "export process fail" , e ) ;
logger . warn ( "Export process definition fail" , e ) ;
} finally {
} finally {
if ( null ! = buff ) {
if ( null ! = buff ) {
try {
try {
buff . close ( ) ;
buff . close ( ) ;
} catch ( Exception e ) {
} catch ( Exception e ) {
logger . warn ( "export process buffer not close" , e ) ;
logger . warn ( "Buffer does not close" , e ) ;
}
}
}
}
if ( null ! = out ) {
if ( null ! = out ) {
try {
try {
out . close ( ) ;
out . close ( ) ;
} catch ( Exception e ) {
} catch ( Exception e ) {
logger . warn ( "export process output stream not close" , e ) ;
logger . warn ( "Output stream does not close" , e ) ;
}
}
}
}
}
}
@ -1026,6 +1073,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
}
}
// check file content
// check file content
if ( CollectionUtils . isEmpty ( dagDataScheduleList ) ) {
if ( CollectionUtils . isEmpty ( dagDataScheduleList ) ) {
logger . warn ( "Process definition file content is empty." ) ;
putMsg ( result , Status . DATA_IS_NULL , "fileContent" ) ;
putMsg ( result , Status . DATA_IS_NULL , "fileContent" ) ;
return result ;
return result ;
}
}
@ -1095,7 +1143,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
long compressionRatio = totalSizeEntry / entry . getCompressedSize ( ) ;
long compressionRatio = totalSizeEntry / entry . getCompressedSize ( ) ;
if ( compressionRatio > THRESHOLD_RATIO ) {
if ( compressionRatio > THRESHOLD_RATIO ) {
throw new IllegalStateException (
throw new IllegalStateException (
"r atio between compressed and uncompressed data is highly suspicious, looks like a Zip Bomb Attack" ) ;
"R atio between compressed and uncompressed data is highly suspicious, looks like a Zip Bomb Attack. " ) ;
}
}
int commentIndex = line . indexOf ( "-- " ) ;
int commentIndex = line . indexOf ( "-- " ) ;
if ( commentIndex > = 0 ) {
if ( commentIndex > = 0 ) {
@ -1143,6 +1191,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
dataSource = queryDatasourceByNameAndUser ( datasourceName , loginUser ) ;
dataSource = queryDatasourceByNameAndUser ( datasourceName , loginUser ) ;
}
}
if ( dataSource = = null ) {
if ( dataSource = = null ) {
logger . error ( "Datasource does not found, may be its name is illegal." ) ;
putMsg ( result , Status . DATASOURCE_NAME_ILLEGAL ) ;
putMsg ( result , Status . DATASOURCE_NAME_ILLEGAL ) ;
return result ;
return result ;
}
}
@ -1167,7 +1216,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
}
}
}
}
} catch ( Exception e ) {
} catch ( Exception e ) {
logger . error ( e . getMessage ( ) , e ) ;
logger . error ( "Import process definition error." , e ) ;
putMsg ( result , Status . IMPORT_PROCESS_DEFINE_ERROR ) ;
putMsg ( result , Status . IMPORT_PROCESS_DEFINE_ERROR ) ;
return result ;
return result ;
}
}
@ -1272,6 +1321,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
try {
try {
processDefinition . setCode ( CodeGenerateUtils . getInstance ( ) . genCode ( ) ) ;
processDefinition . setCode ( CodeGenerateUtils . getInstance ( ) . genCode ( ) ) ;
} catch ( CodeGenerateException e ) {
} catch ( CodeGenerateException e ) {
logger . error ( "Save process definition error because generate process definition code error, projectCode:{}." , projectCode , e ) ;
putMsg ( result , Status . CREATE_PROCESS_DEFINITION_ERROR ) ;
putMsg ( result , Status . CREATE_PROCESS_DEFINITION_ERROR ) ;
return false ;
return false ;
}
}
@ -1294,7 +1344,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
taskCodeMap . put ( taskDefinitionLog . getCode ( ) , code ) ;
taskCodeMap . put ( taskDefinitionLog . getCode ( ) , code ) ;
taskDefinitionLog . setCode ( code ) ;
taskDefinitionLog . setCode ( code ) ;
} catch ( CodeGenerateException e ) {
} catch ( CodeGenerateException e ) {
logger . error ( "Task code get error, " , e ) ;
logger . error ( "Generate task definition code error, projectCode:{}, processDefinitionCode:{}" , projectCode , processDefinition . getCode ( ) , e ) ;
putMsg ( result , Status . INTERNAL_SERVER_ERROR_ARGS , "Error generating task definition code" ) ;
putMsg ( result , Status . INTERNAL_SERVER_ERROR_ARGS , "Error generating task definition code" ) ;
return false ;
return false ;
}
}
@ -1303,6 +1353,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
int insert = taskDefinitionMapper . batchInsert ( taskDefinitionLogList ) ;
int insert = taskDefinitionMapper . batchInsert ( taskDefinitionLogList ) ;
int logInsert = taskDefinitionLogMapper . batchInsert ( taskDefinitionLogList ) ;
int logInsert = taskDefinitionLogMapper . batchInsert ( taskDefinitionLogList ) ;
if ( ( logInsert & insert ) = = 0 ) {
if ( ( logInsert & insert ) = = 0 ) {
logger . error ( "Save task definition error, projectCode:{}, processDefinitionCode:{}" , projectCode , processDefinition . getCode ( ) ) ;
putMsg ( result , Status . CREATE_TASK_DEFINITION_ERROR ) ;
putMsg ( result , Status . CREATE_TASK_DEFINITION_ERROR ) ;
throw new ServiceException ( Status . CREATE_TASK_DEFINITION_ERROR ) ;
throw new ServiceException ( Status . CREATE_TASK_DEFINITION_ERROR ) ;
}
}
@ -1345,6 +1396,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
putMsg ( createDagResult , Status . SUCCESS ) ;
putMsg ( createDagResult , Status . SUCCESS ) ;
} else {
} else {
result . putAll ( createDagResult ) ;
result . putAll ( createDagResult ) ;
logger . error ( "Import process definition error, projectCode:{}, processDefinitionCode:{}." , projectCode , processDefinition . getCode ( ) ) ;
throw new ServiceException ( Status . IMPORT_PROCESS_DEFINE_ERROR ) ;
throw new ServiceException ( Status . IMPORT_PROCESS_DEFINE_ERROR ) ;
}
}
@ -1357,10 +1409,13 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
schedule . setUpdateTime ( now ) ;
schedule . setUpdateTime ( now ) ;
int scheduleInsert = scheduleMapper . insert ( schedule ) ;
int scheduleInsert = scheduleMapper . insert ( schedule ) ;
if ( 0 = = scheduleInsert ) {
if ( 0 = = scheduleInsert ) {
logger . error ( "Import process definition error due to save schedule fail, projectCode:{}, processDefinitionCode:{}." , projectCode , processDefinition . getCode ( ) ) ;
putMsg ( result , Status . IMPORT_PROCESS_DEFINE_ERROR ) ;
putMsg ( result , Status . IMPORT_PROCESS_DEFINE_ERROR ) ;
throw new ServiceException ( Status . IMPORT_PROCESS_DEFINE_ERROR ) ;
throw new ServiceException ( Status . IMPORT_PROCESS_DEFINE_ERROR ) ;
}
}
}
}
logger . info ( "Import process definition complete, projectCode:{}, processDefinitionCode:{}." , projectCode , processDefinition . getCode ( ) ) ;
return true ;
return true ;
}
}
@ -1369,14 +1424,17 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
* /
* /
private boolean checkImportanceParams ( DagDataSchedule dagDataSchedule , Map < String , Object > result ) {
private boolean checkImportanceParams ( DagDataSchedule dagDataSchedule , Map < String , Object > result ) {
if ( dagDataSchedule . getProcessDefinition ( ) = = null ) {
if ( dagDataSchedule . getProcessDefinition ( ) = = null ) {
logger . warn ( "Process definition is null." ) ;
putMsg ( result , Status . DATA_IS_NULL , "ProcessDefinition" ) ;
putMsg ( result , Status . DATA_IS_NULL , "ProcessDefinition" ) ;
return false ;
return false ;
}
}
if ( CollectionUtils . isEmpty ( dagDataSchedule . getTaskDefinitionList ( ) ) ) {
if ( CollectionUtils . isEmpty ( dagDataSchedule . getTaskDefinitionList ( ) ) ) {
logger . warn ( "Task definition list is null." ) ;
putMsg ( result , Status . DATA_IS_NULL , "TaskDefinitionList" ) ;
putMsg ( result , Status . DATA_IS_NULL , "TaskDefinitionList" ) ;
return false ;
return false ;
}
}
if ( CollectionUtils . isEmpty ( dagDataSchedule . getProcessTaskRelationList ( ) ) ) {
if ( CollectionUtils . isEmpty ( dagDataSchedule . getProcessTaskRelationList ( ) ) ) {
logger . warn ( "Process task relation list is null." ) ;
putMsg ( result , Status . DATA_IS_NULL , "ProcessTaskRelationList" ) ;
putMsg ( result , Status . DATA_IS_NULL , "ProcessTaskRelationList" ) ;
return false ;
return false ;
}
}
@ -1411,7 +1469,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
Map < String , Object > result = new HashMap < > ( ) ;
Map < String , Object > result = new HashMap < > ( ) ;
try {
try {
if ( processTaskRelationJson = = null ) {
if ( processTaskRelationJson = = null ) {
logger . error ( "process data is null " ) ;
logger . error ( "Process task relation data is null. " ) ;
putMsg ( result , Status . DATA_IS_NOT_VALID , processTaskRelationJson ) ;
putMsg ( result , Status . DATA_IS_NOT_VALID , processTaskRelationJson ) ;
return result ;
return result ;
}
}
@ -1422,14 +1480,14 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
List < TaskNode > taskNodes = processService . transformTask ( taskRelationList , taskDefinitionLogsList ) ;
List < TaskNode > taskNodes = processService . transformTask ( taskRelationList , taskDefinitionLogsList ) ;
if ( CollectionUtils . isEmpty ( taskNodes ) ) {
if ( CollectionUtils . isEmpty ( taskNodes ) ) {
logger . error ( "process node info is empty " ) ;
logger . error ( "Task node data is empty. " ) ;
putMsg ( result , Status . PROCESS_DAG_IS_EMPTY ) ;
putMsg ( result , Status . PROCESS_DAG_IS_EMPTY ) ;
return result ;
return result ;
}
}
// check has cycle
// check has cycle
if ( graphHasCycle ( taskNodes ) ) {
if ( graphHasCycle ( taskNodes ) ) {
logger . error ( "process DAG has cycle " ) ;
logger . error ( "Process DAG has cycle. " ) ;
putMsg ( result , Status . PROCESS_NODE_HAS_CYCLE ) ;
putMsg ( result , Status . PROCESS_NODE_HAS_CYCLE ) ;
return result ;
return result ;
}
}
@ -1442,7 +1500,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
. dependence ( taskNode . getDependence ( ) )
. dependence ( taskNode . getDependence ( ) )
. switchResult ( taskNode . getSwitchResult ( ) )
. switchResult ( taskNode . getSwitchResult ( ) )
. build ( ) ) ) {
. build ( ) ) ) {
logger . error ( "task node {} parameter invalid " , taskNode . getName ( ) ) ;
logger . error ( "Task node {} parameter invalid. " , taskNode . getName ( ) ) ;
putMsg ( result , Status . PROCESS_NODE_S_PARAMETER_INVALID , taskNode . getName ( ) ) ;
putMsg ( result , Status . PROCESS_NODE_S_PARAMETER_INVALID , taskNode . getName ( ) ) ;
return result ;
return result ;
}
}
@ -1477,7 +1535,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
}
}
ProcessDefinition processDefinition = processDefinitionMapper . queryByCode ( code ) ;
ProcessDefinition processDefinition = processDefinitionMapper . queryByCode ( code ) ;
if ( processDefinition = = null | | projectCode ! = processDefinition . getProjectCode ( ) ) {
if ( processDefinition = = null | | projectCode ! = processDefinition . getProjectCode ( ) ) {
logger . info ( "process define not exists" ) ;
logger . error ( "Process definition does not exist, processDefinitionCode:{}." , code ) ;
putMsg ( result , Status . PROCESS_DEFINE_NOT_EXIST , String . valueOf ( code ) ) ;
putMsg ( result , Status . PROCESS_DEFINE_NOT_EXIST , String . valueOf ( code ) ) ;
return result ;
return result ;
}
}
@ -1509,7 +1567,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
. collect ( Collectors . toSet ( ) ) ;
. collect ( Collectors . toSet ( ) ) ;
List < ProcessDefinition > processDefinitionList = processDefinitionMapper . queryByCodes ( defineCodeSet ) ;
List < ProcessDefinition > processDefinitionList = processDefinitionMapper . queryByCodes ( defineCodeSet ) ;
if ( CollectionUtils . isEmpty ( processDefinitionList ) ) {
if ( CollectionUtils . isEmpty ( processDefinitionList ) ) {
logger . info ( "process definition not exists" ) ;
logger . error ( "Process definitions do not exist, codes:{}." , defineCodeSet ) ;
putMsg ( result , Status . PROCESS_DEFINE_NOT_EXIST , codes ) ;
putMsg ( result , Status . PROCESS_DEFINE_NOT_EXIST , codes ) ;
return result ;
return result ;
}
}
@ -1521,6 +1579,10 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
List < ProcessDefinition > processDefinitionListInProject = processDefinitionList . stream ( )
List < ProcessDefinition > processDefinitionListInProject = processDefinitionList . stream ( )
. filter ( o - > userProjects . containsKey ( o . getProjectCode ( ) ) ) . collect ( Collectors . toList ( ) ) ;
. filter ( o - > userProjects . containsKey ( o . getProjectCode ( ) ) ) . collect ( Collectors . toList ( ) ) ;
if ( CollectionUtils . isEmpty ( processDefinitionListInProject ) ) {
if ( CollectionUtils . isEmpty ( processDefinitionListInProject ) ) {
Set < Long > codesInProject = processDefinitionListInProject . stream ( )
. map ( ProcessDefinition : : getCode ) . collect ( Collectors . toSet ( ) ) ;
logger . error ( "Process definitions do not exist in project, projectCode:{}, processDefinitionsCodes:{}." ,
processDefinitionListInProject . get ( 0 ) . getProjectCode ( ) , codesInProject ) ;
putMsg ( result , Status . PROCESS_DEFINE_NOT_EXIST , codes ) ;
putMsg ( result , Status . PROCESS_DEFINE_NOT_EXIST , codes ) ;
return result ;
return result ;
}
}
@ -1627,7 +1689,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
* /
* /
@Override
@Override
public Map < String , Object > viewTree ( User loginUser , long projectCode , long code , Integer limit ) {
public Map < String , Object > viewTree ( User loginUser , long projectCode , long code , Integer limit ) {
Map < String , Object > result ;
Map < String , Object > result = new HashMap < > ( ) ;
Project project = projectMapper . queryByCode ( projectCode ) ;
Project project = projectMapper . queryByCode ( projectCode ) ;
// check user access for project
// check user access for project
result = projectService . checkProjectAndAuth ( loginUser , project , projectCode , WORKFLOW_TREE_VIEW ) ;
result = projectService . checkProjectAndAuth ( loginUser , project , projectCode , WORKFLOW_TREE_VIEW ) ;
@ -1636,15 +1698,15 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
}
}
ProcessDefinition processDefinition = processDefinitionMapper . queryByCode ( code ) ;
ProcessDefinition processDefinition = processDefinitionMapper . queryByCode ( code ) ;
if ( null = = processDefinition | | projectCode ! = processDefinition . getProjectCode ( ) ) {
if ( null = = processDefinition | | projectCode ! = processDefinition . getProjectCode ( ) ) {
logger . info ( "process define not exists" ) ;
logger . error ( "Process definition does not exist, code:{}." , code ) ;
putMsg ( result , Status . PROCESS_DEFINE_NOT_EXIST , String . valueOf ( code ) ) ;
putMsg ( result , Status . PROCESS_DEFINE_NOT_EXIST , String . valueOf ( code ) ) ;
return result ;
return result ;
}
}
DAG < String , TaskNode , TaskNodeRelation > dag = processService . genDagGraph ( processDefinition ) ;
DAG < String , TaskNode , TaskNodeRelation > dag = processService . genDagGraph ( processDefinition ) ;
// nodes that is running
// nodes that are running
Map < String , List < TreeViewDto > > runningNodeMap = new ConcurrentHashMap < > ( ) ;
Map < String , List < TreeViewDto > > runningNodeMap = new ConcurrentHashMap < > ( ) ;
// nodes that is waiting to run
// nodes that are waiting to run
Map < String , List < TreeViewDto > > waitingRunningNodeMap = new ConcurrentHashMap < > ( ) ;
Map < String , List < TreeViewDto > > waitingRunningNodeMap = new ConcurrentHashMap < > ( ) ;
// List of process instances
// List of process instances
@ -1656,6 +1718,10 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
Map < Long , TaskDefinitionLog > taskDefinitionMap = taskDefinitionList . stream ( )
Map < Long , TaskDefinitionLog > taskDefinitionMap = taskDefinitionList . stream ( )
. collect ( Collectors . toMap ( TaskDefinitionLog : : getCode , taskDefinitionLog - > taskDefinitionLog ) ) ;
. collect ( Collectors . toMap ( TaskDefinitionLog : : getCode , taskDefinitionLog - > taskDefinitionLog ) ) ;
if ( limit < 0 ) {
putMsg ( result , Status . REQUEST_PARAMS_NOT_VALID_ERROR ) ;
return result ;
}
if ( limit > processInstanceList . size ( ) ) {
if ( limit > processInstanceList . size ( ) ) {
limit = processInstanceList . size ( ) ;
limit = processInstanceList . size ( ) ;
}
}
@ -1685,17 +1751,9 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
while ( ! ServerLifeCycleManager . isStopped ( ) ) {
while ( ! ServerLifeCycleManager . isStopped ( ) ) {
Set < String > postNodeList ;
Set < String > postNodeList ;
Set < Map . Entry < String , List < TreeViewDto > > > entries = runningNodeMap . entrySet ( ) ;
Iterator < Map . Entry < String , List < TreeViewDto > > > iter = runningNodeMap . entrySet ( ) . iterator ( ) ;
List < Integer > processInstanceIds = processInstanceList . stream ( )
while ( iter . hasNext ( ) ) {
. limit ( limit ) . map ( ProcessInstance : : getId ) . collect ( Collectors . toList ( ) ) ;
Map . Entry < String , List < TreeViewDto > > en = iter . next ( ) ;
List < Long > nodeCodes = entries . stream ( ) . map ( e - > Long . parseLong ( e . getKey ( ) ) ) . collect ( Collectors . toList ( ) ) ;
List < TaskInstance > taskInstances ;
if ( processInstanceIds . isEmpty ( ) | | nodeCodes . isEmpty ( ) ) {
taskInstances = Collections . emptyList ( ) ;
} else {
taskInstances = taskInstanceMapper . queryByProcessInstanceIdsAndTaskCodes ( processInstanceIds , nodeCodes ) ;
}
for ( Map . Entry < String , List < TreeViewDto > > en : entries ) {
String nodeCode = en . getKey ( ) ;
String nodeCode = en . getKey ( ) ;
parentTreeViewDtoList = en . getValue ( ) ;
parentTreeViewDtoList = en . getValue ( ) ;
@ -1707,14 +1765,8 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
// set treeViewDto instances
// set treeViewDto instances
for ( int i = limit - 1 ; i > = 0 ; i - - ) {
for ( int i = limit - 1 ; i > = 0 ; i - - ) {
ProcessInstance processInstance = processInstanceList . get ( i ) ;
ProcessInstance processInstance = processInstanceList . get ( i ) ;
TaskInstance taskInstance = null ;
TaskInstance taskInstance = taskInstanceMapper . queryByInstanceIdAndCode ( processInstance . getId ( ) ,
for ( TaskInstance instance : taskInstances ) {
Long . parseLong ( nodeCode ) ) ;
if ( instance . getTaskCode ( ) = = Long . parseLong ( nodeCode )
& & instance . getProcessInstanceId ( ) = = processInstance . getId ( ) ) {
taskInstance = instance ;
break ;
}
}
if ( taskInstance = = null ) {
if ( taskInstance = = null ) {
treeViewDto . getInstances ( ) . add ( new Instance ( - 1 , "not running" , 0 , "null" ) ) ;
treeViewDto . getInstances ( ) . add ( new Instance ( - 1 , "not running" , 0 , "null" ) ) ;
} else {
} else {
@ -1838,6 +1890,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
return result ;
return result ;
}
}
if ( projectCode = = targetProjectCode ) {
if ( projectCode = = targetProjectCode ) {
logger . warn ( "Project code is same as target project code, projectCode:{}." , projectCode ) ;
return result ;
return result ;
}
}
@ -1859,6 +1912,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
}
}
if ( StringUtils . isEmpty ( processDefinitionCodes ) ) {
if ( StringUtils . isEmpty ( processDefinitionCodes ) ) {
logger . error ( "Parameter processDefinitionCodes is empty, projectCode is {}." , projectCode ) ;
putMsg ( result , Status . PROCESS_DEFINITION_CODES_IS_EMPTY , processDefinitionCodes ) ;
putMsg ( result , Status . PROCESS_DEFINITION_CODES_IS_EMPTY , processDefinitionCodes ) ;
return result ;
return result ;
}
}
@ -1899,10 +1953,12 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
processDefinition . setProjectCode ( targetProjectCode ) ;
processDefinition . setProjectCode ( targetProjectCode ) ;
String otherParamsJson = doOtherOperateProcess ( loginUser , processDefinition ) ;
String otherParamsJson = doOtherOperateProcess ( loginUser , processDefinition ) ;
if ( isCopy ) {
if ( isCopy ) {
logger . info ( "Copy process definition..." ) ;
List < TaskDefinitionLog > taskDefinitionLogs = processService . genTaskDefineList ( processTaskRelations ) ;
List < TaskDefinitionLog > taskDefinitionLogs = processService . genTaskDefineList ( processTaskRelations ) ;
Map < Long , Long > taskCodeMap = new HashMap < > ( ) ;
Map < Long , Long > taskCodeMap = new HashMap < > ( ) ;
for ( TaskDefinitionLog taskDefinitionLog : taskDefinitionLogs ) {
for ( TaskDefinitionLog taskDefinitionLog : taskDefinitionLogs ) {
if ( COMPLEX_TASK_TYPES . contains ( taskDefinitionLog . getTaskType ( ) ) ) {
if ( COMPLEX_TASK_TYPES . contains ( taskDefinitionLog . getTaskType ( ) ) ) {
logger . error ( "Task types {} do not support copy." , taskDefinitionLog . getTaskType ( ) ) ;
putMsg ( result , Status . NOT_SUPPORT_COPY_TASK_TYPE , taskDefinitionLog . getTaskType ( ) ) ;
putMsg ( result , Status . NOT_SUPPORT_COPY_TASK_TYPE , taskDefinitionLog . getTaskType ( ) ) ;
return ;
return ;
}
}
@ -1911,6 +1967,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
taskCodeMap . put ( taskDefinitionLog . getCode ( ) , taskCode ) ;
taskCodeMap . put ( taskDefinitionLog . getCode ( ) , taskCode ) ;
taskDefinitionLog . setCode ( taskCode ) ;
taskDefinitionLog . setCode ( taskCode ) ;
} catch ( CodeGenerateException e ) {
} catch ( CodeGenerateException e ) {
logger . error ( "Generate task definition code error, projectCode:{}." , targetProjectCode , e ) ;
putMsg ( result , Status . INTERNAL_SERVER_ERROR_ARGS ) ;
putMsg ( result , Status . INTERNAL_SERVER_ERROR_ARGS ) ;
throw new ServiceException ( Status . INTERNAL_SERVER_ERROR_ARGS ) ;
throw new ServiceException ( Status . INTERNAL_SERVER_ERROR_ARGS ) ;
}
}
@ -1931,6 +1988,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
try {
try {
processDefinition . setCode ( CodeGenerateUtils . getInstance ( ) . genCode ( ) ) ;
processDefinition . setCode ( CodeGenerateUtils . getInstance ( ) . genCode ( ) ) ;
} catch ( CodeGenerateException e ) {
} catch ( CodeGenerateException e ) {
logger . error ( "Generate process definition code error, projectCode:{}." , targetProjectCode , e ) ;
putMsg ( result , Status . INTERNAL_SERVER_ERROR_ARGS ) ;
putMsg ( result , Status . INTERNAL_SERVER_ERROR_ARGS ) ;
throw new ServiceException ( Status . INTERNAL_SERVER_ERROR_ARGS ) ;
throw new ServiceException ( Status . INTERNAL_SERVER_ERROR_ARGS ) ;
}
}
@ -1959,6 +2017,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
scheduleObj . setUpdateTime ( date ) ;
scheduleObj . setUpdateTime ( date ) ;
int insertResult = scheduleMapper . insert ( scheduleObj ) ;
int insertResult = scheduleMapper . insert ( scheduleObj ) ;
if ( insertResult ! = 1 ) {
if ( insertResult ! = 1 ) {
logger . error ( "Schedule create error, processDefinitionCode:{}." , processDefinition . getCode ( ) ) ;
putMsg ( result , Status . CREATE_SCHEDULE_ERROR ) ;
putMsg ( result , Status . CREATE_SCHEDULE_ERROR ) ;
throw new ServiceException ( Status . CREATE_SCHEDULE_ERROR ) ;
throw new ServiceException ( Status . CREATE_SCHEDULE_ERROR ) ;
}
}
@ -1967,14 +2026,17 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
result . putAll ( createDagDefine ( loginUser , taskRelationList , processDefinition , taskDefinitionLogs ,
result . putAll ( createDagDefine ( loginUser , taskRelationList , processDefinition , taskDefinitionLogs ,
otherParamsJson ) ) ;
otherParamsJson ) ) ;
} catch ( Exception e ) {
} catch ( Exception e ) {
logger . error ( "Copy process definition error, processDefinitionCode from {} to {}." , oldProcessDefinitionCode , processDefinition . getCode ( ) , e ) ;
putMsg ( result , Status . COPY_PROCESS_DEFINITION_ERROR ) ;
putMsg ( result , Status . COPY_PROCESS_DEFINITION_ERROR ) ;
throw new ServiceException ( Status . COPY_PROCESS_DEFINITION_ERROR ) ;
throw new ServiceException ( Status . COPY_PROCESS_DEFINITION_ERROR ) ;
}
}
} else {
} else {
logger . info ( "Move process definition..." ) ;
try {
try {
result . putAll ( updateDagDefine ( loginUser , taskRelationList , processDefinition , null ,
result . putAll ( updateDagDefine ( loginUser , taskRelationList , processDefinition , null ,
Lists . newArrayList ( ) , otherParamsJson ) ) ;
Lists . newArrayList ( ) , otherParamsJson ) ) ;
} catch ( Exception e ) {
} catch ( Exception e ) {
logger . error ( "Move process definition error, processDefinitionCode:{}." , processDefinition . getCode ( ) , e ) ;
putMsg ( result , Status . MOVE_PROCESS_DEFINITION_ERROR ) ;
putMsg ( result , Status . MOVE_PROCESS_DEFINITION_ERROR ) ;
throw new ServiceException ( Status . MOVE_PROCESS_DEFINITION_ERROR ) ;
throw new ServiceException ( Status . MOVE_PROCESS_DEFINITION_ERROR ) ;
}
}
@ -2030,6 +2092,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
ProcessDefinition processDefinition = processDefinitionMapper . queryByCode ( code ) ;
ProcessDefinition processDefinition = processDefinitionMapper . queryByCode ( code ) ;
if ( Objects . isNull ( processDefinition ) | | projectCode ! = processDefinition . getProjectCode ( ) ) {
if ( Objects . isNull ( processDefinition ) | | projectCode ! = processDefinition . getProjectCode ( ) ) {
logger . error ( "Switch process definition error because it does not exist, projectCode:{}, processDefinitionCode:{}." , projectCode , code ) ;
putMsg ( result , Status . SWITCH_PROCESS_DEFINITION_VERSION_NOT_EXIST_PROCESS_DEFINITION_ERROR , code ) ;
putMsg ( result , Status . SWITCH_PROCESS_DEFINITION_VERSION_NOT_EXIST_PROCESS_DEFINITION_ERROR , code ) ;
return result ;
return result ;
}
}
@ -2037,15 +2100,18 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
ProcessDefinitionLog processDefinitionLog =
ProcessDefinitionLog processDefinitionLog =
processDefinitionLogMapper . queryByDefinitionCodeAndVersion ( code , version ) ;
processDefinitionLogMapper . queryByDefinitionCodeAndVersion ( code , version ) ;
if ( Objects . isNull ( processDefinitionLog ) ) {
if ( Objects . isNull ( processDefinitionLog ) ) {
logger . error ( "Switch process definition error because version does not exist, projectCode:{}, processDefinitionCode:{}, version:{}." , projectCode , code , version ) ;
putMsg ( result , Status . SWITCH_PROCESS_DEFINITION_VERSION_NOT_EXIST_PROCESS_DEFINITION_VERSION_ERROR ,
putMsg ( result , Status . SWITCH_PROCESS_DEFINITION_VERSION_NOT_EXIST_PROCESS_DEFINITION_VERSION_ERROR ,
processDefinition . getCode ( ) , version ) ;
processDefinition . getCode ( ) , version ) ;
return result ;
return result ;
}
}
int switchVersion = processService . switchVersion ( processDefinition , processDefinitionLog ) ;
int switchVersion = processService . switchVersion ( processDefinition , processDefinitionLog ) ;
if ( switchVersion < = 0 ) {
if ( switchVersion < = 0 ) {
logger . error ( "Switch process definition version error, projectCode:{}, processDefinitionCode:{}, version:{}." , projectCode , code , version ) ;
putMsg ( result , Status . SWITCH_PROCESS_DEFINITION_VERSION_ERROR ) ;
putMsg ( result , Status . SWITCH_PROCESS_DEFINITION_VERSION_ERROR ) ;
throw new ServiceException ( Status . SWITCH_PROCESS_DEFINITION_VERSION_ERROR ) ;
throw new ServiceException ( Status . SWITCH_PROCESS_DEFINITION_VERSION_ERROR ) ;
}
}
logger . info ( "Switch process definition version complete, projectCode:{}, processDefinitionCode:{}, version:{}." , projectCode , code , version ) ;
putMsg ( result , Status . SUCCESS ) ;
putMsg ( result , Status . SUCCESS ) ;
return result ;
return result ;
}
}
@ -2062,14 +2128,18 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
private void checkBatchOperateResult ( long srcProjectCode , long targetProjectCode ,
private void checkBatchOperateResult ( long srcProjectCode , long targetProjectCode ,
Map < String , Object > result , List < String > failedProcessList , boolean isCopy ) {
Map < String , Object > result , List < String > failedProcessList , boolean isCopy ) {
if ( ! failedProcessList . isEmpty ( ) ) {
if ( ! failedProcessList . isEmpty ( ) ) {
String failedProcess = String . join ( "," , failedProcessList ) ;
if ( isCopy ) {
if ( isCopy ) {
putMsg ( result , Status . COPY_PROCESS_DEFINITION_ERROR , srcProjectCode , targetProjectCode ,
logger . error ( "Copy process definition error, srcProjectCode:{}, targetProjectCode:{}, failedProcessList:{}." ,
String . join ( "," , failedProcessList ) ) ;
srcProjectCode , targetProjectCode , failedProcess ) ;
putMsg ( result , Status . COPY_PROCESS_DEFINITION_ERROR , srcProjectCode , targetProjectCode , failedProcess ) ;
} else {
} else {
putMsg ( result , Status . MOVE_PROCESS_DEFINITION_ERROR , srcProjectCode , targetProjectCode ,
logger . error ( "Move process definition error, srcProjectCode:{}, targetProjectCode:{}, failedProcessList:{}." ,
String . join ( "," , failedProcessList ) ) ;
srcProjectCode , targetProjectCode , failedProcess ) ;
putMsg ( result , Status . MOVE_PROCESS_DEFINITION_ERROR , srcProjectCode , targetProjectCode , failedProcess ) ;
}
}
} else {
} else {
logger . info ( "Batch {} process definition complete, srcProjectCode:{}, targetProjectCode:{}." , isCopy ? "copy" : "move" , srcProjectCode , targetProjectCode ) ;
putMsg ( result , Status . SUCCESS ) ;
putMsg ( result , Status . SUCCESS ) ;
}
}
}
}
@ -2133,19 +2203,24 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
ProcessDefinition processDefinition = processDefinitionMapper . queryByCode ( code ) ;
ProcessDefinition processDefinition = processDefinitionMapper . queryByCode ( code ) ;
if ( processDefinition = = null | | projectCode ! = processDefinition . getProjectCode ( ) ) {
if ( processDefinition = = null | | projectCode ! = processDefinition . getProjectCode ( ) ) {
logger . error ( "Process definition does not exist, code:{}." , code ) ;
putMsg ( result , Status . PROCESS_DEFINE_NOT_EXIST , String . valueOf ( code ) ) ;
putMsg ( result , Status . PROCESS_DEFINE_NOT_EXIST , String . valueOf ( code ) ) ;
} else {
} else {
if ( processDefinition . getVersion ( ) = = version ) {
if ( processDefinition . getVersion ( ) = = version ) {
logger . warn ( "Process definition can not be deleted due to version is being used, projectCode:{}, processDefinitionCode:{}, version:{}." ,
projectCode , code , version ) ;
putMsg ( result , Status . MAIN_TABLE_USING_VERSION ) ;
putMsg ( result , Status . MAIN_TABLE_USING_VERSION ) ;
return result ;
return result ;
}
}
int deleteLog = processDefinitionLogMapper . deleteByProcessDefinitionCodeAndVersion ( code , version ) ;
int deleteLog = processDefinitionLogMapper . deleteByProcessDefinitionCodeAndVersion ( code , version ) ;
int deleteRelationLog = processTaskRelationLogMapper . deleteByCode ( code , version ) ;
int deleteRelationLog = processTaskRelationLogMapper . deleteByCode ( code , version ) ;
if ( deleteLog = = 0 | | deleteRelationLog = = 0 ) {
if ( deleteLog = = 0 | | deleteRelationLog = = 0 ) {
logger . error ( "Delete process definition version error, projectCode:{}, processDefinitionCode:{}, version:{}." , projectCode , code , version ) ;
putMsg ( result , Status . DELETE_PROCESS_DEFINE_BY_CODE_ERROR ) ;
putMsg ( result , Status . DELETE_PROCESS_DEFINE_BY_CODE_ERROR ) ;
throw new ServiceException ( Status . DELETE_PROCESS_DEFINE_BY_CODE_ERROR ) ;
throw new ServiceException ( Status . DELETE_PROCESS_DEFINE_BY_CODE_ERROR ) ;
}
}
deleteOtherRelation ( project , result , processDefinition ) ;
deleteOtherRelation ( project , result , processDefinition ) ;
logger . info ( "Delete process definition version complete, projectCode:{}, processDefinitionCode:{}, version:{}." , projectCode , code , version ) ;
putMsg ( result , Status . SUCCESS ) ;
putMsg ( result , Status . SUCCESS ) ;
}
}
return result ;
return result ;
@ -2183,12 +2258,15 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
return result ;
return result ;
}
}
if ( checkDescriptionLength ( description ) ) {
if ( checkDescriptionLength ( description ) ) {
logger . warn ( "Parameter description is too long." ) ;
putMsg ( result , Status . DESCRIPTION_TOO_LONG_ERROR ) ;
putMsg ( result , Status . DESCRIPTION_TOO_LONG_ERROR ) ;
return result ;
return result ;
}
}
// check whether the new process define name exist
// check whether the new process define name exist
ProcessDefinition definition = processDefinitionMapper . verifyByDefineName ( project . getCode ( ) , name ) ;
ProcessDefinition definition = processDefinitionMapper . verifyByDefineName ( project . getCode ( ) , name ) ;
if ( definition ! = null ) {
if ( definition ! = null ) {
logger . warn ( "Process definition with the same name {} already exists, processDefinitionCode:{}." ,
definition . getName ( ) , definition . getCode ( ) ) ;
putMsg ( result , Status . PROCESS_DEFINITION_NAME_EXIST , name ) ;
putMsg ( result , Status . PROCESS_DEFINITION_NAME_EXIST , name ) ;
return result ;
return result ;
}
}
@ -2197,6 +2275,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
if ( ! Constants . DEFAULT . equals ( tenantCode ) ) {
if ( ! Constants . DEFAULT . equals ( tenantCode ) ) {
Tenant tenant = tenantMapper . queryByTenantCode ( tenantCode ) ;
Tenant tenant = tenantMapper . queryByTenantCode ( tenantCode ) ;
if ( tenant = = null ) {
if ( tenant = = null ) {
logger . error ( "Tenant does not exist." ) ;
putMsg ( result , Status . TENANT_NOT_EXIST ) ;
putMsg ( result , Status . TENANT_NOT_EXIST ) ;
return result ;
return result ;
}
}
@ -2206,6 +2285,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
try {
try {
processDefinitionCode = CodeGenerateUtils . getInstance ( ) . genCode ( ) ;
processDefinitionCode = CodeGenerateUtils . getInstance ( ) . genCode ( ) ;
} catch ( CodeGenerateException e ) {
} catch ( CodeGenerateException e ) {
logger . error ( "Generate process definition code error, projectCode:{}." , projectCode , e ) ;
putMsg ( result , Status . INTERNAL_SERVER_ERROR_ARGS ) ;
putMsg ( result , Status . INTERNAL_SERVER_ERROR_ARGS ) ;
return result ;
return result ;
}
}
@ -2215,6 +2295,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
processDefinition . setExecutionType ( executionType ) ;
processDefinition . setExecutionType ( executionType ) ;
result = createEmptyDagDefine ( loginUser , processDefinition ) ;
result = createEmptyDagDefine ( loginUser , processDefinition ) ;
if ( result . get ( Constants . STATUS ) ! = Status . SUCCESS ) {
if ( result . get ( Constants . STATUS ) ! = Status . SUCCESS ) {
logger . error ( "Create empty process definition error." ) ;
return result ;
return result ;
}
}
@ -2236,6 +2317,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
Map < String , Object > result = new HashMap < > ( ) ;
Map < String , Object > result = new HashMap < > ( ) ;
int insertVersion = processService . saveProcessDefine ( loginUser , processDefinition , Boolean . TRUE , Boolean . TRUE ) ;
int insertVersion = processService . saveProcessDefine ( loginUser , processDefinition , Boolean . TRUE , Boolean . TRUE ) ;
if ( insertVersion = = 0 ) {
if ( insertVersion = = 0 ) {
logger . error ( "Save process definition error, processDefinitionCode:{}." , processDefinition . getCode ( ) ) ;
putMsg ( result , Status . CREATE_PROCESS_DEFINITION_ERROR ) ;
putMsg ( result , Status . CREATE_PROCESS_DEFINITION_ERROR ) ;
throw new ServiceException ( Status . CREATE_PROCESS_DEFINITION_ERROR ) ;
throw new ServiceException ( Status . CREATE_PROCESS_DEFINITION_ERROR ) ;
}
}
@ -2255,12 +2337,12 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
Date now = new Date ( ) ;
Date now = new Date ( ) ;
scheduleObj . setProcessDefinitionCode ( processDefinition . getCode ( ) ) ;
scheduleObj . setProcessDefinitionCode ( processDefinition . getCode ( ) ) ;
if ( DateUtils . differSec ( scheduleObj . getStartTime ( ) , scheduleObj . getEndTime ( ) ) = = 0 ) {
if ( DateUtils . differSec ( scheduleObj . getStartTime ( ) , scheduleObj . getEndTime ( ) ) = = 0 ) {
logger . warn ( "The start time must not be the same as the end" ) ;
logger . warn ( "The schedule s tart time must not be the same as the end, processDefinitionCode:{}. " , processDefinition . getCode ( ) ) ;
putMsg ( result , Status . SCHEDULE_START_TIME_END_TIME_SAME ) ;
putMsg ( result , Status . SCHEDULE_START_TIME_END_TIME_SAME ) ;
return result ;
return result ;
}
}
if ( ! org . quartz . CronExpression . isValidExpression ( scheduleObj . getCrontab ( ) ) ) {
if ( ! org . quartz . CronExpression . isValidExpression ( scheduleObj . getCrontab ( ) ) ) {
logger . error ( "{} verify failure " , scheduleObj . getCrontab ( ) ) ;
logger . error ( "CronExpression verify failure, cron:{}. " , scheduleObj . getCrontab ( ) ) ;
putMsg ( result , Status . REQUEST_PARAMS_NOT_VALID_ERROR , scheduleObj . getCrontab ( ) ) ;
putMsg ( result , Status . REQUEST_PARAMS_NOT_VALID_ERROR , scheduleObj . getCrontab ( ) ) ;
return result ;
return result ;
}
}
@ -2322,6 +2404,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
return result ;
return result ;
}
}
if ( checkDescriptionLength ( description ) ) {
if ( checkDescriptionLength ( description ) ) {
logger . warn ( "Parameter description is too long." ) ;
putMsg ( result , Status . DESCRIPTION_TOO_LONG_ERROR ) ;
putMsg ( result , Status . DESCRIPTION_TOO_LONG_ERROR ) ;
return result ;
return result ;
}
}
@ -2329,6 +2412,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
if ( ! Constants . DEFAULT . equals ( tenantCode ) ) {
if ( ! Constants . DEFAULT . equals ( tenantCode ) ) {
Tenant tenant = tenantMapper . queryByTenantCode ( tenantCode ) ;
Tenant tenant = tenantMapper . queryByTenantCode ( tenantCode ) ;
if ( tenant = = null ) {
if ( tenant = = null ) {
logger . error ( "Tenant does not exist." ) ;
putMsg ( result , Status . TENANT_NOT_EXIST ) ;
putMsg ( result , Status . TENANT_NOT_EXIST ) ;
return result ;
return result ;
}
}
@ -2338,11 +2422,14 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
ProcessDefinition processDefinition = processDefinitionMapper . queryByCode ( code ) ;
ProcessDefinition processDefinition = processDefinitionMapper . queryByCode ( code ) ;
// check process definition exists
// check process definition exists
if ( processDefinition = = null | | projectCode ! = processDefinition . getProjectCode ( ) ) {
if ( processDefinition = = null | | projectCode ! = processDefinition . getProjectCode ( ) ) {
logger . error ( "Process definition does not exist, code:{}." , code ) ;
putMsg ( result , Status . PROCESS_DEFINE_NOT_EXIST , String . valueOf ( code ) ) ;
putMsg ( result , Status . PROCESS_DEFINE_NOT_EXIST , String . valueOf ( code ) ) ;
return result ;
return result ;
}
}
if ( processDefinition . getReleaseState ( ) = = ReleaseState . ONLINE ) {
if ( processDefinition . getReleaseState ( ) = = ReleaseState . ONLINE ) {
// online can not permit edit
// online can not permit edit
logger . warn ( "Process definition is not allowed to be modified due to {}, processDefinitionCode:{}." ,
ReleaseState . ONLINE . getDescp ( ) , processDefinition . getCode ( ) ) ;
putMsg ( result , Status . PROCESS_DEFINE_NOT_ALLOWED_EDIT , processDefinition . getName ( ) ) ;
putMsg ( result , Status . PROCESS_DEFINE_NOT_ALLOWED_EDIT , processDefinition . getName ( ) ) ;
return result ;
return result ;
}
}
@ -2350,6 +2437,8 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
// check whether the new process define name exist
// check whether the new process define name exist
ProcessDefinition definition = processDefinitionMapper . verifyByDefineName ( project . getCode ( ) , name ) ;
ProcessDefinition definition = processDefinitionMapper . verifyByDefineName ( project . getCode ( ) , name ) ;
if ( definition ! = null ) {
if ( definition ! = null ) {
logger . warn ( "Process definition with the same name {} already exists, processDefinitionCode:{}." ,
definition . getName ( ) , definition . getCode ( ) ) ;
putMsg ( result , Status . PROCESS_DEFINITION_NAME_EXIST , name ) ;
putMsg ( result , Status . PROCESS_DEFINITION_NAME_EXIST , name ) ;
return result ;
return result ;
}
}
@ -2363,6 +2452,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
result = updateDagDefine ( loginUser , taskRelationList , processDefinition , processDefinitionDeepCopy ,
result = updateDagDefine ( loginUser , taskRelationList , processDefinition , processDefinitionDeepCopy ,
Lists . newArrayList ( ) , otherParamsJson ) ;
Lists . newArrayList ( ) , otherParamsJson ) ;
if ( result . get ( Constants . STATUS ) ! = Status . SUCCESS ) {
if ( result . get ( Constants . STATUS ) ! = Status . SUCCESS ) {
logger . error ( "Update process definition basic info error." ) ;
return result ;
return result ;
}
}
@ -2446,11 +2536,13 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
ProcessDefinition processDefinition = processDefinitionMapper . queryByCode ( code ) ;
ProcessDefinition processDefinition = processDefinitionMapper . queryByCode ( code ) ;
if ( processDefinition = = null ) {
if ( processDefinition = = null ) {
logger . error ( "Process definition does not exist, code:{}." , code ) ;
putMsg ( result , Status . PROCESS_DEFINE_NOT_EXIST , String . valueOf ( code ) ) ;
putMsg ( result , Status . PROCESS_DEFINE_NOT_EXIST , String . valueOf ( code ) ) ;
return result ;
return result ;
}
}
Schedule scheduleObj = scheduleMapper . queryByProcessDefinitionCode ( code ) ;
Schedule scheduleObj = scheduleMapper . queryByProcessDefinitionCode ( code ) ;
if ( scheduleObj = = null ) {
if ( scheduleObj = = null ) {
logger . error ( "Schedule cron does not exist, processDefinitionCode:{}." , code ) ;
putMsg ( result , Status . SCHEDULE_CRON_NOT_EXISTS , "processDefinitionCode:" + code ) ;
putMsg ( result , Status . SCHEDULE_CRON_NOT_EXISTS , "processDefinitionCode:" + code ) ;
return result ;
return result ;
}
}
@ -2459,6 +2551,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
List < ProcessTaskRelation > relationList =
List < ProcessTaskRelation > relationList =
processService . findRelationByCode ( code , processDefinition . getVersion ( ) ) ;
processService . findRelationByCode ( code , processDefinition . getVersion ( ) ) ;
if ( CollectionUtils . isEmpty ( relationList ) ) {
if ( CollectionUtils . isEmpty ( relationList ) ) {
logger . warn ( "Process definition has no task relation, processDefinitionCode:{}." , code ) ;
putMsg ( result , Status . PROCESS_DAG_IS_EMPTY ) ;
putMsg ( result , Status . PROCESS_DAG_IS_EMPTY ) ;
return result ;
return result ;
}
}
@ -2470,12 +2563,13 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
processDefinition . setReleaseState ( releaseState ) ;
processDefinition . setReleaseState ( releaseState ) ;
int updateProcess = processDefinitionMapper . updateById ( processDefinition ) ;
int updateProcess = processDefinitionMapper . updateById ( processDefinition ) ;
if ( updateProcess > 0 ) {
if ( updateProcess > 0 ) {
logger . info ( "set schedule offline, project code: {}, schedule id: {}, process definition code: {} " ,
logger . info ( "Set schedule offline, projectCode:{}, processDefinitionCode:{}, scheduleId:{}. " ,
projectCode , scheduleObj . getId ( ) , code ) ;
projectCode , code , scheduleObj . getId ( ) ) ;
// set status
// set status
scheduleObj . setReleaseState ( ReleaseState . OFFLINE ) ;
scheduleObj . setReleaseState ( ReleaseState . OFFLINE ) ;
int updateSchedule = scheduleMapper . updateById ( scheduleObj ) ;
int updateSchedule = scheduleMapper . updateById ( scheduleObj ) ;
if ( updateSchedule = = 0 ) {
if ( updateSchedule = = 0 ) {
logger . error ( "Set schedule offline error, projectCode:{}, processDefinitionCode:{}, scheduleId:{}" , projectCode , code , scheduleObj . getId ( ) ) ;
putMsg ( result , Status . OFFLINE_SCHEDULE_ERROR ) ;
putMsg ( result , Status . OFFLINE_SCHEDULE_ERROR ) ;
throw new ServiceException ( Status . OFFLINE_SCHEDULE_ERROR ) ;
throw new ServiceException ( Status . OFFLINE_SCHEDULE_ERROR ) ;
}
}