PersistentEntity<?, ?> entity = persistentEntities.getPersistentEntity(type);
final List<Descriptor> propertyDescriptors = new ArrayList<Descriptor>();
final JacksonMetadata jackson = new JacksonMetadata(mapper, type);
final PropertyMappings propertyMappings = new PropertyMappings(mappings);
final AssociationLinks associationLinks = new AssociationLinks(mappings);
entity.doWithProperties(new SimplePropertyHandler() {
@Override
public void doWithPersistentProperty(PersistentProperty<?> property) {
BeanPropertyDefinition propertyDefinition = jackson.getDefinitionFor(property);
ResourceMapping propertyMapping = propertyMappings.getMappingFor(property);
if (propertyDefinition != null) {
propertyDescriptors.add(//
descriptor(). //
type(Type.SEMANTIC).//
name(propertyDefinition.getName()).//
doc(getDocFor(propertyMapping.getDescription())).//
build());
}
}
});
entity.doWithAssociations(new SimpleAssociationHandler() {
@Override
public void doWithAssociation(Association<? extends PersistentProperty<?>> association) {
PersistentProperty<?> property = association.getInverse();
ResourceMapping mapping = propertyMappings.getMappingFor(property);
DescriptorBuilder builder = descriptor().//
name(mapping.getRel()).doc(getDocFor(mapping.getDescription()));
if (associationLinks.isLinkableAssociation(property)) {
ResourceMetadata targetTypeMapping = mappings.getMappingFor(property.getActualType());
String localPath = targetTypeMapping.getRel().concat("#").concat(targetTypeMapping.getItemResourceRel());
Link link = ControllerLinkBuilder.linkTo(AlpsController.class).slash(localPath).withSelfRel();