1 28 package com.genimen.djeneric.repository; 29 30 import java.util.HashMap ; 31 32 import com.genimen.djeneric.language.Messages; 33 import com.genimen.djeneric.repository.exceptions.DjenericException; 34 35 public abstract class DjUser 36 { 37 final static long NOT_YET_PERSISTED = -1; 38 39 public abstract void delete(DjSession session) throws DjenericException; 41 42 public abstract void reload(DjSession session) throws DjenericException; 43 44 public abstract void persist(DjSession session) throws DjenericException; 45 46 public abstract void insert(DjSession session) throws DjenericException; 47 48 public abstract void removeAllContextAssociations(DjSession session) throws DjenericException; 49 50 public abstract void addView(DjSession session, DjModelView view) throws DjenericException; 51 52 public abstract void removeView(DjSession session, DjModelView view) throws DjenericException; 53 54 public abstract void removeAllViews(DjSession session) throws DjenericException; 55 56 public abstract DjModelView[] getViews() throws DjenericException; 57 58 public abstract DjUserContextAssociation[] getContextAssociations() throws DjenericException; 59 60 public abstract DjUserContextAssociation getContextAssociation(DjContext ctxt) throws DjenericException; 61 62 64 long _id; 65 String _code = ""; 66 String _name = ""; 67 String _password = ""; 68 boolean _administrator = false; 69 boolean _modeler = false; 70 private DjPersistenceManager _mgr; 71 HashMap _cachedCAs = new HashMap (); 72 73 protected DjUser(DjPersistenceManager mgr) 74 75 { 76 _mgr = mgr; 77 _id = NOT_YET_PERSISTED; 78 } 79 80 protected DjUser(DjPersistenceManager mgr, long id, String code, String name, String password, boolean administrator, 81 boolean modeler) 82 { 83 _mgr = mgr; 84 _id = id; 85 _code = code; 86 _name = name; 87 _password = password; 88 _administrator = administrator; 89 _modeler = modeler; 90 } 91 92 public boolean canModify(DjContext someContext) throws DjenericException 93 { 94 if(someContext == null && !_administrator) throw new DjenericException(Messages.getString("DjPersistenceManager.OnlyAdminCanSeeGlobal")); 95 96 DjUserContextAssociation c = getCachedContextAssociation(someContext); 97 if (c != null) return c.isModify() || _administrator; 98 99 return _administrator; 100 } 101 102 public boolean canCreate(DjContext someContext) throws DjenericException 103 { 104 if(someContext == null && !_administrator) throw new DjenericException(Messages.getString("DjPersistenceManager.OnlyAdminCanSeeGlobal")); 105 106 DjUserContextAssociation c = getCachedContextAssociation(someContext); 107 if (c != null) return c.isCreate() || _administrator; 108 109 return _administrator; 110 } 111 112 public boolean canDelete(DjContext someContext) throws DjenericException 113 { 114 if(someContext == null && !_administrator) throw new DjenericException(Messages.getString("DjPersistenceManager.OnlyAdminCanSeeGlobal")); 115 116 DjUserContextAssociation c = getCachedContextAssociation(someContext); 117 if (c != null) return c.isDelete() || _administrator; 118 119 return _administrator; 120 } 121 122 public boolean canQuery(DjContext someContext) throws DjenericException 123 { 124 if(someContext == null && !_administrator) throw new DjenericException(Messages.getString("DjPersistenceManager.OnlyAdminCanSeeGlobal")); 125 126 DjUserContextAssociation c = getCachedContextAssociation(someContext); 127 if (c != null) return c.isQuery() || _administrator; 128 129 return _administrator; 130 } 131 132 protected DjUserContextAssociation getCachedContextAssociation(DjContext someContext) throws DjenericException 133 { 134 if(someContext == null) return null; 135 136 DjUserContextAssociation c = (DjUserContextAssociation) _cachedCAs.get(someContext); 137 if (c == null) 138 { 139 c = getContextAssociation(someContext); 140 _cachedCAs.put(someContext, c); 141 } 142 return c; 143 } 144 145 public DjPersistenceManager getPersistenceManager() 146 { 147 return _mgr; 148 } 149 150 public long getId() 151 { 152 return _id; 153 } 154 155 protected void setId(long id) 156 { 157 _id = id; 158 } 159 160 public String getName() 161 { 162 return _name; 163 } 164 165 public void setName(String name) 166 { 167 _name = name; 168 } 169 170 public String getPassword() 171 { 172 if (_password == null) return ""; 173 return _password; 174 } 175 176 public void setPassword(String pw) 177 { 178 _password = pw; 179 } 180 181 public String getCode() 182 { 183 return _code; 184 } 185 186 public void setCode(String code) 187 { 188 _code = code.toLowerCase(); 189 } 190 191 public boolean isAdministrator() 192 { 193 return _administrator; 194 } 195 196 public void setAdministrator(boolean administrator) 197 { 198 _administrator = administrator; 199 } 200 201 public void setModeler(boolean modeler) 202 { 203 _modeler = modeler; 204 } 205 206 public boolean isModeler() 207 { 208 return _modeler; 209 } 210 211 public boolean equals(Object obj) 212 { 213 if (!(obj instanceof DjUser)) return false; 214 DjUser r = (DjUser) obj; 215 216 return getId() == r.getId(); 217 } 218 219 public int hashCode() 220 { 221 return (int) getId(); 222 } 223 224 public String toString() 225 { 226 return getName(); 227 } 228 229 } | Popular Tags |