Coverage Report - jp.co.y_net.amm.dao.Usr
 
Classes in this File Line Coverage Branch Coverage Complexity
Usr
0%
0/120
0%
0/18
0
Usr$LastlogindateComparator
0%
0/13
0%
0/10
0
 
 1  0
 package jp.co.y_net.amm.dao;
 2  
 
 3  
 import java.io.Serializable;
 4  
 import java.text.DateFormat;
 5  
 import java.text.SimpleDateFormat;
 6  
 import java.util.Comparator;
 7  
 import java.util.Date;
 8  
 
 9  
 import jp.co.y_net.amm.AppSession.LoginUser;
 10  
 import jp.co.y_net.amm.common.AppLogger;
 11  
 import jp.co.y_net.amm.common.AppUtils;
 12  
 import jp.co.y_net.amm.common.CalcHash;
 13  
 
 14  
 import org.apache.commons.lang.StringUtils;
 15  
 
 16  
 
 17  0
 public class Usr extends AppDto implements Serializable {
 18  
         private static final long serialVersionUID = 1L;
 19  
         
 20  
         
 21  
 
 22  
     private Integer usrid;
 23  
     private String loginid;
 24  
     private String name;
 25  
     private Integer kind;
 26  
     private Integer orgid;
 27  
     private Integer orgrole;
 28  
     private Integer stoplogin;
 29  
     private Integer fromdate;
 30  
     private Integer todate;
 31  
     private String pwhash;
 32  
     private String cres;
 33  
     private Long cresdate;
 34  
     private Long joindate;
 35  
     private Long lastlogintrydate;
 36  
     private Integer loginerrorcount;
 37  
     private Long lastlogindate;
 38  
     private Long modpwdate;
 39  
     private Long leavedate;
 40  
     private Integer status;
 41  
     
 42  
     /* 自動生成のアクセサ - start */
 43  
     public Integer getUsrid() {
 44  0
         return usrid;
 45  
     }
 46  
     public void setUsrid(Integer usrid) {
 47  0
         this.usrid = usrid;
 48  0
     }
 49  
     public String getLoginid() {
 50  0
         return loginid;
 51  
     }
 52  
     public void setLoginid(String loginid) {
 53  0
         this.loginid = loginid;
 54  0
     }
 55  
     public String getName() {
 56  0
         return name;
 57  
     }
 58  
     public void setName(String name) {
 59  0
         this.name = name;
 60  0
     }
 61  
     public Integer getKind() {
 62  0
         return kind;
 63  
     }
 64  
     public void setKind(Integer kind) {
 65  0
         this.kind = kind;
 66  0
     }
 67  
     public Integer getOrgid() {
 68  0
         return orgid;
 69  
     }
 70  
     public void setOrgid(Integer orgid) {
 71  0
         this.orgid = orgid;
 72  0
     }
 73  
     public Integer getOrgrole() {
 74  0
         return orgrole;
 75  
     }
 76  
     public void setOrgrole(Integer olgrole) {
 77  0
         this.orgrole = olgrole;
 78  0
     }
 79  
     public Integer getStoplogin() {
 80  0
         return stoplogin;
 81  
     }
 82  
     public void setStoplogin(Integer stoplogin) {
 83  0
         this.stoplogin = stoplogin;
 84  0
     }
 85  
     public Integer getFromdate() {
 86  0
         return fromdate;
 87  
     }
 88  
     public void setFromdate(Integer fromdate) {
 89  0
         this.fromdate = fromdate;
 90  0
     }
 91  
     public Integer getTodate() {
 92  0
         return todate;
 93  
     }
 94  
     public void setTodate(Integer todate) {
 95  0
         this.todate = todate;
 96  0
     }
 97  
     public String getPwhash() {
 98  0
         return pwhash;
 99  
     }
 100  
     public void setPwhash(String pwhash) {
 101  0
         this.pwhash = pwhash;
 102  0
     }
 103  
     public String getCres() {
 104  0
         return cres;
 105  
     }
 106  
     public void setCres(String cres) {
 107  0
         this.cres = cres;
 108  0
     }
 109  
     public Long getCresdate() {
 110  0
         return cresdate;
 111  
     }
 112  
     public void setCresdate(Long cresdate) {
 113  0
         this.cresdate = cresdate;
 114  0
     }
 115  
     public Long getJoindate() {
 116  0
         return joindate;
 117  
     }
 118  
     public void setJoindate(Long joindate) {
 119  0
         this.joindate = joindate;
 120  0
     }
 121  
     public Long getLastlogintrydate() {
 122  0
         return lastlogintrydate;
 123  
     }
 124  
     public void setLastlogintrydate(Long lastlogintrydate) {
 125  0
         this.lastlogintrydate = lastlogintrydate;
 126  0
     }
 127  
     public Integer getLoginerrorcount() {
 128  0
         return loginerrorcount;
 129  
     }
 130  
     public void setLoginerrorcount(Integer loginerrorcount) {
 131  0
         this.loginerrorcount = loginerrorcount;
 132  0
     }
 133  
     public Long getLastlogindate() {
 134  0
         return lastlogindate;
 135  
     }
 136  
     public void setLastlogindate(Long lastlogindate) {
 137  0
         this.lastlogindate = lastlogindate;
 138  0
     }
 139  
     public Long getModpwdate() {
 140  0
         return modpwdate;
 141  
     }
 142  
     public void setModpwdate(Long modpwdate) {
 143  0
         this.modpwdate = modpwdate;
 144  0
     }
 145  
     public Long getLeavedate() {
 146  0
         return leavedate;
 147  
     }
 148  
     public void setLeavedate(Long leavedate) {
 149  0
         this.leavedate = leavedate;
 150  0
     }
 151  
     public Integer getStatus() {
 152  0
         return status;
 153  
     }
 154  
     public void setStatus(Integer status) {
 155  0
         this.status = status;
 156  0
     }
 157  
     /* 自動生成のアクセサ - end */
 158  
 
 159  
     /**
 160  
      * LoginUserオブジェクトへの値コピー
 161  
      */
 162  
     public void copy(LoginUser loginUser) {
 163  0
         loginUser.setUsrid(this.getUsrid());
 164  0
         loginUser.setLoginid(this.getLoginid());
 165  0
         loginUser.setKind(this.getKind());
 166  0
         loginUser.setOrgid(this.getOrgid());
 167  0
         loginUser.setOrgrole(this.getOrgrole());
 168  0
     }
 169  
     
 170  
     public static final String 管理者初期パスワード = "testtest";
 171  
     public static Usr create運営管理者代表(Org org運営管理){
 172  0
         return create運営管理者(org運営管理, null, null, true);
 173  
     }
 174  
     public static Usr create運営管理者(Org org運営管理, String loginid, String name, boolean is管理者代表) {
 175  
         int role;
 176  0
         if(is管理者代表) {
 177  0
             role = ROLE_管理者;
 178  0
             loginid = "admin";
 179  0
             name = "運営管理者";
 180  0
         } else {
 181  0
             role = ROLE_通常会員;
 182  
         }
 183  0
         Usr usr運営管理者 = new Usr();
 184  0
         usr運営管理者.setLoginid(loginid);
 185  0
         usr運営管理者.setName(name);
 186  0
         usr運営管理者.setKind(Usr.KIND_運営管理者);
 187  0
         usr運営管理者.setOrgrole(role);
 188  0
         usr運営管理者.setOrgid(org運営管理.getOrgid());
 189  0
         usr運営管理者.setStatus(Usr.STATUS_登録済み);
 190  0
         usr運営管理者.setStoplogin(AppDef.FLASE);
 191  0
         String pwhash = CalcHash.passowrdHash(管理者初期パスワード, usr運営管理者.getLoginid()); // 初期パスワード
 192  0
         usr運営管理者.setPwhash(pwhash);
 193  0
         usr運営管理者.setModpwdate(AppUtils.createNowLong());
 194  
         
 195  0
         return usr運営管理者;
 196  
     }
 197  
     
 198  
     
 199  
    
 200  
     
 201  
     /* 会員種別 */
 202  
     public static final int KIND_機関会員 = 1;
 203  
     public static final int KIND_機関管理者 = 2;
 204  
     public static final int KIND_運営管理者 = 3;
 205  
     
 206  
     /* 所属機関での役割 */
 207  0
     public static final Integer ROLE_管理者 = 1;
 208  0
     public static final Integer ROLE_通常会員 = 9;
 209  
     
 210  
     /* 状態 */
 211  
     public static final int STATUS_仮登録 = 0;
 212  
     public static final int STATUS_登録済み = 1;
 213  0
     public static final int STATUS_退会 = 2;
 214  
     
 215  
     /**
 216  
      * @return 状態の名称
 217  
      */
 218  
     public String getStatus_Disp() {
 219  0
         switch (status) {
 220  
         case STATUS_仮登録:
 221  0
             return "仮登録";
 222  
         case STATUS_登録済み:
 223  0
             return "登録済み";
 224  
         case STATUS_退会:
 225  0
             return "退会";
 226  
         default:
 227  0
             return String.valueOf(status);
 228  
         }
 229  
     }
 230  
     
 231  
     /** @return 種類の名称 */
 232  
     public String getKind_Disp() {
 233  0
         switch (kind) {
 234  
         case KIND_機関会員:
 235  0
             return "機関会員";
 236  
         case KIND_機関管理者:
 237  0
             return "機関管理者";
 238  
         case KIND_運営管理者:
 239  0
             return "運営管理者";
 240  
         default:
 241  0
             return String.valueOf(status);
 242  
         }
 243  
     }
 244  
     public String getLastlogindate_Disp() {
 245  
         String lastlogin;
 246  
         try {
 247  0
             final DateFormat DF = new SimpleDateFormat("yyyy/MM/dd HH:mm");
 248  0
             Date d = AppUtils.toDate(this.getLastlogindate());
 249  0
             if(d == null) {
 250  0
                 lastlogin = "未ログイン";
 251  0
             } else {
 252  0
                 lastlogin = DF.format(d);    
 253  
             }
 254  
             
 255  0
         } catch (Exception e) {
 256  0
             AppLogger.error(e);
 257  0
             if (this.getLastlogindate() != null) {
 258  0
                 lastlogin = String.valueOf(this.getLastlogindate());
 259  0
             } else {
 260  0
                 lastlogin = "";
 261  
             };
 262  
         }
 263  0
         return lastlogin;
 264  
     }
 265  
     /**
 266  
      * @return 代表者の時はTrue
 267  
      */
 268  
     public boolean isAdmin() {
 269  0
         return ROLE_管理者.equals(getKind());
 270  
     }
 271  
 
 272  
     public boolean isログイン停止() {
 273  0
         if(this.stoplogin != null && this.stoplogin == 1) {
 274  0
             return true;
 275  
         }
 276  0
         return false;
 277  
     }
 278  
     
 279  
     /**
 280  
      * ・会員情報編集画面からの退会
 281  
      * ・登録会員情報削除によるカスケード退会
 282  
      */
 283  
     public void 退会処理() {
 284  0
         this.setLeavedate(AppUtils.createNowLong());
 285  0
         this.setStatus(Usr.STATUS_退会);
 286  0
     }
 287  
 
 288  
     /**
 289  
      * 最終ログイン日時のソートに用いるComparator
 290  
      */
 291  
     public static class LastlogindateComparator implements Comparator<Usr> {
 292  
         /** trueに変更すると新しい順 */
 293  0
         private boolean desc = false; 
 294  
         
 295  0
         public LastlogindateComparator(boolean desc) {
 296  0
             this.desc = desc;
 297  0
         }
 298  
         
 299  
         @Override
 300  
         public int compare(Usr o1, Usr o2) {
 301  0
             int reverse = 1;
 302  0
             if(desc) {
 303  0
                 reverse = -1;
 304  
             }
 305  
             
 306  0
             Long n1 = 0L;
 307  0
             Long n2 = 0L;
 308  0
             if(o1 != null && o1.getLastlogindate() != null) n1 = o1.getLastlogindate();
 309  0
             if(o2 != null && o2.getLastlogindate() != null) n2 = o2.getLastlogindate();
 310  
             
 311  0
             return Long.compare(n1, n2) * reverse;
 312  
         }
 313  
     }
 314  
 
 315  
     public String getName_Disp() {
 316  0
         String str = StringUtils.abbreviate(getName(), 100);
 317  0
         return str;
 318  
     }
 319  
     public String getLoginid_Disp() {
 320  0
         String str = StringUtils.abbreviate(getLoginid(), 30);
 321  0
         return str;
 322  
     }
 323  
     
 324  
 }