KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > applications > structuretool > actions > UnpublishSiteNodeVersionAction


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue SiteNode Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23
24 package org.infoglue.cms.applications.structuretool.actions;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.List JavaDoc;
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 /**
48  *
49  * @author Mattias Bogeblad
50  *
51  * Present a list of siteNodeVersion under a given siteNode, recursing down in the hierarcy
52  *
53  */

54
55 public class UnpublishSiteNodeVersionAction extends InfoGlueAbstractAction
56 {
57
58     private List JavaDoc siteNodeVersionVOList = new ArrayList JavaDoc();
59     private List JavaDoc siteNodeVOList = new ArrayList JavaDoc();
60     private Integer JavaDoc siteNodeId;
61     private Integer JavaDoc siteNodeVersionId;
62     private Integer JavaDoc repositoryId;
63
64     private List JavaDoc siteNodeVersionIdList = new ArrayList JavaDoc();
65     private Integer JavaDoc stateId;
66     private Integer JavaDoc languageId;
67     private String JavaDoc versionComment;
68     private String JavaDoc attemptDirectPublishing = "false";
69
70     
71     public String JavaDoc doInput() throws Exception JavaDoc
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 JavaDoc 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().getSiteNodeVersionVOWithParentRecursive(siteNodeId, SiteNodeVersionVO.PUBLISHED_STATE);
87
siteNodeVersionVOList = SiteNodeVersionController.getController().getPublishedSiteNodeVersionVOWithParentRecursive(siteNodeId);
88         }
89
90         return "input";
91     }
92     
93     public String JavaDoc doInputChooseSiteNodes() throws Exception JavaDoc
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 JavaDoc 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     /**
115      * This method gets called when calling this action.
116      * If the stateId is 2 which equals that the user tries to prepublish the page. If so we
117      * ask the user for a comment as this is to be regarded as a new version.
118      */

119        
120     public String JavaDoc doExecute() throws Exception JavaDoc
121     {
122         setSiteNodeVersionIdList( getRequest().getParameterValues("sel") );
123         Iterator JavaDoc it = getSiteNodeVersionIdList().iterator();
124         
125         List JavaDoc events = new ArrayList JavaDoc();
126         while(it.hasNext())
127         {
128             Integer JavaDoc siteNodeVersionId = (Integer JavaDoc)it.next();
129             //SiteNodeVersion siteNodeVersion = SiteNodeStateController.changeState((Integer) it.next(), SiteNodeVersionVO.PUBLISH_STATE, getVersionComment(), this.getInfoGluePrincipal(), null, events);
130
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 JavaDoc contentVersionVOList = SiteNodeVersionController.getController().getMetaInfoContentVersionVOList(siteNodeVersionId, this.getInfoGluePrincipal());
142             Iterator JavaDoc 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.setPublisher(this.getInfoGluePrincipal().getName());
163
publicationVO.setRepositoryId(repositoryId);
164             publicationVO = PublicationController.getController().createAndPublish(publicationVO, events, false, this.getInfoGluePrincipal());
165         }
166         
167         return "success";
168     }
169
170     /**
171      * This method will try to unpublish all liver versions of this sitenode.
172      */

173        
174     public String JavaDoc doUnpublishAll() throws Exception JavaDoc
175     {
176         String JavaDoc[] siteNodeIds = getRequest().getParameterValues("sel");
177
178         List JavaDoc events = new ArrayList JavaDoc();
179
180         for(int i=0; i < siteNodeIds.length; i++)
181         {
182             String JavaDoc siteNodeIdString = siteNodeIds[i];
183             List JavaDoc siteNodeVersionVOList = SiteNodeVersionController.getController().getPublishedActiveSiteNodeVersionVOList(new Integer JavaDoc(siteNodeIdString));
184             
185             Iterator JavaDoc 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 JavaDoc contentVersionVOList = SiteNodeVersionController.getController().getMetaInfoContentVersionVOList(siteNodeVersionVO.getId(), this.getInfoGluePrincipal());
201                 Iterator JavaDoc 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.setPublisher(this.getInfoGluePrincipal().getName());
223
publicationVO.setRepositoryId(repositoryId);
224             publicationVO = PublicationController.getController().createAndPublish(publicationVO, events, false, this.getInfoGluePrincipal());
225         }
226         
227         return "success";
228     }
229
230
231     public List JavaDoc getSiteNodeVersions()
232     {
233         return this.siteNodeVersionVOList;
234     }
235
236     public List JavaDoc getSiteNodes()
237     {
238         return this.siteNodeVOList;
239     }
240
241     public Integer JavaDoc getSiteNodeId()
242     {
243         return siteNodeId;
244     }
245
246     public void setSiteNodeId(Integer JavaDoc siteNodeId)
247     {
248         this.siteNodeId = siteNodeId;
249     }
250
251     public Integer JavaDoc getRepositoryId()
252     {
253         return repositoryId;
254     }
255     
256     public java.lang.Integer JavaDoc getLanguageId()
257     {
258         return this.languageId;
259     }
260         
261     public void setLanguageId(Integer JavaDoc languageId)
262     {
263         this.languageId = languageId;
264     }
265                     
266     public void setStateId(Integer JavaDoc stateId)
267     {
268         this.stateId = stateId;
269     }
270
271     public void setVersionComment(String JavaDoc versionComment)
272     {
273         this.versionComment = versionComment;
274     }
275     
276     public String JavaDoc getVersionComment()
277     {
278         return this.versionComment;
279     }
280     
281     public Integer JavaDoc getStateId()
282     {
283         return this.stateId;
284     }
285             
286     /**
287      * @return
288      */

289     public List JavaDoc getSiteNodeVersionIdList()
290     {
291         return siteNodeVersionIdList;
292     }
293
294     /**
295      * @param list
296      */

297     private void setSiteNodeVersionIdList(String JavaDoc[] list)
298     {
299         if(list != null)
300         {
301             for(int i=0; i < list.length; i++)
302             {
303                 siteNodeVersionIdList.add(new Integer JavaDoc(list[i]));
304             }
305         }
306     }
307
308     public void setAttemptDirectPublishing(String JavaDoc attemptDirectPublishing)
309     {
310         this.attemptDirectPublishing = attemptDirectPublishing;
311     }
312     
313     public void setRepositoryId(Integer JavaDoc repositoryId)
314     {
315         this.repositoryId = repositoryId;
316     }
317     
318     public Integer JavaDoc getSiteNodeVersionId()
319     {
320         return siteNodeVersionId;
321     }
322     
323     public void setSiteNodeVersionId(Integer JavaDoc siteNodeVersionId)
324     {
325         this.siteNodeVersionId = siteNodeVersionId;
326     }
327 }
328
Popular Tags