Search in sources :

Example 16 with Entity

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);
        }
    }
}
Also used : JpaValueEncoder(org.apache.tapestry5.internal.jpa.JpaValueEncoder) EntityManagerFactory(javax.persistence.EntityManagerFactory) PersistenceUnitInfo(javax.persistence.spi.PersistenceUnitInfo) Metamodel(javax.persistence.metamodel.Metamodel) ValueEncoderFactory(org.apache.tapestry5.services.ValueEncoderFactory) Contribute(org.apache.tapestry5.ioc.annotations.Contribute)

Example 17 with Entity

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);
    }
}
Also used : JSONObject(org.apache.tapestry5.json.JSONObject) PropertyDescriptor(java.beans.PropertyDescriptor) BeanInfo(java.beans.BeanInfo) IntrospectionException(java.beans.IntrospectionException) JSONObject(org.apache.tapestry5.json.JSONObject)

Example 18 with Entity

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);
    }
}
Also used : JSONObject(org.apache.tapestry5.json.JSONObject)

Aggregations

Session (org.hibernate.Session)7 Test (org.testng.annotations.Test)5 HibernateEntityValueEncoder (org.apache.tapestry5.hibernate.web.internal.HibernateEntityValueEncoder)4 EntityPersistentFieldStrategy (org.apache.tapestry5.hibernate.web.internal.EntityPersistentFieldStrategy)3 Entity (org.apache.tapestry5.integration.app1.data.Entity)3 JSONObject (org.apache.tapestry5.json.JSONObject)3 ValueEncoderFactory (org.apache.tapestry5.services.ValueEncoderFactory)3 Logger (org.slf4j.Logger)3 EntityManagerFactory (javax.persistence.EntityManagerFactory)2 Metamodel (javax.persistence.metamodel.Metamodel)2 PersistenceUnitInfo (javax.persistence.spi.PersistenceUnitInfo)2 SessionRestorable (org.apache.tapestry5.hibernate.web.internal.SessionRestorable)2 Contribute (org.apache.tapestry5.ioc.annotations.Contribute)2 Entity (hu.blackbelt.epsilon.runtime.model.test1.data.Entity)1 BeanInfo (java.beans.BeanInfo)1 IntrospectionException (java.beans.IntrospectionException)1 PropertyDescriptor (java.beans.PropertyDescriptor)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 EntityType (javax.persistence.metamodel.EntityType)1