View Javadoc
1   /**
2    * Copyright 2005-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.labs.inquiry;
17  
18  import edu.sampleu.travel.dataobject.TravelCompany;
19  import org.kuali.rice.core.api.criteria.QueryByCriteria;
20  import org.kuali.rice.core.api.criteria.QueryResults;
21  import org.kuali.rice.krad.data.KradDataServiceLocator;
22  import org.kuali.rice.krad.inquiry.Inquirable;
23  import org.kuali.rice.krad.inquiry.InquirableImpl;
24  import org.kuali.rice.krad.uif.widget.Inquiry;
25  
26  import java.util.Collections;
27  import java.util.Map;
28  
29  /**
30   * InquirableImpl for {@link TravelCompanyCategory}.  This is a very limited implementation to make the
31   * demonstration page work.  Rather than query, it creates an instance of the data object manually.
32   *
33   * @author Kuali Rice Team (rice.collab@kuali.org)
34   */
35  public class TravelCompanyCategoryInquirable extends InquirableImpl implements Inquirable {
36  
37      @Override
38      public void setDataObjectClass(Class<?> dataObjectClass) {
39          if (!TravelCompanyCategory.class.equals(dataObjectClass)) {
40              throw new IllegalArgumentException("This Inquirable is only good for class TravelCompaniesCategory");
41          }
42      }
43  
44      @Override
45      public Object retrieveDataObject(Map<String, String> fieldValues) {
46          TravelCompanyCategory tcc = new TravelCompanyCategory();
47  
48          tcc.setName("Preferred Providers");
49  
50          QueryResults<TravelCompany> travelCompanies =
51                  KradDataServiceLocator.getDataObjectService().findMatching(TravelCompany.class,
52                          QueryByCriteria.Builder.create().build());
53          tcc.setCompanies(travelCompanies.getResults());
54  
55          return tcc;
56      }
57  
58      @Override
59      public void buildInquirableLink(Object dataObject, String propertyName, Inquiry inquiry) {
60          inquiry.buildInquiryLink(dataObject, propertyName, TravelCompanyCategory.class,
61                  Collections.<String,String>emptyMap());
62      }
63  }