View Javadoc

1   /**
2    * Copyright 2005-2013 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 edu.sampleu.demo.kitchensink;
17  
18  import javax.ws.rs.GET;
19  import javax.ws.rs.Path;
20  
21  /**
22   * Test service exposed through REST and connected to a {@link org.kuali.rice.krad.uif.element.DataTable}
23   * component in the UIF
24   *
25   * @author Kuali Rice Team (rice.collab@kuali.org)
26   */
27  @Path("/")
28  public class DataTableRestServiceTestImpl {
29  
30      /**
31       * Returns a string of data in JSON format for populating the table
32       *
33       * @return String json data string
34       */
35      @GET
36      @Path("/TableData")
37      public String getTableData() {
38          StringBuilder sb = new StringBuilder();
39  
40          sb.append("{ \"aaData\": [\n");
41  
42          for (int i = 0; i < 800; i++) {
43              sb.append("[\"CHEM " + i + "\",");
44              // add a hidden script to verify that it runs successfully
45              if (i % 10 == 0) {
46                  String spanId = "nm_row_" + i;
47                  sb.append("\"<span id='" + spanId + "'>INTRODUCTION TO GENERAL CHEMISTRY</span>");
48                  sb.append("<input type='hidden' name='script' value=\\\"jQuery('#"
49                          + spanId + "').attr('style', 'color:green');\\\"/>\"");
50                  sb.append(",");
51              } else {
52                  sb.append("\"INTRODUCTION TO GENERAL CHEMISTRY\",");
53              }
54              sb.append("\"3\",");
55              sb.append("\"AU\",");
56              sb.append("\"NW\",");
57              sb.append("\"Neal\",");
58              sb.append("\"MWF\",");
59              sb.append("\"300.00\",");
60              sb.append("\"3\",");
61              sb.append("\"100\"]");
62  
63              if (i < 799) {
64                  sb.append(",\n");
65              }
66          }
67  
68          sb.append("\n] }");
69  
70          return sb.toString();
71      }
72  }