View Javadoc

1   /*
2    * Copyright 2007-2009 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kim.bo.impl;
17  
18  import java.util.Iterator;
19  import java.util.LinkedHashMap;
20  
21  import javax.persistence.Column;
22  import javax.persistence.Entity;
23  import javax.persistence.Id;
24  import javax.persistence.PrePersist;
25  import javax.persistence.PreUpdate;
26  import javax.persistence.Table;
27  
28  import org.apache.commons.lang.StringUtils;
29  import org.apache.ojb.broker.PersistenceBroker;
30  import org.apache.ojb.broker.PersistenceBrokerException;
31  import org.kuali.rice.kim.bo.role.KimPermission;
32  import org.kuali.rice.kim.bo.types.dto.AttributeSet;
33  import org.kuali.rice.kns.bo.PersistableBusinessObjectBase;
34  
35  /**
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   */
38  @Entity
39  @Table(name="KRIM_PERM_T")
40  public class GenericPermission extends PersistableBusinessObjectBase {
41  //	private static final Logger LOG = Logger.getLogger(GenericPermission.class);	
42  	
43  	private static final long serialVersionUID = 1L;
44  	
45  	@Id
46  	@Column(name="PERM_ID")
47  	protected String permissionId;
48  	protected String namespaceCode;
49  	protected String name;
50  	protected String description;
51  	protected boolean active;
52  	protected String templateId;
53  	protected String detailValues;
54  	protected AttributeSet details;
55  	
56  	/**
57  	 * This constructs a ...
58  	 * 
59  	 */
60  	public GenericPermission() {
61  	}
62  	
63  	public GenericPermission( KimPermission perm ) {
64  		loadFromKimPermission( perm );
65  	}
66  	public void loadFromKimPermission( KimPermission perm ) {
67  		setPermissionId( perm.getPermissionId() );
68  		setNamespaceCode( perm.getNamespaceCode() );
69  		setName( perm.getName() );
70  		setTemplateId( perm.getTemplateId() );
71  		setDescription( perm.getDescription() );
72  		setActive( perm.isActive() );
73  		setDetails( perm.getDetails() );
74  	}
75  	
76  	public String getDetailValues() {
77  		/*StringBuffer sb = new StringBuffer();
78  		if ( details != null ) {
79  			Iterator<String> keyIter = details.keySet().iterator();
80  			while ( keyIter.hasNext() ) {
81  				String key = keyIter.next();
82  				sb.append( key ).append( '=' ).append( details.get( key ) );
83  				if ( keyIter.hasNext() ) {
84  					sb.append( '\n' );
85  				}
86  			}
87  		}
88  		return sb.toString();*/
89  		return detailValues;
90  	}
91  	
92  	public void setDetailValues( String detailValues ) {
93  		this.detailValues = detailValues;
94  		String detailValuesTemp = detailValues;
95  		AttributeSet details = new AttributeSet();
96  		if ( detailValuesTemp != null ) {
97  			// ensure that all line delimiters are single linefeeds
98  			detailValuesTemp = detailValuesTemp.replace( "\r\n", "\n" );
99  			detailValuesTemp = detailValuesTemp.replace( '\r', '\n' );
100 			if ( StringUtils.isNotBlank( detailValuesTemp ) ) {
101 				String[] values = detailValuesTemp.split( "\n" );
102 				for ( String attrib : values ) {
103 					if ( attrib.indexOf( '=' ) != -1 ) {
104 						String[] keyValueArray = attrib.split( "=", 2 );
105 						details.put( keyValueArray[0].trim(), keyValueArray[1].trim() );
106 					}
107 				}
108 			}
109 		}
110 		this.details = details;
111 	}
112 	
113 	public void setDetailValues( AttributeSet detailsAttribs ) {
114 		StringBuffer sb = new StringBuffer();
115 		if ( detailsAttribs != null ) {
116 			Iterator<String> keyIter = detailsAttribs.keySet().iterator();
117 			while ( keyIter.hasNext() ) {
118 				String key = keyIter.next();
119 				sb.append( key ).append( '=' ).append( detailsAttribs.get( key ) );
120 				if ( keyIter.hasNext() ) {
121 					sb.append( '\n' );
122 				}
123 			}
124 		}
125 		detailValues = sb.toString();
126 	}
127 	
128 	/**
129 	 * @see org.kuali.rice.kns.bo.Inactivateable#isActive()
130 	 */
131 	public boolean isActive() {
132 		return active;
133 	}
134 
135 	/**
136 	 * @see org.kuali.rice.kns.bo.Inactivateable#setActive(boolean)
137 	 */
138 	public void setActive(boolean active) {
139 		this.active = active;
140 	}
141 
142 	/**
143 	 * @see org.kuali.rice.kim.bo.role.KimPermission#getDescription()
144 	 */
145 	public String getDescription() {
146 		return description;
147 	}
148 
149 	/**
150 	 * @see org.kuali.rice.kim.bo.role.KimPermission#getPermissionId()
151 	 */
152 	public String getPermissionId() {
153 		return permissionId;
154 	}
155 
156 	/**
157 	 * @see org.kuali.rice.kim.bo.role.KimPermission#getName()
158 	 */
159 	public String getName() {
160 		return name;
161 	}
162 
163 	public void setDescription(String permissionDescription) {
164 		this.description = permissionDescription;
165 	}
166 
167 	public void setName(String permissionName) {
168 		this.name = permissionName;
169 	}
170 
171 	/**
172 	 * @see org.kuali.rice.kns.bo.BusinessObjectBase#toStringMapper()
173 	 */
174 	@SuppressWarnings("unchecked")
175 	@Override
176 	protected LinkedHashMap toStringMapper() {
177 		LinkedHashMap m = new LinkedHashMap();
178 		m.put( "permissionId", permissionId );
179 		m.put( "name", name );
180 		m.put( "details", getDetails() );
181 		return m;
182 	}
183 
184 	public void setDetails( AttributeSet details ) {
185 		this.details = details;
186 		setDetailValues(details);
187 	}
188 	
189 	public String getTemplateId() {
190 		return this.templateId;
191 	}
192 
193 	public void setTemplateId(String templateId) {
194 		this.templateId = templateId;
195 	}
196 
197 	public AttributeSet getDetails() {
198 		return details;
199 	}
200 	
201 	public String getNamespaceCode() {
202 		return this.namespaceCode;
203 	}
204 
205 	public void setNamespaceCode(String namespaceCode) {
206 		this.namespaceCode = namespaceCode;
207 	}
208 
209 	public void setPermissionId(String permissionId) {
210 		this.permissionId = permissionId;
211 	}
212 
213 
214 	public void refresh() {
215 		// do nothing - not a persistable object
216 	}
217 	
218 	@Override
219 	public void refreshNonUpdateableReferences() {
220 		// do nothing - not a persistable object
221 	}
222 	@Override
223 	public void refreshReferenceObject(String referenceObjectName) {
224 		// do nothing - not a persistable object
225 	}
226 
227 	/**
228 	 * This overridden method ...
229 	 * 
230 	 * @see org.kuali.rice.kns.bo.PersistableBusinessObjectBase#beforeInsert()
231 	 */
232 	@Override
233 	@PrePersist
234 	public void beforeInsert() {
235 		throw new UnsupportedOperationException( "This object should never be persisted.");
236 	}
237 	
238 	/**
239 	 * This overridden method ...
240 	 * 
241 	 * @see org.kuali.rice.kns.bo.PersistableBusinessObjectBase#beforeUpdate()
242 	 */
243 	@Override
244 	@PreUpdate
245 	public void beforeUpdate() {
246 		throw new UnsupportedOperationException( "This object should never be persisted.");
247 	}
248 	
249 	/**
250 	 * This overridden method ...
251 	 * 
252 	 * @see org.kuali.rice.kns.bo.PersistableBusinessObjectBase#beforeInsert(org.apache.ojb.broker.PersistenceBroker)
253 	 */
254 	@Override
255 	public void beforeInsert(PersistenceBroker persistenceBroker)
256 			throws PersistenceBrokerException {
257 		throw new UnsupportedOperationException( "This object should never be persisted.");
258 	}
259 	
260 	/**
261 	 * This overridden method ...
262 	 * 
263 	 * @see org.kuali.rice.kns.bo.PersistableBusinessObjectBase#beforeUpdate(org.apache.ojb.broker.PersistenceBroker)
264 	 */
265 	@Override
266 	public void beforeUpdate(PersistenceBroker persistenceBroker) {
267 		throw new UnsupportedOperationException( "This object should never be persisted.");
268 	}
269 
270 	/**
271 	 * This overridden method ...
272 	 * 
273 	 * @see org.kuali.rice.kns.bo.PersistableBusinessObjectBase#beforeDelete(org.apache.ojb.broker.PersistenceBroker)
274 	 */
275 	@Override
276 	public void beforeDelete(PersistenceBroker persistenceBroker)
277 			throws PersistenceBrokerException {
278 		throw new UnsupportedOperationException( "This object should never be persisted.");
279 	}
280 
281 }