use of com.pratilipi.common.exception.InvalidArgumentException in project pratilipi by Pratilipi.
the class InitDataUtil method getInitBanner.
public static BlobEntry getInitBanner(Language language, String name, Integer width) throws InvalidArgumentException, UnexpectedServerException {
BlobEntry blobEntry = DataAccessorFactory.getBlobAccessor().getBlob("init/banners/" + language.getCode() + "/" + name);
if (blobEntry == null) {
JsonObject errorMessages = new JsonObject();
errorMessages.addProperty("name", "Invalid banner name.");
throw new InvalidArgumentException(errorMessages);
}
if (width != null)
blobEntry.setData(ImageUtil.resize(blobEntry.getData(), width));
return blobEntry;
}
use of com.pratilipi.common.exception.InvalidArgumentException in project pratilipi by Pratilipi.
the class MailingListSubscriptionDataUtil method subscribe.
public static void subscribe(MailingList mailingList, Long userId, String email, String phone, Language language, String comment) throws InvalidArgumentException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
MailingListSubscription mailingListSubscription = null;
if (email != null) {
List<MailingListSubscription> mailingListSubscriptionList = dataAccessor.getMailingListSubscriptionList(mailingList, email, null);
for (MailingListSubscription subs : mailingListSubscriptionList) {
if (language != null && subs.getLanguage() != null && language != subs.getLanguage())
continue;
if (phone != null && subs.getPhone() != null && !phone.equals(subs.getPhone()))
continue;
if (comment != null && subs.getComment() != null && !comment.equals(subs.getComment()))
continue;
mailingListSubscription = subs;
break;
}
} else if (phone != null) {
List<MailingListSubscription> mailingListSubscriptionList = dataAccessor.getMailingListSubscriptionList(mailingList, null, phone);
for (MailingListSubscription subs : mailingListSubscriptionList) {
if (language != null && subs.getLanguage() != null && language != subs.getLanguage())
continue;
if (comment != null && subs.getComment() != null && !comment.equals(subs.getComment()))
continue;
mailingListSubscription = subs;
break;
}
} else {
throw new InvalidArgumentException("Either email or phone must be provided.");
}
if (mailingListSubscription == null)
mailingListSubscription = dataAccessor.newMailingListSubscription();
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.MAILING_LIST_SUBSCRIPTION_ADD, mailingListSubscription);
boolean bool = true;
if (// New entry
mailingListSubscription.getMailingList() == null)
mailingListSubscription.setMailingList(mailingList);
if (userId != null && mailingListSubscription.getUserId() == null)
mailingListSubscription.setUserId(userId);
if (email != null && mailingListSubscription.getEmail() == null) {
mailingListSubscription.setEmail(email);
bool = false;
}
if (phone != null && mailingListSubscription.getPhone() == null) {
mailingListSubscription.setPhone(phone);
bool = false;
}
if (language != null && mailingListSubscription.getLanguage() == null) {
mailingListSubscription.setLanguage(language);
bool = false;
}
if (comment != null && mailingListSubscription.getComment() == null) {
mailingListSubscription.setComment(comment);
bool = false;
}
if (// New entry
mailingListSubscription.getSubscriptionDate() == null)
mailingListSubscription.setSubscriptionDate(new Date());
if (bool)
throw new InvalidArgumentException(GenericRequest.ERR_MAILING_LIST_SUBSCRIBED_ALREDY);
dataAccessor.createOrUpdateMailingListSubscription(mailingListSubscription, auditLog);
}
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();
}
}
Aggregations