View Javadoc

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