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