KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content 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.HashMap JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.Map JavaDoc;
30
31 import org.apache.log4j.Logger;
32 import org.exolab.castor.jdo.Database;
33 import org.infoglue.cms.applications.common.actions.InfoGlueAbstractAction;
34 import org.infoglue.cms.controllers.kernel.impl.simple.CastorDatabaseService;
35 import org.infoglue.cms.controllers.kernel.impl.simple.ContentController;
36 import org.infoglue.cms.controllers.kernel.impl.simple.ContentTypeDefinitionController;
37 import org.infoglue.cms.controllers.kernel.impl.simple.LanguageController;
38 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeController;
39 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeStateController;
40 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeVersionController;
41 import org.infoglue.cms.entities.content.Content;
42 import org.infoglue.cms.entities.content.ContentVO;
43 import org.infoglue.cms.entities.management.ContentTypeDefinition;
44 import org.infoglue.cms.entities.management.Language;
45 import org.infoglue.cms.entities.management.LanguageVO;
46 import org.infoglue.cms.entities.management.ServiceDefinitionVO;
47 import org.infoglue.cms.entities.structure.SiteNode;
48 import org.infoglue.cms.entities.structure.SiteNodeVersion;
49 import org.infoglue.cms.entities.structure.SiteNodeVersionVO;
50 import org.infoglue.cms.exception.SystemException;
51 import org.infoglue.cms.util.ConstraintExceptionBuffer;
52
53 import com.opensymphony.module.propertyset.PropertySet;
54 import com.opensymphony.module.propertyset.PropertySetManager;
55
56 /**
57  * This action first checks if there is a bound content linked - if not one is created in a special folder.
58  * The content is then shown to the user for editing.
59  */

60
61 public class ViewAndCreateContentForServiceBindingAction extends InfoGlueAbstractAction
62 {
63     private final static Logger logger = Logger.getLogger(ViewAndCreateContentForServiceBindingAction.class.getName());
64
65     private Integer JavaDoc siteNodeVersionId;
66     private Integer JavaDoc repositoryId;
67     //private Integer availableServiceBindingId;
68
private Integer JavaDoc serviceDefinitionId;
69     private Integer JavaDoc bindingTypeId;
70     private ConstraintExceptionBuffer ceb;
71     private Integer JavaDoc siteNodeId;
72     private ServiceDefinitionVO singleServiceDefinitionVO;
73     //private String qualifyerXML;
74
private String JavaDoc tree;
75     private List JavaDoc repositories;
76     private ContentVO contentVO = new ContentVO();
77     private Integer JavaDoc languageId = null;
78     private Integer JavaDoc metaInfoContentTypeDefinitionId = null;
79     private String JavaDoc changeStateToWorking = null;
80     
81     //private ServiceBindingVO serviceBindingVO = null;
82

83   /*
84     public ViewAndCreateContentForServiceBindingAction()
85     {
86         this(new ServiceBindingVO());
87     }
88     
89     public ViewAndCreateContentForServiceBindingAction(ServiceBindingVO serviceBindingVO)
90     {
91         this.serviceBindingVO = serviceBindingVO;
92         this.ceb = new ConstraintExceptionBuffer();
93     }
94     */

95     
96     public void setSiteNodeVersionId(Integer JavaDoc siteNodeVersionId)
97     {
98         this.siteNodeVersionId = siteNodeVersionId;
99     }
100
101     public void setRepositoryId(Integer JavaDoc repositoryId)
102     {
103         this.repositoryId = repositoryId;
104     }
105
106     /*
107     public void setAvailableServiceBindingId(Integer availableServiceBindingId)
108     {
109         this.availableServiceBindingId = availableServiceBindingId;
110     }
111     */

112
113     public void setServiceDefinitionId(Integer JavaDoc serviceDefinitionId)
114     {
115         this.serviceDefinitionId = serviceDefinitionId;
116     }
117 /*
118     public void setBindingTypeId(Integer bindingTypeId)
119     {
120         this.serviceBindingVO.setBindingTypeId(bindingTypeId);
121     }
122
123     public void setPath(String path)
124     {
125         this.serviceBindingVO.setPath(path);
126     }
127 */

128     public Integer JavaDoc getSiteNodeVersionId()
129     {
130         return this.siteNodeVersionId;
131     }
132
133     public void setSiteNodeId(Integer JavaDoc siteNodeId)
134     {
135         this.siteNodeId = siteNodeId;
136     }
137
138     public Integer JavaDoc getSiteNodeId()
139     {
140         return this.siteNodeId;
141     }
142         
143     public Integer JavaDoc getRepositoryId()
144     {
145         return this.repositoryId;
146     }
147
148     /*
149     public Integer getAvailableServiceBindingId()
150     {
151         return this.availableServiceBindingId;
152     }
153     */

154     
155     public Integer JavaDoc getServiceDefinitionId()
156     {
157         return this.singleServiceDefinitionVO.getServiceDefinitionId();
158     }
159     
160     public Integer JavaDoc getBindingTypeId()
161     {
162         return this.bindingTypeId;
163     }
164
165     /*
166     public void setServiceBindingId(Integer serviceBindingId)
167     {
168         this.serviceBindingVO.setServiceBindingId(serviceBindingId);
169     }
170 */

171     public ServiceDefinitionVO getSingleServiceDefinitionVO()
172     {
173         return this.singleServiceDefinitionVO;
174     }
175     
176     public String JavaDoc getTree()
177     {
178         return tree;
179     }
180
181     public void setTree(String JavaDoc string)
182     {
183         tree = string;
184     }
185     
186     public String JavaDoc getCurrentAction()
187     {
188         return "ViewAndCreateContentForServiceBinding.action";
189     }
190     
191     /**
192      * We first checks if there is a bound content linked - if not one is created in a special folder and
193      * a new service binding is created to it. The content is then shown to the user for editing. Most of this method should
194      * be moved to an controller.
195      */

196     
197     public String JavaDoc doExecute() throws Exception JavaDoc
198     {
199         Database db = CastorDatabaseService.getDatabase();
200         ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer();
201
202         beginTransaction(db);
203
204         try
205         {
206             Language masterLanguage = LanguageController.getController().getMasterLanguage(db, this.repositoryId);
207             this.languageId = masterLanguage.getLanguageId();
208
209             ContentTypeDefinition contentTypeDefinition = ContentTypeDefinitionController.getController().getContentTypeDefinitionWithName("Meta info", db);
210             this.metaInfoContentTypeDefinitionId = contentTypeDefinition.getId();
211             
212             SiteNode siteNode = SiteNodeController.getController().getSiteNodeWithId(this.siteNodeId, db);
213
214             if(this.changeStateToWorking != null && this.changeStateToWorking.equalsIgnoreCase("true"))
215             {
216                 SiteNodeVersion siteNodeVersion = SiteNodeVersionController.getController().getLatestActiveSiteNodeVersion(db, this.siteNodeId);
217                 if(!siteNodeVersion.getStateId().equals(SiteNodeVersionVO.WORKING_STATE))
218                 {
219                     List JavaDoc events = new ArrayList JavaDoc();
220                     SiteNodeStateController.getController().changeState(siteNodeVersion.getId(), SiteNodeVersionVO.WORKING_STATE, "Auto", true, this.getInfoGluePrincipal(), this.siteNodeId, db, events);
221                 }
222             }
223             
224             Content metaInfoContent = null;
225             if(siteNode.getMetaInfoContentId() != null && siteNode.getMetaInfoContentId().intValue() > -1)
226                 metaInfoContent = ContentController.getContentController().getContentWithId(siteNode.getMetaInfoContentId(), db);
227             
228             if(metaInfoContent == null)
229             {
230                 throw new Exception JavaDoc("The site node must have a meta information bound. Please run the appropriate scripts");
231             }
232             else
233             {
234                 this.contentVO = metaInfoContent.getValueObject();
235             }
236
237                 /*
238                 boolean hadMetaInfo = false;
239                 if(this.serviceBindingVO.getId() == null)
240                 {
241                     AvailableServiceBinding availableServiceBinding = AvailableServiceBindingController.getController().getAvailableServiceBindingWithName("Meta information", db, false);
242                     
243                     Collection serviceBindings = SiteNodeVersionController.getServiceBindningList(this.siteNodeVersionId, db);
244                     Iterator serviceBindingIterator = serviceBindings.iterator();
245                     while(serviceBindingIterator.hasNext())
246                     {
247                         ServiceBinding serviceBinding = (ServiceBinding)serviceBindingIterator.next();
248                         if(serviceBinding.getValueObject().getAvailableServiceBindingId().intValue() == availableServiceBinding.getAvailableServiceBindingId().intValue())
249                         {
250                             List boundContents = ContentController.getBoundContents(db, serviceBinding.getServiceBindingId());
251                             if(boundContents.size() > 0)
252                             {
253                                 this.contentVO = (ContentVO)boundContents.get(0);
254                                 hadMetaInfo = true;
255                                 if(siteNode.getMetaInfoContentId() == null || siteNode.getMetaInfoContentId().intValue() == -1)
256                                     siteNode.setMetaInfoContentId(this.contentVO.getId());
257                                 
258                                 break;
259                             }
260                         }
261                     }
262     
263                     if(!hadMetaInfo)
264                         this.contentVO = SiteNodeController.getController().createSiteNodeMetaInfoContent(db, siteNode, this.repositoryId, this.getInfoGluePrincipal(), null).getValueObject();
265                 }
266                 else
267                 {
268                     List boundContents = ContentController.getBoundContents(this.serviceBindingVO.getId());
269                     
270                     if(boundContents.size() > 0)
271                     {
272                         this.contentVO = (ContentVO)boundContents.get(0);
273                         if(siteNode.getMetaInfoContentId() == null || siteNode.getMetaInfoContentId().intValue() == -1)
274                             siteNode.setMetaInfoContentId(this.contentVO.getId());
275                     }
276                     else
277                     {
278                         //Something is broken.... lets try to patch it up by assigning what it should be.
279                         this.contentVO = SiteNodeController.getController().createSiteNodeMetaInfoContent(db, siteNode, this.repositoryId, this.getInfoGluePrincipal(), null).getValueObject();
280                     }
281                 }
282             }
283             else
284             {
285                 this.contentVO = metaInfoContent.getValueObject();
286             }
287             */

288             
289             this.languageId = getInitialLanguageVO(this.contentVO.getId()).getId();
290             
291             commitTransaction(db);
292         }
293         catch(Exception JavaDoc e)
294         {
295             logger.error("An error occurred so we should not completes the transaction:" + e, e);
296             rollbackTransaction(db);
297             throw new SystemException(e.getMessage());
298         }
299         
300         return "success";
301     }
302        
303     public LanguageVO getInitialLanguageVO(Integer JavaDoc contentId) throws Exception JavaDoc
304     {
305         Map JavaDoc args = new HashMap JavaDoc();
306         args.put("globalKey", "infoglue");
307         PropertySet ps = PropertySetManager.getInstance("jdbc", args);
308
309         String JavaDoc initialLanguageId = ps.getString("content_" + contentId + "_initialLanguageId");
310         ContentVO parentContentVO = ContentController.getContentController().getParentContent(contentId);
311         while((initialLanguageId == null || initialLanguageId.equalsIgnoreCase("-1")) && parentContentVO != null)
312         {
313             initialLanguageId = ps.getString("content_" + parentContentVO.getId() + "_initialLanguageId");
314             parentContentVO = ContentController.getContentController().getParentContent(parentContentVO.getId());
315         }
316         
317         if(initialLanguageId != null && !initialLanguageId.equals("") && !initialLanguageId.equals("-1"))
318             return LanguageController.getController().getLanguageVOWithId(new Integer JavaDoc(initialLanguageId));
319         else
320             return LanguageController.getController().getMasterLanguage(repositoryId);
321     }
322
323     public List JavaDoc getRepositories()
324     {
325         return repositories;
326     }
327     
328     public Integer JavaDoc getContentId()
329     {
330         return this.contentVO.getId();
331     }
332     
333     public Integer JavaDoc getLanguageId()
334     {
335         return this.languageId;
336     }
337
338     public String JavaDoc getChangeStateToWorking()
339     {
340         return changeStateToWorking;
341     }
342
343     public void setChangeStateToWorking(String JavaDoc changeStateToWorking)
344     {
345         this.changeStateToWorking = changeStateToWorking;
346     }
347 }
348
Popular Tags