Repository: syncope
Updated Branches:
  refs/heads/2_0_X bd3745196 -> eded0eb3a
  refs/heads/master 909ed6f56 -> b30099b68


[SYNCOPE-992] Use millis to date conversion for create too (used to be set for 
update only) + fix JS onChange events for datepicker


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

Branch: refs/heads/2_0_X
Commit: eded0eb3af5b96b513d934f19509bdf4b06e9df0
Parents: bd37451
Author: Francesco Chicchiriccò <ilgro...@apache.org>
Authored: Fri Jan 13 11:51:11 2017 +0100
Committer: Francesco Chicchiriccò <ilgro...@apache.org>
Committed: Fri Jan 13 11:51:11 2017 +0100

----------------------------------------------------------------------
 .../resources/UserSelfCreateResource.java       | 40 +++++++++++++++++---
 .../enduser/resources/UserSelfReadResource.java |  2 +
 .../resources/UserSelfUpdateResource.java       | 17 +++++----
 .../app/js/directives/dynamicPlainAttribute.js  |  9 ++++-
 4 files changed, 53 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/eded0eb3/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 58d108d..eddd439 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
@@ -19,17 +19,22 @@
 package org.apache.syncope.client.enduser.resources;
 
 import java.io.IOException;
+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;
 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.common.lib.to.AttrTO;
 import org.apache.syncope.common.lib.to.MembershipTO;
+import org.apache.syncope.common.lib.to.PlainSchemaTO;
 import org.apache.syncope.common.lib.to.UserTO;
 import org.apache.syncope.common.rest.api.service.UserSelfService;
 import org.slf4j.Logger;
@@ -72,6 +77,28 @@ public class UserSelfCreateResource extends 
AbstractBaseResource {
             }
 
             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
                 Set<AttrTO> membAttrs = new HashSet<>();
                 for (AttrTO attr : userTO.getPlainAttrs()) {
                     if (attr.getSchema().contains("#")) {
@@ -149,6 +176,7 @@ public class UserSelfCreateResource extends 
AbstractBaseResource {
 
                 LOG.debug("Received user self registration request for user: 
[{}]", userTO.getUsername());
                 LOG.trace("Received user self registration request is: [{}]", 
userTO);
+
                 // adapt request and create user
                 final Response res = userSelfService.create(userTO, true);
 
@@ -159,9 +187,9 @@ public class UserSelfCreateResource extends 
AbstractBaseResource {
                         
attributes.getResponse().write(res.getStatusInfo().getFamily().equals(
                                 Response.Status.Family.SUCCESSFUL)
                                         ? responseMessage.append("User: 
").append(userTO.getUsername()).append(
-                                        " successfully created")
+                                                " successfully created")
                                         : new 
StringBuilder().append("ErrorMessage{{ ").
-                                        
append(res.getStatusInfo().getReasonPhrase()).append(" }}"));
+                                                
append(res.getStatusInfo().getReasonPhrase()).append(" }}"));
                     }
                 });
                 response.setStatusCode(res.getStatus());
@@ -176,10 +204,10 @@ public class UserSelfCreateResource extends 
AbstractBaseResource {
             LOG.error("Could not create userTO", e);
             response.setError(Response.Status.BAD_REQUEST.getStatusCode(),
                     new StringBuilder().
-                    append("ErrorMessage{{ ").
-                    append(e.getMessage()).
-                    append(" }}").
-                    toString());
+                            append("ErrorMessage{{ ").
+                            append(e.getMessage()).
+                            append(" }}").
+                            toString());
         }
         return response;
     }

http://git-wip-us.apache.org/repos/asf/syncope/blob/eded0eb3/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 4f04f31..a792f00 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
@@ -56,6 +56,7 @@ public class UserSelfReadResource extends 
AbstractBaseResource {
             UserTO userTO = 
SerializationUtils.clone(SyncopeEnduserSession.get().getSelfTO());
             Map<String, AttrTO> userPlainAttrMap = userTO.getPlainAttrMap();
 
+            // Date -> millis conversion
             for (PlainSchemaTO plainSchema : 
SyncopeEnduserSession.get().getDatePlainSchemas()) {
                 if (userPlainAttrMap.containsKey(plainSchema.getKey())) {
                     FastDateFormat fmt = 
FastDateFormat.getInstance(plainSchema.getConversionPattern());
@@ -70,6 +71,7 @@ public class UserSelfReadResource extends 
AbstractBaseResource {
                 }
             }
 
+            // membership attributes management
             for (MembershipTO membership : userTO.getMemberships()) {
                 String groupName = membership.getGroupName();
                 for (AttrTO attr : membership.getPlainAttrs()) {

http://git-wip-us.apache.org/repos/asf/syncope/blob/eded0eb3/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 561811a..dbc6bef 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
@@ -64,9 +64,10 @@ public class UserSelfUpdateResource extends 
AbstractBaseResource {
             }
 
             UserTO userTO = MAPPER.readValue(request.getReader().readLine(), 
UserTO.class);
-            
+
             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());
@@ -85,6 +86,7 @@ public class UserSelfUpdateResource extends 
AbstractBaseResource {
                 }
             }
 
+            // membership attributes management
             Set<AttrTO> membAttrs = new HashSet<>();
             for (AttrTO attr : userTO.getPlainAttrs()) {
                 if (attr.getSchema().contains("#")) {
@@ -164,9 +166,10 @@ public class UserSelfUpdateResource extends 
AbstractBaseResource {
 
             final String responseMessage = 
res.getStatusInfo().getFamily().equals(Response.Status.Family.SUCCESSFUL)
                     ? new StringBuilder().
-                    append("User").append(userTO.getUsername()).append(" 
successfully updated").toString()
+                            
append("User").append(userTO.getUsername()).append(" successfully 
updated").toString()
                     : new StringBuilder().
-                    append("ErrorMessage{{ 
").append(res.getStatusInfo().getReasonPhrase()).append(" }}").toString();
+                            append("ErrorMessage{{ 
").append(res.getStatusInfo().getReasonPhrase()).append(" }}").
+                            toString();
             response.setWriteCallback(new WriteCallback() {
 
                 @Override
@@ -181,10 +184,10 @@ public class UserSelfUpdateResource extends 
AbstractBaseResource {
             LOG.error("Error while updating user", e);
             response.setError(Response.Status.BAD_REQUEST.getStatusCode(),
                     new StringBuilder().
-                    append("ErrorMessage{{ ").
-                    append(e.getMessage()).
-                    append(" }}").
-                    toString());
+                            append("ErrorMessage{{ ").
+                            append(e.getMessage()).
+                            append(" }}").
+                            toString());
         }
         return response;
     }

http://git-wip-us.apache.org/repos/asf/syncope/blob/eded0eb3/client/enduser/src/main/resources/META-INF/resources/app/js/directives/dynamicPlainAttribute.js
----------------------------------------------------------------------
diff --git 
a/client/enduser/src/main/resources/META-INF/resources/app/js/directives/dynamicPlainAttribute.js
 
b/client/enduser/src/main/resources/META-INF/resources/app/js/directives/dynamicPlainAttribute.js
index 19f1c9d..1aabdd3 100644
--- 
a/client/enduser/src/main/resources/META-INF/resources/app/js/directives/dynamicPlainAttribute.js
+++ 
b/client/enduser/src/main/resources/META-INF/resources/app/js/directives/dynamicPlainAttribute.js
@@ -93,9 +93,14 @@ angular.module('self')
                     }
 
                     $scope.bindDateToModel = function (selectedDate, 
selectedTime) {
-                      if (selectedDate && selectedTime) {
+                      if (selectedDate) {
                         var extractedDate = 
selectedDate.toString().substring(0, 15);
-                        var extractedTime = 
selectedTime.toString().substring(16);
+                        var extractedTime;
+                        if (selectedTime) {
+                          extractedTime = 
selectedTime.toString().substring(16);
+                        } else {
+                          extractedTime = '00:00:00';
+                        }
                         var resultDate = extractedDate + ' ' + extractedTime;
                         var tmpdate = new Date(resultDate);
                         var milliseconds = tmpdate.getTime();

Reply via email to