use of org.opencastproject.adminui.usersettings.persistence.UserSettingsServiceException in project opencast by opencast.
the class UserSettingsService method deleteUserSetting.
/**
* Delete a user setting by using a unique id to find it.
*
* @param id
* The unique id for the user setting.
* @throws UserSettingsServiceException
*/
public void deleteUserSetting(long id) throws UserSettingsServiceException {
EntityManager em = null;
EntityTransaction tx = null;
try {
em = emf.createEntityManager();
UserSettingDto userSettingsDto = em.find(UserSettingDto.class, id);
tx = em.getTransaction();
tx.begin();
em.remove(userSettingsDto);
tx.commit();
} catch (Exception e) {
logger.error("Could not delete user setting '%d': %s", id, ExceptionUtils.getStackTrace(e));
if (tx.isActive())
tx.rollback();
throw new UserSettingsServiceException(e);
} finally {
if (em != null)
em.close();
}
}
use of org.opencastproject.adminui.usersettings.persistence.UserSettingsServiceException in project opencast by opencast.
the class UserSettingsService method updateUserSetting.
/**
* Update a user setting that currently exists using its unique id to find it.
* @param id The id for the user setting.
* @param key The key for the user setting.
* @param value The value for the user setting.
* @return The updated {@link UserSetting}.
* @throws UserSettingsServiceException
*/
public UserSetting updateUserSetting(long id, String key, String value) throws UserSettingsServiceException {
EntityManager em = null;
EntityTransaction tx = null;
String orgId = "";
String username = "";
logger.debug("Updating user setting id: %d key: %s value: %s", id, key, value);
try {
em = emf.createEntityManager();
tx = em.getTransaction();
tx.begin();
orgId = securityService.getOrganization().getId();
username = securityService.getUser().getUsername();
UserSettingDto userSettingDto = em.find(UserSettingDto.class, id);
em.persist(userSettingDto);
userSettingDto.setKey(key);
userSettingDto.setValue(value);
tx.commit();
return userSettingDto.toUserSetting();
} catch (Exception e) {
logger.error("Could not update user setting username '%s' org:'%s' id:'%d' key:'%s' value:'%s':\n%s", username, orgId, id, key, value, ExceptionUtils.getStackTrace(e));
if (tx.isActive()) {
tx.rollback();
}
throw new UserSettingsServiceException(e);
} finally {
if (em != null) {
em.close();
}
}
}
Aggregations