@ -117,18 +117,7 @@ import java.io.BufferedReader;
import java.io.IOException ;
import java.io.InputStreamReader ;
import java.nio.charset.StandardCharsets ;
import java.util.ArrayList ;
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.* ;
import java.util.concurrent.ConcurrentHashMap ;
import java.util.function.Function ;
import java.util.stream.Collectors ;
@ -261,11 +250,14 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
return result ;
}
if ( checkDescriptionLength ( description ) ) {
logger . warn ( "Parameter description is too long." ) ;
throw new ServiceException ( Status . DESCRIPTION_TOO_LONG_ERROR ) ;
}
// check whether the new process define name exist
ProcessDefinition definition = processDefinitionMapper . verifyByDefineName ( project . getCode ( ) , name ) ;
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 ) ;
}
List < TaskDefinitionLog > taskDefinitionLogs = generateTaskDefinitionList ( taskDefinitionJson ) ;
@ -274,6 +266,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
if ( ! Constants . DEFAULT . equals ( tenantCode ) ) {
Tenant tenant = tenantMapper . queryByTenantCode ( tenantCode ) ;
if ( tenant = = null ) {
logger . error ( "Tenant does not exist." ) ;
throw new ServiceException ( Status . TENANT_NOT_EXIST ) ;
}
tenantId = tenant . getId ( ) ;
@ -298,18 +291,26 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
logger . info ( "The task has not changed, so skip" ) ;
}
if ( saveTaskResult = = Constants . DEFINITION_FAILURE ) {
logger . error ( "Save task definition error." ) ;
throw new ServiceException ( Status . CREATE_TASK_DEFINITION_ERROR ) ;
}
int insertVersion = processService . saveProcessDefine ( loginUser , processDefinition , Boolean . TRUE , Boolean . TRUE ) ;
if ( insertVersion = = 0 ) {
logger . error ( "Save process definition error, processCode:{}." , processDefinition . getCode ( ) ) ;
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 ( ) ,
processDefinition . getCode ( ) ,
insertVersion , taskRelationList , taskDefinitionLogs , Boolean . TRUE ) ;
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 ) ;
}
} else
logger . info ( "Save process task relations complete, projectCode:{}, processCode:{}, processVersion:{}." ,
processDefinition . getProjectCode ( ) , processDefinition . getCode ( ) , insertVersion ) ;
saveOtherRelation ( loginUser , processDefinition , result , otherParamsJson ) ;
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 ( ) ) ;
Collection < Long > codes = CollectionUtils . subtract ( postTaskCodes , taskNodeCodes ) ;
if ( CollectionUtils . isNotEmpty ( codes ) ) {
logger . error ( "the task code is not exist" ) ;
throw new ServiceException ( Status . TASK_DEFINE_NOT_EXIST , StringUtils . join ( codes , Constants . COMMA ) ) ;
String taskCodes = 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 ) ) {
logger . error ( "process DAG has cycle " ) ;
logger . error ( "Process DAG has cycle. " ) ;
throw new ServiceException ( Status . PROCESS_NODE_HAS_CYCLE ) ;
}
// check whether the task relation json is normal
for ( ProcessTaskRelationLog processTaskRelationLog : taskRelationList ) {
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 ) ;
}
}
@ -519,6 +522,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
ProcessDefinition processDefinition = processDefinitionMapper . queryByCode ( code ) ;
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 ) ) ;
} else {
Tenant tenant = tenantMapper . queryById ( processDefinition . getTenantId ( ) ) ;
@ -544,6 +548,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
ProcessDefinition processDefinition = processDefinitionMapper . queryByDefineName ( projectCode , name ) ;
if ( processDefinition = = null ) {
logger . error ( "Process definition does not exist, projectCode:{}." , projectCode ) ;
putMsg ( result , Status . PROCESS_DEFINE_NOT_EXIST , name ) ;
} else {
DagData dagData = processService . genDagData ( processDefinition ) ;
@ -593,6 +598,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
return result ;
}
if ( checkDescriptionLength ( description ) ) {
logger . warn ( "Parameter description is too long." ) ;
putMsg ( result , Status . DESCRIPTION_TOO_LONG_ERROR ) ;
return result ;
}
@ -603,6 +609,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
if ( ! Constants . DEFAULT . equals ( tenantCode ) ) {
Tenant tenant = tenantMapper . queryByTenantCode ( tenantCode ) ;
if ( tenant = = null ) {
logger . error ( "Tenant does not exist." ) ;
putMsg ( result , Status . TENANT_NOT_EXIST ) ;
return result ;
}
@ -612,11 +619,14 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
ProcessDefinition processDefinition = processDefinitionMapper . queryByCode ( code ) ;
// check process definition exists
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 ) ) ;
return result ;
}
if ( processDefinition . getReleaseState ( ) = = ReleaseState . ONLINE ) {
// 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 ( ) ) ;
return result ;
}
@ -624,6 +634,8 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
// check whether the new process define name exist
ProcessDefinition definition = processDefinitionMapper . verifyByDefineName ( project . getCode ( ) , name ) ;
if ( definition ! = null ) {
logger . warn ( "Process definition with the same name already exists, processDefinitionCode:{}." ,
definition . getCode ( ) ) ;
putMsg ( result , Status . PROCESS_DEFINITION_NAME_EXIST , name ) ;
return result ;
}
@ -661,6 +673,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
taskDepMsg . ifPresent ( sb : : append ) ;
}
if ( sb . length ( ) ! = 0 ) {
logger . error ( "Task cannot be deleted because it is dependent" ) ;
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" ) ;
}
if ( saveTaskResult = = Constants . DEFINITION_FAILURE ) {
logger . error ( "Update task definitions error, projectCode:{}, processCode:{}." , processDefinition . getProjectCode ( ) , processDefinition . getCode ( ) ) ;
putMsg ( result , 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 ;
}
if ( isChange ) {
logger . info ( "Process definition needs to be updated, projectCode:{}, processCode:{}, processVersion:{}." ,
processDefinition . getProjectCode ( ) , processDefinition . getCode ( ) , processDefinition . getVersion ( ) ) ;
processDefinition . setUpdateTime ( new Date ( ) ) ;
int insertVersion =
processService . saveProcessDefine ( loginUser , processDefinition , Boolean . TRUE , Boolean . TRUE ) ;
if ( insertVersion < = 0 ) {
logger . error ( "Update process definition error, processCode:{}." , processDefinition . getCode ( ) ) ;
putMsg ( result , 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 ) ;
int insertResult = processService . saveTaskRelation ( loginUser , processDefinition . getProjectCode ( ) ,
processDefinition . getCode ( ) , insertVersion , taskRelationList , taskDefinitionLogs , Boolean . TRUE ) ;
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 ) ;
result . put ( Constants . DATA_LIST , processDefinition ) ;
} else {
logger . error ( "Update process task relations error, projectCode:{}, processCode:{}, processVersion:{}." ,
processDefinition . getProjectCode ( ) , processDefinition . getCode ( ) , insertVersion ) ;
putMsg ( result , Status . UPDATE_PROCESS_DEFINITION_ERROR ) ;
throw new ServiceException ( Status . UPDATE_PROCESS_DEFINITION_ERROR ) ;
}
saveOtherRelation ( loginUser , processDefinition , result , otherParamsJson ) ;
} 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 ) ;
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
* /
@Override
public Map < String , Object > verifyProcessDefinitionName ( User loginUser , long projectCode , String name ,
long processDefinitionCode ) {
public Map < String , Object > verifyProcessDefinitionName ( User loginUser , long projectCode , String name , long processDefinitionCode ) {
Project project = projectMapper . queryByCode ( projectCode ) ;
// check user access for project
Map < String , Object > result =
@ -758,6 +781,8 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
putMsg ( result , Status . SUCCESS ) ;
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 ( ) ) ;
return result ;
}
@ -772,6 +797,8 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
private void processDefinitionUsedInOtherTaskValid ( ProcessDefinition processDefinition ) {
// check process definition is already 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 ( ) ) ;
}
@ -779,6 +806,8 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
List < ProcessInstance > processInstances = processInstanceService
. queryByProcessDefineCodeAndStatus ( processDefinition . getCode ( ) , Constants . NOT_TERMINATED_STATES ) ;
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 ( ) ) ;
}
@ -790,6 +819,8 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
. map ( task - > String . format ( Constants . FORMAT_S_S_COLON , task . getProcessDefinitionName ( ) ,
task . getTaskName ( ) ) )
. 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 ) ;
}
}
@ -814,12 +845,14 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
}
ProcessDefinition processDefinition = processDefinitionMapper . queryByCode ( code ) ;
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 ) ) ;
return result ;
}
// Determine if the login user is the owner of the process definition
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 ) ;
return result ;
}
@ -832,23 +865,27 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
if ( scheduleObj . getReleaseState ( ) = = ReleaseState . OFFLINE ) {
int delete = scheduleMapper . deleteById ( scheduleObj . getId ( ) ) ;
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 ) ;
throw new ServiceException ( Status . DELETE_SCHEDULE_CRON_BY_ID_ERROR ) ;
}
}
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 ( ) ) ;
return result ;
}
}
int delete = processDefinitionMapper . deleteById ( processDefinition . getId ( ) ) ;
if ( delete = = 0 ) {
logger . error ( "Delete process definition error, processDefinitionCode:{}." , code ) ;
putMsg ( result , 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 ( ) ) ;
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 ) ;
putMsg ( result , Status . SUCCESS ) ;
@ -884,6 +921,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
ProcessDefinition processDefinition = processDefinitionMapper . queryByCode ( code ) ;
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 ) ) ;
return result ;
}
@ -892,27 +930,32 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
List < ProcessTaskRelation > relationList =
processService . findRelationByCode ( code , processDefinition . getVersion ( ) ) ;
if ( CollectionUtils . isEmpty ( relationList ) ) {
logger . warn ( "Process definition has no task relation, processDefinitionCode:{}." , code ) ;
putMsg ( result , Status . PROCESS_DAG_IS_EMPTY ) ;
return result ;
}
processDefinition . setReleaseState ( releaseState ) ;
processDefinitionMapper . updateById ( processDefinition ) ;
logger . info ( "Set process definition online, projectCode:{}, processDefinitionCode:{}." , projectCode , code ) ;
break ;
case OFFLINE :
processDefinition . setReleaseState ( releaseState ) ;
int updateProcess = processDefinitionMapper . updateById ( processDefinition ) ;
Schedule schedule = scheduleMapper . queryByProcessDefinitionCode ( code ) ;
if ( updateProcess > 0 & & schedule ! = null ) {
logger . info ( "set schedule offline, project code: {}, schedule id: {}, process definition code: {}" ,
projectCode , schedule . getId ( ) , code ) ;
// set status
schedule . setReleaseState ( releaseState ) ;
int updateSchedule = scheduleMapper . updateById ( schedule ) ;
if ( updateSchedule = = 0 ) {
putMsg ( result , Status . OFFLINE_SCHEDULE_ERROR ) ;
throw new ServiceException ( Status . OFFLINE_SCHEDULE_ERROR ) ;
if ( updateProcess > 0 ) {
logger . info ( "Set process definition offline, projectCode:{}, processDefinitionCode:{}." , projectCode , code ) ;
if ( schedule ! = null ) {
// set status
schedule . setReleaseState ( releaseState ) ;
int updateSchedule = scheduleMapper . updateById ( schedule ) ;
if ( updateSchedule = = 0 ) {
logger . error ( "Set schedule offline error, projectCode:{}, processDefinitionCode:{}, scheduleId:{}" , projectCode , code , schedule . getId ( ) ) ;
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 ;
default :
@ -931,6 +974,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
public void batchExportProcessDefinitionByCodes ( User loginUser , long projectCode , String codes ,
HttpServletResponse response ) {
if ( StringUtils . isEmpty ( codes ) ) {
logger . warn ( "Process definition codes to be exported is empty." ) ;
return ;
}
Project project = projectMapper . queryByCode ( projectCode ) ;
@ -944,6 +988,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
. collect ( Collectors . toSet ( ) ) ;
List < ProcessDefinition > processDefinitionList = processDefinitionMapper . queryByCodes ( defineCodeSet ) ;
if ( CollectionUtils . isEmpty ( processDefinitionList ) ) {
logger . error ( "Process definitions to be exported do not exist, processDefinitionCodes:{}." , defineCodeSet ) ;
return ;
}
// check processDefinition exist in project
@ -952,8 +997,10 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
List < DagDataSchedule > dagDataSchedules =
processDefinitionListInProject . stream ( ) . map ( this : : exportProcessDagData ) . collect ( Collectors . toList ( ) ) ;
if ( CollectionUtils . isNotEmpty ( dagDataSchedules ) ) {
logger . info ( "Start download process definition file, processDefinitionCodes:{}." , defineCodeSet ) ;
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 . close ( ) ;
} catch ( IOException e ) {
logger . warn ( "export process fail" , e ) ;
logger . warn ( "Export process definition fail" , e ) ;
} finally {
if ( null ! = buff ) {
try {
buff . close ( ) ;
} catch ( Exception e ) {
logger . warn ( "export process buffer not close" , e ) ;
logger . warn ( "Buffer does not close" , e ) ;
}
}
if ( null ! = out ) {
try {
out . close ( ) ;
} 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
if ( CollectionUtils . isEmpty ( dagDataScheduleList ) ) {
logger . warn ( "Process definition file content is empty." ) ;
putMsg ( result , Status . DATA_IS_NULL , "fileContent" ) ;
return result ;
}
@ -1095,7 +1143,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
long compressionRatio = totalSizeEntry / entry . getCompressedSize ( ) ;
if ( compressionRatio > THRESHOLD_RATIO ) {
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 ( "-- " ) ;
if ( commentIndex > = 0 ) {
@ -1143,6 +1191,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
dataSource = queryDatasourceByNameAndUser ( datasourceName , loginUser ) ;
}
if ( dataSource = = null ) {
logger . error ( "Datasource does not found, may be its name is illegal." ) ;
putMsg ( result , Status . DATASOURCE_NAME_ILLEGAL ) ;
return result ;
}
@ -1167,7 +1216,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
}
}
} catch ( Exception e ) {
logger . error ( e . getMessage ( ) , e ) ;
logger . error ( "Import process definition error." , e ) ;
putMsg ( result , Status . IMPORT_PROCESS_DEFINE_ERROR ) ;
return result ;
}
@ -1272,6 +1321,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
try {
processDefinition . setCode ( CodeGenerateUtils . getInstance ( ) . genCode ( ) ) ;
} 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 ) ;
return false ;
}
@ -1294,7 +1344,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
taskCodeMap . put ( taskDefinitionLog . getCode ( ) , code ) ;
taskDefinitionLog . setCode ( code ) ;
} 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" ) ;
return false ;
}
@ -1303,6 +1353,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
int insert = taskDefinitionMapper . batchInsert ( taskDefinitionLogList ) ;
int logInsert = taskDefinitionLogMapper . batchInsert ( taskDefinitionLogList ) ;
if ( ( logInsert & insert ) = = 0 ) {
logger . error ( "Save task definition error, projectCode:{}, processDefinitionCode:{}" , projectCode , processDefinition . getCode ( ) ) ;
putMsg ( result , 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 ) ;
} else {
result . putAll ( createDagResult ) ;
logger . error ( "Import process definition error, projectCode:{}, processDefinitionCode:{}." , projectCode , processDefinition . getCode ( ) ) ;
throw new ServiceException ( Status . IMPORT_PROCESS_DEFINE_ERROR ) ;
}
@ -1357,10 +1409,13 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
schedule . setUpdateTime ( now ) ;
int scheduleInsert = scheduleMapper . insert ( schedule ) ;
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 ) ;
throw new ServiceException ( Status . IMPORT_PROCESS_DEFINE_ERROR ) ;
}
}
logger . info ( "Import process definition complete, projectCode:{}, processDefinitionCode:{}." , projectCode , processDefinition . getCode ( ) ) ;
return true ;
}
@ -1369,14 +1424,17 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
* /
private boolean checkImportanceParams ( DagDataSchedule dagDataSchedule , Map < String , Object > result ) {
if ( dagDataSchedule . getProcessDefinition ( ) = = null ) {
logger . warn ( "Process definition is null." ) ;
putMsg ( result , Status . DATA_IS_NULL , "ProcessDefinition" ) ;
return false ;
}
if ( CollectionUtils . isEmpty ( dagDataSchedule . getTaskDefinitionList ( ) ) ) {
logger . warn ( "Task definition list is null." ) ;
putMsg ( result , Status . DATA_IS_NULL , "TaskDefinitionList" ) ;
return false ;
}
if ( CollectionUtils . isEmpty ( dagDataSchedule . getProcessTaskRelationList ( ) ) ) {
logger . warn ( "Process task relation list is null." ) ;
putMsg ( result , Status . DATA_IS_NULL , "ProcessTaskRelationList" ) ;
return false ;
}
@ -1411,7 +1469,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
Map < String , Object > result = new HashMap < > ( ) ;
try {
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 ) ;
return result ;
}
@ -1422,14 +1480,14 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
List < TaskNode > taskNodes = processService . transformTask ( taskRelationList , taskDefinitionLogsList ) ;
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 ) ;
return result ;
}
// check has cycle
if ( graphHasCycle ( taskNodes ) ) {
logger . error ( "process DAG has cycle " ) ;
logger . error ( "Process DAG has cycle. " ) ;
putMsg ( result , Status . PROCESS_NODE_HAS_CYCLE ) ;
return result ;
}
@ -1442,7 +1500,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
. dependence ( taskNode . getDependence ( ) )
. switchResult ( taskNode . getSwitchResult ( ) )
. 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 ( ) ) ;
return result ;
}
@ -1477,7 +1535,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
}
ProcessDefinition processDefinition = processDefinitionMapper . queryByCode ( code ) ;
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 ) ) ;
return result ;
}
@ -1509,7 +1567,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
. collect ( Collectors . toSet ( ) ) ;
List < ProcessDefinition > processDefinitionList = processDefinitionMapper . queryByCodes ( defineCodeSet ) ;
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 ) ;
return result ;
}
@ -1521,6 +1579,10 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
List < ProcessDefinition > processDefinitionListInProject = processDefinitionList . stream ( )
. filter ( o - > userProjects . containsKey ( o . getProjectCode ( ) ) ) . collect ( Collectors . toList ( ) ) ;
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 ) ;
return result ;
}
@ -1627,7 +1689,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
* /
@Override
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 ) ;
// check user access for project
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 ) ;
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 ) ) ;
return result ;
}
DAG < String , TaskNode , TaskNodeRelation > dag = processService . genDagGraph ( processDefinition ) ;
// nodes that is running
// nodes that are running
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 < > ( ) ;
// List of process instances
@ -1656,6 +1718,10 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
Map < Long , TaskDefinitionLog > taskDefinitionMap = taskDefinitionList . stream ( )
. collect ( Collectors . toMap ( TaskDefinitionLog : : getCode , taskDefinitionLog - > taskDefinitionLog ) ) ;
if ( limit < 0 ) {
putMsg ( result , Status . REQUEST_PARAMS_NOT_VALID_ERROR ) ;
return result ;
}
if ( limit > processInstanceList . size ( ) ) {
limit = processInstanceList . size ( ) ;
}
@ -1685,17 +1751,9 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
while ( ! ServerLifeCycleManager . isStopped ( ) ) {
Set < String > postNodeList ;
Set < Map . Entry < String , List < TreeViewDto > > > entries = runningNodeMap . entrySet ( ) ;
List < Integer > processInstanceIds = processInstanceList . stream ( )
. limit ( limit ) . map ( ProcessInstance : : getId ) . collect ( Collectors . toList ( ) ) ;
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 ) {
Iterator < Map . Entry < String , List < TreeViewDto > > > iter = runningNodeMap . entrySet ( ) . iterator ( ) ;
while ( iter . hasNext ( ) ) {
Map . Entry < String , List < TreeViewDto > > en = iter . next ( ) ;
String nodeCode = en . getKey ( ) ;
parentTreeViewDtoList = en . getValue ( ) ;
@ -1707,14 +1765,8 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
// set treeViewDto instances
for ( int i = limit - 1 ; i > = 0 ; i - - ) {
ProcessInstance processInstance = processInstanceList . get ( i ) ;
TaskInstance taskInstance = null ;
for ( TaskInstance instance : taskInstances ) {
if ( instance . getTaskCode ( ) = = Long . parseLong ( nodeCode )
& & instance . getProcessInstanceId ( ) = = processInstance . getId ( ) ) {
taskInstance = instance ;
break ;
}
}
TaskInstance taskInstance = taskInstanceMapper . queryByInstanceIdAndCode ( processInstance . getId ( ) ,
Long . parseLong ( nodeCode ) ) ;
if ( taskInstance = = null ) {
treeViewDto . getInstances ( ) . add ( new Instance ( - 1 , "not running" , 0 , "null" ) ) ;
} else {
@ -1838,6 +1890,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
return result ;
}
if ( projectCode = = targetProjectCode ) {
logger . warn ( "Project code is same as target project code, projectCode:{}." , projectCode ) ;
return result ;
}
@ -1859,6 +1912,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
}
if ( StringUtils . isEmpty ( processDefinitionCodes ) ) {
logger . error ( "Parameter processDefinitionCodes is empty, projectCode is {}." , projectCode ) ;
putMsg ( result , Status . PROCESS_DEFINITION_CODES_IS_EMPTY , processDefinitionCodes ) ;
return result ;
}
@ -1899,10 +1953,12 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
processDefinition . setProjectCode ( targetProjectCode ) ;
String otherParamsJson = doOtherOperateProcess ( loginUser , processDefinition ) ;
if ( isCopy ) {
logger . info ( "Copy process definition..." ) ;
List < TaskDefinitionLog > taskDefinitionLogs = processService . genTaskDefineList ( processTaskRelations ) ;
Map < Long , Long > taskCodeMap = new HashMap < > ( ) ;
for ( TaskDefinitionLog taskDefinitionLog : taskDefinitionLogs ) {
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 ( ) ) ;
return ;
}
@ -1911,6 +1967,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
taskCodeMap . put ( taskDefinitionLog . getCode ( ) , taskCode ) ;
taskDefinitionLog . setCode ( taskCode ) ;
} catch ( CodeGenerateException e ) {
logger . error ( "Generate task definition code error, projectCode:{}." , targetProjectCode , e ) ;
putMsg ( result , 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 {
processDefinition . setCode ( CodeGenerateUtils . getInstance ( ) . genCode ( ) ) ;
} catch ( CodeGenerateException e ) {
logger . error ( "Generate process definition code error, projectCode:{}." , targetProjectCode , e ) ;
putMsg ( result , 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 ) ;
int insertResult = scheduleMapper . insert ( scheduleObj ) ;
if ( insertResult ! = 1 ) {
logger . error ( "Schedule create error, processDefinitionCode:{}." , processDefinition . getCode ( ) ) ;
putMsg ( result , 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 ,
otherParamsJson ) ) ;
} catch ( Exception e ) {
logger . error ( "Copy process definition error, processDefinitionCode from {} to {}." , oldProcessDefinitionCode , processDefinition . getCode ( ) , e ) ;
putMsg ( result , Status . COPY_PROCESS_DEFINITION_ERROR ) ;
throw new ServiceException ( Status . COPY_PROCESS_DEFINITION_ERROR ) ;
}
} else {
logger . info ( "Move process definition..." ) ;
try {
result . putAll ( updateDagDefine ( loginUser , taskRelationList , processDefinition , null ,
Lists . newArrayList ( ) , otherParamsJson ) ) ;
} catch ( Exception e ) {
logger . error ( "Move process definition error, processDefinitionCode:{}." , processDefinition . getCode ( ) , e ) ;
putMsg ( result , 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 ) ;
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 ) ;
return result ;
}
@ -2037,15 +2100,18 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
ProcessDefinitionLog processDefinitionLog =
processDefinitionLogMapper . queryByDefinitionCodeAndVersion ( code , version ) ;
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 ,
processDefinition . getCode ( ) , version ) ;
return result ;
}
int switchVersion = processService . switchVersion ( processDefinition , processDefinitionLog ) ;
if ( switchVersion < = 0 ) {
logger . error ( "Switch process definition version error, projectCode:{}, processDefinitionCode:{}, version:{}." , projectCode , code , version ) ;
putMsg ( result , 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 ) ;
return result ;
}
@ -2062,14 +2128,18 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
private void checkBatchOperateResult ( long srcProjectCode , long targetProjectCode ,
Map < String , Object > result , List < String > failedProcessList , boolean isCopy ) {
if ( ! failedProcessList . isEmpty ( ) ) {
String failedProcess = String . join ( "," , failedProcessList ) ;
if ( isCopy ) {
putMsg ( result , Status . COPY_PROCESS_DEFINITION_ERROR , srcProjectCode , targetProjectCode ,
String . join ( "," , failedProcessList ) ) ;
logger . error ( "Copy process definition error, srcProjectCode:{}, targetProjectCode:{}, failedProcessList:{}." ,
srcProjectCode , targetProjectCode , failedProcess ) ;
putMsg ( result , Status . COPY_PROCESS_DEFINITION_ERROR , srcProjectCode , targetProjectCode , failedProcess ) ;
} else {
putMsg ( result , Status . MOVE_PROCESS_DEFINITION_ERROR , srcProjectCode , targetProjectCode ,
String . join ( "," , failedProcessList ) ) ;
logger . error ( "Move process definition error, srcProjectCode:{}, targetProjectCode:{}, failedProcessList:{}." ,
srcProjectCode , targetProjectCode , failedProcess ) ;
putMsg ( result , Status . MOVE_PROCESS_DEFINITION_ERROR , srcProjectCode , targetProjectCode , failedProcess ) ;
}
} else {
logger . info ( "Batch {} process definition complete, srcProjectCode:{}, targetProjectCode:{}." , isCopy ? "copy" : "move" , srcProjectCode , targetProjectCode ) ;
putMsg ( result , Status . SUCCESS ) ;
}
}
@ -2133,19 +2203,24 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
ProcessDefinition processDefinition = processDefinitionMapper . queryByCode ( code ) ;
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 ) ) ;
} else {
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 ) ;
return result ;
}
int deleteLog = processDefinitionLogMapper . deleteByProcessDefinitionCodeAndVersion ( code , version ) ;
int deleteRelationLog = processTaskRelationLogMapper . deleteByCode ( code , version ) ;
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 ) ;
throw new ServiceException ( Status . DELETE_PROCESS_DEFINE_BY_CODE_ERROR ) ;
}
deleteOtherRelation ( project , result , processDefinition ) ;
logger . info ( "Delete process definition version complete, projectCode:{}, processDefinitionCode:{}, version:{}." , projectCode , code , version ) ;
putMsg ( result , Status . SUCCESS ) ;
}
return result ;
@ -2183,12 +2258,15 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
return result ;
}
if ( checkDescriptionLength ( description ) ) {
logger . warn ( "Parameter description is too long." ) ;
putMsg ( result , Status . DESCRIPTION_TOO_LONG_ERROR ) ;
return result ;
}
// check whether the new process define name exist
ProcessDefinition definition = processDefinitionMapper . verifyByDefineName ( project . getCode ( ) , name ) ;
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 ) ;
return result ;
}
@ -2197,6 +2275,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
if ( ! Constants . DEFAULT . equals ( tenantCode ) ) {
Tenant tenant = tenantMapper . queryByTenantCode ( tenantCode ) ;
if ( tenant = = null ) {
logger . error ( "Tenant does not exist." ) ;
putMsg ( result , Status . TENANT_NOT_EXIST ) ;
return result ;
}
@ -2206,6 +2285,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
try {
processDefinitionCode = CodeGenerateUtils . getInstance ( ) . genCode ( ) ;
} catch ( CodeGenerateException e ) {
logger . error ( "Generate process definition code error, projectCode:{}." , projectCode , e ) ;
putMsg ( result , Status . INTERNAL_SERVER_ERROR_ARGS ) ;
return result ;
}
@ -2215,6 +2295,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
processDefinition . setExecutionType ( executionType ) ;
result = createEmptyDagDefine ( loginUser , processDefinition ) ;
if ( result . get ( Constants . STATUS ) ! = Status . SUCCESS ) {
logger . error ( "Create empty process definition error." ) ;
return result ;
}
@ -2236,6 +2317,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
Map < String , Object > result = new HashMap < > ( ) ;
int insertVersion = processService . saveProcessDefine ( loginUser , processDefinition , Boolean . TRUE , Boolean . TRUE ) ;
if ( insertVersion = = 0 ) {
logger . error ( "Save process definition error, processDefinitionCode:{}." , processDefinition . getCode ( ) ) ;
putMsg ( result , 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 ( ) ;
scheduleObj . setProcessDefinitionCode ( processDefinition . getCode ( ) ) ;
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 ) ;
return result ;
}
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 ( ) ) ;
return result ;
}
@ -2322,6 +2404,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
return result ;
}
if ( checkDescriptionLength ( description ) ) {
logger . warn ( "Parameter description is too long." ) ;
putMsg ( result , Status . DESCRIPTION_TOO_LONG_ERROR ) ;
return result ;
}
@ -2329,6 +2412,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
if ( ! Constants . DEFAULT . equals ( tenantCode ) ) {
Tenant tenant = tenantMapper . queryByTenantCode ( tenantCode ) ;
if ( tenant = = null ) {
logger . error ( "Tenant does not exist." ) ;
putMsg ( result , Status . TENANT_NOT_EXIST ) ;
return result ;
}
@ -2338,11 +2422,14 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
ProcessDefinition processDefinition = processDefinitionMapper . queryByCode ( code ) ;
// check process definition exists
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 ) ) ;
return result ;
}
if ( processDefinition . getReleaseState ( ) = = ReleaseState . ONLINE ) {
// 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 ( ) ) ;
return result ;
}
@ -2350,6 +2437,8 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
// check whether the new process define name exist
ProcessDefinition definition = processDefinitionMapper . verifyByDefineName ( project . getCode ( ) , name ) ;
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 ) ;
return result ;
}
@ -2363,6 +2452,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
result = updateDagDefine ( loginUser , taskRelationList , processDefinition , processDefinitionDeepCopy ,
Lists . newArrayList ( ) , otherParamsJson ) ;
if ( result . get ( Constants . STATUS ) ! = Status . SUCCESS ) {
logger . error ( "Update process definition basic info error." ) ;
return result ;
}
@ -2446,11 +2536,13 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
ProcessDefinition processDefinition = processDefinitionMapper . queryByCode ( code ) ;
if ( processDefinition = = null ) {
logger . error ( "Process definition does not exist, code:{}." , code ) ;
putMsg ( result , Status . PROCESS_DEFINE_NOT_EXIST , String . valueOf ( code ) ) ;
return result ;
}
Schedule scheduleObj = scheduleMapper . queryByProcessDefinitionCode ( code ) ;
if ( scheduleObj = = null ) {
logger . error ( "Schedule cron does not exist, processDefinitionCode:{}." , code ) ;
putMsg ( result , Status . SCHEDULE_CRON_NOT_EXISTS , "processDefinitionCode:" + code ) ;
return result ;
}
@ -2459,6 +2551,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
List < ProcessTaskRelation > relationList =
processService . findRelationByCode ( code , processDefinition . getVersion ( ) ) ;
if ( CollectionUtils . isEmpty ( relationList ) ) {
logger . warn ( "Process definition has no task relation, processDefinitionCode:{}." , code ) ;
putMsg ( result , Status . PROCESS_DAG_IS_EMPTY ) ;
return result ;
}
@ -2470,12 +2563,13 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
processDefinition . setReleaseState ( releaseState ) ;
int updateProcess = processDefinitionMapper . updateById ( processDefinition ) ;
if ( updateProcess > 0 ) {
logger . info ( "set schedule offline, project code: {}, schedule id: {}, process definition code: {} " ,
projectCode , scheduleObj . getId ( ) , code ) ;
logger . info ( "Set schedule offline, projectCode:{}, processDefinitionCode:{}, scheduleId:{}. " ,
projectCode , code , scheduleObj . getId ( ) ) ;
// set status
scheduleObj . setReleaseState ( ReleaseState . OFFLINE ) ;
int updateSchedule = scheduleMapper . updateById ( scheduleObj ) ;
if ( updateSchedule = = 0 ) {
logger . error ( "Set schedule offline error, projectCode:{}, processDefinitionCode:{}, scheduleId:{}" , projectCode , code , scheduleObj . getId ( ) ) ;
putMsg ( result , Status . OFFLINE_SCHEDULE_ERROR ) ;
throw new ServiceException ( Status . OFFLINE_SCHEDULE_ERROR ) ;
}