1 23 24 package org.infoglue.cms.entities.management; 25 26 27 import java.util.Iterator ; 28 29 import org.infoglue.cms.entities.kernel.BaseEntityVO; 30 import org.infoglue.cms.entities.kernel.ValidatableEntityVO; 31 import org.infoglue.cms.entities.management.impl.simple.SystemUserImpl; 32 import org.infoglue.cms.util.ConstraintExceptionBuffer; 33 import org.infoglue.cms.util.validators.Constants; 34 import org.infoglue.cms.util.validators.ConstraintRule; 35 import org.infoglue.cms.util.validators.EmailValidator; 36 import org.infoglue.cms.util.validators.Range; 37 import org.infoglue.cms.util.validators.StringValidator; 38 39 40 public class SystemUserVO extends ValidatableEntityVO implements BaseEntityVO 41 { 42 43 private long timeStamp = 0; 44 private java.lang.String userName; 45 private java.lang.String password; 46 private java.lang.String firstName; 47 private java.lang.String lastName; 48 private java.lang.String email; 49 50 53 public Integer getId() 54 { 55 return null; 56 } 57 58 public String toString() 59 { 60 return getFirstName() + " " + getLastName(); 61 } 62 63 public java.lang.String getUserName() 64 { 65 return this.userName; 66 } 67 68 public void setUserName(java.lang.String userName) 69 { 70 this.userName = userName; 71 } 72 73 public java.lang.String getPassword() 74 { 75 return this.password; 76 } 77 78 public void setPassword(java.lang.String password) 79 { 80 this.password = password; 81 } 82 83 public java.lang.String getFirstName() 84 { 85 return this.firstName; 86 } 87 88 public void setFirstName(java.lang.String firstName) 89 { 90 this.firstName = firstName; 91 } 92 93 public java.lang.String getLastName() 94 { 95 return this.lastName; 96 } 97 98 public void setLastName(java.lang.String lastName) 99 { 100 this.lastName = lastName; 101 } 102 103 public java.lang.String getEmail() 104 { 105 return this.email; 106 } 107 108 public void setEmail(java.lang.String email) 109 { 110 this.email = email; 111 112 } 113 114 public void PrepareValidation() 115 { 116 123 rules.setEntityClass(SystemUserImpl.class); 129 130 ConstraintRule cr = new ConstraintRule(org.infoglue.cms.util.validators.Constants.STRING, "SystemUser.userName"); 133 134 cr.setValidRange(new Range(2, 20) ); 136 cr.unique=true; cr.required=true; cr.setValue(userName); 139 140 rules.addRule(cr); 142 143 cr = new ConstraintRule(org.infoglue.cms.util.validators.Constants.STRING, "SystemUser.password"); 145 cr.setValidRange(new Range(4, 15)); 146 cr.required = true; 147 cr.setValue(password); 148 rules.addRule(cr); 149 150 cr = new ConstraintRule(org.infoglue.cms.util.validators.Constants.STRING, "SystemUser.firstName"); 151 cr.setValidRange(new Range(1, 30)); 152 cr.required = true; 153 cr.setValue(firstName); 154 rules.addRule(cr); 155 156 cr = new ConstraintRule(org.infoglue.cms.util.validators.Constants.STRING, "SystemUser.lastName"); 157 cr.setValidRange(new Range(1, 30)); 158 cr.required = true; 159 cr.setValue(lastName); 160 rules.addRule(cr); 161 162 cr = new ConstraintRule(org.infoglue.cms.util.validators.Constants.EMAIL, "SystemUser.email"); 163 cr.setValidRange(new Range(50)); 164 cr.required = true; 165 cr.setValue(email); 166 rules.addRule(cr); 167 } 168 169 170 public ConstraintExceptionBuffer validate(ValidatableEntityVO vo) 171 { 172 178 ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer(); 179 180 vo.PrepareValidation(); 182 183 Iterator iterator = vo.getConstraintRules().iterator(); 185 while (iterator.hasNext()) 186 { 187 ConstraintRule cr = (ConstraintRule) iterator.next(); 188 String userName = ((SystemUserVO)vo).getUserName(); 189 190 switch (cr.getConstraintType()) 192 { 193 case Constants.EMAIL: 194 { 195 if (cr.getValue() != null) 196 { 197 EmailValidator v = new EmailValidator(cr.getFieldName()); 199 200 v.setObjectClass(vo.getConstraintRuleList().getEntityClass()); 202 v.setRange(cr.getValidRange()); 203 v.setIsRequired(cr.required); 204 v.setMustBeUnique(cr.unique); 205 v.setExcludeId(null); 206 v.setExcludeObject(userName); 207 208 v.validate((String ) cr.getValue(), ceb); 210 211 216 } 217 break; 218 } 219 case Constants.STRING: 220 { 221 if (cr.getValue() != null) 222 { 223 StringValidator v = new StringValidator(cr.getFieldName()); 224 v.setObjectClass(vo.getConstraintRuleList().getEntityClass()); 225 v.setRange(cr.getValidRange()); 226 v.setIsRequired(cr.required); 227 v.setMustBeUnique(cr.unique); 228 v.setExcludeId(null); 229 v.setExcludeObject(userName); 230 231 v.validate((String ) cr.getValue(), ceb); 232 } 233 break; 234 } 235 case Constants.FLOAT: 236 { 237 break; 238 } 239 case Constants.INTEGER: 240 { 241 break; 242 } 243 case Constants.PROPERNOUN: 244 { 245 break; 246 } 247 248 } 250 } 252 return ceb; 253 } 254 } 255 | Popular Tags |