Example usage for org.springframework.dao DataRetrievalFailureException DataRetrievalFailureException

List of usage examples for org.springframework.dao DataRetrievalFailureException DataRetrievalFailureException

Introduction

In this page you can find the example usage for org.springframework.dao DataRetrievalFailureException DataRetrievalFailureException.

Prototype

public DataRetrievalFailureException(String msg, @Nullable Throwable cause) 

Source Link

Document

Constructor for DataRetrievalFailureException.

Usage

From source file:org.jenkinsci.plugins.GithubSecurityRealm.java

/**
 *
 * @param username//from ww  w .j a v  a 2  s  .co  m
 * @return
 * @throws UserMayOrMayNotExistException
 * @throws UsernameNotFoundException
 * @throws DataAccessException
 */
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
    GHUser user = null;

    Authentication token = SecurityContextHolder.getContext().getAuthentication();

    if (token == null) {
        throw new UserMayOrMayNotExistException("Could not get auth token.");
    }

    GithubAuthenticationToken authToken;

    if (token instanceof GithubAuthenticationToken) {
        authToken = (GithubAuthenticationToken) token;
    } else {
        throw new UserMayOrMayNotExistException("Unexpected authentication type: " + token);
    }

    try {
        GithubOAuthUserDetails userDetails = authToken.getUserDetails(username);
        if (userDetails == null)
            throw new UsernameNotFoundException("Unknown user: " + username);

        // Check the username is not an homonym of an organization
        GHOrganization ghOrg = authToken.loadOrganization(username);
        if (ghOrg != null) {
            throw new UsernameNotFoundException("user(" + username + ") is also an organization");
        }

        return userDetails;
    } catch (Error e) {
        throw new DataRetrievalFailureException("loadUserByUsername (username=" + username + ")", e);
    }
}

From source file:ei.ne.ke.cassandra.cql3.AstyanaxCql3Repository.java

/**
 * {@inheritDoc}/*from   w ww.j ava 2s.c o m*/
 */
@Override
public synchronized boolean exists(ID id) {
    try {
        String cql = cqlGen.buildExistsStatement();
        PreparedCqlQuery<String, String> preparedStatement = doPreparedCqlRead(cql);
        Map<String, ByteBuffer> serializedKeyValues = spec.getSerializedKeyValues(id);
        for (String column : spec.getKeyColumns()) {
            preparedStatement = preparedStatement.withValue(serializedKeyValues.get(column));
        }
        OperationResult<CqlResult<String, String>> opResult = preparedStatement.execute();
        LOGGER.debug("attempts: {}, latency: {}ms", opResult.getAttemptsCount(),
                opResult.getLatency(TimeUnit.MILLISECONDS));
        return opResult.getResult().getRows().size() > 0;
    } catch (ConnectionException e) {
        throw new DataRetrievalFailureException("Error while executing CQL3 query", e);
    }
}

From source file:ei.ne.ke.cassandra.cql3.AstyanaxCql3Repository.java

/**
 * {@inheritDoc}//from  w  ww. jav  a  2  s  . c  o m
 * @see https://github.com/Netflix/astyanax/wiki/All-rows-query
 */
@Override
public synchronized List<T> findAll() {
    try {
        String cql = cqlGen.buildFindAllStatement();
        OperationResult<CqlResult<String, String>> opResult = doCqlRead(cql).execute();
        LOGGER.debug("attempts: {}, latency: {}ms", opResult.getAttemptsCount(),
                opResult.getLatency(TimeUnit.MILLISECONDS));
        CqlResult<String, String> cqlResult = opResult.getResult();
        return spec.map(cqlResult.getRows());
    } catch (ConnectionException e) {
        throw new DataRetrievalFailureException("Error while executing CQL3 query", e);
    }
}

From source file:ei.ne.ke.cassandra.cql3.AstyanaxCql3Repository.java

/**
 * {@inheritDoc}/*from   w  ww .  ja  v  a 2s  .c o m*/
 */
@Override
public synchronized <S extends T> S save(S entity) {
    try {
        String cql = cqlGen.buildSaveStatement();
        PreparedCqlQuery<String, String> preparedStatement = doPreparedCqlWrite(cql);
        List<ByteBuffer> serializedEntity = spec.map(entity);
        for (ByteBuffer buf : serializedEntity) {
            preparedStatement = preparedStatement.withValue(buf);
        }
        OperationResult<CqlResult<String, String>> opResult = preparedStatement.execute();
        LOGGER.debug("attempts: {}, latency: {}ms", opResult.getAttemptsCount(),
                opResult.getLatency(TimeUnit.MILLISECONDS));
        return entity;
    } catch (ConnectionException e) {
        throw new DataRetrievalFailureException("Error while executing CQL3 query", e);
    }
}

From source file:ei.ne.ke.cassandra.cql3.AstyanaxCql3Repository.java

/**
 * {@inheritDoc}//  w w  w.j a  v  a  2 s  .  co m
 */
@Override
public synchronized long count(ID restrict) {
    try {
        Map<String, ByteBuffer> serializedKeyValues = spec.getSerializedKeyValues(restrict);
        List<String> keysSet = EntitySpecificationUtils.getKeysSet(serializedKeyValues);
        String cql = cqlGen.buildCountStatement(keysSet);
        PreparedCqlQuery<String, String> preparedStatement = doPreparedCqlRead(cql);
        for (String column : keysSet) {
            preparedStatement = preparedStatement.withValue(serializedKeyValues.get(column));
        }
        OperationResult<CqlResult<String, String>> opResult = preparedStatement.execute();
        LOGGER.debug("attempts: {}, latency: {}ms", opResult.getAttemptsCount(),
                opResult.getLatency(TimeUnit.MILLISECONDS));
        return opResult.getResult().getRows().getRowByIndex(0).getColumns().getColumnByName("count")
                .getLongValue();
    } catch (ConnectionException e) {
        throw new DataRetrievalFailureException("Error while executing CQL3 query", e);
    }
}

From source file:de.tudarmstadt.ukp.clarin.webanno.api.dao.RepositoryServiceDbData.java

/**
 * For a given {@link SourceDocument}, return the {@link AnnotationDocument} for the user or for
 * the CURATION_USER//from  w ww .  j  a v a 2  s. c o  m
 *
 * @param aDocument
 *            the {@link SourceDocument}
 * @param aUsername
 *            the {@link User} who annotates the {@link SourceDocument} or the CURATION_USER
 */
private JCas readCas(SourceDocument aDocument, String aUsername) throws IOException {
    if (log.isDebugEnabled()) {
        log.debug("Getting annotation document [" + aDocument.getName() + "] with ID [" + aDocument.getId()
                + "] in project ID [" + aDocument.getProject().getId() + "] for user [" + aUsername + "]");
    }

    //DebugUtils.smallStack();

    synchronized (lock) {
        File annotationFolder = getAnnotationFolder(aDocument);

        String file = aUsername + ".ser";

        try {
            File serializedCasFile = new File(annotationFolder, file);
            if (!serializedCasFile.exists()) {
                throw new FileNotFoundException("Annotation document of user [" + aUsername
                        + "] for source document [" + aDocument.getName() + "] (" + aDocument.getId()
                        + "). not found in project[" + aDocument.getProject().getName() + "] ("
                        + aDocument.getProject().getId() + ")");
            }

            CAS cas = CasCreationUtils.createCas((TypeSystemDescription) null, null, null);
            readSerializedCas(cas.getJCas(), serializedCasFile);
            return cas.getJCas();
        } catch (UIMAException e) {
            throw new DataRetrievalFailureException("Unable to parse annotation", e);
        }
    }
}

From source file:org.apereo.portal.layout.dlm.RDBMDistributedLayoutStore.java

private IPortletEntity getPortletEntity(String fName, String layoutNodeId, int userId) {
    //Try getting the entity
    final IPortletEntity portletEntity = this.portletEntityDao.getPortletEntity(layoutNodeId, userId);
    if (portletEntity != null) {
        return portletEntity;
    }/*from w w w  .  j  a va2 s. c o m*/

    //Load the portlet definition
    final IPortletDefinition portletDefinition;
    try {
        portletDefinition = this.portletDefinitionRegistry.getPortletDefinitionByFname(fName);
    } catch (Exception e) {
        throw new DataRetrievalFailureException(
                "Failed to retrieve ChannelDefinition for fName='" + fName + "'", e);
    }

    //The channel definition for the fName MUST exist for this class to function
    if (portletDefinition == null) {
        throw new EmptyResultDataAccessException("No ChannelDefinition exists for fName='" + fName + "'", 1);
    }

    //create the portlet entity
    final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
    return this.portletEntityDao.createPortletEntity(portletDefinitionId, layoutNodeId, userId);
}

From source file:org.eurekastreams.server.service.security.userdetails.UserDetailsServiceImpl.java

/**
 * Returns populated UserDetails object for user.
 *
 * @param username//from  w  w  w  . j  a  v a 2 s  .c o  m
 *            The username.
 * @return Populated UserDetails object for user.
 */
@Override
public UserDetails loadUserByUsername(final String username) {
    if (bypassUserName.equalsIgnoreCase(username)) {
        String errorMessage = "Configured to skip loading user details for " + username;
        log.debug(errorMessage);
        throw new UsernameNotFoundException(errorMessage);
    }

    Person person = null;
    PersistentLogin login = null;
    List<GrantedAuthority> authorities = null;
    try {
        person = personMapper.findByAccountId(username);
        login = (loginRepository == null) ? null : loginRepository.getPersistentLogin(username);
        authorities = (authorityProvider == null) ? new ArrayList<GrantedAuthority>(0)
                : authorityProvider.loadAuthoritiesByUsername(username);

        // if user not found in DB, try to create from LDAP
        if (person == null) {
            person = (Person) serviceActionController.execute(new ServiceActionContext(username, null),
                    createUserfromLdapAction);
        }
    } catch (Exception e) {
        String errorMessage = "Error loading user details for: " + username;
        log.error(errorMessage + " " + e.getMessage());

        throw new DataRetrievalFailureException(errorMessage, e);
    }

    // If user still not found, give up.
    if (person == null) {
        String errorMessage = "User not found: " + username;
        log.info(errorMessage);
        throw new UsernameNotFoundException(errorMessage);
    }

    return new ExtendedUserDetailsImpl(person, login,
            authorities.toArray(new GrantedAuthority[authorities.size()]), authenticationType);
}

From source file:org.jasig.portal.layout.dlm.RDBMDistributedLayoutStore.java

protected IPortletEntity getPortletEntity(String fName, String layoutNodeId, int userId) {
    //Try getting the entity
    final IPortletEntity portletEntity = this.portletEntityDao.getPortletEntity(layoutNodeId, userId);
    if (portletEntity != null) {
        return portletEntity;
    }//from w w w  . ja  va 2 s  . c o m

    //Load the portlet definition
    final IPortletDefinition portletDefinition;
    try {
        portletDefinition = this.portletDefinitionRegistry.getPortletDefinitionByFname(fName);
    } catch (Exception e) {
        throw new DataRetrievalFailureException(
                "Failed to retrieve ChannelDefinition for fName='" + fName + "'", e);
    }

    //The channel definition for the fName MUST exist for this class to function
    if (portletDefinition == null) {
        throw new EmptyResultDataAccessException("No ChannelDefinition exists for fName='" + fName + "'", 1);
    }

    //create the portlet entity
    final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
    return this.portletEntityDao.createPortletEntity(portletDefinitionId, layoutNodeId, userId);
}