Class BaseItemAttributeLoader<T>
- All Implemented Interfaces:
AttributeLoader<T>
,ItemAttributeLoader<T>
-
Constructor Summary
ConstructorsConstructorDescriptionBaseItemAttributeLoader
(AttributeSpec<T> attributeSpec, Set<AttributeSpec<?>> dependencies, Set<AttributeContextDependency> contextDependencies, AttributeCachingStrategy cachingStrategy, TrailItemSet globalTrail, Predicate<String> itemTypeSupportedPredicate, BiFunction<ItemIdentity, ItemAttributeContext, AttributeValue<T>> attributeFunction, BiConsumer<Collection<ItemIdentity>, AttributeContext> preloadFunction) -
Method Summary
Modifier and TypeMethodDescriptionboolean
isItemTypeSupported
(String itemType) Lets the loader declare if it can handle items of a given type.loadValue
(ItemIdentity itemId, ItemAttributeContext context) The loading function.void
preload
(Collection<ItemIdentity> itemIds, AttributeContext context) Optional method to perform any bulk actions on a set of items beforeItemAttributeLoader.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.Methods inherited from class BaseAttributeLoader
getAttributeDependencies, getAttributeSpec, getCachingStrategy, getContextDependencies, getGlobalTrail
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface AttributeLoader
getAttributeDependencies, getAttributeSpec, getCachingStrategy, getContextDependencies, getGlobalTrail
-
Constructor Details
-
BaseItemAttributeLoader
public BaseItemAttributeLoader(@NotNull AttributeSpec<T> attributeSpec, @Nullable Set<AttributeSpec<?>> dependencies, @Nullable Set<AttributeContextDependency> contextDependencies, @Nullable AttributeCachingStrategy cachingStrategy, @Nullable TrailItemSet globalTrail, @Nullable Predicate<String> itemTypeSupportedPredicate, @NotNull BiFunction<ItemIdentity, ItemAttributeContext, AttributeValue<T>> attributeFunction, @Nullable BiConsumer<Collection<ItemIdentity>, AttributeContext> preloadFunction)
-
-
Method Details
-
isItemTypeSupported
Description copied from interface:ItemAttributeLoader
Lets the loader declare if it can handle items of a given type. If the loader returns
false
for some type, itsItemAttributeLoader.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 toItemAttributeLoader.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.
- Specified by:
isItemTypeSupported
in interfaceItemAttributeLoader<T>
- Parameters:
itemType
- the type of item- Returns:
- true if the loader supports this item type.
- See Also:
-
loadValue
@Nullable public AttributeValue<T> loadValue(@NotNull ItemIdentity itemId, @NotNull ItemAttributeContext context) Description copied from interface:ItemAttributeLoader
The loading function. The implementation is expected to take
itemId
or the item object (seeItemAttributeContext.getItem(java.lang.Class<I>)
) and provide a value.Attribute system's contract:
- Before this method is called,
ItemAttributeLoader.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,
ItemAttributeLoader.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
.- Specified by:
loadValue
in interfaceItemAttributeLoader<T>
- Parameters:
itemId
- item to load the value forcontext
- loading context- Returns:
- attribute value, or
null
to pass on loading a value for this item
- Before this method is called,
-
preload
Description copied from interface:ItemAttributeLoader
Optional method to perform any bulk actions on a set of items before
ItemAttributeLoader.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
ItemAttributeLoader.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.
- Specified by:
preload
in interfaceItemAttributeLoader<T>
- Parameters:
itemIds
- a collection of item IDs about to be loadedcontext
- loading context
-