1 17 package org.alfresco.web.bean; 18 19 import java.io.Serializable ; 20 import java.util.ArrayList ; 21 import java.util.Date ; 22 import java.util.List ; 23 import java.util.Map ; 24 25 import javax.faces.context.FacesContext; 26 import javax.faces.event.ActionEvent; 27 28 import org.alfresco.service.cmr.action.Action; 29 import org.alfresco.service.cmr.action.ActionCondition; 30 import org.alfresco.service.cmr.repository.NodeRef; 31 import org.alfresco.service.cmr.rule.Rule; 32 import org.alfresco.service.cmr.rule.RuleService; 33 import org.alfresco.web.app.Application; 34 import org.alfresco.web.app.context.IContextListener; 35 import org.alfresco.web.app.context.UIContextService; 36 import org.alfresco.web.bean.repository.Node; 37 import org.alfresco.web.ui.common.Utils; 38 import org.alfresco.web.ui.common.component.UIActionLink; 39 import org.alfresco.web.ui.common.component.UIModeList; 40 import org.alfresco.web.ui.common.component.data.UIRichList; 41 import org.apache.commons.logging.Log; 42 import org.apache.commons.logging.LogFactory; 43 44 49 public class RulesBean implements IContextListener 50 { 51 private static final String MSG_ERROR_DELETE_RULE = "error_delete_rule"; 52 private static final String LOCAL = "local"; 53 private static final String INHERITED = "inherited"; 54 55 private static Log logger = LogFactory.getLog(RulesBean.class); 56 57 private String viewMode = INHERITED; 58 protected BrowseBean browseBean; 59 protected RuleService ruleService; 60 private List <WrappedRule> rules; 61 private Rule currentRule; 62 private UIRichList richList; 63 64 65 68 public RulesBean() 69 { 70 UIContextService.getInstance(FacesContext.getCurrentInstance()).registerBean(this); 71 } 72 73 78 public String getViewMode() 79 { 80 return this.viewMode; 81 } 82 83 86 public Node getSpace() 87 { 88 return this.browseBean.getActionSpace(); 89 } 90 91 96 public List <WrappedRule> getRules() 97 { 98 boolean includeInherited = true; 99 100 if (this.viewMode.equals(LOCAL)) 101 { 102 includeInherited = false; 103 } 104 105 List <Rule> repoRules = this.ruleService.getRules(getSpace().getNodeRef(), includeInherited); 107 this.rules = new ArrayList <WrappedRule>(repoRules.size()); 108 109 for (Rule rule : repoRules) 111 { 112 WrappedRule wrapped = new WrappedRule(rule, getSpace().getNodeRef()); 113 this.rules.add(wrapped); 114 } 115 116 return this.rules; 117 } 118 119 124 public void setupRuleAction(ActionEvent event) 125 { 126 UIActionLink link = (UIActionLink)event.getComponent(); 127 Map <String , String > params = link.getParameterMap(); 128 String id = params.get("id"); 129 if (id != null && id.length() != 0) 130 { 131 if (logger.isDebugEnabled()) 132 logger.debug("Rule clicked, it's id is: " + id); 133 134 this.currentRule = this.ruleService.getRule( 135 getSpace().getNodeRef(), id); 136 137 contextUpdated(); 139 } 140 } 141 142 147 public Rule getCurrentRule() 148 { 149 return this.currentRule; 150 } 151 152 157 public String deleteOK() 158 { 159 String outcome = null; 160 161 if (this.currentRule != null) 162 { 163 try 164 { 165 String ruleTitle = this.currentRule.getTitle(); 166 167 this.ruleService.removeRule(getSpace().getNodeRef(), 168 this.currentRule); 169 170 this.currentRule = null; 172 173 outcome = "manageRules"; 175 176 if (logger.isDebugEnabled()) 177 logger.debug("Deleted rule '" + ruleTitle + "'"); 178 } 179 catch (Throwable err) 180 { 181 Utils.addErrorMessage(Application.getMessage( 182 FacesContext.getCurrentInstance(), MSG_ERROR_DELETE_RULE) + err.getMessage(), err); 183 } 184 } 185 else 186 { 187 logger.warn("WARNING: deleteOK called without a current Rule!"); 188 } 189 190 return outcome; 191 } 192 193 198 public void viewModeChanged(ActionEvent event) 199 { 200 UIModeList viewList = (UIModeList)event.getComponent(); 201 this.viewMode = viewList.getValue().toString(); 202 203 if (this.richList != null) 205 { 206 this.richList.setValue(null); 207 } 208 } 209 210 215 public void setRichList(UIRichList richList) 216 { 217 this.richList = richList; 218 } 219 220 225 public UIRichList getRichList() 226 { 227 return this.richList; 228 } 229 230 233 public void setBrowseBean(BrowseBean browseBean) 234 { 235 this.browseBean = browseBean; 236 } 237 238 241 public void setRuleService(RuleService ruleService) 242 { 243 this.ruleService = ruleService; 244 } 245 246 247 250 253 public void contextUpdated() 254 { 255 if (this.richList != null) 256 { 257 this.richList.setValue(null); 258 } 259 } 260 261 262 266 public class WrappedRule 267 { 268 private Rule rule; 269 private NodeRef ruleNode; 270 271 277 public WrappedRule(Rule rule, NodeRef ruleNode) 278 { 279 this.rule = rule; 280 this.ruleNode = ruleNode; 281 } 282 283 288 public Rule getRule() 289 { 290 return this.rule; 291 } 292 293 299 public boolean getLocal() 300 { 301 return ruleNode.equals(this.rule.getOwningNodeRef()); 302 } 303 304 305 306 311 public String getId() 312 { 313 return this.rule.getId(); 314 } 315 316 321 public String getTitle() 322 { 323 return this.rule.getTitle(); 324 } 325 326 331 public String getDescription() 332 { 333 return this.rule.getDescription(); 334 } 335 336 341 public Date getCreatedDate() 342 { 343 return this.rule.getCreatedDate(); 344 } 345 346 351 public Date getModifiedDate() 352 { 353 return this.rule.getModifiedDate(); 354 } 355 } 356 } 357 | Popular Tags |