use of com.pratilipi.data.client.PratilipiData 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.PratilipiData in project pratilipi by Pratilipi.
the class InitV1Api method get.
@Get
public Response get(GetRequest request) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
List<Response.Section> sectionList = new LinkedList<>();
List<Long> pratilipiIdMasterList = new LinkedList<>();
for (String listName : dataAccessor.getHomeSectionList(request.language)) {
String title = dataAccessor.getPratilipiListTitle(listName, request.language);
if (title == null)
continue;
if (title.indexOf('|') != -1)
title = title.substring(0, title.indexOf('|')).trim();
PratilipiFilter pratilipiFilter = new PratilipiFilter();
pratilipiFilter.setLanguage(request.language);
pratilipiFilter.setListName(listName);
pratilipiFilter.setState(PratilipiState.PUBLISHED);
List<Long> pratilipiIdList = dataAccessor.getPratilipiIdList(pratilipiFilter, null, null, 6).getDataList();
if (pratilipiIdList.size() < 6)
continue;
sectionList.add(new Response.Section(title, "/" + listName));
pratilipiIdMasterList.addAll(pratilipiIdList);
}
List<PratilipiData> pratilipiDataMasterList = PratilipiDataUtil.createPratilipiDataList(pratilipiIdMasterList, true);
if (UxModeFilter.isAndroidApp()) {
DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
for (PratilipiData pratilipiData : pratilipiDataMasterList) {
PratilipiContentDoc pcDoc = docAccessor.getPratilipiContentDoc(pratilipiData.getId());
if (pcDoc == null)
continue;
pratilipiData.setIndex(pcDoc.getIndex());
}
}
for (int i = 0; i < sectionList.size(); i++) sectionList.get(i).setPratilipiList(pratilipiDataMasterList.subList(i * 6, i * 6 + 6));
return new Response(sectionList);
}
use of com.pratilipi.data.client.PratilipiData in project pratilipi by Pratilipi.
the class InitV2Api method get.
@Get
public Response get(GetRequest request) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
List<Response.Section> sectionList = new LinkedList<>();
List<Long> pratilipiIdMasterList = new LinkedList<>();
for (String listName : dataAccessor.getHomeSectionList(request.language)) {
String title = dataAccessor.getPratilipiListTitle(listName, request.language);
if (title == null)
continue;
if (title.indexOf('|') != -1)
title = title.substring(0, title.indexOf('|')).trim();
PratilipiFilter pratilipiFilter = new PratilipiFilter();
pratilipiFilter.setLanguage(request.language);
pratilipiFilter.setListName(listName);
pratilipiFilter.setState(PratilipiState.PUBLISHED);
List<Long> pratilipiIdList = dataAccessor.getPratilipiIdList(pratilipiFilter, null, null, 6).getDataList();
if (pratilipiIdList.size() < 6)
continue;
sectionList.add(new Response.Section(title, "/" + listName));
pratilipiIdMasterList.addAll(pratilipiIdList);
}
List<PratilipiData> pratilipiDataMasterList = PratilipiDataUtil.createPratilipiDataList(pratilipiIdMasterList, true);
for (int i = 0; i < sectionList.size(); i++) sectionList.get(i).setPratilipiList(pratilipiDataMasterList.subList(i * 6, i * 6 + 6));
return new Response(sectionList);
}
use of com.pratilipi.data.client.PratilipiData in project pratilipi by Pratilipi.
the class SearchAccessorMockImpl method searchPratilipi.
@Override
public DataListCursorTuple<Long> searchPratilipi(String query, PratilipiFilter pratilipiFilter, String cursorStr, Integer offset, Integer resultCount) {
List<Long> pratilipiIdList = new LinkedList<>();
for (Object object : GLOBAL_INDEX) {
if (object.getClass() != PratilipiData.class)
continue;
PratilipiData pratilipiData = (PratilipiData) object;
if (pratilipiFilter.getLanguage() != null && !pratilipiFilter.getLanguage().equals(pratilipiData.getLanguage()))
continue;
if (pratilipiFilter.getAuthorId() != null && !pratilipiFilter.getAuthorId().equals(pratilipiData.getAuthorId()))
continue;
if (pratilipiFilter.getType() != null && !pratilipiFilter.getType().equals(pratilipiData.getType()))
continue;
pratilipiIdList.add(((PratilipiData) object).getId());
}
return new DataListCursorTuple<Long>(pratilipiIdList, null);
}
use of com.pratilipi.data.client.PratilipiData in project pratilipi by Pratilipi.
the class PratilipiV1Api method post.
@Post
public Response post(PostRequest request) throws InvalidArgumentException, InsufficientAccessException, UnexpectedServerException {
Gson gson = new Gson();
// Creating PratilipiData object.
PratilipiData pratilipiData = gson.fromJson(gson.toJson(request), PratilipiData.class);
// If not set already, setting AuthorId for new content.
if (pratilipiData.getId() == null && !pratilipiData.hasAuthorId()) {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Author author = dataAccessor.getAuthorByUserId(AccessTokenFilter.getAccessToken().getUserId());
pratilipiData.setAuthorId(author.getId());
}
// Saving PratilipiData object.
pratilipiData = PratilipiDataUtil.savePratilipiData(pratilipiData);
// Creating PratilipiProcess task to process the data.
Task task = TaskQueueFactory.newTask().setUrl("/pratilipi/process").addParam("pratilipiId", pratilipiData.getId().toString()).addParam("processData", "true");
TaskQueueFactory.getPratilipiTaskQueue().add(task);
// If PratilipiState has changed, creating AuthorProcess task to update Author stats.
if (request.hasState && pratilipiData.getAuthorId() != null) {
Task authorTask = TaskQueueFactory.newTask().setUrl("/author/process").addParam("authorId", pratilipiData.getAuthorId().toString()).addParam("updateStats", "true");
TaskQueueFactory.getAuthorTaskQueue().add(authorTask);
}
return new Response(pratilipiData);
}
Aggregations