use of com.pratilipi.data.type.Pratilipi in project pratilipi by Pratilipi.
the class AuthorProcessApi method _validateAuthorData.
private void _validateAuthorData(Long authorId) throws InvalidArgumentException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Author author = dataAccessor.getAuthor(authorId);
Page page = dataAccessor.getPage(PageType.AUTHOR, authorId);
// DELETED Author can not have a Page entity linked.
if (author.getState() == AuthorState.DELETED && page != null)
throw new InvalidArgumentException("DELETED Author has a non-deleted Page entity.");
// Non-DELETED Author must have a page entity linked.
if (author.getState() != AuthorState.DELETED && page == null)
throw new InvalidArgumentException("Page entity is missing for the Author.");
// Pratilipi Entities linked with the Author.
PratilipiFilter pratilipiFilter = new PratilipiFilter();
pratilipiFilter.setAuthorId(authorId);
pratilipiFilter.setState(PratilipiState.PUBLISHED);
List<Pratilipi> pratilipiList = dataAccessor.getPratilipiList(pratilipiFilter, null, null).getDataList();
// DELETED Author cannot have non-DELETED Pratilipi entities linked.
if (author.getState() == AuthorState.DELETED) {
if (pratilipiList.size() != 0)
throw new InvalidArgumentException("DELETED Author has " + pratilipiList.size() + " non-deleted Pratilipi Entities linked.");
return;
}
// Author having Pratilipi entites linked, can not have his/her language set to null.
if (author.getLanguage() == null && pratilipiList.size() != 0)
throw new InvalidArgumentException("Author has " + pratilipiList.size() + " non-deleted Pratilipi Entities linked but his/her language is not set.");
// Count of Pratilipi Entities in each language.
Map<Language, Integer> langCount = new HashMap<>();
for (Pratilipi pratilipi : pratilipiList) {
if (pratilipi.getState() != PratilipiState.PUBLISHED)
continue;
Integer count = langCount.get(pratilipi.getLanguage());
count = count == null ? 1 : count++;
langCount.put(pratilipi.getLanguage(), count);
}
// Author, having Pratilipi entities in just one language, must have the same set as his/her profile language.
if (langCount.keySet().size() == 1) {
Language language = langCount.keySet().iterator().next();
if (langCount.get(language) > 1 && author.getLanguage() != language)
throw new InvalidArgumentException("Author has " + author.getLanguage() + " as his/her profile language but all his/her content pieces are in " + language + ".");
}
// At least one of four name fields must be set.
if (author.getFirstName() == null && author.getLastName() == null && author.getFirstNameEn() == null && author.getLastNameEn() == null)
throw new InvalidArgumentException("Author name is missing.");
// Name fields must not have empty string.
if ((author.getFirstName() != null && author.getFirstName().trim().isEmpty()) || (author.getLastName() != null && author.getLastName().trim().isEmpty()) || (author.getFirstNameEn() != null && author.getFirstNameEn().trim().isEmpty()) || (author.getLastNameEn() != null && author.getLastNameEn().trim().isEmpty()))
throw new InvalidArgumentException("Author name has empty string.");
}
use of com.pratilipi.data.type.Pratilipi in project pratilipi by Pratilipi.
the class PratilipiBackupApi method post.
@Post
public GenericResponse post(PostRequest request) throws UnexpectedServerException {
Pratilipi pratilipi = DataAccessorFactory.getDataAccessor().getPratilipi(request.pratilipiId);
Date dateTime = new Date(pratilipi.getLastUpdated().getTime() + TimeUnit.HOURS.toMillis(1L) - 1);
DateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd-HH'.00'-z");
dateTimeFormat.setTimeZone(TimeZone.getTimeZone("Asia/Kolkata"));
GcsService gcsService = GcsServiceFactory.createGcsService(RetryParams.getDefaultInstance());
String srcBucket = "static.pratilipi.com";
String dstBucket = "backup.pratilipi.com";
String srcPrefix = "pratilipi/" + request.pratilipiId + "/";
String dstPrefix = srcBucket + "/pratilipi-" + dateTimeFormat.format(dateTime) + "/" + request.pratilipiId + "/";
try {
ListResult result = gcsService.list(srcBucket, new ListOptions.Builder().setPrefix(srcPrefix).build());
while (result.hasNext()) {
String srcName = result.next().getName();
String dstName = dstPrefix + srcName.substring(srcPrefix.length());
gcsService.copy(new GcsFilename(srcBucket, srcName), new GcsFilename(dstBucket, dstName));
}
} catch (IOException e) {
logger.log(Level.SEVERE, "", e);
throw new UnexpectedServerException();
}
return new GenericResponse();
}
use of com.pratilipi.data.type.Pratilipi in project pratilipi by Pratilipi.
the class DataStoreCleanupUtil method delete.
public static void delete(Author author, boolean preview) {
System.out.println();
System.out.println("Author id: " + author.getId() + ", state: " + author.getState());
if (!preview && author.getState() != AuthorState.DELETED && author.getState() != AuthorState.BLOCKED) {
author.setState(AuthorState.DELETED);
// Save
ObjectifyService.ofy().save().entity(author).now();
// Delete search index
DataAccessorFactory.getSearchAccessor().deleteAuthorDataIndex(author.getId());
}
// USER_AUTHOR Table
List<UserAuthorEntity> userAuthorList = ObjectifyService.ofy().load().type(UserAuthorEntity.class).filter("AUTHOR_ID", author.getId()).list();
System.out.println("UserAuthorEntity # " + userAuthorList.size());
int followerCount = 0;
for (UserAuthor userAuthor : userAuthorList) if (userAuthor.getFollowState() == UserFollowState.FOLLOWING)
followerCount++;
System.out.println("Follower ## " + followerCount);
if (!preview) {
for (UserAuthor userAuthor : userAuthorList) {
if (userAuthor.getFollowState() != null) {
userAuthor.setFollowState(null);
// Save
ObjectifyService.ofy().save().entity(userAuthor).now();
}
}
}
// PAGE Table
List<PageEntity> pageList = ObjectifyService.ofy().load().type(PageEntity.class).filter("PAGE_TYPE", "AUTHOR").filter("PRIMARY_CONTENT_ID", author.getId()).list();
System.out.println("PageEntity # " + pageList.size());
if (!preview)
for (Page page : pageList) // Delete
ObjectifyService.ofy().delete().entity(page).now();
// PRATILIPI Table
List<PratilipiEntity> pratilipiList = ObjectifyService.ofy().load().type(PratilipiEntity.class).filter("AUTHOR_ID", author.getId()).list();
System.out.println();
System.out.println("PratilipiEntity # " + pratilipiList.size());
if (pratilipiList.size() == 0)
return;
for (Pratilipi pratilipi : pratilipiList) delete(pratilipi, preview);
}
use of com.pratilipi.data.type.Pratilipi in project pratilipi by Pratilipi.
the class DataAccessorMockImpl method getPratilipiIdList.
@Override
public DataListCursorTuple<Long> getPratilipiIdList(PratilipiFilter pratilipiFilter, String cursorStr, Integer offset, Integer resultCount) {
List<Long> pratilipiIdList = new ArrayList<Long>();
for (Pratilipi pratilipi : PratilipiMock.PRATILIPI_TABLE) {
if (pratilipi.getLanguage() == pratilipiFilter.getLanguage()) {
pratilipiIdList.add(pratilipi.getId());
pratilipiIdList.add(pratilipi.getId());
}
}
return new DataListCursorTuple<>(pratilipiIdList, null);
}
use of com.pratilipi.data.type.Pratilipi in project pratilipi by Pratilipi.
the class PratilipiDataUtil method getPratilipiCover.
public static BlobEntry getPratilipiCover(Long pratilipiId, Integer width) throws UnexpectedServerException {
Pratilipi pratilipi = pratilipiId == null ? null : DataAccessorFactory.getDataAccessor().getPratilipi(pratilipiId);
BlobEntry blobEntry = null;
if (pratilipi == null || pratilipi.getCoverImage() == null) {
blobEntry = DataAccessorFactory.getBlobAccessor().getBlob("pratilipi/default/images/cover");
} else {
blobEntry = DataAccessorFactory.getBlobAccessor().getBlob("pratilipi/" + pratilipiId + "/images/" + pratilipi.getCoverImage());
if (blobEntry == null)
blobEntry = DataAccessorFactory.getBlobAccessor().getBlob("pratilipi-cover/original/" + pratilipiId);
}
if (width != null)
blobEntry = ImageUtil.resize(blobEntry, width, (int) (1.5 * width));
return blobEntry;
}
Aggregations