Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -20,7 +20,7 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import de.rwth.idsg.steve.service.WebUserService;
import de.rwth.idsg.steve.service.WebUsersService;
import de.rwth.idsg.steve.web.api.ApiControllerAdvice;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -52,7 +52,7 @@
@RequiredArgsConstructor
public class ApiAuthenticationManager implements AuthenticationManager, AuthenticationEntryPoint {

private final WebUserService webUserService;
private final WebUsersService webUsersService;
private final PasswordEncoder passwordEncoder;
private final ObjectMapper jacksonObjectMapper;

Expand All @@ -65,7 +65,7 @@ public Authentication authenticate(Authentication authentication) throws Authent
throw new BadCredentialsException("Required parameters missing");
}

UserDetails userDetails = webUserService.loadUserByUsernameForApi(username);
UserDetails userDetails = webUsersService.loadUserByUsernameForApi(username);
if (!areValuesSet(userDetails)) {
throw new DisabledException("The user does not exist, exists but is disabled or has API access disabled.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import de.rwth.idsg.steve.ocpp.Ocpp15AndAboveTask;
import de.rwth.idsg.steve.ocpp.OcppCallback;
import de.rwth.idsg.steve.service.OcppTagService;
import de.rwth.idsg.steve.service.OcppTagsService;
import de.rwth.idsg.steve.web.dto.ocpp.SendLocalListParams;
import de.rwth.idsg.steve.web.dto.ocpp.SendLocalListUpdateType;
import ocpp.cp._2015._10.AuthorizationData;
Expand All @@ -40,9 +40,9 @@ public class SendLocalListTask extends Ocpp15AndAboveTask<SendLocalListParams, S

private final ocpp.cp._2015._10.SendLocalListRequest request;

public SendLocalListTask(SendLocalListParams params, OcppTagService ocppTagService) {
public SendLocalListTask(SendLocalListParams params, OcppTagsService ocppTagsService) {
super(params);
this.request = createOcpp16Request(ocppTagService);
this.request = createOcpp16Request(ocppTagsService);
}

@Override
Expand Down Expand Up @@ -91,7 +91,7 @@ public AsyncHandler<ocpp.cp._2015._10.SendLocalListResponse> getOcpp16Handler(St
// Helpers
// -------------------------------------------------------------------------

private ocpp.cp._2015._10.SendLocalListRequest createOcpp16Request(OcppTagService ocppTagService) {
private ocpp.cp._2015._10.SendLocalListRequest createOcpp16Request(OcppTagsService ocppTagsService) {
// DIFFERENTIAL update
if (params.getUpdateType() == SendLocalListUpdateType.DIFFERENTIAL) {
List<ocpp.cp._2015._10.AuthorizationData> auths = new ArrayList<>();
Expand All @@ -102,7 +102,7 @@ private ocpp.cp._2015._10.SendLocalListRequest createOcpp16Request(OcppTagServic
}

// Step 2: For the idTags to be added or updated, insert them with their IdTagInfos
auths.addAll(ocppTagService.getAuthData(params.getAddUpdateList()));
auths.addAll(ocppTagsService.getAuthData(params.getAddUpdateList()));

return new ocpp.cp._2015._10.SendLocalListRequest()
.withListVersion(params.getListVersion())
Expand All @@ -114,7 +114,7 @@ private ocpp.cp._2015._10.SendLocalListRequest createOcpp16Request(OcppTagServic
List<AuthorizationData> values = Collections.emptyList();

if (Boolean.FALSE.equals(params.getSendEmptyListWhenFull())) {
values = ocppTagService.getAuthDataOfAllTags();
values = ocppTagsService.getAuthDataOfAllTags();
}

return new ocpp.cp._2015._10.SendLocalListRequest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ default List<ChargePointSelect> getChargePointSelect(OcppProtocol protocol, List
Map<String, Integer> getChargeBoxIdPkPair(List<String> chargeBoxIdList);

List<ChargePoint.Overview> getOverview(ChargePointQueryForm form);
ChargePoint.Details getDetails(int chargeBoxPk);
Optional<ChargePoint.Details> getDetails(int chargeBoxPk);

default List<ConnectorStatus> getChargePointConnectorStatus() {
return getChargePointConnectorStatus(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
import org.jooq.Select;

import java.util.List;
import java.util.Optional;

/**
* @author Sevket Goekay <sevketgokay@gmail.com>
* @since 19.08.2014
*/
public interface ReservationRepository {
Optional<Reservation> getReservation(int id);
List<Reservation> getReservations(ReservationQueryForm form);

List<Integer> getActiveReservationIds(String chargeBoxId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@
import de.rwth.idsg.steve.web.dto.UserQueryForm;

import java.util.List;
import java.util.Optional;

/**
* @author Sevket Goekay <sevketgokay@gmail.com>
* @since 25.11.2015
*/
public interface UserRepository {
List<User.Overview> getOverview(UserQueryForm form);
User.Details getDetails(int userPk);
Optional<User.Details> getDetails(int userPk);

void add(UserForm form);
Integer add(UserForm form);
void update(UserForm form);
void delete(int userPk);
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,18 +212,18 @@ private Result<Record5<Integer, String, String, String, DateTime>> getOverviewIn
}

@Override
public ChargePoint.Details getDetails(int chargeBoxPk) {
public Optional<ChargePoint.Details> getDetails(int chargeBoxPk) {
ChargeBoxRecord cbr = ctx.selectFrom(CHARGE_BOX)
.where(CHARGE_BOX.CHARGE_BOX_PK.equal(chargeBoxPk))
.fetchOne();

if (cbr == null) {
throw new SteveException("Charge point not found");
return Optional.empty();
}

AddressRecord ar = addressRepository.get(ctx, cbr.getAddressPk());

return new ChargePoint.Details(cbr, ar);
return Optional.of(new ChargePoint.Details(cbr, ar));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import de.rwth.idsg.steve.repository.dto.Reservation;
import de.rwth.idsg.steve.utils.DateTimeUtils;
import de.rwth.idsg.steve.web.dto.ReservationQueryForm;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.joda.time.DateTime;
import org.jooq.DSLContext;
Expand All @@ -36,10 +37,10 @@
import org.jooq.SelectQuery;
import org.jooq.exception.DataAccessException;
import org.jooq.impl.DSL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

import static jooq.steve.db.tables.ChargeBox.CHARGE_BOX;
import static jooq.steve.db.tables.Connector.CONNECTOR;
Expand All @@ -52,13 +53,34 @@
*/
@Slf4j
@Repository
@RequiredArgsConstructor
public class ReservationRepositoryImpl implements ReservationRepository {

private final DSLContext ctx;

@Autowired
public ReservationRepositoryImpl(DSLContext ctx) {
this.ctx = ctx;
@Override
public Optional<Reservation> getReservation(int id) {
SelectQuery selectQuery = ctx.selectQuery();
selectQuery.addFrom(RESERVATION);
selectQuery.addJoin(OCPP_TAG, OCPP_TAG.ID_TAG.eq(RESERVATION.ID_TAG));
selectQuery.addJoin(CONNECTOR, CONNECTOR.CONNECTOR_PK.eq(RESERVATION.CONNECTOR_PK));
selectQuery.addJoin(CHARGE_BOX, CONNECTOR.CHARGE_BOX_ID.eq(CHARGE_BOX.CHARGE_BOX_ID));

selectQuery.addSelect(
RESERVATION.RESERVATION_PK,
RESERVATION.TRANSACTION_PK,
OCPP_TAG.OCPP_TAG_PK,
CHARGE_BOX.CHARGE_BOX_PK,
OCPP_TAG.ID_TAG,
CHARGE_BOX.CHARGE_BOX_ID,
RESERVATION.START_DATETIME,
RESERVATION.EXPIRY_DATETIME,
RESERVATION.STATUS,
CONNECTOR.CONNECTOR_ID
);
selectQuery.addConditions(RESERVATION.RESERVATION_PK.eq(id));
Reservation result = (Reservation) selectQuery.fetchOne(new ReservationMapper());
return Optional.ofNullable(result);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,10 @@
import org.jooq.SelectConditionStep;
import org.jooq.exception.DataAccessException;
import org.jooq.impl.DSL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

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

View workflow job for this annotation

GitHub Actions / checkstyle

[checkstyle] src/main/java/de/rwth/idsg/steve/repository/impl/UserRepositoryImpl.java#L43 <com.puppycrawl.tools.checkstyle.checks.imports.AvoidStarImportCheck>

Using the '.*' form of import should be avoided - java.util.*.
Raw output
/github/workspace/./src/main/java/de/rwth/idsg/steve/repository/impl/UserRepositoryImpl.java:43:17: error: Using the '.*' form of import should be avoided - java.util.*. (com.puppycrawl.tools.checkstyle.checks.imports.AvoidStarImportCheck)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix Checkstyle: avoid star import

Replace java.util.* with explicit imports.

Apply this diff:

-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
🧰 Tools
🪛 GitHub Check: checkstyle

[failure] 43-43: [checkstyle] src/main/java/de/rwth/idsg/steve/repository/impl/UserRepositoryImpl.java#L43 <com.puppycrawl.tools.checkstyle.checks.imports.AvoidStarImportCheck>
Using the '.' form of import should be avoided - java.util..

🤖 Prompt for AI Agents
In src/main/java/de/rwth/idsg/steve/repository/impl/UserRepositoryImpl.java
around line 43, replace the wildcard import "import java.util.*;" with explicit
imports for only the java.util types actually referenced in this file (e.g.
List, Set, Map, Optional, Date, UUID, Collections, etc. as applicable). Update
the import list to include each used class individually or run your IDE's
"Organize/Optimize Imports" to auto-expand the wildcard to concrete imports,
then re-run Checkstyle to confirm the warning is resolved.


import static de.rwth.idsg.steve.utils.CustomDSL.includes;
import static jooq.steve.db.Tables.USER_OCPP_TAG;
Expand Down Expand Up @@ -79,31 +75,31 @@
}

@Override
public User.Details getDetails(int userPk) {
UserRecord ur = ctx.selectFrom(USER)
public Optional<User.Details> getDetails(int userPk) {
var ur = ctx.selectFrom(USER)
.where(USER.USER_PK.equal(userPk))
.fetchOne();

if (ur == null) {
throw new SteveException("There is no user with id '%s'", userPk);
return Optional.empty();
}

return User.Details.builder()
return Optional.of(User.Details.builder()
.userRecord(ur)
.address(addressRepository.get(ctx, ur.getAddressPk()))
.ocppTagEntries(getOcppTagsInternal(userPk, null).getOrDefault(userPk, List.of()))
.build();
.build());
}

@Override
public void add(UserForm form) {
ctx.transaction(configuration -> {
DSLContext ctx = DSL.using(configuration);
public Integer add(UserForm form) {
return ctx.transactionResult(configuration -> {
var ctx = DSL.using(configuration);
try {
Integer addressId = addressRepository.updateOrInsert(ctx, form.getAddress());
Integer userPk = addInternal(ctx, form, addressId);
var addressId = addressRepository.updateOrInsert(ctx, form.getAddress());
var userPk = addInternal(ctx, form, addressId);
refreshOcppTagsInternal(ctx, form, userPk);

return userPk;
} catch (DataAccessException e) {
throw new SteveException("Failed to add the user", e);
}
Expand All @@ -113,9 +109,9 @@
@Override
public void update(UserForm form) {
ctx.transaction(configuration -> {
DSLContext ctx = DSL.using(configuration);
var ctx = DSL.using(configuration);
try {
Integer addressId = addressRepository.updateOrInsert(ctx, form.getAddress());
var addressId = addressRepository.updateOrInsert(ctx, form.getAddress());
updateInternal(ctx, form, addressId);
refreshOcppTagsInternal(ctx, form, form.getUserPk());

Expand All @@ -128,11 +124,10 @@
@Override
public void delete(int userPk) {
ctx.transaction(configuration -> {
DSLContext ctx = DSL.using(configuration);
var ctx = DSL.using(configuration);
try {
addressRepository.delete(ctx, selectAddressId(userPk));
deleteInternal(ctx, userPk);

} catch (DataAccessException e) {
throw new SteveException("Failed to delete the user", e);
}
Expand Down Expand Up @@ -186,7 +181,7 @@
}

private Map<Integer, List<User.OcppTagEntry>> getOcppTagsInternal(Integer userPk, String ocppIdTag) {
List<Condition> conditions = new ArrayList<>();
var conditions = new ArrayList<Condition>();

if (userPk != null) {
conditions.add(USER_OCPP_TAG.USER_PK.eq(userPk));
Expand All @@ -205,7 +200,7 @@
.where(conditions)
.fetch();

Map<Integer, List<User.OcppTagEntry>> map = new HashMap<>();
var map = new HashMap<Integer, List<User.OcppTagEntry>>();
for (var entry : results) {
map.computeIfAbsent(entry.value1(), k -> new ArrayList<>())
.add(new User.OcppTagEntry(entry.value2(), entry.value3()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class CentralSystemService16_Service {
@Autowired private OcppServerRepository ocppServerRepository;
@Autowired private SettingsRepository settingsRepository;

@Autowired private OcppTagService ocppTagService;
@Autowired private OcppTagsService ocppTagsService;
@Autowired private ApplicationEventPublisher applicationEventPublisher;
@Autowired private ChargePointHelperService chargePointHelperService;

Expand Down Expand Up @@ -172,7 +172,7 @@ public DiagnosticsStatusNotificationResponse diagnosticsStatusNotification(

public StartTransactionResponse startTransaction(StartTransactionRequest parameters, String chargeBoxIdentity) {
// Get the authorization info of the user, before making tx changes (will affectAuthorizationStatus)
IdTagInfo info = ocppTagService.getIdTagInfo(
IdTagInfo info = ocppTagsService.getIdTagInfo(
parameters.getIdTag(),
true,
chargeBoxIdentity,
Expand Down Expand Up @@ -205,7 +205,7 @@ public StopTransactionResponse stopTransaction(StopTransactionRequest parameters
String stopReason = parameters.isSetReason() ? parameters.getReason().value() : null;

// Get the authorization info of the user, before making tx changes (will affectAuthorizationStatus)
IdTagInfo idTagInfo = ocppTagService.getIdTagInfo(
IdTagInfo idTagInfo = ocppTagsService.getIdTagInfo(
parameters.getIdTag(),
false,
chargeBoxIdentity,
Expand Down Expand Up @@ -242,7 +242,7 @@ public HeartbeatResponse heartbeat(HeartbeatRequest parameters, String chargeBox

public AuthorizeResponse authorize(AuthorizeRequest parameters, String chargeBoxIdentity) {
// Get the authorization info of the user
IdTagInfo idTagInfo = ocppTagService.getIdTagInfo(
IdTagInfo idTagInfo = ocppTagsService.getIdTagInfo(
parameters.getIdTag(),
false,
chargeBoxIdentity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
import de.rwth.idsg.steve.web.dto.ocpp.UpdateFirmwareParams;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import ocpp.cp._2015._10.ChargingProfilePurposeType;
import ocpp.cp._2015._10.GetCompositeScheduleResponse;
import org.joda.time.DateTime;
import org.springframework.stereotype.Service;
Expand All @@ -86,7 +85,7 @@ public class ChargePointServiceClient {

private final ChargingProfileRepository chargingProfileRepository;
private final ReservationRepository reservationRepository;
private final OcppTagService ocppTagService;
private final OcppTagsService ocppTagsService;

private final DelegatingTaskExecutor asyncTaskExecutor;
private final TaskStore taskStore;
Expand Down Expand Up @@ -333,7 +332,7 @@ public final int getLocalListVersion(MultipleChargePointSelect params,
@SafeVarargs
public final int sendLocalList(SendLocalListParams params,
OcppCallback<String>... callbacks) {
SendLocalListTask task = new SendLocalListTask(params, ocppTagService);
SendLocalListTask task = new SendLocalListTask(params, ocppTagsService);

for (var callback : callbacks) {
task.addCallback(callback);
Expand Down Expand Up @@ -364,7 +363,7 @@ public final int reserveNow(ReserveNowParams params,
.build();

int reservationId = reservationRepository.insert(res);
String parentIdTag = ocppTagService.getParentIdtag(params.getIdTag());
String parentIdTag = ocppTagsService.getParentIdtag(params.getIdTag());

EnhancedReserveNowParams enhancedParams = new EnhancedReserveNowParams(params, reservationId, parentIdTag);
ReserveNowTask task = new ReserveNowTask(enhancedParams, reservationRepository);
Expand Down
Loading
Loading