Search in sources :

Example 26 with DataAccessor

use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.

the class I18nApi method post.

@Post
public static GenericResponse post(PostRequest request) throws InsufficientAccessException, UnexpectedServerException {
    if (!UserAccessUtil.hasUserAccess(AccessTokenFilter.getAccessToken().getUserId(), request.language, AccessType.I18N_UPDATE))
        throw new InsufficientAccessException();
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    List<I18n> i18nList = new ArrayList<>();
    for (Entry<String, String> entry : request.keyValues.entrySet()) {
        I18n i18n = dataAccessor.getI18n(entry.getKey());
        if (i18n == null)
            i18n = dataAccessor.newI18n(entry.getKey());
        // Resetting the group if its already set
        i18n.setGroup(request.group);
        i18n.setI18nString(request.language, entry.getValue());
        i18nList.add(i18n);
    }
    i18nList = dataAccessor.createOrUpdateI18nList(i18nList);
    return new GenericResponse();
}
Also used : GenericResponse(com.pratilipi.api.shared.GenericResponse) DataAccessor(com.pratilipi.data.DataAccessor) ArrayList(java.util.ArrayList) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException) I18n(com.pratilipi.data.type.I18n) Post(com.pratilipi.api.annotation.Post)

Example 27 with DataAccessor

use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.

the class AuditLogProcessApi method _createPratilipiPublishedNotifications.

private void _createPratilipiPublishedNotifications(Pratilipi pratilipi, Set<Long> followersSet) {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    List<Long> followers = new ArrayList<Long>(followersSet);
    List<Notification> existingNotificationList = dataAccessor.getNotificationListIterator(null, NotificationType.PRATILIPI_PUBLISHED_FOLLOWER, pratilipi.getId(), null, null).list();
    for (Notification notification : existingNotificationList) followers.remove(notification.getUserId());
    List<Notification> notificationList = new ArrayList<>(followers.size());
    for (Long followerUserId : followers) notificationList.add(dataAccessor.newNotification(followerUserId, NotificationType.PRATILIPI_PUBLISHED_FOLLOWER, pratilipi.getId()));
    notificationList = dataAccessor.createOrUpdateNotificationList(notificationList);
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) ArrayList(java.util.ArrayList) Notification(com.pratilipi.data.type.Notification)

Example 28 with DataAccessor

use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.

the class AuthorApi method get.

@Get
public Response get(GetRequest request) {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    Author author = dataAccessor.getAuthor(request.authorId);
    UserAuthor userAuthor = dataAccessor.getUserAuthor(AccessTokenFilter.getAccessToken().getUserId(), request.authorId);
    AuthorData authorData = AuthorDataUtil.createAuthorData(author, null, null);
    Response response = new Response(authorData);
    response.setFollowing(userAuthor != null && userAuthor.getFollowState() == UserFollowState.FOLLOWING);
    return response;
}
Also used : GenericResponse(com.pratilipi.api.shared.GenericResponse) DataAccessor(com.pratilipi.data.DataAccessor) AuthorData(com.pratilipi.data.client.AuthorData) UserAuthor(com.pratilipi.data.type.UserAuthor) Author(com.pratilipi.data.type.Author) UserAuthor(com.pratilipi.data.type.UserAuthor) Get(com.pratilipi.api.annotation.Get)

Example 29 with DataAccessor

use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.

the class EventApi method get.

@Get
public Response get(GetRequest request) {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    Event event = dataAccessor.getEvent(request.eventId);
    EventData eventData = EventDataUtil.createEventData(event, true);
    return new Response(eventData);
}
Also used : GenericResponse(com.pratilipi.api.shared.GenericResponse) DataAccessor(com.pratilipi.data.DataAccessor) Event(com.pratilipi.data.type.Event) EventData(com.pratilipi.data.client.EventData) Get(com.pratilipi.api.annotation.Get)

Example 30 with DataAccessor

use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.

the class PratilipiSite method createDataModelForBlogPage.

public Map<String, Object> createDataModelForBlogPage(Long blogId, Language language, boolean basicMode) throws InsufficientAccessException, UnexpectedServerException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    Blog blog = dataAccessor.getBlog(blogId);
    BlogPostListApi.GetRequest request = new BlogPostListApi.GetRequest();
    request.setBlogId(blogId);
    request.setLangugage(language);
    request.setState(BlogPostState.PUBLISHED);
    BlogPostListApi.Response blogPostList = ApiRegistry.getApi(BlogPostListApi.class).get(request);
    BlogPostData blogPostLanguage = new BlogPostData();
    blogPostLanguage.setLanguage(language);
    boolean hasAccessToAdd = BlogPostDataUtil.hasAccessToAddBlogPostData(blogPostLanguage);
    Map<String, Object> dataModel = new HashMap<String, Object>();
    if (// Blog
    blogId.equals(5683739602452480L))
        dataModel.put("title", SEOTitleUtil.getBlogPageTitle(language));
    else if (// Author Interviews
    blogId.equals(5197509039226880L))
        dataModel.put("title", SEOTitleUtil.getAuthorInterviewPageTitle(language));
    else
        dataModel.put("title", blog.getTitle());
    if (basicMode) {
        dataModel.put("blogPostList", blogPostList.getBlogPostList());
    } else {
        Gson gson = new Gson();
        dataModel.put("blogId", blogId);
        dataModel.put("hasAccessToAdd", hasAccessToAdd);
        dataModel.put("blogPostListJson", gson.toJson(blogPostList.getBlogPostList()));
        dataModel.put("blogPostFilterJson", gson.toJson(request));
        dataModel.put("blogPostListCursor", blogPostList.getCursor());
    }
    return dataModel;
}
Also used : HashMap(java.util.HashMap) DataAccessor(com.pratilipi.data.DataAccessor) BlogPostListApi(com.pratilipi.api.impl.blogpost.BlogPostListApi) Gson(com.google.gson.Gson) BlogPostData(com.pratilipi.data.client.BlogPostData) JsonObject(com.google.gson.JsonObject) Blog(com.pratilipi.data.type.Blog)

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