Good day.
I am fairly new to jira development, I have searched for a similar topic and found nothing, so, hopefully, this will not be a double question.
I have a problem with getting a velocity input parameter in the factory class, count in this case. I can not retrieve it from the FunctionDescriptor, can anyone please tell me what I am doing wrong?
This is the code in the input/edit velocity template:
<tr>
<td class="fieldLabelArea">
Number of subtasks:
</td>
<td nowrap>
<input name="count" id="count" value="$count"/>
</td>
</tr>
the view template:
Creates a subtask/subtasks for a transitioning issue! Current number of subtasks for a transitioning issue is set to $count!
And the postfunction factory class:
public class CreateSubTaskForIssuePostFunctionFactory extends AbstractWorkflowPluginFactory implements WorkflowPluginFunctionFactory{
private static final Logger log = LoggerFactory.getLogger(CreateSubTaskForIssuePostFunctionFactory.class);
private final static String COUNT="count";
private final static String DEFAULT_COUNT="1";
@Override
protected void getVelocityParamsForEdit(Map<String, Object> velocityParams, AbstractDescriptor abstractDescriptor) {
getVelocityParamsForInput(velocityParams);
getVelocityParamsForView(velocityParams,abstractDescriptor);
}
@Override
protected void getVelocityParamsForInput(Map<String, Object> velocityParams) {
velocityParams.put(COUNT, DEFAULT_COUNT);
}
@Override
protected void getVelocityParamsForView(Map<String, Object> velocityParams, AbstractDescriptor abstractDescriptor) {
velocityParams.put(COUNT, getCount(abstractDescriptor));
}
private String getCount(AbstractDescriptor abstractDescriptor) {
if(!(abstractDescriptor instanceof FunctionDescriptor)) {
throw new IllegalArgumentException("Descriotor must be a FunctionDescriptor!");
}
FunctionDescriptor functionDescriptor = (FunctionDescriptor) abstractDescriptor;
String numberOfSubtasks = (String) functionDescriptor.getArgs().get(COUNT);
if (numberOfSubtasks == null)log.error("Something is wrong! Count is: "+numberOfSubtasks);
return (numberOfSubtasks != null && numberOfSubtasks.trim().length()>0)?numberOfSubtasks:DEFAULT_COUNT;
}
public Map<String, ?> getDescriptorParams(Map<String, Object> formParams) {
if(formParams != null && formParams.containsKey(COUNT)) {
return MapBuilder.build(COUNT, extractSingleParam(formParams, COUNT));
}
return MapBuilder.emptyMap();
}
}