List of usage examples for org.springframework.data.repository.core EntityInformation getId
@Nullable ID getId(T entity);
From source file:org.lightadmin.core.web.support.DynamicPersistentEntityResourceAssembler.java
/** * @see DATAREST-269 (https://jira.spring.io/browse/DATAREST-269) *///from ww w .ja va2s . c om @Override public Link getSelfLinkFor(Object instance) { Assert.notNull(instance, "Domain object must not be null!"); Repositories repositories = repositories(this); Class instanceType = instance.getClass(); PersistentEntity<?, ?> entity = repositories.getPersistentEntity(instanceType); if (entity == null) { throw new IllegalArgumentException( String.format("Cannot create self link for %s! No persistent entity found!", instanceType)); } EntityInformation<Object, Serializable> entityInformation = repositories .getEntityInformationFor(instanceType); Serializable id = entityInformation.getId(instance); if (id == null) { return entityLinks(this).linkToCollectionResource(entity.getType()).withSelfRel(); } return entityLinks(this).linkToSingleResource(entity.getType(), id).withSelfRel(); }