1616import jakarta .servlet .http .HttpServletRequest ;
1717import jakarta .servlet .http .HttpSession ;
1818import jakarta .validation .Valid ;
19- import jakarta .validation .constraints .NotNull ;
20- import jakarta .ws .rs .BeanParam ;
21- import jakarta .ws .rs .DELETE ;
22- import jakarta .ws .rs .GET ;
23- import jakarta .ws .rs .POST ;
24- import jakarta .ws .rs .PUT ;
25- import jakarta .ws .rs .Path ;
26- import jakarta .ws .rs .PathParam ;
27- import jakarta .ws .rs .Produces ;
28- import jakarta .ws .rs .core .Context ;
29- import jakarta .ws .rs .core .MediaType ;
30- import jakarta .ws .rs .core .Response ;
31- import jakarta .ws .rs .core .UriInfo ;
3219import lombok .RequiredArgsConstructor ;
3320import lombok .extern .slf4j .Slf4j ;
3421import org .springframework .beans .factory .annotation .Autowired ;
22+ import org .springframework .data .domain .Page ;
3523import org .springframework .http .HttpStatus ;
36- import org .springframework .stereotype .Controller ;
24+ import org .springframework .http .MediaType ;
25+ import org .springframework .http .ResponseEntity ;
26+ import org .springframework .util .MultiValueMap ;
27+ import org .springframework .web .bind .annotation .DeleteMapping ;
28+ import org .springframework .web .bind .annotation .GetMapping ;
29+ import org .springframework .web .bind .annotation .ModelAttribute ;
30+ import org .springframework .web .bind .annotation .PathVariable ;
31+ import org .springframework .web .bind .annotation .PostMapping ;
32+ import org .springframework .web .bind .annotation .PutMapping ;
33+ import org .springframework .web .bind .annotation .RequestBody ;
34+ import org .springframework .web .bind .annotation .RequestMapping ;
35+ import org .springframework .web .bind .annotation .RequestParam ;
36+ import org .springframework .web .bind .annotation .RestController ;
3737
3838import java .util .ArrayList ;
39- import java .util .HashMap ;
4039import java .util .List ;
41- import java .util .Map ;
4240import java .util .UUID ;
4341import java .util .stream .Collectors ;
4442
4947 * Only accessible by users with administrative permissions.
5048 */
5149@ Slf4j
52- @ Path ("/ai/configurations" )
53- @ Produces (MediaType .APPLICATION_JSON )
54- @ Controller
50+ @ RestController
51+ @ RequestMapping ("/ai/configurations" )
5552@ RequiredArgsConstructor (onConstructor = @ __ (@ Autowired ))
5653public class AIConfigurationController implements DefaultController {
5754
@@ -87,28 +84,27 @@ public class AIConfigurationController implements DefaultController {
8784 * based on the provided query parameters and pagination settings.
8885 *
8986 * @param request the HttpServletRequest from which to obtain the HttpSession for user validation.
90- * @param uriInfo UriInfo context to extract query parameters for filtering results.
87+ * @param filters All query parameters for filtering results.
9188 * @param queryFilter bean parameter encapsulating filtering and pagination criteria.
9289 * @return a Response object containing the requested page of AIConfigurationDTO objects representing the
9390 * configurations. The status of the response can vary based on the outcome of the request.
9491 */
95- @ GET
96- public Response getAllConfigurations (final @ Context HttpServletRequest request ,
97- final @ Context UriInfo uriInfo ,
98- final @ BeanParam @ Valid QueryFilter queryFilter ) {
92+ @ GetMapping
93+ public ResponseEntity <Page <AIConfigurationDTO >> getAllConfigurations (
94+ final HttpServletRequest request ,
95+ final @ RequestParam MultiValueMap <String , String > filters ,
96+ final @ ModelAttribute QueryFilter queryFilter ) {
9997 HttpSession session = request .getSession ();
10098 User user = userService .getFromSession (session );
10199 userPermissionService .checkPermission (user , "id" , EntityPermission .AI_CONFIGURATION , ActionPermission .ACCESS );
102100
103- Map <String , String > filters = new HashMap <>(this .getFilters (uriInfo ));
104-
105101 log .info ("[{}] Received GET request to get configurations with the following filters: {}" , user .getLogin (),
106102 filters );
107103
108- var resources = aiConfigurationService .findAll (filters , queryFilter . getPagination () )
104+ var resources = aiConfigurationService .findAll (filters , queryFilter )
109105 .map (new BeanMapper <>(AIConfigurationDTO .class ));
110106
111- return Response .status (this .getStatus (resources )).entity (resources ). build ( );
107+ return ResponseEntity .status (this .getStatus (resources )).body (resources );
112108 }
113109
114110 /**
@@ -119,10 +115,9 @@ public Response getAllConfigurations(final @Context HttpServletRequest request,
119115 * @return a Response object containing theAIConfigurationDTO object representing the configuration.
120116 * The status of the response can vary based on the outcome of the request.
121117 */
122- @ GET
123- @ Path ("/{id}" )
124- public Response getConfigurationById (final @ Context HttpServletRequest request ,
125- final @ PathParam ("id" ) @ Valid @ NotNull UUID id ) {
118+ @ GetMapping ("/{id}" )
119+ public ResponseEntity <AIConfigurationDTO > getConfigurationById (final HttpServletRequest request ,
120+ final @ PathVariable UUID id ) {
126121 HttpSession session = request .getSession ();
127122 User user = userService .getFromSession (session );
128123 userPermissionService .checkPermission (user , "id" , EntityPermission .AI_CONFIGURATION , ActionPermission .ACCESS );
@@ -131,9 +126,7 @@ public Response getConfigurationById(final @Context HttpServletRequest request,
131126
132127 var aiConfiguration = aiConfigurationService .findById (id );
133128
134- return Response .status (HttpStatus .OK .value ())
135- .entity (new BeanMapper <>(AIConfigurationDTO .class ).apply (aiConfiguration ))
136- .build ();
129+ return ResponseEntity .ok (new BeanMapper <>(AIConfigurationDTO .class ).apply (aiConfiguration ));
137130 }
138131
139132 /**
@@ -149,9 +142,10 @@ public Response getConfigurationById(final @Context HttpServletRequest request,
149142 * @return a Response object indicating the outcome of the configuration creation. A successful operation returns
150143 * a status of CREATED.
151144 */
152- @ POST
153- public Response createConfiguration (final @ Context HttpServletRequest request ,
154- final @ Valid AIConfigurationRecord aiConfigurationRecord ) {
145+ @ PostMapping
146+ public ResponseEntity <AIConfigurationDTO > createConfiguration (
147+ final HttpServletRequest request ,
148+ final @ RequestBody @ Valid AIConfigurationRecord aiConfigurationRecord ) {
155149 HttpSession session = request .getSession ();
156150 User user = userService .getFromSession (session );
157151 userPermissionService .checkPermission (user , null , EntityPermission .AI_CONFIGURATION , ActionPermission .CREATE );
@@ -164,9 +158,8 @@ public Response createConfiguration(final @Context HttpServletRequest request,
164158
165159 aiService .sendConfiguration (configuration );
166160
167- return Response .status (HttpStatus .CREATED .value ())
168- .entity (new BeanMapper <>(AIConfigurationDTO .class ).apply (aiConfiguration ))
169- .build ();
161+ return ResponseEntity .status (HttpStatus .CREATED .value ())
162+ .body (new BeanMapper <>(AIConfigurationDTO .class ).apply (aiConfiguration ));
170163 }
171164
172165 /**
@@ -182,9 +175,10 @@ public Response createConfiguration(final @Context HttpServletRequest request,
182175 * @return a Response object indicating the outcome of configurations update. A successful operation returns
183176 * a status of OK.
184177 */
185- @ PUT
186- public Response updateConfiguration (final @ Context HttpServletRequest request ,
187- final @ Valid List <UpdateMultipleAIConfigurationRecord > aiConfigurationRecords ) {
178+ @ PutMapping
179+ public ResponseEntity <List <AIConfigurationDTO >> updateConfiguration (
180+ final HttpServletRequest request ,
181+ final @ RequestBody @ Valid List <UpdateMultipleAIConfigurationRecord > aiConfigurationRecords ) {
188182 HttpSession session = request .getSession ();
189183 User user = userService .getFromSession (session );
190184 userPermissionService .checkPermission (user , "id" , EntityPermission .AI_CONFIGURATION , ActionPermission .UPDATE );
@@ -212,9 +206,7 @@ public Response updateConfiguration(final @Context HttpServletRequest request,
212206
213207 aiService .sendConfiguration (configuration );
214208
215- return Response .status (HttpStatus .OK .value ())
216- .entity (configurations )
217- .build ();
209+ return ResponseEntity .ok (configurations );
218210 }
219211
220212 /**
@@ -231,11 +223,11 @@ public Response updateConfiguration(final @Context HttpServletRequest request,
231223 * @return a Response object indicating the outcome of the configuration update. A successful operation returns
232224 * a status of OK.
233225 */
234- @ PUT
235- @ Path ( "/{id}" )
236- public Response updateConfiguration ( final @ Context HttpServletRequest request ,
237- final @ PathParam ( "id" ) @ Valid @ NotNull UUID id ,
238- final @ Valid AIConfigurationRecord aiConfigurationRecord ) {
226+ @ PutMapping ( "/{id}" )
227+ public ResponseEntity < AIConfigurationDTO > updateConfiguration (
228+ final HttpServletRequest request ,
229+ final @ PathVariable UUID id ,
230+ final @ RequestBody @ Valid AIConfigurationRecord aiConfigurationRecord ) {
239231 HttpSession session = request .getSession ();
240232 User user = userService .getFromSession (session );
241233 userPermissionService .checkPermission (user , "id" , EntityPermission .AI_CONFIGURATION , ActionPermission .UPDATE );
@@ -247,9 +239,7 @@ public Response updateConfiguration(final @Context HttpServletRequest request,
247239
248240 aiService .sendConfiguration (configuration );
249241
250- return Response .status (HttpStatus .OK .value ())
251- .entity (new BeanMapper <>(AIConfigurationDTO .class ).apply (aiConfiguration ))
252- .build ();
242+ return ResponseEntity .ok (new BeanMapper <>(AIConfigurationDTO .class ).apply (aiConfiguration ));
253243 }
254244
255245 /**
@@ -264,25 +254,21 @@ public Response updateConfiguration(final @Context HttpServletRequest request,
264254 * @return a Response object with a status indicating the outcome of the deletion operation. A successful operation
265255 * returns a status of NO_CONTENT.
266256 */
267- @ DELETE
268- @ Path ("/{id}" )
269- public Response deleteConfiguration (final @ Context HttpServletRequest request ,
270- final @ PathParam ("id" ) @ Valid @ NotNull UUID id ) {
257+ @ DeleteMapping ("/{id}" )
258+ public ResponseEntity <Object > deleteConfiguration (final HttpServletRequest request ,
259+ final @ PathVariable UUID id ) {
271260 HttpSession session = request .getSession ();
272261 User user = userService .getFromSession (session );
273262 userPermissionService .checkPermission (user , "id" , EntityPermission .AI_CONFIGURATION , ActionPermission .DELETE );
274263
275264 log .info ("[{}] Received DELETE request to delete configuration {}" , user .getLogin (), id );
276- var aiConfiguration = aiConfigurationService .findById (id );
277-
278- aiConfiguration .setValue (null );
279-
265+ aiConfigurationService .findById (id );
280266 var configuration = aiSecretService .generateConfiguration ();
281267
282268 aiService .sendConfiguration (configuration );
283269
284270 aiConfigurationService .delete (id );
285271
286- return Response . noContent ( ).build ();
272+ return ResponseEntity . status ( HttpStatus . NO_CONTENT ). contentType ( MediaType . APPLICATION_JSON ).build ();
287273 }
288274}
0 commit comments