@ -84,6 +84,7 @@ import java.util.ArrayList;
import java.util.Arrays ;
import java.util.Calendar ;
import java.util.Date ;
import java.util.EnumMap ;
import java.util.HashMap ;
import java.util.HashSet ;
import java.util.List ;
@ -167,7 +168,7 @@ public class ProcessService {
@Transactional ( rollbackFor = Exception . class )
public ProcessInstance handleCommand ( Logger logger , String host , int validThreadNum , Command command ) {
ProcessInstance processInstance = constructProcessInstance ( command , host ) ;
//cannot construct process instance, return null;
// cannot construct process instance, return null
if ( processInstance = = null ) {
logger . error ( "scan command, command parameter is error: {}" , command ) ;
moveToErrorCommand ( command , "process instance is null" ) ;
@ -259,7 +260,7 @@ public class ProcessService {
* /
public Boolean verifyIsNeedCreateCommand ( Command command ) {
Boolean isNeedCreate = true ;
Map < CommandType , Integer > cmdTypeMap = new HashMap < CommandType , Integer > ( ) ;
Enum Map< CommandType , Integer > cmdTypeMap = new EnumMap < > ( CommandType . class ) ;
cmdTypeMap . put ( CommandType . REPEAT_RUNNING , 1 ) ;
cmdTypeMap . put ( CommandType . RECOVER_SUSPENDED_PROCESS , 1 ) ;
cmdTypeMap . put ( CommandType . START_FAILURE_TASK_PROCESS , 1 ) ;
@ -296,9 +297,6 @@ public class ProcessService {
/ * *
* get task node list by definitionId
*
* @param defineId
* @return
* /
public List < TaskNode > getTaskNodeListByDefinitionId ( Integer defineId ) {
ProcessDefinition processDefinition = processDefineMapper . selectById ( defineId ) ;
@ -435,7 +433,7 @@ public class ProcessService {
List < TaskNode > taskNodeList = processData . getTasks ( ) ;
if ( taskNodeList ! = null & & taskNodeList . size ( ) > 0 ) {
if ( taskNodeList ! = null & & ! taskNodeList . isEmpty ( ) ) {
for ( TaskNode taskNode : taskNodeList ) {
String parameter = taskNode . getParams ( ) ;
@ -514,11 +512,9 @@ public class ProcessService {
* /
private Date getScheduleTime ( Command command , Map < String , String > cmdParam ) {
Date scheduleTime = command . getScheduleTime ( ) ;
if ( scheduleTime = = null ) {
if ( cmdParam ! = null & & cmdParam . containsKey ( CMDPARAM_COMPLEMENT_DATA_START_DATE ) ) {
if ( scheduleTime = = null & & cmdParam ! = null & & cmdParam . containsKey ( CMDPARAM_COMPLEMENT_DATA_START_DATE ) ) {
scheduleTime = DateUtils . stringToDate ( cmdParam . get ( CMDPARAM_COMPLEMENT_DATA_START_DATE ) ) ;
}
}
return scheduleTime ;
}
@ -714,7 +710,7 @@ public class ProcessService {
// generate one new process instance
processInstance = generateNewProcessInstance ( processDefinition , command , cmdParam ) ;
}
if ( ! checkCmdParam ( command , cmdParam ) ) {
if ( Boolean . FALSE . equals ( checkCmdParam ( command , cmdParam ) ) ) {
logger . error ( "command parameter check failed!" ) ;
return null ;
}
@ -922,13 +918,12 @@ public class ProcessService {
* /
private void initTaskInstance ( TaskInstance taskInstance ) {
if ( ! taskInstance . isSubProcess ( ) ) {
if ( taskInstance . getState ( ) . typeIsCancel ( ) | | taskInstance . getState ( ) . typeIsFailure ( ) ) {
if ( ! taskInstance . isSubProcess ( )
& & ( taskInstance . getState ( ) . typeIsCancel ( ) | | taskInstance . getState ( ) . typeIsFailure ( ) ) ) {
taskInstance . setFlag ( Flag . NO ) ;
updateTaskInstance ( taskInstance ) ;
return ;
}
}
taskInstance . setState ( ExecutionStatus . SUBMITTED_SUCCESS ) ;
updateTaskInstance ( taskInstance ) ;
}
@ -1049,10 +1044,6 @@ public class ProcessService {
/ * *
* complement data needs transform parent parameter to child .
*
* @param instanceMap
* @param parentProcessInstance
* @return
* /
private String getSubWorkFlowParam ( ProcessInstanceMap instanceMap , ProcessInstance parentProcessInstance ) {
// set sub work process command
@ -1071,11 +1062,6 @@ public class ProcessService {
/ * *
* create sub work process command
*
* @param parentProcessInstance
* @param childInstance
* @param instanceMap
* @param task
* /
public Command createSubProcessCommand ( ProcessInstance parentProcessInstance ,
ProcessInstance childInstance ,
@ -1105,8 +1091,6 @@ public class ProcessService {
/ * *
* initialize sub work flow state
* child instance state would be initialized when ' recovery from pause / stop / failure '
*
* @param childInstance
* /
private void initSubInstanceState ( ProcessInstance childInstance ) {
if ( childInstance ! = null ) {
@ -1119,9 +1103,6 @@ public class ProcessService {
* get sub work flow command type
* child instance exist : child command = fatherCommand
* child instance not exists : child command = fatherCommand [ 0 ]
*
* @param parentProcessInstance
* @return
* /
private CommandType getSubCommandType ( ProcessInstance parentProcessInstance , ProcessInstance childInstance ) {
CommandType commandType = parentProcessInstance . getCommandType ( ) ;
@ -1577,7 +1558,7 @@ public class ProcessService {
if ( intList = = null ) {
return new ArrayList < > ( ) ;
}
List < String > result = new ArrayList < String > ( intList . size ( ) ) ;
List < String > result = new ArrayList < > ( intList . size ( ) ) ;
for ( Integer intVar : intList ) {
result . add ( String . valueOf ( intVar ) ) ;
}
@ -1728,7 +1709,7 @@ public class ProcessService {
* /
public CycleDependency getCycleDependency ( int masterId , int processDefinitionId , Date scheduledFireTime ) throws Exception {
List < CycleDependency > list = getCycleDependencies ( masterId , new int [ ] { processDefinitionId } , scheduledFireTime ) ;
return list . size ( ) > 0 ? list . get ( 0 ) : null ;
return ! list . isEmpty ( ) ? list . get ( 0 ) : null ;
}
@ -1742,7 +1723,7 @@ public class ProcessService {
* @throws Exception if error throws Exception
* /
public List < CycleDependency > getCycleDependencies ( int masterId , int [ ] ids , Date scheduledFireTime ) throws Exception {
List < CycleDependency > cycleDependencyList = new ArrayList < CycleDependency > ( ) ;
List < CycleDependency > cycleDependencyList = new ArrayList < > ( ) ;
if ( null = = ids | | ids . length = = 0 ) {
logger . warn ( "ids[] is empty!is invalid!" ) ;
return cycleDependencyList ;
@ -1769,14 +1750,10 @@ public class ProcessService {
}
Calendar calendar = Calendar . getInstance ( ) ;
switch ( cycleEnum ) {
/ * case MINUTE :
calendar . add ( Calendar . MINUTE , - 61 ) ; * /
case HOUR :
calendar . add ( Calendar . HOUR , - 25 ) ;
break ;
case DAY :
calendar . add ( Calendar . DATE , - 32 ) ;
break ;
case WEEK :
calendar . add ( Calendar . DATE , - 32 ) ;
break ;
@ -1784,7 +1761,8 @@ public class ProcessService {
calendar . add ( Calendar . MONTH , - 13 ) ;
break ;
default :
logger . warn ( "Dependent process definition's cycleEnum is {},not support!!" , cycleEnum . name ( ) ) ;
String cycleName = cycleEnum . name ( ) ;
logger . warn ( "Dependent process definition's cycleEnum is {},not support!!" , cycleName ) ;
continue ;
}
Date start = calendar . getTime ( ) ;
@ -1794,7 +1772,7 @@ public class ProcessService {
} else {
list = CronUtils . getFireDateList ( start , scheduledFireTime , depCronExpression ) ;
}
if ( list . size ( ) > = 1 ) {
if ( ! list . isEmpty ( ) ) {
start = list . get ( list . size ( ) - 1 ) ;
CycleDependency dependency = new CycleDependency ( depSchedule . getProcessDefinitionId ( ) , start , CronUtils . getExpirationTime ( start , cycleEnum ) , cycleEnum ) ;
cycleDependencyList . add ( dependency ) ;
@ -1867,6 +1845,7 @@ public class ProcessService {
/ * *
* query project name and user name by processInstanceId .
*
* @param processInstanceId processInstanceId
* @return projectName and userName
* /
@ -1939,30 +1918,27 @@ public class ProcessService {
* @return unauthorized udf function list
* /
public < T > List < T > listUnauthorized ( int userId , T [ ] needChecks , AuthorizationType authorizationType ) {
List < T > resultList = new ArrayList < T > ( ) ;
List < T > resultList = new ArrayList < > ( ) ;
if ( Objects . nonNull ( needChecks ) & & needChecks . length > 0 ) {
Set < T > originResSet = new HashSet < T > ( Arrays . asList ( needChecks ) ) ;
Set < T > originResSet = new HashSet < > ( Arrays . asList ( needChecks ) ) ;
switch ( authorizationType ) {
case RESOURCE_FILE_ID :
Set < Integer > authorizedResourceFiles = resourceMapper . listAuthorizedResourceById ( userId , needChecks ) . stream ( ) . map ( t - > t . getId ( ) ) . collect ( toSet ( ) ) ;
case UDF_FILE :
Set < Integer > authorizedResourceFiles = resourceMapper . listAuthorizedResourceById ( userId , needChecks ) . stream ( ) . map ( Resource : : getId ) . collect ( toSet ( ) ) ;
originResSet . removeAll ( authorizedResourceFiles ) ;
break ;
case RESOURCE_FILE_NAME :
Set < String > authorizedResources = resourceMapper . listAuthorizedResource ( userId , needChecks ) . stream ( ) . map ( t - > t . getFullName ( ) ) . collect ( toSet ( ) ) ;
Set < String > authorizedResources = resourceMapper . listAuthorizedResource ( userId , needChecks ) . stream ( ) . map ( Resource : : getFullName ) . collect ( toSet ( ) ) ;
originResSet . removeAll ( authorizedResources ) ;
break ;
case UDF_FILE :
Set < Integer > authorizedUdfFiles = resourceMapper . listAuthorizedResourceById ( userId , needChecks ) . stream ( ) . map ( t - > t . getId ( ) ) . collect ( toSet ( ) ) ;
originResSet . removeAll ( authorizedUdfFiles ) ;
break ;
case DATASOURCE :
Set < Integer > authorizedDatasources = dataSourceMapper . listAuthorizedDataSource ( userId , needChecks ) . stream ( ) . map ( t - > t . getId ( ) ) . collect ( toSet ( ) ) ;
Set < Integer > authorizedDatasources = dataSourceMapper . listAuthorizedDataSource ( userId , needChecks ) . stream ( ) . map ( DataSource : : getId ) . collect ( toSet ( ) ) ;
originResSet . removeAll ( authorizedDatasources ) ;
break ;
case UDF :
Set < Integer > authorizedUdfs = udfFuncMapper . listAuthorizedUdfFunc ( userId , needChecks ) . stream ( ) . map ( t - > t . getId ( ) ) . collect ( toSet ( ) ) ;
Set < Integer > authorizedUdfs = udfFuncMapper . listAuthorizedUdfFunc ( userId , needChecks ) . stream ( ) . map ( UdfFunc : : getId ) . collect ( toSet ( ) ) ;
originResSet . removeAll ( authorizedUdfs ) ;
break ;
default :
@ -2007,9 +1983,6 @@ public class ProcessService {
/ * *
* format task app id in task instance
*
* @param taskInstance
* @return
* /
public String formatTaskAppId ( TaskInstance taskInstance ) {
ProcessDefinition definition = this . findProcessDefineById ( taskInstance . getProcessDefinitionId ( ) ) ;