Key-Value Service
Key-Value Service
package biz.everit.jira.issue.score.service;
import java.util.List;
import biz.everit.jira.issue.score.service.dto.IssueScoreKeyValueOption;
/**
* Issue score key value manager to help to manage Key-Value custom field.
*/
public interface IssueScoreKeyValueManager {
/**
* Returns the key-value option based on customfieldId and issue key.
*
* @param customFieldId
* the id of Key-Value custom field (eg. 10000).
* @param issueKey
* the key to the issue to be updated.
* @return the {@link IssueScoreKeyValueOption} object. If key-value option not found for the id,
* it returns null.
*
* @throws IllegalArgumentException
* if not found issue/custom field or custom field is not Key-value customfield.
*/
IssueScoreKeyValueOption getKeyValueOption(long customFieldId, String issueKey);
/**
* Returns configured key-value options for Key-Value customfield based on custom field id (eg.
* 10000) for issue.
*
* @param customFieldId
* the id of Key-Value custom field (eg. 10000).
* @param issueKey
* the key to the issue to be updated.
* @return the list of {@link IssueScoreKeyValueOption}. If no value is configured, it returns an
* empty list.
*
* @throws IllegalArgumentException
* if not found issue/custom field or custom field is not Key-value customfield.
*/
List<IssueScoreKeyValueOption> getKeyValueOptions(long customFieldId, String issueKey);
/**
* Update Key-Value custom field's value based on key-value option id. If the issue does not
* exists, method will throw exception. The custom field value will be updated when the Jira
* update event finished. Retruning a correct value is not guaranteed until it.
*
* @param customFieldId
* the id of Key-Value custom field (eg. 10000).
* @param issueKey
* the key to the issue to be updated.
* @param keyValueOptionId
* the id of the key-value option (stored in custom field value).
*
* @throws IllegalArgumentException
* if not found issue/custom field or custom field is not Key-value customfield.
*/
void updateKeyValueCustomFieldValue(long customFieldId, String issueKey, long keyValueOptionId);
/**
* Update Key-Value custom field value based on key value option key. If the issue does not
* exists, method will throw exception. The key-value option's key is not unique in a customfield.
* If multiple options exist with the same name, the first match will be updated. The custom field
* value will be updated when the Jira update event finished. Retruning a correct value is not
* guaranteed until it.
*
* @param customFieldId
* the id of Key-Value custom field (eg. 10000).
* @param issueKey
* the key to the issue to be updated.
* @param optionKey
* the key-value option's key.
*
* @throws IllegalArgumentException
* if not found issue/custom field or custom field is not Key-value customfield.
*/
void updateKeyValueCustomFieldValue(long customFieldId, String issueKey, String optionKey);
DTO
package biz.everit.jira.issue.score.service.dto;
/**
* Data holder for Issue Score Key value option.
*/
public class IssueScoreKeyValueOption {
private final long keyValueOptionId;
private final String optionKey;
private final double optionValue;
/**
* Simple constructor.
*/
public IssueScoreKeyValueOption(final long keyValueOptionId, final String optionKey,
final double optionValue) {
this.keyValueOptionId = keyValueOptionId;
this.optionKey = optionKey;
this.optionValue = optionValue;
}
public long getKeyValueOptionId() {
return this.keyValueOptionId;
}
public String getOptionKey() {
return this.optionKey;
}
public double getOptionValue() {
return this.optionValue;
}
}
Example
import com.onresolve.scriptrunner.runner.customisers.PluginModule;
import com.onresolve.scriptrunner.runner.customisers.WithPlugin;
import biz.everit.jira.issue.score.service.IssueScoreKeyValueManager;
import biz.everit.jira.issue.score.service.dto.IssueScoreKeyValueOption;
@WithPlugin("biz.everit.jira.issue-score")
@PluginModule
IssueScoreKeyValueManager issueScoreKeyValueManager;
def customFieldId = 10701;
def issueKey = 'SAM-1';
def keyValueId = 20;
def optionKey = 'sample';
// gets key value options
List<IssueScoreKeyValueOption> issueScoreKeyValues = issueScoreKeyValueManager.getKeyValueOptions(customFieldId, issueKey);
for(IssueScoreKeyValueOption issueScoreKeyValue : issueScoreKeyValues) {
log.error(issueScoreKeyValue.getOptionKey() + " - " + issueScoreKeyValue.getOptionValue() + " : " + issueScoreKeyValue.getKeyValueOptionId())
}
// gets the key-value option
IssueScoreKeyValueOption keyValueOption = issueScoreKeyValueManager.getKeyValueOption(customFieldId, issueKey);
log.error(keyValueOption.getOptionKey() + " - " + keyValueOption.getOptionValue() + " : " + keyValueOption.getKeyValueOptionId())
// update to specific option based on keyValueId
issueScoreKeyValueManager.updateKeyValueCustomFieldValue(customFieldId, issueKey, keyValueId);
// The custom field value will be updated when the Jira update event finished. Retruning a correct value is not guaranteed until it.
// update to specific option based on optionKey
issueScoreKeyValueManager.updateKeyValueCustomFieldValue(customFieldId, issueKey, optionKey);
// The custom field value will be updated when the Jira update event finished. Retruning a correct value is not guaranteed until it.