KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > controllers > usecases > structuretool > impl > simple > UpdateSiteNodeUCCImpl


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.controllers.usecases.structuretool.impl.simple;
25
26 import org.apache.log4j.Logger;
27 import org.exolab.castor.jdo.Database;
28 import org.infoglue.cms.controllers.kernel.impl.simple.BaseUCCController;
29 import org.infoglue.cms.controllers.kernel.impl.simple.CastorDatabaseService;
30 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeController;
31 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeTypeDefinitionController;
32 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeVersionController;
33 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeVersionControllerProxy;
34 import org.infoglue.cms.controllers.usecases.structuretool.UpdateSiteNodeUCC;
35 import org.infoglue.cms.entities.management.impl.simple.SiteNodeTypeDefinitionImpl;
36 import org.infoglue.cms.entities.structure.SiteNode;
37 import org.infoglue.cms.entities.structure.SiteNodeVO;
38 import org.infoglue.cms.entities.structure.SiteNodeVersionVO;
39 import org.infoglue.cms.exception.AccessConstraintException;
40 import org.infoglue.cms.exception.ConstraintException;
41 import org.infoglue.cms.exception.SystemException;
42 import org.infoglue.cms.security.InfoGluePrincipal;
43 import org.infoglue.cms.util.ConstraintExceptionBuffer;
44 import org.infoglue.cms.util.DateHelper;
45
46 public class UpdateSiteNodeUCCImpl extends BaseUCCController implements UpdateSiteNodeUCC
47 {
48     private final static Logger logger = Logger.getLogger(UpdateSiteNodeUCCImpl.class.getName());
49
50     public SiteNodeVO updateSiteNode(InfoGluePrincipal infoGluePrincipal, SiteNodeVO siteNodeVO, SiteNodeVersionVO updatedSiteNodeVersionVO) throws ConstraintException, SystemException
51     {
52         Database db = CastorDatabaseService.getDatabase();
53         ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer();
54
55         SiteNode siteNode = null;
56
57         beginTransaction(db);
58
59         try
60         {
61             //add validation here if needed
62
siteNode = SiteNodeController.getController().getSiteNodeWithId(siteNodeVO.getSiteNodeId(), db);
63             siteNode.setValueObject(siteNodeVO);
64
65             SiteNodeVersionVO latestSiteNodeVersionVO = SiteNodeVersionController.getController().getLatestSiteNodeVersion(db, siteNodeVO.getSiteNodeId(), false).getValueObject();
66             latestSiteNodeVersionVO.setContentType(updatedSiteNodeVersionVO.getContentType());
67             latestSiteNodeVersionVO.setPageCacheKey(updatedSiteNodeVersionVO.getPageCacheKey());
68             latestSiteNodeVersionVO.setDisableEditOnSight(updatedSiteNodeVersionVO.getDisableEditOnSight());
69             latestSiteNodeVersionVO.setDisablePageCache(updatedSiteNodeVersionVO.getDisablePageCache());
70             latestSiteNodeVersionVO.setDisableLanguages(updatedSiteNodeVersionVO.getDisableLanguages());
71             latestSiteNodeVersionVO.setIsProtected(updatedSiteNodeVersionVO.getIsProtected());
72             latestSiteNodeVersionVO.setVersionModifier(updatedSiteNodeVersionVO.getVersionModifier());
73             latestSiteNodeVersionVO.setModifiedDateTime(DateHelper.getSecondPreciseDate());
74             
75             SiteNodeVersionControllerProxy.getSiteNodeVersionControllerProxy().acUpdate(infoGluePrincipal, latestSiteNodeVersionVO, db);
76
77             //If any of the validations or setMethods reported an error, we throw them up now before create.
78
ceb.throwIfNotEmpty();
79             
80             commitTransaction(db);
81         }
82         catch(ConstraintException ce)
83         {
84             logger.warn("An error occurred so we should not complete the transaction:" + ce, ce);
85             rollbackTransaction(db);
86             throw ce;
87         }
88         catch(Exception JavaDoc e)
89         {
90             logger.error("An error occurred so we should not complete the transaction:" + e, e);
91             rollbackTransaction(db);
92             throw new SystemException(e.getMessage());
93         }
94
95
96         return siteNode.getValueObject();
97     }
98
99     public SiteNodeVO updateSiteNode(InfoGluePrincipal infoGluePrincipal, SiteNodeVO siteNodeVO, Integer JavaDoc siteNodeTypeDefinitionId, SiteNodeVersionVO updatedSiteNodeVersionVO) throws AccessConstraintException, ConstraintException, SystemException
100     {
101         Database db = CastorDatabaseService.getDatabase();
102         ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer();
103
104         SiteNode siteNode = null;
105
106         beginTransaction(db);
107
108         try
109         {
110             //add validation here if needed
111
siteNode = SiteNodeController.getController().getSiteNodeWithId(siteNodeVO.getSiteNodeId(), db);
112             siteNode.setValueObject(siteNodeVO);
113             
114             if(siteNodeTypeDefinitionId != null)
115                 siteNode.setSiteNodeTypeDefinition((SiteNodeTypeDefinitionImpl)SiteNodeTypeDefinitionController.getController().getSiteNodeTypeDefinitionWithId(siteNodeTypeDefinitionId, db));
116
117             
118             SiteNodeVersionVO latestSiteNodeVersionVO = SiteNodeVersionController.getController().getLatestActiveSiteNodeVersion(db, siteNodeVO.getSiteNodeId()).getValueObject();
119             
120             latestSiteNodeVersionVO.setContentType(updatedSiteNodeVersionVO.getContentType());
121             latestSiteNodeVersionVO.setPageCacheKey(updatedSiteNodeVersionVO.getPageCacheKey());
122             latestSiteNodeVersionVO.setDisableEditOnSight(updatedSiteNodeVersionVO.getDisableEditOnSight());
123             latestSiteNodeVersionVO.setDisableLanguages(updatedSiteNodeVersionVO.getDisableLanguages());
124             latestSiteNodeVersionVO.setDisablePageCache(updatedSiteNodeVersionVO.getDisablePageCache());
125             latestSiteNodeVersionVO.setIsProtected(updatedSiteNodeVersionVO.getIsProtected());
126             latestSiteNodeVersionVO.setVersionModifier(infoGluePrincipal.getName());
127             latestSiteNodeVersionVO.setModifiedDateTime(DateHelper.getSecondPreciseDate());
128
129             SiteNodeVersionControllerProxy.getSiteNodeVersionControllerProxy().acUpdate(infoGluePrincipal, latestSiteNodeVersionVO, db);
130
131             //If any of the validations or setMethods reported an error, we throw them up now before create.
132
ceb.throwIfNotEmpty();
133             
134             commitTransaction(db);
135         }
136         catch(ConstraintException ce)
137         {
138             logger.warn("An error occurred so we should not complete the transaction:" + ce, ce);
139             rollbackTransaction(db);
140             throw ce;
141         }
142         catch(Exception JavaDoc e)
143         {
144             logger.error("An error occurred so we should not complete the transaction:" + e, e);
145             rollbackTransaction(db);
146             throw new SystemException(e.getMessage());
147         }
148
149
150         return siteNode.getValueObject();
151     }
152
153 }
154         
155
Popular Tags