001 /**
002 * Copyright 2010-2012 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.common.util.property.processor;
017
018 import java.util.Properties;
019
020 import org.kuali.common.util.Mode;
021 import org.kuali.common.util.OrgUtils;
022 import org.kuali.common.util.PropertyUtils;
023 import org.kuali.common.util.property.Constants;
024 import org.slf4j.Logger;
025 import org.slf4j.LoggerFactory;
026 import org.springframework.util.Assert;
027
028 public class OrgProcessor implements PropertyProcessor {
029 private static final Logger logger = LoggerFactory.getLogger(OrgProcessor.class);
030
031 Mode propertyOverwriteMode = Constants.DEFAULT_PROPERTY_OVERWRITE_MODE;
032
033 String organizationGroupCodeSuffix = Constants.GROUP_ID + "." + Constants.DEFAULT_CODE_SUFFIX;
034 String groupCodeProperty = Constants.DEFAULT_GROUP_ID_PROPERTY + "." + Constants.DEFAULT_CODE_SUFFIX;
035 String organizationGroupId;
036 String groupId;
037
038 public OrgProcessor() {
039 this(null, null);
040 }
041
042 public OrgProcessor(String organizationGroupId, String groupId) {
043 super();
044 this.organizationGroupId = organizationGroupId;
045 this.groupId = groupId;
046 }
047
048 @Override
049 public void process(Properties properties) {
050 logger.debug("organizationGroupId={}", organizationGroupId);
051 logger.debug("groupId={}", groupId);
052
053 Assert.notNull(organizationGroupId, "organizationGroupId is null");
054 Assert.notNull(groupId, "groupId is null");
055
056 String organizationCode = OrgUtils.getOrgCode(organizationGroupId);
057 String groupCode = OrgUtils.getGroupCode(organizationGroupId, groupId);
058
059 String organizationGroupCodeProperty = organizationCode + "." + organizationGroupCodeSuffix;
060
061 PropertyUtils.addOrOverrideProperty(properties, organizationGroupCodeProperty, organizationCode, propertyOverwriteMode);
062 PropertyUtils.addOrOverrideProperty(properties, groupCodeProperty, groupCode, propertyOverwriteMode);
063 }
064
065 public String getOrganizationGroupId() {
066 return organizationGroupId;
067 }
068
069 public void setOrganizationGroupId(String organizationGroupId) {
070 this.organizationGroupId = organizationGroupId;
071 }
072
073 public String getGroupId() {
074 return groupId;
075 }
076
077 public void setGroupId(String groupId) {
078 this.groupId = groupId;
079 }
080
081 public String getGroupCodeProperty() {
082 return groupCodeProperty;
083 }
084
085 public void setGroupCodeProperty(String groupCodeProperty) {
086 this.groupCodeProperty = groupCodeProperty;
087 }
088
089 public Mode getPropertyOverwriteMode() {
090 return propertyOverwriteMode;
091 }
092
093 public void setPropertyOverwriteMode(Mode propertyOverwriteMode) {
094 this.propertyOverwriteMode = propertyOverwriteMode;
095 }
096
097 public String getOrganizationGroupCodeSuffix() {
098 return organizationGroupCodeSuffix;
099 }
100
101 public void setOrganizationGroupCodeSuffix(String organizationGroupCodeSuffix) {
102 this.organizationGroupCodeSuffix = organizationGroupCodeSuffix;
103 }
104
105 }