Coverage Report - org.paneris.rimauresq.model.UserTable
 
Classes in this File Line Coverage Branch Coverage Complexity
UserTable
69%
24/35
80%
8/10
1.75
UserTable$1
80%
4/5
50%
1/2
1.75
 
 1  
 package org.paneris.rimauresq.model;
 2  
 
 3  
 import org.paneris.rimauresq.model.generated.UserTableBase;
 4  
 import org.melati.poem.AccessPoemException;
 5  
 import org.melati.poem.DefinitionSource;
 6  
 import org.melati.poem.Database;
 7  
 import org.melati.poem.InitialisationPoemException;
 8  
 import org.melati.poem.JdbcPersistent;
 9  
 import org.melati.poem.Persistent;
 10  
 import org.melati.poem.PoemException;
 11  
 import org.melati.poem.PoemTask;
 12  
 import org.melati.poem.PoemThread;
 13  
 import org.melati.poem.ValidationPoemException;
 14  
 
 15  
 /**
 16  
  * Melati POEM generated, programmer modifiable stub 
 17  
  * for a <code>UserTable</code> object.
 18  
  * <p>
 19  
  * Description: 
 20  
  *   A WVM User. 
 21  
  * </p>
 22  
  *
 23  
  * 
 24  
  * <table> 
 25  
  * <tr><th colspan='3'>
 26  
  * Field summary for SQL table <code>User</code>
 27  
  * </th></tr>
 28  
  * <tr><th>Name</th><th>Type</th><th>Description</th></tr>
 29  
  * <tr><td> email </td><td> String </td><td> The user's email address 
 30  
  * </td></tr> 
 31  
  * <tr><td> title </td><td> String </td><td> User's title or role </td></tr> 
 32  
  * <tr><td> address </td><td> String </td><td> &nbsp; </td></tr> 
 33  
  * <tr><td> town </td><td> String </td><td> &nbsp; </td></tr> 
 34  
  * <tr><td> postcode </td><td> String </td><td> Order postcode </td></tr> 
 35  
  * <tr><td> country </td><td> String </td><td> &nbsp; </td></tr> 
 36  
  * <tr><td> tel </td><td> String </td><td> User's telephone number </td></tr> 
 37  
  * <tr><td> fax </td><td> String </td><td> User's fax number </td></tr> 
 38  
  * <tr><td> mobile </td><td> String </td><td> User's mobile number </td></tr> 
 39  
  * <tr><td> news </td><td> Boolean </td><td> Does the user want to receive 
 40  
  * the  email newsletter? </td></tr> 
 41  
  * </table> 
 42  
  * 
 43  
  * @generator  org.melati.poem.prepro.TableDef#generateTableMainJava 
 44  
  */
 45  4
 public class UserTable extends UserTableBase {
 46  
 
 47  
  /**
 48  
   * Constructor.
 49  
   * 
 50  
   * @generator org.melati.poem.prepro.TableDef#generateTableMainJava 
 51  
   * @param database          the POEM database we are using
 52  
   * @param name              the name of this <code>Table</code>
 53  
   * @param definitionSource  which definition is being used
 54  
   * @throws PoemException    if anything goes wrong
 55  
   */
 56  
   public UserTable(
 57  
       Database database, String name,
 58  
       DefinitionSource definitionSource) throws PoemException {
 59  4
     super(database, name, definitionSource);
 60  4
   }
 61  
 
 62  
   // programmer's domain-specific code here
 63  
 
 64  
   public void init() throws PoemException {
 65  4
     super.init();
 66  
 
 67  
     // We can't put this in the constructor because the email
 68  
     // column isn't defined until we've called UserTableBase.init()
 69  4
     getEmailColumn().setRaw_unsafe(guestUser, "");
 70  4
     getEmailColumn().setRaw_unsafe(administratorUser, "");
 71  4
   }
 72  
 
 73  
   public void postInitialise() {
 74  4
     super.postInitialise();
 75  4
     PoemThread.withAccessToken(
 76  
         getDatabase().getUserTable().administratorUser(),
 77  
         new PoemTask() {
 78  
           public void run() {
 79  4
             if (((User)administratorUser()).getEmail().equals(""))
 80  4
               getEmailColumn().setRaw_unsafe(administratorUser, 
 81  
                                              "rimauresq@paneris.co.uk");
 82  4
           }
 83  
 
 84  4
           public String toString() {
 85  0
             return "Creating User defaults";
 86  
           }
 87  
     }
 88  
     );
 89  4
   }
 90  
 
 91  
   /**
 92  
    * @return the existing or newly minted user
 93  
    */
 94  
   public User ensure(String name, String title, String tel, 
 95  
                      String email) {
 96  0
     User p = (User)getNameColumn().firstWhereEq(name);
 97  0
     if (p == null) {
 98  0
       p = (User)newPersistent();
 99  0
       p.setLogin(name);
 100  0
       p.setName(name);
 101  0
       p.setPassword(name);
 102  0
       p.setTitle(title);
 103  0
       p.setTel(tel);
 104  0
       p.setEmail(email);
 105  0
       p.makePersistent();
 106  
     }
 107  0
     return p;
 108  
   }
 109  
   
 110  
   protected JdbcPersistent _newPersistent() {
 111  12
     User u = (User)super._newPersistent();
 112  12
     u.setNews_unsafe(Boolean.TRUE);
 113  12
     return u;
 114  
   }
 115  
 
 116  
   public void create(Persistent persistent)
 117  
   throws AccessPoemException, ValidationPoemException,
 118  
          InitialisationPoemException {
 119  10
     User u = (User)persistent; 
 120  10
     if (u.getLogin() == null)
 121  2
       u.setLogin("tmp");
 122  10
     if (u.getPassword() == null)
 123  2
       u.setPassword("tmp");
 124  10
     super.create(persistent);
 125  10
     if (u.getLogin() == "tmp")
 126  2
       u.setLogin(u.troid().toString());
 127  10
     if (u.getPassword() == "tmp")
 128  2
       u.setPassword(u.troid().toString());
 129  10
   }
 130  
 }
 131