gmunozfe commented on code in PR #4078:
URL: 
https://github.com/apache/incubator-kie-kogito-runtimes/pull/4078#discussion_r2536797054


##########
kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/RestResourceQuarkusTemplate.java:
##########
@@ -88,10 +91,23 @@ public class $Type$Resource {
     }
 
     @GET
-    @Produces(MediaType.APPLICATION_JSON)
+    @Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_HTML})
     @Operation(operationId = "getAllProcessInstances_$name$", summary = 
"$documentation$", description = "$processInstanceDescription$")
-    public List<$Type$Output> getResources_$name$() {
-        return processService.getProcessInstanceOutput(process);
+    public Response getResources_$name$(@Context HttpHeaders headers) {
+        List<$Type$Output> out = 
processService.getProcessInstanceOutput(process);
+        boolean wantsHtml = headers.getAcceptableMediaTypes()
+            .stream()
+            .anyMatch(mt -> mt.isCompatible(MediaType.TEXT_HTML_TYPE)
+                    && !mt.isWildcardType() && !mt.isWildcardSubtype());

Review Comment:
   MediaType.isCompatible(TEXT_HTML_TYPE) already excludes generic */*, so 
these extra checks are redundant.
   ```suggestion
                     );
   ```



##########
kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/RestResourceQuarkusTemplate.java:
##########
@@ -88,10 +91,23 @@ public class $Type$Resource {
     }
 
     @GET
-    @Produces(MediaType.APPLICATION_JSON)
+    @Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_HTML})
     @Operation(operationId = "getAllProcessInstances_$name$", summary = 
"$documentation$", description = "$processInstanceDescription$")
-    public List<$Type$Output> getResources_$name$() {
-        return processService.getProcessInstanceOutput(process);
+    public Response getResources_$name$(@Context HttpHeaders headers) {
+        List<$Type$Output> out = 
processService.getProcessInstanceOutput(process);
+        boolean wantsHtml = headers.getAcceptableMediaTypes()
+            .stream()
+            .anyMatch(mt -> mt.isCompatible(MediaType.TEXT_HTML_TYPE)
+                    && !mt.isWildcardType() && !mt.isWildcardSubtype());
+        if (wantsHtml) {
+            InputStream htmlStream = 
getClass().getResourceAsStream("/META-INF/resources/index.html");
+            if (htmlStream == null) {
+                return Response.status(Response.Status.NOT_FOUND)
+                    .entity("HTML resource not found").build();
+        }

Review Comment:
   After this, could we better return a `StreamingOutput` wrapping the 
`InputStream`? In this way, we ensure closure automatically:
   
   ```
   StreamingOutput stream = os -> {
       try (htmlStream) {
           htmlStream.transferTo(os);
       }
   };
   ```



##########
kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/RestResourceQuarkusTemplate.java:
##########
@@ -88,10 +91,23 @@ public class $Type$Resource {
     }
 
     @GET
-    @Produces(MediaType.APPLICATION_JSON)
+    @Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_HTML})
     @Operation(operationId = "getAllProcessInstances_$name$", summary = 
"$documentation$", description = "$processInstanceDescription$")
-    public List<$Type$Output> getResources_$name$() {
-        return processService.getProcessInstanceOutput(process);
+    public Response getResources_$name$(@Context HttpHeaders headers) {
+        List<$Type$Output> out = 
processService.getProcessInstanceOutput(process);
+        boolean wantsHtml = headers.getAcceptableMediaTypes()
+            .stream()
+            .anyMatch(mt -> mt.isCompatible(MediaType.TEXT_HTML_TYPE)
+                    && !mt.isWildcardType() && !mt.isWildcardSubtype());
+        if (wantsHtml) {
+            InputStream htmlStream = 
getClass().getResourceAsStream("/META-INF/resources/index.html");
+            if (htmlStream == null) {
+                return Response.status(Response.Status.NOT_FOUND)
+                    .entity("HTML resource not found").build();
+        }
+        return Response.ok(htmlStream, MediaType.TEXT_HTML).build();

Review Comment:
   Shouldn't it be more correct to use `MediaType.TEXT_HTML_TYPE`?
   ```suggestion
           return Response.ok(htmlStream, MediaType.TEXT_HTML_TYPE).build();
   ```



##########
kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/RestResourceQuarkusTemplate.java:
##########
@@ -88,10 +91,23 @@ public class $Type$Resource {
     }
 
     @GET
-    @Produces(MediaType.APPLICATION_JSON)
+    @Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_HTML})
     @Operation(operationId = "getAllProcessInstances_$name$", summary = 
"$documentation$", description = "$processInstanceDescription$")
-    public List<$Type$Output> getResources_$name$() {
-        return processService.getProcessInstanceOutput(process);
+    public Response getResources_$name$(@Context HttpHeaders headers) {
+        List<$Type$Output> out = 
processService.getProcessInstanceOutput(process);
+        boolean wantsHtml = headers.getAcceptableMediaTypes()
+            .stream()
+            .anyMatch(mt -> mt.isCompatible(MediaType.TEXT_HTML_TYPE)
+                    && !mt.isWildcardType() && !mt.isWildcardSubtype());
+        if (wantsHtml) {
+            InputStream htmlStream = 
getClass().getResourceAsStream("/META-INF/resources/index.html");
+            if (htmlStream == null) {
+                return Response.status(Response.Status.NOT_FOUND)
+                    .entity("HTML resource not found").build();
+        }

Review Comment:
   Indentation typo



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to