use of com.pratilipi.common.util.PratilipiFilter in project pratilipi by Pratilipi.
the class AuthorDataUtil method updateAuthorStats.
public static boolean updateAuthorStats(Long authorId) {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
PratilipiFilter pratilipiFilter = new PratilipiFilter();
pratilipiFilter.setAuthorId(authorId);
// This call is not consistent due to some issue with Google AppEngine
// Relying on Memcahe until the issue is fixed
// List<Pratilipi> pratilipiList = dataAccessor.getPratilipiList( pratilipiFilter, null, null ).getDataList();
List<Long> pratilipiIdList = dataAccessor.getPratilipiIdList(pratilipiFilter, null, null, null).getDataList();
List<Pratilipi> pratilipiList = dataAccessor.getPratilipiList(pratilipiIdList);
int contentDrafted = 0;
int contentPublished = 0;
long totalReadCount = 0;
long totalFbLikeShareCount = 0;
for (Pratilipi pratilipi : pratilipiList) {
if (pratilipi.getState() == PratilipiState.DRAFTED) {
contentDrafted++;
} else if (pratilipi.getState() == PratilipiState.PUBLISHED) {
contentPublished++;
totalReadCount = totalReadCount + pratilipi.getReadCountOffset() + pratilipi.getReadCount();
totalFbLikeShareCount = totalFbLikeShareCount + pratilipi.getFbLikeShareCount();
}
}
Author author = dataAccessor.getAuthor(authorId);
if ((int) author.getContentPublished() == contentPublished && (long) author.getTotalReadCount() == totalReadCount && (long) author.getTotalFbLikeShareCount() == totalFbLikeShareCount)
return false;
author.setContentDrafted(contentDrafted);
author.setContentPublished(contentPublished);
author.setTotalReadCount(totalReadCount);
author.setTotalFbLikeShareCount(totalFbLikeShareCount);
author = dataAccessor.createOrUpdateAuthor(author);
return true;
}
use of com.pratilipi.common.util.PratilipiFilter in project pratilipi by Pratilipi.
the class PratilipiListV1Api method get.
@Get
public Response get(GetRequest request) throws InsufficientAccessException, UnexpectedServerException {
PratilipiFilter pratilipiFilter = new PratilipiFilter();
pratilipiFilter.setAuthorId(request.authorId);
pratilipiFilter.setLanguage(request.language);
pratilipiFilter.setType(request.type);
pratilipiFilter.setListName(request.listName);
pratilipiFilter.setState(request.state);
pratilipiFilter.setOrderByLastUpdate(request.orderByLastUpdated);
DataListCursorTuple<PratilipiData> pratilipiListCursorTuple = PratilipiDataUtil.getPratilipiDataList(request.searchQuery, request.eventId, pratilipiFilter, request.cursor, request.offset, request.resultCount == null ? 20 : request.resultCount);
if (UxModeFilter.isAndroidApp()) {
DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
for (PratilipiData pratilipiData : pratilipiListCursorTuple.getDataList()) {
PratilipiContentDoc pcDoc = docAccessor.getPratilipiContentDoc(pratilipiData.getId());
if (pcDoc == null)
continue;
pratilipiData.setIndex(pcDoc.getIndex());
}
}
Response response = new Response(pratilipiListCursorTuple.getDataList(), pratilipiListCursorTuple.getCursor(), pratilipiListCursorTuple.getNumberFound());
if (UxModeFilter.isAndroidApp() && request.eventId != null && request.cursor == null) {
Event event = DataAccessorFactory.getDataAccessor().getEvent(request.eventId);
response.setBannerUrl(EventDataUtil.createEventBannerUrl(event));
response.setDescription(event.getDescription());
}
return response;
}
use of com.pratilipi.common.util.PratilipiFilter in project pratilipi by Pratilipi.
the class PratilipiListV2Api method get.
@Get
public Response get(GetRequest request) throws InsufficientAccessException, UnexpectedServerException {
PratilipiFilter pratilipiFilter = new PratilipiFilter();
pratilipiFilter.setAuthorId(request.authorId);
pratilipiFilter.setLanguage(request.language);
pratilipiFilter.setType(request.type);
pratilipiFilter.setListName(request.listName);
pratilipiFilter.setState(request.state);
pratilipiFilter.setOrderByLastUpdate(request.orderByLastUpdated);
DataListCursorTuple<PratilipiData> pratilipiListCursorTuple = PratilipiDataUtil.getPratilipiDataList(request.searchQuery, request.eventId, pratilipiFilter, request.cursor, request.offset, request.resultCount == null ? 20 : request.resultCount);
// Preparing & returning response object.
Response response = new Response(pratilipiListCursorTuple.getDataList(), pratilipiListCursorTuple.getCursor(), pratilipiListCursorTuple.getNumberFound());
if (UxModeFilter.isAndroidApp() && request.eventId != null && request.cursor == null) {
Event event = DataAccessorFactory.getDataAccessor().getEvent(request.eventId);
response.setBannerUrl(EventDataUtil.createEventBannerUrl(event));
response.setDescription(event.getDescription());
}
return response;
}
use of com.pratilipi.common.util.PratilipiFilter in project pratilipi by Pratilipi.
the class PratilipiProcessApi method getPratilipiProcess.
@Get
public GenericResponse getPratilipiProcess(GenericRequest request) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
// START: Creating ValidateData Tasks
// Fetching AppProperty
String appPropertyId = "Api.PratilipiProcess.ValidateData";
AppProperty appProperty = dataAccessor.getAppProperty(appPropertyId);
if (appProperty == null) {
appProperty = dataAccessor.newAppProperty(appPropertyId);
appProperty.setValue(new Date(0));
}
// Fetching list of Pratilipi ids.
PratilipiFilter pratilipiFilter = new PratilipiFilter();
pratilipiFilter.setMinLastUpdate((Date) appProperty.getValue(), false);
List<Long> pratilipiIdList = dataAccessor.getPratilipiIdList(pratilipiFilter, null, 0, 10000).getDataList();
// Creating one task per Pratilipi id.
List<Task> taskList = new ArrayList<>(pratilipiIdList.size());
for (Long pratilipiId : pratilipiIdList) {
Task task = TaskQueueFactory.newTask().setUrl("/pratilipi/process").addParam("pratilipiId", pratilipiId.toString()).addParam("validateData", "true");
taskList.add(task);
}
TaskQueueFactory.getPratilipiOfflineTaskQueue().addAll(taskList);
logger.log(Level.INFO, "Added " + taskList.size() + " ValidateData tasks.");
// Updating AppProperty.
if (pratilipiIdList.size() > 0) {
Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiIdList.get(pratilipiIdList.size() - 1));
Date lastUpdatedDate = pratilipi.getLastUpdated();
logger.log(Level.INFO, "Processing all contents updated from " + (Date) appProperty.getValue() + " to " + lastUpdatedDate + ".");
logger.log(Level.INFO, "Last Updated PratilipiID : " + pratilipi.getId());
appProperty.setValue(lastUpdatedDate);
appProperty = dataAccessor.createOrUpdateAppProperty(appProperty);
}
return new GenericResponse();
}
use of com.pratilipi.common.util.PratilipiFilter in project pratilipi by Pratilipi.
the class PratilipiSite method createDataModelForListPage.
private Map<String, Object> createDataModelForListPage(PratilipiType type, String listName, boolean basicMode, Language displayLanugage, Language filterLanguage, HttpServletRequest request) throws InsufficientAccessException, UnexpectedServerException {
String listTitle = null;
String listTitleEn = null;
if (listName == null) {
listTitle = I18n.getString(type.getPluralStringId(), displayLanugage);
listTitleEn = displayLanugage == Language.ENGLISH ? null : I18n.getString(type.getPluralStringId(), Language.ENGLISH);
} else {
String title = getListTitle(listName, filterLanguage);
if (title == null)
return null;
if (title.indexOf('|') == -1) {
listTitle = title.trim();
listTitleEn = null;
} else {
listTitle = title.substring(0, title.indexOf('|')).trim();
listTitleEn = title.substring(title.indexOf('|') + 1).trim();
}
}
Integer offset = null;
Integer pageCurr = 1;
Integer pageSize = 20;
if (basicMode) {
String pageNoStr = request.getParameter(RequestParameter.LIST_PAGE_NUMBER.getName());
if (pageNoStr != null && !pageNoStr.trim().isEmpty()) {
pageCurr = Integer.parseInt(pageNoStr);
offset = (pageCurr - 1) * pageSize;
}
}
PratilipiListV2Api.GetRequest pratilipiListRequest = new PratilipiListV2Api.GetRequest();
pratilipiListRequest.setListName(listName);
pratilipiListRequest.setLanguage(filterLanguage);
pratilipiListRequest.setType(type);
pratilipiListRequest.setState(PratilipiState.PUBLISHED);
pratilipiListRequest.setOffset(offset);
PratilipiListV2Api.Response pratilipiListResponse = ApiRegistry.getApi(PratilipiListV2Api.class).get(pratilipiListRequest);
PratilipiFilter pratilipiFilter = new PratilipiFilter();
pratilipiFilter.setLanguage(filterLanguage);
pratilipiFilter.setType(type);
pratilipiFilter.setListName(listName);
pratilipiFilter.setState(PratilipiState.PUBLISHED);
Map<String, Object> dataModel = new HashMap<String, Object>();
if (listName != null)
dataModel.put("title", SEOTitleUtil.getListPageTitle(listName, filterLanguage));
else
dataModel.put("title", I18n.getString("pratilipi", filterLanguage));
dataModel.put("pratilipiListTitle", listTitle);
if (basicMode) {
dataModel.put("pratilipiList", pratilipiListResponse.getPratilipiList());
dataModel.put("pratilipiListPageCurr", pageCurr);
if (pratilipiListResponse.getNumberFound() != null)
dataModel.put("pratilipiListPageMax", (int) Math.ceil(((double) pratilipiListResponse.getNumberFound()) / pageSize));
} else {
Gson gson = new Gson();
dataModel.put("pratilipiListJson", gson.toJson(pratilipiListResponse.getPratilipiList()));
dataModel.put("pratilipiListFilterJson", gson.toJson(pratilipiFilter));
dataModel.put("pratilipiListCursor", pratilipiListResponse.getCursor());
}
return dataModel;
}
Aggregations