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();
}
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);
}
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;
}
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);
}
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;
}
Aggregations