use of org.apache.tapestry5.integration.app1.data.Entity in project tapestry-5 by apache.
the class JpaModule method provideValueEncoders.
@Contribute(ValueEncoderSource.class)
public static void provideValueEncoders(final MappedConfiguration<Class, ValueEncoderFactory> configuration, @Symbol(JpaSymbols.PROVIDE_ENTITY_VALUE_ENCODERS) final boolean provideEncoders, final EntityManagerSource entityManagerSource, final EntityManagerManager entityManagerManager, final TypeCoercer typeCoercer, final PropertyAccess propertyAccess, final LoggerSource loggerSource) {
if (!provideEncoders)
return;
for (final PersistenceUnitInfo info : entityManagerSource.getPersistenceUnitInfos()) {
final EntityManagerFactory emf = entityManagerSource.getEntityManagerFactory(info.getPersistenceUnitName());
final Metamodel metamodel = emf.getMetamodel();
for (final EntityType<?> entity : metamodel.getEntities()) {
final Class<?> javaType = entity.getJavaType();
final ValueEncoderFactory factory = new ValueEncoderFactory() {
@Override
public ValueEncoder create(final Class type) {
return new JpaValueEncoder(entity, entityManagerManager, info.getPersistenceUnitName(), propertyAccess, typeCoercer, loggerSource.getLogger(javaType));
}
};
configuration.add(javaType, factory);
}
}
}
use of org.apache.tapestry5.integration.app1.data.Entity in project tapestry-5 by apache.
the class DefaultOpenApiTypeDescriber method describeSchema.
@Override
public void describeSchema(Class<?> entity, JSONObject schemas) {
final String name = getSchemaName(entity);
// Don't overwrite already provided schemas
if (!schemas.containsKey(name)) {
JSONObject schema = new JSONObject();
JSONObject properties = new JSONObject();
final BeanInfo beanInfo;
try {
beanInfo = Introspector.getBeanInfo(entity, Object.class);
} catch (IntrospectionException e) {
throw new RuntimeException(e);
}
final PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
final String propertyName = propertyDescriptor.getName();
final Class<?> type = propertyDescriptor.getPropertyType();
Optional<String> schemaType = getOpenApiType(type);
if (schemaType.isPresent()) {
JSONObject propertyDescription = new JSONObject();
propertyDescription.put("type", schemaType.get());
properties.put(propertyName, propertyDescription);
}
// else if (mappedEntities.contains(entity))
// {
// JSONObject propertyDescription = new JSONObject();
// propertyDescription.put("schema",
// new JSONObject("$ref", getSchemaReference(type)));
// properties.put(propertyName, propertyDescription);
// }
}
schema.put("properties", properties);
schemas.put(name, schema);
}
}
use of org.apache.tapestry5.integration.app1.data.Entity in project tapestry-5 by apache.
the class JacksonOpenApiTypeDescriber method describeSchema.
@Override
public void describeSchema(Class<?> entity, JSONObject schemas) {
if (entities.contains(entity)) {
final JSONObject schema = new JSONObject(schemaGenerator.generateSchema(entity).toString());
schema.remove("$schema");
schemas.put(getSchemaName(entity), schema);
}
}
Aggregations