List of usage examples for org.springframework.dao DataAccessException getLocalizedMessage
public String getLocalizedMessage()
From source file:org.esco.portlets.news.services.UserManagerImpl.java
/** * @param uid/*www . ja v a2 s . c o m*/ * @param item * @return <code>boolean</code> true if the user can validate a news. * @see org.esco.portlets.news.services.UserManager * #canValidate(java.lang.String, org.uhp.portlets.news.domain.Item) */ public boolean canValidate(final String uid, final Item item) { try { if (this.isAdmin(uid, item.getCategoryId())) { return true; } List<String> roles = this.userDao.getUserRolesInTopicsByItem(uid, item.getItemId()); if (roles.isEmpty()) { return false; } else if (roles.contains(RolePerm.ROLE_MANAGER.getName())) { return true; } else if (roles.contains(RolePerm.ROLE_EDITOR.getName()) && item.getPostedBy().equals(uid)) { return true; } } catch (DataAccessException e) { LOG.warn("canValidate::" + e.getLocalizedMessage()); } return false; }
From source file:org.esco.portlets.news.services.UserManagerImpl.java
/** * @param uid//w w w . ja va 2 s.c o m * @param item * @return <code>boolean</code> true if the user can edit a news. * @see org.esco.portlets.news.services.UserManager * #canEditItem(java.lang.String, org.uhp.portlets.news.domain.Item) */ public boolean canEditItem(final String uid, final Item item) { try { if (this.isAdmin(uid, item.getCategoryId())) { return true; } List<String> roles = this.userDao.getUserRolesInTopicsByItem(uid, item.getItemId()); if (roles.isEmpty()) { return false; } else if (roles.contains(RolePerm.ROLE_MANAGER.getName())) { return true; } else if ((roles.contains(RolePerm.ROLE_CONTRIBUTOR.getName()) || roles.contains(RolePerm.ROLE_EDITOR.getName())) && (item.getPostedBy().equals(uid))) { return true; } } catch (DataAccessException e) { LOG.warn("canEditItem::" + e.getLocalizedMessage()); } return false; }
From source file:org.uhp.portlets.news.service.BasicFeedService.java
/** * @param id/*from w w w .j a va 2 s .c o m*/ * @param feedUrl * @param fType * @return String * @see org.uhp.portlets.news.service.FeedService# * generateOpml(java.lang.Long, java.lang.String, java.lang.String) */ public String generateOpml(final Long id, final String feedUrl, final String fType) { try { final Category c = this.categoryDao.getCategoryById(id); final List<Topic> topics = topicDao.getTopicListByCategory(id); final StringBuilder sbuf = new StringBuilder(); sbuf.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<opml version=\"1.0\">\n"); sbuf.append("\n<head><title>" + StringEscapeUtils.escapeXml(c.getName()) + "</title></head>\n\n<body>"); sbuf.append("<outline text=\"" + StringEscapeUtils.escapeXml(c.getName()) + "\">\n"); for (Topic t : topics) { if (NewsConstants.S_Y.equals(t.getRssAllowed())) { final String path = (NewsConstants.S_Y.equals(t.getPublicView())) ? NewsConstants.PUBLIC_PATH : NewsConstants.PRIVATE_PATH; sbuf.append("<outline type=\"rss\" text=\"" + StringEscapeUtils.escapeXml(t.getName()) + "\" title=\"" + StringEscapeUtils.escapeXml(t.getName()) + "\" description=\"" + StringEscapeUtils.escapeXml(t.getDesc()) + "\" xmlUrl=\"" + feedUrl + path + "rss?t=" + Constants.EXPORT_TOPIC_FEED + "&topicID=" + t.getTopicId() + "&feedType=" + fType + "\" /> \n"); } } sbuf.append("\n</outline>\n</body>\n</opml>"); return sbuf.toString(); } catch (DataAccessException e) { LOG.error("Error while generating opml feed : " + e.getLocalizedMessage()); } return null; }
From source file:org.uhp.portlets.news.service.BasicFeedService.java
/** * @param id/*from w ww.jav a 2 s. c o m*/ * @param fType * @param feedUrl * @return String * @throws DataAccessException */ private StringBuilder getSimpleCategoryFeed(final Long id, final String fType, final String feedUrl) throws DataAccessException { StringBuilder categoryBuffer = new StringBuilder(); try { final Category c = this.categoryDao.getCategoryById(id); final List<Topic> topics = this.topicDao.getTopicListByCategory(c.getCategoryId()); Integer ttl = getTTL(c.getRefreshPeriod(), c.getRefreshFrequency()); categoryBuffer.append("<category edit=\"all\" name=\"" + StringEscapeUtils.escapeXml(c.getName()) + "\" ttl=\"" + ttl.toString() + "\">\n"); categoryBuffer.append("<description>" + StringEscapeUtils.escapeXml(c.getDesc()) + "</description>\n"); final boolean hasEntitySubs = this.subDao.hasSubscribers(c.getEntityId(), NewsConstants.CTX_E); final boolean hasCatSubs = this.subDao.hasSubscribers(c.getCategoryId(), NewsConstants.CTX_C); String path; // Buffer of the list of categoryProfile from topics StringBuilder topicsBuffer = new StringBuilder(); // Buffer of the list of the visibility of categoryProfile from topics StringBuilder topicsVisibilityBuffer = new StringBuilder(); final String visibilityEntity = this.getCtxVisibility(c.getEntityId(), NewsConstants.CTX_E); for (final Topic t : topics) { if (NewsConstants.S_Y.equals(t.getRssAllowed())) { final boolean hasTopSubs = this.subDao.hasSubscribers(t.getTopicId(), NewsConstants.CTX_T); ttl = getTTL(t.getRefreshPeriod(), t.getRefreshFrequency()); path = (NewsConstants.S_Y.equals(t.getPublicView())) ? NewsConstants.PUBLIC_PATH : NewsConstants.PRIVATE_PATH; final String acc = (NewsConstants.S_Y.equals(t.getPublicView())) ? PUBLIC_ACCESS : PRIVATE_ACCESS; topicsBuffer.append("<sourceProfile id=\"" + t.getTopicId() + "\" access=\"" + acc + "\" name=\"" + StringEscapeUtils.escapeXml(t.getName()) + "\" specificUserContent=\"no\" ttl=\"" + ttl.toString() + "\" url=\"" + feedUrl + path + "rss?t=" + Constants.EXPORT_TOPIC_FEED + "&topicID=" + t.getTopicId() + "&feedType=" + fType + "\"> \n"); if (!hasCatSubs && !hasTopSubs) { topicsBuffer.append(visibilityEntity); } else { String vis = this.getCtxVisibility(t.getTopicId(), NewsConstants.CTX_T); topicsBuffer.append(vis); topicsVisibilityBuffer.append(vis); } topicsBuffer.append("\n</sourceProfile>"); } } if (hasCatSubs) { categoryBuffer.append(getCtxVisibility(c.getCategoryId(), NewsConstants.CTX_C)); } else if (hasEntitySubs) { categoryBuffer.append(this.getCtxVisibility(c.getEntityId(), NewsConstants.CTX_E)); } else { categoryBuffer.append(topicsVisibilityBuffer); } categoryBuffer.append("<sourceProfiles>\n"); categoryBuffer.append(topicsBuffer); categoryBuffer.append("</sourceProfiles>\n</category>\n"); return categoryBuffer; } catch (DataAccessException e) { LOG.error("Error while generating category feed : " + e.getLocalizedMessage()); throw e; } }
From source file:org.uhp.portlets.news.service.BasicFeedService.java
/** * @param id of the Category/*from ww w .j a v a2 s . co m*/ * @param feedType * @param nbLastDays * @param urlEntry * @return SyndFeed * @see org.uhp.portlets.news.service.FeedService# * getMostRecentItemsFeedOfCategory(Long, String, Integer, String) */ public SyndFeed getMostRecentItemsFeedOfCategory(final Long id, final String feedType, final Integer nbLastDays, final String urlEntry) { try { final Category c = this.categoryDao.getCategoryById(id); final List<Item> items = this.itemDao.getMostRecentItemsByCategory(c.getCategoryId(), nbLastDays); SyndFeed feed = new SyndFeedImpl(); feed.setFeedType(feedType); try { feed.setTitle(c.getName()); final String path = (NewsConstants.S_Y.equals(c.getPublicView())) ? NewsConstants.PUBLIC_PATH : NewsConstants.PRIVATE_PATH; feed.setLink(urlEntry + path + "rss?t=" + Constants.EXPORT_MOST_RECENT + "&cID=" + c.getCategoryId() + "&feedType=" + feedType + "&dayCount=" + nbLastDays.intValue()); feed.setDescription(c.getDesc()); feed.setLanguage(c.getLangue()); feed.setEntries(addEntry(items, urlEntry, path)); } catch (final Exception ex) { LOG.error("Error : " + ex.getLocalizedMessage()); } return feed; } catch (DataAccessException e) { LOG.error("Error while generating most recent items feed : " + e.getLocalizedMessage()); } return null; }
From source file:org.uhp.portlets.news.service.BasicFeedService.java
/** * @param id/*from w w w. j a va 2s . co m*/ * @param feedType * @param urlEntry * @return SyndFeed * @see org.uhp.portlets.news.service.FeedService * #getTopicFeed(java.lang.Long, java.lang.String, java.lang.String) */ public SyndFeed getTopicFeed(final Long id, final String feedType, final String urlEntry) { try { final Topic t = this.topicDao.getTopicById(id); final Category c = this.categoryDao.getCategoryById(t.getCategoryId()); final List<Item> items = this.itemDao.getItemListByTopic(t.getTopicId()); String path; final SyndFeed feed = new SyndFeedImpl(); feed.setFeedType(feedType); feed.setTitle(t.getName()); if (NewsConstants.S_N.equals(c.getPublicView())) { path = NewsConstants.PRIVATE_PATH; } else { path = (NewsConstants.S_Y.equals(t.getPublicView())) ? NewsConstants.PUBLIC_PATH : NewsConstants.PRIVATE_PATH; } feed.setLink(urlEntry + path + "rss?t=" + Constants.EXPORT_TOPIC_FEED + "&topicID=" + t.getTopicId() + "&feedType=" + feedType); feed.setDescription(t.getDesc()); feed.setLanguage(t.getLangue()); feed.setEntries(addEntry(items, urlEntry, path)); return feed; } catch (DataAccessException e) { LOG.error("Error while generating topic RSS feed : " + e.getLocalizedMessage()); } return null; }
From source file:org.uhp.portlets.news.service.BasicFeedService.java
/** * @param c/* w w w.j a va 2 s .com*/ * @param t * @param status * @return ItemsView */ public ItemsView getItems(final Category c, final Topic t, final int status) { ItemsView itemsS = new ItemsView(); try { final Long id = t.getTopicId(); switch (status) { case 0: itemsS.setItems(itemDao.getPendingItemListByTopic(id)); itemsS.setItemStatus(ItemStatus.PENDING); break; case 1: itemsS.setItems(itemDao.getValidatedItemListByTopic(id)); itemsS.setItemStatus(ItemStatus.PUBLISHED); break; case 2: itemsS.setItems(itemDao.getExpiredItemListByTopic(id)); itemsS.setItemStatus(ItemStatus.ARCHIVED); break; case 3: itemsS.setItems(itemDao.getScheduledItemListByTopic(id)); itemsS.setItemStatus(ItemStatus.SCHEDULED); break; default: itemsS.setItems(itemDao.getAllItemListByTopic(id)); } } catch (DataAccessException e) { LOG.warn("DAE : " + e.getLocalizedMessage()); } itemsS.setTopic(t); itemsS.setCatName(c.getName()); return itemsS; }
From source file:org.uhp.portlets.news.service.BasicFeedService.java
/** * Returns the feed for all entities of a type. * @param type/*from w ww .j av a 2 s . com*/ * @param fType * @param feedUrl * @return String * @see org.uhp.portlets.news.service.FeedService# * getFeedsOfType(java.lang.String, java.lang.String, java.lang.String) */ public String getFeedsOfType(final String type, final String fType, final String feedUrl) { StringBuilder sbuf = new StringBuilder(); try { sbuf.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"); final Type atype = this.typeDao.getTypeByName(type); if (atype == null) { sbuf.append("<error>The 'type' value given in parameters is unknown from this context.</error>"); return sbuf.toString(); } final List<Entity> entities = this.entityDao.getEntitiesByType(atype.getTypeId()); sbuf.append("<categoryProfilesUrl>\n"); for (Entity entity : entities) { sbuf.append(this.getCategoryProfileOfEntityOfType(entity, atype, feedUrl, fType)); } sbuf.append("</categoryProfilesUrl>"); if (LOG.isDebugEnabled()) { LOG.debug("Returned feed of type : " + sbuf); } return sbuf.toString(); } catch (DataAccessException e) { LOG.error("Error while generating category profile : " + e.getLocalizedMessage()); sbuf.append("<error>An error in database access occured.</error>"); return sbuf.toString(); } }
From source file:org.uhp.portlets.news.service.BasicFeedService.java
/** * @param id/*from w w w . j a v a2 s . c o m*/ * @param fType * @param feedUrl * @param type * @return String * @see org.uhp.portlets.news.service.FeedService * #getEntityTypeFeed(java.lang.Long, java.lang.String, java.lang.String, java.lang.String) */ public String getEntityTypeFeed(final Long id, final String fType, final String feedUrl, final String type) { StringBuilder sbuf = new StringBuilder(); try { sbuf.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"); final Type atype = this.typeDao.getTypeByName(type); if (atype == null) { sbuf.append("<error>The 'type' value given in parameters is unknown from this context.</error>"); return sbuf.toString(); } sbuf.append("<categoryProfilesUrl>\n"); sbuf.append( this.getCategoryProfileOfEntityOfType(this.entityDao.getEntityById(id), atype, feedUrl, fType)); sbuf.append("</categoryProfilesUrl>"); if (LOG.isDebugEnabled()) { LOG.debug("Returned feed of type on entity " + id + " : \n" + sbuf); } return sbuf.toString(); } catch (DataAccessException e) { LOG.error("Error while generating category profile : " + e.getLocalizedMessage()); } return null; }
From source file:org.uhp.portlets.news.service.CategoryManagerImpl.java
/** * @param categoryId/*from w ww . j a v a 2s.co m*/ * @return <code>boolean</code> * @see org.uhp.portlets.news.service.CategoryManager#deleteCategory(java.lang.Long) */ @Transactional(readOnly = false) public boolean deleteCategory(final Long categoryId) { try { List<UserRole> lists = this.userDao.getUsersRolesForCtx(categoryId, NewsConstants.CTX_C); if (this.categoryDao.delete(categoryId)) { this.userDao.removeUsersRoleForCtx(categoryId, NewsConstants.CTX_C); for (UserRole ur : lists) { if (!this.userDao.isSuperAdmin(ur.getPrincipal()) && !this.userDao.userRoleExist(ur.getPrincipal())) { this.userDao.deleteUser(ur.getPrincipal(), false); } } this.subDao.deleteAllSubscribersByCtxId(categoryId, NewsConstants.CTX_C); return true; } } catch (DataAccessException e) { LOG.error("Delete Category error : " + e.getLocalizedMessage()); } return false; }