1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.vnd;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.ole.sys.context.SpringContext;
20 import org.kuali.rice.core.api.config.property.ConfigurationService;
21 import org.kuali.rice.krad.util.ObjectUtils;
22
23
24
25
26 public class VendorUtils {
27
28 public static final char LEFT_COLLECTION_SEPERATOR = '[';
29 public static final char RIGHT_COLLECTION_SEPERATOR = ']';
30 public static final char FIELD_SEPERATOR = '.';
31
32
33
34
35
36
37
38
39
40
41 public static String assembleWithPosition(String full, String[] collections, int[] positions) {
42
43 if (collections.length != positions.length) {
44 throw new IllegalArgumentException();
45 }
46
47 String[] parts = StringUtils.split(full, FIELD_SEPERATOR);
48
49 for (int j = 0; j < parts.length; j++) {
50 for (int i = 0; i < collections.length; i++) {
51 if (StringUtils.equals(parts[j], collections[i])) {
52 parts[j] = collections[i] + LEFT_COLLECTION_SEPERATOR + positions[i] + RIGHT_COLLECTION_SEPERATOR;
53 break;
54 }
55
56 }
57 }
58
59 return StringUtils.join(parts, FIELD_SEPERATOR);
60 }
61
62
63
64
65
66
67
68
69
70
71 public static String assembleWithPosition(String full, String collection, int position) {
72 String[] collections = { collection };
73 int[] positions = { position };
74 return assembleWithPosition(full, collections, positions);
75 }
76
77
78
79
80
81
82
83 public static Integer getVendorHeaderId(String vendorNumber) {
84
85
86 if (!VendorUtils.validVendorNumberFormat(vendorNumber)) {
87 return null;
88 }
89
90
91 String[] vendorNumberParts = vendorNumber.split("-");
92 return new Integer(Integer.parseInt(vendorNumberParts[0]));
93 }
94
95
96
97
98
99
100
101 public static Integer getVendorDetailId(String vendorNumber) {
102
103 if (!VendorUtils.validVendorNumberFormat(vendorNumber)) {
104 return null;
105 }
106
107
108 String[] vendorNumberParts = vendorNumber.split("-");
109 return new Integer(Integer.parseInt(vendorNumberParts[1]));
110 }
111
112
113
114
115
116
117
118
119 public static boolean validVendorNumberFormat(String vendorNumber) {
120
121
122 if (vendorNumber == null) {
123 return false;
124 }
125
126
127 if (!vendorNumber.matches("\\d+-\\d+")) {
128 return false;
129 }
130
131 return true;
132 }
133
134
135
136
137
138
139
140
141 public static String buildMessageText(String messageKey, String... parameters) {
142 String result = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(messageKey);
143 if (ObjectUtils.isNotNull(parameters)) {
144 for (int i = 0; i < parameters.length; i++) {
145 result = StringUtils.replace(result, "{" + i + "}", parameters[i]);
146 }
147 }
148 return result;
149 }
150 }