/modules/cms-core/src/main/java/com/enonic/cms/business/core/content/command/UpdateContentCommand.java

https://github.com/informedindividual/cms-ce · Java · 304 lines · 230 code · 64 blank · 10 comment · 8 complexity · caf9a5eaa34712562c3fcafb4b1da497 MD5 · raw file

  1. /*
  2. * Copyright 2000-2011 Enonic AS
  3. * http://www.enonic.com/license
  4. */
  5. package com.enonic.cms.business.core.content.command;
  6. import java.util.Collection;
  7. import java.util.HashSet;
  8. import java.util.List;
  9. import java.util.Set;
  10. import org.springframework.util.Assert;
  11. import com.enonic.cms.domain.content.ContentEntity;
  12. import com.enonic.cms.domain.content.ContentKey;
  13. import com.enonic.cms.domain.content.ContentStatus;
  14. import com.enonic.cms.domain.content.ContentVersionEntity;
  15. import com.enonic.cms.domain.content.ContentVersionKey;
  16. import com.enonic.cms.domain.content.binary.BinaryDataAndBinary;
  17. import com.enonic.cms.domain.content.binary.BinaryDataKey;
  18. import com.enonic.cms.domain.security.user.UserEntity;
  19. import com.enonic.cms.domain.security.user.UserKey;
  20. public class UpdateContentCommand
  21. extends BaseContentCommand
  22. {
  23. private Boolean updateAsNewVersion;
  24. private Boolean forceNewVersionEventIfUnchanged = Boolean.FALSE;
  25. private ContentVersionKey versionKeyToBaseNewVersionOn;
  26. private ContentVersionKey versionKeyToUpdate;
  27. private boolean updateAsMainVersion = false;
  28. private UpdateStrategy updateStrategy = UpdateStrategy.UPDATE;
  29. private boolean syncAccessRights = true;
  30. private boolean syncRelatedContent = true;
  31. private ContentKey contentKey;
  32. private UserKey modifier;
  33. private UserKey owner;
  34. private ContentStatus status;
  35. private String contentName;
  36. private ContentVersionEntity snapshotSource;
  37. private Set<BinaryDataKey> binaryDataToRemove = new HashSet<BinaryDataKey>();
  38. private boolean useCommandsBinaryDataToRemove = false;
  39. private Set<String> blockGroupsToPurgeByName = new HashSet<String>();
  40. private UserKey assignerKey;
  41. public void populateContentValuesFromContent( ContentEntity content )
  42. {
  43. setContentName( content.getName() );
  44. setContentKey( content.getKey() );
  45. setAvailableFrom( content.getAvailableFrom() );
  46. setAvailableTo( content.getAvailableTo() );
  47. setLanguage( content.getLanguage() );
  48. if ( content.getOwner() != null )
  49. {
  50. setOwner( content.getOwner().getKey() );
  51. }
  52. setPriority( content.getPriority() );
  53. addContentAccessRights( content.getContentAccessRights(), content );
  54. }
  55. public void populateContentVersionValuesFromContentVersion( ContentVersionEntity version )
  56. {
  57. setStatus( version.getStatus() );
  58. setChangeComment( version.getChangeComment() );
  59. setSnapshotSource( version.getSnapshotSource() );
  60. setContentData( version.getContentData() );
  61. }
  62. public void setModifier( UserEntity value )
  63. {
  64. Assert.notNull( value );
  65. this.modifier = value.getKey();
  66. }
  67. public void setModifier( UserKey value )
  68. {
  69. Assert.notNull( value );
  70. this.modifier = value;
  71. }
  72. public UserKey getOwner()
  73. {
  74. return owner;
  75. }
  76. public String getContentName()
  77. {
  78. return contentName;
  79. }
  80. public void setContentName( String contentName )
  81. {
  82. this.contentName = contentName;
  83. }
  84. public void setOwner( UserKey owner )
  85. {
  86. this.owner = owner;
  87. }
  88. public void setUpdateAsMainVersion( Boolean value )
  89. {
  90. if ( value != null )
  91. {
  92. this.updateAsMainVersion = value;
  93. }
  94. }
  95. public static UpdateContentCommand updateExistingVersion2( ContentVersionKey versionKeyToUpdate )
  96. {
  97. UpdateContentCommand command = new UpdateContentCommand();
  98. command.versionKeyToUpdate = versionKeyToUpdate;
  99. command.updateAsNewVersion = false;
  100. return command;
  101. }
  102. public static UpdateContentCommand storeNewVersionEvenIfUnchanged( ContentVersionKey versionKeyToBaseNewVersionOn )
  103. {
  104. UpdateContentCommand command = new UpdateContentCommand();
  105. command.updateAsNewVersion = true;
  106. command.versionKeyToBaseNewVersionOn = versionKeyToBaseNewVersionOn;
  107. command.forceNewVersionEventIfUnchanged = true;
  108. return command;
  109. }
  110. public static UpdateContentCommand storeNewVersionIfChanged( ContentVersionKey versionKeyToBaseNewVersionOn )
  111. {
  112. UpdateContentCommand command = new UpdateContentCommand();
  113. command.updateAsNewVersion = true;
  114. command.versionKeyToBaseNewVersionOn = versionKeyToBaseNewVersionOn;
  115. command.forceNewVersionEventIfUnchanged = false;
  116. return command;
  117. }
  118. public void setBinaryDataToAdd( List<BinaryDataAndBinary> list )
  119. {
  120. if ( list != null )
  121. {
  122. this.binaryDatas = list;
  123. }
  124. }
  125. public void setBinaryDataToRemove( Collection<BinaryDataKey> list )
  126. {
  127. if ( list != null )
  128. {
  129. binaryDataToRemove.clear();
  130. binaryDataToRemove.addAll( list );
  131. }
  132. }
  133. public UserKey getModifier()
  134. {
  135. return modifier;
  136. }
  137. public Boolean getUpdateAsNewVersion()
  138. {
  139. return updateAsNewVersion;
  140. }
  141. public Boolean forceNewVersionEventIfUnchanged()
  142. {
  143. return forceNewVersionEventIfUnchanged;
  144. }
  145. public Boolean getUpdateAsMainVersion()
  146. {
  147. return updateAsMainVersion;
  148. }
  149. public List<BinaryDataAndBinary> getBinaryDataToAdd()
  150. {
  151. return binaryDatas;
  152. }
  153. public Set<BinaryDataKey> getBinaryDataToRemove()
  154. {
  155. return binaryDataToRemove;
  156. }
  157. public Boolean getSyncAccessRights()
  158. {
  159. return syncAccessRights;
  160. }
  161. public void setSyncAccessRights( boolean value )
  162. {
  163. this.syncAccessRights = value;
  164. }
  165. public Boolean getSyncRelatedContent()
  166. {
  167. return syncRelatedContent;
  168. }
  169. public void setSyncRelatedContent( boolean value )
  170. {
  171. this.syncRelatedContent = value;
  172. }
  173. public ContentVersionKey getVersionKeyToBaseNewVersionOn()
  174. {
  175. return versionKeyToBaseNewVersionOn;
  176. }
  177. public ContentVersionKey getVersionKeyToUpdate()
  178. {
  179. return versionKeyToUpdate;
  180. }
  181. /**
  182. * @return the updateStrategy
  183. */
  184. public UpdateStrategy getUpdateStrategy()
  185. {
  186. return updateStrategy;
  187. }
  188. /**
  189. * @param updateStrategy the updateStrategy to set
  190. */
  191. public void setUpdateStrategy( final UpdateStrategy updateStrategy )
  192. {
  193. this.updateStrategy = updateStrategy;
  194. }
  195. public ContentKey getContentKey()
  196. {
  197. return contentKey;
  198. }
  199. public void setContentKey( ContentKey contentKey )
  200. {
  201. this.contentKey = contentKey;
  202. }
  203. public ContentStatus getStatus()
  204. {
  205. return status;
  206. }
  207. public void setStatus( ContentStatus status )
  208. {
  209. this.status = status;
  210. }
  211. public enum UpdateStrategy
  212. {
  213. UPDATE,
  214. MODIFY
  215. }
  216. public boolean useCommandsBinaryDataToRemove()
  217. {
  218. return useCommandsBinaryDataToRemove;
  219. }
  220. public void setUseCommandsBinaryDataToRemove( boolean useCommandsBinaryDataToRemove )
  221. {
  222. this.useCommandsBinaryDataToRemove = useCommandsBinaryDataToRemove;
  223. }
  224. public ContentVersionEntity getSnapshotSource()
  225. {
  226. return snapshotSource;
  227. }
  228. public void setSnapshotSource( ContentVersionEntity snapshotSource )
  229. {
  230. this.snapshotSource = snapshotSource;
  231. }
  232. public void addBlockGroupToPurge( String name )
  233. {
  234. this.blockGroupsToPurgeByName.add( name );
  235. }
  236. public Set<String> getBlockGroupsToPurgeByName()
  237. {
  238. return blockGroupsToPurgeByName;
  239. }
  240. }