// nothing
if (!"".equals(fGroupId)) {
// get ucrBean for the user on this centreId
UsercentrerelBean ucrBeanInDB = (UsercentrerelBean) UsercentrerelFinderBase
.findByPrimaryKey(con, new UsercentrerelKey(userToEdit
.getId(), fCentreId));
if (null == ucrBeanInDB) {
// new relation
isNew = true;
ucrBeanInDB = new UsercentrerelBean();
}
ucrBeanInDB.setStatus(fStatus);
ucrBeanInDB.setGroupid(fGroupId);
ucrBeanInDB.setTsupdated(tsNow);
ucrBeanInDB.setUpdatedby(user.getId());
// not stored in db since before, and is active
// (new relations must be active to be created)
if (isNew && Integer.valueOf(1).equals(fStatus)) {
ucrBeanInDB.setUserid(userToEdit.getId());
ucrBeanInDB.setTscreated(tsNow);
ucrBeanInDB.setCreatedby(user.getId());
ucrBeanInDB.setCentreid(fCentreId);
ucrBeanInDB.create(con);
}
if (!isNew) {
ucrBeanInDB.store(con);
}
// set groupId and status on users changed from nonUcr to ucr
// on users new active centre ()
if (setGroupToActiveCentre
&& fCentreId.equals(userToEdit.getCentreid())
&& null != fGroupId && null != fStatus) {
setGroupToActiveCentre = false;
userToEdit.setGroupid(fGroupId);
userToEdit.setStatus(fStatus);
}
// if userToEdit has a group on this centre now
// and user does not have relation to userToEdit on this centre
// something is wrong, abuse
if (null != UserRelation.retrieveGroupId(con, userToEdit,
fCentreId)
&& !UserRelation.hasUserRelationToUserToEditOnCentre(
con, user, userToEdit, fCentreId)) {
abuseLog("updateData, before update", ucrBean.getUserid(),
ucrBean.getCentreid(), ucrBean.getGroupid());
rollback(con);
return;
}
}
}
if (Integer.valueOf(0).equals(
userGroups.get(userToEdit.getGroupid()).getUseucr())) {
// if no ucr user remove all ucr beans.
for (UsercentrerelBean ucr : UsercentrerelFinder.findByUserid(con, userToEdit.getId())) {
ucr.remove(con);
}
} else {
// ucrUser
/**
* check that the user is still active in relation to its current
* centre, else move to an active relation<br/>
* handle deactivated / activated ucr users
*
*/
boolean activeUcrExists = false;
boolean changeCentre = false;
String possibleActiveCentre = null;
String currentGroupId = null;
UsercentrerelBean ucrB = (UsercentrerelBean) UsercentrerelFinderBase
.findByPrimaryKey(con, new UsercentrerelKey(userToEdit
.getId(), userToEdit.getCentreid()));
if (null == ucrB || !Integer.valueOf(1).equals(ucrB.getStatus())) {
// not active
for (UsercentrerelBean ucr : UsercentrerelFinder.findByUserid(con, userToEdit.getId())) {