View Javadoc

1   /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   */
15  
16  package org.kuali.student.core.messages.bo;
17  
18  import java.util.HashMap;
19  import java.util.LinkedHashMap;
20  import java.util.Map;
21  
22  import javax.persistence.Entity;
23  import javax.persistence.Table;
24  import javax.persistence.Transient;
25  
26  import org.kuali.rice.kns.service.KNSServiceLocator;
27  import org.kuali.student.core.bo.KsBusinessObjectBase;
28  import org.kuali.student.core.enumerationmanagement.bo.EnumeratedValue;
29  
30  @Entity
31  @Table(name = "KSMG_MESSAGE")
32  public class MessageEntity extends KsBusinessObjectBase {
33  
34      public static final String GROUP_NAME_ENUMERATION = "ks.message.groupNames";
35      public static final String LOCALE_ENUMERATION = "ks.message.locales";
36      
37      private static final long serialVersionUID = 1L;
38  
39      
40      private String messageId;
41      private String locale;
42      private String groupName;
43      private String value;
44      
45      @Transient
46      private transient EnumeratedValue localeEnumValue;
47      
48      @Transient
49      private transient EnumeratedValue groupNameEnumValue;
50  
51      
52      @Override
53      protected LinkedHashMap<String, Object> toStringMapper() {
54  
55          LinkedHashMap<String, Object> map = super.toStringMapper();
56  
57          map.put("locale", locale);
58          map.put("groupName", groupName);
59          map.put("messageId", messageId);
60  
61          return map;
62  
63      }
64      
65      protected EnumeratedValue retrieveEnumeratedValue(String enumerationId, String enumerationCode) {
66          Map<String, Object> criteria = new HashMap<String, Object>();
67          criteria.put("enumerationId", enumerationId);
68          criteria.put("code", enumerationCode);
69          
70          return (EnumeratedValue) KNSServiceLocator.getBusinessObjectService().findByPrimaryKey(EnumeratedValue.class, criteria);
71      }
72      
73      
74      public String getLocale() {
75          return locale;
76      }
77  
78      public void setLocale(String locale) {
79          this.locale = locale;
80      }
81  
82      public String getGroupName() {
83          return groupName;
84      }
85  
86      public void setGroupName(String groupName) {
87          this.groupName = groupName;
88      }
89  
90      public String getMessageId() {
91          return messageId;
92      }
93  
94      public void setMessageId(String messageId) {
95          this.messageId = messageId;
96      }
97  
98      public String getValue() {
99          return value;
100     }
101 
102     public void setValue(String value) {
103         this.value = value;
104     }
105 
106 
107     public EnumeratedValue getLocaleEnumValue() {
108         if(localeEnumValue == null) {
109             localeEnumValue = retrieveEnumeratedValue(LOCALE_ENUMERATION, this.locale);            
110         }
111         
112         return localeEnumValue;
113     }
114 
115     public void setLocaleEnumValue(EnumeratedValue localeEnumValue) {
116         this.localeEnumValue = localeEnumValue;
117     }
118 
119     public EnumeratedValue getGroupNameEnumValue() {
120         if(groupNameEnumValue == null) {
121             groupNameEnumValue = retrieveEnumeratedValue(GROUP_NAME_ENUMERATION, this.groupName);
122         }
123         
124         return groupNameEnumValue;
125     }
126 
127     public void setGroupNameEnumValue(EnumeratedValue groupNameEnumValue) {
128         this.groupNameEnumValue = groupNameEnumValue;
129     }
130 
131 }