@Override
public List<JavaClassSource> generateFrom(RestGenerationContext context) throws Exception
{
List<JavaClassSource> result = new ArrayList<>();
JavaClassSource entity = context.getEntity();
Project project = context.getProject();
String contentType = context.getContentType();
String idType = ResourceGeneratorUtil.resolveIdType(entity);
String persistenceUnitName = context.getPersistenceUnitName();
String idGetterName = ResourceGeneratorUtil.resolveIdGetterName(entity);
String entityTable = ResourceGeneratorUtil.getEntityTable(entity);
String selectExpression = ResourceGeneratorUtil.getSelectExpression(entity, entityTable);
String idClause = ResourceGeneratorUtil.getIdClause(entity, entityTable);
String orderClause = ResourceGeneratorUtil.getOrderClause(entity,
ResourceGeneratorUtil.getJpqlEntityVariable(entityTable));
String resourcePath = ResourceGeneratorUtil.getResourcePath(context);
DTOCollection createdDtos = from(project, entity, context.getTargetPackageName() + ".dto");
JavaClassSource rootDto = createdDtos.getDTOFor(entity, true);
Map<Object, Object> map = new HashMap<>();
map.put("entity", entity);
map.put("dto", rootDto);
map.put("idType", idType);
map.put("getIdStatement", idGetterName);
map.put("contentType", contentType);
map.put("persistenceUnitName", persistenceUnitName);
map.put("entityTable", entityTable);
map.put("selectExpression", selectExpression);
map.put("idClause", idClause);
map.put("orderClause", orderClause);
map.put("resourcePath", resourcePath);
Resource<URL> templateResource = resourceFactory.create(getClass().getResource("EndpointWithDTO.jv"));
Template processor = templateFactory.create(templateResource, FreemarkerTemplate.class);
String output = processor.process(map);
JavaClassSource resource = Roaster.parse(JavaClassSource.class, output);
resource.addImport(rootDto.getQualifiedName());
resource.addImport(entity.getQualifiedName());
resource.setPackage(context.getTargetPackageName());
result.add(resource);
result.addAll(createdDtos.allResources());
return result;
}