private void setPersistentEntityId(Object entity, String id) { PersistentProperty idProperty = getPersistentEntityFor(entity.getClass()).getIdProperty(); // Only deal with String because ES generated Ids are strings ! if (idProperty != null && idProperty.getType().isAssignableFrom(String.class)) { Method setter = idProperty.getSetter(); if (setter != null) { try { setter.invoke(entity, id); } catch (Throwable t) { t.printStackTrace(); } } } }
/** * Creates a new {@link PersistentPropertyResourceMapping}. * * @param property must not be {@literal null}. * @param exported whether the property is exported or not. */ public PersistentPropertyResourceMapping( PersistentProperty<?> property, ResourceMapping typeMapping) { Assert.notNull(property, "PersistentProperty must not be null!"); this.property = property; this.typeMapping = typeMapping; this.annotation = property.findAnnotation(RestResource.class); }
private String getPersistentEntityId(Object entity) { PersistentProperty idProperty = getPersistentEntityFor(entity.getClass()).getIdProperty(); if (idProperty != null) { Method getter = idProperty.getGetter(); if (getter != null) { try { Object id = getter.invoke(entity); if (id != null) { return String.valueOf(id); } } catch (Throwable t) { t.printStackTrace(); } } } return null; }
private <T> void setPersistentEntityId(T result, String id, Class<T> clazz) { if (mappingContext != null && clazz.isAnnotationPresent(Document.class)) { PersistentProperty<ElasticsearchPersistentProperty> idProperty = mappingContext.getPersistentEntity(clazz).getIdProperty(); // Only deal with String because ES generated Ids are strings ! if (idProperty != null && idProperty.getType().isAssignableFrom(String.class)) { Method setter = idProperty.getSetter(); if (setter != null) { try { setter.invoke(result, id); } catch (Throwable t) { t.printStackTrace(); } } } } }
/* * (non-Javadoc) * @see org.springframework.data.rest.core.mapping.ResourceMetadataProvider#getMappingFor(org.springframework.data.mapping.PersistentProperty) */ ResourceMapping getMappingFor(PersistentProperty<?> property) { ResourceMapping propertyMapping = propertyCache.get(property); if (propertyMapping != null) { return propertyMapping; } ResourceMetadata propertyTypeMapping = getMappingFor(property.getActualType()); propertyMapping = new PersistentPropertyResourceMapping(property, propertyTypeMapping); propertyCache.put(property, propertyMapping); return propertyMapping; }
/* * (non-Javadoc) * @see org.springframework.data.rest.core.mapping.PersistentEntitiesResourceMappings#isMapped(org.springframework.data.mapping.PersistentProperty) */ @Override public boolean isMapped(PersistentProperty<?> property) { return repositories.hasRepositoryFor(property.getActualType()) && super.isMapped(property); }
/* * (non-Javadoc) * @see org.springframework.data.rest.core.mapping.ResourceMapping#getRel() */ @Override public String getRel() { return annotation != null && StringUtils.hasText(annotation.rel()) ? annotation.rel() : property.getName(); }
/* * (non-Javadoc) * @see org.springframework.data.rest.core.mapping.ResourceMapping#getPath() */ @Override public Path getPath() { return annotation != null && StringUtils.hasText(annotation.path()) ? new Path(annotation.path()) : new Path(property.getName()); }
public static String relativePathToDomainStorageAttributeDirectory( String domainTypeName, Object idValue, PersistentProperty attrMeta) { return relativePathToDomainStorageDirectory(domainTypeName, idValue) + "/" + attrMeta.getName(); }