/** * {@inheritDoc} * * Post a message for a set of users. */ public Future<Void> createMessage(UserId userId, String appId, String msgCollId, Message message, SecurityToken token) throws ProtocolException { for (String recipient : message.getRecipients()) { try { JSONArray outbox = db.getJSONObject(MESSAGE_TABLE).getJSONArray(recipient); if (outbox == null) { outbox = new JSONArray(); db.getJSONObject(MESSAGE_TABLE).put(recipient, outbox); } outbox.put(message); } catch (JSONException je) { throw new ProtocolException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, je.getMessage(), je); } } return ImmediateFuture.newInstance(null); }
/** * {@inheritDoc} * * Post a message for a set of users. */ public Future<Void> createMessage(UserId userId, String appId, String msgCollId, Message message, SecurityToken token) throws ProtocolException { if (message.getId() == null) { // Assign a new ID to the message message.setId(UUID.randomUUID().toString()); } try { JSONObject messagesTable = db.getJSONObject(MESSAGE_TABLE); JSONObject messageObject = convertToJson(message); for (String recipient : message.getRecipients()) { JSONObject collection = messagesTable.getJSONObject(recipient).getJSONObject(msgCollId); JSONArray outbox = collection.getJSONArray(MESSAGES_ARRAY); if (outbox == null) { outbox = new JSONArray(); collection.put(MESSAGES_ARRAY, outbox); } outbox.put(messageObject); } } catch (JSONException je) { throw new ProtocolException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, je.getMessage(), je); } return Futures.immediateFuture(null); }
/** * {@inheritDoc} * * Post a message for a set of users. */ public Future<Void> createMessage(UserId userId, String appId, String msgCollId, Message message, SecurityToken token) throws ProtocolException { if (message.getId() == null) { // Assign a new ID to the message message.setId(UUID.randomUUID().toString()); } try { JSONObject messagesTable = db.getJSONObject(MESSAGE_TABLE); JSONObject messageObject = convertToJson(message); for (String recipient : message.getRecipients()) { JSONObject collection = messagesTable.getJSONObject(recipient).getJSONObject(msgCollId); JSONArray outbox = collection.getJSONArray(MESSAGES_ARRAY); if (outbox == null) { outbox = new JSONArray(); collection.put(MESSAGES_ARRAY, outbox); } outbox.put(messageObject); } } catch (JSONException je) { throw new ProtocolException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, je.getMessage(), je); } return Futures.immediateFuture(null); }
/** * Creates a new message collection or message */ @Operation(httpMethods = "POST", bodyParam = "entity") public Future<?> create(SocialRequestItem request) throws ProtocolException { Set<UserId> userIds = request.getUsers(); String msgCollId = request.getParameter("msgCollId"); List<String> messageIds = request.getListParameter("messageIds"); HandlerPreconditions.requireNotEmpty(userIds, "No userId specified"); HandlerPreconditions.requireSingular(userIds, "Multiple userIds not supported"); UserId user = request.getUsers().iterator().next(); if (msgCollId == null) { // Request to create a new message collection MessageCollection msgCollection = request.getTypedParameter("entity", MessageCollection.class); return service.createMessageCollection(user, msgCollection, request.getToken()); } // A message collection has been specified, allow for posting HandlerPreconditions.requireEmpty(messageIds,"Message IDs not allowed here, use PUT instead"); Message message = request.getTypedParameter("entity", Message.class); HandlerPreconditions.requireNotEmpty(message.getRecipients(), "No recipients specified"); return service.createMessage(userIds.iterator().next(), request.getAppId(), msgCollId, message, request.getToken()); }
/** * Creates a new message collection or message */ @Operation(httpMethods = "POST", bodyParam = "entity") public Future<?> create(SocialRequestItem request) throws ProtocolException { Set<UserId> userIds = request.getUsers(); String msgCollId = request.getParameter("msgCollId"); List<String> messageIds = request.getListParameter("messageIds"); HandlerPreconditions.requireNotEmpty(userIds, "No userId specified"); HandlerPreconditions.requireSingular(userIds, "Multiple userIds not supported"); UserId user = request.getUsers().iterator().next(); if (msgCollId == null) { // Request to create a new message collection MessageCollection msgCollection = request.getTypedParameter("entity", MessageCollection.class); return service.createMessageCollection(user, msgCollection, request.getToken()); } // A message collection has been specified, allow for posting HandlerPreconditions.requireEmpty(messageIds,"Message IDs not allowed here, use PUT instead"); Message message = request.getTypedParameter("entity", Message.class); HandlerPreconditions.requireNotEmpty(message.getRecipients(), "No recipients specified"); return service.createMessage(userIds.iterator().next(), request.getAppId(), msgCollId, message, request.getToken()); }
/** * Creates a new message collection or message */ @Operation(httpMethods = "POST", bodyParam = "entity") public Future<?> modify(SocialRequestItem request) throws ProtocolException { Set<UserId> userIds = request.getUsers(); String msgCollId = request.getParameter("msgCollId"); List<String> messageIds = request.getListParameter("messageIds"); HandlerPreconditions.requireNotEmpty(userIds, "No userId specified"); HandlerPreconditions.requireSingular(userIds, "Multiple userIds not supported"); UserId user = request.getUsers().iterator().next(); if (msgCollId == null) { // Request to create a new message collection MessageCollection msgCollection = request.getTypedParameter("entity", MessageCollection.class); return service.createMessageCollection(user, msgCollection, request.getToken()); } // A message collection has been specified, allow for posting HandlerPreconditions.requireEmpty(messageIds,"Message IDs not allowed here, use PUT instead"); Message message = request.getTypedParameter("entity", Message.class); HandlerPreconditions.requireNotEmpty(message.getRecipients(), "No recipients specified"); return service.createMessage(userIds.iterator().next(), request.getAppId(), msgCollId, message, request.getToken()); }