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;
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations