Coverage Report - org.kuali.student.contract.model.util.HtmlContractServiceWriter
 
Classes in this File Line Coverage Branch Coverage Complexity
HtmlContractServiceWriter
0%
0/248
0%
0/36
3.714
 
 1  
 /*
 2  
  * Copyright 2011 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.osedu.org/licenses/ECL-2.0
 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.student.contract.model.util;
 17  
 
 18  
 import java.util.LinkedHashSet;
 19  
 import java.util.Set;
 20  
 
 21  
 import org.kuali.student.contract.model.Service;
 22  
 import org.kuali.student.contract.model.ServiceContractModel;
 23  
 import org.kuali.student.contract.model.ServiceMethod;
 24  
 import org.kuali.student.contract.model.ServiceMethodError;
 25  
 import org.kuali.student.contract.model.ServiceMethodParameter;
 26  
 import org.kuali.student.contract.model.XmlType;
 27  
 import org.kuali.student.contract.writer.HtmlWriter;
 28  
 
 29  
 /**
 30  
  *
 31  
  * @author nwright
 32  
  */
 33  
 public class HtmlContractServiceWriter
 34  
 {
 35  
 
 36  
  private Service service;
 37  
  private HtmlWriter writer;
 38  
  private ServiceContractModel model;
 39  
  private ModelFinder finder;
 40  
 
 41  
  public HtmlContractServiceWriter (Service service, String directory,
 42  
                                    ServiceContractModel model)
 43  0
  {
 44  0
   this.service = service;
 45  0
   this.writer = new HtmlWriter (directory, service.getName () + ".html",
 46  
                                 service.getName ());
 47  0
   this.model = model;
 48  0
   this.finder = new ModelFinder (this.model);
 49  0
  }
 50  
 
 51  
  public void write ()
 52  
  {
 53  0
   writer.print ("<a href=\"index.html\">home</a>");
 54  0
   this.writeStyleSheet ();
 55  0
   writer.writeTag ("h1", service.getName ());
 56  
 
 57  0
   writer.indentPrintln ("<table id=\"serviceMetaTable\">");
 58  0
   writer.indentPrintln ("<tr>");
 59  0
   writer.writeTag ("th", "class=h", "Name");
 60  0
   writer.writeTag ("td", "id=serviceName colspan=2", service.getKey ());
 61  0
   writer.indentPrintln ("</tr>");
 62  0
   writer.indentPrintln ("<tr>");
 63  0
   writer.writeTag ("th", "class=h", "Version");
 64  0
   writer.writeTag ("td", "id=serviceVersion colspan=2", service.getVersion ());
 65  0
   writer.indentPrintln ("</tr>");
 66  0
   writer.indentPrintln ("</table>");
 67  
 
 68  
 //  writer.indentPrintln ("<div class=\"panel\" style=\"border-width: 1px;\">");
 69  
 //  writer.indentPrintln ("<div class=\"panelHeader\" style=\"border-bottom-width: 1px;\">");
 70  0
   writer.indentPrintln ("<p>");
 71  0
   writer.indentPrintln ("<table id=\"serviceMetaTable\">");
 72  0
   writer.indentPrintln ("<tr>");
 73  0
   writer.indentPrintln ("<th class=h>");
 74  0
   writer.indentPrintln (service.getComments ());
 75  0
   writer.indentPrintln ("</th>");
 76  0
   writer.indentPrintln ("</tr>");
 77  0
   writer.indentPrintln ("</table>");
 78  
 
 79  
 //  writer.indentPrintln ("</div>");
 80  
 //  writer.indentPrintln ("</div>");
 81  
 
 82  0
   writer.indentPrintln (
 83  
     "<div class=\"panel\" style=\"background-color: rgb(255, 255, 255); border: 1px solid rgb(204, 204, 204);\">");
 84  0
   writer.indentPrintln (
 85  
     "<div class=\"panelHeader\" style=\"border-bottom: 1px solid rgb(204, 204, 204); background-color: rgb(238, 238, 238);\">");
 86  0
   writer.indentPrintln ("<b><a name=\"ListOfOperations\"></a>Operations</b>");
 87  0
   writer.indentPrintln (
 88  
     "</div><div class=\"panelContent\" style=\"background-color: rgb(255, 255, 255);\">");
 89  0
   writer.indentPrintln ("<ul>");
 90  0
   for (ServiceMethod method : finder.getServiceMethodsInService (
 91  
     service.getKey ()))
 92  
   {
 93  0
    writer.indentPrint ("<li>");
 94  0
    writer.print ("<a href=\"#" + method.getService () + "-" + method.getName ()
 95  
                  + "\">" + method.getName () + "</a>");
 96  0
    writer.print ("</li>");
 97  
   }
 98  0
   writer.indentPrintln ("</ul>");
 99  0
   writer.indentPrintln ("</div>");
 100  0
   writer.indentPrintln ("</div>");
 101  
 
 102  
   // now write out the root message structures
 103  0
   writer.indentPrintln (
 104  
     "<div class=\"panel\" style=\"background-color: rgb(255, 255, 255); border: 1px solid rgb(204, 204, 204);\">");
 105  0
   writer.indentPrintln (
 106  
     "<div class=\"panelHeader\" style=\"border-bottom: 1px solid rgb(204, 204, 204); background-color: rgb(238, 238, 238);\">");
 107  0
   writer.indentPrintln (
 108  
     "<b><a name=\"MainMessageStructures\"></a>Main Message Structures</b>");
 109  0
   writer.indentPrintln (
 110  
     "</div><div class=\"panelContent\" style=\"background-color: rgb(255, 255, 255);\">");
 111  
 
 112  0
   writer.indentPrintln ("<ul>");
 113  0
   for (XmlType type : this.calcComplexRootXmlTypes ())
 114  
   {
 115  0
    writer.indentPrint ("<li>");
 116  0
    writer.print ("<a href=\"" + type.getName () + ".html"
 117  
                  + "\">" + type.getName () + "</a>");
 118  0
    writer.print ("</li>");
 119  
   }
 120  0
   writer.indentPrintln ("</ul>");
 121  
 
 122  
 
 123  0
   for (ServiceMethod method : finder.getServiceMethodsInService (
 124  
     service.getKey ()))
 125  
   {
 126  0
    this.writeMethod (method);
 127  
   }
 128  
 
 129  0
   writer.writeHeaderBodyAndFooterOutToFile ();
 130  0
  }
 131  
 
 132  
  private Set<XmlType> calcComplexRootXmlTypes ()
 133  
  {
 134  0
   return calcComplexRootXmlTypes (model, service.getKey ());
 135  
  }
 136  
 
 137  
  public static Set<XmlType> calcComplexRootXmlTypes (ServiceContractModel mdl, String serviceOptionaFilter)
 138  
  {
 139  0
   ModelFinder fndr = new ModelFinder (mdl);
 140  0
   Set<XmlType> types = new LinkedHashSet ();
 141  0
   for (ServiceMethod method : mdl.getServiceMethods ())
 142  
   {
 143  0
    if (serviceOptionaFilter != null)
 144  
    {
 145  0
     if ( ! method.getService ().equalsIgnoreCase (serviceOptionaFilter))
 146  
     {
 147  0
      continue;
 148  
     }
 149  
    }
 150  0
    XmlType type = fndr.findXmlType (method.getReturnValue ().getType ());
 151  0
    if (type != null)
 152  
    {
 153  0
     if (type.getPrimitive ().equalsIgnoreCase (XmlType.COMPLEX))
 154  
     {
 155  0
      types.add (type);
 156  
     }
 157  
    }
 158  
 
 159  0
    for (ServiceMethodParameter param : method.getParameters ())
 160  
    {
 161  0
     type = fndr.findXmlType (param.getType ());
 162  0
     if (type != null)
 163  
     {
 164  0
      if (type.getPrimitive ().equalsIgnoreCase (XmlType.COMPLEX))
 165  
      {
 166  0
       types.add (type);
 167  
      }
 168  
     }
 169  
     break;
 170  
    }
 171  0
   }
 172  0
   return types;
 173  
  }
 174  
 
 175  
  public void writeMethod (ServiceMethod method)
 176  
  {
 177  0
   writer.indentPrintln ("<p>");
 178  0
   writer.indentPrintln ("<a name=\"" + method.getService () + "-"
 179  
                         + method.getName () + "\"></a>");
 180  0
   writer.indentPrintln ("<p>");
 181  0
   writer.indentPrintln ("<table class=\"methodTable\">");
 182  
 
 183  0
   writer.indentPrintln ("<tr>");
 184  0
   writer.writeTag ("th", "class=h", "Method");
 185  0
   writer.writeTag ("th", "class=h colspan=3 class=\"methodName\"",
 186  
                    method.getName ());
 187  0
   writer.indentPrintln ("</tr>");
 188  
 
 189  0
   writer.indentPrintln ("<tr>");
 190  0
   writer.writeTag ("th", "class=h", "Description");
 191  0
   writer.writeTag ("td", "colspan=3 class=\"methodDesc\"",
 192  
                    method.getDescription ());
 193  0
   writer.indentPrintln ("</tr>");
 194  
 
 195  0
   if (method.getParameters ().isEmpty ())
 196  
   {
 197  0
    writer.indentPrintln ("<tr>");
 198  0
    writer.writeTag ("th", "class=h", "Parameters");
 199  0
    writer.writeTag ("td", "class=\"methodParamType\"", "None");
 200  0
    writer.writeTag ("td", "class=\"methodParamName\"", "None");
 201  0
    writer.writeTag ("td", "class=\"methodParamDesc\"", "No Parameters");
 202  0
    writer.indentPrintln ("</tr>");
 203  
   }
 204  
   else
 205  
   {
 206  0
    boolean firstTime = true;
 207  0
    for (ServiceMethodParameter param : method.getParameters ())
 208  
    {
 209  0
     writer.indentPrintln ("<tr>");
 210  0
     if (firstTime)
 211  
     {
 212  0
      writer.writeTag ("th", "class=h rowspan=" + method.getParameters ().size (),
 213  
                       "Parameters");
 214  0
      firstTime = false;
 215  
     }
 216  0
     writer.indentPrint ("<td class=\"methodParamType\">");
 217  0
     writer.indentPrintln ("<a href=\"" + stripListFromType (param.getType ())
 218  
                           + ".html" + "\">"
 219  
                           + param.getType () + "</a>");
 220  0
     writer.indentPrint ("</td>");
 221  0
     writer.writeTag ("td", "class=\"methodParamName\"", param.getName ());
 222  0
     writer.writeTag ("td", "class=\"methodParamDesc\"", param.getDescription ());
 223  0
     writer.indentPrintln ("</tr>");
 224  
    }
 225  
   }
 226  0
   writer.indentPrintln ("<tr>");
 227  0
   writer.writeTag ("th", "class=h", "Return");
 228  0
   writer.indentPrint ("<td colspan=2 class=\"methodReturnType\">");
 229  0
   writer.indentPrintln ("<a href=\"" + stripListFromType (
 230  
     method.getReturnValue ().getType ())
 231  
                         + ".html" + "\">"
 232  
                         + method.getReturnValue ().getType () + "</a>");
 233  0
   writer.indentPrint ("</td>");
 234  0
   writer.writeTag ("td", "class=\"methodReturnDesc\"",
 235  
                    method.getReturnValue ().getDescription ());
 236  0
   writer.indentPrintln ("</tr>");
 237  0
   writer.indentPrintln ("</tr>");
 238  
 
 239  0
   if (method.getErrors ().isEmpty ())
 240  
   {
 241  0
    writer.indentPrintln ("<tr>");
 242  0
    writer.writeTag ("th", "class=h", "Errors");
 243  0
    writer.writeTag ("td", "class=\"methodErrorType\" colspan=2", "NONE");
 244  0
    writer.writeTag ("td", "class=\"methodErrorDesc\"", "No Errors");
 245  0
    writer.indentPrintln ("</tr>");
 246  
   }
 247  
   else
 248  
   {
 249  0
    boolean firstTime = true;
 250  0
    for (ServiceMethodError error : method.getErrors ())
 251  
    {
 252  0
     writer.indentPrintln ("<tr>");
 253  0
     if (firstTime)
 254  
     {
 255  0
      writer.writeTag ("th", "class=h rowspan=" + method.getErrors ().size (),
 256  
                       "Errors");
 257  0
      firstTime = false;
 258  
     }
 259  0
     writer.writeTag ("td", "class=\"methodErrorType\" colspan=2",
 260  
                      error.getType ()); // TODO wrap in link to type
 261  0
     writer.writeTag ("td", "class=\"methodErrorDesc\"", error.getDescription ());
 262  0
     writer.indentPrintln ("</tr>");
 263  
    }
 264  
   }
 265  0
   writer.indentPrintln ("</table>");
 266  0
   writer.indentPrintln ("<p>");
 267  0
   writer.indentPrintln ("<a href=\"#ListOfOperations\">Back to Operations</a>");
 268  0
   writer.indentPrintln ("<p>");
 269  0
  }
 270  
 
 271  
  private String stripListFromType (String type)
 272  
  {
 273  0
   if (type.endsWith ("List"))
 274  
   {
 275  0
    return type.substring (0, type.length () - "List".length ());
 276  
   }
 277  0
   return type;
 278  
  }
 279  
 
 280  
  public void writeStyleSheet ()
 281  
  {
 282  0
   writer.indentPrintln ("<style type=\"text/css\">");
 283  0
   writer.indentPrintln ("");
 284  0
   writer.indentPrintln ("table#serviceMetaTable {");
 285  0
   writer.indentPrintln ("border-collapse:collapse;");
 286  0
   writer.indentPrintln ("border:1px solid #000000;");
 287  0
   writer.indentPrintln ("width:95%;");
 288  0
   writer.indentPrintln ("}");
 289  0
   writer.indentPrintln ("table#serviceMetaTable th.h {");
 290  0
   writer.indentPrintln ("border:1px solid #000000;");
 291  0
   writer.indentPrintln ("background-color:#eeeeee;");
 292  0
   writer.indentPrintln ("width:15%;");
 293  0
   writer.indentPrintln ("}");
 294  0
   writer.indentPrintln ("table#serviceMetaTable td#serviceName {");
 295  0
   writer.indentPrintln ("border:1px solid #000000;");
 296  0
   writer.indentPrintln ("width:85%;");
 297  0
   writer.indentPrintln ("}");
 298  0
   writer.indentPrintln ("table#serviceMetaTable td#serviceVersion {");
 299  0
   writer.indentPrintln ("border:1px solid #000000;");
 300  0
   writer.indentPrintln ("width:70%;");
 301  0
   writer.indentPrintln ("}");
 302  0
   writer.indentPrintln ("table#serviceMetaTable td#serviceVersionHistory {");
 303  0
   writer.indentPrintln ("border:1px solid #000000;");
 304  0
   writer.indentPrintln ("width:15%;");
 305  0
   writer.indentPrintln ("}");
 306  0
   writer.indentPrintln ("");
 307  0
   writer.indentPrintln ("</style>");
 308  
 
 309  
 
 310  0
   writer.indentPrintln ("<style type=\"text/css\">");
 311  0
   writer.indentPrintln ("");
 312  0
   writer.indentPrintln ("table.methodTable {");
 313  0
   writer.indentPrintln ("border-collapse:collapse;");
 314  0
   writer.indentPrintln ("border:1px solid #000000;");
 315  0
   writer.indentPrintln ("width:95%;");
 316  0
   writer.indentPrintln ("}");
 317  0
   writer.indentPrintln ("");
 318  0
   writer.indentPrintln ("table.methodTable td.d {");
 319  0
   writer.indentPrintln ("border:1px solid #000000;");
 320  0
   writer.indentPrintln ("}");
 321  0
   writer.indentPrintln ("");
 322  0
   writer.indentPrintln ("table.methodTable th.h {");
 323  0
   writer.indentPrintln ("border:1px solid #000000;");
 324  0
   writer.indentPrintln ("background-color:#eeeeee;");
 325  0
   writer.indentPrintln ("width:15%;");
 326  0
   writer.indentPrintln ("}");
 327  0
   writer.indentPrintln ("");
 328  0
   writer.indentPrintln ("table.methodTable td.methodName {");
 329  0
   writer.indentPrintln ("border:1px solid #000000;");
 330  0
   writer.indentPrintln ("background-color:#f2f2f2;");
 331  0
   writer.indentPrintln ("color:#222222;");
 332  0
   writer.indentPrintln ("text-align:center;");
 333  0
   writer.indentPrintln ("width:85%;");
 334  0
   writer.indentPrintln ("font-weight:bold;");
 335  0
   writer.indentPrintln ("font-style:italic;");
 336  0
   writer.indentPrintln ("}");
 337  0
   writer.indentPrintln ("");
 338  0
   writer.indentPrintln ("table.methodTable td.methodDesc {");
 339  0
   writer.indentPrintln ("border:1px solid #000000;");
 340  0
   writer.indentPrintln ("width:85%;");
 341  0
   writer.indentPrintln ("}");
 342  0
   writer.indentPrintln ("");
 343  0
   writer.indentPrintln ("table.methodTable td.methodParamType {");
 344  0
   writer.indentPrintln ("border:1px solid #000000;");
 345  0
   writer.indentPrintln ("width:21%;");
 346  0
   writer.indentPrintln ("font-style:italic;");
 347  0
   writer.indentPrintln ("}");
 348  0
   writer.indentPrintln ("table.methodTable td.methodParamName {");
 349  0
   writer.indentPrintln ("border:1px solid #000000;");
 350  0
   writer.indentPrintln ("width:21%;");
 351  0
   writer.indentPrintln ("}");
 352  0
   writer.indentPrintln ("table.methodTable td.methodParamDesc {");
 353  0
   writer.indentPrintln ("border:1px solid #000000;");
 354  0
   writer.indentPrintln ("width:43%;");
 355  0
   writer.indentPrintln ("}");
 356  0
   writer.indentPrintln ("table.methodTable td.methodReturnType {");
 357  0
   writer.indentPrintln ("border:1px solid #000000;");
 358  0
   writer.indentPrintln ("width:42%;");
 359  0
   writer.indentPrintln ("font-style:italic;");
 360  0
   writer.indentPrintln ("}");
 361  0
   writer.indentPrintln ("");
 362  0
   writer.indentPrintln ("table.methodTable td.methodReturnDesc {");
 363  0
   writer.indentPrintln ("border:1px solid #000000;");
 364  0
   writer.indentPrintln ("width:43%;");
 365  0
   writer.indentPrintln ("}");
 366  0
   writer.indentPrintln ("");
 367  0
   writer.indentPrintln ("table.methodTable td.methodErrors {");
 368  0
   writer.indentPrintln ("border:1px solid #000000;");
 369  0
   writer.indentPrintln ("width:85%;");
 370  0
   writer.indentPrintln ("}");
 371  0
   writer.indentPrintln ("");
 372  0
   writer.indentPrintln ("");
 373  0
   writer.indentPrintln ("table.methodTable td.methodErrorType {");
 374  0
   writer.indentPrintln ("border:1px solid #000000;");
 375  0
   writer.indentPrintln ("width:42%;");
 376  0
   writer.indentPrintln ("font-style:italic;");
 377  0
   writer.indentPrintln ("}");
 378  0
   writer.indentPrintln ("table.methodTable td.methodErrorDesc {");
 379  0
   writer.indentPrintln ("border:1px solid #000000;");
 380  0
   writer.indentPrintln ("width:43%;");
 381  0
   writer.indentPrintln ("}");
 382  0
   writer.indentPrintln ("");
 383  0
   writer.indentPrintln ("table.methodTable td.capabilityDesc {");
 384  0
   writer.indentPrintln ("border:1px solid #000000;");
 385  0
   writer.indentPrintln ("background:#ffffff;");
 386  0
   writer.indentPrintln ("}");
 387  0
   writer.indentPrintln ("");
 388  0
   writer.indentPrintln ("table.methodTable td.usecaseDesc {");
 389  0
   writer.indentPrintln ("border:1px solid #000000;");
 390  0
   writer.indentPrintln ("background:#ffffff;");
 391  0
   writer.indentPrintln ("}");
 392  0
   writer.indentPrintln ("");
 393  0
   writer.indentPrintln ("table.methodTable td.commentsDesc {");
 394  0
   writer.indentPrintln ("border:1px solid #000000;");
 395  0
   writer.indentPrintln ("background:#ffffff;");
 396  0
   writer.indentPrintln ("}");
 397  0
   writer.indentPrintln ("</style>");
 398  
 
 399  0
  }
 400  
 }