//get social account
final SocialAccount socialAccount = getAccountDao().getSocialAccountById(socialAccountId);
Set<HashTag> hashTags = new HashSet<>();
log.debug("publishTweetPoll socialTwitterAccounts: {"+socialAccount);
//create tweet status
final TweetPollSavedPublishedStatus publishedStatus = new TweetPollSavedPublishedStatus();
//social provider.
publishedStatus.setApiType(socialAccount.getAccounType());
//checking required values.
if (type.equals(TypeSearchResult.TWEETPOLL)) {
//adding tweetpoll
publishedStatus.setTweetPoll(tweetPoll);
hashTags = tweetPoll.getHashTags();
} else if(type.equals(TypeSearchResult.POLL)) {
//adding tweetpoll
publishedStatus.setPoll(poll);
hashTags = poll.getHashTags();
} else if(type.equals(TypeSearchResult.SURVEY)) {
publishedStatus.setSurvey(survey);
hashTags = survey.getHashTags();
} else {
log.error("Type not defined");
}
if (socialAccount != null) {
log.debug("socialAccount Account NAME:{"+socialAccount.getSocialAccountName());
//adding social account
publishedStatus.setSocialAccount(socialAccount);
try {
log.debug("publishTweetPoll Publishing... "+tweetText.length());
final TweetPublishedMetadata metadata = publicTweetPoll(tweetText, socialAccount, hashTags);
if (metadata == null || metadata.getTweetId() == null) {
throw new EnMeFailSendSocialTweetException("status not valid");
}//getMessageProperties(propertieId)
if (metadata.getTweetId() == null) {
log.warn("tweet id is empty");
}
//store original tweet id.
publishedStatus.setTweetId(metadata.getTweetId());
//store original publication date.
publishedStatus.setPublicationDateTweet(metadata.getDatePublished());
//success publish state..
publishedStatus.setStatus(Status.SUCCESS);
//store original tweet content.
publishedStatus.setTweetContent(metadata.getTextTweeted());
//create notification
//createNotification(NotificationEnum.TWEETPOLL_PUBLISHED, "tweet published", socialAccount.getAccount());
createNotification(NotificationEnum.SOCIAL_MESSAGE_PUBLISHED, tweetText, SocialUtils.getSocialTweetPublishedUrl(
metadata.getTweetId(), socialAccount.getSocialAccountName(), socialAccount.getAccounType()), Boolean.TRUE);
} catch (Exception e) {
e.printStackTrace();
log.error("Error publish tweet:{"+e);
//change status to failed
publishedStatus.setStatus(Status.FAILED);
//store error descrition
if (e.getMessage() != null && e.getMessage().isEmpty()) {
publishedStatus.setDescriptionStatus(e.getMessage().substring(254)); //limited to 254 characters.
} else {
publishedStatus.setDescriptionStatus("");
}
//save original tweet content.
publishedStatus.setTweetContent(tweetText);
}
} else {
log.warn("Twitter Account Not Found [Id:"+socialAccountId+"]");
publishedStatus.setStatus(Status.FAILED);
//throw new EnMeFailSendSocialTweetException("Twitter Account Not Found [Id:"+accountId+"]");
if(type.equals(TypeSearchResult.TWEETPOLL)){
tweetPoll.setPublishTweetPoll(Boolean.FALSE);
//getTweetPollDao().saveOrUpdate(tweetPoll);
}
}
log.info("Publish Status Social :{------------>"+publishedStatus.toString());
getTweetPollDao().saveOrUpdate(publishedStatus);
return publishedStatus;
}