View Javadoc

1   /**
2    * Copyright 2010-2013 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.common.util.property.processor;
17  
18  import java.util.Properties;
19  
20  import org.kuali.common.util.Mode;
21  import org.kuali.common.util.OrgUtils;
22  import org.kuali.common.util.PropertyUtils;
23  import org.kuali.common.util.property.Constants;
24  import org.slf4j.Logger;
25  import org.slf4j.LoggerFactory;
26  import org.springframework.util.Assert;
27  
28  public class OrgProcessor implements PropertyProcessor {
29  	private static final Logger logger = LoggerFactory.getLogger(OrgProcessor.class);
30  
31  	Mode propertyOverwriteMode = Constants.DEFAULT_PROPERTY_OVERWRITE_MODE;
32  
33  	String organizationGroupCodeSuffix = Constants.GROUP_ID + "." + Constants.DEFAULT_CODE_SUFFIX;
34  	String groupCodeProperty = Constants.DEFAULT_GROUP_ID_PROPERTY + "." + Constants.DEFAULT_CODE_SUFFIX;
35  	String organizationGroupId;
36  	String groupId;
37  
38  	public OrgProcessor() {
39  		this(null, null);
40  	}
41  
42  	public OrgProcessor(String organizationGroupId, String groupId) {
43  		super();
44  		this.organizationGroupId = organizationGroupId;
45  		this.groupId = groupId;
46  	}
47  
48  	@Override
49  	public void process(Properties properties) {
50  		logger.debug("organizationGroupId={}", organizationGroupId);
51  		logger.debug("groupId={}", groupId);
52  
53  		Assert.notNull(organizationGroupId, "organizationGroupId is null");
54  		Assert.notNull(groupId, "groupId is null");
55  
56  		String organizationCode = OrgUtils.getOrgCode(organizationGroupId);
57  		String groupCode = OrgUtils.getGroupCode(organizationGroupId, groupId);
58  
59  		String organizationGroupCodeProperty = organizationCode + "." + organizationGroupCodeSuffix;
60  
61  		PropertyUtils.addOrOverrideProperty(properties, organizationGroupCodeProperty, organizationCode, propertyOverwriteMode);
62  		PropertyUtils.addOrOverrideProperty(properties, groupCodeProperty, groupCode, propertyOverwriteMode);
63  	}
64  
65  	public String getOrganizationGroupId() {
66  		return organizationGroupId;
67  	}
68  
69  	public void setOrganizationGroupId(String organizationGroupId) {
70  		this.organizationGroupId = organizationGroupId;
71  	}
72  
73  	public String getGroupId() {
74  		return groupId;
75  	}
76  
77  	public void setGroupId(String groupId) {
78  		this.groupId = groupId;
79  	}
80  
81  	public String getGroupCodeProperty() {
82  		return groupCodeProperty;
83  	}
84  
85  	public void setGroupCodeProperty(String groupCodeProperty) {
86  		this.groupCodeProperty = groupCodeProperty;
87  	}
88  
89  	public Mode getPropertyOverwriteMode() {
90  		return propertyOverwriteMode;
91  	}
92  
93  	public void setPropertyOverwriteMode(Mode propertyOverwriteMode) {
94  		this.propertyOverwriteMode = propertyOverwriteMode;
95  	}
96  
97  	public String getOrganizationGroupCodeSuffix() {
98  		return organizationGroupCodeSuffix;
99  	}
100 
101 	public void setOrganizationGroupCodeSuffix(String organizationGroupCodeSuffix) {
102 		this.organizationGroupCodeSuffix = organizationGroupCodeSuffix;
103 	}
104 
105 }