Exemplo n.º 1
0
        public override void execute(BatchJobConfiguration configuration, ExecutionEntity execution, CommandContext commandContext, string tenantId)
        {
            ByteArrayEntity configurationEntity = commandContext.DbEntityManager.selectById(typeof(ByteArrayEntity), configuration.ConfigurationByteArrayId);

            DeleteProcessInstanceBatchConfiguration batchConfiguration = readConfiguration(configurationEntity.Bytes);

            bool initialLegacyRestrictions = commandContext.RestrictUserOperationLogToAuthenticatedUsers;

            commandContext.disableUserOperationLog();
            commandContext.RestrictUserOperationLogToAuthenticatedUsers = true;
            try
            {
                RuntimeService runtimeService = commandContext.ProcessEngineConfiguration.RuntimeService;
                if (batchConfiguration.FailIfNotExists)
                {
                    runtimeService.deleteProcessInstances(batchConfiguration.Ids, batchConfiguration.deleteReason, batchConfiguration.SkipCustomListeners, true, batchConfiguration.SkipSubprocesses);
                }
                else
                {
                    runtimeService.deleteProcessInstancesIfExists(batchConfiguration.Ids, batchConfiguration.deleteReason, batchConfiguration.SkipCustomListeners, true, batchConfiguration.SkipSubprocesses);
                }
            }
            finally
            {
                commandContext.enableUserOperationLog();
                commandContext.RestrictUserOperationLogToAuthenticatedUsers = initialLegacyRestrictions;
            }

            commandContext.ByteArrayManager.delete(configurationEntity);
        }
Exemplo n.º 2
0
        public virtual void deployAndCompleteProcesses()
        {
            ProcessDefinition sourceDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);

            processInstance  = engineRule.RuntimeService.startProcessInstanceById(sourceDefinition.Id);
            processInstance2 = engineRule.RuntimeService.startProcessInstanceById(sourceDefinition.Id);

            IList <string> processInstanceIds = Arrays.asList(new string[] { processInstance.Id, processInstance2.Id });

            runtimeService.deleteProcessInstances(processInstanceIds, null, false, false);

            historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.Id).singleResult();

            historicProcessInstance2 = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance2.Id).singleResult();
        }
Exemplo n.º 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void bulkHistoryDeleteWithDisabledDmn()
        public virtual void bulkHistoryDeleteWithDisabledDmn()
        {
            BpmnModelInstance model = Bpmn.createExecutableProcess("someProcess").startEvent().userTask("userTask").endEvent().done();

            testRule.deploy(model);
            IList <string> ids = prepareHistoricProcesses("someProcess");

            runtimeService.deleteProcessInstances(ids, null, true, true);

            //when
            historyService.deleteHistoricProcessInstancesBulk(ids);

            //then
            assertEquals(0, historyService.createHistoricProcessInstanceQuery().processDefinitionKey("someProcess").count());
        }
Exemplo n.º 4
0
        public virtual void testFindHistoricProcessInstanceIdsForCleanup()
        {
            engineRule.ProcessEngineConfiguration.CommandExecutorTxRequired.execute(new CommandAnonymousInnerClass(this));
            //start processes
            IList <string> ids = prepareHistoricProcesses(ONE_TASK_PROCESS, processInstancesOfProcess1Count);

            ((IList <string>)ids).AddRange(prepareHistoricProcesses(TWO_TASKS_PROCESS, processInstancesOfProcess2Count));

            runtimeService.deleteProcessInstances(ids, null, true, true);

            //some days passed
            ClockUtil.CurrentTime = DateUtils.addDays(DateTime.Now, daysPassedAfterProcessEnd);

            engineRule.ProcessEngineConfiguration.CommandExecutorTxRequired.execute(new CommandAnonymousInnerClass2(this));
        }
Exemplo n.º 5
0
        private void prepareHistoricProcesses(string businessKey)
        {
            DateTime oldCurrentTime = ClockUtil.CurrentTime;

            ClockUtil.CurrentTime = DateUtils.addDays(DateTime.Now, -6);

            IList <string> processInstanceIds = new List <string>();

            for (int i = 0; i < 5; i++)
            {
                ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(businessKey);
                processInstanceIds.Add(processInstance.Id);
            }
            runtimeService.deleteProcessInstances(processInstanceIds, null, true, true);

            ClockUtil.CurrentTime = oldCurrentTime;
        }
Exemplo n.º 6
0
        private void prepareHistoricProcesses(int instanceCount)
        {
            DateTime       oldCurrentTime     = ClockUtil.CurrentTime;
            IList <string> processInstanceIds = new List <string>();

            ClockUtil.CurrentTime = DateUtils.addDays(DateTime.Now, -6);
            for (int i = 0; i < instanceCount; i++)
            {
                ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
                processInstanceIds.Add(processInstance.Id);
            }
            IList <ProcessDefinition> processDefinitions = engineRule.RepositoryService.createProcessDefinitionQuery().list();

            assertEquals(1, processDefinitions.Count);
            engineRule.RepositoryService.updateProcessDefinitionHistoryTimeToLive(processDefinitions[0].Id, 5);

            runtimeService.deleteProcessInstances(processInstanceIds, null, true, true);
            ClockUtil.CurrentTime = oldCurrentTime;
        }
Exemplo n.º 7
0
        public virtual void testCleanupHistory()
        {
            //given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.List<String> ids = prepareHistoricProcesses();
            IList <string> ids = prepareHistoricProcesses();

            runtimeService.deleteProcessInstances(ids, null, true, true);

            // when
            authRule.init(scenario).bindResource("processDefinition", "oneTaskProcess").withUser("demo").start();

            //when
            historyService.deleteHistoricProcessInstancesBulk(ids);

            if (authRule.assertScenario(scenario))
            {
                assertEquals(0, historyService.createHistoricProcessInstanceQuery().processDefinitionKey(ONE_TASK_PROCESS).count());
            }
        }
Exemplo n.º 8
0
        protected internal virtual void prepareProcessInstances(string key, int daysInThePast, int?historyTimeToLive, int instanceCount, string tenantId)
        {
            IList <ProcessDefinition> processDefinitions = null;

            if (string.ReferenceEquals(tenantId, null))
            {
                processDefinitions = repositoryService.createProcessDefinitionQuery().processDefinitionKey(key).withoutTenantId().list();
            }
            else
            {
                processDefinitions = repositoryService.createProcessDefinitionQuery().processDefinitionKey(key).tenantIdIn(tenantId).list();
            }
            assertEquals(1, processDefinitions.Count);
            repositoryService.updateProcessDefinitionHistoryTimeToLive(processDefinitions[0].Id, historyTimeToLive);

            DateTime oldCurrentTime = ClockUtil.CurrentTime;

            ClockUtil.CurrentTime = DateUtils.addDays(oldCurrentTime, daysInThePast);

            IList <string> processInstanceIds = new List <string>();

            {
                for (int i = 0; i < instanceCount; i++)
                {
                    string processInstanceId = null;
                    if (string.ReferenceEquals(tenantId, null))
                    {
                        processInstanceId = runtimeService.createProcessInstanceByKey(PROCESS_DEFINITION_KEY).processDefinitionWithoutTenantId().execute().Id;
                    }
                    else
                    {
                        processInstanceId = runtimeService.createProcessInstanceByKey(PROCESS_DEFINITION_KEY).processDefinitionTenantId(tenantId).execute().Id;
                    }
                    processInstanceIds.Add(processInstanceId);
                }
            }
            runtimeService.deleteProcessInstances(processInstanceIds, null, true, true);

            ClockUtil.CurrentTime = oldCurrentTime;
        }
Exemplo n.º 9
0
        protected internal virtual void prepareProcessInstances(string key, int daysInThePast, int?historyTimeToLive, int instanceCount)
        {
            IList <ProcessDefinition> processDefinitions = repositoryService.createProcessDefinitionQuery().processDefinitionKey(key).list();

            assertEquals(1, processDefinitions.Count);
            repositoryService.updateProcessDefinitionHistoryTimeToLive(processDefinitions[0].Id, historyTimeToLive);

            DateTime oldCurrentTime = ClockUtil.CurrentTime;

            ClockUtil.CurrentTime = DateUtils.addDays(oldCurrentTime, daysInThePast);

            IList <string> processInstanceIds = new List <string>();

            for (int i = 0; i < instanceCount; i++)
            {
                ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(key);
                processInstanceIds.Add(processInstance.Id);
            }
            runtimeService.deleteProcessInstances(processInstanceIds, null, true, true);

            ClockUtil.CurrentTime = oldCurrentTime;
        }