use of org.openmrs.api.db.DAOException in project openmrs-core by openmrs.
the class HL7ServiceImpl method migrateHl7InArchivesToFileSystem.
/**
* @see org.openmrs.hl7.HL7Service#migrateHl7InArchivesToFileSystem(Map)
*/
@Override
public void migrateHl7InArchivesToFileSystem(Map<String, Integer> progressStatusMap) throws APIException {
int numberTransferred = 0;
int numberOfFailedTransfers = 0;
// HL7Constants.HL7_STATUS_ARCHIVED indicates the HL7 has been archived to the filesystem
List<HL7InArchive> hl7InArchives = getHL7InArchivesToMigrate();
// while we still we have any archives to be processed, process them
while (Hl7InArchivesMigrateThread.isActive() && Hl7InArchivesMigrateThread.getTransferStatus() == Status.RUNNING && hl7InArchives != null && !hl7InArchives.isEmpty()) {
Iterator<HL7InArchive> iterator = hl7InArchives.iterator();
while (Hl7InArchivesMigrateThread.isActive() && Hl7InArchivesMigrateThread.getTransferStatus() == Status.RUNNING && iterator.hasNext()) {
HL7InArchive archive = iterator.next();
try {
migrateHL7InArchive(archive);
progressStatusMap.put(HL7Constants.NUMBER_TRANSFERRED_KEY, numberTransferred++);
} catch (DAOException e) {
progressStatusMap.put(HL7Constants.NUMBER_OF_FAILED_TRANSFERS_KEY, numberOfFailedTransfers++);
}
}
// fetch more archives to be processed
hl7InArchives = getHL7InArchivesToMigrate();
}
if (log.isDebugEnabled()) {
log.debug("Transfer of HL7 archives has completed or has been stopped");
}
}
use of org.openmrs.api.db.DAOException in project openmrs-core by openmrs.
the class DatabaseUtil method populateResultsFromSQLQuery.
private static void populateResultsFromSQLQuery(Connection conn, String sql, boolean dataManipulation, List<List<Object>> results) {
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(sql);
if (dataManipulation) {
Integer i = ps.executeUpdate();
List<Object> row = new ArrayList<>();
row.add(i);
results.add(row);
} else {
ResultSet resultSet = ps.executeQuery();
ResultSetMetaData rmd = resultSet.getMetaData();
int columnCount = rmd.getColumnCount();
while (resultSet.next()) {
List<Object> rowObjects = new ArrayList<>();
for (int x = 1; x <= columnCount; x++) {
rowObjects.add(resultSet.getObject(x));
}
results.add(rowObjects);
}
}
} catch (Exception e) {
log.debug("Error while running sql: " + sql, e);
throw new DAOException("Error while running sql: " + sql + " . Message: " + e.getMessage(), e);
} finally {
if (ps != null) {
try {
ps.close();
} catch (SQLException e) {
log.error("Error generated while closing statement", e);
}
}
}
}
use of org.openmrs.api.db.DAOException in project openmrs-core by openmrs.
the class HibernateConceptDAO method getDrugByMapping.
/**
* @see org.openmrs.api.db.ConceptDAO#getDrugs
*/
@Override
public Drug getDrugByMapping(String code, ConceptSource conceptSource, Collection<ConceptMapType> withAnyOfTheseTypesOrOrderOfPreference) throws DAOException {
Criteria criteria = createSearchDrugByMappingCriteria(code, conceptSource, true);
// match with any of the supplied collection or order of preference of conceptMapTypes
if (!withAnyOfTheseTypesOrOrderOfPreference.isEmpty()) {
for (ConceptMapType conceptMapType : withAnyOfTheseTypesOrOrderOfPreference) {
criteria.add(Restrictions.eq("map.conceptMapType", conceptMapType));
List<Drug> drugs = criteria.list();
if (drugs.size() > 1) {
throw new DAOException("There are multiple matches for the highest-priority ConceptMapType");
} else if (drugs.size() == 1) {
return drugs.get(0);
}
// reset for the next execution to avoid unwanted AND clauses on every found map type
criteria = createSearchDrugByMappingCriteria(code, conceptSource, true);
}
} else {
List<Drug> drugs = criteria.list();
if (drugs.size() > 1) {
throw new DAOException("There are multiple matches for the highest-priority ConceptMapType");
} else if (drugs.size() == 1) {
return drugs.get(0);
}
}
return null;
}
use of org.openmrs.api.db.DAOException in project openmrs-core by openmrs.
the class HibernateConceptDAO method deleteConceptStopWord.
/**
* @see org.openmrs.api.db.ConceptDAO#deleteConceptStopWord(java.lang.Integer)
*/
@Override
public void deleteConceptStopWord(Integer conceptStopWordId) throws DAOException {
if (conceptStopWordId == null) {
throw new DAOException("conceptStopWordId is null");
}
Object csw = sessionFactory.getCurrentSession().createCriteria(ConceptStopWord.class).add(Restrictions.eq("conceptStopWordId", conceptStopWordId)).uniqueResult();
if (csw == null) {
throw new DAOException("Concept Stop Word not found or already deleted");
}
sessionFactory.getCurrentSession().delete(csw);
}
use of org.openmrs.api.db.DAOException in project openmrs-core by openmrs.
the class HibernateUserDAO method changePassword.
/**
* @see org.openmrs.api.UserService#changePassword(java.lang.String, java.lang.String)
*/
@Override
public void changePassword(String pw, String pw2) 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");
}
log.info("updating password for " + u.getUsername());
// update the user with the new password
String salt = getLoginCredential(u).getSalt();
String newHashedPassword = Security.encodeString(pw2 + salt);
updateUserPassword(newHashedPassword, salt, u.getUserId(), new Date(), u.getUserId());
}
Aggregations