コード例 #1
0
 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();
       }
     }
   }
 }
コード例 #2
0
    /**
     * 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);
    }
コード例 #3
0
 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;
 }
コード例 #4
0
 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();
         }
       }
     }
   }
 }
コード例 #5
0
  /*
   * (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;
  }
コード例 #6
0
 /*
  * (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);
 }
コード例 #7
0
 /*
  * (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();
 }
コード例 #8
0
 /*
  * (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());
 }
コード例 #9
0
 public static String relativePathToDomainStorageAttributeDirectory(
     String domainTypeName, Object idValue, PersistentProperty attrMeta) {
   return relativePathToDomainStorageDirectory(domainTypeName, idValue) + "/" + attrMeta.getName();
 }