use of com.pratilipi.data.client.UserData in project pratilipi by Pratilipi.
the class NotificationDataUtil method createNotificationDataList.
public static List<NotificationData> createNotificationDataList(List<Notification> notificationList, Language language, boolean plainText) throws UnexpectedServerException {
// Pre-fetching required User and Pratilipi Entities
List<Long> userIdList = new LinkedList<>();
List<Long> pratilipiIdList = new LinkedList<>();
for (Notification notification : notificationList) {
userIdList.add(notification.getUserId());
if (notification.getType() == NotificationType.PRATILIPI) {
pratilipiIdList.add(notification.getSourceIdLong());
} else if (notification.getType() == NotificationType.PRATILIPI_PUBLISHED_FOLLOWER) {
pratilipiIdList.add(notification.getSourceIdLong());
} else if (notification.getType() == NotificationType.AUTHOR_FOLLOW) {
if (notification.getDataIds().size() <= 3)
userIdList.addAll(notification.getDataIds());
else
userIdList.addAll(notification.getDataIds().subList(notification.getDataIds().size() - 3, notification.getDataIds().size()));
}
}
Map<Long, UserData> users = UserDataUtil.createUserDataList(userIdList, true);
List<PratilipiData> pratilipiDataList = PratilipiDataUtil.createPratilipiDataList(pratilipiIdList, true);
Map<Long, PratilipiData> pratilipis = new HashMap<>(pratilipiDataList.size());
for (PratilipiData pratilipiData : pratilipiDataList) pratilipis.put(pratilipiData.getId(), pratilipiData);
// Creating Notification Data list
List<NotificationData> notificationDataList = new ArrayList<>(notificationList.size());
for (Notification notification : notificationList) {
NotificationData notificationData = new NotificationData(notification.getId());
notificationData.setUserId(notification.getUserId());
Language notificationLanguage = language == null ? users.get(notification.getUserId()).getLanguage() : language;
if (notificationLanguage == null)
notificationLanguage = Language.ENGLISH;
if (notification.getType() == NotificationType.PRATILIPI) {
String createdBy = notification.getCreatedBy();
if (createdBy.startsWith("BATCH_PROCESS::")) {
Long batchProcessId = Long.parseLong(createdBy.substring(15));
BatchProcess batchProcess = DataAccessorFactory.getDataAccessor().getBatchProcess(batchProcessId);
JsonObject execDoc = new Gson().fromJson(batchProcess.getExecDoc(), JsonElement.class).getAsJsonObject();
notificationData.setMessage(execDoc.get("message").getAsString());
}
PratilipiData pratilipiData = pratilipis.get(notification.getSourceIdLong());
notificationData.setSourceUrl(pratilipiData.getPageUrl() + "?" + RequestParameter.NOTIFICATION_ID.getName() + "=" + notification.getId());
notificationData.setSourceImageUrl(pratilipiData.getCoverImageUrl());
} else if (notification.getType() == NotificationType.PRATILIPI_PUBLISHED_FOLLOWER) {
PratilipiData pratilipiData = pratilipis.get(notification.getSourceIdLong());
if (pratilipiData.getState() == PratilipiState.PUBLISHED) {
notificationData.setMessage(createNotificationMessage(pratilipiData, notificationLanguage, plainText));
notificationData.setSourceUrl(pratilipiData.getPageUrl() + "?" + RequestParameter.NOTIFICATION_ID.getName() + "=" + notification.getId());
notificationData.setSourceImageUrl(pratilipiData.getCoverImageUrl());
notificationData.setDisplayImageUrl(pratilipiData.getAuthor().getImageUrl());
}
} else if (notification.getType() == NotificationType.AUTHOR_FOLLOW) {
notificationData.setMessage(createNotificationMessage(notification.getDataIds(), users, notificationLanguage, plainText));
notificationData.setSourceUrl("/followers?" + RequestParameter.NOTIFICATION_ID.getName() + "=" + notification.getId());
if (notification.getDataIds().size() != 0)
notificationData.setDisplayImageUrl(users.get(notification.getDataIds().get(notification.getDataIds().size() - 1)).getProfileImageUrl());
}
notificationData.setSourceId(notification.getSourceId());
notificationData.setState(notification.getState());
notificationData.setNotificationType(notification.getType());
notificationData.setLastUpdatedDate(notification.getLastUpdated());
notificationDataList.add(notificationData);
}
return notificationDataList;
}
use of com.pratilipi.data.client.UserData in project pratilipi by Pratilipi.
the class UserVerificationApi method post.
@Post
public UserV1Api.Response post(PostRequest request) throws InvalidArgumentException, InsufficientAccessException {
UserDataUtil.verifyUserEmail(request.getEmail(), request.getVerificationToken());
UserData userData = UserDataUtil.loginUser(request.getEmail(), request.getVerificationToken());
return new UserV1Api.Response(userData, UserVerificationApi.class);
}
use of com.pratilipi.data.client.UserData in project pratilipi by Pratilipi.
the class UserV2Api method get.
@Get
public Response get(GetRequest request) throws InsufficientAccessException {
if (request.userId == null || request.userId.equals(UserDataUtil.getCurrentUser().getId()))
return new Response(UserDataUtil.getCurrentUser(), UserV2Api.class);
if (!UserAccessUtil.hasUserAccess(UserDataUtil.getCurrentUser().getId(), UxModeFilter.getWebsite().getFilterLanguage(), AccessType.AUTHOR_ADD))
throw new InsufficientAccessException();
UserData userData = UserDataUtil.createUserData(DataAccessorFactory.getDataAccessor().getUser(request.userId), null);
userData.setAuthor(new AuthorData());
return new Response(userData, UserV2Api.class);
}
use of com.pratilipi.data.client.UserData in project pratilipi by Pratilipi.
the class UserDataUtil method createUserDataList.
public static Map<Long, UserData> createUserDataList(List<Long> userIdList, boolean includeAuthorData) {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
List<User> userList = dataAccessor.getUserList(userIdList);
Map<Long, UserData> userDataList = new HashMap<>(userIdList.size());
if (includeAuthorData) {
Map<Long, Author> authors = dataAccessor.getAuthorsByUserIds(userIdList);
for (User user : userList) userDataList.put(user.getId(), createUserData(user, authors.get(user.getId())));
} else {
for (User user : userList) userDataList.put(user.getId(), createUserData(user, null));
}
return userDataList;
}
use of com.pratilipi.data.client.UserData in project pratilipi by Pratilipi.
the class CommentDataUtil method createCommentDataList.
public static List<CommentData> createCommentDataList(List<CommentDoc> commentDocList) {
List<Long> userIdList = new ArrayList<>(commentDocList.size());
for (CommentDoc commentDoc : commentDocList) if (!userIdList.contains(commentDoc.getUserId()))
userIdList.add(commentDoc.getUserId());
Map<Long, UserData> userDataMap = UserDataUtil.createUserDataList(userIdList, true);
List<CommentData> commentDataList = new ArrayList<>(commentDocList.size());
for (CommentDoc commentDoc : commentDocList) {
CommentData commentData = createCommentData(commentDoc);
commentData.setUser(userDataMap.get(commentDoc.getUserId()));
commentDataList.add(commentData);
}
return commentDataList;
}
Aggregations