Package org.faktorips.runtime.model.type
Class ProductAssociation
java.lang.Object
org.faktorips.runtime.model.type.ModelElement
org.faktorips.runtime.model.type.TypePart
org.faktorips.runtime.model.type.Association
org.faktorips.runtime.model.type.ProductAssociation
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringFields inherited from class org.faktorips.runtime.model.type.Association
PROPERTY_MAX_CARDINALITY, PROPERTY_MIN_CARDINALITY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<S extends IProductComponent>
SaddTargetObject(S source, Calendar effectiveDate, IProductComponent target, CardinalityRange cardinality) Adds the target object with the given cardinality to this association in the source object.<S extends IProductComponent>
SaddTargetObjects(S source, Calendar effectiveDate, Collection<IProductComponent> targets) Adds the target objects to this association in the source object.<S extends IProductComponent>
SaddTargetObjects(S source, Calendar effectiveDate, IProductComponent... targets) Adds the target objects to this association in the source object.createOverwritingAssociationFor(Type subType) Returns the matching policy component type association or anempty Optionalif no matching association is defined for this association.<T extends IProductComponent>
Optional<IProductComponentLink<T>>getLink(IProductComponent source, IProductComponent target, Calendar effectiveDate) Retrieves thelink- based on this association - from the source product component to the target product component, if one such link exists.<T extends IProductComponent>
Collection<IProductComponentLink<T>>getLinks(IProductComponent prodCmpt, Calendar effectiveDate) Retrieves alllinksfor this association from a product component.Returns the matching policy component type association ornullif no matching association is defined for this association.Returns thePolicyCmptTypeidentified byAssociation.getMatchingAssociationSource()Deprecated.Returns the association that is overridden by this association if this association overrides another one.Returns the target type of this association.getTargetObjects(IProductComponent productComponentSource, Calendar effectiveDate) Returns a list of the target(s) of the given product component's association identified by this model type association.getType()Returns theProductCmptTypethis association belongs to.booleanChecks whether this association is changing over time (resides in the generation) or not (resides in the product component).<S extends IProductComponent>
SremoveTargetObjects(S source, Calendar effectiveDate, List<IProductComponent> targetsToRemove) Removes the target object from this association in the source object.<S extends IProductComponent>
SremoveTargetObjects(S source, Calendar effectiveDate, IProductComponent... targetsToRemove) Removes the target object from this association in the source object.voidvalidate(MessageList list, IValidationContext context, IProductComponent source, Calendar effectiveDate) Validates this association's configuration in the given product against the model.Methods inherited from class org.faktorips.runtime.model.type.Association
findSuperAssociation, getAnnotation, getAssociationKind, getDocumentation, getGetterMethod, getInverseAssociation, getLabelForPlural, getMatchingAssociationName, getMatchingAssociationSource, getMaxCardinality, getMinCardinality, getNamePlural, getResourceBundleName, getUsedName, isDerivedUnion, isMatchingAssociationPresent, isOverriding, isSubsetOfADerivedUnion, isToOneAssociation, toString, validate, validateMethods inherited from class org.faktorips.runtime.model.type.TypePart
getMessageHelper, getMessageKey, getTypeNameMethods inherited from class org.faktorips.runtime.model.type.ModelElement
createMessageHelper, getDeprecation, getDescription, getExtensionPropertyIds, getExtensionPropertyValue, getLabel, getName, getRelevantProductObject, getRelevantProductObject, invokeField, invokeMethod, isDeprecated
-
Field Details
-
MSGCODE_MAX_CARDINALITY_NOT_VALID
- See Also:
-
MSGKEY_MAX_CARDINALITY_NOT_VALID
- See Also:
-
MSGCODE_MIN_CARDINALITY_NOT_VALID
- See Also:
-
MSGKEY_MIN_CARDINALITY_NOT_VALID
- See Also:
-
MSGCODE_MAX_CARDINALITY_EXCEEDS_MODEL_MAX
- See Also:
-
MSGKEY_MAX_CARDINALITY_EXCEEDS_MODEL_MAX
- See Also:
-
MSGCODE_MIN_CARDINALITY_FALLS_BELOW_MODEL_MIN
- See Also:
-
MSGKEY_MIN_CARDINALITY_FALLS_BELOW_MODEL_MIN
- See Also:
-
MSGCODE_DATE_FROM_NOT_VALID
- See Also:
-
MSGKEY_DATE_FROM_NOT_VALID
- See Also:
-
MSGCODE_DATE_TO_NOT_VALID
- See Also:
-
MSGKEY_DATE_TO_NOT_VALID
- See Also:
-
-
Constructor Details
-
ProductAssociation
-
-
Method Details
-
createOverwritingAssociationFor
- Specified by:
createOverwritingAssociationForin classAssociation
-
getType
Returns theProductCmptTypethis association belongs to. -
getModelType
Deprecated.UsegetType()Returns the model type this association belongs to.- Overrides:
getModelTypein classTypePart
-
getTarget
Returns the target type of this association.- Overrides:
getTargetin classAssociation
-
getTargetObjects
public List<IProductComponent> getTargetObjects(IProductComponent productComponentSource, Calendar effectiveDate) Returns a list of the target(s) of the given product component's association identified by this model type association. If this association is changing over time (resides in the generation) the date is used to retrieve the correct generation. If the date isnullthe latest generation is used. If the association is not changing over time the date will be ignored.- Parameters:
productComponentSource- a product object corresponding to theProductCmptTypethis association belongs toeffectiveDate- The date that should be used to get theIProductComponentGenerationif this association is changing over time. May benullto get the latest generation.- Returns:
- a list of the target(s) of the given model object's association identified by this model type association
- Throws:
IllegalArgumentException- if the model object does not have an association fitting this model type association or that association is not accessible for any reason
-
addTargetObjects
public <S extends IProductComponent> S addTargetObjects(S source, Calendar effectiveDate, Collection<IProductComponent> targets) Adds the target objects to this association in the source object. If this is a ..1 ("to one") association, the target object is set (and thus the potentially existing object is overwritten).The return value is the updated source object. It could be used to directly create a tree of objects. For example with a model like:
You could write such code:SalesProduct <>---- Product <>---- CoverageTypeproducts.addTargetObjects(salesProduct, coveragetypes.addTargetObjects(product, coverageType1, coverageType2));- Parameters:
source- the object to add a target object toeffectiveDate- The date that should be used to get theIProductComponentGenerationif this association is changing over time. May benullto get the latest generation.targets- the objects to add to source- Returns:
- the changed source object
- Throws:
IllegalArgumentException- if there is no method annotated with@IpsAssociationAdder. This is the case if the associationis a derived union.IllegalArgumentException- if there are multiple target objects provided for a ..1 ("to one") association- Since:
- 20.6
-
addTargetObjects
public <S extends IProductComponent> S addTargetObjects(S source, Calendar effectiveDate, IProductComponent... targets) Adds the target objects to this association in the source object. If this is a ..1 ("to one") association, the target object is set (and thus the potentially existing object is overwritten).The return value is the updated source object. It could be used to directly create a tree of objects. For example with a model like:
You could write such code:SalesProduct <>---- Product <>---- CoverageTypeproducts.addTargetObjects(salesProduct, coveragetypes.addTargetObjects(product, coverageType1, coverageType2));- Parameters:
source- the object to add a target object toeffectiveDate- the date that should be used to get theIProductComponentGenerationif this association is changing over time. May benullto get the latest generation.targets- the objects to add to source- Returns:
- the changed source object
- Throws:
IllegalArgumentException- if there is no method annotated with@IpsAssociationAdder. This is the case if the associationis a derived union.IllegalArgumentException- if there are multiple target objects provided for a ..1 ("to one") association- Since:
- 20.6
-
addTargetObject
public <S extends IProductComponent> S addTargetObject(S source, Calendar effectiveDate, IProductComponent target, CardinalityRange cardinality) Adds the target object with the given cardinality to this association in the source object. If this is a ..1 ("to one") association, the target object is set (and thus the potentially existing object is overwritten).The return value is the updated source object. It could be used to directly create a tree of objects. For example with a model like:
You could write such code:SalesProduct <>---- Product <>---- CoverageTypeproducts.addTargetObject(salesProduct, coveragetypes.addTargetObject(product, coverageType));- Parameters:
source- the object to add a target object toeffectiveDate- the date that should be used to get theIProductComponentGenerationif this association is changing over time. May benullto get the latest generation.target- the object to add to sourcecardinality- the cardinality range that will be set for the target- Returns:
- the changed source object
- Throws:
IllegalArgumentException- if there is no method annotated with@IpsAssociationAdder. This is the case if the associationis a derived union.IllegalArgumentException- if there are multiple target objects provided for a ..1 ("to one") association- Since:
- 20.6
-
removeTargetObjects
public <S extends IProductComponent> S removeTargetObjects(S source, Calendar effectiveDate, List<IProductComponent> targetsToRemove) Removes the target object from this association in the source object. Does nothing if the target object is not currently referenced (in this association). Sets tonullif this is a ..1 ("to one") association.The return value is the updated source object. It could be used to directly remove objects in a tree of objects. For example with a model like:
You could write such code:SalesProduct <>---- Product <>---- CoverageTypeproducts.removeTargetObjects(SalesProduct, coverageTypes.removeTargetObjects(product, coverageType1, coverageType2));- Parameters:
source- the object to remove a target object fromeffectiveDate- the date that should be used to get theIProductComponentGenerationif this association is changing over time. May benullto get the latest generation.targetsToRemove- the objects to remove from this association in source- Returns:
- the changed source object
- Throws:
IllegalArgumentException- if there is no method annotated with@IpsAssociationRemover(or@IpsAssociationAdderfor a ..1 association). This is the case if the associationis a derived union.IllegalArgumentException- if there are multiple or no target objects provided for a ..1 ("to one") association- Since:
- 20.6
-
removeTargetObjects
public <S extends IProductComponent> S removeTargetObjects(S source, Calendar effectiveDate, IProductComponent... targetsToRemove) Removes the target object from this association in the source object. Does nothing if the target object is not currently referenced (in this association). Sets tonullif this is a ..1 ("to one") association.The return value is the updated source object. It could be used to directly remove objects in a tree of objects. For example with a model like:
You could write such code:SalesProduct <>---- Product <>---- CoverageTypeproducts.removeTargetObjects(SalesProduct, coverageTypes.removeTargetObjects(product, coverageType1, coverageType2));- Parameters:
source- the object to remove a target object fromeffectiveDate- the date that should be used to get theIProductComponentGenerationif this association is changing over time. May benullto get the latest generation.targetsToRemove- the objects to remove from this association in source- Returns:
- the changed source object
- Throws:
IllegalArgumentException- if there is no method annotated with@IpsAssociationRemover(or@IpsAssociationAdderfor a ..1 association). This is the case if the associationis a derived union.IllegalArgumentException- if there are multiple or no target objects provided for a ..1 ("to one") association- Since:
- 20.6
-
getMatchingAssociationSourceType
Returns thePolicyCmptTypeidentified byAssociation.getMatchingAssociationSource()- Overrides:
getMatchingAssociationSourceTypein classAssociation- Returns:
- The policy component type of the matching association source
- See Also:
-
getMatchingAssociation
Returns the matching policy component type association ornullif no matching association is defined for this association.- Overrides:
getMatchingAssociationin classAssociation- Returns:
- The matching association
-
findMatchingAssociation
Returns the matching policy component type association or anempty Optionalif no matching association is defined for this association.- Overrides:
findMatchingAssociationin classAssociation- Returns:
- The matching association
-
isChangingOverTime
public boolean isChangingOverTime()Checks whether this association is changing over time (resides in the generation) or not (resides in the product component).- Specified by:
isChangingOverTimein classTypePart- Returns:
trueif this association is changing over time, elsefalse
-
getLinks
public <T extends IProductComponent> Collection<IProductComponentLink<T>> getLinks(IProductComponent prodCmpt, Calendar effectiveDate) Retrieves alllinksfor this association from a product component.- Parameters:
prodCmpt- the source product component to retrieve the links fromeffectiveDate- the effective-date of the adjustment (a.k.a. product component generation). Ignored if this is a static association (isChangingOverTime()==false).- Returns:
- the list of all link instances defined in the product component for this association. Returns a list with a single link instance for ..1 associations.
- Throws:
IllegalArgumentException- if there is no method annotated with@IpsAssociationLinks. This is the case if the associationis a derived union.- Since:
- 3.22
-
getLink
public <T extends IProductComponent> Optional<IProductComponentLink<T>> getLink(IProductComponent source, IProductComponent target, Calendar effectiveDate) Retrieves thelink- based on this association - from the source product component to the target product component, if one such link exists.- Parameters:
source- the source product component to retrieve the links fromtarget- the target product component of the linkeffectiveDate- the effective-date of the adjustment (a.k.a. product component generation). Ignored if this is a static association (isChangingOverTime()==false).- Returns:
- the
link- based on this association - from the source product component to the target product component, if one such link exists - Throws:
IllegalArgumentException- if there is no method annotated with@IpsAssociationLinks. This is the case if the associationis a derived union.- Since:
- 24.1
-
getSuperAssociation
Description copied from class:AssociationReturns the association that is overridden by this association if this association overrides another one. Otherwise returnsnull.- Overrides:
getSuperAssociationin classAssociation- Returns:
- The association that is overridden by this attribute.
- See Also:
-
validate
public void validate(MessageList list, IValidationContext context, IProductComponent source, Calendar effectiveDate) Validates this association's configuration in the given product against the model.- Overrides:
validatein classTypePart- Parameters:
list- aMessageList, to which validation messages may be addedcontext- theIValidationContext, needed to determine theLocalein which to createMessagessource- theIProductComponentto validateeffectiveDate- the date that determines whichIProductComponentGenerationis to be validated, if theIProductComponenthas any
-
getType()