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.io.File;
019    import java.util.Properties;
020    
021    import org.kuali.common.util.OrgUtils;
022    import org.kuali.common.util.Project;
023    import org.kuali.common.util.Str;
024    import org.springframework.util.Assert;
025    
026    public class ProjectProcessor implements PropertyProcessor {
027    
028            private static final String FS = File.separator;
029            private static final String DOT = ".";
030    
031            @Override
032            public void process(Properties properties) {
033                    Project p = getProject(properties);
034                    validate(p);
035                    String groupCode = OrgUtils.getGroupCode(p.getOrgId(), p.getGroupId());
036                    String groupBase = OrgUtils.getGroupBase(p.getOrgId(), p.getGroupId());
037                    String userHome = System.getProperty("user.home");
038                    String orgHome = userHome + FS + DOT + p.getOrgCode();
039                    String groupHome = orgHome + FS + groupCode;
040                    properties.setProperty("project.groupId.code", groupCode);
041                    properties.setProperty("project.groupId.path", Str.getPath(p.getGroupId()));
042                    properties.setProperty("project.groupId.base", groupBase);
043                    properties.setProperty("project.groupId.base.path", Str.getPath(groupBase));
044                    properties.setProperty("project.orgId.home", orgHome);
045                    properties.setProperty("project.groupId.home", groupHome);
046            }
047    
048            protected void validate(Project project) {
049                    Assert.notNull(project.getOrgId(), "orgId is null");
050                    Assert.notNull(project.getOrgCode(), "orgCode is null");
051                    Assert.notNull(project.getOrgPath(), "orgPath is null");
052                    Assert.notNull(project.getGroupId(), "groupId is null");
053                    Assert.notNull(project.getArtifactId(), "artifactId is null");
054                    Assert.notNull(project.getVersion(), "version is null");
055            }
056    
057            protected Project getProject(Properties properties) {
058                    Project project = new Project();
059                    project.setOrgId(properties.getProperty("project.orgId"));
060                    project.setOrgCode(properties.getProperty("project.orgId.code"));
061                    project.setOrgPath(properties.getProperty("project.orgId.path"));
062                    project.setGroupId(properties.getProperty("project.groupId"));
063                    project.setArtifactId(properties.getProperty("project.artifactId"));
064                    project.setVersion(properties.getProperty("project.version"));
065                    return project;
066            }
067    
068    }