/** * initializes the workflow and a default config * * @return the unique workflow id */ private long createWorkflow() throws InvalidRoleException, InvalidInputException, WorkflowException { this.osWorkflowInstance = new BasicWorkflow(this.caller); DefaultConfiguration config = new DefaultConfiguration(); this.osWorkflowInstance.setConfiguration(config); long wfId = this.osWorkflowInstance.initialize(this.osWorkflowName, this.action, this.map); return wfId; }
/** * Given a map of transientVars from a Workflow Function, returns the user's key of the caller. It is highly * discouraged to use this method directly when fetching user object. Please use {@link * #getCallerUser(java.util.Map)} instead. * * @param transientVars the "transientVars" from the workflow FunctionProvider * @return the userKey of the caller (can be null for anonymous). * @see WorkflowUtil#getCallerUser(java.util.Map) * @since 6.0 */ public static String getCallerKey(Map transientVars) { if(transientVars == null){ return null; } WorkflowContext context = (WorkflowContext) transientVars.get("context"); if(context == null){ return null; } return context.getCaller(); }
public Workflow makeWorkflowWithUserKey(String userKey) { Workflow workflow = new BasicWorkflow(userKey); workflow.setConfiguration(getConfiguration()); return workflow; }
final List initialActions = workflowDescriptor.getInitialActions(); long wfId = workflow.initialize(jiraWorkflow.getName(), actionDescriptor.getId(), fields); throw new WorkflowException(e.getMessage(), e); throw new WorkflowException(e.getMessage(), e); throw new WorkflowException(e.getMessage(), e); throw new WorkflowException(e.getMessage(), e);
int[] availableActions = this.osWorkflowInstance.getAvailableActions(this.workflowId, this.map); try { this.osWorkflowInstance.doAction(this.workflowId,nextAction, this.map); } catch (InvalidInputException iiex) { logger.error(iiex.getMessage()); aborted = true; } catch (WorkflowException wfex) { logger.error(wfex.getMessage()); aborted = true;
private ActionDescriptor getActionDescriptor() { Workflow wf = workflowManager.makeWorkflow(getLoggedInUser()); long workflowId = getIssue().getLong("workflowId"); WorkflowDescriptor wd = wf.getWorkflowDescriptor(wf.getWorkflowName(workflowId)); return wd.getAction(action); }
/** * If the exception was an InvalidInputException then we have some information about what fields are in error. * <p/> * Its up to the implementers of the Validator to get the fields names right, and i18nized and so on for the current * screen scheme. * * @param inputException the workflow input exception */ private void handleInvalidInputException(final ErrorCollection errors, final InvalidInputException inputException) { for (final Object o1 : inputException.getGenericErrors()) { String error = (String) o1; errors.addErrorMessage(error); } for (final Object o : inputException.getErrors().entrySet()) { Map.Entry entry = (Map.Entry) o; errors.addError((String) entry.getKey(), (String) entry.getValue()); } }
if (user == null) throw new InvalidInputException("You don't have the correct permissions - user (" + username + ") not found");
@Override public boolean passesCondition(final Map transientVars, final Map args, final PropertySet ps) throws WorkflowException { try { return condition.passesCondition(transientVars, args, ps); } catch(Throwable throwable) { SafePluginPointAccess.handleException(throwable); return false; } } }
@Override public FunctionProvider getFunction(String type, Map args) throws WorkflowException { final TypeResolver delegate = getDelegate(args); if (delegate == null) { return null; } return delegate.getFunction(type, args); }
@Override public Register getRegister(String type, Map args) throws WorkflowException { final TypeResolver delegate = getDelegate(args); if (delegate == null) { return null; } return delegate.getRegister(type, args); }
public void start() throws Exception { TypeResolver.setResolver(new JiraTypeResolverDelegator()); } ///CLOVER:ON
@Override public void validate(Map transientVars, Map args, PropertySet ps) throws InvalidInputException, WorkflowException { TransitionOptions transitionOptions= TransitionOptions.toTransitionOptions(transientVars); if (transitionOptions.skipValidators()) { return; } validator.validate(transientVars, args, ps); }
@Override public Validator getValidator(String type, Map args) throws WorkflowException { final TypeResolver delegate = getDelegate(args); if (delegate == null) { return null; } return SkippableValidator.of(delegate.getValidator(type, args)); } }
@Override public Condition getCondition(String type, Map args) throws WorkflowException { final TypeResolver delegate = getDelegate(args); if (delegate == null) { return null; } return SkippableCondition.of(delegate.getCondition(type, args)); }
public boolean passesCondition(Map transientVars, Map args, PropertySet ps) { try { Boolean close = (Boolean) transientVars.get("close"); if (!close.booleanValue()) { return false; } Issue issue = getIssue(transientVars); WorkflowContext context = (WorkflowContext) transientVars.get("context"); String username = context.getCaller(); ApplicationUser user = null; if (username != null) user = UserUtils.getUser(username); return ComponentAccessor.getPermissionManager().hasPermission(Permissions.CLOSE_ISSUE, issue, user); } catch (Exception e) { log.error("Exception: " + e, e); return false; } } }
@VisibleForTesting ApplicationUser getCaller(final Map transientVars) throws InvalidInputException { final String userKey = getCallerKey(transientVars); final ApplicationUser user = ComponentAccessor.getUserManager().getUserByKey(userKey); // Check if user was found if (userKey != null && user == null) { throw new InvalidInputException("You don't have the correct permissions - user (" + userKey + ") not found"); } return user; }
@Override public boolean passesCondition(Map transientVars, Map args, PropertySet ps) throws WorkflowException { TransitionOptions transitionOptions= TransitionOptions.toTransitionOptions(transientVars); if (transitionOptions.skipConditions()) { return true; } return condition.passesCondition(transientVars, args, ps); }
@SuppressWarnings ("SimplifiableIfStatement") @VisibleForTesting boolean hasUserPermissionForIssue(Issue issue, ProjectPermissionKey permissionKey, ApplicationUser user, PermissionManager permissionManager) throws InvalidInputException { //Check to see if we have an existing issue in the transient vars, if we do use that, otherwise use the project. if (issue.getGenericValue() != null) { return permissionManager.hasPermission(permissionKey, issue, user); } else if (issue.getProjectObject() != null) { return permissionManager.hasPermission(permissionKey, issue.getProjectObject(), user); } else { throw new InvalidInputException("Invalid project specified."); } } }
private void validateIssueFieldsLength(final WorkflowProgressAware from, final MutableIssue issue) throws InvalidInputException { final IssueTextFieldCharacterLengthValidator.ValidationResult validationResult = textFieldCharacterLengthValidator.validateModifiedFields(issue); if (!validationResult.isValid()) { final I18nHelper i18n = getI18nBean(from.getRemoteUser()); HashMap<String, String> invalidFields = Maps.newHashMapWithExpectedSize(validationResult.getInvalidFieldIds().size()); for (final String fieldId: validationResult.getInvalidFieldIds()) { invalidFields.put(fieldId, i18n.getText("field.error.text.toolong", validationResult.getMaximumNumberOfCharacters())); } throw new InvalidInputException(invalidFields); } }