Search in sources :

Example 1 with Command

use of org.activiti.engine.impl.interceptor.Command in project Activiti by Activiti.

the class JobQueryTest method setUp.

/**
   * Setup will create
   *   - 3 process instances, each with one timer, each firing at t1/t2/t3 + 1 hour (see process)
   *   - 1 message
   */
protected void setUp() throws Exception {
    super.setUp();
    this.commandExecutor = processEngineConfiguration.getCommandExecutor();
    deploymentId = repositoryService.createDeployment().addClasspathResource("org/activiti/engine/test/api/mgmt/timerOnTask.bpmn20.xml").deploy().getId();
    // Create proc inst that has timer that will fire on t1 + 1 hour
    Calendar startTime = Calendar.getInstance();
    startTime.set(Calendar.MILLISECOND, 0);
    Date t1 = startTime.getTime();
    processEngineConfiguration.getClock().setCurrentTime(t1);
    processInstanceIdOne = runtimeService.startProcessInstanceByKey("timerOnTask").getId();
    testStartTime = t1;
    timerOneFireTime = new Date(t1.getTime() + ONE_HOUR);
    // Create proc inst that has timer that will fire on t2 + 1 hour
    startTime.add(Calendar.HOUR_OF_DAY, 1);
    // t2 = t1 + 1 hour
    Date t2 = startTime.getTime();
    processEngineConfiguration.getClock().setCurrentTime(t2);
    processInstanceIdTwo = runtimeService.startProcessInstanceByKey("timerOnTask").getId();
    timerTwoFireTime = new Date(t2.getTime() + ONE_HOUR);
    // Create proc inst that has timer that will fire on t3 + 1 hour
    startTime.add(Calendar.HOUR_OF_DAY, 1);
    // t3 = t2 + 1 hour
    Date t3 = startTime.getTime();
    processEngineConfiguration.getClock().setCurrentTime(t3);
    processInstanceIdThree = runtimeService.startProcessInstanceByKey("timerOnTask").getId();
    timerThreeFireTime = new Date(t3.getTime() + ONE_HOUR);
    // Create one message
    messageId = commandExecutor.execute(new Command<String>() {

        public String execute(CommandContext commandContext) {
            MessageEntity message = new MessageEntity();
            commandContext.getJobEntityManager().send(message);
            return message.getId();
        }
    });
}
Also used : MessageEntity(org.activiti.engine.impl.persistence.entity.MessageEntity) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) Command(org.activiti.engine.impl.interceptor.Command) Calendar(java.util.Calendar) Date(java.util.Date)

Example 2 with Command

use of org.activiti.engine.impl.interceptor.Command in project Activiti by Activiti.

the class ProcessDefinitionInfoCache method get.

public ProcessDefinitionInfoCacheObject get(final String processDefinitionId) {
    ProcessDefinitionInfoCacheObject infoCacheObject = null;
    if (cache.containsKey(processDefinitionId)) {
        infoCacheObject = commandExecutor.execute(new Command<ProcessDefinitionInfoCacheObject>() {

            @Override
            public ProcessDefinitionInfoCacheObject execute(CommandContext commandContext) {
                ProcessDefinitionInfoEntityManager infoEntityManager = commandContext.getProcessDefinitionInfoEntityManager();
                ObjectMapper objectMapper = commandContext.getProcessEngineConfiguration().getObjectMapper();
                ProcessDefinitionInfoCacheObject cacheObject = cache.get(processDefinitionId);
                ProcessDefinitionInfoEntity infoEntity = infoEntityManager.findProcessDefinitionInfoByProcessDefinitionId(processDefinitionId);
                if (infoEntity != null && infoEntity.getRevision() != cacheObject.getRevision()) {
                    cacheObject.setRevision(infoEntity.getRevision());
                    if (infoEntity.getInfoJsonId() != null) {
                        byte[] infoBytes = infoEntityManager.findInfoJsonById(infoEntity.getInfoJsonId());
                        try {
                            ObjectNode infoNode = (ObjectNode) objectMapper.readTree(infoBytes);
                            cacheObject.setInfoNode(infoNode);
                        } catch (Exception e) {
                            throw new ActivitiException("Error reading json info node for process definition " + processDefinitionId, e);
                        }
                    }
                } else if (infoEntity == null) {
                    cacheObject.setRevision(0);
                    cacheObject.setInfoNode(objectMapper.createObjectNode());
                }
                return cacheObject;
            }
        });
    }
    return infoCacheObject;
}
Also used : ProcessDefinitionInfoEntityManager(org.activiti.engine.impl.persistence.entity.ProcessDefinitionInfoEntityManager) ActivitiException(org.activiti.engine.ActivitiException) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Command(org.activiti.engine.impl.interceptor.Command) ProcessDefinitionInfoEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionInfoEntity) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ActivitiException(org.activiti.engine.ActivitiException)

Aggregations

Command (org.activiti.engine.impl.interceptor.Command)2 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 ActivitiException (org.activiti.engine.ActivitiException)1 MessageEntity (org.activiti.engine.impl.persistence.entity.MessageEntity)1 ProcessDefinitionInfoEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionInfoEntity)1 ProcessDefinitionInfoEntityManager (org.activiti.engine.impl.persistence.entity.ProcessDefinitionInfoEntityManager)1