use of com.pratilipi.api.shared.GenericResponse in project pratilipi by Pratilipi.
the class VoteApi method post.
@Post
public GenericResponse post(PostRequest request) throws InvalidArgumentException, InsufficientAccessException {
VoteData voteData = VoteDataUtil.saveVoteData(AccessTokenFilter.getAccessToken().getUserId(), request.parentType, request.parentId, request.type);
if (voteData.getReferenceType() == ReferenceType.PRATILIPI) {
Task task = TaskQueueFactory.newTask().setUrl("/pratilipi/process").addParam("pratilipiId", voteData.getReferenceId()).addParam("updateReviewsDoc", "true");
TaskQueueFactory.getPratilipiTaskQueue().add(task);
}
return new GenericResponse();
}
use of com.pratilipi.api.shared.GenericResponse in project pratilipi by Pratilipi.
the class PratilipiIdfApi method get.
@Get
public GenericResponse get(GenericRequest request) throws UnexpectedServerException {
Date idfGenerationDate = new Date();
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
PratilipiFilter pratilipiFilter = new PratilipiFilter();
String cursor = null;
DataListCursorTuple<Long> pratilipiIdListCursorTupe = dataAccessor.getPratilipiIdList(pratilipiFilter, cursor, null, null);
List<Long> pratilipiIdList = pratilipiIdListCursorTupe.getDataList();
// Populate Keyword-Frequency map.
final HashMap<String, Integer> keywordFrequencyMap = new HashMap<>();
for (Long pratilipiId : pratilipiIdList) {
String[] keywords = PratilipiDataUtil.getPratilipiKeywords(pratilipiId).split("\\s+");
if (keywords == null)
continue;
for (String keyword : keywords) {
if (keywordFrequencyMap.containsKey(keyword))
keywordFrequencyMap.put(keyword, keywordFrequencyMap.get(keyword) + 1);
else
keywordFrequencyMap.put(keyword, 1);
}
}
// Sort Keyword-Frequency map in descending order of frequency
Comparator<String> comparator = new Comparator<String>() {
@Override
public int compare(String a, String b) {
return keywordFrequencyMap.get(a) >= keywordFrequencyMap.get(b) ? -1 : 1;
}
};
TreeMap<String, Integer> sortedKeywordFrequencyMap = new TreeMap<>(comparator);
sortedKeywordFrequencyMap.putAll(keywordFrequencyMap);
// Transform sorted map to csv string
StringBuilder csv = new StringBuilder();
for (Map.Entry<String, Integer> entry : sortedKeywordFrequencyMap.entrySet()) {
csv.append(entry.getKey() + ",");
csv.append(entry.getValue().toString() + ",");
csv.append("\n");
}
// Persist csv string in BlobStore
BlobAccessor blobAccessor = DataAccessorFactory.getBlobAccessor();
BlobEntry blobEntry = blobAccessor.newBlob("pratilipi/" + new SimpleDateFormat("yyyy-MM-dd-HH:mm").format(idfGenerationDate) + "-idf.csv", null, "text/plain");
blobEntry.setData(csv.toString().getBytes(Charset.forName("UTF-8")));
blobAccessor.createOrUpdateBlob(blobEntry);
logger.log(Level.INFO, "Generated IDF with " + keywordFrequencyMap.size() + " keywords.");
return new GenericResponse();
}
use of com.pratilipi.api.shared.GenericResponse in project pratilipi by Pratilipi.
the class UserProcessApi method get.
@Get
public GenericResponse get(GenericRequest request) {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
// Fetching AppProperty
AppProperty appProperty = dataAccessor.getAppProperty(appPropertyId);
if (appProperty == null) {
appProperty = dataAccessor.newAppProperty(appPropertyId);
appProperty.setValue(new Date(0));
}
List<Key<UserEntity>> keyList = ObjectifyService.ofy().load().type(UserEntity.class).filter("SIGN_UP_DATE >", appProperty.getValue()).order("SIGN_UP_DATE").limit(10000).keys().list();
// Creating task for each user.
List<Task> taskList = new ArrayList<>(keyList.size());
for (Key<UserEntity> key : keyList) {
Task task = TaskQueueFactory.newTask().setUrl("/user/process").addParam("userId", key.getId() + "").addParam("validateData", "true");
taskList.add(task);
}
TaskQueueFactory.getUserOfflineTaskQueue().addAll(taskList);
logger.log(Level.INFO, "Added " + taskList.size() + " tasks.");
// Updating AppProperty.
if (taskList.size() > 0) {
appProperty.setValue(dataAccessor.getUser(keyList.get(keyList.size() - 1).getId()).getSignUpDate());
dataAccessor.createOrUpdateAppProperty(appProperty);
}
return new GenericResponse();
}
use of com.pratilipi.api.shared.GenericResponse in project pratilipi by Pratilipi.
the class PratilipiContentBatchApi method get.
@Post
public static GenericResponse get(PostRequest request) throws InvalidArgumentException, InsufficientAccessException, UnexpectedServerException {
PratilipiDocUtil.saveContentPageBatch(request.pratilipiId, request.jsonObject);
Task task = TaskQueueFactory.newTask().setUrl("/pratilipi/process").addParam("pratilipiId", request.pratilipiId.toString()).addParam("processContentDoc", "true");
TaskQueueFactory.getPratilipiTaskQueue().add(task);
return new GenericResponse();
}
Aggregations