1 | |
package org.kuali.student.lum.common.client.widgets; |
2 | |
|
3 | |
import java.util.List; |
4 | |
|
5 | |
import org.kuali.student.common.assembly.data.Data; |
6 | |
import org.kuali.student.common.assembly.data.LookupMetadata; |
7 | |
import org.kuali.student.common.assembly.data.LookupParamMetadata; |
8 | |
import org.kuali.student.common.search.dto.SearchParam; |
9 | |
import org.kuali.student.common.ui.client.widgets.DataHelper; |
10 | |
import org.kuali.student.lum.lu.dto.MembershipQueryInfo; |
11 | |
|
12 | 0 | public class CluSetRangeDataHelper implements DataHelper { |
13 | |
|
14 | |
private LookupMetadata lookupMetadata; |
15 | |
|
16 | |
@Override |
17 | |
public String parse(Data data) { |
18 | |
MembershipQueryInfo membershipQueryInfo; |
19 | 0 | StringBuilder labelText = new StringBuilder(); |
20 | 0 | int paramCounter = 0; |
21 | 0 | membershipQueryInfo = CluSetRangeModelUtil.INSTANCE.toMembershipQueryInfo(data); |
22 | 0 | if (membershipQueryInfo != null) { |
23 | 0 | if (membershipQueryInfo.getQueryParamValueList() != null && |
24 | |
!membershipQueryInfo.getQueryParamValueList().isEmpty()) { |
25 | 0 | for (SearchParam searchParam : membershipQueryInfo.getQueryParamValueList()) { |
26 | 0 | if (paramCounter > 0) { |
27 | 0 | labelText.append(" "); |
28 | |
} |
29 | 0 | labelText.append(getParameterDisplayName(searchParam.getKey())).append(": "); |
30 | 0 | labelText.append("<b>").append(searchParam.getValue()).append("</b>"); |
31 | 0 | paramCounter++; |
32 | |
} |
33 | |
} else { |
34 | 0 | labelText.append("All Courses"); |
35 | |
} |
36 | |
} |
37 | 0 | return labelText.toString(); |
38 | |
} |
39 | |
|
40 | |
@Override |
41 | |
public String getKey(Data data) { |
42 | 0 | return parse(data); |
43 | |
} |
44 | |
|
45 | |
private String getParameterDisplayName(String parameterKey) { |
46 | 0 | String parameterDisplayName = null; |
47 | 0 | if (lookupMetadata == null) { |
48 | 0 | parameterDisplayName = parameterKey; |
49 | |
} else { |
50 | 0 | List<LookupParamMetadata> searchParams = lookupMetadata.getParams(); |
51 | 0 | if (searchParams != null) { |
52 | 0 | for (LookupParamMetadata searchParam : searchParams) { |
53 | 0 | if (nullSafeEquals(searchParam.getKey(), parameterKey)) { |
54 | 0 | parameterDisplayName = searchParam.getName(); |
55 | |
} |
56 | |
} |
57 | |
} |
58 | 0 | if (parameterDisplayName == null) { |
59 | 0 | parameterDisplayName = parameterKey; |
60 | |
} |
61 | |
} |
62 | 0 | return parameterDisplayName; |
63 | |
} |
64 | |
|
65 | |
private boolean nullSafeEquals(Object str1, Object str2) { |
66 | 0 | return (str1 == null && str2 == null || |
67 | |
str1 != null && str2 != null && str1.equals(str2)); |
68 | |
} |
69 | |
|
70 | |
public LookupMetadata getLookupMetadata() { |
71 | 0 | return lookupMetadata; |
72 | |
} |
73 | |
|
74 | |
public void setLookupMetadata(LookupMetadata lookupMetadata) { |
75 | 0 | this.lookupMetadata = lookupMetadata; |
76 | 0 | } |
77 | |
|
78 | |
} |