@JsonRequest
@ApiOperation(value = "Set user properties once", request = User.class, response = Integer.class)
@ApiResponses(value = {@ApiResponse(code = 404, message = "User does not exist.")})
@Path("/set_properties_once")
public void setPropertiesOnce(RakamHttpRequest request) {
request.bodyHandler(s -> {
User req;
try {
req = JsonHelper.readSafe(s, User.class);
} catch (IOException e) {
returnError(request, e.getMessage(), BAD_REQUEST);
return;
}
String project = apiKeyService.getProjectOfApiKey(req.api.apiKey, WRITE_KEY);
DefaultFullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, wrappedBuffer(OK_MESSAGE));
response.headers().set(ACCESS_CONTROL_ALLOW_ORIGIN, request.headers().get(ORIGIN));
List<Cookie> cookies = mapProperties(project, req, request);
if (cookies != null) {
response.headers().add(SET_COOKIE,
STRICT.encode(cookies));
}
String headerList = getHeaderList(response.headers().iterator());
if (headerList != null) {
response.headers().set(ACCESS_CONTROL_EXPOSE_HEADERS, headerList);
}
service.setUserPropertiesOnce(project, req.id, req.properties);
request.response(OK_MESSAGE).end();
});
}