Interface ItemAttributeLoader<T>
- Type Parameters:
T- type of the loaded value
- All Superinterfaces:
AttributeLoader<T>
- All Known Implementing Classes:
AbstractItemAttributeLoader,BaseItemAttributeLoader,DelegatingItemAttributeLoader,IssueAttributeLoader,ItemClassAttributeLoader,ItemTypeAttributeLoader
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()).
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbooleanisItemTypeSupported(String itemType) Lets the loader declare if it can handle items of a given type.loadValue(ItemIdentity itemId, ItemAttributeContext context) The loading function.default voidpreload(Collection<ItemIdentity> itemIds, AttributeContext context) Optional method to perform any bulk actions on a set of items beforeloadValue(com.almworks.jira.structure.api.item.ItemIdentity, com.almworks.jira.structure.api.attribute.loader.ItemAttributeContext)method is called for each item in the collection.Methods inherited from interface AttributeLoader
getAttributeDependencies, getAttributeSpec, getCachingStrategy, getContextDependencies, getGlobalTrail
-
Method Details
-
isItemTypeSupported
Lets the loader declare if it can handle items of a given type. If the loader returns
falsefor some type, itsloadValue(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 topreload(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.
- Parameters:
itemType- the type of item- Returns:
- true if the loader supports this item type.
- See Also:
-
loadValue
@Nullable AttributeValue<T> loadValue(@NotNull ItemIdentity itemId, @NotNull ItemAttributeContext context) The loading function. The implementation is expected to take
itemIdor the item object (seeItemAttributeContext.getItem(java.lang.Class<I>)) and provide a value.Attribute system's contract:
- Before this method is called,
isItemTypeSupported(java.lang.String)method has been called at least once for the type of the passed item, and this loader has returnedtrue. - Before this method is called,
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 includeditemId, 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 returnnull.- Parameters:
itemId- item to load the value forcontext- loading context- Returns:
- attribute value, or
nullto pass on loading a value for this item
- Before this method is called,
-
preload
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.
- Parameters:
itemIds- a collection of item IDs about to be loadedcontext- loading context
-