1 | |
package org.kuali.student.lum.common.client.widgets; |
2 | |
|
3 | |
import java.util.ArrayList; |
4 | |
import java.util.List; |
5 | |
|
6 | |
import org.kuali.student.common.assembly.data.Data; |
7 | |
import org.kuali.student.common.search.dto.SearchParam; |
8 | |
import org.kuali.student.common.search.dto.SearchRequest; |
9 | |
import org.kuali.student.lum.lu.dto.MembershipQueryInfo; |
10 | |
|
11 | |
public class CluSetRangeModelUtil { |
12 | |
|
13 | 0 | public static CluSetRangeModelUtil INSTANCE = new CluSetRangeModelUtil(); |
14 | |
|
15 | 0 | private CluSetRangeModelUtil() { |
16 | 0 | } |
17 | |
|
18 | |
public Data toData(SearchRequest searchRequest, String searchRequestId) { |
19 | 0 | if (searchRequest == null) { |
20 | 0 | return null; |
21 | |
} |
22 | 0 | List<SearchParam> searchParams = searchRequest.getParams(); |
23 | 0 | CluSetRangeHelper cluSetRangeHelper = CluSetRangeHelper.wrap(new Data()); |
24 | 0 | cluSetRangeHelper.setId(searchRequestId); |
25 | 0 | cluSetRangeHelper.setSearchTypeKey(searchRequest.getSearchKey()); |
26 | 0 | if (searchParams != null) { |
27 | 0 | for (SearchParam searchParam : searchParams) { |
28 | 0 | QueryParamHelper queryParamHelper = QueryParamHelper.wrap(new Data()); |
29 | 0 | queryParamHelper.setValue(null); |
30 | 0 | queryParamHelper.setListValue(null); |
31 | 0 | queryParamHelper.setKey(searchParam.getKey()); |
32 | |
|
33 | |
|
34 | 0 | if (searchParam.getValue() != null) { |
35 | 0 | if (searchParam.getValue().getClass().equals(String.class)) { |
36 | 0 | queryParamHelper.setValue((String)searchParam.getValue()); |
37 | 0 | if (cluSetRangeHelper.getQueryParams() == null) { |
38 | 0 | cluSetRangeHelper.setQueryParams(new Data()); |
39 | |
} |
40 | 0 | cluSetRangeHelper.getQueryParams().add(queryParamHelper.getData()); |
41 | |
} |
42 | |
} |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | 0 | } |
48 | |
} |
49 | |
|
50 | 0 | return cluSetRangeHelper.getData(); |
51 | |
} |
52 | |
|
53 | |
public Data toData(MembershipQueryInfo membershipQueryInfo) { |
54 | 0 | if (membershipQueryInfo == null) { |
55 | 0 | return null; |
56 | |
} |
57 | 0 | List<SearchParam> searchParams = membershipQueryInfo.getQueryParamValueList(); |
58 | 0 | CluSetRangeHelper cluSetRangeHelper = CluSetRangeHelper.wrap(new Data()); |
59 | 0 | cluSetRangeHelper.setId(membershipQueryInfo.getId()); |
60 | 0 | cluSetRangeHelper.setSearchTypeKey(membershipQueryInfo.getSearchTypeKey()); |
61 | 0 | if (searchParams != null) { |
62 | 0 | for (SearchParam searchParam : searchParams) { |
63 | 0 | QueryParamHelper queryParamHelper = QueryParamHelper.wrap(new Data()); |
64 | 0 | queryParamHelper.setValue((String)searchParam.getValue()); |
65 | 0 | queryParamHelper.setListValue(null); |
66 | 0 | queryParamHelper.setKey(searchParam.getKey()); |
67 | 0 | if (cluSetRangeHelper.getQueryParams() == null) { |
68 | 0 | cluSetRangeHelper.setQueryParams(new Data()); |
69 | |
} |
70 | 0 | cluSetRangeHelper.getQueryParams().add(queryParamHelper.getData()); |
71 | 0 | } |
72 | |
} |
73 | |
|
74 | 0 | return cluSetRangeHelper.getData(); |
75 | |
} |
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
public MembershipQueryInfo toMembershipQueryInfo(Data data) { |
99 | 0 | MembershipQueryInfo membershipQueryInfo = null; |
100 | 0 | if (data != null) { |
101 | 0 | CluSetRangeHelper cluSetRangeHelper = CluSetRangeHelper.wrap(data); |
102 | 0 | Data queryParamsData = cluSetRangeHelper.getQueryParams(); |
103 | 0 | membershipQueryInfo = new MembershipQueryInfo(); |
104 | 0 | membershipQueryInfo.setId(cluSetRangeHelper.getId()); |
105 | 0 | membershipQueryInfo.setSearchTypeKey(cluSetRangeHelper.getSearchTypeKey()); |
106 | |
|
107 | |
|
108 | 0 | if (membershipQueryInfo.getSearchTypeKey() == null || |
109 | |
membershipQueryInfo.getSearchTypeKey().trim().isEmpty()) { |
110 | 0 | return null; |
111 | |
} |
112 | 0 | for (Data.Property p : queryParamsData) { |
113 | 0 | QueryParamHelper queryParamHelper = QueryParamHelper.wrap((Data)p.getValue()); |
114 | 0 | SearchParam searchParam = new SearchParam(); |
115 | 0 | searchParam.setKey(queryParamHelper.getKey()); |
116 | 0 | searchParam.setValue(queryParamHelper.getValue()); |
117 | 0 | if (membershipQueryInfo.getQueryParamValueList() == null) { |
118 | 0 | membershipQueryInfo.setQueryParamValueList(new ArrayList<SearchParam>()); |
119 | |
} |
120 | 0 | membershipQueryInfo.getQueryParamValueList().add(searchParam); |
121 | 0 | } |
122 | |
} |
123 | 0 | return membershipQueryInfo; |
124 | |
} |
125 | |
|
126 | |
} |