Search in sources :

Example 11 with DataAccessor

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);
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) Page(com.pratilipi.data.type.Page)

Example 12 with DataAccessor

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);
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) Page(com.pratilipi.data.type.Page) Date(java.util.Date)

Example 13 with DataAccessor

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;
}
Also used : Navigation(com.pratilipi.data.type.Navigation) DataAccessor(com.pratilipi.data.DataAccessor) ArrayList(java.util.ArrayList) NavigationData(com.pratilipi.data.client.NavigationData)

Example 14 with DataAccessor

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());
}
Also used : DataListCursorTuple(com.pratilipi.data.DataListCursorTuple) DataAccessor(com.pratilipi.data.DataAccessor) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException) Notification(com.pratilipi.data.type.Notification)

Example 15 with DataAccessor

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);
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException) Notification(com.pratilipi.data.type.Notification)

Aggregations

DataAccessor (com.pratilipi.data.DataAccessor)162 Date (java.util.Date)53 InsufficientAccessException (com.pratilipi.common.exception.InsufficientAccessException)37 Pratilipi (com.pratilipi.data.type.Pratilipi)34 Author (com.pratilipi.data.type.Author)33 AuditLog (com.pratilipi.data.type.AuditLog)32 UserPratilipi (com.pratilipi.data.type.UserPratilipi)32 ArrayList (java.util.ArrayList)30 Page (com.pratilipi.data.type.Page)28 HashMap (java.util.HashMap)25 GenericResponse (com.pratilipi.api.shared.GenericResponse)24 DocAccessor (com.pratilipi.data.DocAccessor)22 User (com.pratilipi.data.type.User)22 Get (com.pratilipi.api.annotation.Get)20 InvalidArgumentException (com.pratilipi.common.exception.InvalidArgumentException)19 PratilipiData (com.pratilipi.data.client.PratilipiData)15 UserData (com.pratilipi.data.client.UserData)14 BlobAccessor (com.pratilipi.data.BlobAccessor)13 Email (com.pratilipi.data.type.Email)13 JsonObject (com.google.gson.JsonObject)12