diff --git a/.editorconfig b/.editorconfig index 145f0fcf..dcd941f2 100644 --- a/.editorconfig +++ b/.editorconfig @@ -17,7 +17,7 @@ trim_trailing_whitespace = false indent_style = space indent_size = 4 -[*.{xml,html,js,yml,css}] +[*.{xml,html,js,yml,css,jsp}] indent_style = space indent_size = 2 diff --git a/src/server-rm/src/main/java/co/oslc/refimpl/rm/gen/services/RequirementsService.java b/src/server-rm/src/main/java/co/oslc/refimpl/rm/gen/services/RequirementsService.java index ef3736ad..f54038d9 100644 --- a/src/server-rm/src/main/java/co/oslc/refimpl/rm/gen/services/RequirementsService.java +++ b/src/server-rm/src/main/java/co/oslc/refimpl/rm/gen/services/RequirementsService.java @@ -273,42 +273,54 @@ public void queryRequirementsAsHtml( ) @GET @Path("selector") - @Consumes({ MediaType.TEXT_HTML, MediaType.WILDCARD }) + @Consumes({MediaType.TEXT_HTML, MediaType.WILDCARD}) public Response RequirementSelector( @QueryParam("terms") final String terms , @PathParam("serviceProviderId") final String serviceProviderId - ) throws ServletException, IOException, JSONException - { + ) throws ServletException, IOException, JSONException { // Start of user code RequirementSelector_init - // End of user code - - httpServletRequest.setAttribute("selectionUri",UriBuilder.fromUri(OSLC4JUtils.getServletURI()).path(uriInfo.getPath()).build().toString()); + // End of user code + + httpServletRequest.setAttribute("selectionUri", + UriBuilder.fromUri(OSLC4JUtils.getServletURI()).path(uriInfo.getPath()).build().toString()); // Start of user code RequirementSelector_setAttributes - // End of user code - - if (terms != null ) { + // End of user code + + if (terms != null) { httpServletRequest.setAttribute("terms", terms); - final List resources = delegate.RequirementSelector(httpServletRequest, serviceProviderId, terms); - if (resources!= null) { - JSONArray resourceArray = new JSONArray(); - for (Requirement resource : resources) { - JSONObject r = new JSONObject(); - r.put("oslc:label", resource.toString()); - r.put("rdf:resource", resource.getAbout().toString()); - r.put("Label", resource.toString()); - // Start of user code RequirementSelector_setResponse - // End of user code - resourceArray.add(r); + final List resources = delegate.RequirementSelector(httpServletRequest, + serviceProviderId, terms); + if (resources != null) { + if ("true".equalsIgnoreCase(httpServletRequest.getHeader("hx-request"))) { + // we need to return HTML fragment + RequestDispatcher rd = httpServletRequest.getRequestDispatcher("/co/oslc/refimpl/rm" + + "/gen/requirementselector-results.jsp"); + httpServletRequest.setAttribute("resources", resources); + rd.forward(httpServletRequest, httpServletResponse); + } else { + // this is really bad, we should not be mixing HTML and JSON without content + // negotiation + JSONArray resourceArray = new JSONArray(); + for (Requirement resource : resources) { + JSONObject r = new JSONObject(); + r.put("oslc:label", resource.toString()); + r.put("rdf:resource", resource.getAbout().toString()); + r.put("Label", resource.toString()); + // Start of user code RequirementSelector_setResponse + // End of user code + resourceArray.add(r); + } + JSONObject response = new JSONObject(); + response.put("oslc:results", resourceArray); + return Response.ok(response.write()).build(); } - JSONObject response = new JSONObject(); - response.put("oslc:results", resourceArray); - return Response.ok(response.write()).build(); + } log.error("A empty search should return an empty list and not NULL!"); - throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); - + return Response.noContent().build(); } else { - RequestDispatcher rd = httpServletRequest.getRequestDispatcher("/co/oslc/refimpl/rm/gen/requirementselector.jsp"); + RequestDispatcher rd = httpServletRequest.getRequestDispatcher("/co/oslc/refimpl/rm" + + "/gen/requirementselector.jsp"); rd.forward(httpServletRequest, httpServletResponse); return null; } diff --git a/src/server-rm/src/main/webapp/co/oslc/refimpl/rm/gen/requirementselector-results.jsp b/src/server-rm/src/main/webapp/co/oslc/refimpl/rm/gen/requirementselector-results.jsp new file mode 100644 index 00000000..0b544e16 --- /dev/null +++ b/src/server-rm/src/main/webapp/co/oslc/refimpl/rm/gen/requirementselector-results.jsp @@ -0,0 +1,34 @@ +<%-- + Copyright (c) 2025 Contributors to the Eclipse Foundation + + See the NOTICE file(s) distributed with this work for additional + information regarding copyright ownership. + + This program and the accompanying materials are made available under the + terms of the Eclipse Distribution License 1.0 which is available at + http://www.eclipse.org/org/documents/edl-v10.php. + + SPDX-License-Identifier: BSD-3-Simple + + This file is generated by Lyo Designer (https://www.eclipse.org/lyo/) +--%> + +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> +<%@page import="org.eclipse.lyo.oslc.domains.rm.Requirement"%> + +<%@ page contentType="text/html" language="java" pageEncoding="UTF-8" %> + + diff --git a/src/server-rm/src/main/webapp/co/oslc/refimpl/rm/gen/requirementselector.jsp b/src/server-rm/src/main/webapp/co/oslc/refimpl/rm/gen/requirementselector.jsp index 642dafab..c6904836 100644 --- a/src/server-rm/src/main/webapp/co/oslc/refimpl/rm/gen/requirementselector.jsp +++ b/src/server-rm/src/main/webapp/co/oslc/refimpl/rm/gen/requirementselector.jsp @@ -1,7 +1,7 @@ <%--To avoid the overriding of any manual code changes upon subsequent code generations, disable "Generate JSP Files" option in the Adaptor model.--%> <%-- - Copyright (c) 2020 Contributors to the Eclipse Foundation + Copyright (c) 2025 Contributors to the Eclipse Foundation See the NOTICE file(s) distributed with this work for additional information regarding copyright ownership. @@ -27,38 +27,55 @@ <% String selectionUri = (String) request.getAttribute("selectionUri"); - %> - - - + + + + + RequirementSD - - - -
-

Find a specific resource through a free-text search.

- - - + + + + +
+

Find a specific OSLC resource through a free-text search.

- - +
+
+
-
- -
- -
- - -
-
-
+