Coverage Report - org.kuali.student.contract.model.util.HtmlContractMessageStructureWriter
 
Classes in this File Line Coverage Branch Coverage Complexity
HtmlContractMessageStructureWriter
0%
0/246
0%
0/38
3.889
 
 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.MessageStructure;
 22  
 import org.kuali.student.contract.model.ServiceContractModel;
 23  
 import org.kuali.student.contract.model.ServiceMethod;
 24  
 import org.kuali.student.contract.model.ServiceMethodParameter;
 25  
 import org.kuali.student.contract.model.XmlType;
 26  
 import org.kuali.student.contract.writer.HtmlWriter;
 27  
 
 28  
 /**
 29  
  *
 30  
  * @author nwright
 31  
  */
 32  
 public class HtmlContractMessageStructureWriter
 33  
 {
 34  
 
 35  
  private XmlType xmlType;
 36  
  private HtmlWriter writer;
 37  
  private ServiceContractModel model;
 38  
  private ModelFinder finder;
 39  
 
 40  
  public HtmlContractMessageStructureWriter (XmlType xmlType, String directory,
 41  
                                             ServiceContractModel model)
 42  0
  {
 43  0
   this.xmlType = xmlType;
 44  0
   this.writer = new HtmlWriter (directory, xmlType.getName () + ".html",
 45  
                                 xmlType.getName ());
 46  0
   this.model = model;
 47  0
   this.finder = new ModelFinder (this.model);
 48  0
  }
 49  
 
 50  
  public void write ()
 51  
  {
 52  0
   writer.print ("<a href=\"index.html\">home</a>");
 53  0
   this.writeStyleSheet ();
 54  0
   writer.writeTag ("h1", xmlType.getName ());
 55  
 
 56  0
   writer.indentPrintln ("<table id=\"structureMetaTable\">");
 57  0
   writer.indentPrintln ("<tr>");
 58  0
   writer.writeTag ("th", "class=h", "Name");
 59  0
   writer.writeTag ("td", "id=structureName colspan=2", xmlType.getName ());
 60  0
   writer.indentPrintln ("</tr>");
 61  0
   writer.indentPrintln ("<tr>");
 62  0
   writer.writeTag ("th", "class=h", "Version");
 63  0
   writer.writeTag ("td", "id=structureVersion colspan=2", xmlType.getVersion ());
 64  0
   writer.indentPrintln ("</tr>");
 65  0
   writer.indentPrintln ("<tr>");
 66  0
   writer.writeTag ("th", "rowspan=3 class=h", "Usage");
 67  0
   writer.indentPrint ("<td id=\"structureVersion\" colspan=2>");
 68  0
   for (String servKey : xmlType.getService ().split (","))
 69  
   {
 70  0
    writer.indentPrintln ("<a href=\"" + servKey + "Service" + ".html" + "\">"
 71  
                          + servKey + "Service" + "</a>");
 72  
   }
 73  0
   writer.indentPrint ("</td>");
 74  
 
 75  0
   writer.indentPrintln ("</tr>");
 76  0
   writer.indentPrintln ("<tr>");
 77  0
   writer.writeTag ("th", "class=h", "");
 78  0
   writer.indentPrint ("<td id=\"structureVersion\" colspan=2>");
 79  0
   for (ServiceMethod method : this.calcUsageByMethods (xmlType))
 80  
   {
 81  0
    writer.indentPrintln ("<a href=\"" + method.getService () + "Service"
 82  
                          + ".html" + "#" + method.getService () + "-"
 83  
                          + method.getName () + "\">"
 84  
                          + method.getName () + "</a>");
 85  
   }
 86  0
   writer.indentPrint ("</td>");
 87  0
   writer.indentPrintln ("</tr>");
 88  0
   writer.indentPrintln ("<tr>");
 89  0
   writer.writeTag ("th", "class=h", "");
 90  0
   writer.indentPrint ("<td id=\"structureVersion\" colspan=2>");
 91  0
   for (String xmlTypeName : this.calcOtherXmlTypeUsages (xmlType))
 92  
   {
 93  0
    XmlType usageType = finder.findXmlType (xmlTypeName);
 94  0
    if (usageType == null)
 95  
    {
 96  0
     throw new NullPointerException ("Coud not find XmlType with name="
 97  
                                     + xmlTypeName);
 98  
    }
 99  0
    writer.indentPrintln ("<a href=\"" + usageType.getName () + ".html" + "\">"
 100  
                          + usageType.getName () + "</a>");
 101  0
   }
 102  0
   writer.indentPrint ("</td>");
 103  0
   writer.indentPrintln ("</tr>");
 104  
 
 105  0
   writer.writeTag ("th", "class=h", "Type");
 106  0
   writer.writeTag ("td", "id=structureVersion colspan=2",
 107  
                    xmlType.getPrimitive ());
 108  0
   writer.indentPrintln ("</tr>");
 109  0
   writer.indentPrintln ("</table>");
 110  
 
 111  0
   writer.writeTag ("h2", "Description");
 112  0
   writer.indentPrintln (xmlType.getDesc ());
 113  
 
 114  0
   if ( ! xmlType.getPrimitive ().equals (XmlType.COMPLEX))
 115  
   {
 116  0
    return;
 117  
   }
 118  0
   writer.indentPrintln (
 119  
     "<h2><a name=\"StructureDefinition\"></a>Structure Definition</h2>");
 120  
 
 121  
 
 122  0
   writer.indentPrintln ("<table class=\"structTable\">");
 123  0
   writer.indentPrintln ("<tr>");
 124  0
   writer.indentPrintln ("<th class=\"h\">ShortName</th>");
 125  0
   writer.indentPrintln ("<th class=\"h\">Name</th>");
 126  0
   writer.indentPrintln ("<th class=\"h\">Type</th>");
 127  0
   writer.indentPrintln ("<th class=\"h\">Description</th>");
 128  0
   writer.indentPrintln ("<th class=\"h\">Required</th>");
 129  0
   writer.indentPrintln ("<th class=\"h\">Cardinality</th>");
 130  0
   writer.indentPrintln ("<th class=\"h\">XML Attribute?</th>");
 131  0
   writer.indentPrintln ("<th class=\"h\">Data Team Status</th>");
 132  0
   writer.indentPrintln ("<th class=\"h\">Comments/Feedback</th>");
 133  0
   writer.indentPrintln ("</tr>");
 134  
 
 135  0
   for (MessageStructure ms : finder.findMessageStructures (xmlType.getName ()))
 136  
   {
 137  0
    this.writeMessageStructure (ms);
 138  
   }
 139  0
   writer.indentPrintln ("</table>");
 140  0
   writer.writeHeaderBodyAndFooterOutToFile ();
 141  0
  }
 142  
 
 143  
  private Set<ServiceMethod> calcUsageByMethods (XmlType xmlType)
 144  
  {
 145  0
   Set<ServiceMethod> methods = new LinkedHashSet ();
 146  0
   for (ServiceMethod method : model.getServiceMethods ())
 147  
   {
 148  0
    if (method.getReturnValue ().getType ().equalsIgnoreCase (xmlType.getName ()))
 149  
    {
 150  0
     methods.add (method);
 151  0
     continue;
 152  
    }
 153  0
    for (ServiceMethodParameter param : method.getParameters ())
 154  
    {
 155  0
     if (param.getType ().equalsIgnoreCase (xmlType.getName ()))
 156  
     {
 157  0
      methods.add (method);
 158  0
      break;
 159  
     }
 160  
    }
 161  
   }
 162  0
   return methods;
 163  
  }
 164  
 
 165  
  private Set<String> calcOtherXmlTypeUsages (XmlType xmlType)
 166  
  {
 167  0
   return calcOtherXmlTypeUsages (model, xmlType);
 168  
  }
 169  
 
 170  
  public static Set<String> calcOtherXmlTypeUsages (ServiceContractModel mdl,
 171  
                                                    XmlType xmlType)
 172  
  {
 173  0
   Set<String> xmlTypeNames = new LinkedHashSet ();
 174  0
   for (MessageStructure ms : mdl.getMessageStructures ())
 175  
   {
 176  0
    if (ms.getType () == null)
 177  
    {
 178  0
     throw new NullPointerException (ms.getId () + " has no type set");
 179  
    }
 180  0
    if (ms.getType ().equalsIgnoreCase (xmlType.getName ()))
 181  
    {
 182  0
     xmlTypeNames.add (ms.getXmlObject ());
 183  
    }
 184  
   }
 185  0
   return xmlTypeNames;
 186  
  }
 187  
 
 188  
  private void writeMessageStructure (MessageStructure ms)
 189  
  {
 190  0
   writer.indentPrintln ("<tr>");
 191  0
   writer.writeTag ("td", "class=\"structSName\"", ms.getShortName ());
 192  0
   writer.writeTag ("td", "class=\"structLName\"", ms.getName ());
 193  0
   XmlType subType = finder.findXmlType (this.stripListFromType (ms.getType ()));
 194  0
   if (subType == null)
 195  
   {
 196  0
    for (XmlType xmlt : model.getXmlTypes ())
 197  
    {
 198  0
     System.out.println (this.getClass ().getSimpleName () + ": "
 199  
                         + xmlt.getName ());
 200  
    }
 201  0
    throw new NullPointerException (ms.getXmlObject () + "." + ms.getShortName ()
 202  
                                    + " has type " + ms.getType ()
 203  
                                    + " was not found in list of known types");
 204  
   }
 205  0
   if (subType.getPrimitive ().equals (XmlType.COMPLEX))
 206  
   {
 207  0
    writer.indentPrint ("<td class=\"structType\">");
 208  0
    writer.indentPrintln ("<a href=\"" + subType.getName () + ".html" + "\">"
 209  
                          + ms.getType () + "</a>");
 210  0
    writer.indentPrint ("</td>");
 211  
   }
 212  
   else
 213  
   {
 214  0
    writer.writeTag ("td", "class=\"structType\"", ms.getType ());
 215  
   }
 216  0
   writer.writeTag ("td", "class=\"structDesc\"", missingData (
 217  
     ms.getDescription ()));
 218  0
   writer.writeTag ("td", "class=\"structOpt\"", ms.getOptional ());
 219  0
   writer.writeTag ("td", "class=\"structCard\"", ms.getCardinality ());
 220  0
   writer.writeTag ("td", "class=\"structAttr\"", ms.getXmlAttribute ());
 221  0
   writer.writeTag ("td", "class=\"structStatus\"", ms.getStatus ());
 222  0
   writer.writeTag ("td", "class=\"commentsDesc\"", ms.getFeedback ());
 223  0
   writer.indentPrintln ("</tr>");
 224  
 
 225  
 //  writer.indentPrintln ("</table>");
 226  
 //  writer.indentPrintln ("<p>");
 227  
 
 228  
 //  writer.indentPrintln ("<p>");
 229  0
  }
 230  
 
 231  
  private String missingData (String str)
 232  
  {
 233  0
   if (str == null)
 234  
   {
 235  0
    return "???";
 236  
   }
 237  0
   if (str.trim ().isEmpty ())
 238  
   {
 239  0
    return "???";
 240  
   }
 241  0
   return str;
 242  
  }
 243  
 
 244  
  private String stripListFromType (String type)
 245  
  {
 246  0
   if (type.endsWith ("List"))
 247  
   {
 248  0
    return type.substring (0, type.length () - "List".length ());
 249  
   }
 250  0
   return type;
 251  
  }
 252  
 
 253  
  public void writeStyleSheet ()
 254  
  {
 255  0
   writer.indentPrintln ("<style type=\"text/css\">");
 256  0
   writer.indentPrintln ("");
 257  0
   writer.indentPrintln ("table#structureMetaTable {");
 258  0
   writer.indentPrintln ("border-collapse:collapse;");
 259  0
   writer.indentPrintln ("border:1px solid #000000;");
 260  0
   writer.indentPrintln ("width:95%;");
 261  0
   writer.indentPrintln ("}");
 262  0
   writer.indentPrintln ("table#structureMetaTable th.h {");
 263  0
   writer.indentPrintln ("border:1px solid #000000;");
 264  0
   writer.indentPrintln ("background-color:#eeeeee;");
 265  0
   writer.indentPrintln ("width:15%;");
 266  0
   writer.indentPrintln ("}");
 267  0
   writer.indentPrintln ("table#structureMetaTable td#structureName {");
 268  0
   writer.indentPrintln ("border:1px solid #000000;");
 269  0
   writer.indentPrintln ("width:85%;");
 270  0
   writer.indentPrintln ("}");
 271  0
   writer.indentPrintln ("table#structureMetaTable td#structureVersion {");
 272  0
   writer.indentPrintln ("border:1px solid #000000;");
 273  0
   writer.indentPrintln ("width:70%;");
 274  0
   writer.indentPrintln ("}");
 275  0
   writer.indentPrintln ("table#structureMetaTable td#structureVersionHistory {");
 276  0
   writer.indentPrintln ("border:1px solid #000000;");
 277  0
   writer.indentPrintln ("width:15%;");
 278  0
   writer.indentPrintln ("}");
 279  0
   writer.indentPrintln ("");
 280  0
   writer.indentPrintln ("</style>");
 281  
 
 282  0
   writer.indentPrintln ("<style type=\"text/css\">");
 283  0
   writer.indentPrintln ("");
 284  0
   writer.indentPrintln ("table.structTable {");
 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 ("");
 290  0
   writer.indentPrintln ("table.structTable td.d {");
 291  0
   writer.indentPrintln ("border:1px solid #000000;");
 292  0
   writer.indentPrintln ("}");
 293  0
   writer.indentPrintln ("");
 294  0
   writer.indentPrintln ("table.structTable th.h {");
 295  0
   writer.indentPrintln ("border:1px solid #000000;");
 296  0
   writer.indentPrintln ("background-color:#eeeeee;");
 297  0
   writer.indentPrintln ("}");
 298  0
   writer.indentPrintln ("");
 299  0
   writer.indentPrintln ("table.structTable td.structSName {");
 300  0
   writer.indentPrintln ("border:1px solid #000000;");
 301  0
   writer.indentPrintln ("background-color:#f2f2f2;");
 302  0
   writer.indentPrintln ("color:#222222;");
 303  0
   writer.indentPrintln ("text-align:left;");
 304  0
   writer.indentPrintln ("vertical-align:top;");
 305  0
   writer.indentPrintln ("font-weight:bold;");
 306  0
   writer.indentPrintln ("font-style:italic;");
 307  0
   writer.indentPrintln ("");
 308  0
   writer.indentPrintln ("}");
 309  0
   writer.indentPrintln ("");
 310  0
   writer.indentPrintln ("table.structTable td.structLName {");
 311  0
   writer.indentPrintln ("border:1px solid #000000;");
 312  0
   writer.indentPrintln ("background:#ffffff;");
 313  0
   writer.indentPrintln ("vertical-align:top;");
 314  0
   writer.indentPrintln ("");
 315  0
   writer.indentPrintln ("}");
 316  0
   writer.indentPrintln ("");
 317  0
   writer.indentPrintln ("table.structTable td.structType {");
 318  0
   writer.indentPrintln ("border:1px solid #000000;");
 319  0
   writer.indentPrintln ("background:#ffffff;");
 320  0
   writer.indentPrintln ("vertical-align:top;");
 321  0
   writer.indentPrintln ("font-style:italic;");
 322  0
   writer.indentPrintln ("");
 323  0
   writer.indentPrintln ("}");
 324  0
   writer.indentPrintln ("");
 325  0
   writer.indentPrintln ("table.structTable td.structDesc {");
 326  0
   writer.indentPrintln ("border:1px solid #000000;");
 327  0
   writer.indentPrintln ("background:#ffffff;");
 328  0
   writer.indentPrintln ("vertical-align:top;");
 329  0
   writer.indentPrintln ("");
 330  0
   writer.indentPrintln ("}");
 331  0
   writer.indentPrintln ("");
 332  0
   writer.indentPrintln ("table.structTable td.structOpt {");
 333  0
   writer.indentPrintln ("border:1px solid #000000;");
 334  0
   writer.indentPrintln ("background:#ffffff;");
 335  0
   writer.indentPrintln ("vertical-align:top;");
 336  0
   writer.indentPrintln ("text-align: center;");
 337  0
   writer.indentPrintln ("}");
 338  0
   writer.indentPrintln ("");
 339  0
   writer.indentPrintln ("table.structTable td.structReq {");
 340  0
   writer.indentPrintln ("border:1px solid #000000;");
 341  0
   writer.indentPrintln ("background:#ccccff;");
 342  0
   writer.indentPrintln ("vertical-align:top;");
 343  0
   writer.indentPrintln ("text-align: center;");
 344  0
   writer.indentPrintln ("}");
 345  0
   writer.indentPrintln ("");
 346  0
   writer.indentPrintln ("");
 347  0
   writer.indentPrintln ("table.structTable td.structCard {");
 348  0
   writer.indentPrintln ("border:1px solid #000000;");
 349  0
   writer.indentPrintln ("background:#ffffff;");
 350  0
   writer.indentPrintln ("vertical-align:top;");
 351  0
   writer.indentPrintln ("text-align: center;");
 352  0
   writer.indentPrintln ("}");
 353  0
   writer.indentPrintln ("");
 354  0
   writer.indentPrintln ("table.structTable td.structAttr {");
 355  0
   writer.indentPrintln ("border:1px solid #000000;");
 356  0
   writer.indentPrintln ("background:#ffffff;");
 357  0
   writer.indentPrintln ("vertical-align:top;");
 358  0
   writer.indentPrintln ("text-align: center;");
 359  0
   writer.indentPrintln ("}");
 360  0
   writer.indentPrintln ("");
 361  0
   writer.indentPrintln ("table.structTable td.structElem {");
 362  0
   writer.indentPrintln ("border:1px solid #000000;");
 363  0
   writer.indentPrintln ("background:#ccccff;");
 364  0
   writer.indentPrintln ("vertical-align:top;");
 365  0
   writer.indentPrintln ("text-align: center;");
 366  0
   writer.indentPrintln ("}");
 367  0
   writer.indentPrintln ("");
 368  0
   writer.indentPrintln ("table.structTable td.structStatus {");
 369  0
   writer.indentPrintln ("border:1px solid #000000;");
 370  0
   writer.indentPrintln ("background:#ffffff;");
 371  0
   writer.indentPrintln ("vertical-align:top;");
 372  0
   writer.indentPrintln ("text-align: center;");
 373  0
   writer.indentPrintln ("");
 374  0
   writer.indentPrintln ("}");
 375  0
   writer.indentPrintln ("");
 376  0
   writer.indentPrintln ("table.structTable td.commentsDesc {");
 377  0
   writer.indentPrintln ("border:1px solid #000000;");
 378  0
   writer.indentPrintln ("background:#ffffff;");
 379  0
   writer.indentPrintln ("vertical-align:top;");
 380  0
   writer.indentPrintln ("");
 381  0
   writer.indentPrintln ("}");
 382  0
   writer.indentPrintln ("");
 383  0
   writer.indentPrintln ("");
 384  0
   writer.indentPrintln ("</style>");
 385  
 
 386  
 
 387  0
  }
 388  
 }