Guest User

Untitled

a guest
Jan 22nd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. package com.dotmarketing.portlets.workflows.actionlet;
  2.  
  3. import com.dotcms.business.WrapInTransaction;
  4. import com.dotmarketing.business.APILocator;
  5. import com.dotmarketing.portlets.contentlet.business.ContentletAPI;
  6. import com.dotmarketing.portlets.contentlet.model.Contentlet;
  7. import com.dotmarketing.portlets.workflows.model.*;
  8. import com.dotmarketing.util.Logger;
  9. import com.google.common.annotations.VisibleForTesting;
  10.  
  11. import java.util.List;
  12. import java.util.Map;
  13.  
  14. /**
  15. * Do the save for a content (checkin)
  16. * @author jsanca
  17. */
  18. public class SaveContentActionlet extends WorkFlowActionlet {
  19.  
  20. private final ContentletAPI contentletAPI;
  21.  
  22. public SaveContentActionlet () {
  23.  
  24. this(APILocator.getContentletAPI());
  25. }
  26.  
  27. @VisibleForTesting
  28. protected SaveContentActionlet (final ContentletAPI contentletAPI) {
  29.  
  30. this.contentletAPI = contentletAPI;
  31. }
  32.  
  33. /**
  34. *
  35. */
  36. private static final long serialVersionUID = 1L;
  37.  
  38. public String getName() {
  39. return "Save content";
  40. }
  41.  
  42. public String getHowTo() {
  43.  
  44. return "This actionlet will checkin the content.";
  45. }
  46.  
  47. @WrapInTransaction
  48. public void executeAction(final WorkflowProcessor processor,
  49. final Map<String, WorkflowActionClassParameter> params) throws WorkflowActionFailureException {
  50.  
  51. try {
  52.  
  53. final Contentlet contentlet =
  54. processor.getContentlet();
  55.  
  56. Logger.debug(this,
  57. "Saving the content of the contentlet: " + contentlet.getIdentifier());
  58.  
  59. final Contentlet checkoutContentlet = this.contentletAPI.checkout
  60. (contentlet.getInode(), processor.getUser(), false);
  61. final String inode = checkoutContentlet.getInode();
  62.  
  63. this.contentletAPI.copyProperties(checkoutContentlet, contentlet.getMap());
  64. checkoutContentlet.setInode(inode);
  65. checkoutContentlet.setProperty(Contentlet.WORKFLOW_IN_PROGRESS, Boolean.TRUE);
  66.  
  67. final Contentlet contentletNew = this.contentletAPI.checkin(
  68. checkoutContentlet, processor.getUser(), false);
  69.  
  70. processor.setContentlet(contentletNew);
  71.  
  72. Logger.debug(this,
  73. "content version already saved for the contentlet: " + contentlet.getIdentifier());
  74. } catch (Exception e) {
  75.  
  76. Logger.error(this.getClass(),e.getMessage(),e);
  77. throw new WorkflowActionFailureException(e.getMessage());
  78. }
  79. }
  80.  
  81. public WorkflowStep getNextStep() {
  82.  
  83. return null;
  84. }
  85.  
  86. @Override
  87. public List<WorkflowActionletParameter> getParameters() {
  88.  
  89. return null;
  90. }
  91. }
Add Comment
Please, Sign In to add comment