List of usage examples for org.springframework.data.mapping PersistentEntity getPersistentProperty
@Nullable default P getPersistentProperty(Class<? extends Annotation> annotationType)
From source file:org.lightadmin.core.web.support.FileResourceLoader.java
private PersistentProperty attributeMetadata(Class<?> domainType, String field) { DomainTypeAdministrationConfiguration domainTypeAdministrationConfiguration = configuration .forManagedDomainType(domainType); PersistentEntity persistentEntity = domainTypeAdministrationConfiguration.getPersistentEntity(); return persistentEntity.getPersistentProperty(field); }
From source file:org.springframework.data.rest.webmvc.json.Jackson2DatatypeHelperIntegrationTests.java
/** * @see DATAREST-500/*from w w w .j av a2 s . com*/ */ @Test public void configuresHIbernate4ModuleToLoadLazyLoadingProxies() throws Exception { PersistentEntity<?, ?> entity = entities.getPersistentEntity(Order.class); PersistentProperty<?> property = entity.getPersistentProperty("creator"); PersistentPropertyAccessor accessor = entity.getPropertyAccessor(orders.findOne(this.order.getId())); assertThat(objectMapper.writeValueAsString(accessor.getProperty(property)), is(not("null"))); }
From source file:org.springframework.data.rest.webmvc.json.JacksonMetadataUnitTests.java
/** * @see DATAREST-644/*w w w .j a va2 s . c o m*/ */ @Test public void detectsReadOnlyProperty() { JacksonMetadata metadata = new JacksonMetadata(mapper, User.class); PersistentEntity<?, ?> entity = context.getPersistentEntity(User.class); PersistentProperty<?> property = entity.getPersistentProperty("username"); assertThat(metadata.isExported(property), is(true)); assertThat(metadata.isReadOnly(property), is(true)); }
From source file:org.springframework.data.rest.webmvc.json.JacksonMetadataUnitTests.java
/** * @see DATAREST-644//from w ww . j a v a 2 s . c o m */ @Test public void reportsConstructorArgumentAsJacksonWritable() { JacksonMetadata metadata = new JacksonMetadata(mapper, Value.class); PersistentEntity<?, ?> entity = context.getPersistentEntity(Value.class); PersistentProperty<?> property = entity.getPersistentProperty("value"); assertThat(metadata.isReadOnly(property), is(false)); }
From source file:org.lightadmin.core.config.bootstrap.parsing.validation.PersistentFieldMetadataValidator.java
@Override @SuppressWarnings("unchecked") public Collection<? extends DomainConfigurationProblem> validateFieldMetadata( PersistentFieldMetadata fieldMetadata, Class<?> domainType, DomainConfigurationValidationContext validationContext) { MappingContext mappingContext = validationContext.getMappingContext(); final LightAdminConfiguration lightAdminConfiguration = validationContext.getLightAdminConfiguration(); final PersistentEntity persistentEntity = mappingContext.getPersistentEntity(domainType); PersistentProperty persistentProperty = persistentEntity.getPersistentProperty(fieldMetadata.getField()); if (persistentProperty == null) { return newArrayList(validationContext.notPersistableFieldProblem(fieldMetadata.getName())); }/*from ww w . ja v a 2 s .c om*/ if (!isSupportedAttributeType(PersistentPropertyType.forPersistentProperty(persistentProperty))) { return newArrayList(validationContext.notSupportedTypeFieldProblem(fieldMetadata.getName())); } if (!isOfFileReferenceType(persistentProperty)) { return emptyList(); } Annotation annotation = persistentProperty.findAnnotation(FileReference.class); FileReference fileReference = (FileReference) annotation; if (isEmpty(fileReference.baseDirectory())) { if (lightAdminConfiguration.getFileStorageDirectory() != null) { return emptyList(); } return newArrayList( validationContext.missingBaseDirectoryInFileReferenceProblem(fieldMetadata.getName())); } final File directory = getFile(fileReference.baseDirectory()); if (directory.exists() && directory.isDirectory()) { return emptyList(); } return newArrayList(validationContext.missingBaseDirectoryInFileReferenceProblem(fieldMetadata.getName())); }
From source file:org.lightadmin.core.web.json.DynamicFilePropertyOmittingSerializerModifier.java
private PersistentProperty<?> findProperty(String finalName, PersistentEntity<?, ?> entity, BeanDescription description) {//from w ww . j a va 2s . co m for (BeanPropertyDefinition definition : description.findProperties()) { if (definition.getName().equals(finalName)) { return entity.getPersistentProperty(definition.getInternalName()); } } return null; }
From source file:org.moserp.common.json_schema.JsonSchemaBuilderTest.java
public void setupMocks() throws URISyntaxException { configuration = mock(RepositoryRestConfiguration.class); when(configuration.getBaseUri()).thenReturn(new URI("http://localhost:8080/")); mappings = mock(ResourceMappings.class); metaData = mock(ResourceMetadata.class); when(metaData.getPath()).thenReturn(new Path("valueLists")); PersistentEntity persistentEntity = mock(PersistentEntity.class); when(persistentEntities.getPersistentEntity(any())).thenReturn(persistentEntity); PersistentProperty persistentProperty = mock(PersistentProperty.class); when(persistentEntity.getPersistentProperty(any(String.class))).thenReturn(persistentProperty); when(entityLinks.linkFor(any())).thenReturn(BaseUriLinkBuilder.create(new URI("http://localhost:8080/"))); moduleRegistry = mock(ModuleRegistry.class); when(moduleRegistry.getBaseUriForResource(anyString())) .thenReturn(new RestUri("http://localhost:8080/valueLists")); }
From source file:org.moserp.common.json_schema.JsonSchemaBuilder.java
private void populateProperties(Class<?> domainType, BusinessEntity entity) { Map<String, EntityProperty> properties = new HashMap<>(); final PersistentEntity<?, ?> persistentEntity = persistentEntities.getPersistentEntity(domainType); JacksonMetadata jacksonMetadata = new JacksonMetadata(objectMapper, domainType); for (BeanPropertyDefinition definition : jacksonMetadata) { PersistentProperty<?> persistentProperty = persistentEntity .getPersistentProperty(definition.getInternalName()); PropertyFactoryContext context = new PropertyFactoryContext(definition, jacksonMetadata, persistentProperty);/*w w w. j a v a 2 s. com*/ PropertyFactory factory = getFactoryFor(context); if (factory != null) { EntityProperty property = factory.create(context); properties.put(definition.getInternalName(), property); if (property.isRequired()) { entity.getRequired().add(definition.getInternalName()); } } } entity.setProperties(properties); }
From source file:org.moserp.common.structure.ApplicationStructureBuilder.java
private List<EntityProperty> buildProperties(Class<?> domainType) { List<EntityProperty> properties = new ArrayList<>(); final PersistentEntity<?, ?> persistentEntity = persistentEntities.getPersistentEntity(domainType); JacksonMetadata jacksonMetadata = new JacksonMetadata(objectMapper, domainType); for (BeanPropertyDefinition definition : jacksonMetadata) { PersistentProperty<?> persistentProperty = persistentEntity .getPersistentProperty(definition.getInternalName()); PropertyFactoryContext context = new PropertyFactoryContext(definition, jacksonMetadata, persistentProperty);/* ww w .java2 s . c o m*/ PropertyFactory factory = getFactoryFor(context); if (factory != null) { properties.add(factory.create(context)); } } return properties; }
From source file:org.lightadmin.core.web.RepositoryFilePropertyController.java
@RequestMapping(value = BASE_MAPPING + "/file", method = GET) public void filePropertyOfEntity(RootResourceInformation repoRequest, ServletResponse response, @BackendId Serializable id, @PathVariable String property) throws Exception { PersistentEntity<?, ?> persistentEntity = repoRequest.getPersistentEntity(); RepositoryInvoker invoker = repoRequest.getInvoker(); Object domainObj = invoker.invokeFindOne(id); if (null == domainObj) { throw new ResourceNotFoundException(); }/*w ww . ja va 2 s .c o m*/ PersistentProperty<?> prop = persistentEntity.getPersistentProperty(property); if (null == prop) { throw new ResourceNotFoundException(); } if (isOfFileType(prop)) { fileResourceLoader().downloadFile(domainObj, prop, (HttpServletResponse) response); } }