Coverage Report - rs.mgifos.mosquito.model.MetaColumn
 
Classes in this File Line Coverage Branch Coverage Complexity
MetaColumn
34%
31/92
0%
0/14
0
 
 1  
 /* 
 2  
  * This file is part of Mosquito meta-loader.
 3  
  *
 4  
  * Mosquito meta-loader is free software; you can redistribute it and/or modify
 5  
  * it under the terms of the GNU Lesser General Public License as published by
 6  
  * the Free Software Foundation; either version 3 of the License, or
 7  
  * (at your option) any later version.
 8  
  *
 9  
  * Mosquito meta-loader is distributed in the hope that it will be useful,
 10  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 12  
  * GNU Lesser General Public License for more details.
 13  
  *
 14  
  * You should have received a copy of the GNU Lesser General Public License
 15  
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 16  
  */
 17  
 
 18  
 package rs.mgifos.mosquito.model;
 19  
 
 20  
 import java.util.Iterator;
 21  
 import java.util.LinkedHashMap;
 22  
 import java.util.Map;
 23  
 import java.util.Set;
 24  
 
 25  
 /**
 26  
  *
 27  
  * @author <a href="mailto:nikola.petkov@gmail.com">Nikola Petkov &lt;nikola.petkov@gmail.com&gt;</a>
 28  
  */
 29  
 public class MetaColumn {
 30  
     protected String code;
 31  
 
 32  
     protected String comment;
 33  
 
 34  18
     protected MetaColumn fkColParent = null;
 35  
 
 36  
     protected String jClassName;
 37  
 
 38  
     protected int length;
 39  
 
 40  18
     protected boolean mandatory = false;
 41  
 
 42  
     protected String name;
 43  
 
 44  18
     protected MetaKey parentKey = null;
 45  
 
 46  
     protected String parentTable;
 47  
 
 48  
     protected int precision;
 49  
 
 50  
     protected String defaultVal;
 51  
 
 52  18
     protected LinkedHashMap<String, String> lhmListOfVals = new LinkedHashMap<String, String>();
 53  
 
 54  
     /**
 55  
      * Creates full initialized instance of MetaColumn
 56  
      * 
 57  
      * @param aCode
 58  
      *            code
 59  
      * @param aName
 60  
      *            name
 61  
      * @param aParentTable
 62  
      *            name of the table owner
 63  
      * @param aMandatory
 64  
      *            true if this MetaColumn is mandatory
 65  
      * @param aFKParent
 66  
      *            Foreign Key parent MetaColumn. It could be null value
 67  
      * @param aJClassName
 68  
      * @param aLength
 69  
      * @param aPrecision
 70  
      * @param aComment
 71  
      */
 72  
     public MetaColumn(String aCode, String aName, String aParentTable,
 73  
             boolean aMandatory, MetaColumn aFKParent, String aJClassName,
 74  
             int aLength, int aPrecision, String aComment) {
 75  18
         super();
 76  18
         code = aCode;
 77  18
         name = aName;
 78  18
         parentTable = aParentTable;
 79  18
         mandatory = aMandatory;
 80  18
         fkColParent = aFKParent;
 81  18
         jClassName = aJClassName;
 82  18
         length = aLength;
 83  18
         precision = aPrecision;
 84  18
         comment = aComment;
 85  18
     }
 86  
 
 87  
     /**
 88  
      * Returns code of this MetaColumn
 89  
      * 
 90  
      * @return code.
 91  
      */
 92  
     public String getCode() {
 93  45
         return code;
 94  
     }
 95  
 
 96  
     /**
 97  
      * @return comment.
 98  
      */
 99  
     public String getComment() {
 100  18
         return comment;
 101  
     }
 102  
 
 103  
     /**
 104  
      * Returns foreign key MetaColumn of this MetaColumn
 105  
      * 
 106  
      * @return fkColParent.
 107  
      */
 108  
     public MetaColumn getFkColParent() {
 109  0
         return fkColParent;
 110  
     }
 111  
 
 112  
     /**
 113  
      * @return jClassName.
 114  
      */
 115  
     public String getJClassName() {
 116  18
         return jClassName;
 117  
     }
 118  
 
 119  
     /**
 120  
      * @return length.
 121  
      */
 122  
     public int getLength() {
 123  18
         return length;
 124  
     }
 125  
 
 126  
     /**
 127  
      * Returns name of this MetaColumn
 128  
      * 
 129  
      * @return name of this MetaColumn
 130  
      */
 131  
     public String getName() {
 132  18
         return name;
 133  
     }
 134  
 
 135  
     /**
 136  
      * @return parentKey.
 137  
      */
 138  
     public MetaKey getParentKey() {
 139  0
         return parentKey;
 140  
     }
 141  
 
 142  
     /**
 143  
      * Returns parent MetaTable of this MetaColumn
 144  
      * 
 145  
      * @return parent MetaTable of this MetaColumn
 146  
      */
 147  
     public String getParentTable() {
 148  0
         return parentTable;
 149  
     }
 150  
 
 151  
     /**
 152  
      * @return precision.
 153  
      */
 154  
     public int getPrecision() {
 155  18
         return precision;
 156  
     }
 157  
 
 158  
     /**
 159  
      * Returns "parentTableCode" + "." + "thisColumnCode"
 160  
      * 
 161  
      * @return "parentTableCode" + "." + "thisColumnCode"
 162  
      */
 163  
     public String getTableDotColumnCode() {
 164  18
         return parentTable + "." + code;
 165  
     }
 166  
 
 167  
     /**
 168  
      * Returns true if this MetaColumn is mandatory
 169  
      * 
 170  
      * @return true if this MetaColumn is mandatory
 171  
      */
 172  
     public boolean isMandatory() {
 173  0
         return mandatory;
 174  
     }
 175  
 
 176  
     /**
 177  
      * Returns true if this MetaColumn is part of foreign key
 178  
      * 
 179  
      * @return true if this MetaColumn is part of foreign key fkColParent !=
 180  
      *         null
 181  
      */
 182  
     public boolean isPartOfFK() {
 183  0
         return fkColParent != null;
 184  
     }
 185  
 
 186  
     /**
 187  
      * Returns true if this MetaColumn is part of primary key
 188  
      * 
 189  
      * @return true if this MetaColumn is part of primary key
 190  
      */
 191  
     public boolean isPartOfPK() {
 192  0
         return parentKey != null;
 193  
     }
 194  
 
 195  
     /**
 196  
      * @return
 197  
      */
 198  
     private String recursiveFkHTMLTable() {
 199  0
         String retVal = "<TABLE border=\"1\">" + "<CAPTION><B>" + parentTable
 200  
                 + "." + code + "</B></CAPTION>";
 201  0
         retVal += "<TBODY>";
 202  0
         retVal += "<TR><TD align=\"right\">" + "<B>name</B>" + "</TD>"
 203  
                 + "<TD align=\"left\">" + name + "</TD></TR>";
 204  0
         retVal += "<TR><TD align=\"right\">" + "<B>code</B>" + "</TD>"
 205  
                 + "<TD align=\"left\">" + code + "</TD></TR>";
 206  0
         retVal += "<TR><TD align=\"right\">" + "<B>fkColParent</B>" + "</TD>";
 207  0
         if (fkColParent != null) {
 208  0
             retVal += "<TD>" + fkColParent.recursiveFkHTMLTable() + "</TD>";
 209  
         }
 210  0
         retVal += "</TBODY></TABLE>";
 211  0
         return retVal;
 212  
     }
 213  
 
 214  
     /**
 215  
      * Sets code for this MetaColumn
 216  
      * 
 217  
      * @param aCode
 218  
      *            the code to set
 219  
      */
 220  
     public void setCode(String aCode) {
 221  0
         code = aCode;
 222  0
     }
 223  
 
 224  
     /**
 225  
      * @param aComment
 226  
      *            The comment to set.
 227  
      */
 228  
     public void setComment(String aComment) {
 229  0
         comment = aComment;
 230  0
     }
 231  
 
 232  
     /**
 233  
      * Sets foreign key parent MetaColumn of this MetaColumn
 234  
      * 
 235  
      * @param aFkColParent
 236  
      *            foreign key parent MetaColumn
 237  
      */
 238  
     public void setFkColParent(MetaColumn aFkColParent) {
 239  4
         fkColParent = aFkColParent;
 240  4
     }
 241  
 
 242  
     /**
 243  
      * @param aClassName
 244  
      *            The jClassName to set.
 245  
      */
 246  
     public void setJClassName(String aClassName) {
 247  0
         jClassName = aClassName;
 248  0
     }
 249  
 
 250  
     /**
 251  
      * @param aLength
 252  
      *            The length to set.
 253  
      */
 254  
     public void setLength(int aLength) {
 255  0
         length = aLength;
 256  0
     }
 257  
 
 258  
     /**
 259  
      * Sets mandatory column
 260  
      * 
 261  
      * @param aMandatory
 262  
      *            The mandatory to set.
 263  
      */
 264  
     public void setMandatory(boolean aMandatory) {
 265  0
         mandatory = aMandatory;
 266  0
     }
 267  
 
 268  
     /**
 269  
      * Sets the name for this MetaColumn
 270  
      * 
 271  
      * @param aName
 272  
      *            the name to set.
 273  
      */
 274  
     public void setName(String aName) {
 275  0
         name = aName;
 276  0
     }
 277  
 
 278  
     /**
 279  
      * @param aParentKey
 280  
      *            The parentKey to set.
 281  
      */
 282  
     public void setParentKey(MetaKey aParentKey) {
 283  5
         parentKey = aParentKey;
 284  5
     }
 285  
 
 286  
     /**
 287  
      * Sets name of parent MetaTable of this MetaColumn
 288  
      * 
 289  
      * @param aParentTable
 290  
      *            the parent MetaTable to set
 291  
      */
 292  
     public void setParentTable(String aParentTable) {
 293  18
         parentTable = aParentTable;
 294  18
     }
 295  
 
 296  
     /**
 297  
      * @param aPrecision
 298  
      *            The precision to set.
 299  
      */
 300  
     public void setPrecision(int aPrecision) {
 301  0
         precision = aPrecision;
 302  0
     }
 303  
 
 304  
     /**
 305  
      * Returns string representation of this MetaColumn
 306  
      * 
 307  
      * @see java.lang.Object#toString()
 308  
      */
 309  
     public String toString() {
 310  0
         return name;
 311  
     }
 312  
 
 313  
     /**
 314  
      * Returns verbose html description of this MetaColumn
 315  
      * 
 316  
      * @return verbose html description of this MetaColumn
 317  
      */
 318  
     public String toStringVerbose() {
 319  0
         String retVal = "<HTML><TABLE border=\"1\" >"//
 320  
                 + "<CAPTION><STRONG>" + parentTable + "." + code
 321  
                 + "</STRONG></CAPTION>";
 322  0
         retVal += "<TBODY>";
 323  0
         retVal += "<TR><TD align=\"right\">" + "<B>name</B>" + "</TD>"
 324  
                 + "<TD align=\"left\">" + name + "</TD></TR>";
 325  0
         retVal += "<TR><TD align=\"right\">" + "<B>code</B>" + "</TD>"
 326  
                 + "<TD align=\"left\">" + code + "</TD></TR>";
 327  0
         retVal += "<TR><TD align=\"right\">" + "<B>parentTable</B>" + "</TD>"
 328  
                 + "<TD align=\"left\">" + parentTable + "</TD></TR>";
 329  0
         retVal += "<TR><TD align=\"right\">" + "<B>partOfPK</B>" + "</TD>"
 330  
                 + "<TD align=\"left\">" + isPartOfPK() + "</TD></TR>";
 331  0
         retVal += "<TR><TD align=\"right\">" + "<B>mandatory</B>" + "</TD>"
 332  
                 + "<TD align=\"left\">" + mandatory + "</TD></TR>";
 333  0
         retVal += "<TR><TD align=\"right\">" + "<B>jClassName</B>" + "</TD>"
 334  
                 + "<TD align=\"left\">" + jClassName + "</TD></TR>";
 335  0
         retVal += "<TR><TD align=\"right\">" + "<B>length</B>" + "</TD>"
 336  
                 + "<TD align=\"left\">" + length + "</TD></TR>";
 337  0
         retVal += "<TR><TD align=\"right\">" + "<B>precision</B>" + "</TD>"
 338  
                 + "<TD align=\"left\">" + precision + "</TD></TR>";
 339  
 
 340  0
         retVal += "<TR><TD align=\"right\">" + "<B>defaultVal</B>" + "</TD>"
 341  
                 + "<TD align=\"left\">" + defaultVal + "</TD></TR>";
 342  
 
 343  0
         retVal += "<TR><TD align=\"right\">" + "<B>value-label map</B>"
 344  
                 + "</TD>";
 345  0
         Set<Map.Entry<String, String>> entries = lhmListOfVals.entrySet();
 346  0
         if (!lhmListOfVals.isEmpty()) {
 347  0
             retVal += "<TD><TABLE border=\"1\"><TBODY>";
 348  0
             for (Iterator<Map.Entry<String, String>> iter = entries.iterator(); iter
 349  0
                     .hasNext();) {
 350  0
                 Map.Entry<String, String> entry = iter.next();
 351  0
                 retVal += "<TR><TD align=\"right\">" + "<B>value,label</B>"
 352  
                         + "</TD>" + "<TD align=\"left\">" + entry.getKey()
 353  
                         + "," + entry.getValue() + "</TD></TR>";
 354  0
             }
 355  0
             retVal += "</TBODY></TABLE></TD>";
 356  
         }
 357  0
         retVal += "</TR>";
 358  0
         retVal += "<TR><TD align=\"right\">" + "<B>comment</B>" + "</TD>"
 359  
                 + "<TD align=\"left\">"
 360  
                 + MetaUtils.insertHTMLBreaks(comment, 50) + "</TD></TR>";
 361  0
         retVal += "<TR><TD align=\"right\">" + "<B>fkColParent</B>" + "</TD>";
 362  0
         if (fkColParent != null) {
 363  0
             retVal += "<TD rowspan=\"2\">" + fkColParent.recursiveFkHTMLTable()
 364  
                     + "</TD>";
 365  
         }
 366  0
         retVal += "</TBODY></TABLE></HTML>";
 367  0
         return retVal;
 368  
     }
 369  
 
 370  
     /**
 371  
      * @return defaultVal.
 372  
      */
 373  
     public String getDefaultVal() {
 374  18
         return defaultVal;
 375  
     }
 376  
 
 377  
     /**
 378  
      * @param aDefaultVal
 379  
      *            The defaultVal to set.
 380  
      */
 381  
     public void setDefaultVal(String aDefaultVal) {
 382  18
         defaultVal = aDefaultVal;
 383  18
     }
 384  
 
 385  
     /**
 386  
      * Returns Pair(Value,Label) of an ListValues entry.
 387  
      * 
 388  
      * @see java.util.HashMap#entrySet()
 389  
      */
 390  
     public Set entrySet_Value_Label() {
 391  0
         return lhmListOfVals.entrySet();
 392  
     }
 393  
 
 394  
     /**
 395  
      * @return true if list of values is not empty, otherwise false
 396  
      * @see java.util.HashMap#isEmpty()
 397  
      */
 398  
     public boolean hasListOfVals() {
 399  0
         return !lhmListOfVals.isEmpty();
 400  
     }
 401  
 
 402  
     /**
 403  
      * @see java.util.HashMap#put(java.lang.Object, java.lang.Object)
 404  
      */
 405  
     public Object put(String aValue, String aLabel) {
 406  0
         return lhmListOfVals.put(aValue, aLabel);
 407  
     }
 408  
 }