Class ProductAssociation

    • Constructor Detail

      • ProductAssociation

        public ProductAssociation​(Type type,
                                  java.lang.reflect.Method getterMethod,
                                  java.lang.reflect.Method addMethod,
                                  java.lang.reflect.Method addMethodWithCardinality,
                                  java.lang.reflect.Method removeMethod,
                                  boolean changingOverTime,
                                  java.lang.reflect.Method getLinksMethod)
    • Method Detail

      • getTargetObjects

        public java.util.List<IProductComponent> getTargetObjects​(IProductComponent productComponentSource,
                                                                  java.util.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:
        java.lang.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,
                                                                java.util.Calendar effectiveDate,
                                                                java.util.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:
        java.lang.IllegalArgumentException - if there is no method annotated with @IpsAssociationAdder. This is the case if the association is a derived union.
        java.lang.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,
                                                                java.util.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:
        java.lang.IllegalArgumentException - if there is no method annotated with @IpsAssociationAdder. This is the case if the association is a derived union.
        java.lang.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,
                                                               java.util.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:
        java.lang.IllegalArgumentException - if there is no method annotated with @IpsAssociationAdder. This is the case if the association is a derived union.
        java.lang.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,
                                                                   java.util.Calendar effectiveDate,
                                                                   java.util.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:
        java.lang.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.
        java.lang.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,
                                                                   java.util.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:
        java.lang.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.
        java.lang.IllegalArgumentException - if there are multiple or no target objects provided for a ..1 ("to one") association
        Since:
        20.6
      • 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 java.util.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).
        Returns:
        true if this association is changing over time, else false
      • getLinks

        public <T extends IProductComponent> java.util.Collection<IProductComponentLink<T>> getLinks​(IProductComponent prodCmpt,
                                                                                                     java.util.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:
        java.lang.IllegalArgumentException - if there is no method annotated with @IpsAssociationLinks. This is the case if the association is a derived union.
        Since:
        3.22