Search in sources :

Example 56 with DataAccessor

use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.

the class AuthorDataUtil method _getRecommendAuthorGlobalList.

private static List<Long> _getRecommendAuthorGlobalList(Language language) {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    Memcache memcache = DataAccessorFactory.getL2CacheAccessor();
    String memcacheId = "AuthorDataUtil.RecommendAuthorGlobalList-" + language.getCode();
    List<Long> authorList = memcache.get(memcacheId);
    if (authorList != null)
        return authorList;
    Long minReadCount;
    switch(language) {
        case BENGALI:
            minReadCount = 3000L;
            break;
        case GUJARATI:
            minReadCount = 2000L;
            break;
        case HINDI:
            minReadCount = 7500L;
            break;
        case KANNADA:
            minReadCount = 200L;
            break;
        case MALAYALAM:
            minReadCount = 4000L;
            break;
        case MARATHI:
            minReadCount = 2000L;
            break;
        case TAMIL:
            minReadCount = 2200L;
            break;
        case TELUGU:
            minReadCount = 500L;
            break;
        default:
            minReadCount = 2000L;
    }
    authorList = dataAccessor.getAuthorIdListWithMaxReadCount(language, minReadCount, 1000);
    // Algorithm - Shuffling the list in order
    int[] order = { 1, 3, 2, 4, 6, 5, 7, 9, 8, 10, 12, 11, 13, 15, 14, 16, 18, 17, 19, 21, 20, 22, 24, 23 };
    int orderSize = order.length;
    ArrayList<Long> resultList = new ArrayList<>(authorList.size());
    int chunkSize = authorList.size() / orderSize;
    for (int i = 0; i < order.length; i++) {
        int beginIndex = (order[i] - 1) * chunkSize;
        List<Long> subList = authorList.subList(beginIndex, beginIndex + chunkSize);
        Collections.shuffle(subList);
        resultList.addAll(subList);
    }
    resultList.addAll(authorList.subList(authorList.size() - (authorList.size() % orderSize), authorList.size()));
    // Caching the result in memcache for 3 hours
    memcache.put(memcacheId, resultList, 180);
    return resultList;
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) ArrayList(java.util.ArrayList) Memcache(com.pratilipi.data.Memcache)

Example 57 with DataAccessor

use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.

the class AuthorDataUtil method createOrUpdateAuthorPageUrl.

public static boolean createOrUpdateAuthorPageUrl(Long authorId) {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    Author author = dataAccessor.getAuthor(authorId);
    Page page = dataAccessor.getPage(PageType.AUTHOR, authorId);
    boolean isNew = page == null;
    boolean isChanged = false;
    if (isNew) {
        page = dataAccessor.newPage();
        page.setType(PageType.AUTHOR);
        page.setUri(PageType.AUTHOR.getUrlPrefix() + authorId);
        page.setPrimaryContentId(authorId);
        page.setCreationDate(new Date());
    }
    if (author.getState() == AuthorState.DELETED) {
        if (page.getUriAlias() == null) {
            if (!isNew)
                return false;
        } else {
            page.setUriAlias(null);
            isChanged = true;
        }
    } else if (page.getUriAlias() == null) {
        // Static Author page urls
        String uriAlias = UriAliasUtil.generateUriAlias(page.getUriAlias(), "/", author.getFirstNameEn(), author.getLastNameEn(), author.getPenNameEn());
        //			if( ! isNew ) {
        //				if( uriAlias == page.getUriAlias()
        //						|| ( uriAlias != null && uriAlias.equals( page.getUriAlias() ) )
        //						|| ( page.getUriAlias() != null && page.getUriAlias().equals( uriAlias ) ) )
        //					return false;
        //			}
        logger.log(Level.INFO, "Updating Author Page Url: '" + page.getUriAlias() + "' -> '" + uriAlias + "'");
        page.setUriAlias(uriAlias);
        isChanged = true;
    }
    if (isNew || isChanged)
        page = dataAccessor.createOrUpdatePage(page);
    return true;
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) Author(com.pratilipi.data.type.Author) Page(com.pratilipi.data.type.Page) Date(java.util.Date)

Example 58 with DataAccessor

use of com.pratilipi.data.DataAccessor 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 59 with DataAccessor

use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.

the class AuthorDataUtil method createAuthorProfile.

public static Long createAuthorProfile(UserData userData, Language language) {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    Author author = dataAccessor.getAuthorByUserId(userData.getId());
    if (author != null && author.getState() != AuthorState.DELETED)
        return author.getId();
    else
        author = dataAccessor.newAuthor();
    AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.AUTHOR_ADD, author);
    author.setUserId(userData.getId());
    author.setFirstName(userData.getFirstName());
    author.setLastName(userData.getLastName());
    author.setGender(userData.getGender());
    author.setDateOfBirth(userData.getDateOfBirth());
    author.setLanguage(language);
    author.setState(AuthorState.ACTIVE);
    author.setRegistrationDate(userData.getSignUpDate());
    author.setLastUpdated(userData.getSignUpDate());
    author = dataAccessor.createOrUpdateAuthor(author, auditLog);
    createOrUpdateAuthorPageUrl(author.getId());
    return author.getId();
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) Author(com.pratilipi.data.type.Author) AuditLog(com.pratilipi.data.type.AuditLog)

Example 60 with DataAccessor

use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.

the class BatchProcessApi method get.

@Get
public GenericResponse get(GenericRequest request) throws UnexpectedServerException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    List<BatchProcess> batchProcessList = dataAccessor.getIncompleteBatchProcessList();
    for (BatchProcess batchProcess : batchProcessList) if (BatchProcessDataUtil.exec(batchProcess.getId()))
        // Only one execution per iteration as next BatchProcess' state might change by the time it is picked up.
        break;
    return new GenericResponse();
}
Also used : GenericResponse(com.pratilipi.api.shared.GenericResponse) DataAccessor(com.pratilipi.data.DataAccessor) BatchProcess(com.pratilipi.data.type.BatchProcess) Get(com.pratilipi.api.annotation.Get)

Aggregations

DataAccessor (com.pratilipi.data.DataAccessor)162 Date (java.util.Date)53 InsufficientAccessException (com.pratilipi.common.exception.InsufficientAccessException)37 Pratilipi (com.pratilipi.data.type.Pratilipi)34 Author (com.pratilipi.data.type.Author)33 AuditLog (com.pratilipi.data.type.AuditLog)32 UserPratilipi (com.pratilipi.data.type.UserPratilipi)32 ArrayList (java.util.ArrayList)30 Page (com.pratilipi.data.type.Page)28 HashMap (java.util.HashMap)25 GenericResponse (com.pratilipi.api.shared.GenericResponse)24 DocAccessor (com.pratilipi.data.DocAccessor)22 User (com.pratilipi.data.type.User)22 Get (com.pratilipi.api.annotation.Get)20 InvalidArgumentException (com.pratilipi.common.exception.InvalidArgumentException)19 PratilipiData (com.pratilipi.data.client.PratilipiData)15 UserData (com.pratilipi.data.client.UserData)14 BlobAccessor (com.pratilipi.data.BlobAccessor)13 Email (com.pratilipi.data.type.Email)13 JsonObject (com.google.gson.JsonObject)12