Class LocationService

java.lang.Object
restapi.services.LocationService

@Service public class LocationService extends Object
  • Field Details

    • userService

      @NonNull private final @NonNull UserService userService
    • dateService

      @NonNull private final @NonNull DateService dateService
    • locationRepository

      @NonNull private final @NonNull LocationRepository locationRepository
    • messagingTemplate

      @NonNull private final @NonNull org.springframework.messaging.simp.SimpMessagingTemplate messagingTemplate
    • matchService

      @NonNull private final @NonNull MatchService matchService
    • logger

      private final Logger logger
  • Constructor Details

    • LocationService

      public LocationService()
  • Method Details

    • distance

      public static double distance(double lat1, double lon1, double el1, double lat2, double lon2, double el2)
      Calculate distance between two points in latitude and longitude taking into account height difference. If you are not interested in height difference pass 0.0. Uses Haversine method as its base.

      lat1, lon1 Start point lat2, lon2 End point el1 Start altitude in meters el2 End altitude in meters

      Parameters:
      lat1 - Start point
      lon1 - Start point
      el1 - Start altitude in meters
      lat2 - End point
      lon2 - End point
      el2 - End altitude in meters
      Returns:
      Distance in Meters
    • compareLocations

      protected boolean compareLocations(@NonNull @NonNull LocationDTO loc1, @NonNull @NonNull LocationDTO loc2, long restriction)
      Returns if two users are close enough to send notification
      Parameters:
      loc1 - LocationDTO of user 1
      loc2 - LocationDTO of user 2
      restriction - maximum distance between users to consider them near each other
      Returns:
      if two users are close enough to send notification
    • getNearMe

      public HashMap<Long,MatchRequestDTO> getNearMe(long userId, HashMap<Long,Long> contacts, LocationDTO locationDTO) throws CustomNotFoundException
      Returns a map of contacts that are near the user and made from the map passed by parameter
      Parameters:
      userId -
      contacts -
      locationDTO -
      Returns:
      Throws:
      CustomNotFoundException
    • getLocation

      @Nullable public @Nullable LocationDTO getLocation(long id)
      Get location saved on the database for user with id = id
      Parameters:
      id -
      Returns:
    • saveLocation

      public void saveLocation(@NonNull @NonNull LocationDTO locationDTO) throws CustomNotFoundException
      Saves the location in the database
      Parameters:
      locationDTO -
      Throws:
      CustomNotFoundException
    • sendMatch

      public void sendMatch(long userId, long contactId, ContactEntity contact) throws CustomNotFoundException
      If there is a recent match between users passed by parameter, it sends it to both users via websocket
      Parameters:
      userId -
      contactId -
      contact -
      Throws:
      CustomNotFoundException
    • sendChange

      public void sendChange(String username, MatchRequestDTO match)
      Send match to user via websocket
      Parameters:
      username -
      match -