Skip to content

Commit 4026ce8

Browse files
committed
Resolve comments, add metadata endpoint
Signed-off-by: achour94 <[email protected]>
1 parent f4e8619 commit 4026ce8

17 files changed

+246
-317
lines changed

pom.xml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
</developers>
4343

4444
<properties>
45-
<gridsuite-dependencies.version>33</gridsuite-dependencies.version>
45+
<gridsuite-dependencies.version>34</gridsuite-dependencies.version>
4646
<liquibase-hibernate-package>org.gridsuite.spreadsheetconfig.server</liquibase-hibernate-package>
4747
</properties>
4848

@@ -82,7 +82,6 @@
8282

8383
<dependencies>
8484
<!-- Compilation dependencies -->
85-
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-validation</artifactId></dependency>
8685
<dependency>
8786
<groupId>com.fasterxml.jackson.core</groupId>
8887
<artifactId>jackson-databind</artifactId>
@@ -131,11 +130,6 @@
131130
<artifactId>spring-boot-starter-actuator</artifactId>
132131
<scope>runtime</scope>
133132
</dependency>
134-
<dependency>
135-
<groupId>io.micrometer</groupId>
136-
<artifactId>micrometer-registry-prometheus</artifactId>
137-
<scope>runtime</scope>
138-
</dependency>
139133

140134
<!-- Test dependencies -->
141135
<dependency>

src/main/java/org/gridsuite/spreadsheetconfig/server/RestResponseEntityExceptionHandler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
public class RestResponseEntityExceptionHandler {
2121

2222
@ExceptionHandler(EntityNotFoundException.class)
23-
protected ResponseEntity<Object> handleEntityNotFound(
24-
EntityNotFoundException ex, WebRequest request) {
23+
protected ResponseEntity<Object> handleEntityNotFound(EntityNotFoundException ex, WebRequest request) {
2524
String bodyOfResponse = ex.getMessage();
2625
return new ResponseEntity<>(bodyOfResponse, HttpStatus.NOT_FOUND);
2726
}

src/main/java/org/gridsuite/spreadsheetconfig/server/RestTemplateConfig.java

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,9 @@
66
*/
77
package org.gridsuite.spreadsheetconfig.server;
88

9-
import com.fasterxml.jackson.databind.ObjectMapper;
10-
import com.fasterxml.jackson.databind.SerializationFeature;
11-
import org.springframework.boot.jackson.JsonComponentModule;
9+
import org.springframework.boot.web.client.RestTemplateBuilder;
1210
import org.springframework.context.annotation.Bean;
1311
import org.springframework.context.annotation.Configuration;
14-
import org.springframework.http.converter.HttpMessageConverter;
15-
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
16-
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
1712
import org.springframework.web.client.RestTemplate;
1813

1914
/**
@@ -23,36 +18,8 @@
2318
public class RestTemplateConfig {
2419

2520
@Bean
26-
public RestTemplate restTemplate() {
27-
final RestTemplate restTemplate = new RestTemplate();
28-
29-
//find and replace Jackson message converter with our own
30-
for (int i = 0; i < restTemplate.getMessageConverters().size(); i++) {
31-
final HttpMessageConverter<?> httpMessageConverter = restTemplate.getMessageConverters().get(i);
32-
if (httpMessageConverter instanceof MappingJackson2HttpMessageConverter) {
33-
restTemplate.getMessageConverters().set(i, mappingJackson2HttpMessageConverter());
34-
}
35-
}
36-
37-
return restTemplate;
38-
}
39-
40-
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
41-
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
42-
converter.setObjectMapper(objectMapper());
43-
return converter;
44-
}
45-
46-
private ObjectMapper createObjectMapper() {
47-
var objectMapper = Jackson2ObjectMapperBuilder.json().build();
48-
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
49-
objectMapper.registerModule(new JsonComponentModule());
50-
return objectMapper;
51-
}
52-
53-
@Bean
54-
public ObjectMapper objectMapper() {
55-
return createObjectMapper();
21+
public RestTemplate restTemplate(RestTemplateBuilder builder) {
22+
return builder.build();
5623
}
5724
}
5825

src/main/java/org/gridsuite/spreadsheetconfig/server/SwaggerConfig.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public class SwaggerConfig {
2121
public OpenAPI openAPI() {
2222
return new OpenAPI()
2323
.info(new Info()
24-
.title("Spreadsheet Config API")
25-
.description("This is the documentation of the spreadsheet config REST API")
26-
.version(SpreadsheetConfigApi.API_VERSION));
24+
.title("Spreadsheet Config API")
25+
.description("This is the documentation of the spreadsheet config REST API")
26+
.version(SpreadsheetConfigApi.API_VERSION));
2727
}
2828
}

src/main/java/org/gridsuite/spreadsheetconfig/server/controller/SpreadsheetConfigController.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
import jakarta.validation.Valid;
1616
import lombok.RequiredArgsConstructor;
1717
import org.gridsuite.spreadsheetconfig.server.SpreadsheetConfigApi;
18-
import org.gridsuite.spreadsheetconfig.server.dto.SpreadsheetConfigDto;
18+
import org.gridsuite.spreadsheetconfig.server.dto.MetadataInfos;
19+
import org.gridsuite.spreadsheetconfig.server.dto.SpreadsheetConfigInfos;
1920
import org.gridsuite.spreadsheetconfig.server.service.SpreadsheetConfigService;
2021
import org.springframework.http.HttpStatus;
2122
import org.springframework.http.ResponseEntity;
@@ -44,7 +45,7 @@ public class SpreadsheetConfigController {
4445
description = "Creates a new spreadsheet configuration and returns its ID")
4546
@ApiResponse(responseCode = "201", description = "Configuration created",
4647
content = @Content(schema = @Schema(implementation = UUID.class)))
47-
public ResponseEntity<UUID> createSpreadsheetConfig(@Parameter(description = "Configuration to save") @Valid @RequestBody SpreadsheetConfigDto dto) {
48+
public ResponseEntity<UUID> createSpreadsheetConfig(@Parameter(description = "Configuration to save") @Valid @RequestBody SpreadsheetConfigInfos dto) {
4849
UUID id = spreadsheetConfigService.createSpreadsheetConfig(dto);
4950
return ResponseEntity.status(HttpStatus.CREATED).body(id);
5051
}
@@ -56,28 +57,36 @@ public ResponseEntity<UUID> createSpreadsheetConfig(@Parameter(description = "Co
5657
content = @Content(schema = @Schema(implementation = UUID.class)))
5758
@ApiResponse(responseCode = "404", description = "Configuration not found")
5859
public ResponseEntity<UUID> duplicateSpreadsheetConfig(@Parameter(description = "UUID of the configuration to duplicate") @RequestParam(name = DUPLICATE_FROM) UUID id) {
59-
return spreadsheetConfigService.duplicateSpreadsheetConfig(id)
60-
.map(newId -> ResponseEntity.status(HttpStatus.CREATED).body(newId))
61-
.orElse(ResponseEntity.notFound().build());
60+
UUID newId = spreadsheetConfigService.duplicateSpreadsheetConfig(id);
61+
return ResponseEntity.status(HttpStatus.CREATED).body(newId);
6262
}
6363

6464
@GetMapping("/{id}")
6565
@Operation(summary = "Get a spreadsheet configuration",
6666
description = "Retrieves a spreadsheet configuration by its ID")
6767
@ApiResponse(responseCode = "200", description = "Configuration found",
68-
content = @Content(schema = @Schema(implementation = SpreadsheetConfigDto.class)))
68+
content = @Content(schema = @Schema(implementation = SpreadsheetConfigInfos.class)))
6969
@ApiResponse(responseCode = "404", description = "Configuration not found")
70-
public ResponseEntity<SpreadsheetConfigDto> getSpreadsheetConfig(
70+
public ResponseEntity<SpreadsheetConfigInfos> getSpreadsheetConfig(
7171
@Parameter(description = "ID of the configuration to retrieve") @PathVariable UUID id) {
72-
return ResponseEntity.of(spreadsheetConfigService.getSpreadsheetConfig(id));
72+
return ResponseEntity.ok(spreadsheetConfigService.getSpreadsheetConfig(id));
73+
}
74+
75+
@GetMapping("/metadata")
76+
@Operation(summary = "Get spreadsheet configurations metadata",
77+
description = "Retrieves metadata of spreadsheet configurations by their IDs")
78+
@ApiResponse(responseCode = "200", description = "Metadata found",
79+
content = @Content(schema = @Schema(implementation = MetadataInfos.class)))
80+
public ResponseEntity<List<MetadataInfos>> getSpreadsheetConfigsMetadata(@RequestParam List<UUID> ids) {
81+
return ResponseEntity.ok(spreadsheetConfigService.getSpreadsheetConfigsMetadata(ids));
7382
}
7483

7584
@GetMapping
7685
@Operation(summary = "Get all spreadsheet configurations",
7786
description = "Retrieves all spreadsheet configurations")
7887
@ApiResponse(responseCode = "200", description = "List of configurations",
79-
content = @Content(schema = @Schema(implementation = SpreadsheetConfigDto.class)))
80-
public ResponseEntity<List<SpreadsheetConfigDto>> getAllSpreadsheetConfigs() {
88+
content = @Content(schema = @Schema(implementation = SpreadsheetConfigInfos.class)))
89+
public ResponseEntity<List<SpreadsheetConfigInfos>> getAllSpreadsheetConfigs() {
8190
return ResponseEntity.ok(spreadsheetConfigService.getAllSpreadsheetConfigs());
8291
}
8392

@@ -88,7 +97,7 @@ public ResponseEntity<List<SpreadsheetConfigDto>> getAllSpreadsheetConfigs() {
8897
@ApiResponse(responseCode = "404", description = "Configuration not found")
8998
public ResponseEntity<Void> updateSpreadsheetConfig(
9099
@Parameter(description = "ID of the configuration to update") @PathVariable UUID id,
91-
@Valid @RequestBody SpreadsheetConfigDto dto) {
100+
@Valid @RequestBody SpreadsheetConfigInfos dto) {
92101
spreadsheetConfigService.updateSpreadsheetConfig(id, dto);
93102
return ResponseEntity.noContent().build();
94103
}

src/main/java/org/gridsuite/spreadsheetconfig/server/dto/CustomColumnDto.java renamed to src/main/java/org/gridsuite/spreadsheetconfig/server/dto/CustomColumnInfos.java

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,17 @@
88

99
import io.swagger.v3.oas.annotations.media.Schema;
1010
import jakarta.validation.constraints.NotNull;
11-
import lombok.AllArgsConstructor;
12-
import lombok.Builder;
13-
import lombok.Data;
14-
import lombok.extern.jackson.Jacksonized;
15-
16-
import java.util.UUID;
1711

1812
/**
1913
* @author Achour BERRAHMA <achour.berrahma at rte-france.com>
2014
*/
21-
@Data
22-
@AllArgsConstructor
23-
@Builder
24-
@Jacksonized
2515
@Schema(name = "CustomColumnDto", description = "Custom column configuration")
26-
public class CustomColumnDto {
27-
28-
@Schema(description = "Custom column ID")
29-
UUID id;
16+
public record CustomColumnInfos(
3017

3118
@NotNull(message = "Column name is mandatory")
3219
@Schema(description = "Column name")
33-
String name;
20+
String name,
3421

3522
@Schema(description = "Column formula")
36-
String formula;
37-
}
23+
String formula
24+
) { }
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright (c) 2024, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.spreadsheetconfig.server.dto;
8+
9+
import io.swagger.v3.oas.annotations.media.Schema;
10+
import org.gridsuite.spreadsheetconfig.server.constants.SheetType;
11+
12+
import java.util.UUID;
13+
14+
/**
15+
* @author Achour BERRAHMA <achour.berrahma at rte-france.com>
16+
*/
17+
@Schema(name = "MetadataDto", description = "Spreadsheet configuration metadata")
18+
public record MetadataInfos(
19+
20+
@Schema(description = "Spreadsheet configuration ID")
21+
UUID id,
22+
23+
@Schema(description = "Spreadsheet type")
24+
SheetType sheetType
25+
26+
) { }

src/main/java/org/gridsuite/spreadsheetconfig/server/dto/SpreadsheetConfigDto.java renamed to src/main/java/org/gridsuite/spreadsheetconfig/server/dto/SpreadsheetConfigInfos.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88

99
import io.swagger.v3.oas.annotations.media.Schema;
1010
import jakarta.validation.constraints.NotNull;
11-
import lombok.Builder;
12-
import lombok.Value;
13-
import lombok.extern.jackson.Jacksonized;
1411
import org.gridsuite.spreadsheetconfig.server.constants.SheetType;
1512

1613
import java.util.List;
@@ -19,19 +16,16 @@
1916
/**
2017
* @author Achour BERRAHMA <achour.berrahma at rte-france.com>
2118
*/
22-
@Value
23-
@Builder
24-
@Jacksonized
2519
@Schema(name = "SpreadsheetConfigDto", description = "Spreadsheet configuration")
26-
public class SpreadsheetConfigDto {
20+
public record SpreadsheetConfigInfos(
2721

2822
@Schema(description = "Spreadsheet configuration ID")
29-
UUID id;
23+
UUID id,
3024

3125
@NotNull(message = "Sheet type is mandatory")
3226
@Schema(description = "Spreadsheet type")
33-
SheetType sheetType;
27+
SheetType sheetType,
3428

3529
@Schema(description = "Custom columns")
36-
List<CustomColumnDto> customColumns;
37-
}
30+
List<CustomColumnInfos> customColumns
31+
) { }

src/main/java/org/gridsuite/spreadsheetconfig/server/entities/CustomColumnEntity.java renamed to src/main/java/org/gridsuite/spreadsheetconfig/server/entities/CustomColumnEmbeddable.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,21 @@
99
import jakarta.persistence.*;
1010
import lombok.*;
1111

12-
import java.util.UUID;
13-
1412
/**
1513
* @author Achour BERRAHMA <achour.berrahma at rte-france.com>
1614
*/
17-
@Entity
18-
@Table(name = "spreadsheet_custom_column")
15+
@Embeddable
1916
@Getter
2017
@Setter
2118
@NoArgsConstructor
2219
@AllArgsConstructor
2320
@Builder
24-
public class CustomColumnEntity {
25-
26-
@Id
27-
@GeneratedValue(strategy = GenerationType.AUTO)
28-
@Column(name = "id")
29-
private UUID id;
21+
public class CustomColumnEmbeddable {
3022

3123
@Column(name = "name", nullable = false, columnDefinition = "varchar(255)")
3224
private String name;
3325

34-
@Column(name = "formula", columnDefinition = "varchar(255)")
26+
@Column(name = "formula", columnDefinition = "CLOB")
3527
private String formula;
3628

37-
@ManyToOne(fetch = FetchType.LAZY)
38-
@JoinColumn(name = "spreadsheet_config_id", nullable = false, foreignKey = @ForeignKey(name = "spreadsheet_config_id_fk_constraint"))
39-
private SpreadsheetConfigEntity spreadsheetConfig;
4029
}

src/main/java/org/gridsuite/spreadsheetconfig/server/entities/SpreadsheetConfigEntity.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ public class SpreadsheetConfigEntity {
3535
@Enumerated(EnumType.STRING)
3636
private SheetType sheetType;
3737

38-
@OneToMany(mappedBy = "spreadsheetConfig", cascade = CascadeType.ALL, orphanRemoval = true)
38+
@ElementCollection
39+
@CollectionTable(
40+
name = "spreadsheet_custom_column",
41+
joinColumns = @JoinColumn(name = "spreadsheet_config_id")
42+
)
3943
@Builder.Default
40-
private List<CustomColumnEntity> customColumns = new ArrayList<>();
44+
private List<CustomColumnEmbeddable> customColumns = new ArrayList<>();
4145

4246
}

0 commit comments

Comments
 (0)