if(isAccount || isGroup) {
uri = uri.removeLastSegment();
final String realmId = uri.lastSegment().toString();
final AbstractRealm realm = (AbstractRealm)findRealmForRealmId(realmId);
final Configuration conf = Configurator.parse(document);
Integer id = -1;
if(isRemoved) {
id = conf.getPropertyInteger("id");
}
final String name = conf.getProperty("name");
if(isAccount) {
if (isRemoved && id > 2 && !hasUser(id)) {
final AccountImpl account = new AccountImpl( realm, conf );
account.removed = true;
addUser(account.getId(), account);
} else if(name != null) {
if (realm.hasAccount(name)) {
final Integer oldId = saving.get(document.getURI());
final Integer newId = conf.getPropertyInteger("id");
//XXX: resolve conflicts on ids!!!
if (!newId.equals(oldId)) {
final Account current = realm.getAccount(name);
accountLocks.getWriteLock(current).lock();
try {
usersById.modify(new PrincipalDbModify<Account>(){
@Override
public void execute(final Int2ObjectHashMap<Account> principalDb) {
principalDb.remove(oldId);
principalDb.put(newId, current);
}
});
} finally {
accountLocks.getWriteLock(current).unlock();
}
}
} else {
final Account account = new AccountImpl( realm, conf );
addUser(account.getId(), account);
realm.registerAccount(account);
}
} else {
//this can't be! log any way
LOG.error("Account '"+name+"' pressent at '"+realmId+"' realm, but get event that new one created.");
}
} else if(isGroup) {
if (isRemoved && id > 2 && !hasGroup(id)) {
final GroupImpl group = new GroupImpl( realm, conf );
group.removed = true;
addGroup(group.getId(), group);
} else if (name != null && !realm.hasGroup(name)) {
final GroupImpl group = new GroupImpl( realm, conf );
addGroup(group.getId(), group);
realm.registerGroup(group);
} else {
//this can't be! log any way
LOG.error("Group '"+name+"' pressent at '"+realmId+"' realm, but get event that new one created.");
}