com.atlassian.jira.issue.customfields.impl
Class MultiSelectCFType

java.lang.Object
  extended by com.atlassian.jira.issue.customfields.impl.AbstractCustomFieldType<Collection<S>,S>
      extended by com.atlassian.jira.issue.customfields.impl.AbstractMultiCFType<Option>
          extended by com.atlassian.jira.issue.customfields.impl.MultiSelectCFType
All Implemented Interfaces:
ProjectImportableCustomField, CustomFieldType<Collection<Option>,Option>, GroupSelectorField, MultipleCustomFieldType<Collection<Option>,Option>, MultipleSettableCustomFieldType<Collection<Option>,Option>, SortableCustomField<List<String>>, RestAwareCustomFieldType, RestCustomFieldTypeOperations

public class MultiSelectCFType
extends AbstractMultiCFType<Option>
implements MultipleSettableCustomFieldType<Collection<Option>,Option>, SortableCustomField<List<String>>, GroupSelectorField, ProjectImportableCustomField, RestAwareCustomFieldType, RestCustomFieldTypeOperations

Multiple Select Type allows selecting of multiple Options

Transport Object Type
Collection
Singular Object Type
Option
Database Storage Type
String of option id


Nested Class Summary
static interface MultiSelectCFType.InputTextProvider
          Support interface to delay the data input text evaluation to vm-processing time.
static interface MultiSelectCFType.Visitor<T>
           
 
Nested classes/interfaces inherited from class com.atlassian.jira.issue.customfields.impl.AbstractCustomFieldType
AbstractCustomFieldType.VisitorBase<X>
 
Field Summary
static String COMMA_REPLACEMENT
           
 
Fields inherited from class com.atlassian.jira.issue.customfields.impl.AbstractMultiCFType
customFieldValuePersister, genericConfigManager
 
Fields inherited from interface com.atlassian.jira.issue.customfields.CustomFieldType
DEFAULT_VALUE_TYPE, RESOURCE_PREVIEW
 
Constructor Summary
MultiSelectCFType(OptionsManager optionsManager, CustomFieldValuePersister valuePersister, GenericConfigManager genericConfigManager, JiraBaseUrls jiraBaseUrls, SearchService searchService, FeatureManager featureManager)
           
 
Method Summary
 Object accept(AbstractCustomFieldType.VisitorBase visitor)
           
 int compare(List<String> customFieldObjectValue1, List<String> customFieldObjectValue2, FieldConfig fieldConfig)
          Compares the two custom field objects.
protected  Option convertDbValueToType(Object dbValue)
          Converts a given db value to Single form of Transport Object
protected  Object convertTypeToDbValue(Option value)
          Converts a given underlying type to its db storage value.
static Collection<String> extractTransferObjectFromString(String value)
          Parses the given comma-separated String value into a Collection.
 String getChangelogString(CustomField field, Collection<Option> value)
          Returns a String of representing values to be stored in the change log, an example is the name of a version field that a version id will resolve to within JIRA.
 List<FieldConfigItemType> getConfigurationItemTypes()
          Returns a List of FieldConfigItemType objects.
protected  PersistenceFieldType getDatabaseType()
          Type of database field needed to store this field.
 Collection<Option> getDefaultValue(FieldConfig fieldConfig)
          Retrieves the Object representing the default CustomField value for the Custom Field.
 FieldTypeInfo getFieldTypeInfo(FieldTypeInfoContext fieldTypeInfoContext)
          Returns lower level Information about the field.
 Set<Long> getIssueIdsWithValue(CustomField field, Option option)
          Returns a Set of issue ids (Long) that have the given option selected.
 JsonData getJsonDefaultValue(IssueContext issueCtx, CustomField field)
          Return The default data for this system field.
 FieldJsonRepresentation getJsonFromIssue(CustomField field, Issue issue, boolean renderedVersionRequested, FieldLayoutItem fieldLayoutItem)
          Return a JsonData representation of the field value
 JsonType getJsonSchema(CustomField customField)
          Return a description of the shape of this field when represented as JSON.
 Options getOptions(FieldConfig fieldConfig, JiraContextNode jiraContextNode)
          Returns all possible Options for this field.
 ProjectCustomFieldImporter getProjectImporter()
          Returns the object that will perform the actual project import functions for the custom field type.
 org.apache.lucene.search.Query getQueryForGroup(String fieldID, String groupName)
          This method should be implemented in your custom type to return a Query.
 RestFieldOperationsHandler getRestFieldOperation(CustomField field)
          Returns the RestFieldOperationsHandler for this field.
 Option getSingularObjectFromString(String string)
          Returns a Singular Object, given the string value as passed by the presentation tier.
 String getStringFromSingularObject(Option optionObject)
          Returns the String representation of a single value within the CustomFieldType.
static String getStringFromTransferObject(Collection<String> collection)
          Takes a Collection of values and creates a comma-separated String that represents this Collection.
 Object getStringValueFromCustomFieldParams(CustomFieldParams parameters)
          Return the String value object from the CustomFieldParams.
protected  Comparator<Option> getTypeComparator()
          Returns a comparator for underlying type of this custom field.
 Collection<Option> getValueFromCustomFieldParams(CustomFieldParams parameters)
          Retrieves the Transport Object representing the CustomField value instance from the CustomFieldParams of Strings.
 Map<String,Object> getVelocityParameters(Issue issue, CustomField field, FieldLayoutItem fieldLayoutItem)
          The custom field may wish to pass parameters to the velocity context beyond the getValueFromIssue methods (eg managers).
 Set<Long> remove(CustomField field)
          called when removing a field.
 void removeValue(CustomField field, Issue issue, Option option)
          Perform any actions required if the option selected by the issue is removed.
 void setDefaultValue(FieldConfig fieldConfig, Collection<Option> value)
          Sets the default value for a Custom Field.
 void validateFromParams(CustomFieldParams relevantParams, ErrorCollection errorCollectionToAddTo, FieldConfig config)
          Ensures that the CustomFieldParams of Strings is a valid representation of the Custom Field values.
 boolean valuesEqual(Collection<Option> v1, Collection<Option> v2)
          Used to compare 2 field values and work out whether a change item should be generated
 
Methods inherited from class com.atlassian.jira.issue.customfields.impl.AbstractMultiCFType
convertDbObjectToTypes, convertTypesToDbObjects, createValue, getChangelogValue, getValueFromIssue, updateValue
 
Methods inherited from class com.atlassian.jira.issue.customfields.impl.AbstractCustomFieldType
assertObjectImplementsType, availableForBulkEdit, getDescription, getDescriptor, getI18nBean, getKey, getName, getRelatedIndexers, getVelocityParameters, init, isRenderable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.atlassian.jira.issue.customfields.CustomFieldType
availableForBulkEdit, createValue, getChangelogValue, getDescription, getDescriptor, getKey, getName, getRelatedIndexers, getValueFromIssue, init, isRenderable, updateValue
 

Field Detail

COMMA_REPLACEMENT

public static final String COMMA_REPLACEMENT
See Also:
Constant Field Values
Constructor Detail

MultiSelectCFType

public MultiSelectCFType(OptionsManager optionsManager,
                         CustomFieldValuePersister valuePersister,
                         GenericConfigManager genericConfigManager,
                         JiraBaseUrls jiraBaseUrls,
                         SearchService searchService,
                         FeatureManager featureManager)
Method Detail

remove

public Set<Long> remove(CustomField field)
Description copied from class: AbstractMultiCFType
called when removing a field. return issue IDs affected.

Subclasses should override this if they have specific cleanup that they need to do (such as removing select list values)

Specified by:
remove in interface CustomFieldType<Collection<Option>,Option>
Overrides:
remove in class AbstractMultiCFType<Option>
Parameters:
field - The custom field that is being removed, so any data stored for any issues for that field can be deleted.
Returns:
Set of issue ids that has been affected

getOptions

public Options getOptions(FieldConfig fieldConfig,
                          JiraContextNode jiraContextNode)
Description copied from interface: MultipleCustomFieldType
Returns all possible Options for this field.

Specified by:
getOptions in interface MultipleCustomFieldType<Collection<Option>,Option>
Parameters:
fieldConfig - configuration for this field
jiraContextNode - context
Returns:
all possible Options for this field.

removeValue

public void removeValue(CustomField field,
                        Issue issue,
                        Option option)
Description copied from interface: MultipleSettableCustomFieldType
Perform any actions required if the option selected by the issue is removed.

Specified by:
removeValue in interface MultipleSettableCustomFieldType<Collection<Option>,Option>
Parameters:
field - being edited
issue - to remove stuff from
option - option being removed.

getIssueIdsWithValue

public Set<Long> getIssueIdsWithValue(CustomField field,
                                      Option option)
Description copied from interface: MultipleSettableCustomFieldType
Returns a Set of issue ids (Long) that have the given option selected.

Specified by:
getIssueIdsWithValue in interface MultipleSettableCustomFieldType<Collection<Option>,Option>
Parameters:
field - the CustomField to search on
option - the Object representing a single value to search on.
Returns:
Set of Longs

getDatabaseType

@Nonnull
protected PersistenceFieldType getDatabaseType()
Description copied from class: AbstractMultiCFType
Type of database field needed to store this field.

Specified by:
getDatabaseType in class AbstractMultiCFType<Option>
Returns:
One of the predefined PersistenceFieldType types.

convertDbValueToType

protected Option convertDbValueToType(Object dbValue)
Description copied from class: AbstractMultiCFType
Converts a given db value to Single form of Transport Object

Specified by:
convertDbValueToType in class AbstractMultiCFType<Option>
Parameters:
dbValue - db representation as returned by AbstractMultiCFType.convertTypeToDbValue(Object)
Returns:
Single form of Transport Object

convertTypeToDbValue

protected Object convertTypeToDbValue(Option value)
Description copied from class: AbstractMultiCFType
Converts a given underlying type to its db storage value. Must be compatable with PersistenceFieldType returned by AbstractMultiCFType.getDatabaseType()

Specified by:
convertTypeToDbValue in class AbstractMultiCFType<Option>
Parameters:
value - Single form of Transport Object
Returns:
database representation of given Transport Object.

getTypeComparator

protected Comparator<Option> getTypeComparator()
Description copied from class: AbstractMultiCFType
Returns a comparator for underlying type of this custom field. Used e.g. for sorting values retrieved from the Database

Specified by:
getTypeComparator in class AbstractMultiCFType<Option>
Returns:
a comparator, null if can't be compared without extra context

setDefaultValue

public void setDefaultValue(FieldConfig fieldConfig,
                            Collection<Option> value)
Description copied from class: AbstractMultiCFType
Sets the default value for a Custom Field.

Specified by:
setDefaultValue in interface CustomFieldType<Collection<Option>,Option>
Overrides:
setDefaultValue in class AbstractMultiCFType<Option>
Parameters:
fieldConfig - CustomField for which the default is being stored
value - Transport Object representing the value instance of the CustomField.
See Also:
CustomFieldType.setDefaultValue(com.atlassian.jira.issue.fields.config.FieldConfig,Object)

getDefaultValue

public Collection<Option> getDefaultValue(FieldConfig fieldConfig)
Description copied from interface: CustomFieldType
Retrieves the Object representing the default CustomField value for the Custom Field.

Specified by:
getDefaultValue in interface CustomFieldType<Collection<Option>,Option>
Overrides:
getDefaultValue in class AbstractMultiCFType<Option>
Parameters:
fieldConfig - CustomField for default value
Returns:
Transport Object of the Default Value
See Also:
CustomFieldType.getDefaultValue(com.atlassian.jira.issue.fields.config.FieldConfig)

getValueFromCustomFieldParams

public Collection<Option> getValueFromCustomFieldParams(CustomFieldParams parameters)
                                                 throws FieldValidationException
Description copied from interface: CustomFieldType
Retrieves the Transport Object representing the CustomField value instance from the CustomFieldParams of Strings.

Specified by:
getValueFromCustomFieldParams in interface CustomFieldType<Collection<Option>,Option>
Parameters:
parameters - CustomFieldParams of String objects. Will contain one value for Singular field types.
Returns:
Transport Object matching the Object parameter of CustomFieldType.createValue(com.atlassian.jira.issue.fields.CustomField, com.atlassian.jira.issue.Issue, T), CustomFieldType.updateValue(com.atlassian.jira.issue.fields.CustomField, com.atlassian.jira.issue.Issue, T)
Throws:
FieldValidationException - if the String value fails to convert into Objects
See Also:
CustomFieldType.createValue(com.atlassian.jira.issue.fields.CustomField, com.atlassian.jira.issue.Issue, Object), CustomFieldType.updateValue(com.atlassian.jira.issue.fields.CustomField, com.atlassian.jira.issue.Issue, Object), CustomFieldType.getValueFromIssue(com.atlassian.jira.issue.fields.CustomField, com.atlassian.jira.issue.Issue)

getStringValueFromCustomFieldParams

public Object getStringValueFromCustomFieldParams(CustomFieldParams parameters)
Description copied from interface: CustomFieldType
Return the String value object from the CustomFieldParams. The object may be a single String (e.g. TextCFType, List of Strings (e.g. MultiSelectCFType) or CustomFieldParams of Strings (e.g. CascadingSelectCFType). Among other things these values are passed to Velocity for rendering edit screens.

Specified by:
getStringValueFromCustomFieldParams in interface CustomFieldType<Collection<Option>,Option>
Parameters:
parameters - - CustomFieldParams containing String values
Returns:
String value object from the CustomFieldParams

validateFromParams

public void validateFromParams(CustomFieldParams relevantParams,
                               ErrorCollection errorCollectionToAddTo,
                               FieldConfig config)
Description copied from interface: CustomFieldType
Ensures that the CustomFieldParams of Strings is a valid representation of the Custom Field values. Any errors should be added to the ErrorCollection under the appropriate key as required.

Specified by:
validateFromParams in interface CustomFieldType<Collection<Option>,Option>
Parameters:
relevantParams - parameter object of Strings
errorCollectionToAddTo - errorCollection to which any erros should be added (never null)
config - FieldConfig

getChangelogString

public String getChangelogString(CustomField field,
                                 Collection<Option> value)
Description copied from interface: CustomFieldType
Returns a String of representing values to be stored in the change log, an example is the name of a version field that a version id will resolve to within JIRA.

Specified by:
getChangelogString in interface CustomFieldType<Collection<Option>,Option>
Overrides:
getChangelogString in class AbstractCustomFieldType<Collection<Option>,Option>
Parameters:
field - CustomField that the value belongs to
value - Transport Object representing the value instance of the CustomField
Returns:
Change log string.

getSingularObjectFromString

public Option getSingularObjectFromString(String string)
                                   throws FieldValidationException
Description copied from interface: CustomFieldType
Returns a Singular Object, given the string value as passed by the presentation tier. Throws FieldValidationException if the string is an invalid representation of the Object.

Specified by:
getSingularObjectFromString in interface CustomFieldType<Collection<Option>,Option>
Parameters:
string - the String
Returns:
singularObject instance
Throws:
FieldValidationException - if the string is an invalid representation of the Object.

getStringFromSingularObject

public String getStringFromSingularObject(Option optionObject)
Description copied from interface: CustomFieldType
Returns the String representation of a single value within the CustomFieldType. This is the value that is passed to the presentation tier for editing. For single CustomFieldTypes the Singular Object is the same as a Transport Object. However, for multi-dimensional CustomFieldTypes, the Singular Object is the Object contained within the Collection or Map

Specified by:
getStringFromSingularObject in interface CustomFieldType<Collection<Option>,Option>
Parameters:
optionObject - the object
Returns:
String representation of the Object

getConfigurationItemTypes

@Nonnull
public List<FieldConfigItemType> getConfigurationItemTypes()
Description copied from interface: CustomFieldType
Returns a List of FieldConfigItemType objects. Can not be immutable. This opens up possibilities for configurable custom fields.

Specified by:
getConfigurationItemTypes in interface CustomFieldType<Collection<Option>,Option>
Overrides:
getConfigurationItemTypes in class AbstractCustomFieldType<Collection<Option>,Option>
Returns:
List of FieldConfigItemType

compare

public int compare(@Nonnull
                   List<String> customFieldObjectValue1,
                   @Nonnull
                   List<String> customFieldObjectValue2,
                   FieldConfig fieldConfig)
Description copied from interface: SortableCustomField
Compares the two custom field objects.

Specified by:
compare in interface SortableCustomField<List<String>>
Parameters:
customFieldObjectValue1 - Never null
customFieldObjectValue2 - Never null
Returns:
0, 1 or -1

getProjectImporter

public ProjectCustomFieldImporter getProjectImporter()
Description copied from interface: ProjectImportableCustomField
Returns the object that will perform the actual project import functions for the custom field type.

Specified by:
getProjectImporter in interface ProjectImportableCustomField
Returns:
the object that will perform the actual project import functions for the custom field type.

extractTransferObjectFromString

public static Collection<String> extractTransferObjectFromString(String value)
Parses the given comma-separated String value into a Collection. Whitespace is trimmed and blank fields are discarded. If literal commas are required, then they can be escaped with a backslash. Therefore the input String "red, white\, and blue" would produce two tokens in its list:

Parameters:
value - The comma-separated input String.
Returns:
Collection of tokens parsed from the input value.
See Also:
getStringFromTransferObject(java.util.Collection)

getStringFromTransferObject

public static String getStringFromTransferObject(Collection<String> collection)
Takes a Collection of values and creates a comma-separated String that represents this Collection.

If any items in the collection include literal commas, then these commas are escaped with a prepended backslash. eg a list that looks like:

Will be turned into a string that looks like "All sorts,Tom\, Dick\, and Harry"

Parameters:
collection - a collection of Strings to be comma separated

valuesEqual

public boolean valuesEqual(Collection<Option> v1,
                           Collection<Option> v2)
Description copied from interface: CustomFieldType
Used to compare 2 field values and work out whether a change item should be generated

Specified by:
valuesEqual in interface CustomFieldType<Collection<Option>,Option>
Overrides:
valuesEqual in class AbstractCustomFieldType<Collection<Option>,Option>
Parameters:
v1 - current value
v2 - new value
Returns:
true if the change item should be generated, false otherwise

accept

public Object accept(AbstractCustomFieldType.VisitorBase visitor)
Overrides:
accept in class AbstractMultiCFType<Option>

getQueryForGroup

public org.apache.lucene.search.Query getQueryForGroup(String fieldID,
                                                       String groupName)
Description copied from interface: GroupSelectorField
This method should be implemented in your custom type to return a Query. Generally you should return a TermQuery in the form of fieldName:groupName. However some custom fields, such as (@Link SelectCFType) manipulate the field identifiers and values before storing in the index. In cases like this you will have to implement the method such that it searches the correct fields.

Specified by:
getQueryForGroup in interface GroupSelectorField
Parameters:
fieldID - the id of the custom field
groupName - the name of the group to filter on
Returns:
the (@Link Query) to pass to the searcher

getFieldTypeInfo

public FieldTypeInfo getFieldTypeInfo(FieldTypeInfoContext fieldTypeInfoContext)
Description copied from interface: RestAwareCustomFieldType
Returns lower level Information about the field. This information contains allowed values and/or the autocomplete url

Specified by:
getFieldTypeInfo in interface RestAwareCustomFieldType
Parameters:
fieldTypeInfoContext - context information for generating the FieldTypeInfo.
Returns:
Low level information about the field.

getJsonSchema

public JsonType getJsonSchema(CustomField customField)
Description copied from interface: RestAwareCustomFieldType
Return a description of the shape of this field when represented as JSON.

Specified by:
getJsonSchema in interface RestAwareCustomFieldType

getJsonFromIssue

public FieldJsonRepresentation getJsonFromIssue(CustomField field,
                                                Issue issue,
                                                boolean renderedVersionRequested,
                                                @Nullable
                                                FieldLayoutItem fieldLayoutItem)
Description copied from interface: RestAwareCustomFieldType
Return a JsonData representation of the field value

Specified by:
getJsonFromIssue in interface RestAwareCustomFieldType
Parameters:
field - configuration of the current field
issue - to get field data from
renderedVersionRequested - whether the use requested the return of rendered/pretty data as well as raw data
fieldLayoutItem - field layout for this field.
Returns:
FieldJsonDataPair containing a json representation of the raw data for this field, and if required, a json representation of the rendered data for easy display.

getJsonDefaultValue

public JsonData getJsonDefaultValue(IssueContext issueCtx,
                                    CustomField field)
Description copied from interface: RestCustomFieldTypeOperations
Return The default data for this system field. May be null if there is no default.

Specified by:
getJsonDefaultValue in interface RestCustomFieldTypeOperations
Parameters:
issueCtx - Issue (This should really only need to be an issue context, but for historical reasons we need an issue object.
field - the Custom Field
Returns:
The default data for this system field.

getRestFieldOperation

public RestFieldOperationsHandler getRestFieldOperation(CustomField field)
Description copied from interface: RestCustomFieldTypeOperations
Returns the RestFieldOperationsHandler for this field.

Specified by:
getRestFieldOperation in interface RestCustomFieldTypeOperations
Parameters:
field - the Custom Field
Returns:
the RestFieldOperationsHandler for this field.

getVelocityParameters

@Nonnull
public Map<String,Object> getVelocityParameters(Issue issue,
                                                        CustomField field,
                                                        FieldLayoutItem fieldLayoutItem)
Description copied from interface: CustomFieldType
The custom field may wish to pass parameters to the velocity context beyond the getValueFromIssue methods (eg managers).

The values are added to the context for all velocity views (edit, search, view, xml)

Specified by:
getVelocityParameters in interface CustomFieldType<Collection<Option>,Option>
Overrides:
getVelocityParameters in class AbstractCustomFieldType<Collection<Option>,Option>
Parameters:
issue - The issue currently in context (Note: this will be null in cases like 'default value')
field - CustomField
fieldLayoutItem - FieldLayoutItem
Returns:
A Map of parameters to add to the velocity context, or an empty Map otherwise (never null)


Copyright © 2002-2014 Atlassian. All Rights Reserved.