Class AbstractSingleFieldType<T>
java.lang.Object
com.atlassian.jira.issue.customfields.impl.AbstractCustomFieldType<T,T>
com.atlassian.jira.issue.customfields.impl.AbstractSingleFieldType<T>
- All Implemented Interfaces:
CustomFieldType<T,
T>
- Direct Known Subclasses:
DateCFType
,DateTimeCFType
,GenericTextCFType
,NumberCFType
,ProjectCFType
,SelectCFType
,StringCFType
,UserCFType
An abstract class that simplifies creating a CustomField that stores
a single values via ofbiz. Possible values to store are:
- Short text (< 255 chars)
FIELD_TYPE_STRING
- Long text (unlimited)
FIELD_TYPE_TEXT
- Floating point values
FIELD_TYPE_NUMBER
- Date values
FIELD_TYPE_DATE
- In Memory Object (aka Transport Object)
- This is used as the primary version of the custom field value. This
is what is passed to the view layer. An example would be a
User
or aGenericValue
representing a project. - String representation
- When editing a custom field value, it needs to be send to the web browser and received in text format. The in Memory Object mentioned above must have a text representation of itself, and be able to parse it. This is the value passed to the edit template. An example would be a username, or project id.
- Database representation (required if storing in a database)
- A custom field can be stored in a database, and there needs to be a way of getting from the object value to the database value. An example of this would be the project id.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class com.atlassian.jira.issue.customfields.impl.AbstractCustomFieldType
AbstractCustomFieldType.VisitorBase<X>
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final CustomFieldValuePersister
protected static final String
protected static final String
protected static final String
protected static final String
protected final GenericConfigManager
protected static final org.apache.log4j.Logger
Fields inherited from interface com.atlassian.jira.issue.customfields.CustomFieldType
DEFAULT_VALUE_TYPE, RESOURCE_PREVIEW
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractSingleFieldType
(CustomFieldValuePersister customFieldValuePersister, GenericConfigManager genericConfigManager) -
Method Summary
Modifier and TypeMethodDescriptionvoid
createValue
(CustomField field, Issue issue, T value) At this point we know that the value doesn't exist, and thatis not null. getChangelogValue
(CustomField field, T value) Returns a values to be stored in the change log, example is the id of the changed item.protected abstract PersistenceFieldType
Type of database field needed to store this field.protected abstract Object
getDbValueFromObject
(T customFieldObject) Returns the database representation of the Java object as stored for that CustomField.getDefaultValue
(FieldConfig fieldConfig) Retrieves the Object representing the default CustomField value for the Custom Field.getJsonDefaultValue
(IssueContext issueCtx, CustomField field) protected abstract T
getObjectFromDbValue
(Object databaseValue) Returns the Transport Object for the given Custom Field value as represented by the value stored in the databasegetStringValueFromCustomFieldParams
(CustomFieldParams parameters) Return the String value object from the CustomFieldParams.getValueFromCustomFieldParams
(CustomFieldParams relevantParams) Retrieves the Transport Object representing the CustomField value instance from the CustomFieldParams of Strings.getValueFromIssue
(CustomField field, Issue issue) Retrieves the Transport Object representing the current CustomField value for the given issue.protected T
getValueFromIssue
(CustomField field, Long issueId, String issueKey) Retrieve the current value of the customfield in the DB based on issue id.remove
(CustomField field) called when removing a field.void
setDefaultValue
(FieldConfig fieldConfig, T value) Sets the default value for a Custom Fieldvoid
updateValue
(CustomField customField, Issue issue, T value) the value does exist, and the new value is different than the existing one.void
validateFromParams
(CustomFieldParams relevantParams, ErrorCollection errorCollectionToAddTo, FieldConfig config) Ensures that theCustomFieldParams
of Strings is a valid representation of the Custom Field values.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
areAllRequiredParametersPresent, getCloneOptionConfiguration, getCloneValue, getNonNullCustomFieldProvider, getSingularObjectFromString, getStringFromSingularObject, isUserInputRequiredForMove
-
Field Details
-
log
protected static final org.apache.log4j.Logger log -
FIELD_TYPE_STRING
- See Also:
-
FIELD_TYPE_TEXT
- See Also:
-
FIELD_TYPE_DATE
- See Also:
-
FIELD_TYPE_NUMBER
- See Also:
-
customFieldValuePersister
-
genericConfigManager
-
-
Constructor Details
-
AbstractSingleFieldType
protected AbstractSingleFieldType(CustomFieldValuePersister customFieldValuePersister, GenericConfigManager genericConfigManager)
-
-
Method Details
-
getValueFromIssue
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 valueissue
- 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)
-
getValueFromIssue
@Nullable protected T getValueFromIssue(@Nonnull CustomField field, @Nullable Long issueId, @Nullable String issueKey) Retrieve the current value of the customfield in the DB based on issue id.Could be used directly in sub-classes when we don't have the full issue object.
- Parameters:
field
- the customfieldissueId
- the id of the issueissueKey
- the issue key. optional, only used for logging purpose- Returns:
- the value object
-
remove
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)
-
createValue
At this point we know that the value doesn't exist, and thatis not null. - Parameters:
field
-CustomField
for which the value is being storedissue
- TheIssue
to be stored against.value
- Transport Object representing the value instance of the CustomField. Can not benull
.
-
updateValue
the value does exist, and the new value is different than the existing one.- Parameters:
customField
-CustomField
for which the value is being storedissue
- TheIssue
to be stored against.value
- Transport Object representing the value instance of the CustomField.
-
setDefaultValue
Description copied from interface:CustomFieldType
Sets the default value for a Custom Field- Parameters:
fieldConfig
- CustomField for which the default is being storedvalue
- Transport Object representing the value instance of the CustomField
-
getDefaultValue
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
-
validateFromParams
public void validateFromParams(CustomFieldParams relevantParams, ErrorCollection errorCollectionToAddTo, FieldConfig config) Description copied from interface:CustomFieldType
Ensures that theCustomFieldParams
of Strings is a valid representation of the Custom Field values. Any errors should be added to theErrorCollection
under the appropriate key as required.- Parameters:
relevantParams
- parameter object of StringserrorCollectionToAddTo
- errorCollection to which any errors should be added (never null)config
- FieldConfig
-
getValueFromCustomFieldParams
public T getValueFromCustomFieldParams(CustomFieldParams relevantParams) throws FieldValidationException Description copied from interface:CustomFieldType
Retrieves the Transport Object representing the CustomField value instance from the CustomFieldParams of Strings.- Parameters:
relevantParams
- 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
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.- Parameters:
parameters
- - CustomFieldParams containing String values- Returns:
- String value object from the CustomFieldParams
-
getChangelogValue
Description copied from interface:CustomFieldType
Returns a values to be stored in the change log, example is the id of the changed item.- Parameters:
field
- CustomField that the value belongs tovalue
- Transport Object representing the value instance of the CustomField- Returns:
- Change log value.
-
getDatabaseType
Type of database field needed to store this field.- Returns:
- One of the predefined
PersistenceFieldType
types.
-
getDbValueFromObject
Returns the database representation of the Java object as stored for that CustomField. (eg. ProjectId if the Value represents a project). Must be compatable with type returned bygetDatabaseType()
- Parameters:
customFieldObject
- the Transport Object- Returns:
- String, Double or Date
-
getObjectFromDbValue
@Nullable protected abstract T getObjectFromDbValue(@Nonnull Object databaseValue) throws FieldValidationException Returns the Transport Object for the given Custom Field value as represented by the value stored in the database- Parameters:
databaseValue
- - String, Double or Date objects as returned fromgetDbValueFromObject(Object)
- Returns:
- Domain object or GenericValue
- Throws:
FieldValidationException
- if field validation fails.
-
accept
- Overrides:
accept
in classAbstractCustomFieldType<T,
T>
-
getJsonDefaultValue
-