Example usage for javax.persistence EntityNotFoundException EntityNotFoundException

List of usage examples for javax.persistence EntityNotFoundException EntityNotFoundException

Introduction

In this page you can find the example usage for javax.persistence EntityNotFoundException EntityNotFoundException.

Prototype

public EntityNotFoundException(String message) 

Source Link

Document

Constructs a new EntityNotFoundException exception with the specified detail message.

Usage

From source file:it.smartcommunitylab.aac.apikey.APIKeyManager.java

/**
 * Update key scopes. /* w w  w . ja v  a2  s  .c  o  m*/
 * @param key
 * @param data
 * @return
 * @throws #{@link EntityNotFoundException} if the key does not exists
 */
public APIKey updateKeyScopes(String key, Set<String> scopes) throws EntityNotFoundException {
    APIKeyEntity entity = keyRepo.findOne(key);
    if (entity != null) {
        if (scopes != null) {
            ClientDetailsEntity client = clientRepo.findByClientId(entity.getClientId());
            Set<String> targetScopes = new HashSet<>(scopes);
            targetScopes.retainAll(client.getScope());
            entity.setScope(StringUtils.collectionToCommaDelimitedString(targetScopes));
        }

        keyRepo.save(entity);
        APIKey result = new APIKey(entity);
        log.debug("Update API Key data " + key);
        keyCache.put(key, result);
        return result;
    }
    throw new EntityNotFoundException(key);
}

From source file:org.apache.cxf.fediz.service.idp.service.jpa.ApplicationDAOJPAImpl.java

@Override
public void removeClaimFromApplication(Application application, RequestClaim claim) {
    ApplicationEntity applicationEntity = null;
    if (application.getId() != 0) {
        applicationEntity = em.find(ApplicationEntity.class, application.getId());
    } else {/*from   ww w . ja v  a 2s  .  com*/
        Query query = null;
        query = em.createQuery("select a from Application a where a.realm=:realm");
        query.setParameter("realm", application.getRealm());

        applicationEntity = (ApplicationEntity) query.getSingleResult();
    }

    ApplicationClaimEntity foundEntity = null;
    for (ApplicationClaimEntity acm : applicationEntity.getRequestedClaims()) {
        if (claim.getClaimType().toString().equals(acm.getClaim().getClaimType())) {
            foundEntity = acm;
            break;
        }
    }
    if (foundEntity == null) {
        throw new EntityNotFoundException("ApplicationClaimEntity not found");
    }

    applicationEntity.getRequestedClaims().remove(foundEntity);
}

From source file:it.smartcommunitylab.aac.apikey.APIKeyManager.java

/**
 * Create a new key for the specified client app
 * @param clientId//  w ww .  j a va  2  s  .  co  m
 * @param validity
 * @param data
 * @return
 * @throws #{@link EntityNotFoundException} if the specified client does not exist 
 */
public APIKey createKey(String clientId, Long validity, Map<String, Object> data, Set<String> scopes)
        throws EntityNotFoundException {
    ClientDetailsEntity client = clientRepo.findByClientId(clientId);
    if (client == null)
        throw new EntityNotFoundException("Client not found: " + clientId);

    APIKeyEntity entity = new APIKeyEntity();
    entity.setAdditionalInformation(APIKey.toDataString(data));
    entity.setValidity(validity);
    entity.setClientId(clientId);
    entity.setApiKey(UUID.randomUUID().toString());
    entity.setIssuedTime(System.currentTimeMillis());
    entity.setUserId(client.getDeveloperId());
    entity.setUsername(userManager.getUserInternalName(client.getDeveloperId()));
    entity.setRoles(APIKey.toRolesString(userManager.getUserRoles(client.getDeveloperId())));
    if (scopes != null && !scopes.isEmpty()) {
        Set<String> targetScopes = new HashSet<>(scopes);
        targetScopes.retainAll(client.getScope());
        entity.setScope(StringUtils.collectionToCommaDelimitedString(targetScopes));
    }
    keyRepo.save(entity);
    log.debug("Saved API Key  " + entity.getApiKey());

    APIKey result = new APIKey(entity);
    keyCache.put(result.getApiKey(), result);
    return result;
}

From source file:com.expressui.core.view.field.SelectField.java

/**
 * Listener method invoked when user selects item.
 *///from   w ww. j  av a2 s  .c o m
public void itemSelected() {
    V selectedValue = getSelectedValue();
    V reFoundEntity = genericDao.reFind(selectedValue);
    if (reFoundEntity == null) {
        throw new EntityNotFoundException(selectedValue.toString());
    }

    T bean = typedForm.getBean();
    try {
        PropertyUtils.setProperty(bean, propertyId, selectedValue);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    } catch (InvocationTargetException e) {
        throw new RuntimeException(e);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(e);
    }

    Property property = field.getPropertyDataSource();
    field.setPropertyDataSource(property);
    entitySelect.close();
}

From source file:com.impetus.ankush.common.dao.impl.GenericDaoJpa.java

/**
 * {@inheritDoc}/*from   w ww.j a  v  a  2 s. co  m*/
 */
public T getReference(P id) {
    try {
        T entity = this.entityManager.getReference(this.persistentClass, id);
        if (entity == null) {
            throw new RuntimeException();
        }
        return entity;
    } catch (Exception e) {
        String msg = "Uh oh, '" + this.persistentClass + "' object with id '" + id + "' not found...";
        log.warn(msg);
        throw new EntityNotFoundException(msg);
    }
}

From source file:io.syndesis.dao.manager.DataManager.java

public <T extends WithId<T>> void update(T entity) {
    Optional<String> id = entity.getId();
    if (!id.isPresent()) {
        throw new EntityNotFoundException("Setting the id on the entity is required for updates");
    }//w  ww  .  ja v  a2 s.  c o m

    String idVal = id.get();

    Kind kind = entity.getKind();
    T previous = this.<T, T>doWithDataAccessObject(kind.getModelClass(), d -> d.update(entity));

    Map<String, T> cache = caches.getCache(kind.getModelName());
    if (!cache.containsKey(idVal) && previous == null) {
        throw new EntityNotFoundException("Can not find " + kind + " with id " + idVal);
    }

    cache.put(idVal, entity);
    broadcast("updated", kind.getModelName(), idVal);

    //TODO 1. properly merge the data ? + add data validation in the REST Resource
}

From source file:io.syndesis.dao.manager.DataManager.java

public <T extends WithId<T>> boolean delete(Class<T> model, String id) {
    if (id == null || id.equals("")) {
        throw new EntityNotFoundException("Setting the id on the entity is required for updates");
    }/*from w  w w. j av a  2s .  com*/

    Kind kind = Kind.from(model);
    Map<String, WithId<T>> cache = caches.getCache(kind.getModelName());

    // Remove it out of the cache
    WithId<T> entity = cache.remove(id);
    boolean deletedInCache = entity != null;

    // And out of the DAO
    boolean deletedFromDAO = Boolean.TRUE.equals(doWithDataAccessObject(model, d -> d.delete(id)));

    // Return true if the entity was found in any of the two.
    if (deletedInCache || deletedFromDAO) {
        broadcast("deleted", kind.getModelName(), id);
        return true;
    }

    return false;
}

From source file:org.apache.cxf.fediz.service.idp.service.jpa.IdpDAOJPAImpl.java

@Override
public void removeClaimFromIdp(Idp idp, Claim claim) {
    IdpEntity idpEntity = null;//from   w ww.  j  a  va  2 s.  c o  m
    if (idp.getId() != 0) {
        idpEntity = em.find(IdpEntity.class, idp.getId());
    } else {
        idpEntity = getIdpEntity(idp.getRealm(), em);
    }
    if (idpEntity == null) {
        throw new EntityNotFoundException("IdpEntity not found");
    }

    ClaimEntity claimEntity = null;
    if (claim.getId() != 0) {
        claimEntity = em.find(ClaimEntity.class, claim.getId());
    } else {
        claimEntity = ClaimDAOJPAImpl.getClaimEntity(claim.getClaimType().toString(), em);
    }
    if (claimEntity == null) {
        throw new EntityNotFoundException("ClaimEntity not found");
    }

    if (!idpEntity.getClaimTypesOffered().remove(claimEntity)) {
        throw new EntityNotFoundException("ClaimEntity not assigned to IdpEntity");
    }

    LOG.debug("Claim '{}' removed from IDP '{}'", claim.getClaimType(), idp.getRealm());
}

From source file:com.redhat.ipaas.api.v1.rest.DataManager.java

public void update(WithId entity) {
    String kind = entity.kind();/*  ww w  .  j  a v  a2  s .c om*/
    Map<String, WithId> cache = caches.getCache(kind);

    Optional<String> id = entity.getId();
    if (!id.isPresent()) {
        throw new EntityNotFoundException("Setting the id on the entity is required for updates");
    }

    String idVal = id.get();
    if (!cache.containsKey(idVal)) {
        throw new EntityNotFoundException("Can not find " + kind + " with id " + idVal);
    }

    doWithDataAccessObject(kind, d -> d.update(entity));
    cache.put(idVal, entity);
    //TODO 1. properly merge the data ? + add data validation in the REST Resource
}

From source file:com.redhat.ipaas.api.v1.rest.DataManager.java

public boolean delete(String kind, String id) {
    Map<String, WithId> cache = caches.getCache(kind);
    if (id == null || id.equals(""))
        throw new EntityNotFoundException("Setting the id on the entity is required for updates");
    if (!cache.containsKey(id))
        throw new EntityNotFoundException("Can not find " + kind + " with id " + id);

    WithId entity = cache.get(id);/*from  ww  w .  j a  va 2  s. co m*/
    if (entity != null && doWithDataAccessObject(kind, d -> d.delete(entity))) {
        cache.remove(id);
        return true;
    } else {
        return false;
    }
}