Class ParkingAccessRestClient

java.lang.Object
net.commuty.parking.rest.ParkingAccessRestClient
All Implemented Interfaces:
ParkingAccess

public class ParkingAccessRestClient extends Object implements ParkingAccess
  • Field Details

  • Constructor Details

    • ParkingAccessRestClient

      public ParkingAccessRestClient(Configuration configuration)
  • Method Details

    • authenticate

      Description copied from interface: ParkingAccess

      Retrieve a token based on the username and password you provided at the creation of the Builder.

      By calling this method, the client will fetch a token and then save a local copy of it for further queries.

      You don't need to use this method as the client will handle authentication for you.

      Specified by:
      authenticate in interface ParkingAccess
      Returns:
      The token generated by the api The token is valid for 24 hours.
      Throws:
      CredentialsException - Your username or password is invalid.
      HttpRequestException - The query was sent to the api but the status is unsuccessful (HTTP status code ≥ 400). See HttpRequestException for more details.
      HttpClientException - The query did not reached the api, i.e. there was a network issue.
    • isGranted

      public boolean isGranted(String parkingSiteId, UserId user) throws CredentialsException, HttpRequestException, HttpClientException
      Description copied from interface: ParkingAccess

      Check whether a UserId is allowed to enter the parking site (or not) when the request is made.

      If a user has more thant one identifier known by Commuty (i.e. a badge code and a number plate), only one identifier is required to check its grant status.

      Specified by:
      isGranted in interface ParkingAccess
      Parameters:
      parkingSiteId - The identifier of the parking site that was given by Commuty.
      user - The UserId to check.
      Returns:
      true if the user is allowed on the site, false otherwise.
      Throws:
      CredentialsException - Your username or password is invalid.
      HttpRequestException - The query was sent to the api but the status is unsuccessful (HTTP status code ≥ 400). See HttpRequestException for more details.
      HttpClientException - The query did not reached the api, i.e. there was a network issue.
    • listAccessRightsForToday

      Description copied from interface: ParkingAccess

      List all users (identified by one or more UserId) that are allowed or denied on the parking site today.

      This will return all accesses of the current day, even if they were already retrieved.

      Specified by:
      listAccessRightsForToday in interface ParkingAccess
      Returns:
      One or more AccessRight. Each user known by Commuty will at least have one access (granted or not). A user can have multiple accesses.
      Throws:
      CredentialsException - Your username or password is invalid.
      HttpRequestException - The query was sent to the api but the status is unsuccessful (HTTP status code ≥ 400). See HttpRequestException for more details.
      HttpClientException - The query did not reached the api, i.e. there was a network issue.
    • listAccessRightsForToday

      public Collection<AccessRight> listAccessRightsForToday(boolean unreadOnly) throws CredentialsException, HttpRequestException, HttpClientException
      Description copied from interface: ParkingAccess

      List all users (identified by one or more UserId) that are allowed or denied on the parking site today.

      If unreadOnly is false, all the accesses of the current day will be returned, even if they were already retrieved. This is the same as calling ParkingAccess.listAccessRightsForToday().

      If unreadOnly is true, only the new accesses (the ones that were never retrieved via an api call) will be listed.

      Specified by:
      listAccessRightsForToday in interface ParkingAccess
      Parameters:
      unreadOnly - Whether you want to retrieve unread only accesses (true) or all accesses (false)
      Returns:
      One or more AccessRight. Each user known by Commuty will at least have one access (granted or not). A user can have multiple accesses.
      Throws:
      CredentialsException - Your username or password is invalid.
      HttpRequestException - The query was sent to the api but the status is unsuccessful (HTTP status code ≥ 400). See HttpRequestException for more details.
      HttpClientException - The query did not reached the api, i.e. there was a network issue.
    • listAccessRights

      public Collection<AccessRight> listAccessRights(LocalDate date, Boolean unreadOnly, Boolean dryRun, LocalDateTime createdAfter, Boolean granted, String parkingSiteId, UUID subjectId, Set<AccessRightAttributeName> includeAttributes) throws CredentialsException, HttpRequestException, HttpClientException
      Description copied from interface: ParkingAccess

      List all users (identified by one or more UserId) that are allowed or denied on the parking site for a given day.

      The date parameter will filter accesses that occurs on or after midnight of the given day and before midnight of the next day.

      If unreadOnly is false, all the accesses of the current day will be returned, even if they were already retrieved. This is the same as calling ParkingAccess.listAccessRightsForToday().

      If unreadOnly is true, only the new accesses (the ones that were never retrieved via an api call) will be listed.

      Specified by:
      listAccessRights in interface ParkingAccess
      Parameters:
      date - The LocalDate of the events you want to retrieve. If date is null, the accesses of the current day will be retrieved.
      unreadOnly - Whether you want to retrieve unread only accesses (true) or all accesses (false). If unreadOnly is null, all the accesses (read and unread) will be retrieved.
      dryRun - Whether you want to prevent to flag the retrieve accesses as "read" (true) or not (false). If unreadOnly is null, all the accesses retrieved will be flagged as "read".
      createdAfter - Only retrieve events created after this LocalDateTime. Represents a UTC timestamp. If createdAfter is null, all the accesses will be retrieved.
      granted - If set to `true`, only the access rights that are granted will be returned. If set to `false`, only the access rights that are denied will be returned. If granted is null, all the accesses will be retrieved.
      parkingSiteId - If set, only the access rights associated with the provided parkingSiteId (case-sensitive) will be returned. If parkingSiteId is null or blank, all the accesses will be retrieved.
      includeAttributes - Whether you want to fetch extra attributes about each access. The possible values are listed in AccessRightAttributeName.
      Returns:
      One or more AccessRight. Each user known by Commuty will at least have one access (granted or not). A user can have multiple accesses.
      Throws:
      CredentialsException - Your username or password is invalid.
      HttpRequestException - The query was sent to the api but the status is unsuccessful (HTTP status code ≥ 400). See HttpRequestException for more details.
      HttpClientException - The query did not reached the api, i.e. there was a network issue.
    • reportAccessLog

      public String reportAccessLog(String parkingSiteId, Collection<AccessLog> accessLogs) throws CredentialsException, HttpRequestException, HttpClientException
      Description copied from interface: ParkingAccess

      Report to Commuty one or more AccessLog of users that entered/exited the parking site.

      This will allow Commuty to create attendance reports for parking site owners.

      Upon success of this request, Commuty will reply with an unique identifier (an UUID). You can keep this identifier when Communicating with Commuty if there is an issue.

      Specified by:
      reportAccessLog in interface ParkingAccess
      Parameters:
      parkingSiteId - The identifier of the parking site that was given by Commuty.
      accessLogs - A collection of one or more AccessLog.
      Returns:
      An identifier of the request you made. This can be kept for further reference
      Throws:
      CredentialsException - Your username or password is invalid.
      HttpRequestException - The query was sent to the api but the status is unsuccessful (HTTP status code ≥ 400). See HttpRequestException for more details. This exception can happen if the parkingSiteId is not known.
      HttpClientException - The query did not reached the api, i.e. there was a network issue.
    • reportMissingUserId

      public UserId reportMissingUserId(UserId user) throws CredentialsException, HttpRequestException, HttpClientException
      Description copied from interface: ParkingAccess

      Report any user (identified by an id and a UserIdType) that is known by you but not by Commuty.

      This will allow Commuty to display a list of problematic users to parking site owners.

      Specified by:
      reportMissingUserId in interface ParkingAccess
      Parameters:
      user - The UserId to report to Commuty.
      Returns:
      The reported user.
      Throws:
      CredentialsException - Your username or password is invalid.
      HttpRequestException - The query was sent to the api but the status is unsuccessful (HTTP status code ≥ 400). See HttpRequestException for more details.
      HttpClientException - The query did not reached the api, i.e. there was a network issue.
    • reportAvailableSpotCount

      public Count reportAvailableSpotCount(String parkingSiteId, int count, Integer total) throws CredentialsException, HttpRequestException, HttpClientException
      Description copied from interface: ParkingAccess

      Report the number of available spots (and optionally the total number of spots) on a parking site.

      Specified by:
      reportAvailableSpotCount in interface ParkingAccess
      Parameters:
      parkingSiteId - The identifier of the parking site that was given by Commuty.
      count - The number of available spots at the time of the submission.
      total - The total number of spots (the size of the parking site) at the time of the submission. Ca be null.
      Returns:
      The reported counts.
      Throws:
      CredentialsException - Your username or password is invalid.
      HttpRequestException - The query was sent to the api but the status is unsuccessful (HTTP status code ≥ 400). See HttpRequestException for more details.
      HttpClientException - The query did not reached the api, i.e. there was a network issue.
    • listParkingSpots

      public List<ParkingSpot> listParkingSpots(String parkingSiteId) throws CredentialsException, HttpRequestException, HttpClientException
      Description copied from interface: ParkingAccess

      Lists all the parking spot of a given parking site.

      It does not return the parking spots that have been deleted.

      Specified by:
      listParkingSpots in interface ParkingAccess
      Parameters:
      parkingSiteId - The identifier of the parking site that was given by Commuty. must not be null or blank
      Returns:
      the active (not deleted) ParkingSpots for the given parking site.
      Throws:
      CredentialsException - Your username or password is invalid.
      HttpRequestException - The query was sent to the api but the status is unsuccessful (HTTP status code ≥ 400). See HttpRequestException for more details.
      HttpClientException - The query did not reached the api, i.e. there was a network issue.
    • reportApplicationLog

      Description copied from interface: ParkingAccess

      This endpoint enables the submission of application logs to the server for storage, analysis, and monitoring purposes.

      Application logs can be sent to this endpoint to record important events, troubleshoot issues, and enhance operational visibility.

      While this endpoint is available for submitting application logs, it is essential to exercise discretion and prudence in its usage.

      The system behind this endpoint is not designed as a comprehensive application log storage solution, but rather as a mechanism to capture and share specific logs that hold substantial relevance or utility beyond individual application contexts.

      • Selectivity is Key: Reserve the use of this endpoint for logs that offer substantial insights, are crucial for monitoring, or are essential for cross-system analysis. Sending every log generated by the application can overwhelm the system and make it challenging to identify and address critical issues.
      • Significant Events: Focus on logging significant events or milestones within the application, such as successful logins, critical errors, security-related incidents, or events that signify successful integrations with external systems. These logs should provide valuable information to developers, operators, or stakeholders.
      • Troubleshooting and Analysis: Prioritize logs that are instrumental in diagnosing issues, detecting discrepancies, or aiding in performance optimization. Logs that contribute to troubleshooting and root cause analysis are particularly valuable.
      • Avoid Noise: Refrain from sending routine or low-impact logs that do not significantly contribute to monitoring, debugging, or analysis. Examples include routine system health checks or verbose debugging messages meant solely for development purposes.
      • Resource Considerations: Keep in mind that the system behind this endpoint may have resource limitations. Sending excessive, unnecessary logs can strain resources, impacting the system's overall performance and responsiveness.
      • Adhere to Data Privacy and Compliance: Ensure that any logs sent through this endpoint comply with data privacy regulations and do not include sensitive or personally identifiable information (PII) unless necessary and appropriately protected.
      • Documentation and Communication: Establish clear guidelines and documentation within your development team regarding which logs should be sent through this endpoint. Promote open communication among team members to ensure that only relevant logs are transmitted.
      Specified by:
      reportApplicationLog in interface ParkingAccess
      Parameters:
      log - The application log to send.
      Returns:
      The application log's id once it is saved by the API.
      Throws:
      CredentialsException - Your username or password is invalid.
      HttpRequestException - The query was sent to the api but the status is unsuccessful (HTTP status code ≥ 400). See HttpRequestException for more details.
      HttpClientException - The query did not reached the api, i.e. there was a network issue.