Hi all,
I am making a plugin that should create a validator and associate that validatory to particular workflow steps affecting particular issue types.
I have managed to create a validator and am able to go through find the steps of workflow associated with the issue types I am concerned about. So, my question is how do I programmatically associate a workflow step with a validator.
Can someone point me in the right direction?
Thanks
Monish
Community moderators have prevented the ability to post new answers.
After searching for hours finally got it working. For anyone looking to do similar thing here is the code for it.
actions is the collection of action descriptor for which the validation happens
MyFieldValidator and MyFieldValidatorFactory are the classes used to implement the validator, I followed this tutorial.
//going through the unique actions
for (ActionDescriptor thisAction : actions) {
log.debug("Adding workflow validator for: " + thisAction.getName());
//create a empty validator descriptor
ValidatorDescriptor validatorDescriptor = DescriptorFactory.getFactory().createValidatorDescriptor();
validatorDescriptor.setType("class");
//fill the empty validator descriptor with description of our validator
final Map validatorArgs = validatorDescriptor.getArgs();
validatorArgs.put("class.name", new MyFieldValidator(customfieldManager).getClass().getName());
//adding the parameters required for our validator
WorkflowPluginValidatorFactory workflowPluginValidatorFactory = new MyFieldValidatorFactory(customfieldManager);
validatorArgs.putAll(workflowPluginValidatorFactory.getDescriptorParams((Map<String, Object>) workflowPluginValidatorFactory.getDescriptorParams(null)));
//safety check
if (thisAction.getValidators() != null) {
//making sure no duplicates
boolean flag = true;
for(Object validatorObject: thisAction.getValidators()){
ValidatorDescriptor thisValidator = (ValidatorDescriptor)validatorObject;
if(thisValidator.getName()==validatorDescriptor.getName()){
flag = false;
break;
}
}
if(flag){
thisAction.getValidators().add(validatorDescriptor);
}
} else {
log.debug("The action: "+ thisAction.getName() +" validators is null.");
}
}
To all the experts out there, please feel free to show me better way of doing things.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can use WorkflowTransitionService to do that: https://developer.atlassian.com/static/javadoc/jira/6.4/reference/com/atlassian/jira/bc/workflow/WorkflowTransitionService.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
After learching for hours finally got it working. For anyone lloking to do similar thing here is the code for it. actions is the collection of action descriptor for which the validation happens MyFieldValidator and MyFieldValidatorFactory are the classes used to implement the validator, I followed this tutorial.
//going through the unique actions
for (ActionDescriptor thisAction : actions) { log.debug("Adding workflow validator for: " + thisAction.getName()); //create a empty validator descriptor ValidatorDescriptor validatorDescriptor = DescriptorFactory.getFactory().createValidatorDescriptor(); validatorDescriptor.setType("class"); //fill the empty validator descriptor with description of our validator final Map validatorArgs = validatorDescriptor.getArgs(); validatorArgs.put("class.name", new ComSysFieldValidator(customfieldManager).getClass().getName()); //adding the parameters required for our validator WorkflowPluginValidatorFactory workflowPluginValidatorFactory = new ComSysFieldValidatorFactory(customfieldManager); validatorArgs.putAll(workflowPluginValidatorFactory.getDescriptorParams((Map<String, Object>) workflowPluginValidatorFactory.getDescriptorParams(null))); //safety check if (thisAction.getValidators() != null) { //making sure no duplicates boolean flag = true; for(Object validatorObject: thisAction.getValidators()){ ValidatorDescriptor thisValidator = (ValidatorDescriptor)validatorObject; if(thisValidator.getName()==validatorDescriptor.getName()){ flag = false; break; } } if(flag){ thisAction.getValidators().add(validatorDescriptor); } } else { log.debug("The action: "+ thisAction.getName() +" validators is null."); } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Penny for the heads up. I shall now embark on my quest to programmatically add workflow validator.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I don't know the answer to your question (sorry), but to point you closer to the right direction... validators, conditions and post-functions aren't assigned to workflow steps, but to transitions - the actions that move you between steps. A workflow validator defines rules as to whether the transition is completed successfully or not.
Something else that may trip you up is that you can't edit transitions/steps/etc in a workflow that is live - that is, actively assigned to a project. You will most likely need to create a draft of the workflow first, edit the draft, then publish it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.