Skip to content

Commit

Permalink
refactor DTO class names
Browse files Browse the repository at this point in the history
reason: swagger UI cannot infer the proper schema, if there are overlapping inner classes
with the same name, such as:
- OcppTagQueryForm.ForApi
- TransactionQueryForm.ForApi
  • Loading branch information
goekay committed Jan 26, 2025
1 parent 4703d1c commit d89ae17
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* @since 19.08.2014
*/
public interface OcppTagRepository {
List<OcppTag.Overview> getOverview(OcppTagQueryForm form);
List<OcppTag.OcppTagOverview> getOverview(OcppTagQueryForm form);

Result<OcppTagActivityRecord> getRecords();
Result<OcppTagActivityRecord> getRecords(List<String> idTagList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public final class OcppTag {
@Getter
@Builder
@ToString
public static final class Overview {
public static final class OcppTagOverview {
@Schema(description = "PK of the OCPP tag")
private final Integer ocppTagPk;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import de.rwth.idsg.steve.SteveException;
import de.rwth.idsg.steve.repository.OcppTagRepository;
import de.rwth.idsg.steve.repository.dto.OcppTag.Overview;
import de.rwth.idsg.steve.repository.dto.OcppTag.OcppTagOverview;
import de.rwth.idsg.steve.web.dto.OcppTagForm;
import de.rwth.idsg.steve.web.dto.OcppTagQueryForm;
import jooq.steve.db.tables.OcppTagActivity;
Expand Down Expand Up @@ -66,7 +66,7 @@ public OcppTagRepositoryImpl(DSLContext ctx) {

@Override
@SuppressWarnings("unchecked")
public List<Overview> getOverview(OcppTagQueryForm form) {
public List<OcppTagOverview> getOverview(OcppTagQueryForm form) {
SelectQuery selectQuery = ctx.selectQuery();
selectQuery.addFrom(OCPP_TAG_ACTIVITY);

Expand Down Expand Up @@ -258,10 +258,10 @@ private void processBooleanType(SelectQuery selectQuery,
}

private static class UserMapper
implements RecordMapper<Record10<Integer, Integer, String, String, DateTime, Boolean, Boolean, Integer, Long, String>, Overview> {
implements RecordMapper<Record10<Integer, Integer, String, String, DateTime, Boolean, Boolean, Integer, Long, String>, OcppTagOverview> {

Check failure on line 261 in src/main/java/de/rwth/idsg/steve/repository/impl/OcppTagRepositoryImpl.java

View workflow job for this annotation

GitHub Actions / checkstyle

[checkstyle] src/main/java/de/rwth/idsg/steve/repository/impl/OcppTagRepositoryImpl.java#L261 <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck>

Line is longer than 120 characters (found 149).
Raw output
/github/workspace/./src/main/java/de/rwth/idsg/steve/repository/impl/OcppTagRepositoryImpl.java:261:0: error: Line is longer than 120 characters (found 149). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)
@Override
public Overview map(Record10<Integer, Integer, String, String, DateTime, Boolean, Boolean, Integer, Long, String> r) {
return Overview.builder()
public OcppTagOverview map(Record10<Integer, Integer, String, String, DateTime, Boolean, Boolean, Integer, Long, String> r) {

Check failure on line 263 in src/main/java/de/rwth/idsg/steve/repository/impl/OcppTagRepositoryImpl.java

View workflow job for this annotation

GitHub Actions / checkstyle

[checkstyle] src/main/java/de/rwth/idsg/steve/repository/impl/OcppTagRepositoryImpl.java#L263 <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck>

Line is longer than 120 characters (found 133).
Raw output
/github/workspace/./src/main/java/de/rwth/idsg/steve/repository/impl/OcppTagRepositoryImpl.java:263:0: error: Line is longer than 120 characters (found 133). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)
return OcppTagOverview.builder()
.ocppTagPk(r.value1())
.parentOcppTagPk(r.value2())
.idTag(r.value3())
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/de/rwth/idsg/steve/service/OcppTagService.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import static de.rwth.idsg.steve.utils.OcppTagActivityRecordUtils.isExpired;

import com.google.common.base.Strings;
import de.rwth.idsg.steve.SteveException;
import de.rwth.idsg.steve.repository.OcppTagRepository;
import de.rwth.idsg.steve.repository.dto.OcppTag;
import de.rwth.idsg.steve.service.dto.UnidentifiedIncomingObject;
Expand Down Expand Up @@ -56,7 +55,7 @@ public class OcppTagService {
private final OcppTagRepository ocppTagRepository;
private final AuthTagService authTagService;

public List<OcppTag.Overview> getOverview(OcppTagQueryForm form) {
public List<OcppTag.OcppTagOverview> getOverview(OcppTagQueryForm form) {
return ocppTagRepository.getOverview(form);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
package de.rwth.idsg.steve.web.api;

import de.rwth.idsg.steve.SteveException;
import de.rwth.idsg.steve.repository.dto.OcppTag;
import de.rwth.idsg.steve.repository.dto.OcppTag.OcppTagOverview;
import de.rwth.idsg.steve.service.OcppTagService;
import de.rwth.idsg.steve.web.api.ApiControllerAdvice.ApiErrorResponse;
import de.rwth.idsg.steve.web.dto.OcppTagForm;
import de.rwth.idsg.steve.web.dto.OcppTagQueryForm;
import de.rwth.idsg.steve.web.dto.OcppTagQueryForm.OcppTagQueryFormForApi;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
Expand Down Expand Up @@ -80,7 +80,7 @@ public class OcppTagsRestController {
)
@GetMapping(value = "")
@ResponseBody
public List<OcppTag.Overview> get(OcppTagQueryForm.ForApi params) {
public List<OcppTagOverview> get(OcppTagQueryFormForApi params) {
log.debug("Read request for query: {}", params);

var response = ocppTagService.getOverview(params);
Expand All @@ -100,7 +100,7 @@ public List<OcppTag.Overview> get(OcppTagQueryForm.ForApi params) {
)
@GetMapping("/{ocppTagPk}")
@ResponseBody
public OcppTag.Overview getOne(@PathVariable("ocppTagPk") Integer ocppTagPk) {
public OcppTagOverview getOne(@PathVariable("ocppTagPk") Integer ocppTagPk) {
log.debug("Read request for ocppTagPk: {}", ocppTagPk);

var response = getOneInternal(ocppTagPk);
Expand All @@ -123,7 +123,7 @@ public OcppTag.Overview getOne(@PathVariable("ocppTagPk") Integer ocppTagPk) {
@PostMapping
@ResponseBody
@ResponseStatus(HttpStatus.CREATED)
public OcppTag.Overview create(@RequestBody @Valid OcppTagForm params) {
public OcppTagOverview create(@RequestBody @Valid OcppTagForm params) {
log.debug("Create request: {}", params);

int ocppTagPk = ocppTagService.addOcppTag(params);
Expand All @@ -145,7 +145,7 @@ public OcppTag.Overview create(@RequestBody @Valid OcppTagForm params) {
)
@PutMapping("/{ocppTagPk}")
@ResponseBody
public OcppTag.Overview update(@PathVariable("ocppTagPk") Integer ocppTagPk, @RequestBody @Valid OcppTagForm params) {
public OcppTagOverview update(@PathVariable("ocppTagPk") Integer ocppTagPk, @RequestBody @Valid OcppTagForm params) {

Check failure on line 148 in src/main/java/de/rwth/idsg/steve/web/api/OcppTagsRestController.java

View workflow job for this annotation

GitHub Actions / checkstyle

[checkstyle] src/main/java/de/rwth/idsg/steve/web/api/OcppTagsRestController.java#L148 <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck>

Line is longer than 120 characters (found 121).
Raw output
/github/workspace/./src/main/java/de/rwth/idsg/steve/web/api/OcppTagsRestController.java:148:0: error: Line is longer than 120 characters (found 121). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)
params.setOcppTagPk(ocppTagPk); // the one from incoming params does not matter
log.debug("Update request: {}", params);

Expand All @@ -169,7 +169,7 @@ public OcppTag.Overview update(@PathVariable("ocppTagPk") Integer ocppTagPk, @Re
)
@DeleteMapping("/{ocppTagPk}")
@ResponseBody
public OcppTag.Overview delete(@PathVariable("ocppTagPk") Integer ocppTagPk) {
public OcppTagOverview delete(@PathVariable("ocppTagPk") Integer ocppTagPk) {
log.debug("Delete request for ocppTagPk: {}", ocppTagPk);

var response = getOneInternal(ocppTagPk);
Expand All @@ -179,11 +179,11 @@ public OcppTag.Overview delete(@PathVariable("ocppTagPk") Integer ocppTagPk) {
return response;
}

private OcppTag.Overview getOneInternal(int ocppTagPk) {
OcppTagQueryForm.ForApi params = new OcppTagQueryForm.ForApi();
private OcppTagOverview getOneInternal(int ocppTagPk) {
OcppTagQueryFormForApi params = new OcppTagQueryFormForApi();
params.setOcppTagPk(ocppTagPk);

List<OcppTag.Overview> results = ocppTagService.getOverview(params);
List<OcppTagOverview> results = ocppTagService.getOverview(params);
if (results.isEmpty()) {
throw new SteveException.NotFound("Could not find this ocppTag");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class TransactionsRestController {
)
@GetMapping(value = "")
@ResponseBody
public List<Transaction> get(@Valid TransactionQueryForm.ForApi params) {
public List<Transaction> get(@Valid TransactionQueryForm.TransactionQueryFormForApi params) {
log.debug("Read request for query: {}", params);

if (params.isReturnCSV()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ public static BooleanType fromValue(String v) {
}

@ToString(callSuper = true)
public static class ForApi extends OcppTagQueryForm {
public static class OcppTagQueryFormForApi extends OcppTagQueryForm {

public ForApi () {
public OcppTagQueryFormForApi() {
super();
setExpired(BooleanType.ALL);
setInTransaction(BooleanType.ALL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ public static QueryPeriodType fromValue(String v) {
}

@ToString(callSuper = true)
public static class ForApi extends TransactionQueryForm {
public static class TransactionQueryFormForApi extends TransactionQueryForm {

public ForApi() {
public TransactionQueryFormForApi() {
super();
setType(QueryType.ALL);
setPeriodType(QueryPeriodType.ALL);
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/de/rwth/idsg/steve/issues/Issue1219.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private void realTest() {
var repository = new OcppTagRepositoryImpl(ctx);

long start = System.currentTimeMillis();
List<OcppTag.Overview> values = repository.getOverview(new OcppTagQueryForm());
List<OcppTag.OcppTagOverview> values = repository.getOverview(new OcppTagQueryForm());
long stop = System.currentTimeMillis();

System.out.println("took " + Duration.millis(stop - start));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void setup() {
@DisplayName("GET all: Test with empty results, expected 200")
public void test1() throws Exception {
// given
List<OcppTag.Overview> results = Collections.emptyList();
List<OcppTag.OcppTagOverview> results = Collections.emptyList();

// when
when(ocppTagService.getOverview(any())).thenReturn(results);
Expand All @@ -102,7 +102,7 @@ public void test1() throws Exception {
@DisplayName("GET all: Test with one result, expected 200")
public void test2() throws Exception {
// given
List<OcppTag.Overview> results = List.of(OcppTag.Overview.builder().ocppTagPk(96).build());
List<OcppTag.OcppTagOverview> results = List.of(OcppTag.OcppTagOverview.builder().ocppTagPk(96).build());

// when
when(ocppTagService.getOverview(any())).thenReturn(results);
Expand Down Expand Up @@ -141,7 +141,7 @@ public void test4() throws Exception {
public void test5() throws Exception {
// given
DateTime someDate = DateTime.parse("2020-10-01T00:00:00.000Z");
OcppTag.Overview result = OcppTag.Overview.builder()
OcppTag.OcppTagOverview result = OcppTag.OcppTagOverview.builder()
.ocppTagPk(121)
.idTag("id-1")
.parentOcppTagPk(454)
Expand Down Expand Up @@ -206,7 +206,7 @@ public void test7() throws Exception {
@DisplayName("GET one: One entity found, expected 200")
public void test8() throws Exception {
// given
OcppTag.Overview result = OcppTag.Overview.builder().ocppTagPk(12).build();
OcppTag.OcppTagOverview result = OcppTag.OcppTagOverview.builder().ocppTagPk(12).build();

// when
when(ocppTagService.getOverview(any())).thenReturn(List.of(result));
Expand Down Expand Up @@ -265,7 +265,7 @@ public void test11() throws Exception {
OcppTagForm form = new OcppTagForm();
form.setIdTag("id-123");

OcppTag.Overview result = OcppTag.Overview.builder()
OcppTag.OcppTagOverview result = OcppTag.OcppTagOverview.builder()
.ocppTagPk(ocppTagPk)
.idTag(form.getIdTag())
.build();
Expand Down Expand Up @@ -296,7 +296,7 @@ public void test12() throws Exception {
form.setIdTag("id-123");
form.setNote("note-1");

OcppTag.Overview result = OcppTag.Overview.builder()
OcppTag.OcppTagOverview result = OcppTag.OcppTagOverview.builder()
.ocppTagPk(ocppTagPk)
.idTag(form.getIdTag())
.note(form.getNote())
Expand Down Expand Up @@ -367,7 +367,7 @@ public void test15() throws Exception {
// given
int ocppTagPk = 123;

OcppTag.Overview result = OcppTag.Overview.builder()
OcppTag.OcppTagOverview result = OcppTag.OcppTagOverview.builder()
.ocppTagPk(ocppTagPk)
.idTag("id-123")
.note("note-2")
Expand All @@ -390,7 +390,7 @@ public void test16() throws Exception {
// given
int ocppTagPk = 123;

OcppTag.Overview result = OcppTag.Overview.builder()
OcppTag.OcppTagOverview result = OcppTag.OcppTagOverview.builder()
.ocppTagPk(ocppTagPk)
.idTag("id-123")
.note("note-2")
Expand Down Expand Up @@ -445,14 +445,14 @@ public void test18() throws Exception {
.andExpectAll(errorJsonMatchers());

verify(ocppTagService, times(0)).removeUnknown(anyList());
verify(ocppTagService, times(0)).getOverview(any(OcppTagQueryForm.ForApi.class));
verify(ocppTagService, times(0)).getOverview(any(OcppTagQueryForm.OcppTagQueryFormForApi.class));
}

@Test
@DisplayName("GET all: Query param 'expired' is translated correctly, while others are defaulted")
public void test19() throws Exception {
// given
ArgumentCaptor<OcppTagQueryForm.ForApi> formToCapture = ArgumentCaptor.forClass(OcppTagQueryForm.ForApi.class);
ArgumentCaptor<OcppTagQueryForm.OcppTagQueryFormForApi> formToCapture = ArgumentCaptor.forClass(OcppTagQueryForm.OcppTagQueryFormForApi.class);

// when
when(ocppTagService.getOverview(any())).thenReturn(Collections.emptyList());
Expand All @@ -463,7 +463,7 @@ public void test19() throws Exception {
.andExpect(status().isOk());

verify(ocppTagService).getOverview(formToCapture.capture());
OcppTagQueryForm.ForApi capturedForm = formToCapture.getValue();
OcppTagQueryForm.OcppTagQueryFormForApi capturedForm = formToCapture.getValue();

assertEquals(capturedForm.getExpired(), OcppTagQueryForm.BooleanType.FALSE);
assertEquals(capturedForm.getInTransaction(), OcppTagQueryForm.BooleanType.ALL);
Expand All @@ -474,7 +474,7 @@ public void test19() throws Exception {
@DisplayName("GET all: Query param 'inTransaction' is translated correctly, while others are defaulted")
public void test20() throws Exception {
// given
ArgumentCaptor<OcppTagQueryForm.ForApi> formToCapture = ArgumentCaptor.forClass(OcppTagQueryForm.ForApi.class);
ArgumentCaptor<OcppTagQueryForm.OcppTagQueryFormForApi> formToCapture = ArgumentCaptor.forClass(OcppTagQueryForm.OcppTagQueryFormForApi.class);

// when
when(ocppTagService.getOverview(any())).thenReturn(Collections.emptyList());
Expand All @@ -485,7 +485,7 @@ public void test20() throws Exception {
.andExpect(status().isOk());

verify(ocppTagService).getOverview(formToCapture.capture());
OcppTagQueryForm.ForApi capturedForm = formToCapture.getValue();
OcppTagQueryForm.OcppTagQueryFormForApi capturedForm = formToCapture.getValue();

assertEquals(capturedForm.getExpired(), OcppTagQueryForm.BooleanType.ALL);
assertEquals(capturedForm.getInTransaction(), OcppTagQueryForm.BooleanType.TRUE);
Expand All @@ -496,7 +496,7 @@ public void test20() throws Exception {
@DisplayName("GET all: Query param 'inTransaction' is translated correctly, while others are defaulted")
public void test21() throws Exception {
// given
ArgumentCaptor<OcppTagQueryForm.ForApi> formToCapture = ArgumentCaptor.forClass(OcppTagQueryForm.ForApi.class);
ArgumentCaptor<OcppTagQueryForm.OcppTagQueryFormForApi> formToCapture = ArgumentCaptor.forClass(OcppTagQueryForm.OcppTagQueryFormForApi.class);

// when
when(ocppTagService.getOverview(any())).thenReturn(Collections.emptyList());
Expand All @@ -507,7 +507,7 @@ public void test21() throws Exception {
.andExpect(status().isOk());

verify(ocppTagService).getOverview(formToCapture.capture());
OcppTagQueryForm.ForApi capturedForm = formToCapture.getValue();
OcppTagQueryForm.OcppTagQueryFormForApi capturedForm = formToCapture.getValue();

assertEquals(capturedForm.getExpired(), OcppTagQueryForm.BooleanType.ALL);
assertEquals(capturedForm.getInTransaction(), OcppTagQueryForm.BooleanType.ALL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public void test9() throws Exception {
@DisplayName("GET all: Query param 'type' is translated correctly, while others are defaulted")
public void test10() throws Exception {
// given
ArgumentCaptor<TransactionQueryForm.ForApi> formToCapture = ArgumentCaptor.forClass(TransactionQueryForm.ForApi.class);
ArgumentCaptor<TransactionQueryForm.TransactionQueryFormForApi> formToCapture = ArgumentCaptor.forClass(TransactionQueryForm.TransactionQueryFormForApi.class);

// when
when(transactionRepository.getTransactions(any())).thenReturn(Collections.emptyList());
Expand All @@ -224,7 +224,7 @@ public void test10() throws Exception {
.andExpect(status().isOk());

verify(transactionRepository).getTransactions(formToCapture.capture());
TransactionQueryForm.ForApi capturedForm = formToCapture.getValue();
TransactionQueryForm.TransactionQueryFormForApi capturedForm = formToCapture.getValue();

assertEquals(capturedForm.getType(), TransactionQueryForm.QueryType.ACTIVE);
assertEquals(capturedForm.getPeriodType(), TransactionQueryForm.QueryPeriodType.ALL);
Expand All @@ -234,7 +234,7 @@ public void test10() throws Exception {
@DisplayName("GET all: Query param 'periodType' is translated correctly, while others are defaulted")
public void test11() throws Exception {
// given
ArgumentCaptor<TransactionQueryForm.ForApi> formToCapture = ArgumentCaptor.forClass(TransactionQueryForm.ForApi.class);
ArgumentCaptor<TransactionQueryForm.TransactionQueryFormForApi> formToCapture = ArgumentCaptor.forClass(TransactionQueryForm.TransactionQueryFormForApi.class);

// when
when(transactionRepository.getTransactions(any())).thenReturn(Collections.emptyList());
Expand All @@ -245,7 +245,7 @@ public void test11() throws Exception {
.andExpect(status().isOk());

verify(transactionRepository).getTransactions(formToCapture.capture());
TransactionQueryForm.ForApi capturedForm = formToCapture.getValue();
TransactionQueryForm.TransactionQueryFormForApi capturedForm = formToCapture.getValue();

assertEquals(capturedForm.getType(), TransactionQueryForm.QueryType.ALL);
assertEquals(capturedForm.getPeriodType(), TransactionQueryForm.QueryPeriodType.LAST_30);
Expand Down

0 comments on commit d89ae17

Please sign in to comment.