Boolean showContactDataToContacts) {
if (AuthLevelmanagement.getInstance().checkUserLevel(user_level)
&& user_id != 0) {
try {
Users us = UsersDaoImpl.getInstance().getUser(user_id);
// Check for duplicates
boolean checkName = true;
if (!login.equals(us.getLogin())) {
checkName = UsersDaoImpl.getInstance()
.checkUserLogin(login);
}
boolean checkEmail = true;
// Compare old address with new address
if (!email.equals(us.getAdresses().getEmail())) {
// Its a new one - check, whether another user already uses
// that one...
checkEmail = Emailmanagement.getInstance().checkUserEMail(
email);
}
if (generateSipUserData) {
if (password.length() == 0) {
// Cannot perform a SIP Creation without password
// re-enter
return new Long(-43);
}
}
if (checkName && checkEmail) {
// log.info("user_id " + user_id);
us.setLastname(lastname);
us.setFirstname(firstname);
us.setAge(age);
us.setLogin(login);
us.setUpdatetime(new Date());
us.setAvailible(availible);
us.setStatus(status);
us.setTitle_id(title_id);
us.setOmTimeZone(OmTimeZoneDaoImpl.getInstance()
.getOmTimeZone(jNameTimeZone));
us.setForceTimeZoneCheck(forceTimeZoneCheck);
us.setUserOffers(userOffers);
us.setUserSearchs(userSearchs);
us.setShowContactData(showContactData);
us.setShowContactDataToContacts(showContactDataToContacts);
if (level_id != 0)
us.setLevel_id(new Long(level_id));
if (password.length() != 0) {
if (password.length() >= 6) {
us.setPassword(ManageCryptStyle.getInstance()
.getInstanceOfCrypt()
.createPassPhrase(password));
} else {
return new Long(-7);
}
}
Addressmanagement.getInstance().updateAdress(
us.getAdresses().getAdresses_id(), street, zip,
town, states_id, additionalname, comment, fax,
email, phone);
// Emailmanagement.getInstance().updateUserEmail(mail.getMail().getMail_id(),user_id,
// email);
// add or delete organisations from this user
if (organisations != null) {
Organisationmanagement.getInstance()
.updateUserOrganisationsByUser(us,
organisations);
}
if (generateSipUserData) {
UserSipData userSipData = OpenXGHttpClient
.getInstance().openSIPgUserCreateUser(
firstname, "", lastname,
us.getAdresses().getEmail(), password,
login);
if (us.getUserSipData() == null) {
Long userSipDataId = UserSipDataDaoImpl
.getInstance().addUserSipData(userSipData);
us.setUserSipData(UserSipDataDaoImpl.getInstance()
.getUserSipDataById(userSipDataId));
} else {
us.getUserSipData().setUsername(
userSipData.getUsername());
us.getUserSipData().setUserpass(
userSipData.getUserpass());
us.getUserSipData().setAuthId(
userSipData.getAuthId());
UserSipDataDaoImpl.getInstance().updateUserSipData(
us.getUserSipData());
}
} else if (us.getUserSipData() == null) {
UserSipData userSipData = new UserSipData();
userSipData.setUsername(sip_user);
userSipData.setUserpass(sip_pass);
userSipData.setAuthId(sip_auth);
Long userSipDataId = UserSipDataDaoImpl.getInstance()
.addUserSipData(userSipData);
us.setUserSipData(UserSipDataDaoImpl.getInstance()
.getUserSipDataById(userSipDataId));
} else {
UserSipData userSipData = UserSipDataDaoImpl
.getInstance().getUserSipDataById(
us.getUserSipData().getUserSipDataId());
userSipData.setUsername(sip_user);
userSipData.setUserpass(sip_pass);
userSipData.setAuthId(sip_auth);
UserSipDataDaoImpl.getInstance().updateUserSipData(
userSipData);
us.setUserSipData(userSipData);
}
// log.info("USER " + us.getLastname());
Object idf = PersistenceSessionUtil.createSession();
EntityManager session = PersistenceSessionUtil.getSession();
EntityTransaction tx = session.getTransaction();
tx.begin();
if (us.getUser_id() == null) {
session.persist(us);
} else {
if (!session.contains(us)) {
session.merge(us);
}
}
tx.commit();
PersistenceSessionUtil.closeSession(idf);
return us.getUser_id();
} else {
if (!checkName) {
return new Long(-15);
} else if (!checkEmail) {