下面列出了org.springframework.core.io.ContextResource#org.activiti.engine.ActivitiException 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
protected void setVariable(Execution execution, String name, Object value, RestVariableScope scope, boolean isNew) {
// Create can only be done on new variables. Existing variables should
// be updated using PUT
boolean hasVariable = hasVariableOnScope(execution, name, scope);
if (isNew && hasVariable) {
throw new ActivitiException("Variable '" + name + "' is already present on execution '" + execution.getId() + "'.");
}
if (!isNew && !hasVariable) {
throw new ActivitiObjectNotFoundException("Execution '" + execution.getId() + "' doesn't have a variable with name: '" + name + "'.", null);
}
if (scope == RestVariableScope.LOCAL) {
runtimeService.setVariableLocal(execution.getId(), name, value);
} else {
if (execution.getParentId() != null) {
runtimeService.setVariable(execution.getParentId(), name, value);
} else {
runtimeService.setVariable(execution.getId(), name, value);
}
}
}
/**
* Generates an image of what currently is drawn on the canvas.
*
* Throws an {@link ActivitiException} when {@link #close()} is already
* called.
*/
public InputStream generateImage(String imageType) {
if (closed) {
throw new ActivitiException("ProcessDiagramGenerator already closed");
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
// Try to remove white space
minX = (minX <= 5) ? 5 : minX;
minY = (minY <= 5) ? 5 : minY;
BufferedImage imageToSerialize = processDiagram;
if (minX >= 0 && minY >= 0) {
imageToSerialize = processDiagram.getSubimage(minX - 5, minY - 5, canvasWidth - minX + 5, canvasHeight - minY + 5);
}
ImageIO.write(imageToSerialize, imageType, out);
} catch (IOException e) {
throw new ActivitiException("Error while generating process image", e);
} finally {
IoUtil.closeSilently(out);
}
return new ByteArrayInputStream(out.toByteArray());
}
@Override
public DeploymentBuilder addZipInputStream(ZipInputStream zipInputStream) {
try {
ZipEntry entry = zipInputStream.getNextEntry();
while (entry != null) {
if (!entry.isDirectory()) {
String entryName = entry.getName();
byte[] bytes = IoUtil.readInputStream(zipInputStream, entryName);
ResourceEntity resource = new ResourceEntity();
resource.setName(entryName);
resource.setBytes(bytes);
deployment.addResource(resource);
}
entry = zipInputStream.getNextEntry();
}
} catch (Exception e) {
throw new ActivitiException("problem reading zip input stream", e);
}
return this;
}
public static boolean isActiviti5ProcessDefinition(CommandContext commandContext, ProcessDefinition processDefinition) {
if (!commandContext.getProcessEngineConfiguration().isActiviti5CompatibilityEnabled()) {
return false;
}
if (processDefinition.getEngineVersion() != null) {
if (Activiti5CompatibilityHandler.ACTIVITI_5_ENGINE_TAG.equals(processDefinition.getEngineVersion())) {
if (commandContext.getProcessEngineConfiguration().isActiviti5CompatibilityEnabled()) {
return true;
}
} else {
throw new ActivitiException("Invalid 'engine' for process definition " + processDefinition.getId() + " : " + processDefinition.getEngineVersion());
}
}
return false;
}
public void testQueryByCandidateGroupOr() {
TaskQuery query = taskService.createTaskQuery()
.or()
.taskId("invalid")
.taskCandidateGroup("management");
assertEquals(3, query.count());
assertEquals(3, query.list().size());
try {
query.singleResult();
fail("expected exception");
} catch (ActivitiException e) {
// OK
}
query = taskService.createTaskQuery()
.or()
.taskId("invalid")
.taskCandidateGroup("sales");
assertEquals(0, query.count());
assertEquals(0, query.list().size());
}
@Deployment
public void testConfigurationBeanAccess() {
// Exposed bean returns 'I'm exposed' when to-string is called in first
// service-task
ProcessInstance pi = runtimeService.startProcessInstanceByKey("expressionBeanAccess");
assertEquals("I'm exposed", runtimeService.getVariable(pi.getId(), "exposedBeanResult"));
// After signaling, an expression tries to use a bean that is present in
// the configuration but is not added to the beans-list
try {
runtimeService.trigger(runtimeService.createExecutionQuery().processInstanceId(pi.getId()).onlyChildExecutions().singleResult().getId());
fail("Exception expected");
} catch (ActivitiException ae) {
assertNotNull(ae.getCause());
assertTrue(ae.getCause() instanceof RuntimeException);
RuntimeException runtimeException = (RuntimeException) ae.getCause();
assertTrue(runtimeException.getCause() instanceof PropertyNotFoundException);
}
}
@Override
public boolean evaluate(String sequenceFlowId, DelegateExecution execution) {
String conditionExpression = null;
if (Context.getProcessEngineConfiguration().isEnableProcessDefinitionInfoCache()) {
ObjectNode elementProperties = Context.getBpmnOverrideElementProperties(sequenceFlowId, execution.getProcessDefinitionId());
conditionExpression = getActiveValue(initialConditionExpression, DynamicBpmnConstants.SEQUENCE_FLOW_CONDITION, elementProperties);
} else {
conditionExpression = initialConditionExpression;
}
Expression expression = Context.getProcessEngineConfiguration().getExpressionManager().createExpression(conditionExpression);
Object result = expression.getValue(execution);
if (result == null) {
throw new ActivitiException("condition expression returns null (sequenceFlowId: " + sequenceFlowId + ")" );
}
if (!(result instanceof Boolean)) {
throw new ActivitiException("condition expression returns non-Boolean (sequenceFlowId: " + sequenceFlowId + "): " + result + " (" + result.getClass().getName() + ")");
}
return (Boolean) result;
}
public void testGetLatestProcessDefinitionTextByKey() {
disableValidation();
repositoryService.createDeployment().addClasspathResource("org/activiti/engine/test/regression/ProcessValidationExecutedAfterDeployTest.bpmn20.xml").deploy();
enableValidation();
clearDeploymentCache();
ProcessDefinition definition = getLatestProcessDefinitionVersionByKey("testProcess1");
if (definition == null) {
fail("Error occurred in fetching process model.");
}
try {
repositoryService.getProcessModel(definition.getId());
assertTrue(true);
} catch (ActivitiException e) {
fail("Error occurred in fetching process model.");
}
for (org.activiti.engine.repository.Deployment deployment : repositoryService.createDeploymentQuery().list()) {
repositoryService.deleteDeployment(deployment.getId());
}
}
/**
* Generates an image of what currently is drawn on the canvas.
* <p/>
* Throws an {@link ActivitiException} when {@link #close()} is already
* called.
*/
public InputStream generateImage(String imageType) {
if (closed) {
throw new ActivitiException("ProcessDiagramGenerator already closed");
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
// Try to remove white space
minX = (minX <= 5) ? 5 : minX;
minY = (minY <= 5) ? 5 : minY;
BufferedImage imageToSerialize = processDiagram;
if (minX >= 0 && minY >= 0) {
imageToSerialize = processDiagram.getSubimage(minX - 5, minY - 5, canvasWidth - minX + 5, canvasHeight - minY + 5);
}
ImageIO.write(imageToSerialize, imageType, out);
} catch (IOException e) {
throw new ActivitiException("Error while generating process image", e);
} finally {
IoUtil.closeSilently(out);
}
return new ByteArrayInputStream(out.toByteArray());
}
@Override
public void deployResources(final String deploymentNameHint, final Resource[] resources, final RepositoryService repositoryService) {
// Create a separate deployment for each resource using the resource
// name
for (final Resource resource : resources) {
final String resourceName = determineResourceName(resource);
final DeploymentBuilder deploymentBuilder = repositoryService.createDeployment().enableDuplicateFiltering().name(resourceName);
try {
if (resourceName.endsWith(".bar") || resourceName.endsWith(".zip") || resourceName.endsWith(".jar")) {
deploymentBuilder.addZipInputStream(new ZipInputStream(resource.getInputStream()));
} else {
deploymentBuilder.addInputStream(resourceName, resource.getInputStream());
}
} catch (IOException e) {
throw new ActivitiException("couldn't auto deploy resource '" + resource + "': " + e.getMessage(), e);
}
deploymentBuilder.deploy();
}
}
@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testCannotSuspendSuspendedProcessInstance() {
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
runtimeService.startProcessInstanceByKey(processDefinition.getKey());
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().singleResult();
assertFalse(processInstance.isSuspended());
runtimeService.suspendProcessInstanceById(processInstance.getId());
try {
runtimeService.suspendProcessInstanceById(processInstance.getId());
fail("Expected activiti exception");
} catch (ActivitiException e) {
// expected
}
}
public void testQueryByProcessDefinitionId() {
final ProcessDefinition processDefinition1 = repositoryService.createProcessDefinitionQuery().processDefinitionKey(PROCESS_DEFINITION_KEY).singleResult();
ProcessInstanceQuery query1 = runtimeService.createProcessInstanceQuery().processDefinitionId(processDefinition1.getId());
assertEquals(PROCESS_DEFINITION_KEY_DEPLOY_COUNT, query1.count());
assertEquals(PROCESS_DEFINITION_KEY_DEPLOY_COUNT, query1.list().size());
try {
query1.singleResult();
fail();
} catch (ActivitiException e) {
// Exception is expected
}
final ProcessDefinition processDefinition2 = repositoryService.createProcessDefinitionQuery().processDefinitionKey(PROCESS_DEFINITION_KEY_2).singleResult();
ProcessInstanceQuery query2 = runtimeService.createProcessInstanceQuery().processDefinitionId(processDefinition2.getId());
assertEquals(PROCESS_DEFINITION_KEY_2_DEPLOY_COUNT, query2.count());
assertEquals(PROCESS_DEFINITION_KEY_2_DEPLOY_COUNT, query2.list().size());
assertNotNull(query2.singleResult());
}
public VariableType getResult(ResultSet resultSet, int columnIndex) throws SQLException {
String typeName = resultSet.getString(columnIndex);
VariableType type = getVariableTypes().getVariableType(typeName);
if (type == null) {
throw new ActivitiException("unknown variable type name " + typeName);
}
return type;
}
public void testQueryNoCriteria() {
DeploymentQuery query = repositoryService.createDeploymentQuery();
assertEquals(2, query.list().size());
assertEquals(2, query.count());
try {
query.singleResult();
fail();
} catch (ActivitiException e) {}
}
public static ProcessDefinitionEntity getProcessDefinitionFromDatabase(String processDefinitionId) {
ProcessDefinitionEntityManager processDefinitionEntityManager = Context.getProcessEngineConfiguration().getProcessDefinitionEntityManager();
ProcessDefinitionEntity processDefinition = processDefinitionEntityManager.findById(processDefinitionId);
if (processDefinition == null) {
throw new ActivitiException("No process definition found with id " + processDefinitionId);
}
return processDefinition;
}
public void submitTaskFormData(String taskId, Map<String, String> properties, boolean completeTask) {
org.activiti5.engine.impl.identity.Authentication.setAuthenticatedUserId(Authentication.getAuthenticatedUserId());
try {
if (completeTask) {
getProcessEngine().getFormService().submitTaskFormData(taskId, properties);
} else {
getProcessEngine().getFormService().saveFormData(taskId, properties);
}
} catch (org.activiti5.engine.ActivitiException e) {
handleActivitiException(e);
}
}
@Override
public CommandInterceptor createTransactionInterceptor() {
if (transactionManager == null) {
throw new ActivitiException("transactionManager is required property for SpringProcessEngineConfiguration, use " + StandaloneProcessEngineConfiguration.class.getName() + " otherwise");
}
return new SpringTransactionInterceptor(transactionManager);
}
@Override
protected List<VariableInstanceEntity> getSpecificVariables(Collection<String> variableNames) {
CommandContext commandContext = Context.getCommandContext();
if (commandContext == null) {
throw new ActivitiException("lazy loading outside command context");
}
return commandContext
.getVariableInstanceEntityManager()
.findVariableInstancesByExecutionAndNames(id, variableNames);
}
public InputStream getInputStream() {
try {
return new ByteArrayInputStream(byteArrayEncoding == null ? string.getBytes() : string.getBytes(byteArrayEncoding));
} catch (UnsupportedEncodingException e) {
throw new ActivitiException("Unsupported enconding for string", e);
}
}
@Test(expected = ActivitiException.class)
public void testDeployResourcesIOExceptionYieldsActivitiException() throws Exception {
when(resourceMock3.getInputStream()).thenThrow(new IOException());
final Resource[] resources = new Resource[] { resourceMock3 };
classUnderTest.deployResources(deploymentNameHint, resources, repositoryServiceMock);
fail("Expected exception for IOException");
}
protected void handleException(DelegateExecution execution, String msg, Exception e, boolean doIgnoreException, String exceptionVariable) {
if (doIgnoreException) {
LOG.info("Ignoring email send error: " + msg, e);
if (exceptionVariable != null && exceptionVariable.length() > 0) {
execution.setVariable(exceptionVariable, msg);
}
} else {
if (e instanceof ActivitiException) {
throw (ActivitiException) e;
} else {
throw new ActivitiException(msg, e);
}
}
}
public void deleteJob(String jobId) {
try {
getProcessEngine().getManagementService().deleteJob(jobId);
} catch (org.activiti5.engine.ActivitiException e) {
handleActivitiException(e);
}
}
@Deployment
public void testInvalidMethodExpression() {
try {
runtimeService.startProcessInstanceByKey("invalidMethodExpression",
CollectionUtil.singletonMap("order", new ExclusiveGatewayTestOrder(50)));
fail();
} catch (ActivitiException e) {
assertTextPresent("Unknown method used in expression", e.getMessage());
}
}
public void testQueryByProcessDefinitionKeys() {
final Set<String> processDefinitionKeySet = new HashSet<String>(2);
processDefinitionKeySet.add(PROCESS_DEFINITION_KEY);
processDefinitionKeySet.add(PROCESS_DEFINITION_KEY_2);
ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().processDefinitionKeys(processDefinitionKeySet);
assertEquals(PROCESS_DEPLOY_COUNT, query.count());
assertEquals(PROCESS_DEPLOY_COUNT, query.list().size());
try {
query.singleResult();
fail();
} catch (ActivitiException e) {
// Exception is expected
}
}
public void claimTask(String taskId, String userId) {
org.activiti5.engine.impl.identity.Authentication.setAuthenticatedUserId(Authentication.getAuthenticatedUserId());
try {
getProcessEngine().getTaskService().claim(taskId, userId);
} catch (org.activiti5.engine.ActivitiException e) {
handleActivitiException(e);
}
}
protected Transaction getTransaction() {
try {
return transactionManager.getTransaction();
} catch (SystemException e) {
throw new ActivitiException("SystemException while getting transaction ", e);
}
}
@SuppressWarnings("rawtypes")
public void complete(Map variablesMap, boolean localScope, boolean fireEvents) {
if (getDelegationState() != null && getDelegationState() == DelegationState.PENDING) {
throw new ActivitiException("A delegated task cannot be completed, but should be resolved instead.");
}
if (fireEvents) {
fireEvent(TaskListener.EVENTNAME_COMPLETE);
}
if (Authentication.getAuthenticatedUserId() != null && processInstanceId != null) {
getProcessInstance().involveUser(Authentication.getAuthenticatedUserId(), IdentityLinkType.PARTICIPANT);
}
if (Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled() && fireEvents) {
Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
ActivitiEventBuilder.createEntityWithVariablesEvent(FlowableEngineEventType.TASK_COMPLETED, this, variablesMap, localScope));
}
Context
.getCommandContext()
.getTaskEntityManager()
.deleteTask(this, TaskEntity.DELETE_REASON_COMPLETED, false);
if (executionId != null) {
ExecutionEntity execution = getExecution();
execution.removeTask(this);
execution.signal(null, null);
}
}
@Deployment
public void testInvalidFormKeyReference() {
try {
formService.getRenderedStartForm(repositoryService.createProcessDefinitionQuery().singleResult().getId());
fail();
} catch (ActivitiException e) {
assertTextPresent("Form with formKey 'IDoNotExist' does not exist", e.getMessage());
}
}
public void testQueryNoSpecificsSingleResult() {
ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery();
try {
query.singleResult();
fail();
} catch (ActivitiException e) {
// Exception is expected
}
}
protected byte[] getDeploymentResourceData(String deploymentId, String resourceName, HttpServletResponse response) {
if (deploymentId == null) {
throw new ActivitiIllegalArgumentException("No deployment id provided");
}
if (resourceName == null) {
throw new ActivitiIllegalArgumentException("No resource name provided");
}
// Check if deployment exists
Deployment deployment = repositoryService.createDeploymentQuery().deploymentId(deploymentId).singleResult();
if (deployment == null) {
throw new ActivitiObjectNotFoundException("Could not find a deployment with id '" + deploymentId + "'.", Deployment.class);
}
List<String> resourceList = repositoryService.getDeploymentResourceNames(deploymentId);
if (resourceList.contains(resourceName)) {
final InputStream resourceStream = repositoryService.getResourceAsStream(deploymentId, resourceName);
String contentType = contentTypeResolver.resolveContentType(resourceName);
response.setContentType(contentType);
try {
return IOUtils.toByteArray(resourceStream);
} catch (Exception e) {
throw new ActivitiException("Error converting resource stream", e);
}
} else {
// Resource not found in deployment
throw new ActivitiObjectNotFoundException("Could not find a resource with name '" + resourceName + "' in deployment '" + deploymentId + "'.", String.class);
}
}