List of usage examples for org.springframework.dao DataAccessException getLocalizedMessage
public String getLocalizedMessage()
From source file:org.esco.portlets.news.services.EntityManagerImpl.java
/** * Sauvegarder une entit./*from w ww. j a v a 2 s . com*/ * @param entity * @see org.esco.portlets.news.services.EntityManager#saveEntity(org.esco.portlets.news.domain.Entity) */ @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW) public void saveEntity(final Entity entity) { if (entity == null) { throw new IllegalArgumentException("Can't save an entity when given a null Entity instance."); } try { this.entityDao.saveEntity(entity); } catch (DataIntegrityViolationException dive) { LOG.error("Could not save entity, duplicate entity id or name ??", dive); throw dive; } catch (DataAccessException e) { LOG.error("Could not save entity " + e.getLocalizedMessage(), e); throw e; } }
From source file:org.esco.portlets.news.services.EntityManagerImpl.java
/** * Obtenir une entit partir de son id.//from w w w.j a v a 2s .c o m * @param entityId * @return <code>Entity</code> * @see org.esco.portlets.news.services.EntityManager#getEntityById(java.lang.Long) */ public Entity getEntityById(final Long entityId) { try { return this.entityDao.getEntityById(entityId); } catch (DataAccessException e) { LOG.error("Get Entity By Id error : " + e.getLocalizedMessage()); throw e; } }
From source file:org.esco.portlets.news.services.EntityManagerImpl.java
/** * Supprimer une entit si aucune actagorie n'y est lie. * @param entityId/* w ww . ja va 2 s. co m*/ * @return true si la suppression s'est bien passe, faux sinon. * @see org.esco.portlets.news.services.EntityManager#deleteEntity(java.lang.Long) */ @Transactional(readOnly = false) public boolean deleteEntity(final Long entityId) { try { List<UserRole> lists = this.userDao.getUsersRolesForCtx(entityId, NewsConstants.CTX_E); if (this.entityDao.deleteEntityById(entityId)) { this.userDao.removeUsersRoleForCtx(entityId, NewsConstants.CTX_E); if (lists != null && !lists.isEmpty()) { for (UserRole ur : lists) { if (!this.userDao.isSuperAdmin(ur.getPrincipal()) && !this.userDao.userRoleExist(ur.getPrincipal())) { this.userDao.deleteUser(ur.getPrincipal(), false); } } } this.subDao.deleteAllSubscribersByCtxId(entityId, NewsConstants.CTX_E); return true; } return false; } catch (DataAccessException e) { LOG.error("Delete Entity error : " + e.getLocalizedMessage()); throw e; } }
From source file:org.esco.portlets.news.services.EntityManagerImpl.java
/** * Lister les entity dans lesquelles l'utilisateurs les droits d'accs. * @param uid/*from w ww . ja v a 2 s . c om*/ * @return <code>List<Entity></code> * @see org.esco.portlets.news.services.EntityManager#getEntitiesByUser(java.lang.String) */ public List<Entity> getEntitiesByUser(final String uid) { List<Entity> entities = null; try { if (this.userDao.isSuperAdmin(uid)) { entities = this.entityDao.getAllEntities(); } else { entities = this.entityDao.getEntitiesByUser(uid); } } catch (DataAccessException e) { LOG.error("Get Entites By User Error msg : " + e.getLocalizedMessage()); throw e; } return entities; }
From source file:org.esco.portlets.news.services.EntityManagerImpl.java
/** * Lister les entities par leur type.// www .j a va 2 s . co m * @param typeId Identifiant du type. * @return <code>List<Entity></code> * @see org.esco.portlets.news.services.EntityManager#getEntitiesByType(java.lang.Long) */ public List<Entity> getEntitiesByType(final Long typeId) { List<Entity> entities = null; try { entities = this.entityDao.getEntitiesByType(typeId); } catch (DataAccessException e) { LOG.error("Get Entites By Type Error msg : " + e.getLocalizedMessage()); throw e; } return entities; }
From source file:org.esco.portlets.news.services.EntityManagerImpl.java
/** * Lister les types disponibles pour les catgories de l'entit. * @param entityId/*from w w w . ja v a 2s . com*/ * @return <code>List<Type></code> * @see org.esco.portlets.news.services.EntityManager#getAutorizedTypesOfEntity(java.lang.Long) */ public List<Type> getAutorizedTypesOfEntity(final Long entityId) { List<Type> types = null; try { types = this.entityDao.getAuthorizedTypesOfEntity(entityId); } catch (DataAccessException e) { LOG.error("Get Authorized Types Of Entity Error msg : " + e.getLocalizedMessage()); throw e; } return types; }
From source file:org.esco.portlets.news.services.EntityManagerImpl.java
/** * Lier des types une entit./* w w w .j a va 2s.c om*/ * @param typeIds * @param entityId * @see org.esco.portlets.news.services.EntityManager#addAutorizedTypesOfEntity(java.util.List, java.lang.Long) */ @Transactional(readOnly = false) public void addAutorizedTypesOfEntity(final List<Long> typeIds, final Long entityId) { try { if (typeIds != null && !typeIds.isEmpty()) { this.entityDao.addAuthorizedTypesToEntity(typeIds, entityId); } else if (this.getAutorizedTypesOfEntity(entityId).isEmpty()) { List<Long> types = new ArrayList<Long>(); types.add(this.typeDao.getTypeByName(NewsConstants.DEFAULT_TYPE).getTypeId()); this.entityDao.addAuthorizedTypesToEntity(types, entityId); } } catch (DataAccessException e) { LOG.error("Add Authorized Types Of Entity Error msg : " + e.getLocalizedMessage()); throw e; } }
From source file:org.esco.portlets.news.services.EntityManagerImpl.java
/** * Supprime les types disponibles pour les entits, mais en vrifiant * qu'aucune des catgories de l'entit n'aient encore le type de li. * @param typeIds// w w w. j ava 2s. co m * @param entityId * @see org.esco.portlets.news.services.EntityManager#deleteAutorizedTypesOfEntity(java.util.List, java.lang.Long) */ @Transactional(readOnly = false) public void deleteAutorizedTypesOfEntity(final List<Long> typeIds, final Long entityId) { try { Type defaultType = this.typeDao.getTypeByName(NewsConstants.DEFAULT_TYPE); List<Long> type = new ArrayList<Long>(); typeIds.remove(defaultType.getTypeId()); boolean b = true; for (Long typeId : typeIds) { List<Category> cats = this.catDao.getCategoryByTypeOfEntity(typeId, entityId); if (cats == null || cats.isEmpty()) { type.add(typeId); } else { b = false; } } if (!type.isEmpty()) { this.entityDao.deleteAuthorizedTypesToEntity(typeIds, entityId); } if (!b) { String msg = "Delete of some types unauthorized, somes are always attached to Categories."; LOG.error(msg); throw new UnauthorizedException(msg); } } catch (DataAccessException e) { LOG.error("Delete Authorized Types Of Entity error : " + e.getLocalizedMessage()); throw e; } }
From source file:org.esco.portlets.news.services.EntityManagerImpl.java
/** * Add search filter to the entity./* w w w .ja v a2 s.c o m*/ * @param filter A filter. * @throws DataAccessException */ @Transactional(readOnly = false) public void addFilterToEntity(final Filter filter) { try { if (filter != null) { if (!this.filterDao.isFilterOnEntityExist(filter)) { this.filterDao.saveFilterOfEntity(filter); } else { LOG.error("Add Filter to Entity error : A same filter already exist."); throw new IllegalArgumentException("A same filter already exist."); } } } catch (DataAccessException e) { LOG.error("Add Filter to Entity error : " + e.getLocalizedMessage()); throw e; } }
From source file:org.esco.portlets.news.services.EntityManagerImpl.java
/** * update search filter to the entity.// w ww.j a v a2 s . com * @param filter A filter. * @throws DataAccessException */ @Transactional(readOnly = false) public void updateFilterToEntity(final Filter filter) { try { if (filter != null) { if (!this.filterDao.isFilterOnEntityExist(filter)) { this.filterDao.saveFilterOfEntity(filter); } else { LOG.error("update Filter to Entity error : A same filter already exist " + "or try to update a filter not modified."); throw new IllegalArgumentException("A same filter already exist."); } } } catch (DataAccessException e) { LOG.error("update Filter to Entity error : " + e.getLocalizedMessage()); throw e; } }