@Transactional
public Response store(@Context Request request, @Context HttpHeaders headers,
@Context Credentials credentials, @PathParam("user_id") String userId,
@PathParam("name") String name, byte[] body) throws CryptographicException {
final Session session = credentials.buildSession(userDAO, userId);
Document doc = documentDAO.findByOwnerAndName(session.getUser(), name);
if (doc == null) {
doc = documentDAO.newDocument(session.getUser(), name, headers.getMediaType());
} else {
checkPreconditions(request, doc);
}
doc.setModifiedAt(new DateTime(DateTimeZone.UTC));
doc.encryptAndSetBody(
session.getKeySet(),
randomProvider.get(),
body
);
documentDAO.saveOrUpdate(doc);