PageRenderTime 74ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/plugin/src/main/java/com/atlassian/developer/calliope/plugin/rest/UploadResource.java

https://bitbucket.org/rtalusan/calliope
Java | 50 lines | 42 code | 8 blank | 0 comment | 2 complexity | 3e10947e1cd967370464f5e418a92bb3 MD5 | raw file
  1. package com.atlassian.developer.calliope.plugin.rest;
  2. import java.util.Date;
  3. import javax.ws.rs.PUT;
  4. import javax.ws.rs.Path;
  5. import javax.ws.rs.PathParam;
  6. import javax.ws.rs.core.Response;
  7. import com.atlassian.confluence.core.DefaultSaveContext;
  8. import com.atlassian.confluence.pages.Page;
  9. import com.atlassian.confluence.pages.PageManager;
  10. import com.atlassian.confluence.spaces.SpaceManager;
  11. import com.atlassian.plugins.rest.common.security.AnonymousAllowed;
  12. import static javax.ws.rs.core.Response.ok;
  13. @Path("/upload/{title}")
  14. public class UploadResource
  15. {
  16. private final PageManager pageManager;
  17. private final SpaceManager spaceManager;
  18. public UploadResource(PageManager pageManager, SpaceManager spaceManager)
  19. {
  20. this.pageManager = pageManager;
  21. this.spaceManager = spaceManager;
  22. }
  23. @PUT
  24. @AnonymousAllowed
  25. public Response put(@PathParam("title") String title, String content)
  26. {
  27. Page page = pageManager.getPage("api", title);
  28. if (page == null)
  29. {
  30. page = new Page();
  31. page.setCreatorName("Calliope");
  32. page.setCreationDate(new Date());
  33. page.setSpace(spaceManager.getSpace("api"));
  34. page.setTitle(title);
  35. }
  36. page.setLastModifierName("Calliope");
  37. page.setLastModificationDate(new Date());
  38. page.setContent(content);
  39. pageManager.saveContentEntity(page, new DefaultSaveContext());
  40. return ok().build();
  41. }
  42. }