use of com.pratilipi.common.exception.UnexpectedServerException 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.common.exception.UnexpectedServerException 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.UnexpectedServerException in project pratilipi by Pratilipi.
the class UserPratilipiBackfillApi method updateUserPratilipi.
private UserPratilipiData updateUserPratilipi(Long userId, Long pratilipiId, String lastPageOpened, String lastOpenedDate) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
UserPratilipi userPratilipi = dataAccessor.getUserPratilipi(userId, pratilipiId);
if (userPratilipi == null) {
// CREATE USER PRATILIPI
userPratilipi = dataAccessor.newUserPratilipi();
userPratilipi.setUserId(userId);
userPratilipi.setPratilipiId(pratilipiId);
}
// Creating Auditlog entity
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.USER_PRATILIPI_REVIEW, userPratilipi);
// update lastPageOpened
userPratilipi.setLastOpenedPage(lastPageOpened);
try {
// update lastPageOpenedDate
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
formatter.setTimeZone(TimeZone.getTimeZone("IST"));
Date date = (Date) formatter.parse(lastOpenedDate);
userPratilipi.setLastOpenedDate(date);
userPratilipi = dataAccessor.createOrUpdateUserPratilipi(userPratilipi, auditLog);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
logger.log(Level.SEVERE, "Event Date : " + lastOpenedDate);
throw new UnexpectedServerException("Error while parsing date.");
}
return UserPratilipiDataUtil.createUserPratilipiData(userPratilipi);
}
use of com.pratilipi.common.exception.UnexpectedServerException in project pratilipi by Pratilipi.
the class PratilipiTagsUpdateApi method updatePratilipiTags.
@Post
public PostResponse updatePratilipiTags(PostRequest request) throws InsufficientAccessException, UnexpectedServerException {
List<Long> tagIds = request.getTagIds();
List<String> suggestedTags = request.getSuggestedTags();
PratilipiType pratilipiType = request.getPratilipiType();
Long pratilipiId = request.getPratilipiId();
Logger.getLogger(PratilipiTagsUpdateApi.class.getSimpleName()).log(Level.INFO, "TagIds : " + tagIds);
Logger.getLogger(PratilipiTagsUpdateApi.class.getSimpleName()).log(Level.INFO, "SuggestedTags : " + suggestedTags);
if (tagIds == null && suggestedTags == null)
throw new UnexpectedServerException("Both tagIds and suggestedTags cannot be null");
boolean isUpdated = PratilipiDataUtil.updatePratilipiTags(pratilipiId, pratilipiType, tagIds, suggestedTags);
return new PostResponse(isUpdated);
}
use of com.pratilipi.common.exception.UnexpectedServerException in project pratilipi by Pratilipi.
the class RtdbAccessorFirebaseImpl method _getUserPreferences.
private Map<Long, UserPreferenceRtdb> _getUserPreferences(Map<String, String> paramsMap) throws UnexpectedServerException {
try {
BlobEntry blobEntry = HttpUtil.doGet(_getUserPreferenceDbUrl(), headersMap, paramsMap);
String jsonStr = new String(blobEntry.getData(), "UTF-8");
JsonObject json = new Gson().fromJson(jsonStr, JsonElement.class).getAsJsonObject();
Map<Long, UserPreferenceRtdb> userPreferenceMap = new HashMap<>();
for (Entry<String, JsonElement> entry : json.entrySet()) userPreferenceMap.put(Long.parseLong(entry.getKey()), _getUserPreferenceRtdb(entry.getValue().getAsJsonObject()));
return userPreferenceMap;
} catch (UnsupportedEncodingException e) {
logger.log(Level.SEVERE, e.getMessage());
throw new UnexpectedServerException();
}
}
Aggregations