001/**
002 * Copyright 2005-2018 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.krad.rules.rule.event;
017
018import java.util.ArrayList;
019import java.util.HashMap;
020import java.util.List;
021import java.util.Map;
022
023/**
024 * Created by nigupta on 4/28/2014.
025 */
026abstract public class RuleEventBase implements RuleEvent {
027
028    private String name;
029    private final String description;
030    private final String errorPathPrefix;
031    private Map<String, Object> facts = new HashMap<String, Object>();
032    private String ruleMethodName;
033
034    /**
035     * As a general rule, business rule classes should not change the original object. This constructor was created so
036     * that PreRulesCheckEvent, a UI level rule checker, can make changes.
037     *
038     * @param description
039     * @param errorPathPrefix
040     */
041    public RuleEventBase( String description, String errorPathPrefix ) {
042        this.description = description;
043        this.errorPathPrefix = errorPathPrefix;
044    }
045
046    public void addFact( String key, Object object ) {
047        facts.put( key, object );
048    }
049
050    /**
051     * the name of this event
052     * @return - the event name
053     */
054    public String getName() {
055        return name;
056    }
057
058    /**
059     * @see RuleEventBase#getName()
060     */
061    public void setName( String name ) {
062        this.name = name;
063    }
064
065    /**
066     * @return a description of this event
067     */
068    public final String getDescription() {
069        return description;
070    }
071
072    /**
073     * @return the error path prefix for this event
074     */
075    public String getErrorPathPrefix() {
076        return errorPathPrefix;
077    }
078
079    /**
080     * @see java.lang.Object#toString()
081     */
082    @Override
083    public String toString() {
084        return getName();
085    }
086
087    /**
088     * {@inheritDoc}
089     */
090    public Map<String, Object> getFacts() {
091        return facts;
092    }
093
094    /**
095     * @see RuleEventBase#getFacts()
096     */
097    public void setFacts( Map<String, Object> facts ) {
098        this.facts = facts;
099    }
100
101    /**
102     * {@inheritDoc}
103     */
104    public String getRuleMethodName() {
105        return ruleMethodName;
106    }
107
108    /**
109     * @see RuleEventBase#getRuleMethodName()
110     */
111    public void setRuleMethodName( String name ) {
112        this.ruleMethodName = name;
113    }
114
115    /**
116     * @see org.kuali.rice.krad.rules.rule.event.RuleEvent#generateEvents()
117     */
118    @Override
119    public List<RuleEvent> generateEvents() {
120        return new ArrayList<RuleEvent>();
121    }
122}