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;
}
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;
}
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;
}
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();
}
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();
}
Aggregations