1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.select.service.impl;
17
18 import org.kuali.ole.select.service.OleForiegnVendorPhoneNumberService;
19 import org.kuali.ole.vnd.VendorParameterConstants;
20 import org.kuali.ole.vnd.businessobject.VendorDetail;
21 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
22 import org.kuali.rice.krad.util.ObjectUtils;
23
24 import java.util.ArrayList;
25 import java.util.List;
26 import java.util.regex.Matcher;
27 import java.util.regex.Pattern;
28
29 public class OleForiegnVendorPhoneNumberServiceImpl implements OleForiegnVendorPhoneNumberService {
30
31 public ParameterService parameterService;
32 public List<String> phoneNumberFormats;
33
34 public void setParameterService(ParameterService parameterService) {
35 this.parameterService = parameterService;
36 }
37
38 @Override
39 public boolean isValidForiegnVendorPhoneNumber(String phoneNumber) {
40
41 String[] formats = parseFormats();
42 for (int i = 0; i < formats.length; i++) {
43 if (phoneNumber.matches(formats[i])) {
44 return true;
45 }
46 }
47 return false;
48 }
49
50 protected String[] parseFormats() {
51 if (ObjectUtils.isNull(phoneNumberFormats)) {
52 phoneNumberFormats = new ArrayList<String>(parameterService.getParameterValuesAsString(VendorDetail.class, VendorParameterConstants.FOREIGN_VENDOR_PHONE_NUMBER_FORMATS));
53 }
54 return phoneNumberFormats.toArray(new String[]{});
55 }
56
57 }