Search in sources :

Example 6 with DAOException

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");
    }
}
Also used : DAOException(org.openmrs.api.db.DAOException) HL7InArchive(org.openmrs.hl7.HL7InArchive)

Example 7 with DAOException

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);
            }
        }
    }
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) DAOException(org.openmrs.api.db.DAOException) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DAOException(org.openmrs.api.db.DAOException) SQLException(java.sql.SQLException)

Example 8 with DAOException

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;
}
Also used : Drug(org.openmrs.Drug) DAOException(org.openmrs.api.db.DAOException) ConceptMapType(org.openmrs.ConceptMapType) Criteria(org.hibernate.Criteria)

Example 9 with DAOException

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);
}
Also used : DAOException(org.openmrs.api.db.DAOException) OpenmrsObject(org.openmrs.OpenmrsObject)

Example 10 with DAOException

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());
}
Also used : DAOException(org.openmrs.api.db.DAOException) User(org.openmrs.User) LoginCredential(org.openmrs.api.db.LoginCredential) Date(java.util.Date)

Aggregations

DAOException (org.openmrs.api.db.DAOException)11 User (org.openmrs.User)3 LoginCredential (org.openmrs.api.db.LoginCredential)3 Date (java.util.Date)2 Criteria (org.hibernate.Criteria)2 ConceptMapType (org.openmrs.ConceptMapType)2 SerializationException (org.openmrs.serialization.SerializationException)2 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 FlushMode (org.hibernate.FlushMode)1 Auditable (org.openmrs.Auditable)1 ConceptStopWord (org.openmrs.ConceptStopWord)1 Drug (org.openmrs.Drug)1 OpenmrsData (org.openmrs.OpenmrsData)1 OpenmrsMetadata (org.openmrs.OpenmrsMetadata)1 OpenmrsObject (org.openmrs.OpenmrsObject)1 SerializedObject (org.openmrs.api.db.SerializedObject)1