syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andreapatrice...@apache.org
Subject syncope git commit: [SYNCOPE-1060] missing fix about dates on membership attributes on self registration
Date Mon, 10 Apr 2017 07:02:48 GMT
Repository: syncope
Updated Branches:
  refs/heads/master b024bc8ee -> fad07ef43


[SYNCOPE-1060] missing fix about dates on membership attributes on self registration


Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/fad07ef4
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/fad07ef4
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/fad07ef4

Branch: refs/heads/master
Commit: fad07ef43d271a302f1b3fb5c99ee6dc68cfdbff
Parents: b024bc8
Author: Andrea Patricelli <andreapatricelli@apache.org>
Authored: Fri Apr 7 17:05:37 2017 +0200
Committer: Andrea Patricelli <andreapatricelli@apache.org>
Committed: Mon Apr 10 09:02:22 2017 +0200

----------------------------------------------------------------------
 .../enduser/resources/BaseUserSelfResource.java | 67 ++++++++++++++++++++
 .../resources/UserSelfCreateResource.java       | 36 ++++-------
 .../enduser/resources/UserSelfReadResource.java | 20 +-----
 .../resources/UserSelfUpdateResource.java       | 24 +------
 4 files changed, 80 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/fad07ef4/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/BaseUserSelfResource.java
----------------------------------------------------------------------
diff --git a/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/BaseUserSelfResource.java
b/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/BaseUserSelfResource.java
new file mode 100644
index 0000000..6071642
--- /dev/null
+++ b/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/BaseUserSelfResource.java
@@ -0,0 +1,67 @@
+/*
+ * 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.syncope.client.enduser.resources;
+
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import org.apache.commons.lang3.time.FastDateFormat;
+import org.apache.syncope.common.lib.to.AttrTO;
+import org.apache.syncope.common.lib.to.PlainSchemaTO;
+
+public abstract class BaseUserSelfResource extends BaseResource {
+
+    private static final long serialVersionUID = -5892402817902884085L;
+
+    protected void dateToMillis(final Map<String, AttrTO> plainAttrMap, final PlainSchemaTO
plainSchema)
+            throws ParseException {
+        if (plainAttrMap.containsKey(plainSchema.getKey())) {
+            FastDateFormat fmt = FastDateFormat.getInstance(plainSchema.getConversionPattern());
+
+            AttrTO dateAttr = plainAttrMap.get(plainSchema.getKey());
+            List<String> milliValues = new ArrayList<>(dateAttr.getValues().size());
+            for (String value : dateAttr.getValues()) {
+                milliValues.add(String.valueOf(fmt.parse(value).getTime()));
+            }
+            dateAttr.getValues().clear();
+            dateAttr.getValues().addAll(milliValues);
+        }
+    }
+
+    protected void millisToDate(final Map<String, AttrTO> plainAttrMap, final PlainSchemaTO
plainSchema)
+            throws IllegalArgumentException {
+        if (plainAttrMap.containsKey(plainSchema.getKey())) {
+            FastDateFormat fmt = FastDateFormat.getInstance(plainSchema.getConversionPattern());
+
+            AttrTO dateAttr = plainAttrMap.get(plainSchema.getKey());
+            List<String> formattedValues = new ArrayList<>(dateAttr.getValues().size());
+            for (String value : dateAttr.getValues()) {
+                try {
+                    formattedValues.add(fmt.format(Long.valueOf(value)));
+                } catch (NumberFormatException e) {
+                    throw new IllegalArgumentException("Invalid format value for " + value);
+                }
+            }
+            dateAttr.getValues().clear();
+            dateAttr.getValues().addAll(formattedValues);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/fad07ef4/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/UserSelfCreateResource.java
----------------------------------------------------------------------
diff --git a/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/UserSelfCreateResource.java
b/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/UserSelfCreateResource.java
index c8baa53..fbb2e33 100644
--- a/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/UserSelfCreateResource.java
+++ b/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/UserSelfCreateResource.java
@@ -22,9 +22,7 @@ import static org.apache.syncope.client.enduser.resources.BaseResource.LOG;
 
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
 import java.util.HashSet;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import javax.servlet.http.HttpServletRequest;
@@ -33,7 +31,6 @@ import javax.ws.rs.core.Response;
 import org.apache.commons.collections4.IterableUtils;
 import org.apache.commons.collections4.Predicate;
 import org.apache.commons.lang3.SerializationUtils;
-import org.apache.commons.lang3.time.FastDateFormat;
 import org.apache.syncope.client.enduser.SyncopeEnduserConstants;
 import org.apache.syncope.client.enduser.SyncopeEnduserSession;
 import org.apache.syncope.client.enduser.annotations.Resource;
@@ -45,7 +42,7 @@ import org.apache.syncope.common.lib.to.UserTO;
 import org.apache.syncope.common.rest.api.service.UserSelfService;
 
 @Resource(key = "userSelfCreate", path = "/api/self/create")
-public class UserSelfCreateResource extends BaseResource {
+public class UserSelfCreateResource extends BaseUserSelfResource {
 
     private static final long serialVersionUID = -2721621682300247583L;
 
@@ -86,28 +83,8 @@ public class UserSelfCreateResource extends BaseResource {
             }
 
             if (isSelfRegistrationAllowed() && userTO != null) {
-                Map<String, AttrTO> userPlainAttrMap = userTO.getPlainAttrMap();
-
-                // millis -> Date conversion
-                for (PlainSchemaTO plainSchema : SyncopeEnduserSession.get().getDatePlainSchemas())
{
-                    if (userPlainAttrMap.containsKey(plainSchema.getKey())) {
-                        FastDateFormat fmt = FastDateFormat.getInstance(plainSchema.getConversionPattern());
-
-                        AttrTO dateAttr = userPlainAttrMap.get(plainSchema.getKey());
-                        List<String> formattedValues = new ArrayList<>(dateAttr.getValues().size());
-                        for (String value : dateAttr.getValues()) {
-                            try {
-                                formattedValues.add(fmt.format(Long.valueOf(value)));
-                            } catch (NumberFormatException e) {
-                                throw new IllegalArgumentException("Invalid format value
for " + value);
-                            }
-                        }
-                        dateAttr.getValues().clear();
-                        dateAttr.getValues().addAll(formattedValues);
-                    }
-                }
 
-                // membership attributes management
+                // 1. membership attributes management
                 Set<AttrTO> membAttrs = new HashSet<>();
                 for (AttrTO attr : userTO.getPlainAttrs()) {
                     if (attr.getSchema().contains("#")) {
@@ -133,6 +110,15 @@ public class UserSelfCreateResource extends BaseResource {
                 }
                 userTO.getPlainAttrs().removeAll(membAttrs);
 
+                // 2. millis -> Date conversion for PLAIN attributes of USER and its MEMBERSHIPS
+                Map<String, AttrTO> userPlainAttrMap = userTO.getPlainAttrMap();
+                for (PlainSchemaTO plainSchema : SyncopeEnduserSession.get().getDatePlainSchemas())
{
+                    millisToDate(userPlainAttrMap, plainSchema);
+                    for (MembershipTO membership : userTO.getMemberships()) {
+                        millisToDate(membership.getPlainAttrMap(), plainSchema);
+                    }
+                }
+
                 membAttrs.clear();
                 for (AttrTO attr : userTO.getDerAttrs()) {
                     if (attr.getSchema().contains("#")) {

http://git-wip-us.apache.org/repos/asf/syncope/blob/fad07ef4/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/UserSelfReadResource.java
----------------------------------------------------------------------
diff --git a/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/UserSelfReadResource.java
b/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/UserSelfReadResource.java
index 3d913e2..056e757 100644
--- a/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/UserSelfReadResource.java
+++ b/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/UserSelfReadResource.java
@@ -20,15 +20,11 @@ package org.apache.syncope.client.enduser.resources;
 
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
-import java.text.ParseException;
-import java.util.ArrayList;
-import java.util.List;
 import java.util.Map;
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import org.apache.commons.lang3.SerializationUtils;
-import org.apache.commons.lang3.time.FastDateFormat;
 import org.apache.syncope.client.enduser.SyncopeEnduserSession;
 import org.apache.syncope.client.enduser.annotations.Resource;
 import org.apache.syncope.common.lib.to.AttrTO;
@@ -39,7 +35,7 @@ import org.apache.wicket.request.resource.AbstractResource;
 import org.apache.wicket.request.resource.IResource;
 
 @Resource(key = "userSelfRead", path = "/api/self/read")
-public class UserSelfReadResource extends BaseResource {
+public class UserSelfReadResource extends BaseUserSelfResource {
 
     private static final long serialVersionUID = -9184809392631523912L;
 
@@ -111,18 +107,4 @@ public class UserSelfReadResource extends BaseResource {
         return response;
     }
 
-    private void dateToMillis(final Map<String, AttrTO> plainAttrMap, final PlainSchemaTO
plainSchema)
-            throws ParseException {
-        if (plainAttrMap.containsKey(plainSchema.getKey())) {
-            FastDateFormat fmt = FastDateFormat.getInstance(plainSchema.getConversionPattern());
-
-            AttrTO dateAttr = plainAttrMap.get(plainSchema.getKey());
-            List<String> milliValues = new ArrayList<>(dateAttr.getValues().size());
-            for (String value : dateAttr.getValues()) {
-                milliValues.add(String.valueOf(fmt.parse(value).getTime()));
-            }
-            dateAttr.getValues().clear();
-            dateAttr.getValues().addAll(milliValues);
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/fad07ef4/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/UserSelfUpdateResource.java
----------------------------------------------------------------------
diff --git a/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/UserSelfUpdateResource.java
b/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/UserSelfUpdateResource.java
index 9934aad..bc1a9fd 100644
--- a/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/UserSelfUpdateResource.java
+++ b/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/UserSelfUpdateResource.java
@@ -20,9 +20,7 @@ package org.apache.syncope.client.enduser.resources;
 
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
 import java.util.HashSet;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import javax.servlet.http.HttpServletRequest;
@@ -31,7 +29,6 @@ import javax.ws.rs.core.Response;
 import org.apache.commons.collections4.IterableUtils;
 import org.apache.commons.collections4.Predicate;
 import org.apache.commons.lang3.SerializationUtils;
-import org.apache.commons.lang3.time.FastDateFormat;
 import org.apache.syncope.client.enduser.SyncopeEnduserConstants;
 import org.apache.syncope.client.enduser.SyncopeEnduserSession;
 import org.apache.syncope.client.enduser.annotations.Resource;
@@ -45,7 +42,7 @@ import org.apache.wicket.request.resource.AbstractResource;
 import org.apache.wicket.request.resource.IResource;
 
 @Resource(key = "userSelfUpdate", path = "/api/self/update")
-public class UserSelfUpdateResource extends BaseResource {
+public class UserSelfUpdateResource extends BaseUserSelfResource {
 
     private static final long serialVersionUID = -2721621682300247583L;
 
@@ -187,23 +184,4 @@ public class UserSelfUpdateResource extends BaseResource {
         return response;
     }
 
-    private void millisToDate(final Map<String, AttrTO> plainAttrMap, final PlainSchemaTO
plainSchema)
-            throws IllegalArgumentException {
-        LOG.info("CONVERTING >>>>>>>>>> {}", plainSchema.getKey());
-        if (plainAttrMap.containsKey(plainSchema.getKey())) {
-            FastDateFormat fmt = FastDateFormat.getInstance(plainSchema.getConversionPattern());
-
-            AttrTO dateAttr = plainAttrMap.get(plainSchema.getKey());
-            List<String> formattedValues = new ArrayList<>(dateAttr.getValues().size());
-            for (String value : dateAttr.getValues()) {
-                try {
-                    formattedValues.add(fmt.format(Long.valueOf(value)));
-                } catch (NumberFormatException e) {
-                    throw new IllegalArgumentException("Invalid format value for " + value);
-                }
-            }
-            dateAttr.getValues().clear();
-            dateAttr.getValues().addAll(formattedValues);
-        }
-    }
 }


Mime
View raw message