Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Programmatically adding workflow validator

MonishP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 23, 2012

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

5 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
MonishP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 27, 2012

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.");

}

}

MonishP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 27, 2012

To all the experts out there, please feel free to show me better way of doing things.

0 votes
MonishP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 27, 2012
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&lt;String, Object&gt;) 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.");
	        }
		}


0 votes
MonishP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 27, 2012

Thanks Penny for the heads up. I shall now embark on my quest to programmatically add workflow validator.

0 votes
Penny Wyatt (On Leave to July 2021)
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 23, 2012

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.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events