Example usage for javax.persistence PersistenceException getLocalizedMessage

List of usage examples for javax.persistence PersistenceException getLocalizedMessage

Introduction

In this page you can find the example usage for javax.persistence PersistenceException getLocalizedMessage.

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:fr.treeptik.cloudunit.service.impl.ImageServiceImpl.java

@Override
public Long countNumberOfInstances(String moduleName, String applicationName, String userLogin)
        throws ServiceException {
    try {// w  w w  .j  a  va2 s .  c  om
        return imageDAO.countNumberOfInstances(moduleName, applicationName, userLogin);
    } catch (PersistenceException e) {
        logger.error("Error ImageService : error find number of images Method : " + e);
        throw new ServiceException(e.getLocalizedMessage(), e);

    }
}

From source file:cn.org.once.cstack.service.impl.UserServiceImpl.java

@Override
public List<User> findByEmail(String email) throws ServiceException {
    try {/*www. jav a 2s .  c o m*/
        logger.debug("Methods parameters : " + email);
        return userDAO.findByEmail(email);
    } catch (PersistenceException e) {
        throw new ServiceException(e.getLocalizedMessage(), e);
    }
}

From source file:cn.org.once.cstack.service.impl.UserServiceImpl.java

@Override
public User findByLogin(String login) throws ServiceException {
    try {//from  ww  w .ja va2s . c o  m
        logger.debug("Methods parameters : " + login);
        return userDAO.findByLogin(login);
    } catch (PersistenceException e) {
        throw new ServiceException(e.getLocalizedMessage(), e);
    }
}

From source file:cn.org.once.cstack.service.impl.ImageServiceImpl.java

@Override
@Transactional//w w  w.  ja va  2s.  co m
public void remove(Image image) throws ServiceException {
    try {
        logger.debug("remove : Methods parameters : " + image.toString());
        logger.info("Starting removing application " + image.getName());

        imageDAO.delete(image);

        logger.info("ImageService : Image successfully removed ");

    } catch (PersistenceException e) {

        logger.error("ImageService Error : failed to remove " + image.getName() + " : " + e);

        throw new ServiceException(e.getLocalizedMessage(), e);
    }
}

From source file:cn.org.once.cstack.service.impl.UserServiceImpl.java

@Override
@Transactional// www.j  a  v  a 2  s .co m
public User update(User user) throws ServiceException {

    logger.debug("update : Methods parameters : " + user.toString());
    logger.info("UserService : Starting updating user " + user.getLastName());
    try {
        userDAO.saveAndFlush(user);
    } catch (PersistenceException e) {
        logger.error("UserService Error : update User" + e);
        throw new ServiceException(e.getLocalizedMessage(), e);
    }

    logger.info("UserService : User " + user.getLogin() + " successfully updated.");

    return user;
}

From source file:cn.org.once.cstack.service.impl.UserServiceImpl.java

@Override
public User findById(Integer id) throws ServiceException {
    try {/*from  w w w  .j  av  a  2  s  .  co m*/
        logger.debug("findById : Methods parameters : " + id);
        User user = userDAO.findOne(id);
        logger.info("user with id " + id + " found!");
        return user;
    } catch (PersistenceException e) {
        logger.error("Error UserService : error findById Method : " + e);
        throw new ServiceException(e.getLocalizedMessage(), e);

    }
}

From source file:cn.org.once.cstack.service.impl.UserServiceImpl.java

@Override
public List<User> findAll() throws ServiceException {
    try {//from   w  w  w.  ja v a2s  .c  om
        logger.debug("start findAll");
        List<User> users = userDAO.findAll();
        logger.info("UserService : All Users found ");
        return users;
    } catch (PersistenceException e) {
        logger.error("Error UserService : error findById Method : " + e);
        throw new ServiceException(e.getLocalizedMessage(), e);

    }
}

From source file:cn.org.once.cstack.service.impl.UserServiceImpl.java

@Override
@Transactional/* ww w  .j av a2 s . co  m*/
public void activationAccount(User user) throws ServiceException {
    try {
        logger.debug("UserService : User " + user.toString());

        user = userDAO.findOne(user.getId());
        user.setStatus(User.STATUS_ACTIF);
        user = userDAO.saveAndFlush(user);

    } catch (PersistenceException e) {
        logger.error("UserService Error : Activate User Account" + e);
        throw new ServiceException(e.getLocalizedMessage(), e);
    }

    logger.info(
            "UserService : User " + user.getLastName() + " account activated - status = " + user.getStatus());

}

From source file:cn.org.once.cstack.service.impl.UserServiceImpl.java

@Transactional
@Override/*ww w  .  java  2s.c  o  m*/
public void changePassword(User user, String newPassword) throws ServiceException {

    Map<String, String> configShell = new HashMap<>();
    String userLogin = user.getLogin();
    user = this.findById(user.getId());
    user.setPassword(newPassword);
    List<Application> listApplications = user.getApplications();

    try {
        logger.debug("Methods parameters : " + user + " new password : " + newPassword);

        userDAO.saveAndFlush(user);
    } catch (PersistenceException e) {
        logger.error("Error UserService : error changePassword : " + e);
        throw new ServiceException(e.getLocalizedMessage(), e);
    }
    logger.info("UserService : User " + user.getLastName() + " password successfully updated.");

}

From source file:cn.org.once.cstack.service.impl.UserServiceImpl.java

@Override
@Transactional//w  ww.  java 2s .co m
public User create(User user) throws ServiceException, CheckException {
    // Map<String, Object> mapConfigMail = new HashMap<>();

    try {
        // VALIDATION

        if (user.getClearedPassword().length() < 6 & user.getClearedPassword().length() > 16) {
            throw new CheckException("The password must be have between 6 and 16 characters");
        }
        //ENCODING THE PASSWORD

        user.setPassword(new CustomPasswordEncoder().encode(user.getClearedPassword()));

        if (user.getEmail() == null || user.getLogin() == null || user.getPassword() == null) {
            throw new CheckException("One of the required is not set");
        }

        if (user.getLogin().length() > 20) {
            throw new CheckException("The password must be have between 6 and 16 characters");
        }

        if (user.getPassword().length() < 6 & user.getPassword().length() > 16) {
            throw new CheckException("The password must be have between 6 and 16 characters");
        }

        if (!Pattern
                .compile("^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
                        + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$")
                .matcher(user.getEmail()).matches()) {
            throw new CheckException("This email is incorrect. Please verify.");
        }

        if (this.findByLogin(user.getLogin()) != null) {
            throw new CheckException("This login is already used");
        }
        if (!this.findByEmail(user.getEmail()).isEmpty()) {
            throw new CheckException("There is already a account registered with this email");
        }
        Role role = new Role();
        role.setDescription("ROLE_USER");
        role = roleDAO.findByRole(role.getDescription());
        user.setRole(role);
        user.setStatus(User.STATUS_MAIL_NOT_CONFIRMED);
        user.setSignin(new Date());

        user = userDAO.save(user);

        // mapConfigMail.put("user", user);
        // mapConfigMail.put("emailType", "activation");
        // emailUtils.sendEmail(mapConfigMail);

    } catch (PersistenceException e) {
        logger.error("UserService Error : Create User" + e);
        throw new ServiceException(e.getLocalizedMessage(), e);
    }
    logger.info("UserService : User " + user.getLastName() + " successfully created.");

    return user;
}