KickJava   Java API By Example, From Geeks To Geeks.

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


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.Collections JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.List JavaDoc;
29
30 import org.apache.log4j.Logger;
31 import org.exolab.castor.jdo.Database;
32 import org.infoglue.cms.applications.common.VisualFormatter;
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.ContentVersionController;
37 import org.infoglue.cms.controllers.kernel.impl.simple.DigitalAssetController;
38 import org.infoglue.cms.controllers.kernel.impl.simple.LanguageController;
39 import org.infoglue.cms.controllers.kernel.impl.simple.PageTemplateController;
40 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeController;
41 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeControllerProxy;
42 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeTypeDefinitionController;
43 import org.infoglue.cms.entities.content.ContentVersionVO;
44 import org.infoglue.cms.entities.content.DigitalAssetVO;
45 import org.infoglue.cms.entities.management.LanguageVO;
46 import org.infoglue.cms.entities.structure.SiteNode;
47 import org.infoglue.cms.entities.structure.SiteNodeVO;
48 import org.infoglue.cms.exception.SystemException;
49 import org.infoglue.cms.util.ConstraintExceptionBuffer;
50 import org.infoglue.cms.util.sorters.ReflectionComparator;
51
52 /**
53  * This action represents the CreateSiteNode Usecase.
54  */

55
56 public class CreateSiteNodeAction extends InfoGlueAbstractAction
57 {
58     private final static Logger logger = Logger.getLogger(CreateSiteNodeAction.class.getName());
59
60     private Integer JavaDoc siteNodeId;
61     private String JavaDoc name;
62     private Boolean JavaDoc isBranch;
63     private Integer JavaDoc parentSiteNodeId;
64     private Integer JavaDoc siteNodeTypeDefinitionId;
65     private Integer JavaDoc pageTemplateContentId;
66     private Integer JavaDoc repositoryId;
67     private ConstraintExceptionBuffer ceb;
68     private SiteNodeVO siteNodeVO;
69     private SiteNodeVO newSiteNodeVO;
70     private String JavaDoc sortProperty = "name";
71   
72     public CreateSiteNodeAction()
73     {
74         this(new SiteNodeVO());
75     }
76     
77     public CreateSiteNodeAction(SiteNodeVO siteNodeVO)
78     {
79         this.siteNodeVO = siteNodeVO;
80         this.ceb = new ConstraintExceptionBuffer();
81     }
82
83     public void setParentSiteNodeId(Integer JavaDoc parentSiteNodeId)
84     {
85         this.parentSiteNodeId = parentSiteNodeId;
86     }
87
88     public Integer JavaDoc getParentSiteNodeId()
89     {
90         return this.parentSiteNodeId;
91     }
92
93     public void setRepositoryId(Integer JavaDoc repositoryId)
94     {
95         this.repositoryId = repositoryId;
96     }
97
98     public Integer JavaDoc getRepositoryId()
99     {
100         return this.repositoryId;
101     }
102
103     public void setSiteNodeTypeDefinitionId(Integer JavaDoc siteNodeTypeDefinitionId)
104     {
105         this.siteNodeTypeDefinitionId = siteNodeTypeDefinitionId;
106     }
107
108     public Integer JavaDoc getSiteNodeTypeDefinitionId()
109     {
110         return this.siteNodeTypeDefinitionId;
111     }
112     
113     public java.lang.String JavaDoc getName()
114     {
115         return this.siteNodeVO.getName();
116     }
117
118     public String JavaDoc getPublishDateTime()
119     {
120         return new VisualFormatter().formatDate(this.siteNodeVO.getPublishDateTime(), "yyyy-MM-dd HH:mm");
121     }
122         
123     public String JavaDoc getExpireDateTime()
124     {
125         return new VisualFormatter().formatDate(this.siteNodeVO.getExpireDateTime(), "yyyy-MM-dd HH:mm");
126     }
127
128     public Boolean JavaDoc getIsBranch()
129     {
130         return this.siteNodeVO.getIsBranch();
131     }
132             
133     public void setName(java.lang.String JavaDoc name)
134     {
135         this.siteNodeVO.setName(name);
136     }
137         
138     public void setPublishDateTime(String JavaDoc publishDateTime)
139     {
140         logger.info("publishDateTime:" + publishDateTime);
141         this.siteNodeVO.setPublishDateTime(new VisualFormatter().parseDate(publishDateTime, "yyyy-MM-dd HH:mm"));
142     }
143
144     public void setExpireDateTime(String JavaDoc expireDateTime)
145     {
146         logger.info("expireDateTime:" + expireDateTime);
147         this.siteNodeVO.setExpireDateTime(new VisualFormatter().parseDate(expireDateTime, "yyyy-MM-dd HH:mm"));
148     }
149  
150     public void setIsBranch(Boolean JavaDoc isBranch)
151     {
152         this.siteNodeVO.setIsBranch(isBranch);
153     }
154      
155     public Integer JavaDoc getSiteNodeId()
156     {
157         return newSiteNodeVO.getSiteNodeId();
158     }
159     
160     public String JavaDoc getSortProperty()
161     {
162         return sortProperty;
163     }
164     
165     /**
166      * This method returns the contents that are of contentTypeDefinition "PageTemplate" sorted on the property given.
167      */

168     
169     public List JavaDoc getSortedPageTemplates(String JavaDoc sortProperty) throws Exception JavaDoc
170     {
171         SiteNodeVO parentSiteNodeVO = SiteNodeController.getController().getSiteNodeVOWithId(this.parentSiteNodeId);
172         LanguageVO masterLanguageVO = LanguageController.getController().getMasterLanguage(parentSiteNodeVO.getRepositoryId());
173
174         List JavaDoc components = PageTemplateController.getController().getPageTemplates(this.getInfoGluePrincipal(), masterLanguageVO.getId());
175         
176         Collections.sort(components, new ReflectionComparator(sortProperty));
177         
178         return components;
179     }
180         
181     
182     /**
183      * This method fetches an url to the asset for the component.
184      */

185     
186     public String JavaDoc getDigitalAssetUrl(Integer JavaDoc contentId, String JavaDoc key) throws Exception JavaDoc
187     {
188         String JavaDoc imageHref = null;
189         try
190         {
191             LanguageVO masterLanguage = LanguageController.getController().getMasterLanguage(ContentController.getContentController().getContentVOWithId(contentId).getRepositoryId());
192             ContentVersionVO contentVersionVO = ContentVersionController.getContentVersionController().getLatestActiveContentVersionVO(contentId, masterLanguage.getId());
193             List JavaDoc digitalAssets = DigitalAssetController.getDigitalAssetVOList(contentVersionVO.getId());
194             Iterator JavaDoc i = digitalAssets.iterator();
195             while(i.hasNext())
196             {
197                 DigitalAssetVO digitalAssetVO = (DigitalAssetVO)i.next();
198                 if(digitalAssetVO.getAssetKey().equals(key))
199                 {
200                     imageHref = DigitalAssetController.getDigitalAssetUrl(digitalAssetVO.getId());
201                     break;
202                 }
203             }
204         }
205         catch(Exception JavaDoc e)
206         {
207             logger.warn("We could not get the url of the digitalAsset: " + e.getMessage(), e);
208             imageHref = e.getMessage();
209         }
210         
211         return imageHref;
212     }
213     
214     /**
215      * This method fetches the list of SiteNodeTypeDefinitions
216      */

217     
218     public List JavaDoc getSiteNodeTypeDefinitions() throws Exception JavaDoc
219     {
220         return SiteNodeTypeDefinitionController.getController().getSiteNodeTypeDefinitionVOList();
221     }
222       
223     public String JavaDoc doExecute() throws Exception JavaDoc
224     {
225         ceb = this.siteNodeVO.validate();
226         ceb.throwIfNotEmpty();
227         
228         logger.info("name:" + this.siteNodeVO.getName());
229         logger.info("publishDateTime:" + this.siteNodeVO.getPublishDateTime());
230         logger.info("expireDateTime:" + this.siteNodeVO.getExpireDateTime());
231         logger.info("isBranch:" + this.siteNodeVO.getIsBranch());
232         
233         Database db = CastorDatabaseService.getDatabase();
234         ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer();
235
236         beginTransaction(db);
237
238         try
239         {
240             SiteNode newSiteNode = SiteNodeControllerProxy.getSiteNodeControllerProxy().acCreate(this.getInfoGluePrincipal(), this.parentSiteNodeId, this.siteNodeTypeDefinitionId, this.repositoryId, this.siteNodeVO, db);
241             newSiteNodeVO = newSiteNode.getValueObject();
242             
243             SiteNodeController.getController().createSiteNodeMetaInfoContent(db, newSiteNode, this.repositoryId, this.getInfoGluePrincipal(), this.pageTemplateContentId);
244             
245             commitTransaction(db);
246         }
247         catch(Exception JavaDoc e)
248         {
249             logger.error("An error occurred so we should not completes the transaction:" + e, e);
250             rollbackTransaction(db);
251             throw new SystemException(e.getMessage());
252         }
253         
254         return "success";
255     }
256
257
258     public String JavaDoc doInput() throws Exception JavaDoc
259     {
260         return "input";
261     }
262         
263     public Integer JavaDoc getPageTemplateContentId()
264     {
265         return pageTemplateContentId;
266     }
267     
268     public void setPageTemplateContentId(Integer JavaDoc pageTemplateContentId)
269     {
270         this.pageTemplateContentId = pageTemplateContentId;
271     }
272 }
273
Popular Tags