Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Zorin95670 committed Nov 21, 2024
1 parent d575c35 commit 1116e83
Show file tree
Hide file tree
Showing 118 changed files with 2,228 additions and 4,212 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
id 'com.adarshr.test-logger' version '4.0.0'
id 'jacoco'
id 'idea'
id "info.solidsoft.pitest" version "1.15.0"
id 'info.solidsoft.pitest' version '1.15.0'
}

idea {
Expand Down Expand Up @@ -40,17 +40,17 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-jersey'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
implementation 'org.springframework.session:spring-session-jdbc:3.3.3'
implementation 'org.flywaydb:flyway-core:10.20.1'
implementation "org.flywaydb:flyway-database-postgresql:10.20.1"
implementation 'org.flywaydb:flyway-database-postgresql:10.20.1'
implementation 'commons-lang:commons-lang:2.6'
implementation 'commons-beanutils:commons-beanutils:1.9.4'
implementation 'com.github.erosb:json-sKema:0.18.0'
implementation 'com.hubspot.jinjava:jinjava:2.7.3'
implementation 'io.github.zorin95670:spring-query-filter:1.1.3'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'org.postgresql:postgresql:42.7.4'
annotationProcessor 'org.projectlombok:lombok'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
* All constants value.
*/
public final class Constants {
/**
* Minimum resource size.
*/
public static final int MINIMUM_RESOURCE_SIZE = 1;
/**
* Maximum resource size.
*/
Expand Down
61 changes: 0 additions & 61 deletions src/main/java/com/ditrit/letomodelizerapi/config/JerseyConfig.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,23 @@
import jakarta.servlet.http.HttpSession;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import jakarta.ws.rs.BeanParam;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.UriInfo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
Expand All @@ -49,9 +46,8 @@
* Only accessible by users with administrative permissions.
*/
@Slf4j
@Path("/ai/configurations")
@Produces(MediaType.APPLICATION_JSON)
@Controller
@RestController
@RequestMapping("/ai/configurations")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class AIConfigurationController implements DefaultController {

Expand Down Expand Up @@ -87,28 +83,27 @@ public class AIConfigurationController implements DefaultController {
* based on the provided query parameters and pagination settings.
*
* @param request the HttpServletRequest from which to obtain the HttpSession for user validation.
* @param uriInfo UriInfo context to extract query parameters for filtering results.
* @param filters All query parameters for filtering results.
* @param queryFilter bean parameter encapsulating filtering and pagination criteria.
* @return a Response object containing the requested page of AIConfigurationDTO objects representing the
* configurations. The status of the response can vary based on the outcome of the request.
*/
@GET
public Response getAllConfigurations(final @Context HttpServletRequest request,
final @Context UriInfo uriInfo,
final @BeanParam @Valid QueryFilter queryFilter) {
@GetMapping
public ResponseEntity<Page<AIConfigurationDTO>> getAllConfigurations(
final HttpServletRequest request,
final @RequestParam Map<String, List<String>> filters,
final @ModelAttribute QueryFilter queryFilter) {
HttpSession session = request.getSession();
User user = userService.getFromSession(session);
userPermissionService.checkPermission(user, "id", EntityPermission.AI_CONFIGURATION, ActionPermission.ACCESS);

Map<String, String> filters = new HashMap<>(this.getFilters(uriInfo));

log.info("[{}] Received GET request to get configurations with the following filters: {}", user.getLogin(),
filters);

var resources = aiConfigurationService.findAll(filters, queryFilter.getPagination())
var resources = aiConfigurationService.findAll(filters, queryFilter)
.map(new BeanMapper<>(AIConfigurationDTO.class));

return Response.status(this.getStatus(resources)).entity(resources).build();
return ResponseEntity.status(this.getStatus(resources)).body(resources);
}

/**
Expand All @@ -119,10 +114,9 @@ public Response getAllConfigurations(final @Context HttpServletRequest request,
* @return a Response object containing theAIConfigurationDTO object representing the configuration.
* The status of the response can vary based on the outcome of the request.
*/
@GET
@Path("/{id}")
public Response getConfigurationById(final @Context HttpServletRequest request,
final @PathParam("id") @Valid @NotNull UUID id) {
@GetMapping("/{id}")
public ResponseEntity<AIConfigurationDTO> getConfigurationById(final HttpServletRequest request,
final @PathVariable @Valid @NotNull UUID id) {
HttpSession session = request.getSession();
User user = userService.getFromSession(session);
userPermissionService.checkPermission(user, "id", EntityPermission.AI_CONFIGURATION, ActionPermission.ACCESS);
Expand All @@ -131,9 +125,7 @@ public Response getConfigurationById(final @Context HttpServletRequest request,

var aiConfiguration = aiConfigurationService.findById(id);

return Response.status(HttpStatus.OK.value())
.entity(new BeanMapper<>(AIConfigurationDTO.class).apply(aiConfiguration))
.build();
return ResponseEntity.ok(new BeanMapper<>(AIConfigurationDTO.class).apply(aiConfiguration));
}

/**
Expand All @@ -149,9 +141,10 @@ public Response getConfigurationById(final @Context HttpServletRequest request,
* @return a Response object indicating the outcome of the configuration creation. A successful operation returns
* a status of CREATED.
*/
@POST
public Response createConfiguration(final @Context HttpServletRequest request,
final @Valid AIConfigurationRecord aiConfigurationRecord) {
@PostMapping
public ResponseEntity<AIConfigurationDTO> createConfiguration(
final HttpServletRequest request,
final @Valid AIConfigurationRecord aiConfigurationRecord) {
HttpSession session = request.getSession();
User user = userService.getFromSession(session);
userPermissionService.checkPermission(user, null, EntityPermission.AI_CONFIGURATION, ActionPermission.CREATE);
Expand All @@ -164,9 +157,8 @@ public Response createConfiguration(final @Context HttpServletRequest request,

aiService.sendConfiguration(configuration);

return Response.status(HttpStatus.CREATED.value())
.entity(new BeanMapper<>(AIConfigurationDTO.class).apply(aiConfiguration))
.build();
return ResponseEntity.status(HttpStatus.CREATED.value())
.body(new BeanMapper<>(AIConfigurationDTO.class).apply(aiConfiguration));
}

/**
Expand All @@ -182,9 +174,10 @@ public Response createConfiguration(final @Context HttpServletRequest request,
* @return a Response object indicating the outcome of configurations update. A successful operation returns
* a status of OK.
*/
@PUT
public Response updateConfiguration(final @Context HttpServletRequest request,
final @Valid List<UpdateMultipleAIConfigurationRecord> aiConfigurationRecords) {
@PutMapping
public ResponseEntity<List<AIConfigurationDTO>> updateConfiguration(
final HttpServletRequest request,
final @Valid List<UpdateMultipleAIConfigurationRecord> aiConfigurationRecords) {
HttpSession session = request.getSession();
User user = userService.getFromSession(session);
userPermissionService.checkPermission(user, "id", EntityPermission.AI_CONFIGURATION, ActionPermission.UPDATE);
Expand Down Expand Up @@ -212,9 +205,7 @@ public Response updateConfiguration(final @Context HttpServletRequest request,

aiService.sendConfiguration(configuration);

return Response.status(HttpStatus.OK.value())
.entity(configurations)
.build();
return ResponseEntity.ok(configurations);
}

/**
Expand All @@ -231,11 +222,11 @@ public Response updateConfiguration(final @Context HttpServletRequest request,
* @return a Response object indicating the outcome of the configuration update. A successful operation returns
* a status of OK.
*/
@PUT
@Path("/{id}")
public Response updateConfiguration(final @Context HttpServletRequest request,
final @PathParam("id") @Valid @NotNull UUID id,
final @Valid AIConfigurationRecord aiConfigurationRecord) {
@PutMapping("/{id}")
public ResponseEntity<AIConfigurationDTO> updateConfiguration(
final HttpServletRequest request,
final @PathVariable @Valid @NotNull UUID id,
final @Valid AIConfigurationRecord aiConfigurationRecord) {
HttpSession session = request.getSession();
User user = userService.getFromSession(session);
userPermissionService.checkPermission(user, "id", EntityPermission.AI_CONFIGURATION, ActionPermission.UPDATE);
Expand All @@ -247,9 +238,7 @@ public Response updateConfiguration(final @Context HttpServletRequest request,

aiService.sendConfiguration(configuration);

return Response.status(HttpStatus.OK.value())
.entity(new BeanMapper<>(AIConfigurationDTO.class).apply(aiConfiguration))
.build();
return ResponseEntity.ok(new BeanMapper<>(AIConfigurationDTO.class).apply(aiConfiguration));
}

/**
Expand All @@ -264,10 +253,9 @@ public Response updateConfiguration(final @Context HttpServletRequest request,
* @return a Response object with a status indicating the outcome of the deletion operation. A successful operation
* returns a status of NO_CONTENT.
*/
@DELETE
@Path("/{id}")
public Response deleteConfiguration(final @Context HttpServletRequest request,
final @PathParam("id") @Valid @NotNull UUID id) {
@DeleteMapping("/{id}")
public ResponseEntity<Object> deleteConfiguration(final HttpServletRequest request,
final @PathVariable @Valid @NotNull UUID id) {
HttpSession session = request.getSession();
User user = userService.getFromSession(session);
userPermissionService.checkPermission(user, "id", EntityPermission.AI_CONFIGURATION, ActionPermission.DELETE);
Expand All @@ -283,6 +271,6 @@ public Response deleteConfiguration(final @Context HttpServletRequest request,

aiConfigurationService.delete(id);

return Response.noContent().build();
return ResponseEntity.noContent().build();
}
}
Loading

0 comments on commit 1116e83

Please sign in to comment.