Search in sources :

Example 86 with ActivitiIllegalArgumentException

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());
    }
}
Also used : Field(java.lang.reflect.Field) ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) Method(java.lang.reflect.Method) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 87 with ActivitiIllegalArgumentException

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");
                }
            }
        }
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) HashSet(java.util.HashSet) Set(java.util.Set) Expression(org.activiti.engine.delegate.Expression) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) Iterator(java.util.Iterator) Collection(java.util.Collection)

Example 88 with ActivitiIllegalArgumentException

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;
}
Also used : ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) MessageEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity) MessageEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity) SignalEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.SignalEventSubscriptionEntity) EventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity) SignalEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.SignalEventSubscriptionEntity)

Example 89 with ActivitiIllegalArgumentException

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());
    }
}
Also used : Field(java.lang.reflect.Field) ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) Method(java.lang.reflect.Method) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 90 with ActivitiIllegalArgumentException

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);
    }
}
Also used : ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException)

Aggregations

ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)154 ActivitiException (org.activiti.engine.ActivitiException)32 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)31 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)27 HashMap (java.util.HashMap)24 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)20 Deployment (org.activiti.engine.test.Deployment)16 ArrayList (java.util.ArrayList)12 TaskQuery (org.activiti.engine.task.TaskQuery)12 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)11 MultipartHttpServletRequest (org.springframework.web.multipart.MultipartHttpServletRequest)10 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)9 RestVariable (org.activiti.rest.service.api.engine.variable.RestVariable)9 UserQuery (org.activiti.engine.identity.UserQuery)8 Execution (org.activiti.engine.runtime.Execution)8 QueryVariable (org.activiti.rest.service.api.engine.variable.QueryVariable)8 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)7 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)6 RestVariableScope (org.activiti.rest.service.api.engine.variable.RestVariable.RestVariableScope)6 MultipartFile (org.springframework.web.multipart.MultipartFile)6