com.atlassian.jira.issue.customfields.impl
Class AbstractMultiCFType<S>

java.lang.Object
  extended by com.atlassian.jira.issue.customfields.impl.AbstractCustomFieldType<Collection<S>,S>
      extended by com.atlassian.jira.issue.customfields.impl.AbstractMultiCFType<S>
Type Parameters:
S - Single object contained within the Collection Transport Object
All Implemented Interfaces:
CustomFieldType<Collection<S>,S>
Direct Known Subclasses:
MultiGroupCFType, MultiSelectCFType, MultiUserCFType, VersionCFType

@PublicSpi
public abstract class AbstractMultiCFType<S>
extends AbstractCustomFieldType<Collection<S>,S>

Abstract class for Multi-select Custom field types. Note that there is also another multi-select Custom Field for arbitrary Options - (MultiSelectCFType which lives in jira-core).

The Transport Object for this Custom Field type is a Collection of S, where S is defined by the subclass Data is stored in the database a representations of a single S. E.g. A Custom Field that stores multiple Users, will have each user saved seperately as an Object defined by convertTypeToDbValue(S) See the javadoc of CustomFieldType.updateValue(com.atlassian.jira.issue.fields.CustomField,com.atlassian.jira.issue.Issue,Object), CustomFieldType.createValue(com.atlassian.jira.issue.fields.CustomField,com.atlassian.jira.issue.Issue,Object), and CustomFieldType.setDefaultValue(com.atlassian.jira.issue.fields.config.FieldConfig,Object) for instance.

See Also:
CustomFieldType

Nested Class Summary
static interface AbstractMultiCFType.Visitor<X>
           
 
Nested classes/interfaces inherited from class com.atlassian.jira.issue.customfields.impl.AbstractCustomFieldType
AbstractCustomFieldType.VisitorBase<X>
 
Field Summary
protected  CustomFieldValuePersister customFieldValuePersister
           
protected  GenericConfigManager genericConfigManager
           
 
Fields inherited from interface com.atlassian.jira.issue.customfields.CustomFieldType
DEFAULT_VALUE_TYPE
 
Constructor Summary
protected AbstractMultiCFType(CustomFieldValuePersister customFieldValuePersister, GenericConfigManager genericConfigManager)
           
 
Method Summary
 Object accept(AbstractCustomFieldType.VisitorBase visitor)
           
protected  Collection<S> convertDbObjectToTypes(Collection<Object> dbObjects)
          Converts a collection of objects representing the underlying type to a collection of underlying types.
protected abstract  S convertDbValueToType(Object dbValue)
          Converts a given db value to Single form of Transport Object
protected  Collection<Object> convertTypesToDbObjects(Collection<S> typedList)
          Converts a collection of underlying types to a collection of db representations of underlying type.
protected abstract  Object convertTypeToDbValue(S value)
          Converts a given underlying type to its db storage value.
 void createValue(CustomField customField, Issue issue, Collection<S> value)
          Create a multi-select value for an issue.
 String getChangelogValue(CustomField field, Collection<S> values)
          Returns a string representation of the value if not null.
protected abstract  PersistenceFieldType getDatabaseType()
          Type of database field needed to store this field.
 Collection<S> getDefaultValue(FieldConfig fieldConfig)
          Retrieves the Object representing the default CustomField value for the Custom Field.
protected abstract  Comparator<S> getTypeComparator()
          Returns a comparator for underlying type of this custom field.
 Collection<S> getValueFromIssue(CustomField field, Issue issue)
          Retrieves the Transport Object representing the current CustomField value for the given issue.
 Set<Long> remove(CustomField field)
          called when removing a field.
 void setDefaultValue(FieldConfig fieldConfig, Collection<S> value)
          Sets the default value for a Custom Field.
 void updateValue(CustomField customField, Issue issue, Collection<S> value)
          Update a multi-select value for an issue.
 
Methods inherited from class com.atlassian.jira.issue.customfields.impl.AbstractCustomFieldType
assertObjectImplementsType, availableForBulkEdit, getChangelogString, getConfigurationItemTypes, getDescription, getDescriptor, getI18nBean, getKey, getName, getRelatedIndexers, getVelocityParameters, getVelocityParameters, init, isRenderable, valuesEqual
 
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
getSingularObjectFromString, getStringFromSingularObject, getStringValueFromCustomFieldParams, getValueFromCustomFieldParams, validateFromParams
 

Field Detail

customFieldValuePersister

protected final CustomFieldValuePersister customFieldValuePersister

genericConfigManager

protected final GenericConfigManager genericConfigManager
Constructor Detail

AbstractMultiCFType

protected AbstractMultiCFType(CustomFieldValuePersister customFieldValuePersister,
                              GenericConfigManager genericConfigManager)
Method Detail

getTypeComparator

@Nullable
protected abstract Comparator<S> getTypeComparator()
Returns a comparator for underlying type of this custom field. Used e.g. for sorting values retrieved from the Database

Returns:
a comparator, null if can't be compared without extra context

convertTypeToDbValue

@Nullable
protected abstract Object convertTypeToDbValue(@Nullable
                                                        S value)
Converts a given underlying type to its db storage value. Must be compatable with PersistenceFieldType returned by getDatabaseType()

Parameters:
value - Single form of Transport Object
Returns:
database representation of given Transport Object.

convertDbValueToType

@Nullable
protected abstract S convertDbValueToType(@Nullable
                                                   Object dbValue)
Converts a given db value to Single form of Transport Object

Parameters:
dbValue - db representation as returned by convertTypeToDbValue(Object)
Returns:
Single form of Transport Object

getDatabaseType

@NotNull
protected abstract PersistenceFieldType getDatabaseType()
Type of database field needed to store this field.

Returns:
One of the predefined PersistenceFieldType types.

getDefaultValue

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

Parameters:
fieldConfig - CustomField for default value
Returns:
Transport Object of the Default Value
See Also:
CustomFieldType.getDefaultValue(com.atlassian.jira.issue.fields.config.FieldConfig)

setDefaultValue

public void setDefaultValue(FieldConfig fieldConfig,
                            Collection<S> value)
Sets the default value for a Custom Field.

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)

createValue

public void createValue(CustomField customField,
                        Issue issue,
                        Collection<S> value)
Create a multi-select value for an issue.

Parameters:
customField - CustomField for which the value is being stored
issue - The Issue.
value - Transport Object representing the value instance of the CustomField.
See Also:
CustomFieldType.createValue(com.atlassian.jira.issue.fields.CustomField,com.atlassian.jira.issue.Issue,Object)

updateValue

public void updateValue(CustomField customField,
                        Issue issue,
                        Collection<S> value)
Update a multi-select value for an issue.

Parameters:
customField - CustomField for which the value is being stored
issue - The Issue.
value - Transport Object representing the value instance of the CustomField.
See Also:
CustomFieldType.updateValue(com.atlassian.jira.issue.fields.CustomField,com.atlassian.jira.issue.Issue,Object)

getValueFromIssue

public Collection<S> getValueFromIssue(CustomField field,
                                       Issue issue)
Description copied from interface: CustomFieldType
Retrieves the Transport Object representing the current CustomField value for the given issue.

Parameters:
field - Custom field for which to retrieve the value
issue - Issue from which to retrieve the value
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)
See Also:
CustomFieldType.getValueFromIssue(com.atlassian.jira.issue.fields.CustomField,com.atlassian.jira.issue.Issue)

getChangelogValue

public String getChangelogValue(CustomField field,
                                Collection<S> values)
Returns a string representation of the value if not null.

Parameters:
field - not used
values - value to create a change log for
Returns:
string representaion of value if not null, empty string otherwise

convertTypesToDbObjects

protected final Collection<Object> convertTypesToDbObjects(Collection<S> typedList)
Converts a collection of underlying types to a collection of db representations of underlying type.

If a Collection of String is passed, then a new Collection is still created, containing the original String values.

Parameters:
typedList - a collection of underlying types
Returns:
a collection of string representations of underlying type

convertDbObjectToTypes

protected final Collection<S> convertDbObjectToTypes(Collection<Object> dbObjects)
Converts a collection of objects representing the underlying type to a collection of underlying types. Returns empty list when given strings collection is null.

Parameters:
dbObjects - collection of db representations of types.
Returns:
a collection of underlying types

remove

public Set<Long> remove(CustomField field)
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)

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

accept

public Object accept(AbstractCustomFieldType.VisitorBase visitor)
Overrides:
accept in class AbstractCustomFieldType<Collection<S>,S>


Copyright © 2002-2012 Atlassian. All Rights Reserved.