Class RelationSetter
java.lang.Object
ch.tocco.nice2.entityoperation.api.util.RelationSetter
- All Implemented Interfaces:
EntityUpdater
A class to adjust lookup entity relations depending on other fields pr relations.
Example:
If the relation "relEvent_status" is set to "archived"
the relation "relRegistration.relRegistration_status" should be changed to "attended"
but only if the status was "booked"
Code:
RelationSetter setter =
RelationSetter.setRelation("relRegistration.relRegistration_status", "attended")
.ifCondition(field("relEvent_status.unique_id").is("archived"))
.expectTargetState("booked");
setter.applyOn(entity);
Note: The class only support the changing of lookup entities atm
-
Method Summary
Modifier and TypeMethodDescriptionbooleanintapplyOn(EntityList list) expectTargetState(String expectedTargetState) Can be used if you only want to adjust a relation if it has a certain state Note: You can add more than one stateexpectTargetStates(String... expectedTargetStates) ifCondition(Condition condition) Pass theConditionwhich will be applied on the entity you want to adjust.static RelationSettersetRelation(QueryBuilderFactory qbFactory, String path, String state) Note: if you apply the returned instance of this method to anEntityall of the relations will be adjusted
-
Method Details
-
setRelation
Note: if you apply the returned instance of this method to anEntityall of the relations will be adjusted- Parameters:
path- path to the relationstate- the unique_id of the lookup entity which should be related to the given path- Returns:
- a new instance of a
RelationSetter
-
ifCondition
Pass theConditionwhich will be applied on the entity you want to adjust. If this method gets called multiple times it will connect the Conditions withConditions.and(ch.tocco.nice2.persist.core.api.qb2.Condition...)- Parameters:
condition- the state when the relation should get adjusted- Returns:
- this
-
expectTargetState
Can be used if you only want to adjust a relation if it has a certain state Note: You can add more than one state- Parameters:
expectedTargetState- the expected state- Returns:
- this
-
expectTargetStates
-
applyOn
- Specified by:
applyOnin interfaceEntityUpdater- Parameters:
entity- the entity to adjust- Returns:
- true if a relation got adjusted, false otherwise
-
applyOn
- Specified by:
applyOnin interfaceEntityUpdater- Parameters:
list- the entity list to adjust- Returns:
- number of adjusted entities
-