1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util.config;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.apache.commons.lang3.StringUtils;
22 import org.springframework.util.Assert;
23
24
25
26
27 @Deprecated
28 public class ConfigUtils {
29
30 public static final String DELIMITER = ":";
31
32 public static List<ProjectConfig> getProjectConfigs(List<String> configIds) {
33 List<ProjectConfig> requests = new ArrayList<ProjectConfig>();
34 for (String configId : configIds) {
35 ProjectConfig request = ConfigUtils.getProjectConfig(configId);
36 requests.add(request);
37 }
38 return requests;
39 }
40
41 public static String getConfigId(ProjectConfig config) {
42 return getConfigId(config.getGroupId(), config.getArtifactId(), config.getContextId());
43 }
44
45 public static String getConfigId(String groupId, String artifactId, String contextId) {
46 Assert.hasText(groupId, "groupId is blank");
47 Assert.hasText(artifactId, "artifactId is blank");
48 StringBuilder sb = new StringBuilder();
49 sb.append(StringUtils.trimToEmpty(groupId));
50 sb.append(DELIMITER);
51 sb.append(StringUtils.trimToEmpty(artifactId));
52 if (!StringUtils.isBlank(contextId)) {
53 sb.append(DELIMITER);
54 sb.append(StringUtils.trimToEmpty(contextId));
55 }
56 return sb.toString();
57 }
58
59 public static ProjectConfig getProjectConfig(String configId) {
60
61
62 String[] tokens = StringUtils.split(configId, DELIMITER);
63
64
65
66 Assert.isTrue(tokens.length > 1, "2 tokens are required");
67
68
69 String groupId = tokens[0];
70 String artifactId = tokens[1];
71 String contextId = getContextId(tokens);
72
73
74 DefaultProjectConfig config = new DefaultProjectConfig();
75 config.setGroupId(groupId);
76 config.setArtifactId(artifactId);
77 config.setContextId(contextId);
78 return config;
79 }
80
81 protected static String getContextId(String[] tokens) {
82 if (tokens.length < 3) {
83 return null;
84 }
85 StringBuilder sb = new StringBuilder();
86 for (int i = 2; i < tokens.length; i++) {
87 if (i != 2) {
88 sb.append(DELIMITER);
89 }
90 sb.append(tokens[i]);
91 }
92 return sb.toString();
93 }
94
95 }