@Override @Transactional public LocalizationResponse localize(MeasurementContainer container) { User user = userRepository.findByUsername(container.getUsername()); List<Fingerprint> userPrints = container.getFingerprints(); // We sort the prints to make matching easier Collections.sort(userPrints); List<Place> places = placeRepository.findAll(); // If there are no places we won't do anything if (places.isEmpty()) { return new LocalizationResponse(); } Place leastErraneousPlace = localizationAlgorithms.get(container.getType()).localize(places, userPrints); cutDownHistoryOccurrencesTo9(user.getHistory()); saveAsHistoryOccurrence(leastErraneousPlace, user); LocalizationResponse response = new LocalizationResponse(); response.setPlaceName(leastErraneousPlace.getName()); response.setAuthenticationSuccessful(true); return response; }
private void saveAsHistoryOccurrence(Place place, User user) { HistoryOccurrence occurrence = new HistoryOccurrence(); occurrence.setPlace(place); occurrence.setMeasureTime(new Date()); user.getHistory().add(occurrence); userRepository.save(user); }
/** * Localizes user by selected localization measure by selecting a proper localization command * object and adding closest place to user's history * * @param username Username of user to be localized * @param measurementform Measurement form containing user's Fingerprint data and selected * localization measure */ @Override @Transactional public void localize(String username, MeasurementForm measurementform) { User user = userRepository.findByUsername(username); ArrayList<Fingerprint> userPrints = measurementform.makeFingerprints(); // We sort the prints to make matching easier Collections.sort(userPrints); List<Place> places = placeRepository.findAll(); // If there are no places we won't do anything if (places.isEmpty()) { return; } Place leastErraneousPlace = localizationAlgorithms.get(measurementform.getType()).localize(places, userPrints); cutDownHistoryOccurrencesTo9(user.getHistory()); saveAsHistoryOccurrence(leastErraneousPlace, user); }