1 23 24 package org.infoglue.cms.applications.structuretool.actions; 25 26 import java.util.ArrayList ; 27 import java.util.HashMap ; 28 import java.util.List ; 29 import java.util.Map ; 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 60 61 public class ViewAndCreateContentForServiceBindingAction extends InfoGlueAbstractAction 62 { 63 private final static Logger logger = Logger.getLogger(ViewAndCreateContentForServiceBindingAction.class.getName()); 64 65 private Integer siteNodeVersionId; 66 private Integer repositoryId; 67 private Integer serviceDefinitionId; 69 private Integer bindingTypeId; 70 private ConstraintExceptionBuffer ceb; 71 private Integer siteNodeId; 72 private ServiceDefinitionVO singleServiceDefinitionVO; 73 private String tree; 75 private List repositories; 76 private ContentVO contentVO = new ContentVO(); 77 private Integer languageId = null; 78 private Integer metaInfoContentTypeDefinitionId = null; 79 private String changeStateToWorking = null; 80 81 83 95 96 public void setSiteNodeVersionId(Integer siteNodeVersionId) 97 { 98 this.siteNodeVersionId = siteNodeVersionId; 99 } 100 101 public void setRepositoryId(Integer repositoryId) 102 { 103 this.repositoryId = repositoryId; 104 } 105 106 112 113 public void setServiceDefinitionId(Integer serviceDefinitionId) 114 { 115 this.serviceDefinitionId = serviceDefinitionId; 116 } 117 128 public Integer getSiteNodeVersionId() 129 { 130 return this.siteNodeVersionId; 131 } 132 133 public void setSiteNodeId(Integer siteNodeId) 134 { 135 this.siteNodeId = siteNodeId; 136 } 137 138 public Integer getSiteNodeId() 139 { 140 return this.siteNodeId; 141 } 142 143 public Integer getRepositoryId() 144 { 145 return this.repositoryId; 146 } 147 148 154 155 public Integer getServiceDefinitionId() 156 { 157 return this.singleServiceDefinitionVO.getServiceDefinitionId(); 158 } 159 160 public Integer getBindingTypeId() 161 { 162 return this.bindingTypeId; 163 } 164 165 171 public ServiceDefinitionVO getSingleServiceDefinitionVO() 172 { 173 return this.singleServiceDefinitionVO; 174 } 175 176 public String getTree() 177 { 178 return tree; 179 } 180 181 public void setTree(String string) 182 { 183 tree = string; 184 } 185 186 public String getCurrentAction() 187 { 188 return "ViewAndCreateContentForServiceBinding.action"; 189 } 190 191 196 197 public String doExecute() throws Exception 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 events = new ArrayList (); 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 ("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 288 289 this.languageId = getInitialLanguageVO(this.contentVO.getId()).getId(); 290 291 commitTransaction(db); 292 } 293 catch(Exception 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 contentId) throws Exception 304 { 305 Map args = new HashMap (); 306 args.put("globalKey", "infoglue"); 307 PropertySet ps = PropertySetManager.getInstance("jdbc", args); 308 309 String 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 (initialLanguageId)); 319 else 320 return LanguageController.getController().getMasterLanguage(repositoryId); 321 } 322 323 public List getRepositories() 324 { 325 return repositories; 326 } 327 328 public Integer getContentId() 329 { 330 return this.contentVO.getId(); 331 } 332 333 public Integer getLanguageId() 334 { 335 return this.languageId; 336 } 337 338 public String getChangeStateToWorking() 339 { 340 return changeStateToWorking; 341 } 342 343 public void setChangeStateToWorking(String changeStateToWorking) 344 { 345 this.changeStateToWorking = changeStateToWorking; 346 } 347 } 348 | Popular Tags |