001    package org.kuali.student.common.search;
002    
003    import java.util.ArrayList;
004    import java.util.List;
005    
006    import org.kuali.student.common.exceptions.DoesNotExistException;
007    import org.kuali.student.common.exceptions.InvalidParameterException;
008    import org.kuali.student.common.exceptions.MissingParameterException;
009    import org.kuali.student.common.exceptions.OperationFailedException;
010    import org.kuali.student.common.search.dto.SearchCriteriaTypeInfo;
011    import org.kuali.student.common.search.dto.SearchRequest;
012    import org.kuali.student.common.search.dto.SearchResult;
013    import org.kuali.student.common.search.dto.SearchResultCell;
014    import org.kuali.student.common.search.dto.SearchResultRow;
015    import org.kuali.student.common.search.dto.SearchResultTypeInfo;
016    import org.kuali.student.common.search.dto.SearchTypeInfo;
017    import org.kuali.student.common.search.service.SearchService;
018    import org.kuali.student.common.search.service.impl.CrossSearchManager;
019    import org.kuali.student.common.search.service.impl.SearchDispatcherImpl;
020    import org.kuali.student.common.search.service.impl.SearchManagerImpl;
021    
022    public class MockSearch implements SearchService {
023            SearchManagerImpl sm;
024            public MockSearch(){
025                    sm = new SearchManagerImpl("classpath:test-cross-search.xml");
026                    CrossSearchManager csm = new CrossSearchManager();
027                    sm.setCrossSearchManager(csm);
028                    SearchDispatcherImpl sd = new SearchDispatcherImpl();
029                    List<SearchService> services = new ArrayList<SearchService>();
030                    services.add(this);
031                    sd.setServices(services);
032                    csm.setSearchDispatcher(sd);
033            }
034            @Override
035            public List<SearchTypeInfo> getSearchTypes()
036                            throws OperationFailedException {
037                    return sm.getSearchTypes();
038            }
039    
040            @Override
041            public SearchTypeInfo getSearchType(String searchTypeKey)
042                            throws DoesNotExistException, InvalidParameterException,
043                            MissingParameterException, OperationFailedException {
044                    return sm.getSearchType(searchTypeKey);
045            }
046    
047            @Override
048            public List<SearchTypeInfo> getSearchTypesByResult(
049                            String searchResultTypeKey) throws DoesNotExistException,
050                            InvalidParameterException, MissingParameterException,
051                            OperationFailedException {
052                    return sm.getSearchTypesByResult(searchResultTypeKey);
053            }
054    
055            @Override
056            public List<SearchTypeInfo> getSearchTypesByCriteria(
057                            String searchCriteriaTypeKey) throws DoesNotExistException,
058                            InvalidParameterException, MissingParameterException,
059                            OperationFailedException {
060                    return sm.getSearchTypesByCriteria(searchCriteriaTypeKey);
061            }
062    
063            @Override
064            public List<SearchResultTypeInfo> getSearchResultTypes()
065                            throws OperationFailedException {
066                    return sm.getSearchResultTypes();
067            }
068    
069            @Override
070            public SearchResultTypeInfo getSearchResultType(String searchResultTypeKey)
071                            throws DoesNotExistException, InvalidParameterException,
072                            MissingParameterException, OperationFailedException {
073                    return sm.getSearchResultType(searchResultTypeKey);
074            }
075    
076            @Override
077            public List<SearchCriteriaTypeInfo> getSearchCriteriaTypes()
078                            throws OperationFailedException {
079                    return sm.getSearchCriteriaTypes();
080            }
081    
082            @Override
083            public SearchCriteriaTypeInfo getSearchCriteriaType(
084                            String searchCriteriaTypeKey) throws DoesNotExistException,
085                            InvalidParameterException, MissingParameterException,
086                            OperationFailedException {
087                    return sm.getSearchCriteriaType(searchCriteriaTypeKey);
088            }
089    
090            @Override
091            public SearchResult search(SearchRequest searchRequest)
092                            throws MissingParameterException {
093                    if("test.search1".equals(searchRequest.getSearchKey())){
094                            SearchResult searchResult = new SearchResult();
095                            SearchResultRow row = new SearchResultRow();
096                            SearchResultCell cell = new SearchResultCell();
097                            cell.setKey("col1");
098                            cell.setValue("value1-1");
099                            row.getCells().add(cell);
100                            
101                            cell = new SearchResultCell();
102                            cell.setKey("col2");
103                            cell.setValue("value2-1");
104                            row.getCells().add(cell);
105                            
106                            searchResult.getRows().add(row);
107                    
108                            row = new SearchResultRow();
109                            cell = new SearchResultCell();
110                            cell.setKey("col1");
111                            cell.setValue("value1-2");
112                            row.getCells().add(cell);
113                            
114                            cell = new SearchResultCell();
115                            cell.setKey("col2");
116                            cell.setValue("value2-2");
117                            row.getCells().add(cell);
118                            
119                            searchResult.getRows().add(row);
120                            return searchResult;
121                    }
122                    
123                    if("test.search2".equals(searchRequest.getSearchKey())){
124                            SearchResult searchResult = new SearchResult();
125                            SearchResultRow row = new SearchResultRow();
126                            SearchResultCell cell = new SearchResultCell();
127                            cell.setKey("C-A");
128                            cell.setValue("Avalue1-1");
129                            row.getCells().add(cell);
130                            
131                            cell = new SearchResultCell();
132                            cell.setKey("C-B");
133                            cell.setValue("Avalue2-1");
134                            row.getCells().add(cell);
135                            
136                            searchResult.getRows().add(row);
137                    
138                            row = new SearchResultRow();
139                            cell = new SearchResultCell();
140                            cell.setKey("C-A");
141                            cell.setValue("Avalue1-2");
142                            row.getCells().add(cell);
143                            
144                            cell = new SearchResultCell();
145                            cell.setKey("C-B");
146                            cell.setValue("Avalue2-2");
147                            row.getCells().add(cell);
148                            
149                            searchResult.getRows().add(row);
150                            return searchResult;
151                    }else if("test.crossSearch".equals(searchRequest.getSearchKey())){
152                            return sm.search(searchRequest, null);
153                    }
154                    return null;
155            }
156    
157    }