T
- the type of the referenced objectpublic interface Reference<T> extends Referenceable<T>, Identifiable<T>, ResourceIdentifier<T>
Reference
is a loose reference to another resource in Composable Commerce.
The reference may have a copy of the referenced object available via the method getObj()
on certain conditions
.
getTypeId()
and getId()
are compared used and getObj()
will be ignored.Modifier and Type | Method and Description |
---|---|
default Reference<T> |
filled(T obj) |
String |
getId()
Id of the object this reference represents.
|
default String |
getKey()
In references the key should always be null
|
T |
getObj()
The nullable value of the referenced object.
|
String |
getTypeId()
Type id of the object this reference represents, e.g.
|
static <T> Reference<T> |
of(String typeId,
String id) |
static <T> Reference<T> |
of(String typeId,
String id,
T obj) |
static <T extends Identifiable<T>> |
of(String typeId,
T obj) |
static <T> Reference<T> |
ofResourceTypeIdAndId(String typeId,
String id) |
static <T> Reference<T> |
ofResourceTypeIdAndIdAndObj(String typeId,
String id,
T obj) |
static <T extends Identifiable<T>> |
ofResourceTypeIdAndObj(String typeId,
T obj) |
default boolean |
referencesSameResource(Referenceable<T> counterpart) |
default Reference<T> |
toReference()
Creates a reference to this resource, the reference may not be filled.
|
default ResourceIdentifier<T> |
toResourceIdentifier() |
hasSameIdAs
String getId()
getId
in interface Identifiable<T>
getId
in interface ResourceIdentifier<T>
String getTypeId()
getTypeId
in interface ResourceIdentifier<T>
@Nullable T getObj()
withCustomerInGroup(client(), (customer, customerGroup) -> { final CustomerByIdGet customerByIdGet = CustomerByIdGet.of(customer); final Customer loadedCustomer = client().executeBlocking(customerByIdGet); final Reference<CustomerGroup> customerGroupReference = loadedCustomer.getCustomerGroup(); assertThat(customerGroupReference.getId()).isEqualTo(customerGroup.getId()); assertThat(customerGroupReference.getObj()) .as("reference is not expanded") .isNull(); });
See the test code.
ReferenceExpansionDsl.withExpansionPaths(List)
on requests:
withCustomerInGroup(client(), (customer, customerGroup) -> { final CustomerByIdGet customerByIdGet = CustomerByIdGet.of(customer) .withExpansionPaths(m -> m.customerGroup());//the important part final Customer loadedCustomer = client().executeBlocking(customerByIdGet); final Reference<CustomerGroup> customerGroupReference = loadedCustomer.getCustomerGroup(); final CustomerGroup loadedCustomerGroup = customerGroupReference.getObj(); assertThat(loadedCustomerGroup) .as("reference is expanded") .isEqualTo(customerGroup); });
See the test code.
ReferenceExpansionDsl
which endpoints support reference expansion.static <T extends Identifiable<T>> Reference<T> of(String typeId, T obj)
static <T> Reference<T> ofResourceTypeIdAndIdAndObj(String typeId, String id, T obj)
static <T extends Identifiable<T>> Reference<T> ofResourceTypeIdAndObj(String typeId, T obj)
default boolean referencesSameResource(Referenceable<T> counterpart)
default Reference<T> toReference()
Referenceable
toReference
in interface Referenceable<T>
default ResourceIdentifier<T> toResourceIdentifier()
toResourceIdentifier
in interface Referenceable<T>
toResourceIdentifier
in interface ResourceIdentifiable<T>
toResourceIdentifier
in interface ResourceIdentifier<T>
@Nullable default String getKey()
getKey
in interface ResourceIdentifier<T>