Search in sources :

Example 1 with EntityNotFoundException

use of com.joliciel.jochre.EntityNotFoundException in project jochre by urieli.

the class SecurityDao method loadUser.

public User loadUser(int userId) {
    User user = this.jochreSession.getObjectCache().getEntity(User.class, userId);
    if (user == null) {
        NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
        String sql = "SELECT " + SELECT_USER + " FROM ocr_user WHERE user_id=:user_id";
        MapSqlParameterSource paramSource = new MapSqlParameterSource();
        paramSource.addValue("user_id", userId);
        LOG.info(sql);
        logParameters(paramSource);
        try {
            user = jt.queryForObject(sql, paramSource, new UserMapper());
        } catch (EmptyResultDataAccessException ex) {
            throw new EntityNotFoundException("No User found for user id " + userId);
        }
        this.jochreSession.getObjectCache().putEntity(User.class, userId, user);
    }
    return user;
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) EntityNotFoundException(com.joliciel.jochre.EntityNotFoundException)

Example 2 with EntityNotFoundException

use of com.joliciel.jochre.EntityNotFoundException in project jochre by urieli.

the class GraphicsDao method loadGroupOfShapes.

GroupOfShapes loadGroupOfShapes(int groupId) {
    GroupOfShapes group = this.jochreSession.getObjectCache().getEntity(GroupOfShapes.class, groupId);
    if (group == null) {
        NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
        String sql = "SELECT " + SELECT_GROUP + " FROM ocr_group WHERE group_id=:group_id";
        MapSqlParameterSource paramSource = new MapSqlParameterSource();
        paramSource.addValue("group_id", groupId);
        LOG.debug(sql);
        logParameters(paramSource);
        try {
            group = jt.queryForObject(sql, paramSource, new GroupOfShapesMapper());
        } catch (EmptyResultDataAccessException ex) {
            throw new EntityNotFoundException("No GroupOfShapes found for groupId " + groupId);
        }
        this.jochreSession.getObjectCache().putEntity(GroupOfShapes.class, groupId, group);
    }
    return group;
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) EntityNotFoundException(com.joliciel.jochre.EntityNotFoundException)

Example 3 with EntityNotFoundException

use of com.joliciel.jochre.EntityNotFoundException in project jochre by urieli.

the class GraphicsDao method loadParagraph.

Paragraph loadParagraph(int paragraphId) {
    Paragraph paragraph = this.jochreSession.getObjectCache().getEntity(Paragraph.class, paragraphId);
    if (paragraph == null) {
        NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
        String sql = "SELECT " + SELECT_PARAGRAPH + " FROM ocr_paragraph WHERE paragraph_id=:paragraph_id";
        MapSqlParameterSource paramSource = new MapSqlParameterSource();
        paramSource.addValue("paragraph_id", paragraphId);
        LOG.debug(sql);
        logParameters(paramSource);
        try {
            paragraph = jt.queryForObject(sql, paramSource, new ParagraphMapper());
        } catch (EmptyResultDataAccessException ex) {
            throw new EntityNotFoundException("No Paragraph found for paragraphId " + paragraphId);
        }
        this.jochreSession.getObjectCache().putEntity(Paragraph.class, paragraphId, paragraph);
    }
    return paragraph;
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) EntityNotFoundException(com.joliciel.jochre.EntityNotFoundException)

Example 4 with EntityNotFoundException

use of com.joliciel.jochre.EntityNotFoundException in project jochre by urieli.

the class DocumentDao method loadAuthor.

public Author loadAuthor(int authorId) {
    Author author = this.jochreSession.getObjectCache().getEntity(Author.class, authorId);
    if (author == null) {
        NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
        String sql = "SELECT " + SELECT_AUTHOR + " FROM ocr_author WHERE author_id=:author_id";
        MapSqlParameterSource paramSource = new MapSqlParameterSource();
        paramSource.addValue("author_id", authorId);
        LOG.info(sql);
        logParameters(paramSource);
        try {
            author = jt.queryForObject(sql, paramSource, new AuthorMapper());
        } catch (EmptyResultDataAccessException ex) {
            throw new EntityNotFoundException("No Author found for authorId " + authorId);
        }
        this.jochreSession.getObjectCache().putEntity(Author.class, authorId, author);
    }
    return author;
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) EntityNotFoundException(com.joliciel.jochre.EntityNotFoundException)

Example 5 with EntityNotFoundException

use of com.joliciel.jochre.EntityNotFoundException in project jochre by urieli.

the class LoginController method onClick$btnLogin.

@Listen("onClick = #btnLogin")
public void onClick$btnLogin(Event event) {
    try {
        LOG.debug("onClick$btnLogin");
        Session session = Sessions.getCurrent();
        SecurityDao securityDao = SecurityDao.getInstance(jochreSession);
        User user = null;
        try {
            user = securityDao.findUser(txtUserName.getValue());
        } catch (EntityNotFoundException enfe) {
            LOG.debug("Unknown user: " + txtUserName.getValue());
            lblError.setVisible(true);
        }
        if (user != null) {
            boolean success = user.login(txtPassword.getValue());
            if (!success) {
                LOG.debug("Login failed");
                lblError.setVisible(true);
                Parameters parameters = securityDao.loadParameters();
                Date lastFailedLoginAttempt = parameters.getLastFailedLoginAttempt();
                Date now = new Date();
                long diff = now.getTime() - lastFailedLoginAttempt.getTime();
                LOG.debug("time since last failed login: " + diff);
            } else {
                LOG.debug("Login success");
                session.setAttribute(SESSION_JOCHRE_USER, user);
                Executions.sendRedirect("docs.zul");
            }
        }
    } catch (Exception e) {
        LOG.error("Failure in onClick$btnLogin", e);
        throw new RuntimeException(e);
    }
}
Also used : User(com.joliciel.jochre.security.User) Parameters(com.joliciel.jochre.security.Parameters) EntityNotFoundException(com.joliciel.jochre.EntityNotFoundException) Date(java.util.Date) EntityNotFoundException(com.joliciel.jochre.EntityNotFoundException) Session(org.zkoss.zk.ui.Session) JochreSession(com.joliciel.jochre.JochreSession) SecurityDao(com.joliciel.jochre.security.SecurityDao) Listen(org.zkoss.zk.ui.select.annotation.Listen)

Aggregations

EntityNotFoundException (com.joliciel.jochre.EntityNotFoundException)13 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)12 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)12 NamedParameterJdbcTemplate (org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)12 JochreSession (com.joliciel.jochre.JochreSession)1 Parameters (com.joliciel.jochre.security.Parameters)1 SecurityDao (com.joliciel.jochre.security.SecurityDao)1 User (com.joliciel.jochre.security.User)1 Date (java.util.Date)1 Session (org.zkoss.zk.ui.Session)1 Listen (org.zkoss.zk.ui.select.annotation.Listen)1