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:cn.org.once.cstack.service.impl.UserServiceImpl.java

@Override
@Transactional/*from  w ww .  java  2 s .  co  m*/
public void remove(User user) throws ServiceException, CheckException {
    try {
        logger.debug("remove : Methods parameters : " + user.toString());
        logger.info("Starting removing User " + user.getLastName());

        List<Application> applications = applicationService.findAllByUser(user);

        for (Application application : applications) {
            applicationService.remove(application, user);
        }

        this.deleteAllUsersMessages(user);

        userDAO.delete(user);

        logger.info("UserService : User successfully removed ");

    } catch (PersistenceException e) {

        logger.error("UserService Error : failed to remove " + user.getLastName() + " : " + e);

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

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

/**
 * Methode permettant de mettre l'application dans un tat particulier pour
 * se prmunir d'ventuel problme de concurrence au niveau mtier
 *//*w w w  .j av  a 2 s  .  c o m*/
@Override
@Transactional
public void setStatus(Application application, Status status) throws ServiceException {
    try {
        Application _application = applicationDAO.findOne(application.getId());
        _application.setStatus(status);
        application.setStatus(status);
        applicationDAO.saveAndFlush(_application);
    } catch (PersistenceException e) {
        throw new ServiceException(e.getLocalizedMessage(), e);
    }
}

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

@Transactional
@Override/*  w w  w . j  av a  2 s  .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.");

    try {

        for (Application application : listApplications) {
            for (Server server : application.getServers()) {
                configShell.put("port", server.getSshPort());
                configShell.put("dockerManagerAddress", server.getApplication().getManagerIp());
                String command = "sh /cloudunit/scripts/change-password.sh " + userLogin + " " + newPassword;
                configShell.put("password", application.getUser().getPassword());
                shellUtils.executeShell(command, configShell);

                String commandSource = "source /etc/environment";
                logger.debug(commandSource);

                shellUtils.executeShell(commandSource, configShell);
            }
        }

    } catch (Exception e) {
        logger.error("change Passsword - Error execute ssh Request - " + e);
        throw new ServiceException(e.getLocalizedMessage(), e);
    }
}

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

@Override
@Transactional//from w w w.  ja v  a2  s.c  o  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;
}

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

@Override
public List<Module> findByApp(Application application) throws ServiceException {
    try {// www.  j  ava 2 s .c  om
        return moduleDAO.findByApp(application.getName(), cuInstanceName);
    } catch (PersistenceException e) {
        logger.error("Error ModuleService : error findByApp Method : " + e);
        throw new ServiceException(e.getLocalizedMessage(), e);
    }
}

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

@Override
public List<Module> findAll() throws ServiceException {
    try {//from w  w  w. j a va  2s  .  c o  m
        logger.debug("start findAll");
        List<Module> modules = moduleDAO.findAll();
        logger.info("ModuleService : All Modules found ");
        return modules;
    } catch (PersistenceException e) {
        logger.error("Error ModuleService : error findAll Method : " + e);
        throw new ServiceException(e.getLocalizedMessage(), e);
    }
}

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

@Override
public Module findById(Integer id) throws ServiceException {
    try {//  ww  w  .  j  ava2s.c o m
        logger.debug("findById : Methods parameters : " + id);
        Module module = moduleDAO.findOne(id);
        logger.info("Module with id " + id + " found!");
        return module;
    } catch (PersistenceException e) {
        logger.error("Error ModuleService : error findById Method : " + e);
        throw new ServiceException(e.getLocalizedMessage(), e);
    }
}

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

@Override
public Module findByContainerID(String id) throws ServiceException {
    try {/* ww w. j av  a  2s. c om*/
        return moduleDAO.findByContainerID(id);
    } catch (PersistenceException e) {
        logger.error("Error ModuleService : error findCloudId Method : " + e);
        throw new ServiceException(e.getLocalizedMessage(), e);
    }
}

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

@Override
public Module findByName(String moduleName) throws ServiceException {
    try {//from  ww w. j a va2s. c o  m
        logger.debug("findByName : " + moduleName);
        Module module = moduleDAO.findByName(moduleName);
        logger.debug("findByName : " + module);

        return module;
    } catch (PersistenceException e) {
        logger.error("Error ModuleService : error findName Method : " + e);
        throw new ServiceException(e.getLocalizedMessage(), e);
    }
}

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

@Override
public List<Module> findByAppAndUser(User user, String applicationName) throws ServiceException {
    try {/*  w w w  . j  av  a  2 s  .com*/
        List<Module> modules = moduleDAO.findByAppAndUser(user.getId(), applicationName, cuInstanceName);
        return modules;
    } catch (PersistenceException e) {
        logger.error("Error ModuleService : error findByAppAndUser Method : " + e);
        throw new ServiceException(e.getLocalizedMessage(), e);
    }
}