1 23 24 package org.infoglue.cms.applications.contenttool.actions; 25 26 import java.util.ArrayList ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 30 import org.infoglue.cms.applications.common.actions.InfoGlueAbstractAction; 31 import org.infoglue.cms.controllers.kernel.impl.simple.AccessRightController; 32 import org.infoglue.cms.controllers.kernel.impl.simple.ContentController; 33 import org.infoglue.cms.controllers.kernel.impl.simple.ContentControllerProxy; 34 import org.infoglue.cms.controllers.kernel.impl.simple.ContentVersionController; 35 import org.infoglue.cms.controllers.kernel.impl.simple.EventController; 36 import org.infoglue.cms.controllers.kernel.impl.simple.PublicationController; 37 import org.infoglue.cms.entities.content.ContentVO; 38 import org.infoglue.cms.entities.content.ContentVersion; 39 import org.infoglue.cms.entities.content.ContentVersionVO; 40 import org.infoglue.cms.entities.publishing.PublicationVO; 41 import org.infoglue.cms.entities.workflow.EventVO; 42 import org.infoglue.cms.exception.AccessConstraintException; 43 import org.infoglue.cms.util.AccessConstraintExceptionBuffer; 44 45 52 53 public class UnpublishContentVersionAction extends InfoGlueAbstractAction 54 { 55 private static final long serialVersionUID = 1L; 56 57 private List contentVersionVOList = new ArrayList (); 58 private List contentVOList = new ArrayList (); 59 private Integer contentId; 60 private Integer repositoryId; 61 62 private List contentVersionId = new ArrayList (); 63 private Integer stateId; 64 private Integer languageId; 65 private String versionComment; 66 private boolean overrideVersionModifyer = false; 67 private String attemptDirectPublishing = "false"; 68 69 70 public String doInput() throws Exception 71 { 72 if(this.contentId != null) 73 { 74 ContentVO contentVO = ContentController.getContentController().getContentVOWithId(this.contentId); 75 this.repositoryId = contentVO.getRepositoryId(); 76 77 AccessConstraintExceptionBuffer ceb = new AccessConstraintExceptionBuffer(); 78 79 Integer protectedContentId = ContentControllerProxy.getController().getProtectedContentId(contentId); 80 if(protectedContentId != null && !AccessRightController.getController().getIsPrincipalAuthorized(this.getInfoGluePrincipal(), "Content.SubmitToPublish", protectedContentId.toString())) 81 ceb.add(new AccessConstraintException("Content.contentId", "1005")); 82 83 ceb.throwIfNotEmpty(); 84 85 contentVersionVOList = ContentVersionController.getContentVersionController().getContentVersionVOWithParentRecursive(contentId, ContentVersionVO.PUBLISHED_STATE, false); 86 } 87 88 return "input"; 89 } 90 91 public String doInputChooseContents() throws Exception 92 { 93 if(this.contentId != null) 94 { 95 ContentVO contentVO = ContentController.getContentController().getContentVOWithId(this.contentId); 96 this.repositoryId = contentVO.getRepositoryId(); 97 98 AccessConstraintExceptionBuffer ceb = new AccessConstraintExceptionBuffer(); 99 100 Integer protectedContentId = ContentControllerProxy.getController().getProtectedContentId(contentId); 101 if(protectedContentId != null && !AccessRightController.getController().getIsPrincipalAuthorized(this.getInfoGluePrincipal(), "Content.SubmitToPublish", protectedContentId.toString())) 102 ceb.add(new AccessConstraintException("Content.contentId", "1005")); 103 104 ceb.throwIfNotEmpty(); 105 106 contentVOList = ContentController.getContentController().getContentVOWithParentRecursive(contentId); 107 } 108 109 return "inputChooseContents"; 110 } 111 112 117 118 public String doExecute() throws Exception  119 { 120 setContentVersionId( getRequest().getParameterValues("sel") ); 121 Iterator it = getContentVersionId().iterator(); 122 123 List events = new ArrayList (); 124 while(it.hasNext()) 125 { 126 Integer contentVersionId = (Integer )it.next(); 127 ContentVersionVO contentVersionVO = ContentVersionController.getContentVersionController().getContentVersionVOWithId(contentVersionId); 129 130 EventVO eventVO = new EventVO(); 131 eventVO.setDescription(this.versionComment); 132 eventVO.setEntityClass(ContentVersion.class.getName()); 133 eventVO.setEntityId(contentVersionId); 134 eventVO.setName(contentVersionVO.getContentName() + "(" + contentVersionVO.getLanguageName() + ")"); 135 eventVO.setTypeId(EventVO.UNPUBLISH_LATEST); 136 eventVO = EventController.create(eventVO, this.repositoryId, this.getInfoGluePrincipal()); 137 events.add(eventVO); 138 } 139 140 if(attemptDirectPublishing.equalsIgnoreCase("true")) 141 { 142 PublicationVO publicationVO = new PublicationVO(); 143 publicationVO.setName("Direct publication by " + this.getInfoGluePrincipal().getName()); 144 publicationVO.setDescription(getVersionComment()); 145 publicationVO.setRepositoryId(repositoryId); 147 publicationVO = PublicationController.getController().createAndPublish(publicationVO, events, this.overrideVersionModifyer, this.getInfoGluePrincipal()); 148 } 149 150 return "success"; 151 } 152 153 154 157 158 public String doUnpublishAll() throws Exception  159 { 160 String [] contentIds = getRequest().getParameterValues("sel"); 161 162 List events = new ArrayList (); 163 164 for(int i=0; i < contentIds.length; i++) 165 { 166 String contentIdString = contentIds[i]; 167 List contentVersionsVOList = ContentVersionController.getContentVersionController().getPublishedActiveContentVersionVOList(new Integer (contentIdString)); 168 169 Iterator it = contentVersionsVOList.iterator(); 170 171 while(it.hasNext()) 172 { 173 ContentVersionVO contentVersionVO = (ContentVersionVO)it.next(); 174 175 EventVO eventVO = new EventVO(); 176 eventVO.setDescription(this.versionComment); 177 eventVO.setEntityClass(ContentVersion.class.getName()); 178 eventVO.setEntityId(contentVersionVO.getContentVersionId()); 179 eventVO.setName(contentVersionVO.getContentName() + "(" + contentVersionVO.getLanguageName() + ")"); 180 eventVO.setTypeId(EventVO.UNPUBLISH_LATEST); 181 eventVO = EventController.create(eventVO, this.repositoryId, this.getInfoGluePrincipal()); 182 events.add(eventVO); 183 } 184 } 185 186 if(attemptDirectPublishing.equalsIgnoreCase("true")) 187 { 188 PublicationVO publicationVO = new PublicationVO(); 189 publicationVO.setName("Direct publication by " + this.getInfoGluePrincipal().getName()); 190 publicationVO.setDescription(getVersionComment()); 191 publicationVO.setRepositoryId(repositoryId); 193 publicationVO = PublicationController.getController().createAndPublish(publicationVO, events, this.overrideVersionModifyer, this.getInfoGluePrincipal()); 194 } 195 196 return "success"; 197 } 198 199 public List getContentVersions() 200 { 201 return this.contentVersionVOList; 202 } 203 204 public List getContents() 205 { 206 return contentVOList; 207 } 208 209 public Integer getContentId() 210 { 211 return contentId; 212 } 213 214 public void setContentId(Integer contentId) 215 { 216 this.contentId = contentId; 217 } 218 219 public Integer getRepositoryId() 220 { 221 return repositoryId; 222 } 223 224 public java.lang.Integer getLanguageId() 225 { 226 return this.languageId; 227 } 228 229 public void setLanguageId(Integer languageId) 230 { 231 this.languageId = languageId; 232 } 233 234 public void setStateId(Integer stateId) 235 { 236 this.stateId = stateId; 237 } 238 239 public void setVersionComment(String versionComment) 240 { 241 this.versionComment = versionComment; 242 } 243 244 public String getVersionComment() 245 { 246 return this.versionComment; 247 } 248 249 public Integer getStateId() 250 { 251 return this.stateId; 252 } 253 254 257 public List getContentVersionId() 258 { 259 return contentVersionId; 260 } 261 262 265 private void setContentVersionId(String [] list) 266 { 267 contentVersionId = new ArrayList (); 268 for(int i=0; i < list.length; i++) 269 { 270 contentVersionId.add(new Integer (list[i])); 271 } 272 } 273 274 public void setAttemptDirectPublishing(String attemptDirectPublishing) 275 { 276 this.attemptDirectPublishing = attemptDirectPublishing; 277 } 278 279 public void setRepositoryId(Integer repositoryId) 280 { 281 this.repositoryId = repositoryId; 282 } 283 284 public boolean getOverrideVersionModifyer() 285 { 286 return overrideVersionModifyer; 287 } 288 289 public void setOverrideVersionModifyer(boolean overrideVersionModifyer) 290 { 291 this.overrideVersionModifyer = overrideVersionModifyer; 292 } 293 } 294 | Popular Tags |