Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 1009 → Rev 1010

/hostadmiral/trunk/src/ak/hostadmiral/core/model/UserManager.java
25,11 → 25,12
 
registered = true;
try {
/*
HibernateUtil.getConfiguration().addResource(
"ak/hostadmiral/core/model/User.hbm.xml");
HibernateUtil.getConfiguration().addResource(
"ak/hostadmiral/core/model/UserLogin.hbm.xml");
 
*/
userManager = new UserManager();
}
catch(Exception ex) {
43,7 → 44,10
register();
}
 
private Collection createdListeners = new ArrayList();
private Collection modifiedListeners = new ArrayList();
private Collection beforeDeleteListeners = new ArrayList();
private Collection deletedListeners = new ArrayList();
private Map loggedinUsers = new WeakHashMap();
 
private UserManager()
56,7 → 60,13
{
if(!allowedToCreate(editor)) throw new ModelSecurityException();
 
return new User();
User user = new User();
 
if(!user.mayChangeBoss(editor)) { // ordinal user can create only own "subusers"
user.setBoss(editor);
}
 
return user;
}
 
public boolean allowedToCreate(User editor)
73,8 → 83,7
try {
user = (User)HibernateUtil.currentSession().load(User.class, id);
}
catch(HibernateException ex)
{
catch(HibernateException ex) {
throw new ModelException(ex);
}
 
100,8 → 109,7
new Type[] { Hibernate.STRING, Hibernate.entity(User.class) } )
.next()).intValue() > 0;
}
catch(HibernateException ex)
{
catch(HibernateException ex) {
throw new ModelException(ex);
}
}
120,8 → 128,7
else
return (User)list.get(0);
}
catch(HibernateException ex)
{
catch(HibernateException ex) {
throw new ModelException(ex);
}
}
135,13 → 142,15
throw new ModelSecurityException();
}
 
user.setModUser(editor);
boolean isNew = user.isNew();
 
//user.setModUser(editor); // FIXME: disabled because hb throws exception
// if user edits itself
 
try {
HibernateUtil.currentSession().saveOrUpdate(user);
}
catch(HibernateException ex)
{
catch(HibernateException ex) {
throw new ModelException(ex);
}
 
151,8 → 160,44
if(u.equals(user))
u.update(user);
}
 
// inform listeners
if(isNew) {
for(Iterator i = createdListeners.iterator(); i.hasNext(); ) {
UserCreatedListener listener = (UserCreatedListener)i.next();
listener.userCreated(editor, user);
}
}
else {
User oldUser = user.getOrigin();
if(oldUser == null) oldUser = user;
for(Iterator i = modifiedListeners.iterator(); i.hasNext(); ) {
UserModifiedListener listener = (UserModifiedListener)i.next();
listener.userModified(editor, user, oldUser);
}
}
}
 
public void addCreatedListener(UserCreatedListener listener)
{
createdListeners.add(listener);
}
 
public void removeCreatedListener(UserCreatedListener listener)
{
createdListeners.remove(listener);
}
 
public void addModifiedListener(UserModifiedListener listener)
{
modifiedListeners.add(listener);
}
 
public void removeModifiedListener(UserModifiedListener listener)
{
modifiedListeners.remove(listener);
}
 
public void addBeforeDeleteListener(UserBeforeDeleteListener listener)
{
beforeDeleteListeners.add(listener);
163,6 → 208,16
beforeDeleteListeners.remove(listener);
}
 
public void addDeletedListener(UserDeletedListener listener)
{
deletedListeners.add(listener);
}
 
public void removeDeletedListener(UserDeletedListener listener)
{
deletedListeners.remove(listener);
}
 
public Collection beforeDelete(User editor, User user, Collection known)
throws ModelException
{
181,16 → 236,26
public void delete(User editor, User user)
throws ModelException
{
// chech rights
if(!user.deleteableBy(editor))
throw new ModelSecurityException();
 
// backup copy
User oldUser = new User(user);
 
// delete it
try {
HibernateUtil.currentSession().delete(user);
}
catch(HibernateException ex)
{
catch(HibernateException ex) {
throw new ModelException(ex);
}
 
// inform listeners
for(Iterator i = deletedListeners.iterator(); i.hasNext(); ) {
UserDeletedListener listener = (UserDeletedListener)i.next();
listener.userDeleted(editor, oldUser);
}
}
 
public Collection listUsers(User editor)
207,8 → 272,7
new Type[] { Hibernate.entity(User.class), Hibernate.entity(User.class) } );
}
}
catch(HibernateException ex)
{
catch(HibernateException ex) {
throw new ModelException(ex);
}
}
228,8 → 292,7
.next()).intValue() > 0;
}
}
catch(HibernateException ex)
{
catch(HibernateException ex) {
throw new ModelException(ex);
}
}
245,12 → 308,12
try {
HibernateUtil.currentSession().saveOrUpdate(userLogin);
}
catch(HibernateException ex)
{
catch(HibernateException ex) {
throw new ModelException(ex);
}
 
if(success) {
user = new User(user); // unbind the user from hibernate
loggedinUsers.put(user, Boolean.TRUE);
return user;
}
272,9 → 335,8
"from UserLogin where success = ?",
Boolean.FALSE, Hibernate.BOOLEAN);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
catch(HibernateException ex) {
throw new ModelException(ex);
}
}
 
288,8 → 350,7
"from User where boss = ?",
user, Hibernate.entity(User.class) );
}
catch(HibernateException ex)
{
catch(HibernateException ex) {
throw new ModelException(ex);
}