@Override
public List<JavaClassSource> generateFrom(RestGenerationContext context) throws Exception
{
List<JavaClassSource> result = new ArrayList<>();
JavaClassSource entity = context.getEntity();
Project project = context.getProject();
String contentType = ResourceGeneratorUtil.getContentType(context.getContentType());
String idType = JPAEntityUtil.resolveIdType(entity);
String persistenceUnitName = context.getPersistenceUnitName();
String idGetterName = JPAEntityUtil.resolveIdGetterName(entity);
String entityTable = JPAEntityUtil.getEntityTable(entity);
String selectExpression = JPAEntityUtil.getSelectExpression(entity, entityTable);
String idClause = JPAEntityUtil.getIdClause(entity, entityTable);
String orderClause = JPAEntityUtil.getOrderClause(entity,
JPAEntityUtil.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;
}