use of org.openmrs.api.db.DAOException in project openmrs-core by openmrs.
the class HibernateSerializedObjectDAO method convertSerializedObject.
/**
* @see SerializedObjectDAO#convertSerializedObject(Class, SerializedObject)
*/
@Override
@SuppressWarnings("unchecked")
public <T extends OpenmrsObject> T convertSerializedObject(Class<T> clazz, SerializedObject serializedObject) throws DAOException {
if (serializedObject == null) {
return null;
}
OpenmrsSerializer serializer = getSerializer(serializedObject);
T obj;
try {
Class<?> subtype = Context.loadClass(serializedObject.getSubtype());
obj = (T) serializer.deserialize(serializedObject.getSerializedData(), subtype);
} catch (Exception e) {
ExceptionUtil.rethrowAPIAuthenticationException(e);
throw new DAOException("Unable to deserialize object: " + serializedObject, e);
}
if (obj == null) {
// it's probably impossible to reach this code branch
throw new DAOException("Unable to deserialize object: " + serializedObject);
}
obj.setId(serializedObject.getId());
obj.setUuid(serializedObject.getUuid());
return obj;
}
use of org.openmrs.api.db.DAOException in project openmrs-core by openmrs.
the class HibernateConceptDAO method getDefaultConceptMapType.
/**
* @see org.openmrs.api.db.ConceptDAO#getDefaultConceptMapType()
*/
@Override
public ConceptMapType getDefaultConceptMapType() throws DAOException {
FlushMode previousFlushMode = sessionFactory.getCurrentSession().getFlushMode();
sessionFactory.getCurrentSession().setFlushMode(FlushMode.MANUAL);
try {
// Defaults to same-as if the gp is not set.
String defaultConceptMapType = Context.getAdministrationService().getGlobalProperty(OpenmrsConstants.GP_DEFAULT_CONCEPT_MAP_TYPE);
if (defaultConceptMapType == null) {
throw new DAOException("The default concept map type is not set. You need to set the '" + OpenmrsConstants.GP_DEFAULT_CONCEPT_MAP_TYPE + "' global property.");
}
ConceptMapType conceptMapType = getConceptMapTypeByName(defaultConceptMapType);
if (conceptMapType == null) {
throw new DAOException("The default concept map type (name: " + defaultConceptMapType + ") does not exist! You need to set the '" + OpenmrsConstants.GP_DEFAULT_CONCEPT_MAP_TYPE + "' global property.");
}
return conceptMapType;
} finally {
sessionFactory.getCurrentSession().setFlushMode(previousFlushMode);
}
}
use of org.openmrs.api.db.DAOException in project openmrs-core by openmrs.
the class HibernateConceptDAO method saveConceptStopWord.
/**
* @see org.openmrs.api.db.ConceptDAO#saveConceptStopWord(org.openmrs.ConceptStopWord)
*/
@Override
public ConceptStopWord saveConceptStopWord(ConceptStopWord conceptStopWord) throws DAOException {
if (conceptStopWord != null) {
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(ConceptStopWord.class);
criteria.add(Restrictions.eq("value", conceptStopWord.getValue()));
criteria.add(Restrictions.eq("locale", conceptStopWord.getLocale()));
List<ConceptStopWord> stopWordList = criteria.list();
if (!stopWordList.isEmpty()) {
throw new DAOException("Duplicate ConceptStopWord Entry");
}
sessionFactory.getCurrentSession().saveOrUpdate(conceptStopWord);
}
return conceptStopWord;
}
use of org.openmrs.api.db.DAOException in project openmrs-core by openmrs.
the class HibernateUserDAO method updateUserPassword.
/**
* @param newHashedPassword
* @param salt
* @param userId
* @param date
* @param userId2
*/
private void updateUserPassword(String newHashedPassword, String salt, Integer changedBy, Date dateChanged, Integer userIdToChange) {
User changeForUser = getUser(userIdToChange);
if (changeForUser == null) {
throw new DAOException("Couldn't find user to set password for userId=" + userIdToChange);
}
User changedByUser = getUser(changedBy);
LoginCredential credentials = getLoginCredential(changeForUser);
credentials.setUserId(userIdToChange);
credentials.setHashedPassword(newHashedPassword);
credentials.setSalt(salt);
credentials.setChangedBy(changedByUser);
credentials.setDateChanged(dateChanged);
credentials.setUuid(changeForUser.getUuid());
sessionFactory.getCurrentSession().merge(credentials);
// reset lockout
changeForUser.setUserProperty(OpenmrsConstants.USER_PROPERTY_LOCKOUT_TIMESTAMP, "");
changeForUser.setUserProperty(OpenmrsConstants.USER_PROPERTY_LOGIN_ATTEMPTS, "0");
saveUser(changeForUser, null);
}
use of org.openmrs.api.db.DAOException in project openmrs-core by openmrs.
the class HibernateUserDAO method changeQuestionAnswer.
/**
* @see org.openmrs.api.UserService#changeQuestionAnswer(java.lang.String, java.lang.String,
* java.lang.String)
*/
@Override
public void changeQuestionAnswer(String pw, String question, String answer) throws DAOException {
User u = Context.getAuthenticatedUser();
LoginCredential credentials = getLoginCredential(u);
if (!credentials.checkPassword(pw)) {
log.error("Passwords don't match");
throw new DAOException("Passwords don't match");
}
changeQuestionAnswer(u, question, answer);
}
Aggregations