无法理解,getSingularObjectFromString方法有什么作用? [英] Can't understand, what does method getSingularObjectFromString do?

查看:100
本文介绍了无法理解,getSingularObjectFromString方法有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在JIRA中开发自己的自定义字段类型. 我的课程很简单,它扩展了GenericTextCFType. 我的目标是在数据库中存储字段值的某些标识符(ID),但在问题"表单上显示该字段值的人类可读标题.

I'm developing own custom field type in JIRA. My class is very simple, it extends GenericTextCFType. My goal is to store some identifier (ID) of field value in database but to show human-readable caption of the field value on Issue form.

我搜索了GenericTextCFType类的方法,找到了getSingularObjectFromString方法,但我不明白它的作用. JIRA javadoc说:给定表示层传递的字符串值,返回一个奇异对象" 但是什么是奇异对象,它需要什么呢?

I searched methods of GenericTextCFType class and found method getSingularObjectFromString, and I don't understand, what it does. JIRA javadoc says: "Returns a Singular Object, given the string value as passed by the presentation tier" But what is the Singular Object and what is it needed for?

推荐答案

是的,这不是一个好名字.我在实用JIRA插件"中详细介绍了它 (奥莱利).这是其中的摘录,其中详细描述了许多方法(对格式表示抱歉).该书还提供了工作示例,可在 https://bitbucket.org/mdoar/practical-jira-plugins中找到

Yes, it's not a great name. I wrote about it in detail in "Practical JIRA Plugins" (O'Reilly). Here's an extract from there describing many of the methods in detail (sorry about the formatting). The book also has worked examples available at https://bitbucket.org/mdoar/practical-jira-plugins

CustomFieldType方法 该示例的自定义字段类型类将照常实现CustomFieldType接口,但将在继承层次结构中扩展一个比NumberCFType高的类.我们将扩展的类是AbstractCustomFieldType,它是大多数实现CustomFieldType的类的根.

CustomFieldType Methods The example’s custom field type class will implement the CustomFieldType interface as usual, but instead will extend a class higher up in the inheritance hierarchy than NumberCFType. The class we will extend is AbstractCustomFieldType and it’s at the root of most classes that implement CustomFieldType.

CustomFieldType接口中名称为"SingularObject"的方法引用单个对象,在本示例中为Carrier对象. JIRA 4自定义字段中引用对象的所有其他方法都引用传输对象,例如,载波对象的集合. JIRA 5删除了大多数自定义字段方法中对Object的使用. 有关JIRA 5.0中带有自定义字段的更改的更多信息,请参见 https://developer.atlassian.com/display/JIRADEV/Java+API+Changes+in+JIRA+5.0#JavaAPIChangesinJIRA5.0-CustomFieldTypes .类层次结构发生了一些重大变化,现在大多数类都将Java泛型作为参数,而不再像以前那样使用Object.

The methods in the CustomFieldType interface with "SingularObject" in their name refer to the singular object, in this example a Carrier object. All other methods in JIRA 4 custom fields that refer to an Object are referring the transport object, e.g., a Collection of Carrier objects. JIRA 5 removed the use of Object in most custom field methods. For more information about what changed in JIRA 5.0 with custom fields see https://developer.atlassian.com/display/JIRADEV/Java+API+Changes+in+JIRA+5.0#JavaAPIChangesinJIRA5.0-CustomFieldTypes. There were some major changes in the class hierarchy, and most classes now have a Java generic as a parameter instead of just using an Object as before.

通常将两个对象注入到自定义字段类型的类的构造函数中.第一个是CustomFieldValuePersister持久性对象,该对象实际上将与数据库进行交互.第二个是GenericConfigManager对象,用于存储和检索自定义字段的默认值.根据需要将其他对象注入到构造函数中,例如,示例2-2中的DoubleConverter. 第一组要考虑的方法是自定义字段类型用于以某种方式与数据库交互的方法.

There are two objects that are typically injected into the constructor of a custom field type’s class. The first is a CustomFieldValuePersister persister object, which is what will actually interact with the database. The second is a GenericConfigManager object that is used for storing and retrieving default values for the custom field. Other objects are injected into the constructor as needed—for example, the DoubleConverter in Example 2-2. The first set of methods to consider are the ones that the custom field type uses to interact with the database in some way.

getSingularObjectFromString()

此方法将从数据库中获取的字符串(例如"42.0 ###答案")转换为Carrier对象.空值表示未定义此类对象.

This method converts a string taken from the database such as "42.0###The answer" into a Carrier object. A null value means that there is no such object defined.

具有多个值的字段

Collection<Carrier> getValueFromIssue(CustomField field, Issue issue)

这是提取给定问题字段包含的主要方法.它使用持久性从数据库中获取问题的值,将每个值转换为一个Carrier对象,然后将所有Carrier对象放入一个运输对象Collection中.空值表示此字段没有为给定问题存储任何值.这是在JIRA 5.0之前用于返回Object的方法之一.

This is the main method for extracting what a field contains for a given issue. It uses the persister to retrieve the values from the database for the issue, converts each value into a Carrier object and then puts all the Carrier objects into a trans- port object Collection. A null value means that this field has no value stored for the given issue. This is one of the methods that used to return an Object before JIRA 5.0

createValue(CustomField field, Issue issue, Collection<Carrier> value)
updateValue(CustomField field, Issue issue, Collection<Carrier> value)

这些方法为给定问题中的字段创建一个新值或更新现有值.执行此操作的持久性程序希望存储字符串集合,因此这两个方法都调用方法getDbValueFromCollection来帮助实现此目的.

These methods create a new value or update an existing value for the field in the given issue. The persister that does this expects a Collection of Strings to store, so both of these methods call the method getDbValueFromCollection to help with that.

getDbValueFromCollection()

在许多自定义字段类型类中找到的私有便捷方法,有时使用不同的名称.它用于将运输对象(例如,载体对象的集合)转换为字符串集合,以存储在数据库中.

A private convenience method found in many custom field type classes, sometimes with a different name. It is used to convert a transport object (e.g., a Collection of Carrier objects) to a Collection of Strings for storing in the database.

setDefaultValue(FieldConfig fieldConfig, Collection<Carrier> value)

将传输对象(运营商对象集合)转换为其数据库表示形式,并将其存储在通用配置表中的数据库中.

Convert a transport object (a Collection of Carrier objects) to its database repre- sentation and store it in the database in the genericconfiguration table.

Collection<Carrier> getDefaultValue(FieldConfig fieldConfig)

从数据库中检索默认值(如果有),并将其转换为传输对象(Carrier对象的集合). FieldConfig对象代表了自定义字段中每个默认值的上下文.

Retrieve a default value, if any, from the database and convert it to a transport object (a Collection of Carrier objects). The FieldConfig object is what represents the context of each default value in a custom field.

要考虑的下一组方法是与网页进行某种方式交互的方法.网页中的所有值都作为Custom FieldParams对象的一部分到达一个自定义字段类型对象,该对象是HTML输入元素的值的Map的持有人.

The next set of methods to consider are the ones that interact with a web page in some way. All values from web pages arrive at a custom field type object as part of a Custom FieldParams object, which is a holder for a Map of the values of the HTML input elements.

validateFromParams(CustomFieldParams params, ErrorCollection errors, FieldConfig config)

这是用户编辑自定义字段的值后调用的第一个方法.此处记录的任何错误都将很好地显示在编辑页面中该字段的旁边.

This is the first method that is called after a user has edited a custom field’s value. Any errors recorded here will be nicely displayed next to the field in the edit page.

getValueFromCustomFieldParams(CustomFieldParams customFieldParams)

在此方法中,将验证ValidFromParams接受的字段的新值清除并转换为传输对象.自定义FieldParams对象将仅包含名称属性为自定义字段ID(例如customfield_10010)的HTML元素的字符串.空值表示此字段没有任何值.

This method is where a new value for a field that has been accepted by validate FromParams is cleaned and converted into a transport object. The custom FieldParams object will only contain strings for the HTML elements with a name attribute that is the custom field ID—e.g., customfield_10010. A null value means that there is no value for this field.

getStringValueFromCustomFieldParams(CustomFieldParams parameters)

此方法返回一个对象,该对象可能是String,String的集合,甚至是CustomFieldParams对象.用于填充第3章:高级自定义字段类型速度模板中使用的value变量.自定义字段搜索者使用的Provider类中也使用了它.

This method returns an object that may be a String, a Collection of Strings or even a CustomFieldParams object. It’s used to populate the value variable used in Chapter 3: Advanced Custom Field Types Velocity templates. It’s also used in the Provider classes that are used by custom field searchers.

String getStringFromSingularObject(Carrier singularObject)

此方法与getSingularObjectFromString并不完全相反,正如您所期望的那样.相反,它用于将单个对象(运营商)转换为网页中使用的字符串,而不是数据库值.返回的字符串有时也存储在Lucene索引中以进行搜索(第57页的更复杂的搜索器").单一对象在JIRA 5.0之前作为对象传递给此方法.

This method is not the direct opposite of getSingularObjectFromString as you might expect. Instead, it is used to convert a singular object (Carrier) to the string that is used in the web page, not to the database value. The returned String is also sometimes what is stored in the Lucene indexes for searching ("More Complex Searchers" on page 57). The singular object was passed into this method as an Object before JIRA 5.0.

要考虑的最后一组CustomFieldType方法是:

The final set of CustomFieldType methods to consider are:

Set<Long> remove(CustomField field)

从JIRA实例中完全删除自定义字段时,将调用此方法,并返回受删除影响的问题ID.用于从字段中删除值的正确方法是updateValue.

This method is called when a custom field is entirely removed from a JIRA instance, and returns the issue ids that were affected by the removal. The correct method to use for deleting a value from a field is updateValue.

String getChangelogValue(CustomField field, Object value)
String getChangelogString(CustomField field, Object value)

这些方法是生成问题的历史记录"选项卡中的文本的方式.当此类型的自定义字段更改时,将使用该字段的before和after值调用这些方法.两种方法的区别在于,如果以后值无效,则将显示字符串( https://developer.atlassian.com/display/JIRADEV/Database+Schema#DatabaseSchema-ChangeHistory ).

These methods are how the text that is seen in the History tab of an issue is gen- erated. When a custom field of this type changes, these methods are called with the before and after values of the field. The difference between the two methods is that the if the value later becomes invalid, the string will be shown instead (https://developer.atlassian.com/display/JIRADEV/Database+Schema#DatabaseSchema-ChangeHistory).

extractTransferObjectFromString()
extractStringFromTransferObject()

这些方法不是来自CustomFieldType界面,而是存在于标准Multi字段中,以便在项目导入期间使用.

These methods are not from the CustomFieldType interface but they exist in the standard Multi fields for use during project imports.

其他界面

还有一些其他接口通常由自定义字段类型实现.

There are a few other interfaces that are commonly implemented by custom field types.

ProjectImportableCustomField

此接口中的getProjectImporter方法用于实现从XML备份导入项目时如何填充自定义字段.如果您未实现此界面,则项目导入将不会为您的自定义字段导入值.

The getProjectImporter method from this interface is used to implement how the custom field is populated during importing a project from an XML backup. If you don’t implement this interface then project imports will not import values for your custom field.

MultipleCustomFieldType
MultipleSettableCustomFieldType

这两个接口由具有选项的自定义字段使用,并且可以具有多个选项.对于这些类,可以使用Options类(它们是Java List的简单子类)来访问值.这些接口并非真正适合通用多值自定义字段类型使用.

These two interfaces are used by custom fields with options and that furthermore can have more than one option. For these classes, the values can be accessed using the Options class, which is a simple subclass of a Java List. These interfaces are not really intended for use by general-purpose multiple value custom field types.

具有多个值的字段| 41

SortableCustomField

此接口包含用于比较两个奇异对象的比较方法.当您单击列标题以对问题页面进行排序时,问题导航器将使用此选项.对于没有搜索者的自定义字段,这实际上是一个较慢的后备时间(请参见第4章).

This interface contains a compare method for comparing two singular objects. This is used by the Issue Navigator when you click on a column’s heading to sort a page of issues. This is actually a slower fallback for custom fields that don’t have a searcher associated with them (see Chapter 4).

RestAwareCustomFieldType
RestCustomFieldTypeOperations

这两个接口是JIRA REST API如何知道可以检索或更新哪些字段的方式. JIRA 5.0中的新功能.

These two interfaces are how the JIRA REST API knows which fields can be retrieved or updated. New in JIRA 5.0.

这篇关于无法理解,getSingularObjectFromString方法有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆