IDEMPIERE-1408 User window must not show System users

This commit is contained in:
Carlos Ruiz 2013-10-03 10:42:44 -05:00
parent ab6efd300c
commit cd1722bd6b
3 changed files with 112 additions and 7 deletions

View File

@ -26,8 +26,6 @@ import java.util.Collection;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.activation.DataHandler; import javax.activation.DataHandler;
import javax.activation.DataSource; import javax.activation.DataSource;
@ -1097,14 +1095,20 @@ public final class EMail implements Serializable
/** /**
* Validate format of an email address * Validate format of an email address
* IDEMPIERE-1409 - based on http://examples.javacodegeeks.com/core-java/util/regex/matcher/validate-email-address-with-java-regular-expression-example/ * IDEMPIERE-1409
* @return true if email has proper format * @return true if email has proper format
*/ */
private static final String EMAIL_PATTERN = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
private static Pattern pattern = Pattern.compile(EMAIL_PATTERN);
public static boolean validate(final String email) { public static boolean validate(final String email) {
Matcher matcher = pattern.matcher(email); try
return matcher.matches(); {
new InternetAddress (email, true);
}
catch (Exception e)
{
log.log(Level.WARNING, email + ": " + e.toString());
return false;
}
return true;
} }
/************************************************************************** /**************************************************************************

View File

@ -12,5 +12,8 @@ Export-Package: compiere.model,
Fragment-Host: org.adempiere.base;bundle-version="0.0.0" Fragment-Host: org.adempiere.base;bundle-version="0.0.0"
Eclipse-PatchFragment: true Eclipse-PatchFragment: true
Import-Package: junit.framework;version="3.8.2", Import-Package: junit.framework;version="3.8.2",
org.junit;version="4.8.2",
org.junit.runner,
org.junit.runners;version="4.8.2",
org.supercsv.io, org.supercsv.io,
org.supercsv.prefs org.supercsv.prefs

View File

@ -0,0 +1,98 @@
/**********************************************************************
* This file is part of iDempiere ERP Open Source *
* http://www.idempiere.org *
* *
* Copyright (C) Contributors *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *
* MA 02110-1301, USA. *
* *
* Contributors: *
* - Carlos Ruiz - globalqss *
**********************************************************************/
package test.functional;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import java.util.Collection;
import org.compiere.util.EMail;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
/*
* Unit test sample from http://examples.javacodegeeks.com/core-java/util/regex/matcher/validate-email-address-with-java-regular-expression-example/
*/
@RunWith(Parameterized.class)
public class EmailFormatValidatorTest {
private String arg;
private Boolean expectedValidation;
public EmailFormatValidatorTest(String str, Boolean expectedValidation) {
this.arg = str;
this.expectedValidation = expectedValidation;
}
@BeforeClass
public static void initialize() {
}
@Parameters
public static Collection<Object[]> data() {
Object[][] data = new Object[][] {
{ "javacodegeeks@gmail.com.2j",true },
{ "java@java@oracle.com", false }, // you cannot have @ twice in the address
{ "java!!!@example.com", true },
{ "mysite@.com", false }, // tld cannot start with a dot
{ "javacodegees.com", false }, // must contain a @ character and a tld
{ ".javacodegees.com@at.com", true },
{ "javacodegees..javacom@at.com", true },
{ "javacodegeeks@gmail.com",true },
{ "nikos+mylist@gmail.com", true },
{ "abc.efg-900@gmail-list.com", true },
{ "abc123@example.com.gr", true },
{ "username+detail@example.com", true },
{ "user@example.museum", true },
{ "myemail+sketchysite@gmail.com", true },
{ "micky.o'finnagan@wherever.com", true },
{ "exampleemail@testing.info", true },
{ "marcelo.calbucci%mandic@fapesp.com.br", true },
{ "customer/department=shipping@example.com", true },
{ "$A12345@example.com", true },
{ "!def!xyz%abc@example.com", true },
{ "_somename@example.com", true },
{ "nuñez@globalqss.com", false },
{ "name@tld", true },
{ "john@server.department.company.com", true }
};
return Arrays.asList(data);
}
@Test
public void test() {
Boolean res = EMail.validate(this.arg);
String validv = (res) ? "valid" : "invalid";
System.out.println("EMail "+arg+ " is " + validv);
assertEquals("Result", this.expectedValidation, res);
}
}