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