@Override public long getNumberOfProcessDataInstances(final long processInstanceId) throws ProcessInstanceNotFoundException { try { return getNumberOfDataInstancesOfContainer(processInstanceId, DataInstanceContainer.PROCESS_INSTANCE); } catch (final SBonitaException e) { throw new ProcessInstanceNotFoundException(e); } }
/** * Constructs a new exception and the message with the identifier of the process instance. * * @param processInstanceId * The identifier of the process instance */ public ProcessInstanceNotFoundException(final long processInstanceId) { super("No process instance found !!"); setProcessInstanceIdOnContext(processInstanceId); }
@Test public void merge_stack_when_no_cause() { ProcessInstanceNotFoundException cause = new ProcessInstanceNotFoundException("the process"); ServerWrappedException e = new ServerWrappedException(cause); ServerWrappedException newE = StackTraceTransformer.mergeStackTraces(e); assertEquals("the process", cause.getMessage()); assertEquals(cause, newE.getCause()); }
@Override public long getNumberOfProcessDataInstances(final long processInstanceId) throws ProcessInstanceNotFoundException { try { return getNumberOfDataInstancesOfContainer(processInstanceId, DataInstanceContainer.PROCESS_INSTANCE); } catch (final SBonitaException e) { throw new ProcessInstanceNotFoundException(e); } }
/** * Constructs a new exception and the message with the identifier of the process instance. * * @param processInstanceId * The identifier of the process instance */ public ProcessInstanceNotFoundException(final long processInstanceId) { super("No process instance found !!"); setProcessInstanceIdOnContext(processInstanceId); }
@Override public long getProcessInstanceIdFromActivityInstanceId(final long activityInstanceId) throws ProcessInstanceNotFoundException { final TenantServiceAccessor tenantAccessor = getTenantAccessor(); try { final SActivityInstance sActivityInstance = getSActivityInstance(activityInstanceId); return sActivityInstance.getRootContainerId(); } catch (final SActivityInstanceNotFoundException e) { logInstanceNotFound(tenantAccessor, e); throw new ProcessInstanceNotFoundException(e); } catch (final SBonitaException e) { logError(tenantAccessor, e); throw new ProcessInstanceNotFoundException(e); } }
@Override public long getProcessInstanceIdFromActivityInstanceId(final long activityInstanceId) throws ProcessInstanceNotFoundException { final TenantServiceAccessor tenantAccessor = getTenantAccessor(); try { final SActivityInstance sActivityInstance = getSActivityInstance(activityInstanceId); return sActivityInstance.getRootContainerId(); } catch (final SActivityInstanceNotFoundException e) { logInstanceNotFound(tenantAccessor, e); throw new ProcessInstanceNotFoundException(e); } catch (final SBonitaException e) { logError(tenantAccessor, e); throw new ProcessInstanceNotFoundException(e); } }
@Override public ProcessInstance getProcessInstance(final long processInstanceId) throws ProcessInstanceNotFoundException { final TenantServiceAccessor tenantAccessor = getTenantAccessor(); final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); try { final SProcessInstance sProcessInstance = getSProcessInstance(processInstanceId); return ModelConvertor.toProcessInstances(Collections.singletonList(sProcessInstance), processDefinitionService).get(0); } catch (final SProcessInstanceNotFoundException notFound) { throw new ProcessInstanceNotFoundException(notFound); } catch (final SBonitaException e) { throw new RetrieveException(e); } }
@Override public ProcessInstance getProcessInstance(final long processInstanceId) throws ProcessInstanceNotFoundException { final TenantServiceAccessor tenantAccessor = getTenantAccessor(); final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); try { final SProcessInstance sProcessInstance = getSProcessInstance(processInstanceId); return ModelConvertor.toProcessInstances(Collections.singletonList(sProcessInstance), processDefinitionService).get(0); } catch (final SProcessInstanceNotFoundException notFound) { throw new ProcessInstanceNotFoundException(notFound); } catch (final SBonitaException e) { throw new RetrieveException(e); } }
boolean isArchivedProcessInitiator(long userId, long processInstanceId) throws ProcessInstanceNotFoundException { final ProcessInstanceService processInstanceService = getTenantServiceAccessor().getProcessInstanceService(); final List<OrderByOption> orderByOptions = Arrays.asList( new OrderByOption(SAProcessInstance.class, ArchivedProcessInstancesSearchDescriptor.ARCHIVE_DATE, OrderByType.DESC), new OrderByOption(SAProcessInstance.class, ArchivedProcessInstancesSearchDescriptor.END_DATE, OrderByType.DESC)); final List<FilterOption> filterOptions = Collections.singletonList(new FilterOption(SAProcessInstance.class, ArchivedProcessInstancesSearchDescriptor.SOURCE_OBJECT_ID, processInstanceId)); final QueryOptions queryOptions = new QueryOptions(0, 1, orderByOptions, filterOptions, null); final List<SAProcessInstance> saProcessInstances; try { saProcessInstances = processInstanceService.searchArchivedProcessInstances(queryOptions); } catch (SBonitaReadException e) { throw new RetrieveException(e); } if (saProcessInstances.isEmpty()) { throw new ProcessInstanceNotFoundException(processInstanceId); } return userId == (saProcessInstances.get(0).getStartedBy()); }
boolean isArchivedProcessInitiator(long userId, long processInstanceId) throws ProcessInstanceNotFoundException { final ProcessInstanceService processInstanceService = getTenantServiceAccessor().getProcessInstanceService(); final List<OrderByOption> orderByOptions = Arrays.asList( new OrderByOption(SAProcessInstance.class, ArchivedProcessInstancesSearchDescriptor.ARCHIVE_DATE, OrderByType.DESC), new OrderByOption(SAProcessInstance.class, ArchivedProcessInstancesSearchDescriptor.END_DATE, OrderByType.DESC)); final List<FilterOption> filterOptions = Collections.singletonList(new FilterOption(SAProcessInstance.class, ArchivedProcessInstancesSearchDescriptor.SOURCE_OBJECT_ID, processInstanceId)); final QueryOptions queryOptions = new QueryOptions(0, 1, orderByOptions, filterOptions, null); final List<SAProcessInstance> saProcessInstances; try { saProcessInstances = processInstanceService.searchArchivedProcessInstances(queryOptions); } catch (SBonitaReadException e) { throw new RetrieveException(e); } if (saProcessInstances.isEmpty()) { throw new ProcessInstanceNotFoundException(processInstanceId); } return userId == (saProcessInstances.get(0).getStartedBy()); }
@Override public Map<String, Serializable> getProcessInstanceExecutionContext(long processInstanceId) throws ProcessInstanceNotFoundException, ExpressionEvaluationException { TenantServiceAccessor tenantAccessor = getTenantAccessor(); try { SProcessInstance processInstance = getProcessInstanceService(tenantAccessor).getProcessInstance(processInstanceId); if (processInstance == null) { throw new ProcessInstanceNotFoundException("Process Instance not found " + processInstanceId); } SProcessDefinition processDefinition = tenantAccessor.getProcessDefinitionService().getProcessDefinition(processInstance.getProcessDefinitionId()); final SExpressionContext expressionContext = createExpressionContext(processInstanceId, processDefinition, CONTAINER_TYPE_PROCESS_INSTANCE, null); return evaluateContext(tenantAccessor.getExpressionResolverService(), expressionContext, processDefinition.getContext()); } catch (SProcessInstanceNotFoundException | SBonitaReadException | SProcessInstanceReadException | SProcessDefinitionNotFoundException e) { throw new ProcessInstanceNotFoundException(e); } catch (SInvalidExpressionException | SExpressionEvaluationException | SExpressionDependencyMissingException | SExpressionTypeUnknownException e) { throw new ExpressionEvaluationException(e); } }
@Override public Map<String, Serializable> getProcessInstanceExecutionContext(long processInstanceId) throws ProcessInstanceNotFoundException, ExpressionEvaluationException { TenantServiceAccessor tenantAccessor = getTenantAccessor(); try { SProcessInstance processInstance = getProcessInstanceService(tenantAccessor).getProcessInstance(processInstanceId); if (processInstance == null) { throw new ProcessInstanceNotFoundException("Process Instance not found " + processInstanceId); } SProcessDefinition processDefinition = tenantAccessor.getProcessDefinitionService().getProcessDefinition(processInstance.getProcessDefinitionId()); final SExpressionContext expressionContext = createExpressionContext(processInstanceId, processDefinition, CONTAINER_TYPE_PROCESS_INSTANCE, null); return evaluateContext(tenantAccessor.getExpressionResolverService(), expressionContext, processDefinition.getContext()); } catch (SProcessInstanceNotFoundException | SBonitaReadException | SProcessInstanceReadException | SProcessDefinitionNotFoundException e) { throw new ProcessInstanceNotFoundException(e); } catch (SInvalidExpressionException | SExpressionEvaluationException | SExpressionDependencyMissingException | SExpressionTypeUnknownException e) { throw new ExpressionEvaluationException(e); } }
@Override public Map<String, Serializable> getArchivedProcessInstanceExecutionContext(long archivedProcessInstanceId) throws ProcessInstanceNotFoundException, ExpressionEvaluationException { TenantServiceAccessor tenantAccessor = getTenantAccessor(); try { SAProcessInstance processInstance = getProcessInstanceService(tenantAccessor).getArchivedProcessInstance(archivedProcessInstanceId); if (processInstance == null) { throw new ProcessInstanceNotFoundException("Archived Process Instance not found " + archivedProcessInstanceId); } SProcessDefinition processDefinition = tenantAccessor.getProcessDefinitionService().getProcessDefinition(processInstance.getProcessDefinitionId()); final SExpressionContext expressionContext = createExpressionContext(processInstance.getSourceObjectId(), processDefinition, CONTAINER_TYPE_PROCESS_INSTANCE, processInstance.getArchiveDate()); return evaluateContext(tenantAccessor.getExpressionResolverService(), expressionContext, processDefinition.getContext()); } catch (SBonitaReadException | SProcessInstanceReadException | SProcessDefinitionNotFoundException e) { throw new ProcessInstanceNotFoundException(e); } catch (SInvalidExpressionException | SExpressionEvaluationException | SExpressionDependencyMissingException | SExpressionTypeUnknownException e) { throw new ExpressionEvaluationException(e); } }
@Override public Map<String, Serializable> getArchivedProcessInstanceExecutionContext(long archivedProcessInstanceId) throws ProcessInstanceNotFoundException, ExpressionEvaluationException { TenantServiceAccessor tenantAccessor = getTenantAccessor(); try { SAProcessInstance processInstance = getProcessInstanceService(tenantAccessor).getArchivedProcessInstance(archivedProcessInstanceId); if (processInstance == null) { throw new ProcessInstanceNotFoundException("Archived Process Instance not found " + archivedProcessInstanceId); } SProcessDefinition processDefinition = tenantAccessor.getProcessDefinitionService().getProcessDefinition(processInstance.getProcessDefinitionId()); final SExpressionContext expressionContext = createExpressionContext(processInstance.getSourceObjectId(), processDefinition, CONTAINER_TYPE_PROCESS_INSTANCE, processInstance.getArchiveDate()); return evaluateContext(tenantAccessor.getExpressionResolverService(), expressionContext, processDefinition.getContext()); } catch (SBonitaReadException | SProcessInstanceReadException | SProcessDefinitionNotFoundException e) { throw new ProcessInstanceNotFoundException(e); } catch (SInvalidExpressionException | SExpressionEvaluationException | SExpressionDependencyMissingException | SExpressionTypeUnknownException e) { throw new ExpressionEvaluationException(e); } }
@Test public void merge_stack_reduce_stack_length() throws Exception { ProcessInstanceNotFoundException cause3 = new ProcessInstanceNotFoundException("the process"); BonitaRuntimeException cause2 = new BonitaRuntimeException("org.Unknown", cause3); IllegalStateException cause = new IllegalStateException(cause2); ServerWrappedException e = new ServerWrappedException(cause); cause.printStackTrace(); ServerWrappedException newE = StackTraceTransformer.mergeStackTraces(e); newE.getCause().printStackTrace(); noDuplicate(newE.getCause()); }
@Test public void merge_stack_keep_message_of_cause() { ProcessInstanceNotFoundException cause3 = new ProcessInstanceNotFoundException("the process"); BonitaRuntimeException cause2 = new BonitaRuntimeException("org.Unknown", cause3); IllegalStateException cause = new IllegalStateException(cause2); ServerWrappedException e = new ServerWrappedException(cause); ServerWrappedException newE = StackTraceTransformer.mergeStackTraces(e); assertTrue(containsMessage(newE.getCause().getStackTrace(), "org.Unknown")); assertTrue(containsMessage(newE.getCause().getStackTrace(), "the process")); }
@Test public void merge_stack_work_even_with_security_restriction() { ProcessInstanceNotFoundException cause3 = new ProcessInstanceNotFoundException("the process"); BonitaRuntimeException cause2 = new BonitaRuntimeException("org.Unknown", cause3); IllegalStateException cause = new IllegalStateException(cause2); ServerWrappedException e = new ServerWrappedException(cause); Field field = StackTraceTransformer.field; StackTraceTransformer.field = null; ServerWrappedException newE = StackTraceTransformer.mergeStackTraces(e); StackTraceTransformer.field = field; assertTrue(containsMessage(newE.getCause().getStackTrace(), "org.Unknown")); assertTrue(containsMessage(newE.getCause().getStackTrace(), "the process")); }
@Test public void merge_stack_keep_stack_of_cause() { ProcessInstanceNotFoundException cause3 = new ProcessInstanceNotFoundException("the process"); BonitaRuntimeException cause2 = new BonitaRuntimeException("org.Unknown", cause3); IllegalStateException cause = new IllegalStateException(cause2); ServerWrappedException e = new ServerWrappedException(cause); ServerWrappedException newE = StackTraceTransformer.mergeStackTraces(e); assertTrue(containsStack(newE.getCause().getStackTrace(), "BonitaRuntimeException")); assertTrue(containsStack(newE.getCause().getStackTrace(), "ProcessInstanceNotFoundException")); }
@Override public void cancelProcessInstance(final long processInstanceId) throws ProcessInstanceNotFoundException, UpdateException { final TenantServiceAccessor tenantAccessor = getTenantAccessor(); final LockService lockService = tenantAccessor.getLockService(); final ProcessInstanceInterruptor processInstanceInterruptor = tenantAccessor.getProcessInstanceInterruptor(); // lock process execution final String objectType = SFlowElementsContainerType.PROCESS.name(); BonitaLock lock = null; try { lock = lockService.lock(processInstanceId, objectType, tenantAccessor.getTenantId()); processInstanceInterruptor.interruptProcessInstance(processInstanceId, SStateCategory.CANCELLING); } catch (final SProcessInstanceNotFoundException spinfe) { throw new ProcessInstanceNotFoundException(processInstanceId); } catch (final SBonitaException e) { throw new UpdateException(e); } finally { // unlock process execution try { lockService.unlock(lock, tenantAccessor.getTenantId()); } catch (final SLockException e) { // ignore it } } }