use of org.activiti.engine.ActivitiIllegalArgumentException in project Activiti by Activiti.
the class ClassDelegate method applyFieldDeclaration.
public static void applyFieldDeclaration(FieldDeclaration declaration, Object target, boolean throwExceptionOnMissingField) {
Method setterMethod = ReflectUtil.getSetter(declaration.getName(), target.getClass(), declaration.getValue().getClass());
if (setterMethod != null) {
try {
setterMethod.invoke(target, declaration.getValue());
} catch (IllegalArgumentException e) {
throw new ActivitiException("Error while invoking '" + declaration.getName() + "' on class " + target.getClass().getName(), e);
} catch (IllegalAccessException e) {
throw new ActivitiException("Illegal acces when calling '" + declaration.getName() + "' on class " + target.getClass().getName(), e);
} catch (InvocationTargetException e) {
throw new ActivitiException("Exception while invoking '" + declaration.getName() + "' on class " + target.getClass().getName(), e);
}
} else {
Field field = ReflectUtil.getField(declaration.getName(), target);
if (field == null) {
if (throwExceptionOnMissingField) {
throw new ActivitiIllegalArgumentException("Field definition uses unexisting field '" + declaration.getName() + "' on class " + target.getClass().getName());
} else {
return;
}
}
// Check if the delegate field's type is correct
if (!fieldTypeCompatible(declaration, field)) {
throw new ActivitiIllegalArgumentException("Incompatible type set on field declaration '" + declaration.getName() + "' for class " + target.getClass().getName() + ". Declared value has type " + declaration.getValue().getClass().getName() + ", while expecting " + field.getType().getName());
}
ReflectUtil.setField(field, target, declaration.getValue());
}
}
use of org.activiti.engine.ActivitiIllegalArgumentException in project Activiti by Activiti.
the class UserTaskActivityBehavior method handleAssignments.
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void handleAssignments(Expression assigneeExpression, Expression ownerExpression, Set<Expression> candidateUserExpressions, Set<Expression> candidateGroupExpressions, TaskEntity task, ActivityExecution execution) {
if (assigneeExpression != null) {
Object assigneeExpressionValue = assigneeExpression.getValue(execution);
String assigneeValue = null;
if (assigneeExpressionValue != null) {
assigneeValue = assigneeExpressionValue.toString();
}
task.setAssignee(assigneeValue, true, false);
}
if (ownerExpression != null) {
Object ownerExpressionValue = ownerExpression.getValue(execution);
String ownerValue = null;
if (ownerExpressionValue != null) {
ownerValue = ownerExpressionValue.toString();
}
task.setOwner(ownerValue);
}
if (candidateGroupExpressions != null && !candidateGroupExpressions.isEmpty()) {
for (Expression groupIdExpr : candidateGroupExpressions) {
Object value = groupIdExpr.getValue(execution);
if (value instanceof String) {
List<String> candidates = extractCandidates((String) value);
task.addCandidateGroups(candidates);
} else if (value instanceof Collection) {
task.addCandidateGroups((Collection) value);
} else {
throw new ActivitiIllegalArgumentException("Expression did not resolve to a string or collection of strings");
}
}
}
if (candidateUserExpressions != null && !candidateUserExpressions.isEmpty()) {
for (Expression userIdExpr : candidateUserExpressions) {
Object value = userIdExpr.getValue(execution);
if (value instanceof String) {
List<String> candiates = extractCandidates((String) value);
task.addCandidateUsers(candiates);
} else if (value instanceof Collection) {
task.addCandidateUsers((Collection) value);
} else {
throw new ActivitiException("Expression did not resolve to a string or collection of strings");
}
}
}
if (!taskDefinition.getCustomUserIdentityLinkExpressions().isEmpty()) {
Map<String, Set<Expression>> identityLinks = taskDefinition.getCustomUserIdentityLinkExpressions();
for (String identityLinkType : identityLinks.keySet()) {
for (Expression idExpression : identityLinks.get(identityLinkType)) {
Object value = idExpression.getValue(execution);
if (value instanceof String) {
List<String> userIds = extractCandidates((String) value);
for (String userId : userIds) {
task.addUserIdentityLink(userId, identityLinkType);
}
} else if (value instanceof Collection) {
Iterator userIdSet = ((Collection) value).iterator();
while (userIdSet.hasNext()) {
task.addUserIdentityLink((String) userIdSet.next(), identityLinkType);
}
} else {
throw new ActivitiException("Expression did not resolve to a string or collection of strings");
}
}
}
}
if (!taskDefinition.getCustomGroupIdentityLinkExpressions().isEmpty()) {
Map<String, Set<Expression>> identityLinks = taskDefinition.getCustomGroupIdentityLinkExpressions();
for (String identityLinkType : identityLinks.keySet()) {
for (Expression idExpression : identityLinks.get(identityLinkType)) {
Object value = idExpression.getValue(execution);
if (value instanceof String) {
List<String> groupIds = extractCandidates((String) value);
for (String groupId : groupIds) {
task.addGroupIdentityLink(groupId, identityLinkType);
}
} else if (value instanceof Collection) {
Iterator groupIdSet = ((Collection) value).iterator();
while (groupIdSet.hasNext()) {
task.addGroupIdentityLink((String) groupIdSet.next(), identityLinkType);
}
} else {
throw new ActivitiException("Expression did not resolve to a string or collection of strings");
}
}
}
}
}
use of org.activiti.engine.ActivitiIllegalArgumentException in project Activiti by Activiti.
the class EventSubscriptionDeclaration method prepareEventSubscriptionEntity.
public EventSubscriptionEntity prepareEventSubscriptionEntity(ExecutionEntity execution) {
EventSubscriptionEntity eventSubscriptionEntity = null;
if (eventType.equals("message")) {
eventSubscriptionEntity = new MessageEventSubscriptionEntity(execution);
} else if (eventType.equals("signal")) {
eventSubscriptionEntity = new SignalEventSubscriptionEntity(execution);
} else {
throw new ActivitiIllegalArgumentException("Found event definition of unknown type: " + eventType);
}
eventSubscriptionEntity.setEventName(eventName);
if (activityId != null) {
ActivityImpl activity = execution.getProcessDefinition().findActivity(activityId);
eventSubscriptionEntity.setActivity(activity);
}
if (configuration != null) {
eventSubscriptionEntity.setConfiguration(configuration);
}
return eventSubscriptionEntity;
}
use of org.activiti.engine.ActivitiIllegalArgumentException in project Activiti by Activiti.
the class ClassDelegateUtil method applyFieldDeclaration.
public static void applyFieldDeclaration(FieldDeclaration declaration, Object target) {
Method setterMethod = ReflectUtil.getSetter(declaration.getName(), target.getClass(), declaration.getValue().getClass());
if (setterMethod != null) {
try {
setterMethod.invoke(target, declaration.getValue());
} catch (IllegalArgumentException e) {
throw new ActivitiException("Error while invoking '" + declaration.getName() + "' on class " + target.getClass().getName(), e);
} catch (IllegalAccessException e) {
throw new ActivitiException("Illegal acces when calling '" + declaration.getName() + "' on class " + target.getClass().getName(), e);
} catch (InvocationTargetException e) {
throw new ActivitiException("Exception while invoking '" + declaration.getName() + "' on class " + target.getClass().getName(), e);
}
} else {
Field field = ReflectUtil.getField(declaration.getName(), target);
if (field == null) {
throw new ActivitiIllegalArgumentException("Field definition uses unexisting field '" + declaration.getName() + "' on class " + target.getClass().getName());
}
// Check if the delegate field's type is correct
if (!fieldTypeCompatible(declaration, field)) {
throw new ActivitiIllegalArgumentException("Incompatible type set on field declaration '" + declaration.getName() + "' for class " + target.getClass().getName() + ". Declared value has type " + declaration.getValue().getClass().getName() + ", while expecting " + field.getType().getName());
}
ReflectUtil.setField(field, target, declaration.getValue());
}
}
use of org.activiti.engine.ActivitiIllegalArgumentException in project Activiti by Activiti.
the class SkipExpressionUtil method isSkipExpressionEnabled.
public static boolean isSkipExpressionEnabled(ActivityExecution execution, Expression skipExpression) {
if (skipExpression == null) {
return false;
}
final String skipExpressionEnabledVariable = "_ACTIVITI_SKIP_EXPRESSION_ENABLED";
Object isSkipExpressionEnabled = execution.getVariable(skipExpressionEnabledVariable);
if (isSkipExpressionEnabled == null) {
return false;
} else if (isSkipExpressionEnabled instanceof Boolean) {
return ((Boolean) isSkipExpressionEnabled).booleanValue();
} else {
throw new ActivitiIllegalArgumentException(skipExpressionEnabledVariable + " variable does not resolve to a boolean. " + isSkipExpressionEnabled);
}
}
Aggregations