dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #00356
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 109: dhis-web-maintenance-user: Fixed bug #339955 Email address validation. Added field phoneNumber to...
------------------------------------------------------------
revno: 109
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Tue 2009-03-24 15:27:01 +0100
message:
dhis-web-maintenance-user: Fixed bug #339955 Email address validation. Added field phoneNumber to User. Added general ValidationUtils class in dhis-support-system.
added:
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java
dhis-2/dhis-services/dhis-service-user-hibernate/src/main/resources/org/hisp/dhis/user/hibernate/User.hbm.xml
dhis-2/dhis-support/dhis-support-system/pom.xml
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/pom.xml
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/AddUserAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/UpdateUserAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/ValidateUserAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/addUserForm.vm
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/javascript/user.js
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/updateUserForm.vm
dhis-2/pom.xml
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java 2009-03-24 14:27:01 +0000
@@ -54,6 +54,8 @@
private String firstName;
private String email;
+
+ private String phoneNumber;
/**
* All OrgUnits where the user could belong
@@ -66,9 +68,6 @@
// hashCode and equals
// -------------------------------------------------------------------------
- /**
- * No real candidate key here. Doing the best we can.
- */
@Override
public int hashCode()
{
@@ -76,15 +75,11 @@
int result = 1;
result = result * prime + surname.hashCode();
- result = result * prime + firstName.hashCode();
- result = result * prime + (email != null ? email.hashCode() : 0);
+ result = result * prime + firstName.hashCode();
return result;
}
- /**
- * No real candidate key here. Doing the best we can.
- */
@Override
public boolean equals( Object o )
{
@@ -106,9 +101,7 @@
final User other = (User) o;
return surname.equals( other.getSurname() )
- && firstName.equals( other.getFirstName() )
- && ((email == null && other.getEmail() == null) || email.equals( other.getEmail() ));
-
+ && firstName.equals( other.getFirstName() );
}
// -------------------------------------------------------------------------
@@ -125,6 +118,16 @@
this.id = id;
}
+ public String getFirstName()
+ {
+ return firstName;
+ }
+
+ public void setFirstName( String firstName )
+ {
+ this.firstName = firstName;
+ }
+
public String getSurname()
{
return surname;
@@ -145,16 +148,16 @@
this.email = email;
}
- public String getFirstName()
- {
- return firstName;
- }
-
- public void setFirstName( String firstName )
- {
- this.firstName = firstName;
- }
-
+ public String getPhoneNumber()
+ {
+ return phoneNumber;
+ }
+
+ public void setPhoneNumber( String phoneNumber )
+ {
+ this.phoneNumber = phoneNumber;
+ }
+
public Collection<OrganisationUnit> getOrganisationUnits()
{
return organisationUnits;
@@ -164,5 +167,4 @@
{
this.organisationUnits = organisationUnits;
}
-
}
=== modified file 'dhis-2/dhis-services/dhis-service-user-hibernate/src/main/resources/org/hisp/dhis/user/hibernate/User.hbm.xml'
--- dhis-2/dhis-services/dhis-service-user-hibernate/src/main/resources/org/hisp/dhis/user/hibernate/User.hbm.xml 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-services/dhis-service-user-hibernate/src/main/resources/org/hisp/dhis/user/hibernate/User.hbm.xml 2009-03-24 14:27:01 +0000
@@ -12,19 +12,15 @@
<generator class="native"/>
</id>
- <property name="surname">
- <column name="surname" not-null="true" length="160"/>
- </property>
+ <property name="surname" not-null="true" length="160"/>
- <property name="firstName">
- <column name="firstname" not-null="true" length="160"/>
- </property>
+ <property name="firstName" not-null="true" length="160"/>
- <property name="email">
- <column name="email" length="160"/>
- </property>
-
- <set name="organisationUnits" table="usermembership">
+ <property name="email" length="160"/>
+
+ <property name="phoneNumber" length="80"/>
+
+ <set name="organisationUnits" table="usermembership">
<key column="userinfoid"/>
<many-to-many class="org.hisp.dhis.organisationunit.OrganisationUnit"
column="organisationunitid" foreign-key="fk_userinfo_organisationunitid"/>
=== modified file 'dhis-2/dhis-support/dhis-support-system/pom.xml'
--- dhis-2/dhis-support/dhis-support-system/pom.xml 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-support/dhis-support-system/pom.xml 2009-03-24 14:27:01 +0000
@@ -61,6 +61,10 @@
<artifactId>commons-math</artifactId>
</dependency>
<dependency>
+ <groupId>commons-validator</groupId>
+ <artifactId>commons-validator</artifactId>
+ </dependency>
+ <dependency>
<groupId>jep</groupId>
<artifactId>jep</artifactId>
</dependency>
=== added file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java 2009-03-24 14:27:01 +0000
@@ -0,0 +1,86 @@
+package org.hisp.dhis.system.util;
+
+/*
+ * Copyright (c) 2004-2007, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Locale;
+
+import org.apache.commons.validator.DateValidator;
+import org.apache.commons.validator.EmailValidator;
+import org.apache.commons.validator.UrlValidator;
+
+/**
+ * @author Lars Helge Overland
+ * @version $Id$
+ */
+public class ValidationUtils
+{
+ /**
+ * Validates whether an email string is valid.
+ *
+ * @param email the email string.
+ * @return true if the email string is valid, false otherwise.
+ */
+ public static boolean emailIsValid( String email )
+ {
+ return EmailValidator.getInstance().isValid( email );
+ }
+
+ /**
+ * Validates whether a date string is valid for the given Locale.
+ *
+ * @param date the date string.
+ * @param locale the Locale
+ * @return true if the date string is valid, false otherwise.
+ */
+ public static boolean dateIsValid( String date, Locale locale )
+ {
+ return DateValidator.getInstance().isValid( date, locale );
+ }
+
+ /**
+ * Validates whether a date string is valid for the default Locale.
+ *
+ * @param date the date string.
+ * @return true if the date string is valid, false otherwise.
+ */
+ public static boolean dateIsValid( String date )
+ {
+ return dateIsValid( date, null );
+ }
+
+ /**
+ * Validates whether an URL string is valid.
+ *
+ * @param url the URL string.
+ * @return true if the URL string is valid, false otherwise.
+ */
+ public static boolean urlIsValid( String url )
+ {
+ return new UrlValidator().isValid( url );
+ }
+}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/pom.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/pom.xml 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/pom.xml 2009-03-24 14:27:01 +0000
@@ -35,6 +35,10 @@
</dependency>
<dependency>
<groupId>org.hisp.dhis</groupId>
+ <artifactId>dhis-support-system</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hisp.dhis</groupId>
<artifactId>dhis-web-commons</artifactId>
</dependency>
<dependency>
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/AddUserAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/AddUserAction.java 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/AddUserAction.java 2009-03-24 14:27:01 +0000
@@ -118,6 +118,13 @@
{
this.email = email;
}
+
+ private String phoneNumber;
+
+ public void setPhoneNumber( String phoneNumber )
+ {
+ this.phoneNumber = phoneNumber;
+ }
private String passwordUnMatched;
@@ -166,6 +173,7 @@
user.setSurname( surname );
user.setFirstName( firstName );
user.setEmail( email );
+ user.setPhoneNumber( phoneNumber );
user.setOrganisationUnits( orgUnits );
UserCredentials userCredentials = new UserCredentials();
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/UpdateUserAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/UpdateUserAction.java 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/UpdateUserAction.java 2009-03-24 14:27:01 +0000
@@ -120,6 +120,13 @@
this.email = email;
}
+ private String phoneNumber;
+
+ public void setPhoneNumber( String phoneNumber )
+ {
+ this.phoneNumber = phoneNumber;
+ }
+
private Collection<String> selectedList = new ArrayList<String>();
public void setSelectedList( Collection<String> selectedList )
@@ -158,6 +165,7 @@
user.setSurname( surname );
user.setFirstName( firstName );
user.setEmail( email );
+ user.setPhoneNumber( phoneNumber );
user.setOrganisationUnits( units );
UserCredentials userCredentials = userStore.getUserCredentials( user );
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/ValidateUserAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/ValidateUserAction.java 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/ValidateUserAction.java 2009-03-24 14:27:01 +0000
@@ -28,6 +28,7 @@
*/
import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.system.util.ValidationUtils;
import org.hisp.dhis.user.UserCredentials;
import org.hisp.dhis.user.UserStore;
@@ -89,6 +90,13 @@
{
this.firstName = firstName;
}
+
+ private String email;
+
+ public void setEmail( String email )
+ {
+ this.email = email;
+ }
private String rawPassword;
@@ -175,17 +183,24 @@
return INPUT;
}
+ if ( firstName == null || firstName.trim().length() == 0 )
+ {
+ message = i18n.getString( "specify_first_name" );
+
+ return INPUT;
+ }
+
if ( surname == null || surname.trim().length() == 0 )
{
message = i18n.getString( "specify_surname" );
return INPUT;
}
-
- if ( firstName == null || firstName.trim().length() == 0 )
+
+ if ( email != null && !ValidationUtils.emailIsValid( email ) )
{
- message = i18n.getString( "specify_first_name" );
-
+ message = i18n.getString( "email_is_not_valid" );
+
return INPUT;
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties 2009-03-14 08:30:32 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties 2009-03-24 14:27:01 +0000
@@ -157,4 +157,6 @@
edit_user_role = Update user role
create_new_user_role = Create new user role
filter_by_user_name = Filter by username
-filter_by_role_name = Filter by rolename
\ No newline at end of file
+filter_by_role_name = Filter by rolename
+phone_number = Phone number
+email_is_not_valid = E-mail is not valid
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/addUserForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/addUserForm.vm 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/addUserForm.vm 2009-03-24 14:27:01 +0000
@@ -43,6 +43,12 @@
<td></td>
<td></td>
</tr>
+ <tr>
+ <td><label for="phoneNumber">$i18n.getString( "phone_number" )</label></td>
+ <td><input type="text" id="phoneNumber" name="phoneNumber" style="width:20em"></td>
+ <td></td>
+ <td></td>
+ </tr>
<tr>
<td colspan="4" height="10"></td>
</tr>
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/javascript/user.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/javascript/user.js 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/javascript/user.js 2009-03-24 14:27:01 +0000
@@ -53,7 +53,8 @@
'&surname=' + getFieldValue( 'surname' ) +
'&firstName=' + getFieldValue( 'firstName' ) +
'&rawPassword=' + getFieldValue( 'rawPassword' ) +
- '&retypePassword=' + getFieldValue( 'retypePassword' ) );
+ '&retypePassword=' + getFieldValue( 'retypePassword' ) +
+ '&email=' + getFieldValue( 'email' ) );
return false;
}
@@ -96,7 +97,8 @@
'&surname=' + getFieldValue( 'surname' ) +
'&firstName=' + getFieldValue( 'firstName' ) +
'&rawPassword=' + getFieldValue( 'rawPassword' ) +
- '&retypePassword=' + getFieldValue( 'retypePassword' ) );
+ '&retypePassword=' + getFieldValue( 'retypePassword' ) +
+ '&email=' + getFieldValue( 'email' ) );
return false;
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/updateUserForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/updateUserForm.vm 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/updateUserForm.vm 2009-03-24 14:27:01 +0000
@@ -47,6 +47,12 @@
<td></td>
<td></td>
</tr>
+ <tr>
+ <td><label for="phoneNumber">$i18n.getString( "phone_number" )</label></td>
+ <td><input type="text" id="phoneNumber" name="phoneNumber" value="$!encoder.htmlEncode( $userCredentials.user.phoneNumber )" style="width:20em"></td>
+ <td></td>
+ <td></td>
+ </tr>
<tr>
<td colspan="4" height="10"></td>
</tr>
=== modified file 'dhis-2/pom.xml'
--- dhis-2/pom.xml 2009-03-10 07:42:12 +0000
+++ dhis-2/pom.xml 2009-03-24 14:27:01 +0000
@@ -334,6 +334,11 @@
<version>1.2</version>
</dependency>
<dependency>
+ <groupId>commons-validator</groupId>
+ <artifactId>commons-validator</artifactId>
+ <version>1.3.1</version>
+ </dependency>
+ <dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1</version>
--
Trunk
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription.