Search in sources :

Example 81 with NoResultException

use of javax.persistence.NoResultException in project ORCID-Source by ORCID.

the class ClientDetailsManagerReadOnlyImpl method findByClientId.

@Override
public ClientDetailsEntity findByClientId(String clientId) {
    ClientDetailsEntity result = null;
    try {
        Date lastModified = clientDetailsDao.getLastModified(clientId);
        result = clientDetailsDao.findByClientId(clientId, lastModified.getTime());
        if (result != null) {
            if (!result.getClientId().equals(clientId))
                LOGGER.error("Client getClientId doesn't match. Requested: " + clientId + " Returned: " + result.getClientId());
            if (!result.getId().equals(clientId))
                LOGGER.error("Client getId() doesn't match. Requested: " + clientId + " Returned: " + result.getId());
        }
    } catch (NoResultException nre) {
        LOGGER.error("Error getting client by id:" + clientId, nre);
    }
    return result;
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) NoResultException(javax.persistence.NoResultException) Date(java.util.Date)

Example 82 with NoResultException

use of javax.persistence.NoResultException in project ORCID-Source by ORCID.

the class OrcidApiServiceDelegatorImpl method getOrcidSearchResultsResponse.

private Response getOrcidSearchResultsResponse(OrcidSearchResults orcidSearchResults, String query) {
    if (orcidSearchResults != null) {
        OrcidMessage orcidMessage = new OrcidMessage();
        orcidMessage.setMessageVersion("1.2");
        orcidMessage.setOrcidSearchResults(orcidSearchResults);
        //TODO: THIS FAILS if there is no profile in SOLR (org.orcid.core.indexPublicProfile=false or via message-listener)
        orcidMessageUtil.setSourceName(orcidMessage);
        return Response.ok(orcidMessage).build();
    } else {
        Object[] params = { query };
        throw new NoResultException(localeManager.resolveMessage("apiError.no_search_result.exception", params));
    }
}
Also used : OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) NoResultException(javax.persistence.NoResultException)

Example 83 with NoResultException

use of javax.persistence.NoResultException in project ORCID-Source by ORCID.

the class OrcidPropsDaoImpl method getValue.

@Override
public String getValue(String key) {
    Assert.hasText(key, "Cannot look for empty keys");
    Query query = entityManager.createQuery("SELECT value FROM OrcidPropsEntity WHERE key=:key");
    query.setParameter("key", key);
    try {
        return (String) query.getSingleResult();
    } catch (NonUniqueResultException nure) {
        throw nure;
    } catch (NoResultException nre) {
        return null;
    }
}
Also used : NonUniqueResultException(javax.persistence.NonUniqueResultException) Query(javax.persistence.Query) NoResultException(javax.persistence.NoResultException)

Example 84 with NoResultException

use of javax.persistence.NoResultException in project ORCID-Source by ORCID.

the class OrcidPropsDaoImpl method exists.

/**
     * Checks if the given key exists in the OrcidPropsEntity table.
     * 
     * @param key
     * @return true if the key exists on the OrcidPropsEntity table
     * @throws NonUniqueResultException
     *             if there are more than one row with the same key name
     * */
@Override
public boolean exists(String key) throws NonUniqueResultException {
    Assert.hasText(key, "Cannot look for empty keys");
    Query query = entityManager.createQuery("FROM OrcidPropsEntity WHERE key=:key");
    query.setParameter("key", key);
    try {
        query.getSingleResult();
    } catch (NoResultException nre) {
        return false;
    } catch (NonUniqueResultException nure) {
        throw nure;
    }
    return true;
}
Also used : NonUniqueResultException(javax.persistence.NonUniqueResultException) Query(javax.persistence.Query) NoResultException(javax.persistence.NoResultException)

Example 85 with NoResultException

use of javax.persistence.NoResultException in project ORCID-Source by ORCID.

the class InternalSSODaoImpl method getRecordLastModified.

@Override
public Date getRecordLastModified(String orcid, String token, Date maxAge) {
    TypedQuery<Date> query = entityManager.createQuery("SELECT lastModified FROM InternalSSOEntity WHERE orcid = :orcid AND token = :token AND last_modified >= :maxAge", Date.class);
    query.setParameter("orcid", orcid);
    query.setParameter("token", token);
    query.setParameter("maxAge", maxAge);
    try {
        Date result = query.getSingleResult();
        return result;
    } catch (NoResultException nre) {
    }
    return null;
}
Also used : NoResultException(javax.persistence.NoResultException) Date(java.util.Date)

Aggregations

NoResultException (javax.persistence.NoResultException)169 Query (javax.persistence.Query)130 EntityManager (javax.persistence.EntityManager)40 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)17 NonUniqueResultException (javax.persistence.NonUniqueResultException)15 Test (org.junit.Test)14 Transactional (org.springframework.transaction.annotation.Transactional)14 UnitOfWork (com.google.inject.persist.UnitOfWork)12 ConfigurationStoreException (org.nhindirect.config.store.ConfigurationStoreException)9 TblMle (com.intel.mtwilson.as.data.TblMle)8 IOException (java.io.IOException)8 TblModuleManifest (com.intel.mtwilson.as.data.TblModuleManifest)7 WebResource (org.asqatasun.entity.subject.WebResource)6 ASException (com.intel.mountwilson.as.common.ASException)5 IllegalOrphanException (com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)5 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)5 UserAccount (com.jappstart.model.auth.UserAccount)5 List (java.util.List)5 Parameter (org.asqatasun.entity.parameterization.Parameter)5 Transactional (com.google.inject.persist.Transactional)4