View Javadoc

1   /*
2    * Copyright 2008-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.role.dto;
17  
18  import java.io.Serializable;
19  import java.util.Map;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.apache.commons.lang.builder.ToStringBuilder;
23  import org.kuali.rice.core.resourceloader.GlobalResourceLoader;
24  import org.kuali.rice.kim.bo.role.KimPermission;
25  import org.kuali.rice.kim.service.PermissionService;
26  import org.kuali.rice.kim.util.KimConstants;
27  
28  /**
29   * This is a description of what this class does - kellerj don't forget to fill this in. 
30   * 
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   *
33   */
34  public class KimPermissionInfo extends PermissionDetailsInfo implements KimPermission, Serializable {
35  
36  	private static final long serialVersionUID = 1L;
37  	protected String namespaceCode;
38  	protected String name;
39  	protected String description;
40  	protected String templateId;
41  	protected KimPermissionTemplateInfo template;
42  	
43  	protected boolean active;
44  	
45  	public String getName() {
46  		return this.name;
47  	}
48  	public void setName(String name) {
49  		this.name = name;
50  	}
51  	public String getDescription() {
52  		return this.description;
53  	}
54  	public void setDescription(String description) {
55  		this.description = description;
56  	}
57  	public boolean isActive() {
58  		return this.active;
59  	}
60  	public void setActive(boolean active) {
61  		this.active = active;
62  	}
63  	public String getNamespaceCode() {
64  		return this.namespaceCode;
65  	}
66  	public void setNamespaceCode(String namespaceCode) {
67  		this.namespaceCode = namespaceCode;
68  	}
69  	public KimPermissionTemplateInfo getTemplate() {
70  		return this.template;
71  	}
72  	public void setTemplate(KimPermissionTemplateInfo template) {
73  		this.template = template;
74  	}
75      /**
76       * @see java.lang.Object#toString()
77       */
78      public String toString() {
79          return new ToStringBuilder(this).append("details", this.details).append("template", this.template).append("namespaceCode", this.namespaceCode).append("name", this.name).toString();
80      }
81  	
82  	/**
83  	 * @see java.lang.Object#hashCode()
84  	 */
85  	@Override
86  	public int hashCode() {
87  		if ( getPermissionId() == null ) {
88  			return 0;
89  		}
90  		return getPermissionId().hashCode();
91  	}
92  	
93  	/**
94  	 * @see java.lang.Object#equals(java.lang.Object)
95  	 */
96  	@Override
97  	public boolean equals(Object obj) {
98  		if ( obj == null || !(obj instanceof KimPermissionInfo) ) {
99  			return false;
100 		}
101 		return StringUtils.equals( getPermissionId(), ((KimPermissionInfo)obj).getPermissionId() );
102 	}
103 	
104 	public String getNameToDisplay(){
105 		return (StringUtils.isBlank(getName()) && getTemplate()!=null)?getTemplate().getName():getName();
106 	}
107 
108 	public String getDetailObjectsValues(){
109 		StringBuffer detailObjectsToDisplay = new StringBuffer();
110 		for( Map.Entry<String,String> entry: getDetails().entrySet() ){
111 			detailObjectsToDisplay.append(entry.getKey()+KimConstants.KimUIConstants.COMMA_SEPARATOR);
112 		}
113 		return StringUtils.chomp(detailObjectsToDisplay.toString(), KimConstants.KimUIConstants.COMMA_SEPARATOR );
114 	}
115 
116 	public String getDetailObjectsToDisplay() {
117 		StringBuffer detailObjectsToDisplay = new StringBuffer();
118 		for( Map.Entry<String,String> entry: getDetails().entrySet() ){
119 			detailObjectsToDisplay.append(getAttributeDetailToDisplay(entry));
120 		}
121 		return StringUtils.chomp(detailObjectsToDisplay.toString(), KimConstants.KimUIConstants.COMMA_SEPARATOR );
122 	}
123 
124 	public String getAttributeDetailToDisplay(Map.Entry<String,String> entry){
125 		return getKimAttributeLabelFromDD(entry.getKey())+KimConstants.KimUIConstants.NAME_VALUE_SEPARATOR+
126 				entry.getValue()+KimConstants.KimUIConstants.COMMA_SEPARATOR;
127 	}
128 	
129 	//TODO: remove this and find a better way to do this. Should be done by next week with role doc task
130 	protected String getKimAttributeLabelFromDD(String attributeName){
131     	return getPermissionService().getPermissionDetailLabel(permissionId, template.getKimTypeId(), attributeName );
132     }
133 
134 	private transient static PermissionService permissionService;
135 	protected PermissionService getPermissionService() {
136 		if(permissionService == null){
137 			permissionService = (PermissionService)GlobalResourceLoader.getService( "kimPermissionService" );
138 		}
139 		return permissionService;
140 	}
141 	public String getTemplateId() {
142 		return this.templateId;
143 	}
144 	public void setTemplateId(String templateId) {
145 		this.templateId = templateId;
146 	}
147 	
148 }