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