Class Consent

  • All Implemented Interfaces:
    Serializable

    public class Consent
    extends Object
    implements Serializable
    A consent is an object attached to a profile that indicates whether the profile has agreed or denied a special consent type. For example a user might have agreed to receiving a newsletter but might have not agreed to being tracked.
    See Also:
    Serialized Form
    • Constructor Detail

      • Consent

        public Consent()
        Empty constructor mostly used for JSON (de-) serialization
      • Consent

        public Consent​(String scope,
                       String typeIdentifier,
                       ConsentStatus status,
                       Date statusDate,
                       Date revokeDate)
        A constructor to directly build a consent with all it's properties
        Parameters:
        scope - the scope for this consent
        typeIdentifier - the identifier of the type this consent applies to
        status - the type of status that we are storing for this consent. May be one of @ConsentStatus.DENIED, @ConsentStatus.GRANTED, @ConsentStatus.REVOKED
        statusDate - the starting date at which this consent was given
        revokeDate - the date at which this consent will (automatically) revoke
      • Consent

        public Consent​(Map<String,​Object> consentMap,
                       DateFormat dateFormat)
                throws ParseException
        A constructor from a map used for example when we use the deserialized data from event properties.
        Parameters:
        consentMap - a Map that contains the following key-value pairs : typeIdentifier:String, status:String (must be one of GRANTED, DENIED or REVOKED), statusDate:String (ISO8601 date format !), revokeDate:String (ISO8601 date format !)
        dateFormat - a DateFormat instance to convert the date string to date objects
        Throws:
        ParseException - in case one of the dates failed to parse properly
    • Method Detail

      • getScope

        public String getScope()
        Retrieve the scope for this consent
        Returns:
        a scope identifier
      • setScope

        public void setScope​(String scope)
        Set the scope for this consent
        Parameters:
        scope - a scope identifier
      • setTypeIdentifier

        public void setTypeIdentifier​(String typeIdentifier)
        Set the type identifier. This must be (no validation is done) a unique identifier for the consent type. These are usually externally defined, Apache Unomi has no knowledge of them except for this type identifier.
        Parameters:
        typeIdentifier - a unique String to identify the consent type
      • getTypeIdentifier

        public String getTypeIdentifier()
        Retrieve the consent type identifier for this consent.
        Returns:
        a String containing the type identifier
      • getStatus

        public ConsentStatus getStatus()
        Retrieves the status for this consent. This is of type @ConsentStatus
        Returns:
        the current value for the status.
      • setStatus

        public void setStatus​(ConsentStatus status)
        Sets the status for this consent. A Consent status of type REVOKED means that this consent is meant to be destroyed.
        Parameters:
        status - the status to set on this consent
      • getStatusDate

        public Date getStatusDate()
        Retrieve the date at which this consent was given. If this date is in the future the consent should not be considered valid yet.
        Returns:
        a valid date or null if this date was not set.
      • setStatusDate

        public void setStatusDate​(Date statusDate)
        Sets the date from which this consent applies.
        Parameters:
        statusDate - a valid Date or null if we set not starting date (immediately valid)
      • getRevokeDate

        public Date getRevokeDate()
        Retrieves the end date for this consent. After this date the consent is no longer valid and should be disposed of. If this date is not set it means the consent will never expire
        Returns:
        a valid Date or null to indicate an unlimited consent
      • setRevokeDate

        public void setRevokeDate​(Date revokeDate)
        Sets the end date for this consent. After this date the consent is no longer valid and should be disposed of. If this date is not set it means the consent will never expire
        Parameters:
        revokeDate - a valid Date or null to indicate an unlimited consent
      • isConsentGrantedNow

        public boolean isConsentGrantedNow()
        Test if the consent is GRANTED right now.
        Returns:
        true if the consent is granted using the current date (internally a new Date() is created and the isConsentGrantedAtDate(java.util.Date) is called.
      • isConsentGrantedAtDate

        public boolean isConsentGrantedAtDate​(Date testDate)
        Tests if the consent is GRANTED at the specified date
        Parameters:
        testDate - the date against which to test the consent to be granted.
        Returns:
        true if the consent is granted at the specified date, false otherwise.
      • toMap

        public Map<String,​Object> toMap​(DateFormat dateFormat)
        This is a utility method to generate a Map based on the contents of the consents. The format of the map is the same as the one used in the Map Consent constructor. For dates you must specify a dateFormat that will be used to format the dates. This dateFormat should usually support ISO8601 to make integrate with Javascript clients easy to integrate.
        Parameters:
        dateFormat - a dateFormat instance such as ISO8601DateFormat to generate the String formats for the statusDate and revokeDate map entries.
        Returns:
        a Map that contains the following key-value pairs : typeIdentifier:String, status:String (must be one of GRANTED, DENIED or REVOKED), statusDate:String (generated by the dateFormat), revokeDate:String (generated by the dateFormat)