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:org.sharetask.repository.base.BaseJpaRepositoryImpl.java

public T read(final ID id) {
    final T entity = entityManager.find(this.entityClass, id);
    if (entity == null) {
        throw new EntityNotFoundException(
                "Entity for class " + this.entityClass + " with id " + id + " can not be found!");
    }/*from  ww  w . ja va2s.co m*/
    return entity;
}

From source file:com.tapas.evidence.repository.data.ReadOnlyRepositoryImpl.java

@Override
public T read(ID id) {
    if (log.isTraceEnabled()) {
        log.trace("Reading entity for id: " + id);
    }// w  w w . j av a 2s  .  c o m
    final T entry = this.entityManager.find(this.entityClass, id);
    if (entry == null) {
        throw new EntityNotFoundException(
                "Entity for class " + this.entityClass + " with id " + id + " can not be found!");
    }
    return entry;
}

From source file:nh.examples.springintegration.order.framework.domain.Repository.java

public T getById(EntityIdentifier entityIdentifier) {
    checkNotNull(entityIdentifier);/*www  .j a v a2  s  .c o  m*/

    T aggregateRoot = _entityManager.find(getAggregateType(), entityIdentifier);

    if (aggregateRoot == null) {
        throw new EntityNotFoundException(format("Aggregate with id '{}' not found", entityIdentifier));
    }

    return aggregateRoot;

}

From source file:com.training.rest.api.BookController.java

@RequestMapping(value = "/books/{id}", method = RequestMethod.GET)
@ResponseBody//from  ww  w .j  ava 2  s. c o m
public Book getBook(@PathVariable(value = "id") Long id) {
    Book book = bookService.getBook(id);
    if (book == null) {
        throw new EntityNotFoundException("Book not found");
    }
    return book;
}

From source file:controllers.base.SareTransactionalAction.java

public static <T extends PersistentObject> T fetchResource(Context ctx, UUID id, Class<T> clazz,
        boolean bypassAccessibility) {
    Validate.notNull(clazz);//from   ww w.  j  a v  a2  s  . c  om

    Logger.info(LoggedAction.getLogEntry(ctx,
            String.format("attempting to fetch resource: %s of type: %s", id, clazz.getName())));

    T object = null;
    try {
        byte[] uuid = UuidUtils.toBytes(id);
        object = em().find(clazz, uuid);

        if (object != null && (!SessionedAction.isOwnerOf(object)
                || (!bypassAccessibility && object instanceof UserInaccessibleModel))) {
            throw new AccessControlException(UuidUtils.normalize(id));
        }
    } catch (EntityNotFoundException e) {
        object = null;
    }

    if (object == null) {
        throw new EntityNotFoundException(UuidUtils.normalize(id));
    }

    Logger.info(LoggedAction.getLogEntry(ctx,
            String.format("found resource: %s of type: %s", id, clazz.getName())));
    return object;
}

From source file:io.syndesis.rest.v1.handler.connection.ConnectionActionHandler.java

public ConnectionActionHandler(final Connection connection, final VerificationConfigurationProperties config) {
    this.connection = connection;
    this.config = config;

    final Optional<Connector> maybeConnector = connection.getConnector();
    connector = maybeConnector.orElseThrow(() -> new EntityNotFoundException(
            "Connection with id `" + connection.getId() + "` does not have a Connector defined"));

    actions = connector.getActions();//  w  w  w .j a  v a  2s  .  co  m
}

From source file:com.github.lothar.security.acl.jpa.repository.AclJpaRepository.java

@Override
public T getOne(ID id) {
    T entity = this.findOne(id);
    if (entity == null) {
        throw new EntityNotFoundException("Unable to find " + getDomainClass().getName() + " with id " + id);
    }/*w w w. ja va  2s .c o m*/
    return entity;
}

From source file:com.tapas.evidence.repository.data.CrudRepositoryImpl.java

@Override
public T read(ID id) {
    if (log.isTraceEnabled()) {
        log.trace("Reading entity for id: " + id);
    }//www. jav  a2 s  . co  m
    final T entry;
    if (entityClass.isInstance(TenantAware.class)) {
        entry = readTenantAware(id);
    } else {
        entry = this.entityManager.find(this.entityClass, id);
    }
    if (entry == null) {
        throw new EntityNotFoundException(
                "Entity for class " + this.entityClass + " with id " + id + " can not be found!");
    }
    return entry;
}

From source file:com.hartveld.commons.db.DAOBase.java

@Override
public void removeById(final long id) {
    LOG.trace("removeById: {}", id);

    final T entity = em.find(entityClass, id);

    if (entity != null) {
        em.remove(entity);// ww w.  jav a2s .  co m
    } else {
        throw new EntityNotFoundException(
                "Entity of type '" + entityName + "' with id '" + id + "' does not exist");
    }
}

From source file:io.syndesis.rest.v1.handler.connection.ConnectionActionHandler.java

@POST
@Path(value = "/{id}")
@Produces(MediaType.APPLICATION_JSON)/*from  w w w  .  j a v a 2s .  c  om*/
@ApiOperation("Retrieves enriched action definition, that is an action definition that has input/output data shapes and property enums defined with respect to the given action properties")
@ApiResponses(@ApiResponse(code = 200, response = ActionDefinition.class, message = "A map of zero or more action property suggestions keyed by the property name"))
public ActionDefinition enrichWithMetadata(
        @PathParam("id") @ApiParam(required = true, example = "io.syndesis:salesforce-create-or-update:latest") final String id,
        final Map<String, String> properties) {

    final Action action = actions.stream().filter(a -> a.idEquals(id)).findAny()
            .orElseThrow(() -> new EntityNotFoundException("Action with id: " + id));

    final ActionDefinition defaultDefinition = action.getDefinition();

    if (!action.getTags().contains("dynamic")) {
        return defaultDefinition;
    }

    final String connectorId = connector.getId().get();

    final Map<String, String> parameters = new HashMap<>(
            Optional.ofNullable(properties).orElseGet(HashMap::new));
    // put all action parameters with `null` values
    defaultDefinition.getPropertyDefinitionSteps()
            .forEach(step -> step.getProperties().forEach((k, v) -> parameters.putIfAbsent(k, null)));

    // lastly put all connection properties
    parameters.putAll(connection.getConfiguredProperties());

    final Client client = createClient();
    final WebTarget target = client.target(
            String.format("http://%s/api/v1/connectors/%s/actions/%s", config.getService(), connectorId, id));

    final ActionDefinition.Builder enriched = new ActionDefinition.Builder().createFrom(defaultDefinition);
    final DynamicActionMetadata dynamicActionMetadata = target.request(MediaType.APPLICATION_JSON)
            .post(Entity.entity(parameters, MediaType.APPLICATION_JSON), DynamicActionMetadata.class);

    final Map<String, List<DynamicActionMetadata.ActionPropertySuggestion>> actionPropertySuggestions = dynamicActionMetadata
            .properties();
    actionPropertySuggestions.forEach((k, vals) -> enriched.replaceConfigurationProperty(k, b -> b.addAllEnum(
            vals.stream().map(s -> ConfigurationProperty.PropertyValue.Builder.from(s))::iterator)));

    //Setting the defaultValue as suggested by the metadata
    for (Entry<String, List<ActionPropertySuggestion>> suggestions : actionPropertySuggestions.entrySet()) {
        if (suggestions.getValue().size() == 1) {
            for (DynamicActionMetadata.ActionPropertySuggestion suggestion : suggestions.getValue()) {
                enriched.replaceConfigurationProperty(suggestion.displayValue(),
                        v -> v.defaultValue(suggestion.value()));
            }
        }
    }

    final Object input = dynamicActionMetadata.inputSchema();
    if (shouldEnrichDataShape(defaultDefinition.getInputDataShape(), input)) {
        enriched.inputDataShape(new DataShape.Builder().type(typeFrom(input)).kind("json-schema")
                .specification(specificationFrom(input)).build());
    }

    final Object output = dynamicActionMetadata.outputSchema();
    if (shouldEnrichDataShape(defaultDefinition.getOutputDataShape(), output)) {
        enriched.outputDataShape(new DataShape.Builder().type(typeFrom(output)).kind("json-schema")
                .specification(specificationFrom(output)).build());
    }

    return enriched.build();
}