use of com.pratilipi.common.exception.InvalidArgumentException in project pratilipi by Pratilipi.
the class BlogPostDataUtil method _validateBlogPostDataForSave.
private static void _validateBlogPostDataForSave(BlogPostData blogPostData) throws InvalidArgumentException {
boolean isNew = blogPostData.getId() == null;
JsonObject errorMessages = new JsonObject();
// New blogPost must have blog id.
if (isNew && (!blogPostData.hasBlogId() || blogPostData.getBlogId() == null))
errorMessages.addProperty("blogId", GenericRequest.ERR_BLOG_ID_REQUIRED);
else // Blog id can not be un-set or set to null.
if (!isNew && blogPostData.hasBlogId() && blogPostData.getBlogId() == null)
errorMessages.addProperty("blogId", GenericRequest.ERR_BLOG_ID_REQUIRED);
// New blogPost must have language.
if (isNew && (!blogPostData.hasLanguage() || blogPostData.getLanguage() == null))
errorMessages.addProperty("language", GenericRequest.ERR_LANGUAGE_REQUIRED);
else // Language can not be un-set or set to null.
if (!isNew && blogPostData.hasLanguage() && blogPostData.getLanguage() == null)
errorMessages.addProperty("language", GenericRequest.ERR_LANGUAGE_REQUIRED);
// New blogPost must have state.
if (isNew && (!blogPostData.hasState() || blogPostData.getState() == null))
errorMessages.addProperty("state", GenericRequest.ERR_BLOG_POST_STATE_REQUIRED);
if (errorMessages.entrySet().size() > 0)
throw new InvalidArgumentException(errorMessages);
}
use of com.pratilipi.common.exception.InvalidArgumentException in project pratilipi by Pratilipi.
the class EventDataUtil method _validateEventDataForSave.
private static void _validateEventDataForSave(EventData eventData) throws InvalidArgumentException {
boolean isNew = eventData.getId() == null;
JsonObject errorMessages = new JsonObject();
// New event must have language.
if (isNew && (!eventData.hasLanguage() || eventData.getLanguage() == null))
errorMessages.addProperty("langauge", GenericRequest.ERR_LANGUAGE_REQUIRED);
else // Language can not be un-set or set to null.
if (!isNew && eventData.hasLanguage() && eventData.getLanguage() == null)
errorMessages.addProperty("langauge", GenericRequest.ERR_LANGUAGE_REQUIRED);
if (errorMessages.entrySet().size() > 0)
throw new InvalidArgumentException(errorMessages);
}
use of com.pratilipi.common.exception.InvalidArgumentException in project pratilipi by Pratilipi.
the class ConversationDataUtil method saveMessage.
public static void saveMessage(ContactTeam team, Long userId, String name, String email, String phone, String message, JsonObject data) throws InvalidArgumentException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
User user = dataAccessor.getUser(userId);
Author author = dataAccessor.getAuthorByUserId(userId);
Conversation conversation = dataAccessor.getConversation(team, userId);
if (conversation == null)
dataAccessor.getConversation(team, email);
if (conversation != null) {
// Do Nothing !
} else if (user != null && (user.getState() == UserState.ACTIVE || user.getState() == UserState.REGISTERED)) {
// &&
// conversation
// ==
// null
conversation = dataAccessor.newConversation(team, userId);
conversation.setCreator(userId);
conversation.setCreatorName(name);
conversation.setCreatorEmail(email);
conversation.setCreatorPhone(phone);
conversation.setCreationDate(new Date());
List<ConversationUser> conversationUserList = new ArrayList<>(team.getUserIds().length + 1);
conversationUserList.add(dataAccessor.newConversationUser(conversation.getId(), userId));
for (Long recipientUserId : team.getUserIds()) conversationUserList.add(dataAccessor.newConversationUser(conversation.getId(), recipientUserId));
conversation = dataAccessor.createOrUpdateConversation(conversation, conversationUserList);
} else if (email != null) {
// && conversation == null
conversation = dataAccessor.newConversation(team, email);
conversation.setCreatorName(name);
conversation.setCreatorEmail(email);
conversation.setCreatorPhone(phone);
conversation.setCreationDate(new Date());
List<ConversationUser> conversationUserList = new ArrayList<>(team.getUserIds().length + 1);
for (Long recipientUserId : team.getUserIds()) conversationUserList.add(dataAccessor.newConversationUser(conversation.getId(), recipientUserId));
conversation = dataAccessor.createOrUpdateConversation(conversation, conversationUserList);
} else {
throw new InvalidArgumentException("Valid 'email' is required.");
}
conversation.setLastUpdated(new Date());
ConversationMessage conversationMessage = dataAccessor.newConversationMessage();
conversationMessage.setConversationId(conversation.getId());
conversationMessage.setCreatorId(userId);
conversationMessage.setMessage(message);
conversationMessage.setData(data);
conversationMessage.setCreationDate(new Date());
conversation = dataAccessor.createOrUpdateConversation(conversation, conversationMessage);
String language = author != null ? author.getLanguage().getNameEn().toLowerCase() : null;
try {
ArrayList<String> receiverList = createReceiversId(team.name().toLowerCase(), language);
createSupportMailTask(receiverList, userId.toString(), name, email, phone, message, data, team.name(), language);
} catch (UnsupportedEncodingException | UnexpectedServerException e) {
logger.log(Level.SEVERE, "Exception while creating conversation mail task");
logger.log(Level.SEVERE, "User ID : " + userId);
logger.log(Level.SEVERE, "Conversation Id : " + conversation.getId());
e.printStackTrace();
}
}
use of com.pratilipi.common.exception.InvalidArgumentException in project pratilipi by Pratilipi.
the class AuthorDataUtil method saveAuthorImage.
public static String saveAuthorImage(Long authorId, BlobEntry blobEntry) throws InvalidArgumentException, InsufficientAccessException, UnexpectedServerException {
if (blobEntry.getData() == null || blobEntry.getData().length == 0)
throw new InvalidArgumentException("Image data is missing.");
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Author author = dataAccessor.getAuthor(authorId);
if (!hasAccessToUpdateAuthorData(author, null))
throw new InsufficientAccessException();
String profileImageName = new Date().getTime() + "";
BlobAccessor blobAccessor = DataAccessorFactory.getBlobAccessor();
blobEntry.setName("author/" + authorId + "/images/profile/" + profileImageName);
blobAccessor.createOrUpdateBlob(blobEntry);
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.AUTHOR_UPDATE, author);
author.setProfileImage(profileImageName);
author.setLastUpdated(new Date());
author = dataAccessor.createOrUpdateAuthor(author, auditLog);
return createAuthorProfileImageUrl(author);
}
use of com.pratilipi.common.exception.InvalidArgumentException in project pratilipi by Pratilipi.
the class AuthorDataUtil method _validateAuthorDataForSave.
private static void _validateAuthorDataForSave(AuthorData authorData) throws InvalidArgumentException {
boolean isNew = authorData.getId() == null;
JsonObject errorMessages = new JsonObject();
// Language is mandatory.
if (isNew && (!authorData.hasLanguage() || authorData.getLanguage() == null))
errorMessages.addProperty("langauge", GenericRequest.ERR_LANGUAGE_REQUIRED);
// Language can not be un-set or set to null.
if (!isNew && authorData.hasLanguage() && authorData.getLanguage() == null)
errorMessages.addProperty("langauge", GenericRequest.ERR_LANGUAGE_REQUIRED);
// State must be ACTIVE for new profile.
if (isNew && (!authorData.hasState() || authorData.getState() != AuthorState.ACTIVE))
errorMessages.addProperty("state", GenericRequest.ERR_AUTHOR_STATE_INVALID);
// State can not be un-set or set to null.
if (!isNew && authorData.hasState() && authorData.getState() == null)
errorMessages.addProperty("state", GenericRequest.ERR_AUTHOR_STATE_REQUIRED);
if (errorMessages.entrySet().size() > 0)
throw new InvalidArgumentException(errorMessages);
}
Aggregations