Repository: incubator-unomi
Updated Branches:
  refs/heads/master 5653606cf -> 9f1bab437


UNOMI-133 Consent grant renaming to consent Status

Signed-off-by: Serge Huber <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/9f1bab43
Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/9f1bab43
Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/9f1bab43

Branch: refs/heads/master
Commit: 9f1bab437fd93826dc54d318ed00d3b2e3161437
Parents: 5653606
Author: Serge Huber <[email protected]>
Authored: Thu Nov 23 15:37:33 2017 +0100
Committer: Serge Huber <[email protected]>
Committed: Thu Nov 23 15:37:33 2017 +0100

----------------------------------------------------------------------
 .../main/java/org/apache/unomi/api/Consent.java | 78 ++++++++++----------
 .../java/org/apache/unomi/api/ConsentGrant.java | 27 -------
 .../org/apache/unomi/api/ConsentStatus.java     | 27 +++++++
 .../main/java/org/apache/unomi/api/Profile.java |  6 +-
 .../apache/unomi/itests/ModifyConsentIT.java    |  6 +-
 .../baseplugin/actions/ModifyConsentAction.java |  2 +-
 .../conditions/modifyConsentEventCondition.json |  8 +-
 .../services/services/ProfileServiceImpl.java   |  2 +-
 8 files changed, 78 insertions(+), 78 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/9f1bab43/api/src/main/java/org/apache/unomi/api/Consent.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/unomi/api/Consent.java 
b/api/src/main/java/org/apache/unomi/api/Consent.java
index 1f60252..4276d2d 100644
--- a/api/src/main/java/org/apache/unomi/api/Consent.java
+++ b/api/src/main/java/org/apache/unomi/api/Consent.java
@@ -31,8 +31,8 @@ import java.util.Map;
 public class Consent {
 
     private String typeIdentifier; // type identifiers are defined and managed 
externally of Apache Unomi
-    private ConsentGrant grant;
-    private Date grantDate;
+    private ConsentStatus status;
+    private Date statusDate;
     private Date revokeDate;
 
     /**
@@ -44,36 +44,36 @@ public class Consent {
     /**
      * A constructor to directly build a consent with all it's properties
      * @param typeIdentifier the identifier of the type this consent applies to
-     * @param grant the type of grant that we are storing for this consent. 
May be one of @ConsentGrant.DENY, @ConsentGrant.GRANT, @ConsentGrant.REVOKE
-     * @param grantDate the starting date at which this consent was given
+     * @param status the type of status that we are storing for this consent. 
May be one of @ConsentStatus.DENIED, @ConsentStatus.GRANTED, 
@ConsentStatus.REVOKED
+     * @param statusDate the starting date at which this consent was given
      * @param revokeDate the date at which this consent will (automatically) 
revoke
      */
-    public Consent(String typeIdentifier, ConsentGrant grant, Date grantDate, 
Date revokeDate) {
+    public Consent(String typeIdentifier, ConsentStatus status, Date 
statusDate, Date revokeDate) {
         this.typeIdentifier = typeIdentifier;
-        this.grant = grant;
-        this.grantDate = grantDate;
+        this.status = status;
+        this.statusDate = statusDate;
         this.revokeDate = revokeDate;
     }
 
     /**
      * A constructor from a map used for example when we use the deserialized 
data from event
      * properties.
-     * @param consentMap a Map that contains the following key-value pairs : 
typeIdentifier:String, grant:String (must
-     *                   be one of GRANT, DENY or REVOKE), grantDate:String 
(ISO8601 date format !), revokeDate:String (ISO8601 date format !)
+     * @param 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 !)
      * @param dateFormat a DateFormat instance to convert the date string to 
date objects
      */
     public Consent(Map<String,Object> consentMap, DateFormat dateFormat) 
throws ParseException {
         if (consentMap.containsKey("typeIdentifier")) {
             setTypeIdentifier((String) consentMap.get("typeIdentifier"));
         }
-        if (consentMap.containsKey("grant")) {
-            String grantString = (String) consentMap.get("grant");
-            setGrant(ConsentGrant.valueOf(grantString));
+        if (consentMap.containsKey("status")) {
+            String consentStatus = (String) consentMap.get("status");
+            setStatus(ConsentStatus.valueOf(consentStatus));
         }
-        if (consentMap.containsKey("grantDate")) {
-            String grantDateStr = (String) consentMap.get("grantDate");
-            if (grantDateStr != null && grantDateStr.trim().length() > 0) {
-                setGrantDate(dateFormat.parse(grantDateStr));
+        if (consentMap.containsKey("statusDate")) {
+            String statusDateStr = (String) consentMap.get("statusDate");
+            if (statusDateStr != null && statusDateStr.trim().length() > 0) {
+                setStatusDate(dateFormat.parse(statusDateStr));
             }
         }
         if (consentMap.containsKey("revokeDate")) {
@@ -102,19 +102,19 @@ public class Consent {
     }
 
     /**
-     * Retrieves the grant for this consent. This is of type @ConsentGrant
-     * @return the current value for the grant.
+     * Retrieves the status for this consent. This is of type @ConsentStatus
+     * @return the current value for the status.
      */
-    public ConsentGrant getGrant() {
-        return grant;
+    public ConsentStatus getStatus() {
+        return status;
     }
 
     /**
-     * Sets the grant for this consent. A Consent Grant of type REVOKE means 
that this consent is meant to be destroyed.
-     * @param grant the grant to set on this consent
+     * Sets the status for this consent. A Consent status of type REVOKED 
means that this consent is meant to be destroyed.
+     * @param status the status to set on this consent
      */
-    public void setGrant(ConsentGrant grant) {
-        this.grant = grant;
+    public void setStatus(ConsentStatus status) {
+        this.status = status;
     }
 
     /**
@@ -122,16 +122,16 @@ public class Consent {
      * considered valid yet.
      * @return a valid date or null if this date was not set.
      */
-    public Date getGrantDate() {
-        return grantDate;
+    public Date getStatusDate() {
+        return statusDate;
     }
 
     /**
      * Sets the date from which this consent applies.
-     * @param grantDate a valid Date or null if we set not starting date 
(immediately valid)
+     * @param statusDate a valid Date or null if we set not starting date 
(immediately valid)
      */
-    public void setGrantDate(Date grantDate) {
-        this.grantDate = grantDate;
+    public void setStatusDate(Date statusDate) {
+        this.statusDate = statusDate;
     }
 
     /**
@@ -169,8 +169,8 @@ public class Consent {
      */
     @XmlTransient
     public boolean isConsentGrantedAtDate(Date testDate) {
-        if (getGrantDate().before(testDate) && (getRevokeDate() == null || 
(getRevokeDate().after(testDate)))) {
-            if (getGrant().equals(ConsentGrant.GRANT)) {
+        if (getStatusDate().before(testDate) && (getRevokeDate() == null || 
(getRevokeDate().after(testDate)))) {
+            if (getStatus().equals(ConsentStatus.GRANTED)) {
                 return true;
             }
         }
@@ -182,18 +182,18 @@ public class Consent {
      * 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.
-     * @param dateFormat a dateFormat instance such as ISO8601DateFormat to 
generate the String formats for the grantDate
+     * @param dateFormat a dateFormat instance such as ISO8601DateFormat to 
generate the String formats for the statusDate
      *                   and revokeDate map entries.
-     * @return a Map that contains the following key-value pairs : 
typeIdentifier:String, grant:String (must
-     *                   be one of GRANT, DENY or REVOKE), grantDate:String 
(generated by the dateFormat), revokeDate:String (generated by the dateFormat)
+     * @return 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)
      */
     @XmlTransient
     public Map<String,Object> toMap(DateFormat dateFormat) {
         Map<String,Object> map = new LinkedHashMap<>();
         map.put("typeIdentifier", typeIdentifier);
-        map.put("grant", grant.toString());
-        if (grantDate != null) {
-            map.put("grantDate", dateFormat.format(grantDate));
+        map.put("status", status.toString());
+        if (statusDate != null) {
+            map.put("statusDate", dateFormat.format(statusDate));
         }
         if (revokeDate != null) {
             map.put("revokeDate", dateFormat.format(revokeDate));
@@ -205,8 +205,8 @@ public class Consent {
     public String toString() {
         final StringBuilder sb = new StringBuilder("Consent{");
         sb.append("typeIdentifier='").append(typeIdentifier).append('\'');
-        sb.append(", grant=").append(grant);
-        sb.append(", grantDate=").append(grantDate);
+        sb.append(", status=").append(status);
+        sb.append(", statusDate=").append(statusDate);
         sb.append(", revokeDate=").append(revokeDate);
         sb.append('}');
         return sb.toString();

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/9f1bab43/api/src/main/java/org/apache/unomi/api/ConsentGrant.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/unomi/api/ConsentGrant.java 
b/api/src/main/java/org/apache/unomi/api/ConsentGrant.java
deleted file mode 100644
index fea2642..0000000
--- a/api/src/main/java/org/apache/unomi/api/ConsentGrant.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.unomi.api;
-
-/**
- * This enum class represents the type of grant a @Consent might have. The 
revoke grant type is a special one used to
- * remove a consent for a profile.
- */
-public enum ConsentGrant {
-    GRANT,
-    DENY,
-    REVOKE
-}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/9f1bab43/api/src/main/java/org/apache/unomi/api/ConsentStatus.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/unomi/api/ConsentStatus.java 
b/api/src/main/java/org/apache/unomi/api/ConsentStatus.java
new file mode 100644
index 0000000..d51fab0
--- /dev/null
+++ b/api/src/main/java/org/apache/unomi/api/ConsentStatus.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.unomi.api;
+
+/**
+ * This enum class represents the type of grant a @Consent might have. The 
revoke grant type is a special one used to
+ * remove a consent for a profile.
+ */
+public enum ConsentStatus {
+    GRANTED,
+    DENIED,
+    REVOKED
+}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/9f1bab43/api/src/main/java/org/apache/unomi/api/Profile.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/unomi/api/Profile.java 
b/api/src/main/java/org/apache/unomi/api/Profile.java
index a6f7ec0..899d1b1 100644
--- a/api/src/main/java/org/apache/unomi/api/Profile.java
+++ b/api/src/main/java/org/apache/unomi/api/Profile.java
@@ -214,14 +214,14 @@ public class Profile extends Item {
 
     /**
      * Set a consent into the profile.
-     * @param consent if the consent is a REVOKE grant, it will try to remove 
a consent with the same type id if it
+     * @param consent if the consent is REVOKED, it will try to remove a 
consent with the same type id if it
      *                exists for the profile.
-     * @return true if the operation was successful (inserted excpetion in the 
case of a revoke grant, in which case
+     * @return true if the operation was successful (inserted exception in the 
case of a revoked consent, in which case
      * it is successful if there was a consent to revoke).
      */
     @XmlTransient
     public boolean setConsent(Consent consent) {
-        if (ConsentGrant.REVOKE.equals(consent.getGrant())) {
+        if (ConsentStatus.REVOKED.equals(consent.getStatus())) {
             if (consents.containsKey(consent.getTypeIdentifier())) {
                 consents.remove(consent.getTypeIdentifier());
                 return true;

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/9f1bab43/itests/src/test/java/org/apache/unomi/itests/ModifyConsentIT.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/unomi/itests/ModifyConsentIT.java 
b/itests/src/test/java/org/apache/unomi/itests/ModifyConsentIT.java
index 52e60ef..0d7ebfa 100644
--- a/itests/src/test/java/org/apache/unomi/itests/ModifyConsentIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/ModifyConsentIT.java
@@ -18,7 +18,7 @@ package org.apache.unomi.itests;
 
 import com.fasterxml.jackson.databind.util.ISO8601DateFormat;
 import org.apache.unomi.api.Consent;
-import org.apache.unomi.api.ConsentGrant;
+import org.apache.unomi.api.ConsentStatus;
 import org.apache.unomi.api.Event;
 import org.apache.unomi.api.Profile;
 import org.apache.unomi.api.services.EventService;
@@ -72,10 +72,10 @@ public class ModifyConsentIT extends BaseIT {
         modifyConsentEvent.setPersistent(false);
 
         ISO8601DateFormat dateFormat = new ISO8601DateFormat();
-        Consent consent1 = new Consent("consentType01", ConsentGrant.GRANT, 
new Date(), null);
+        Consent consent1 = new Consent("consentType01", ConsentStatus.GRANTED, 
new Date(), null);
         modifyConsentEvent.setProperty("consent", consent1.toMap(dateFormat));
         int changes = eventService.send(modifyConsentEvent);
-        Consent consent2 = new Consent("consentType02", ConsentGrant.GRANT, 
new Date(), null);
+        Consent consent2 = new Consent("consentType02", ConsentStatus.GRANTED, 
new Date(), null);
         modifyConsentEvent.setProperty("consent", consent2.toMap(dateFormat));
         changes |= eventService.send(modifyConsentEvent);
 

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/9f1bab43/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/ModifyConsentAction.java
----------------------------------------------------------------------
diff --git 
a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/ModifyConsentAction.java
 
b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/ModifyConsentAction.java
index 344d5eb..7facccf 100644
--- 
a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/ModifyConsentAction.java
+++ 
b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/ModifyConsentAction.java
@@ -46,7 +46,7 @@ public class ModifyConsentAction implements ActionExecutor {
         ISO8601DateFormat dateFormat = new ISO8601DateFormat();
         Map consentMap = (Map) 
event.getProperties().get(CONSENT_PROPERTY_NAME);
         if (consentMap != null) {
-            if (consentMap.containsKey("typeIdentifier") && 
consentMap.containsKey("grant")) {
+            if (consentMap.containsKey("typeIdentifier") && 
consentMap.containsKey("status")) {
                 Consent consent = null;
                 try {
                     consent = new Consent(consentMap, dateFormat);

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/9f1bab43/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/modifyConsentEventCondition.json
----------------------------------------------------------------------
diff --git 
a/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/modifyConsentEventCondition.json
 
b/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/modifyConsentEventCondition.json
index e808aa8..6dd0334 100644
--- 
a/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/modifyConsentEventCondition.json
+++ 
b/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/modifyConsentEventCondition.json
@@ -2,7 +2,7 @@
   "metadata": {
     "id": "modifyConsentEventCondition",
     "name": "modifyConsentEventCondition",
-    "description": "Used to match grant modifications on a specific consent",
+    "description": "Used to match status modifications on a specific consent",
     "systemTags": [
       "profileTags",
       "event",
@@ -33,9 +33,9 @@
         {
           "type": "eventPropertyCondition",
           "parameterValues": {
-            "propertyName": "properties.consent.grant",
+            "propertyName": "properties.consent.status",
             "comparisonOperator": "equals",
-            "propertyValue": "parameter::consentGrant"
+            "propertyValue": "parameter::consentStatus"
           }
         }
       ]
@@ -50,7 +50,7 @@
       "multivalued": false
     },
     {
-      "id": "consentGrant",
+      "id": "consentStatus",
       "type": "String",
       "multivalued": false
     }

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/9f1bab43/services/src/main/java/org/apache/unomi/services/services/ProfileServiceImpl.java
----------------------------------------------------------------------
diff --git 
a/services/src/main/java/org/apache/unomi/services/services/ProfileServiceImpl.java
 
b/services/src/main/java/org/apache/unomi/services/services/ProfileServiceImpl.java
index a7d2949..1f83160 100644
--- 
a/services/src/main/java/org/apache/unomi/services/services/ProfileServiceImpl.java
+++ 
b/services/src/main/java/org/apache/unomi/services/services/ProfileServiceImpl.java
@@ -530,7 +530,7 @@ public class ProfileServiceImpl implements ProfileService, 
SynchronousBundleList
                         
if(masterProfile.getConsents().get(key).getRevokeDate().before(new Date())) {
                             masterProfile.getConsents().remove(key);
                             masterProfileChanged[0] = true;
-                        } else 
if(masterProfile.getConsents().get(key).getGrantDate().before(value.getGrantDate()))
 {
+                        } else 
if(masterProfile.getConsents().get(key).getStatusDate().before(value.getStatusDate()))
 {
                             masterProfile.getConsents().replace(key, value);
                             masterProfileChanged[0] = true;
                         }

Reply via email to