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.io.File;
19  import java.util.Properties;
20  
21  import org.kuali.common.util.OrgUtils;
22  import org.kuali.common.util.Project;
23  import org.kuali.common.util.Str;
24  import org.springframework.util.Assert;
25  
26  public class ProjectProcessor implements PropertyProcessor {
27  
28  	private static final String FS = File.separator;
29  	private static final String DOT = ".";
30  
31  	@Override
32  	public void process(Properties properties) {
33  		Project p = getProject(properties);
34  		validate(p);
35  		String groupCode = OrgUtils.getGroupCode(p.getOrgId(), p.getGroupId());
36  		String groupBase = OrgUtils.getGroupBase(p.getOrgId(), p.getGroupId());
37  		String userHome = System.getProperty("user.home");
38  		String orgHome = userHome + FS + DOT + p.getOrgCode();
39  		String groupHome = orgHome + FS + groupCode;
40  		properties.setProperty("project.groupId.code", groupCode);
41  		properties.setProperty("project.groupId.path", Str.getPath(p.getGroupId()));
42  		properties.setProperty("project.groupId.base", groupBase);
43  		properties.setProperty("project.groupId.base.path", Str.getPath(groupBase));
44  		properties.setProperty("project.orgId.home", orgHome);
45  		properties.setProperty("project.groupId.home", groupHome);
46  	}
47  
48  	protected void validate(Project project) {
49  		Assert.notNull(project.getOrgId(), "orgId is null");
50  		Assert.notNull(project.getOrgCode(), "orgCode is null");
51  		Assert.notNull(project.getOrgPath(), "orgPath is null");
52  		Assert.notNull(project.getGroupId(), "groupId is null");
53  		Assert.notNull(project.getArtifactId(), "artifactId is null");
54  		Assert.notNull(project.getVersion(), "version is null");
55  	}
56  
57  	protected Project getProject(Properties properties) {
58  		Project project = new Project();
59  		project.setOrgId(properties.getProperty("project.orgId"));
60  		project.setOrgCode(properties.getProperty("project.orgId.code"));
61  		project.setOrgPath(properties.getProperty("project.orgId.path"));
62  		project.setGroupId(properties.getProperty("project.groupId"));
63  		project.setArtifactId(properties.getProperty("project.artifactId"));
64  		project.setVersion(properties.getProperty("project.version"));
65  		return project;
66  	}
67  
68  }