Class ProductAssociation


public class ProductAssociation extends Association
  • Field Details

  • Constructor Details

    • ProductAssociation

      public ProductAssociation(Type type, Method getterMethod, Method addMethod, Method addMethodWithCardinality, Method removeMethod, boolean changingOverTime, Method getLinksMethod)
  • Method Details

    • createOverwritingAssociationFor

      public ProductAssociation createOverwritingAssociationFor(Type subType)
      Specified by:
      createOverwritingAssociationFor in class Association
    • getType

      public ProductCmptType getType()
      Returns the ProductCmptType this association belongs to.
      Overrides:
      getType in class TypePart
    • getModelType

      @Deprecated public ProductCmptType getModelType()
      Deprecated.
      Returns the model type this association belongs to.
      Overrides:
      getModelType in class TypePart
    • getTarget

      public ProductCmptType getTarget()
      Returns the target type of this association.
      Overrides:
      getTarget in class Association
    • 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 is null the latest generation is used. If the association is not changing over time the date will be ignored.
      Parameters:
      productComponentSource - a product object corresponding to the ProductCmptType this association belongs to
      effectiveDate - The date that should be used to get the IProductComponentGeneration if this association is changing over time. May be null to 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:

       
       SalesProduct <>---- Product <>---- CoverageType
       
       
      You could write such code:
       
            products.addTargetObjects(salesProduct,
                coveragetypes.addTargetObjects(product,
                    coverageType1, coverageType2));
       
       
      Parameters:
      source - the object to add a target object to
      effectiveDate - The date that should be used to get the IProductComponentGeneration if this association is changing over time. May be null to 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 association is 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:

       
       SalesProduct <>---- Product <>---- CoverageType
       
       
      You could write such code:
       
            products.addTargetObjects(salesProduct,
                coveragetypes.addTargetObjects(product,
                    coverageType1, coverageType2));
       
       
      Parameters:
      source - the object to add a target object to
      effectiveDate - the date that should be used to get the IProductComponentGeneration if this association is changing over time. May be null to 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 association is 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:

       
       SalesProduct <>---- Product <>---- CoverageType
       
       
      You could write such code:
       
            products.addTargetObject(salesProduct,
                coveragetypes.addTargetObject(product,
                    coverageType));
       
       
      Parameters:
      source - the object to add a target object to
      effectiveDate - the date that should be used to get the IProductComponentGeneration if this association is changing over time. May be null to get the latest generation.
      target - the object to add to source
      cardinality - 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 association is 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 to null if 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:

       
       SalesProduct <>---- Product <>---- CoverageType
       
       
      You could write such code:
       
            products.removeTargetObjects(SalesProduct,
                coverageTypes.removeTargetObjects(product,
                    coverageType1, coverageType2));
       
       
      Parameters:
      source - the object to remove a target object from
      effectiveDate - the date that should be used to get the IProductComponentGeneration if this association is changing over time. May be null to 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 @IpsAssociationAdder for a ..1 association). This is the case if the association is 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 to null if 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:

       
       SalesProduct <>---- Product <>---- CoverageType
       
       
      You could write such code:
       
            products.removeTargetObjects(SalesProduct,
                coverageTypes.removeTargetObjects(product,
                    coverageType1, coverageType2));
       
       
      Parameters:
      source - the object to remove a target object from
      effectiveDate - the date that should be used to get the IProductComponentGeneration if this association is changing over time. May be null to 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 @IpsAssociationAdder for a ..1 association). This is the case if the association is a derived union.
      IllegalArgumentException - if there are multiple or no target objects provided for a ..1 ("to one") association
      Since:
      20.6
    • getMatchingAssociationSourceType

      public PolicyCmptType getMatchingAssociationSourceType()
      Overrides:
      getMatchingAssociationSourceType in class Association
      Returns:
      The policy component type of the matching association source
      See Also:
    • getMatchingAssociation

      public PolicyAssociation getMatchingAssociation()
      Returns the matching policy component type association or null if no matching association is defined for this association.
      Overrides:
      getMatchingAssociation in class Association
      Returns:
      The matching association
    • findMatchingAssociation

      public Optional<PolicyAssociation> findMatchingAssociation()
      Returns the matching policy component type association or an empty Optional if no matching association is defined for this association.
      Overrides:
      findMatchingAssociation in class Association
      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:
      isChangingOverTime in class TypePart
      Returns:
      true if this association is changing over time, else false
    • getLinks

      public <T extends IProductComponent> Collection<IProductComponentLink<T>> getLinks(IProductComponent prodCmpt, Calendar effectiveDate)
      Retrieves all links for this association from a product component.
      Parameters:
      prodCmpt - the source product component to retrieve the links from
      effectiveDate - 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 association is a derived union.
      Since:
      3.22
    • getLink

      public <T extends IProductComponent> Optional<IProductComponentLink<T>> getLink(IProductComponent source, IProductComponent target, Calendar effectiveDate)
      Retrieves the link - 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 from
      target - the target product component of the link
      effectiveDate - 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 association is a derived union.
      Since:
      24.1
    • getSuperAssociation

      public ProductAssociation getSuperAssociation()
      Description copied from class: Association
      Returns the association that is overridden by this association if this association overrides another one. Otherwise returns null.
      Overrides:
      getSuperAssociation in class Association
      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:
      validate in class TypePart
      Parameters:
      list - a MessageList, to which validation messages may be added
      context - the IValidationContext, needed to determine the Locale in which to create Messages
      source - the IProductComponent to validate
      effectiveDate - the date that determines which IProductComponentGeneration is to be validated, if the IProductComponent has any