use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.
the class BlogPostDataUtil method createBlogPostData.
public static BlogPostData createBlogPostData(BlogPost blogPost) {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Page blogPostPage = dataAccessor.getPage(PageType.BLOG_POST, blogPost.getId());
return createBlogPostData(blogPost, blogPostPage);
}
use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.
the class BlogPostDataUtil method _updateBlogPostPageUrl.
private static void _updateBlogPostPageUrl(BlogPost blogPost) {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Page blogPage = dataAccessor.getPage(PageType.BLOG, blogPost.getBlogId());
Page blogPostPage = dataAccessor.getPage(PageType.BLOG_POST, blogPost.getId());
if (blogPost.getState() == BlogPostState.DELETED) {
if (blogPostPage != null)
dataAccessor.deletePage(blogPostPage);
return;
}
boolean isNew = blogPostPage == null;
if (isNew) {
blogPostPage = dataAccessor.newPage();
blogPostPage.setType(PageType.BLOG_POST);
blogPostPage.setUri(PageType.BLOG_POST.getUrlPrefix() + blogPost.getId());
blogPostPage.setPrimaryContentId(blogPost.getId());
blogPostPage.setCreationDate(new Date());
}
String uriAlias = UriAliasUtil.generateUriAlias(blogPostPage.getUriAlias(), blogPage.getUriAlias() + "/", blogPost.getTitleEn() == null ? blogPost.getTitle() : blogPost.getTitleEn());
if (isNew && uriAlias == null) {
// Do Not Return
} else if (uriAlias == blogPostPage.getUriAlias() || (uriAlias != null && uriAlias.equals(blogPostPage.getUriAlias())) || (blogPostPage.getUriAlias() != null && blogPostPage.getUriAlias().equals(uriAlias))) {
// Do Nothing.
return;
} else {
logger.log(Level.INFO, "Updating Event Page Url: '" + blogPostPage.getUriAlias() + "' -> '" + uriAlias + "'");
blogPostPage.setUriAlias(uriAlias);
}
blogPostPage = dataAccessor.createOrUpdatePage(blogPostPage);
}
use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.
the class NavigationDataUtil method getNavigationDataList.
public static List<NavigationData> getNavigationDataList(Language language) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
List<Navigation> navigationList = dataAccessor.getNavigationList(language);
List<NavigationData> navigationDataList = new ArrayList<>(navigationList.size());
for (Navigation navigation : navigationList) navigationDataList.add(new NavigationData(navigation.getTitle(), navigation.getLinkList()));
return navigationDataList;
}
use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.
the class NotificationDataUtil method getNotificationList.
public static DataListCursorTuple<NotificationData> getNotificationList(Long userId, Language language, String cursor, Integer resultCount) throws InsufficientAccessException, UnexpectedServerException {
if (!hasAccessToListData(userId))
throw new InsufficientAccessException();
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
// Fetching Notification Entities
DataListIterator<Notification> notifListIterator = dataAccessor.getNotificationListIterator(userId, null, (String) null, cursor, null);
List<Notification> notifList = resultCount == null ? new ArrayList<Notification>() : new ArrayList<Notification>(resultCount);
while (notifListIterator.hasNext()) {
Notification notif = notifListIterator.next();
if (notif.getType().isValid(notif))
notifList.add(notif);
if (resultCount != null && notifList.size() == resultCount)
break;
}
// Return
return new DataListCursorTuple<>(createNotificationDataList(notifList, language, false), notifListIterator.getCursor());
}
use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.
the class NotificationDataUtil method saveNotificationState.
public static void saveNotificationState(Long notificationId, NotificationState state) throws InsufficientAccessException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Notification notification = dataAccessor.getNotification(notificationId);
if (notification.getState() == state)
return;
if (!hasAccessToUpdateData(notification))
throw new InsufficientAccessException();
notification.setState(state);
notification = dataAccessor.createOrUpdateNotification(notification);
}
Aggregations