[507] | 1 | /*
|
---|
| 2 | * To change this template, choose Tools | Templates
|
---|
| 3 | * and open the template in the editor.
|
---|
| 4 | */
|
---|
| 5 | package gov.hhs.fha.nhinc.util.format;
|
---|
| 6 |
|
---|
| 7 | import gov.hhs.fha.nhinc.nhinclib.NullChecker;
|
---|
| 8 | import java.util.ArrayList;
|
---|
| 9 | import java.util.List;
|
---|
| 10 |
|
---|
| 11 | /**
|
---|
| 12 | *
|
---|
| 13 | * @author rayj
|
---|
| 14 | */
|
---|
| 15 | public class DocumentClassCodeParser {
|
---|
| 16 |
|
---|
| 17 | private static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(DocumentClassCodeParser.class);
|
---|
| 18 |
|
---|
| 19 | public static List<String> parseFormattedParameter(List<String> rawList) {
|
---|
| 20 | List<String> normalizedList = new ArrayList<String>();
|
---|
| 21 | for (String item : rawList) {
|
---|
| 22 | normalizedList = parseFormattedParameter(item, normalizedList);
|
---|
| 23 | }
|
---|
| 24 | return normalizedList;
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | public static List<String> parseFormattedParameter(String paramFormattedString) {
|
---|
| 28 | return parseFormattedParameter(paramFormattedString, null);
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | public static List<String> parseFormattedParameter(String paramFormattedString, List<String> resultCollection) {
|
---|
| 32 | if (resultCollection == null) {
|
---|
| 33 | resultCollection = new ArrayList<String>();
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | if ((NullChecker.isNotNullish(paramFormattedString)) && (resultCollection != null)) {
|
---|
| 37 | if (paramFormattedString.startsWith("(")) {
|
---|
| 38 | String working = paramFormattedString.substring(1);
|
---|
| 39 | int endIndex = working.indexOf(")");
|
---|
| 40 | if (endIndex != -1) {
|
---|
| 41 | working = working.substring(0, endIndex);
|
---|
| 42 | }
|
---|
| 43 | String[] multiValueString = working.split(",");
|
---|
| 44 | if (multiValueString != null) {
|
---|
| 45 | for (int i = 0; i < multiValueString.length; i++) {
|
---|
| 46 | String singleValue = multiValueString[i];
|
---|
| 47 | if (singleValue != null) {
|
---|
| 48 | singleValue = singleValue.trim();
|
---|
| 49 | }
|
---|
| 50 | if (singleValue.startsWith("'")) {
|
---|
| 51 | singleValue = singleValue.substring(1);
|
---|
| 52 | }
|
---|
| 53 | if (singleValue.endsWith("'")) {
|
---|
| 54 | int endTickIndex = singleValue.indexOf("'");
|
---|
| 55 | if (endTickIndex != -1) {
|
---|
| 56 | singleValue = singleValue.substring(0, endTickIndex);
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
| 59 | resultCollection.add(singleValue);
|
---|
| 60 | if (log.isDebugEnabled()) {
|
---|
| 61 | log.debug("Added single value: " + singleValue + " to query parameters");
|
---|
| 62 | }
|
---|
| 63 | }
|
---|
| 64 | }
|
---|
| 65 | } else {
|
---|
| 66 | resultCollection.add(paramFormattedString);
|
---|
| 67 | if (log.isDebugEnabled()) {
|
---|
| 68 | log.debug("No wrapper on status - adding status: " + paramFormattedString + " to query parameters");
|
---|
| 69 | }
|
---|
| 70 | }
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | return resultCollection;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | public static String buildDocumentClassCodeItem(List<String> documentClassCodeList) {
|
---|
| 77 | String buffer = "";
|
---|
| 78 |
|
---|
| 79 | if ((documentClassCodeList != null) && (documentClassCodeList.size() > 0)) {
|
---|
| 80 | buffer = "(";
|
---|
| 81 | for (String documentClassCode : documentClassCodeList) {
|
---|
| 82 | documentClassCode = documentClassCode.trim();
|
---|
| 83 | if (NullChecker.isNotNullish(buffer)) {
|
---|
| 84 | buffer = buffer + "'" + documentClassCode + "'" + ",";
|
---|
| 85 | }
|
---|
| 86 | }
|
---|
| 87 | if (buffer.endsWith(",")) {
|
---|
| 88 | buffer = buffer.substring(0, buffer.length() - 1);
|
---|
| 89 | }
|
---|
| 90 | buffer = buffer + ")";
|
---|
| 91 | }
|
---|
| 92 | if (buffer.contentEquals("()")) {
|
---|
| 93 | buffer = "";
|
---|
| 94 | }
|
---|
| 95 | return buffer;
|
---|
| 96 | }
|
---|
| 97 | }
|
---|