Search in sources :

Example 1 with PratilipiFilter

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;
}
Also used : PratilipiFilter(com.pratilipi.common.util.PratilipiFilter) DataAccessor(com.pratilipi.data.DataAccessor) Author(com.pratilipi.data.type.Author) Pratilipi(com.pratilipi.data.type.Pratilipi)

Example 2 with PratilipiFilter

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;
}
Also used : GenericResponse(com.pratilipi.api.shared.GenericResponse) PratilipiFilter(com.pratilipi.common.util.PratilipiFilter) PratilipiData(com.pratilipi.data.client.PratilipiData) DocAccessor(com.pratilipi.data.DocAccessor) Event(com.pratilipi.data.type.Event) PratilipiContentDoc(com.pratilipi.data.type.PratilipiContentDoc) Get(com.pratilipi.api.annotation.Get)

Example 3 with PratilipiFilter

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;
}
Also used : PratilipiFilter(com.pratilipi.common.util.PratilipiFilter) PratilipiData(com.pratilipi.data.client.PratilipiData) Event(com.pratilipi.data.type.Event) Get(com.pratilipi.api.annotation.Get)

Example 4 with PratilipiFilter

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();
}
Also used : PratilipiFilter(com.pratilipi.common.util.PratilipiFilter) Task(com.pratilipi.taskqueue.Task) GenericResponse(com.pratilipi.api.shared.GenericResponse) DataAccessor(com.pratilipi.data.DataAccessor) ArrayList(java.util.ArrayList) Pratilipi(com.pratilipi.data.type.Pratilipi) AppProperty(com.pratilipi.data.type.AppProperty) Date(java.util.Date) Get(com.pratilipi.api.annotation.Get)

Example 5 with PratilipiFilter

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;
}
Also used : PratilipiFilter(com.pratilipi.common.util.PratilipiFilter) PratilipiListV2Api(com.pratilipi.api.impl.pratilipi.PratilipiListV2Api) HashMap(java.util.HashMap) Gson(com.google.gson.Gson) JsonObject(com.google.gson.JsonObject)

Aggregations

PratilipiFilter (com.pratilipi.common.util.PratilipiFilter)11 DataAccessor (com.pratilipi.data.DataAccessor)7 Get (com.pratilipi.api.annotation.Get)6 GenericResponse (com.pratilipi.api.shared.GenericResponse)4 PratilipiData (com.pratilipi.data.client.PratilipiData)4 Pratilipi (com.pratilipi.data.type.Pratilipi)4 HashMap (java.util.HashMap)4 Gson (com.google.gson.Gson)2 JsonObject (com.google.gson.JsonObject)2 PratilipiListV2Api (com.pratilipi.api.impl.pratilipi.PratilipiListV2Api)2 InvalidArgumentException (com.pratilipi.common.exception.InvalidArgumentException)2 DocAccessor (com.pratilipi.data.DocAccessor)2 Author (com.pratilipi.data.type.Author)2 Event (com.pratilipi.data.type.Event)2 PratilipiContentDoc (com.pratilipi.data.type.PratilipiContentDoc)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 LinkedList (java.util.LinkedList)2 Language (com.pratilipi.common.type.Language)1 PratilipiState (com.pratilipi.common.type.PratilipiState)1