UserServiceInt.java
package com.sunilos.proj0.service;
import java.util.List;
import com.sunilos.proj0.dto.RoleDTO;
import com.sunilos.proj0.dto.UserDTO;
import com.sunilos.proj0.exception.ApplicationException;
/**
* User Service interface.
*
* @author SunilOS
* @version 1.0
* @Copyright (c) SunilOS
*/
public interface UserServiceInt {
/**
* Adds a user
*
* @param dto
*/
public long add(UserDTO dto);
/**
* Registers a user
*
* @param dto
* @throws ApplicationException
*/
public long registerUser(UserDTO dto);
/**
* Updates a User
*
* @param dto
*/
public void update(UserDTO dto);
/**
* Deletes a user
*
* @param dto
*/
public void delete(long id);
/**
* Finds user by Login
*
* @param login
* : get parameter
* @return dto
*/
public UserDTO findByLogin(String login);
/**
* Finds user by PK
*
* @param pk
* : get parameter
* @return dto
*/
public UserDTO findByPK(long pk);
/**
* Searches Users with pagination
*
* @return list : List of Users
* @param dto
* : Search Parameters
* @param pageNo
* : Current Page No.
* @param pageSize
* : Size of Page
*/
public List search(UserDTO dto, int pageNo, int pageSize);
/**
* Searches Users
*
* @return list : List of Users
* @param dto
* : Search Parameters
*/
public List search(UserDTO dto);
/**
* Change Password By pk
*
* @param pk
* ,oldPassword,newPassword : get parameter
* @return dto
*/
public boolean changePassword(Long id, String oldPassword,
String newPassword);
/**
* User Authentication
*
* @return dto : Contains User's information
* @param dto
*/
public UserDTO authenticate(UserDTO dto);
/**
* Lock User for certain time duration
*
* @return boolean : true if success otherwise false
* @param login
* : User Login
*/
public boolean lock(String login);
/**
* Reset Password of User with auto generated Password
*
* @return boolean : true if success otherwise false
* @param login
* : User Login
* @throws ApplicationException
*/
public boolean resetPassword(String login) throws ApplicationException;
/**
* Send the password of User to his Email
*
* @return boolean : true if success otherwise false
* @param login
* : User Login
* @throws ApplicationException
*/
public boolean forgetPassword(String login) throws ApplicationException;
/**
* Get User Roles
*
* @return RoleDTO : User Role
* @param dto
*/
public RoleDTO getRole(UserDTO dto);
/**
* Update User access
* package com.sunilos.proj0.util;
/**
* Validates Input data.
*
* @author SunilOS
* @version 1.0
* @Copyright (c) SunilOS
*
*/
public class package com.sunilos.proj0.service;
import java.util.List;
import com.sunilos.proj0.dto.RoleDTO;
import com.sunilos.proj0.dto.UserDTO;
import com.sunilos.proj0.exception.ApplicationException;
/**
* User Service interface.
*
* @author SunilOS
* @version 1.0
* @Copyright (c) SunilOS
*/
public interface UserServiceInt {
/**
* Adds a user
*
* @param dto
*/
public long add(UserDTO dto);
/**
* Registers a user
*
* @param dto
* @throws ApplicationException
*/
public long registerUser(UserDTO dto);
/**
* Updates a User
*
* @param dto
*/
public void update(UserDTO dto);
/**
* Deletes a user
*
* @param dto
*/
public void delete(long id);
/**
* Finds user by Login
*
* @param login
* : get parameter
* @return dto
*/
public UserDTO findByLogin(String login);
/**
* Finds user by PK
*
* @param pk
* : get parameter
* @return dto
*/
public UserDTO findByPK(long pk);
/**
* Searches Users with pagination
*
* @return list : List of Users
* @param dto
* : Search Parameters
* @param pageNo
* : Current Page No.
* @param pageSize
* : Size of Page
*/
public List search(UserDTO dto, int pageNo, int pageSize);
/**
* Searches Users
*
* @return list : List of Users
* @param dto
* : Search Parameters
*/
public List search(UserDTO dto);
/**
* Change Password By pk
*
* @param pk
* ,oldPassword,newPassword : get parameter
* @return dto
*/
public boolean changePassword(Long id, String oldPassword,
String newPassword);
/**
* User Authentication
*
* @return dto : Contains User's information
* @param dto
*/
public UserDTO authenticate(UserDTO dto);
/**
* Lock User for certain time duration
*
* @return boolean : true if success otherwise false
* @param login
* : User Login
*/
public boolean lock(String login);
/**
* Reset Password of User with auto generated Password
*
* @return boolean : true if success otherwise false
* @param login
* : User Login
* @throws ApplicationException
*/
public boolean resetPassword(String login) throws ApplicationException;
/**
* Send the password of User to his Email
*
* @return boolean : true if success otherwise false
* @param login
* : User Login
* @throws ApplicationException
*/
public boolean forgetPassword(String login) throws ApplicationException;
/**
* Get User Roles
*
* @return RoleDTO : User Role
* @param dto
*/
public RoleDTO getRole(UserDTO dto);
/**
* Update User access
*
* @return dto
* @param dto
* @throws ApplicationException
*/
public UserDTO updateAccess(UserDTO dto);
}
{
/**
* Checks if value is Null
*
* @param val
* @return
*/
public static boolean isNull(String val) {
if (val == null || val.trim().length() == 0) {
return true;
} else {
return false;
}
}
/**
* Checks if value is NOT Null
*
* @param val
* @return
*/
public static boolean isNotNull(String val) {
return !isNull(val);
}
/**
* Checks if value is an Integer
*
* @param val
* @return
*/
public static boolean isInteger(String val) {
if (isNotNull(val)) {
try {
int i = Integer.parseInt(val);
return true;
} catch (NumberFormatException e) {
return false;
}
} else {
return false;
}
}
/**
* Checks if value is Long
*
* @param val
* @return
*/
public static boolean isLong(String val) {
if (isNotNull(val)) {
try {
long i = Long.parseLong(val);
return true;
} catch (NumberFormatException e) {
return false;
}
} else {
return false;
}
}
/**
* Checks if value is valid Email ID
*
* @param val
* @return
*/
public static boolean isEmail(String val) {
String emailreg = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
if (isNotNull(val)) {
try {
return val.matches(emailreg);
} catch (NumberFormatException e) {
return false;
}
} else {
return false;
}
}
/**
* Test above methods
*
* @param args
*/
public static void main(String[] args) {
System.out.println("Not Null 1" + isEmail("salman.khan@sunrays.co.in"));
System.out.println("Not Null 2" + isNotNull("salman"));
System.out.println("Not Null 3" + isNotNull(null));
System.out.println("Not Null 4" + isNull("123"));
System.out.println("Is Int " + isInteger(null));
System.out.println("Is Int " + isInteger("ABC1"));
System.out.println("Is Int " + isInteger("123"));
System.out.println("Is Int " + isNotNull("123"));
}
}
* @return dto
* @param dto
* @throws ApplicationException
*/
public UserDTO updateAccess(UserDTO dto);
}