View Javadoc

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  //    public SearchRequestInfo toSearchRequest(Data data) {
79  //        SearchRequestInfo searchRequest = null;
80  //        if (data != null) {
81  //            CluSetRangeHelper cluSetRangeHelper = CluSetRangeHelper.wrap(data);
82  //            Data queryParamsData = cluSetRangeHelper.getQueryParams();
83  //            searchRequest = new SearchRequestInfo();
84  //            searchRequest.setSearchKey(cluSetRangeHelper.getSearchTypeKey());
85  //            for (Data.Property p : queryParamsData) {
86  //                QueryParamHelper queryParamHelper = QueryParamHelper.wrap((Data)p.getValue());
87  //                SearchParamInfo searchParam = new SearchParamInfo();
88  //                searchParam.setKey(queryParamHelper.getKey());
89  //                searchParam.setValue(queryParamHelper.getValue());
90  //                if (searchRequest.getParams() == null) {
91  //                    searchRequest.setParams(new ArrayList<SearchParamInfo>());
92  //                }
93  //                searchRequest.getParams().add(searchParam);
94  //            }
95  //        }
96  //        return searchRequest;
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             // make sure the membershipQueryInfo has some contents in it.
108             // Return null if otherwise.
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 }