1 18 package org.alfresco.web.bean.wizard; 19 20 import java.io.Serializable ; 21 import java.text.MessageFormat ; 22 import java.util.HashMap ; 23 import java.util.Map ; 24 25 import javax.faces.context.FacesContext; 26 import javax.faces.event.ActionEvent; 27 import javax.transaction.UserTransaction ; 28 29 import org.alfresco.error.AlfrescoRuntimeException; 30 import org.alfresco.model.ContentModel; 31 import org.alfresco.model.ForumModel; 32 import org.alfresco.service.cmr.repository.ChildAssociationRef; 33 import org.alfresco.service.cmr.repository.NodeRef; 34 import org.alfresco.service.namespace.QName; 35 import org.alfresco.web.app.AlfrescoNavigationHandler; 36 import org.alfresco.web.app.Application; 37 import org.alfresco.web.bean.repository.Repository; 38 import org.alfresco.web.ui.common.Utils; 39 import org.alfresco.web.ui.common.component.UIActionLink; 40 import org.apache.commons.logging.Log; 41 import org.apache.commons.logging.LogFactory; 42 43 48 public class NewDiscussionWizard extends NewTopicWizard 49 { 50 private static final Log logger = LogFactory.getLog(NewDiscussionWizard.class); 51 52 private NodeRef discussingNodeRef; 53 54 57 @Override 58 public void startWizard(ActionEvent event) 59 { 60 UIActionLink link = (UIActionLink)event.getComponent(); 61 Map <String , String > params = link.getParameterMap(); 62 String id = params.get("id"); 63 if (id == null || id.length() == 0) 64 { 65 throw new AlfrescoRuntimeException("startDiscussion called without an id"); 66 } 67 68 FacesContext context = FacesContext.getCurrentInstance(); 69 UserTransaction tx = null; 70 NodeRef forumNodeRef = null; 71 72 try 73 { 74 tx = Repository.getUserTransaction(context); 75 tx.begin(); 76 77 this.discussingNodeRef = new NodeRef(Repository.getStoreRef(), id); 78 79 if (this.nodeService.hasAspect(this.discussingNodeRef, ForumModel.ASPECT_DISCUSSABLE)) 80 { 81 throw new AlfrescoRuntimeException("startDiscussion called for an object that already has a discussion!"); 82 } 83 84 this.nodeService.addAspect(this.discussingNodeRef, ForumModel.ASPECT_DISCUSSABLE, null); 86 87 String name = (String )this.nodeService.getProperty(this.discussingNodeRef, 90 ContentModel.PROP_NAME); 91 String msg = Application.getMessage(FacesContext.getCurrentInstance(), "discussion_for"); 92 String forumName = MessageFormat.format(msg, new Object [] {name}); 93 94 Map <QName, Serializable > forumProps = new HashMap <QName, Serializable >(1); 95 forumProps.put(ContentModel.PROP_NAME, forumName); 96 ChildAssociationRef childRef = this.nodeService.createNode(this.discussingNodeRef, 97 ForumModel.ASSOC_DISCUSSION, 98 QName.createQName(ForumModel.FORUMS_MODEL_URI, "discussion"), 99 ForumModel.TYPE_FORUM, forumProps); 100 101 forumNodeRef = childRef.getChildRef(); 102 103 Map <QName, Serializable > uiFacetsProps = new HashMap <QName, Serializable >(5); 105 uiFacetsProps.put(ContentModel.PROP_ICON, "forum_large"); 106 this.nodeService.addAspect(forumNodeRef, ContentModel.ASPECT_UIFACETS, uiFacetsProps); 107 108 if (logger.isDebugEnabled()) 109 logger.debug("created forum for content: " + this.discussingNodeRef.toString()); 110 111 tx.commit(); 113 } 114 catch (Throwable e) 115 { 116 try { if (tx != null) {tx.rollback();} } catch (Exception ex) {} 118 Utils.addErrorMessage(MessageFormat.format(Application.getMessage( 119 context, Repository.ERROR_GENERIC), e.getMessage()), e); 120 } 121 122 if (forumNodeRef != null) 124 { 125 this.browseBean.clickSpace(forumNodeRef); 126 127 super.startWizard(event); 129 context.getApplication().getNavigationHandler().handleNavigation(context, null, "dialog:createDiscussion"); 130 } 131 } 132 133 136 @Override 137 public String cancel() 138 { 139 143 FacesContext context = FacesContext.getCurrentInstance(); 144 UserTransaction tx = null; 145 146 try 147 { 148 tx = Repository.getUserTransaction(context); 149 tx.begin(); 150 151 this.nodeService.removeAspect(this.discussingNodeRef, ForumModel.ASPECT_DISCUSSABLE); 153 154 this.browseBean.setActionSpace(this.navigator.getCurrentNode()); 156 this.browseBean.deleteSpaceOK(); 157 158 tx.commit(); 160 } 161 catch (Throwable e) 162 { 163 try { if (tx != null) {tx.rollback();} } catch (Exception ex) {} 165 Utils.addErrorMessage(MessageFormat.format(Application.getMessage( 166 context, Repository.ERROR_GENERIC), e.getMessage()), e); 167 } 168 169 super.cancel(); 171 172 return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME + 176 AlfrescoNavigationHandler.DIALOG_SEPARATOR + "browse"; 177 } 178 179 180 } 181 | Popular Tags |