001/**
002 * Copyright 2010-2014 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 */
016package org.kuali.common.util.property.processor;
017
018import java.util.Properties;
019
020import org.kuali.common.util.Mode;
021import org.kuali.common.util.OrgUtils;
022import org.kuali.common.util.PropertyUtils;
023import org.kuali.common.util.maven.MavenConstants;
024import org.kuali.common.util.property.Constants;
025import org.slf4j.Logger;
026import org.slf4j.LoggerFactory;
027import org.springframework.util.Assert;
028
029public class OrgProcessor implements PropertyProcessor {
030        private static final Logger logger = LoggerFactory.getLogger(OrgProcessor.class);
031
032        Mode propertyOverwriteMode = Constants.DEFAULT_PROPERTY_OVERWRITE_MODE;
033
034        String organizationGroupCodeSuffix = Constants.GROUP_ID + "." + Constants.DEFAULT_CODE_SUFFIX;
035        String groupCodeProperty = MavenConstants.GROUP_ID_KEY + "." + Constants.DEFAULT_CODE_SUFFIX;
036        String organizationGroupId;
037        String groupId;
038
039        public OrgProcessor() {
040                this(null, null);
041        }
042
043        public OrgProcessor(String organizationGroupId, String groupId) {
044                super();
045                this.organizationGroupId = organizationGroupId;
046                this.groupId = groupId;
047        }
048
049        @Override
050        public void process(Properties properties) {
051                logger.debug("organizationGroupId={}", organizationGroupId);
052                logger.debug("groupId={}", groupId);
053
054                Assert.notNull(organizationGroupId, "organizationGroupId is null");
055                Assert.notNull(groupId, "groupId is null");
056
057                String organizationCode = OrgUtils.getOrgCode(organizationGroupId);
058                String groupCode = OrgUtils.getGroupCode(organizationGroupId, groupId);
059
060                String organizationGroupCodeProperty = organizationCode + "." + organizationGroupCodeSuffix;
061
062                PropertyUtils.addOrOverrideProperty(properties, organizationGroupCodeProperty, organizationCode, propertyOverwriteMode);
063                PropertyUtils.addOrOverrideProperty(properties, groupCodeProperty, groupCode, propertyOverwriteMode);
064        }
065
066        public String getOrganizationGroupId() {
067                return organizationGroupId;
068        }
069
070        public void setOrganizationGroupId(String organizationGroupId) {
071                this.organizationGroupId = organizationGroupId;
072        }
073
074        public String getGroupId() {
075                return groupId;
076        }
077
078        public void setGroupId(String groupId) {
079                this.groupId = groupId;
080        }
081
082        public String getGroupCodeProperty() {
083                return groupCodeProperty;
084        }
085
086        public void setGroupCodeProperty(String groupCodeProperty) {
087                this.groupCodeProperty = groupCodeProperty;
088        }
089
090        public Mode getPropertyOverwriteMode() {
091                return propertyOverwriteMode;
092        }
093
094        public void setPropertyOverwriteMode(Mode propertyOverwriteMode) {
095                this.propertyOverwriteMode = propertyOverwriteMode;
096        }
097
098        public String getOrganizationGroupCodeSuffix() {
099                return organizationGroupCodeSuffix;
100        }
101
102        public void setOrganizationGroupCodeSuffix(String organizationGroupCodeSuffix) {
103                this.organizationGroupCodeSuffix = organizationGroupCodeSuffix;
104        }
105
106}