Skip to content

Commit

Permalink
Updated documentation, fixed location according ocpi spec
Browse files Browse the repository at this point in the history
  • Loading branch information
klymenko-galyna-ew committed Nov 23, 2023
1 parent 67ec4ea commit 3ecaeaa
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/snapshot-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Publish Snapshot to GitHub Packages
on:
push:
branches:
- dev
- RC-2023*

jobs:
publish:
Expand Down
76 changes: 57 additions & 19 deletions README.md

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<modelVersion>4.0.0</modelVersion>

<groupId>com.extrawest</groupId>
<artifactId>Extrawest-OCPI-2.2.1-CPO-Server</artifactId>
<version>2023.8.27-SNAPSHOT</version>
<artifactId>extrawest-ocpi-2.2.1-cpo-server</artifactId>
<version>2023.11.21-SNAPSHOT</version>

<name>Extrawest-OCPI-2.2.1-CPO-Server</name>
<description>Extrawest-OCPI-2.2.1-CPO-Server</description>
Expand All @@ -24,6 +24,12 @@
<organization>extrawest</organization>
<organizationUrl>https://www.extrawest.com/</organizationUrl>
</developer>
<developer>
<name>Galyna Klymenko</name>
<email>galyna.klymenko@extrawest.com</email>
<organization>extrawest</organization>
<organizationUrl>https://www.extrawest.com/</organizationUrl>
</developer>
</developers>
<organization>
<name>Extrawest</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
Expand All @@ -19,6 +20,7 @@
@RestController
@RequestMapping("/cpo/api/2.2.1/locations")
@Tag(name = "CPOLocation")
@Validated
public class CpoLocationController {
protected final CpoLocationService cpoLocationService;
protected final PaginationService paginationService;
Expand Down Expand Up @@ -63,17 +65,13 @@ public ResponseEntity<ResponseFormat<List<Location>>> getLocations(
/**
* Retrieve a Location as it is stored in the eMSP system.
*
* @param countryCode Country code of the CPO requesting data from the eMSP system.
* @param partyId Party ID (Provider ID) of the CPO requesting data from the eMSP system.
* @param locationId Location.id of the Location object to retrieve.
* @return The Location object
*/
@GetMapping("/{country_code}/{party_id}/{location_id}")
@GetMapping("/{location_id}")
public ResponseEntity<ResponseFormat<LocationData>> getLocation(
@PathVariable(value = "country_code") String countryCode,
@PathVariable(value = "party_id") String partyId,
@PathVariable(value = "location_id") String locationId) {
LocationData locationData = cpoLocationService.getLocation(countryCode, partyId, locationId);
LocationData locationData = cpoLocationService.getLocation(locationId);

ResponseFormat<LocationData> responseFormat = new ResponseFormat<LocationData>()
.build(OcpiStatusCode.SUCCESS, locationData);
Expand All @@ -83,19 +81,15 @@ public ResponseEntity<ResponseFormat<LocationData>> getLocation(
/**
* Retrieve a Location as it is stored in the eMSP system.
*
* @param countryCode Country code of the CPO requesting data from the eMSP system.
* @param partyId Party ID (Provider ID) of the CPO requesting data from the eMSP system.
* @param locationId Location.id of the Location object to retrieve.
* @param evseUid EVSE.id of the EVSE object to retrieve.
* @return The EVSE object
*/
@GetMapping("/{country_code}/{party_id}/{location_id}/{evse_uid}")
@GetMapping("/{location_id}/{evse_uid}")
public ResponseEntity<ResponseFormat<LocationData>> getEvse(
@PathVariable(value = "country_code") String countryCode,
@PathVariable(value = "party_id") String partyId,
@PathVariable(value = "location_id") String locationId,
@PathVariable(value = "evse_uid") String evseUid) {
LocationData locationData = cpoLocationService.getEvse(countryCode, partyId, locationId, evseUid);
LocationData locationData = cpoLocationService.getEvse(locationId, evseUid);

ResponseFormat<LocationData> responseFormat = new ResponseFormat<LocationData>()
.build(OcpiStatusCode.SUCCESS, locationData);
Expand All @@ -105,21 +99,17 @@ public ResponseEntity<ResponseFormat<LocationData>> getEvse(
/**
* Retrieve a Location as it is stored in the eMSP system.
*
* @param countryCode Country code of the CPO requesting data from the eMSP system.
* @param partyId Party ID (Provider ID) of the CPO requesting data from the eMSP system.
* @param locationId Location.id of the Location object to retrieve.
* @param evseUid EVSE.id of the EVSE object to retrieve.
* @param connectorId Connector.id of the Connector object to retrieve.
* @return The Connector object
*/
@GetMapping("/{country_code}/{party_id}/{location_id}/{evse_uid}/{connector_id}")
@GetMapping("/{location_id}/{evse_uid}/{connector_id}")
public ResponseEntity<ResponseFormat<LocationData>> getConnector(
@PathVariable(value = "country_code") String countryCode,
@PathVariable(value = "party_id") String partyId,
@PathVariable(value = "location_id") String locationId,
@PathVariable(value = "evse_uid") String evseUid,
@PathVariable(value = "connector_id") String connectorId) {
LocationData locationData = cpoLocationService.getConnector(countryCode, partyId, locationId, evseUid, connectorId);
LocationData locationData = cpoLocationService.getConnector(locationId, evseUid, connectorId);

ResponseFormat<LocationData> responseFormat = new ResponseFormat<LocationData>()
.build(OcpiStatusCode.SUCCESS, locationData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.extrawest.ocpi.model.enums.TokenType;
import com.extrawest.ocpi.model.enums.status_codes.OcpiStatusCode;
import com.extrawest.ocpi.service.CpoTokensService;
import com.extrawest.ocpi.validation.ClientObjectValidation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.Size;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -66,6 +67,8 @@ public ResponseEntity<ResponseFormat<TokenDto>> putToken(
@PathVariable(value = "party_id") @Size(min = 3, max = 3) String partyId,
@PathVariable(value = "token_uid") @Size(min = 1, max = 36) String tokenUid,
@PathVariable(value = "type", required = false) TokenType type) {

ClientObjectValidation.checkClientCanModifyObject(tokenDTO, countryCode, partyId, tokenUid);
TokenDto dto = cpoTokensService.putToken(tokenDTO, countryCode, partyId, tokenUid, type);

ResponseFormat<TokenDto> responseFormat = new ResponseFormat<TokenDto>()
Expand All @@ -90,6 +93,8 @@ public ResponseEntity<ResponseFormat<TokenDto>> patchToken(
@PathVariable(value = "party_id") @Size(min = 3, max = 3) String partyId,
@PathVariable(value = "token_uid") @Size(min = 1, max = 36) String tokenUid,
@PathVariable(value = "type", required = false) TokenType type) {

ClientObjectValidation.checkClientCanModifyObject(tokenDTO, countryCode, partyId, tokenUid);
TokenDto dto = cpoTokensService.patchToken(tokenDTO, countryCode, partyId, tokenUid, type);

ResponseFormat<TokenDto> responseFormat = new ResponseFormat<TokenDto>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ public interface CpoLocationService {

long getTotalCount(LocalDateTime dateFrom, LocalDateTime dateTo);

Location getLocation(String countryCode, String partyId, String locationId);
Location getLocation(String locationId);

EVSE getEvse(String countryCode, String partyId, String locationId, String evseUid);

Connector getConnector(String countryCode, String partyId, String locationId, String evseUid,
String connectorId);
EVSE getEvse(String locationId, String evseUid);

Connector getConnector(String locationId, String evseUid, String connectorId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.extrawest.ocpi.model.dto.ClientOwnedObject;
import com.extrawest.ocpi.model.dto.location.Connector;
import com.extrawest.ocpi.model.dto.location.EVSE;
import com.extrawest.ocpi.model.dto.token.TokenDto;
import lombok.experimental.UtilityClass;

import java.util.Objects;
Expand All @@ -17,31 +18,16 @@ public class ClientObjectValidation {
* @throws OcpiInvalidParametersException if tariff_id in request parameters is other than in request body
*/

public static <T extends ClientOwnedObject> void checkClientCanModifyObject(T object,
public static <T extends ClientOwnedObject> void checkClientCanModifyObject(TokenDto object,
String countryCode,
String partyId,
String id) {
String uid) {
if (!Objects.equals(object.getCountryCode(), countryCode)
|| !Objects.equals(object.getPartyId(), partyId))
throw new OcpiGeneralClientException();

if (!Objects.equals(object.getId(), id)) {
if (!Objects.equals(object.getUid(), uid)) {
throw new OcpiInvalidParametersException();
}
}

public static void checkClientCanModifyObject(EVSE evse,
String id) {
if (!Objects.equals(evse.getUid(), id)) {
throw new OcpiInvalidParametersException();
}
}

public static void checkClientCanModifyObject(Connector connector,
String id) {
if (!Objects.equals(connector.getConnectorId(), id)) {
throw new OcpiInvalidParametersException();
}
}

}

0 comments on commit 3ecaeaa

Please sign in to comment.