*
* @param data Map of key/value pairs to be persisted in AppData
* @return new Request object to update the current viewer's AppData
*/
public static Request updateAppData(Map<String, String> data) {
Request request = new Request(restTemplate, "appdata.update", "PUT");
request.setSelector(SELF);
request.setAppId(APP);
request.setGuid(VIEWER);
// Add RPC payload parameters
List<String> fields = new ArrayList<String>(data.size());
for (Map.Entry<String, String> field : data.entrySet()) {
fields.add(field.getKey());
}
request.addRpcPayloadParameter("data", data);
request.addRpcPayloadParameter("fields", fields);
// Add REST query string parameters
StringBuilder fieldsBuilder = new StringBuilder();
for (Map.Entry<String, String> datum : data.entrySet()) {
if (fieldsBuilder.length() != 0) {
fieldsBuilder.append(",");
}
fieldsBuilder.append(datum.getKey());
}
request.addRestQueryStringParameter("fields", fieldsBuilder.toString());
// Add REST payload parameters
for (Map.Entry<String, String> datum : data.entrySet()) {
request.addRestPayloadParameter(datum.getKey(), datum.getValue());
}
return request;
}