1 23 24 package org.infoglue.cms.applications.structuretool.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.EventController; 33 import org.infoglue.cms.controllers.kernel.impl.simple.PublicationController; 34 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeController; 35 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeVersionController; 36 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeVersionControllerProxy; 37 import org.infoglue.cms.entities.content.ContentVersion; 38 import org.infoglue.cms.entities.content.ContentVersionVO; 39 import org.infoglue.cms.entities.publishing.PublicationVO; 40 import org.infoglue.cms.entities.structure.SiteNodeVO; 41 import org.infoglue.cms.entities.structure.SiteNodeVersion; 42 import org.infoglue.cms.entities.structure.SiteNodeVersionVO; 43 import org.infoglue.cms.entities.workflow.EventVO; 44 import org.infoglue.cms.exception.AccessConstraintException; 45 import org.infoglue.cms.util.AccessConstraintExceptionBuffer; 46 47 54 55 public class UnpublishSiteNodeVersionAction extends InfoGlueAbstractAction 56 { 57 58 private List siteNodeVersionVOList = new ArrayList (); 59 private List siteNodeVOList = new ArrayList (); 60 private Integer siteNodeId; 61 private Integer siteNodeVersionId; 62 private Integer repositoryId; 63 64 private List siteNodeVersionIdList = new ArrayList (); 65 private Integer stateId; 66 private Integer languageId; 67 private String versionComment; 68 private String attemptDirectPublishing = "false"; 69 70 71 public String doInput() throws Exception 72 { 73 if(this.siteNodeId != null) 74 { 75 SiteNodeVO siteNodeVO = SiteNodeController.getController().getSiteNodeVOWithId(this.siteNodeId); 76 this.repositoryId = siteNodeVO.getRepositoryId(); 77 78 AccessConstraintExceptionBuffer ceb = new AccessConstraintExceptionBuffer(); 79 80 Integer protectedSiteNodeVersionId = SiteNodeVersionControllerProxy.getSiteNodeVersionControllerProxy().getProtectedSiteNodeVersionId(siteNodeVersionId); 81 if(protectedSiteNodeVersionId != null && !AccessRightController.getController().getIsPrincipalAuthorized(this.getInfoGluePrincipal(), "SiteNodeVersion.SubmitToPublish", protectedSiteNodeVersionId.toString())) 82 ceb.add(new AccessConstraintException("SiteNodeVersion.siteNodeId", "1005")); 83 84 ceb.throwIfNotEmpty(); 85 86 siteNodeVersionVOList = SiteNodeVersionController.getController().getPublishedSiteNodeVersionVOWithParentRecursive(siteNodeId); 88 } 89 90 return "input"; 91 } 92 93 public String doInputChooseSiteNodes() throws Exception 94 { 95 if(this.siteNodeId != null) 96 { 97 SiteNodeVO siteNodeVO = SiteNodeController.getController().getSiteNodeVOWithId(this.siteNodeId); 98 this.repositoryId = siteNodeVO.getRepositoryId(); 99 100 AccessConstraintExceptionBuffer ceb = new AccessConstraintExceptionBuffer(); 101 102 Integer protectedSiteNodeVersionId = SiteNodeVersionControllerProxy.getSiteNodeVersionControllerProxy().getProtectedSiteNodeVersionId(siteNodeVersionId); 103 if(protectedSiteNodeVersionId != null && !AccessRightController.getController().getIsPrincipalAuthorized(this.getInfoGluePrincipal(), "SiteNodeVersion.SubmitToPublish", protectedSiteNodeVersionId.toString())) 104 ceb.add(new AccessConstraintException("SiteNodeVersion.siteNodeId", "1005")); 105 106 ceb.throwIfNotEmpty(); 107 108 siteNodeVOList = SiteNodeController.getController().getSiteNodeVOWithParentRecursive(siteNodeId); 109 } 110 111 return "inputChooseSiteNodes"; 112 } 113 114 119 120 public String doExecute() throws Exception 121 { 122 setSiteNodeVersionIdList( getRequest().getParameterValues("sel") ); 123 Iterator it = getSiteNodeVersionIdList().iterator(); 124 125 List events = new ArrayList (); 126 while(it.hasNext()) 127 { 128 Integer siteNodeVersionId = (Integer )it.next(); 129 SiteNodeVersionVO siteNodeVersionVO = SiteNodeVersionController.getController().getSiteNodeVersionVOWithId(siteNodeVersionId); 131 132 EventVO eventVO = new EventVO(); 133 eventVO.setDescription(this.versionComment); 134 eventVO.setEntityClass(SiteNodeVersion.class.getName()); 135 eventVO.setEntityId(siteNodeVersionId); 136 eventVO.setName(siteNodeVersionVO.getSiteNodeName()); 137 eventVO.setTypeId(EventVO.UNPUBLISH_LATEST); 138 eventVO = EventController.create(eventVO, this.repositoryId, this.getInfoGluePrincipal()); 139 events.add(eventVO); 140 141 List contentVersionVOList = SiteNodeVersionController.getController().getMetaInfoContentVersionVOList(siteNodeVersionId, this.getInfoGluePrincipal()); 142 Iterator contentVersionVOListIterator = contentVersionVOList.iterator(); 143 while(contentVersionVOListIterator.hasNext()) 144 { 145 ContentVersionVO currentContentVersionVO = (ContentVersionVO)contentVersionVOListIterator.next(); 146 EventVO versionEventVO = new EventVO(); 147 versionEventVO.setDescription(this.versionComment); 148 versionEventVO.setEntityClass(ContentVersion.class.getName()); 149 versionEventVO.setEntityId(currentContentVersionVO.getId()); 150 versionEventVO.setName(currentContentVersionVO.getContentName()); 151 versionEventVO.setTypeId(EventVO.UNPUBLISH_LATEST); 152 versionEventVO = EventController.create(versionEventVO, this.repositoryId, this.getInfoGluePrincipal()); 153 events.add(versionEventVO); 154 } 155 } 156 157 if(attemptDirectPublishing.equalsIgnoreCase("true")) 158 { 159 PublicationVO publicationVO = new PublicationVO(); 160 publicationVO.setName("Direct publication by " + this.getInfoGluePrincipal().getName()); 161 publicationVO.setDescription(getVersionComment()); 162 publicationVO.setRepositoryId(repositoryId); 164 publicationVO = PublicationController.getController().createAndPublish(publicationVO, events, false, this.getInfoGluePrincipal()); 165 } 166 167 return "success"; 168 } 169 170 173 174 public String doUnpublishAll() throws Exception 175 { 176 String [] siteNodeIds = getRequest().getParameterValues("sel"); 177 178 List events = new ArrayList (); 179 180 for(int i=0; i < siteNodeIds.length; i++) 181 { 182 String siteNodeIdString = siteNodeIds[i]; 183 List siteNodeVersionVOList = SiteNodeVersionController.getController().getPublishedActiveSiteNodeVersionVOList(new Integer (siteNodeIdString)); 184 185 Iterator it = siteNodeVersionVOList.iterator(); 186 187 while(it.hasNext()) 188 { 189 SiteNodeVersionVO siteNodeVersionVO = (SiteNodeVersionVO)it.next(); 190 191 EventVO eventVO = new EventVO(); 192 eventVO.setDescription(this.versionComment); 193 eventVO.setEntityClass(SiteNodeVersion.class.getName()); 194 eventVO.setEntityId(siteNodeVersionVO.getId()); 195 eventVO.setName(siteNodeVersionVO.getSiteNodeName()); 196 eventVO.setTypeId(EventVO.UNPUBLISH_LATEST); 197 eventVO = EventController.create(eventVO, this.repositoryId, this.getInfoGluePrincipal()); 198 events.add(eventVO); 199 200 List contentVersionVOList = SiteNodeVersionController.getController().getMetaInfoContentVersionVOList(siteNodeVersionVO.getId(), this.getInfoGluePrincipal()); 201 Iterator contentVersionVOListIterator = contentVersionVOList.iterator(); 202 while(contentVersionVOListIterator.hasNext()) 203 { 204 ContentVersionVO currentContentVersionVO = (ContentVersionVO)contentVersionVOListIterator.next(); 205 EventVO versionEventVO = new EventVO(); 206 versionEventVO.setDescription(this.versionComment); 207 versionEventVO.setEntityClass(ContentVersion.class.getName()); 208 versionEventVO.setEntityId(currentContentVersionVO.getId()); 209 versionEventVO.setName(currentContentVersionVO.getContentName()); 210 versionEventVO.setTypeId(EventVO.UNPUBLISH_LATEST); 211 versionEventVO = EventController.create(versionEventVO, this.repositoryId, this.getInfoGluePrincipal()); 212 events.add(versionEventVO); 213 } 214 } 215 } 216 217 if(attemptDirectPublishing.equalsIgnoreCase("true")) 218 { 219 PublicationVO publicationVO = new PublicationVO(); 220 publicationVO.setName("Direct publication by " + this.getInfoGluePrincipal().getName()); 221 publicationVO.setDescription(getVersionComment()); 222 publicationVO.setRepositoryId(repositoryId); 224 publicationVO = PublicationController.getController().createAndPublish(publicationVO, events, false, this.getInfoGluePrincipal()); 225 } 226 227 return "success"; 228 } 229 230 231 public List getSiteNodeVersions() 232 { 233 return this.siteNodeVersionVOList; 234 } 235 236 public List getSiteNodes() 237 { 238 return this.siteNodeVOList; 239 } 240 241 public Integer getSiteNodeId() 242 { 243 return siteNodeId; 244 } 245 246 public void setSiteNodeId(Integer siteNodeId) 247 { 248 this.siteNodeId = siteNodeId; 249 } 250 251 public Integer getRepositoryId() 252 { 253 return repositoryId; 254 } 255 256 public java.lang.Integer getLanguageId() 257 { 258 return this.languageId; 259 } 260 261 public void setLanguageId(Integer languageId) 262 { 263 this.languageId = languageId; 264 } 265 266 public void setStateId(Integer stateId) 267 { 268 this.stateId = stateId; 269 } 270 271 public void setVersionComment(String versionComment) 272 { 273 this.versionComment = versionComment; 274 } 275 276 public String getVersionComment() 277 { 278 return this.versionComment; 279 } 280 281 public Integer getStateId() 282 { 283 return this.stateId; 284 } 285 286 289 public List getSiteNodeVersionIdList() 290 { 291 return siteNodeVersionIdList; 292 } 293 294 297 private void setSiteNodeVersionIdList(String [] list) 298 { 299 if(list != null) 300 { 301 for(int i=0; i < list.length; i++) 302 { 303 siteNodeVersionIdList.add(new Integer (list[i])); 304 } 305 } 306 } 307 308 public void setAttemptDirectPublishing(String attemptDirectPublishing) 309 { 310 this.attemptDirectPublishing = attemptDirectPublishing; 311 } 312 313 public void setRepositoryId(Integer repositoryId) 314 { 315 this.repositoryId = repositoryId; 316 } 317 318 public Integer getSiteNodeVersionId() 319 { 320 return siteNodeVersionId; 321 } 322 323 public void setSiteNodeVersionId(Integer siteNodeVersionId) 324 { 325 this.siteNodeVersionId = siteNodeVersionId; 326 } 327 } 328 | Popular Tags |