Search in sources :

Example 1 with AuthorByReadCountData

use of com.pratilipi.data.client.AuthorByReadCountData in project pratilipi by Pratilipi.

the class AuthorDataUtil method createAuthorByReadCountDataList.

public static List<AuthorByReadCountData> createAuthorByReadCountDataList(List<AuthorByReadCount> authorByReadCountList) {
    List<AuthorByReadCountData> authorByReadCountDataList = new ArrayList<>(authorByReadCountList.size());
    for (AuthorByReadCount authorByReadCount : authorByReadCountList) {
        logger.log(Level.INFO, "Author Name : " + authorByReadCount.getName());
        AuthorByReadCountData data = createAuthorByReadCountData(authorByReadCount);
        authorByReadCountDataList.add(data);
    }
    return authorByReadCountDataList;
}
Also used : AuthorByReadCountData(com.pratilipi.data.client.AuthorByReadCountData)

Example 2 with AuthorByReadCountData

use of com.pratilipi.data.client.AuthorByReadCountData in project pratilipi by Pratilipi.

the class AuthorDataUtil method createAuthorByReadCountData.

/**
 * Developer : Rahul Ranjan
 * Function : Following functions are used for Author leaders board.
 */
public static AuthorByReadCountData createAuthorByReadCountData(AuthorByReadCount authorByReadCount) {
    AuthorByReadCountData authorByReadCountData = new AuthorByReadCountData();
    authorByReadCountData.setId(authorByReadCount.getId());
    authorByReadCountData.setAuthorId(authorByReadCount.getAuthorId());
    authorByReadCountData.setName(authorByReadCount.getName());
    authorByReadCountData.setUserId(authorByReadCount.getUserId());
    authorByReadCountData.setImageUrl(authorByReadCount.getCoverImageUrl());
    authorByReadCountData.setPageUrl(authorByReadCount.getProfilePageUrl());
    authorByReadCountData.setReadCount(authorByReadCount.getReadCount());
    return authorByReadCountData;
}
Also used : AuthorByReadCountData(com.pratilipi.data.client.AuthorByReadCountData)

Example 3 with AuthorByReadCountData

use of com.pratilipi.data.client.AuthorByReadCountData in project pratilipi by Pratilipi.

the class AuthorDataUtil method getAuthorListByReadCount.

public static DataListCursorTuple<AuthorByReadCountData> getAuthorListByReadCount(Language language, Integer resultCount, String cursor) {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    AppProperty appProperty = dataAccessor.getAppProperty(AppProperty.TOP_AUTHORS_DATE);
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
    String dateString;
    if (appProperty == null) {
        // IF AppProperty is not present return day before yesterday's date.
        // Same is present in AppPropertyUtil.getTopAuthorLoadDate function, line 52
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DATE, -2);
        dateString = dateFormat.format(cal.getTime());
    } else {
        logger.log(Level.INFO, "AppProperty value : " + appProperty.getValue());
        dateString = appProperty.getValue();
    }
    try {
        Date date = dateFormat.parse(dateString);
        logger.log(Level.INFO, "Filter : " + date);
        DataListCursorTuple<AuthorByReadCount> cursorTuple = dataAccessor.getAuthorsByReadCount(date, language, resultCount, cursor);
        List<AuthorByReadCountData> authorsData = createAuthorByReadCountDataList(cursorTuple.getDataList());
        logger.log(Level.INFO, "Number of authors returned : " + authorsData.size());
        return new DataListCursorTuple<>(authorsData, cursorTuple.getCursor(), cursorTuple.getNumberFound());
    } catch (ParseException e) {
        e.printStackTrace();
        logger.log(Level.SEVERE, "Error while parsing date.");
        return null;
    }
}
Also used : DataListCursorTuple(com.pratilipi.data.DataListCursorTuple) DataAccessor(com.pratilipi.data.DataAccessor) AuthorByReadCountData(com.pratilipi.data.client.AuthorByReadCountData) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 4 with AuthorByReadCountData

use of com.pratilipi.data.client.AuthorByReadCountData in project pratilipi by Pratilipi.

the class AuthorListByReadCountApi method get.

@Get
public GetResponse get(GetRequest request) throws UnexpectedServerException {
    DataListCursorTuple<AuthorByReadCountData> dataListCursorTuple = AuthorDataUtil.getAuthorListByReadCount(request.getLanguage(), request.getResultCount(), request.getCursor());
    if (dataListCursorTuple == null) {
        Logger.getLogger(AuthorListByReadCountApi.class.getSimpleName()).log(Level.INFO, "DB returned null cursor tuple");
        throw new UnexpectedServerException();
    }
    Date date = AppPropertyUtil.getTopAuthorLoadDate();
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
    Logger.getLogger(AuthorListByReadCountApi.class.getSimpleName()).log(Level.INFO, "Date : " + dateFormat.format(date));
    return new GetResponse(dataListCursorTuple.getDataList(), dateFormat.format(date), dataListCursorTuple.getCursor());
}
Also used : UnexpectedServerException(com.pratilipi.common.exception.UnexpectedServerException) AuthorByReadCountData(com.pratilipi.data.client.AuthorByReadCountData) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Get(com.pratilipi.api.annotation.Get)

Aggregations

AuthorByReadCountData (com.pratilipi.data.client.AuthorByReadCountData)4 SimpleDateFormat (java.text.SimpleDateFormat)2 Get (com.pratilipi.api.annotation.Get)1 UnexpectedServerException (com.pratilipi.common.exception.UnexpectedServerException)1 DataAccessor (com.pratilipi.data.DataAccessor)1 DataListCursorTuple (com.pratilipi.data.DataListCursorTuple)1 ParseException (java.text.ParseException)1 Date (java.util.Date)1