1 23 24 package org.infoglue.cms.applications.structuretool.actions; 25 26 import java.util.Collections ; 27 import java.util.Iterator ; 28 import java.util.List ; 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 55 56 public class CreateSiteNodeAction extends InfoGlueAbstractAction 57 { 58 private final static Logger logger = Logger.getLogger(CreateSiteNodeAction.class.getName()); 59 60 private Integer siteNodeId; 61 private String name; 62 private Boolean isBranch; 63 private Integer parentSiteNodeId; 64 private Integer siteNodeTypeDefinitionId; 65 private Integer pageTemplateContentId; 66 private Integer repositoryId; 67 private ConstraintExceptionBuffer ceb; 68 private SiteNodeVO siteNodeVO; 69 private SiteNodeVO newSiteNodeVO; 70 private String 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 parentSiteNodeId) 84 { 85 this.parentSiteNodeId = parentSiteNodeId; 86 } 87 88 public Integer getParentSiteNodeId() 89 { 90 return this.parentSiteNodeId; 91 } 92 93 public void setRepositoryId(Integer repositoryId) 94 { 95 this.repositoryId = repositoryId; 96 } 97 98 public Integer getRepositoryId() 99 { 100 return this.repositoryId; 101 } 102 103 public void setSiteNodeTypeDefinitionId(Integer siteNodeTypeDefinitionId) 104 { 105 this.siteNodeTypeDefinitionId = siteNodeTypeDefinitionId; 106 } 107 108 public Integer getSiteNodeTypeDefinitionId() 109 { 110 return this.siteNodeTypeDefinitionId; 111 } 112 113 public java.lang.String getName() 114 { 115 return this.siteNodeVO.getName(); 116 } 117 118 public String getPublishDateTime() 119 { 120 return new VisualFormatter().formatDate(this.siteNodeVO.getPublishDateTime(), "yyyy-MM-dd HH:mm"); 121 } 122 123 public String getExpireDateTime() 124 { 125 return new VisualFormatter().formatDate(this.siteNodeVO.getExpireDateTime(), "yyyy-MM-dd HH:mm"); 126 } 127 128 public Boolean getIsBranch() 129 { 130 return this.siteNodeVO.getIsBranch(); 131 } 132 133 public void setName(java.lang.String name) 134 { 135 this.siteNodeVO.setName(name); 136 } 137 138 public void setPublishDateTime(String 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 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 isBranch) 151 { 152 this.siteNodeVO.setIsBranch(isBranch); 153 } 154 155 public Integer getSiteNodeId() 156 { 157 return newSiteNodeVO.getSiteNodeId(); 158 } 159 160 public String getSortProperty() 161 { 162 return sortProperty; 163 } 164 165 168 169 public List getSortedPageTemplates(String sortProperty) throws Exception 170 { 171 SiteNodeVO parentSiteNodeVO = SiteNodeController.getController().getSiteNodeVOWithId(this.parentSiteNodeId); 172 LanguageVO masterLanguageVO = LanguageController.getController().getMasterLanguage(parentSiteNodeVO.getRepositoryId()); 173 174 List components = PageTemplateController.getController().getPageTemplates(this.getInfoGluePrincipal(), masterLanguageVO.getId()); 175 176 Collections.sort(components, new ReflectionComparator(sortProperty)); 177 178 return components; 179 } 180 181 182 185 186 public String getDigitalAssetUrl(Integer contentId, String key) throws Exception 187 { 188 String 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 digitalAssets = DigitalAssetController.getDigitalAssetVOList(contentVersionVO.getId()); 194 Iterator 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 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 217 218 public List getSiteNodeTypeDefinitions() throws Exception 219 { 220 return SiteNodeTypeDefinitionController.getController().getSiteNodeTypeDefinitionVOList(); 221 } 222 223 public String doExecute() throws Exception 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 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 doInput() throws Exception 259 { 260 return "input"; 261 } 262 263 public Integer getPageTemplateContentId() 264 { 265 return pageTemplateContentId; 266 } 267 268 public void setPageTemplateContentId(Integer pageTemplateContentId) 269 { 270 this.pageTemplateContentId = pageTemplateContentId; 271 } 272 } 273 | Popular Tags |