T
- type of the loaded value@PublicSpi public interface ItemAttributeLoader<T> extends AttributeLoader<T>
Item loaders calculate attribute value for a particular item, based on ItemIdentity
. The value loaded does not depend on
a particular forest and generally will be the same for all structures (unless structure context dependency is declared, see below).
Values calculated by item loaders are stored in the per-item cache and shared between structures.
Item attributes may, but should not depend on row-based attributes. If that happens though, they will be stored in a per-forest cache. If you have such an attribute, consider splitting it into an item and derived attributes.
If an item attribute declares context dependency on structure (by including AttributeContextDependency.STRUCTURE
in the
result of AttributeLoader.getContextDependencies()
), then, although it will still work as an item attribute, it will be able
to return different values for the same item, depending on the current structure (retrieved via AttributeContext.getBaseStructureId()
).
AttributeLoader
Modifier and Type | Method and Description |
---|---|
boolean |
isItemTypeSupported(String itemType)
Lets the loader declare if it can handle items of a given type.
|
AttributeValue<T> |
loadValue(ItemIdentity itemId,
ItemAttributeContext context)
The loading function.
|
default void |
preload(Collection<ItemIdentity> itemIds,
AttributeContext context)
Optional method to perform any bulk actions on a set of items before
loadValue(com.almworks.jira.structure.api.item.ItemIdentity, com.almworks.jira.structure.api.attribute.loader.ItemAttributeContext) method is called for each item in the collection. |
getAttributeDependencies, getAttributeSpec, getCachingStrategy, getContextDependencies, getGlobalTrail
boolean isItemTypeSupported(@NotNull String itemType)
Lets the loader declare if it can handle items of a given type. If the loader returns false
for some type, its loadValue(com.almworks.jira.structure.api.item.ItemIdentity, com.almworks.jira.structure.api.attribute.loader.ItemAttributeContext)
function will not be called for items of that type; also, non-supported items will be excluded from the collection passed to preload(java.util.Collection<com.almworks.jira.structure.api.item.ItemIdentity>, com.almworks.jira.structure.api.attribute.loader.AttributeContext)
method.
The returned value must be the same for the same item type throughout the lifetime of the object.
itemType
- the type of itemItemIdentity
@Nullable AttributeValue<T> loadValue(@NotNull ItemIdentity itemId, @NotNull ItemAttributeContext context)
The loading function. The implementation is expected to take itemId
or the item object (see ItemAttributeContext.getItem(java.lang.Class<I>)
)
and provide a value.
Attribute system's contract:
isItemTypeSupported(java.lang.String)
method has been called at least once for the type of the
passed item, and this loader has returned true
.preload(java.util.Collection<com.almworks.jira.structure.api.item.ItemIdentity>, com.almworks.jira.structure.api.attribute.loader.AttributeContext)
has been called for a set of items that included itemId
, and that was
a part of the same loading process, sharing the same context (so all values put into the context are still there).If the value is missing or empty, the loader should return AttributeValue.undefined()
. If for some reason this loader
is not applicable for the given item, it should return null
.
itemId
- item to load the value forcontext
- loading contextnull
to pass on loading a value for this itemdefault void preload(@NotNull Collection<ItemIdentity> itemIds, @NotNull AttributeContext context)
Optional method to perform any bulk actions on a set of items before loadValue(com.almworks.jira.structure.api.item.ItemIdentity, com.almworks.jira.structure.api.attribute.loader.ItemAttributeContext)
method is called for each item in the collection.
The results of the preloading should be stored using AttributeContext.putObject(java.lang.Object, java.lang.Object)
.
Do not store the preloading results as loader's instance fields! All loaders should be stateless.
Note that this method may be called several times during a single loading operation, for arbitrary sets of items, including those already pre-loaded. Be careful not to overwrite one execution's result with another's.
When this method is called, the attribute system excludes any non-supported items from the list of passed items
(checking isItemTypeSupported(java.lang.String)
).
The loader's dependencies may not be loaded at the time of the call. In fact, there's no way to access the dependency values.
itemIds
- a collection of item IDs about to be loadedcontext
- loading contextCopyright © 2024 Tempo Software. All Rights Reserved.