Hi I created a simple plugin that extends SelectCFType. I got it to populate the customfieldoption and save the selected option value and then highlight the selected option value. I have noticed that when I stop restart the Jira, on restart the plugin gets disabled automatically, even if i enable it, the custom field created from it does not appear anymore. The ony way to get it working is to uninstall the plugin and reinstall it. Once I do this I cannot see the previous custom field say xyz created. The only way to get it only if I creat a new custom field say zzz. Once zzz is created both xyz and zzz appear. I scanned through the logs and the error I get is There was a problem loading the descriptor for module 'CustomDB Field' in plugin 'Customdb'.
Given module class: java.lang.Void does not implement com.atlassian.jira.issue.customfields.CustomFieldType
Not sure what the problem is
package com.xyz.jira.plugin;
import com.atlassian.jira.issue.customfields.impl.SelectCFType;
import com.atlassian.jira.issue.customfields.persistence.CustomFieldValuePersister;
import com.atlassian.jira.issue.customfields.converters.StringConverter;
import com.atlassian.jira.issue.customfields.converters.SelectConverter;
import com.atlassian.jira.issue.customfields.manager.OptionsManager;
import com.atlassian.jira.issue.customfields.manager.GenericConfigManager;
import com.atlassian.jira.issue.customfields.view.CustomFieldParams;
import com.atlassian.jira.issue.customfields.option.Options;
import com.atlassian.jira.issue.customfields.option.Option;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.search.SearchContextImpl;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.fields.config.FieldConfig;
import com.atlassian.jira.issue.fields.layout.field.FieldLayoutItem;
import com.atlassian.jira.util.ErrorCollection;
import java.util.Map;
import java.util.HashMap;
/**
*/
public class CustomDBPlugin extends SelectCFType {
/** The options manager. */
private final OptionsManager optionsManager;
//private DatabaseCFOption conf;
public CustomDBPlugin(CustomFieldValuePersister customFieldValuePersister, StringConverter stringConverter, SelectConverter selectConverter, OptionsManager optionsManager, GenericConfigManager genericConfigManager) {
super(customFieldValuePersister, stringConverter, selectConverter, optionsManager, genericConfigManager);
this.optionsManager = optionsManager;
}
/**
*/
@Override
public void validateFromParams(CustomFieldParams relevantParams,
ErrorCollection errorCollectionToAddTo, FieldConfig config) {
// do nothing, no validation required yet.
}
/**
*/
@Override
@SuppressWarnings("unchecked")
public Map getVelocityParameters(Issue issue, CustomField field,
FieldLayoutItem fieldLayoutItem) {
Map parameters = super.getVelocityParameters(issue, field, fieldLayoutItem);
FieldConfig fieldConfig = null;
if(issue == null)
{
fieldConfig = field.getReleventConfig(new SearchContextImpl());
} else
{
fieldConfig = field.getRelevantConfig(issue);
}
Options options = this.optionsManager.getOptions(fieldConfig);
if (options.isEmpty()) {
this.optionsManager.createOption(fieldConfig, null, new Long(1), "A");
this.optionsManager.createOption(fieldConfig, null, new Long(2), "B");
}
options = this.optionsManager.getOptions(fieldConfig);
Map<Long, String> results = new HashMap<Long, String>();
Long selectedId= (long) -1;
boolean selected = false;
Object value = field.getValue(issue);
if (value!=null) {
selected=true;
}
for (Option option : (Iterable<Option>) options) {
results.put(option.getOptionId(), option.getValue());
if (selected && value.toString().equals(option.getValue())) {
selectedId = option.getOptionId();
}
}
parameters.put("results", results);
parameters.put("selectedId", selectedId);
return parameters;
}
}
Here is the velocity template custom-db-field-edit.vm
#* @vtlvariable name="results" type="java.util.Map" *#
#* @vtlvariable name="selectedId" type="java.lang.String" *#
#controlHeader ($action $customField.id $customField.name $fieldLayoutItem.required $displayParameters.noHeader)
<select name="$customField.id" id="$customField.id" >
<option value="">Not selected</option>
#foreach ($mapEntry in $results.entrySet())
#if ( $selectedId == $mapEntry.key )
<option selected="selected" value="$mapEntry.key">$mapEntry.value</option>
#else
<option value="$mapEntry.key">$mapEntry.value</option>
#end
#end
</select>
#controlFooter ($action $fieldLayoutItem.fieldDescription $displayParameters.noHeader)
Here is the plugin desctiptor.
<atlassian-plugin key="com.xyz.jira.plugin.customdbplugin" name="CustomDB" plugins-version="2">
<plugin-info>
<description>xyx</description>
<version>1.0-SNAPSHOT</version>
<vendor name="XYZ" url="http://www.xyz.com/" />
</plugin-info>
<customfield-type key="customdb-field" name="CustomDB Field" class="com.xyz.jira.plugin.CustomDBPlugin">
<description>Custom DB Plugin</description>
<label>Custom DB Field</label>
<resource type="velocity" name="view" location="templates/plugins/custom-db/custom-db-field-edit.vm"/>
<resource type="velocity" name="edit" location="templates/plugins/custom-db/custom-db-field-edit.vm"/>
<resource type="velocity" name="xml" location="templates/plugins/fields/xml/xml-basictext.vm"/>
</customfield-type>
</atlassian-plugin>