Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve query functionality #1682

Merged
merged 2 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -158,6 +158,10 @@ private Result<Record5<Integer, String, String, String, DateTime>> getOverviewIn
selectQuery.addConditions(includes(CHARGE_BOX.CHARGE_BOX_ID, form.getChargeBoxId()));
}

if (form.isSetNote()) {
selectQuery.addConditions(includes(CHARGE_BOX.NOTE, form.getNote()));
}

switch (form.getHeartbeatPeriod()) {
case ALL:
break;
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 All @@ -43,6 +43,7 @@
import java.util.List;
import java.util.stream.Collectors;

import static de.rwth.idsg.steve.utils.CustomDSL.includes;
import static de.rwth.idsg.steve.utils.DateTimeUtils.humanize;
import static de.rwth.idsg.steve.utils.DateTimeUtils.toDateTime;
import static jooq.steve.db.tables.OcppTag.OCPP_TAG;
Expand All @@ -65,7 +66,7 @@

@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 @@ -98,6 +99,10 @@
selectQuery.addConditions(OCPP_TAG_ACTIVITY.PARENT_ID_TAG.eq(form.getParentIdTag()));
}

if (form.isNoteSet()) {
selectQuery.addConditions(includes(OCPP_TAG_ACTIVITY.NOTE, form.getNote()));
}

switch (form.getExpired()) {
case ALL:
break;
Expand Down Expand Up @@ -253,10 +258,10 @@
}

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 @@
)
@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 @@
)
@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 @@
@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 @@
)
@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 @@
)
@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 @@
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 @@ -18,6 +18,7 @@
*/
package de.rwth.idsg.steve.web.dto;

import com.google.common.base.Strings;
import de.rwth.idsg.steve.ocpp.OcppVersion;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
Expand All @@ -35,6 +36,7 @@ public class ChargePointQueryForm {

private String chargeBoxId;
private String description;
private String note;
private OcppVersion ocppVersion;
private QueryPeriodType heartbeatPeriod;

Expand All @@ -57,6 +59,10 @@ public boolean isSetChargeBoxId() {
return chargeBoxId != null;
}

public boolean isSetNote() {
return !Strings.isNullOrEmpty(note);
}

@RequiredArgsConstructor
public enum QueryPeriodType {
ALL("All"),
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/de/rwth/idsg/steve/web/dto/OcppTagQueryForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package de.rwth.idsg.steve.web.dto;

import com.google.common.base.Strings;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -53,6 +54,9 @@
@Schema(description = "Return blocked, not blocked, or all Ocpp tags? Defaults to ALL")
private BooleanType blocked = BooleanType.FALSE;

@Schema(description = "Query by the note associated with the OCPP tag. The value of this field does not have to exactly match the note. A substring is also accepted.")

Check failure on line 57 in src/main/java/de/rwth/idsg/steve/web/dto/OcppTagQueryForm.java

View workflow job for this annotation

GitHub Actions / checkstyle

[checkstyle] src/main/java/de/rwth/idsg/steve/web/dto/OcppTagQueryForm.java#L57 <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck>

Line is longer than 120 characters (found 171).
Raw output
/github/workspace/./src/main/java/de/rwth/idsg/steve/web/dto/OcppTagQueryForm.java:57:0: error: Line is longer than 120 characters (found 171). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)
private String note;

@Schema(hidden = true)
public boolean isOcppTagPkSet() {
return ocppTagPk != null;
Expand All @@ -68,6 +72,11 @@
return parentIdTag != null;
}

@Schema(hidden = true)
public boolean isNoteSet() {
return !Strings.isNullOrEmpty(note);
}

public BooleanType getExpired() {
return Objects.requireNonNullElse(expired, BooleanType.ALL);
}
Expand Down Expand Up @@ -107,9 +116,9 @@
}

@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
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@
</form:select>
</td>
</tr>
<tr>
<td>Note:</td>
<td><form:input path="note"/></td>
</tr>
<tr>
<td></td>
<td id="add_space">
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/webapp/WEB-INF/views/data-man/ocppTags.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@
</form:select>
</td>
</tr>
<tr>
<td>Note:</td>
<td><form:input path="note"/></td>
</tr>
<tr>
<td></td>
<td id="add_space">
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
Loading
Loading