if (dtoCollection.containsDTOFor(entity, topLevel))
{
return dtoCollection.getDTOFor(entity, topLevel);
}
JPAProperty idProperty = null;
JPABean bean = new JPABean(entity);
idProperty = parseIdPropertyForJPAEntity(bean);
DTOClassBuilder dtoClassBuilder = new DTOClassBuilder(entity, idProperty, topLevel)
.setPackage(dtoPackage)
.setEmbeddedType(isEmbeddedType);
for (JPAProperty property : bean.getProperties())
{
if (property.isTransient() || property.hasAnnotation(Transient.class))
{
// No known reason for transient fields to be present in DTOs.
// Revisit this if necessary for @Transient
continue;
}
String qualifiedPropertyType = property.getQualifiedType();
// Get the JavaClass for the field's type so that we can inspect it later for annotations and such
// and recursively generate a DTO for it as well.
JavaClass propertyClass = tryGetJavaClass(qualifiedPropertyType);
boolean isReadable = property.isReadable();
boolean isCollection = property.hasAnnotation(OneToMany.class) || property.hasAnnotation(ManyToMany.class);
Type<?> propertyTypeInspector = property.getType();
boolean parameterized = propertyTypeInspector.isParameterized();
boolean hasAssociation = property.hasAnnotation(OneToOne.class) || property.hasAnnotation(ManyToOne.class);
boolean isEmbedded = property.hasAnnotation(Embedded.class)
|| (propertyClass != null && propertyClass.hasAnnotation(Embeddable.class));
if (!isReadable)
{
// Skip the field if it lacks a getter. It is obviously not permitted to be read by other classes
continue;
}
if (isCollection && parameterized)
{
if (!topLevel)
{
// Do not expand collections beyond the root
continue;
}
// Create a DTO having the PK-field of the parameterized type of multi-valued collections,
// if it does not exist
Type<?> type = propertyTypeInspector.getTypeArguments().get(0);
String qualifiedParameterizedType = type.getQualifiedName();
JavaClass parameterizedClass = tryGetJavaClass(qualifiedParameterizedType);
if (parameterizedClass == null)
{
ShellMessages.warn(writer, "Omitting creation of fields and DTO for type " + qualifiedParameterizedType
+ " due to missing source.");
continue;
}
JavaClass nestedDTOClass = generatedDTOGraphForEntity(parameterizedClass, dtoPackage, false, false);
// Then update the DTO for the collection field
JPABean parameterizedClassBean = new JPABean(parameterizedClass);
JPAProperty nestedDtoId = parseIdPropertyForJPAEntity(parameterizedClassBean);
dtoClassBuilder.updateForCollectionProperty(property, nestedDTOClass, type, nestedDtoId);
}
else if (hasAssociation)
{
if (!topLevel)