Fixed problem
Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
parent
3335155cd8
commit
b0a1d929e4
@ -32,7 +32,7 @@ public class UserService {
|
||||
/**
|
||||
* checks if user exist and return him or creates new one with student role
|
||||
* otherwise
|
||||
*
|
||||
*
|
||||
* @param email user email in usos
|
||||
* @param usosId user id in usos
|
||||
* @return user entity instace containing changes saved in database
|
||||
@ -43,7 +43,7 @@ public class UserService {
|
||||
|
||||
/**
|
||||
* checks if user exist and creates new one if doesn't
|
||||
*
|
||||
*
|
||||
* @param email user email in usos
|
||||
* @param usosId user id in usos
|
||||
* @param roleIfNotExist role to be set in case user is not in database yet
|
||||
@ -72,27 +72,19 @@ public class UserService {
|
||||
/**
|
||||
* generates token for user and if user don't have name in database it will
|
||||
* attemp to obtain these from usos api and saves changes in database
|
||||
*
|
||||
*
|
||||
* @param authority user we want to login
|
||||
* @return user with changed values after save in db
|
||||
* @throws UserNotFoundException throwed if user doesn't exist
|
||||
*/
|
||||
public User login(User authority) throws UserNotFoundException {
|
||||
final String token = UUID.randomUUID().toString();
|
||||
System.out.println(token);
|
||||
if ((authority.getName() == null || authority.getSurname() == null) && authority.getUsosId() != null) {
|
||||
System.out.println("IF");
|
||||
final UserApiResponse resp = this.service.getUserData(authority.getUsosId());
|
||||
System.out.println("W IFIE");
|
||||
authority.updateWithUsosData(resp);
|
||||
System.out.println("PRAWIE WYCHODZE Z IFA");
|
||||
}
|
||||
try {
|
||||
System.out.println("TRY!!!!");
|
||||
authority.setToken(token);
|
||||
System.out.println(authority.getToken());
|
||||
System.out.println(authority.getName());
|
||||
System.out.println(authority.getSurname());
|
||||
this.repo.save(authority);
|
||||
} catch (Exception e) {
|
||||
throw new UserNotFoundException(e.getMessage());
|
||||
@ -102,7 +94,7 @@ public class UserService {
|
||||
|
||||
/**
|
||||
* sacves user to databse and return instatnce with id
|
||||
*
|
||||
*
|
||||
* @param user to be saved
|
||||
* @return instatnce with bd id
|
||||
*/
|
||||
@ -111,7 +103,7 @@ public class UserService {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param email of user to be find
|
||||
* @return user with given mail
|
||||
* @throws UserNotFoundException throwed if user doesn't exist
|
||||
@ -124,7 +116,7 @@ public class UserService {
|
||||
|
||||
/**
|
||||
* return user by given authority
|
||||
*
|
||||
*
|
||||
* @param authority user usosId or email
|
||||
* @return optional with user if found
|
||||
*/
|
||||
@ -138,7 +130,7 @@ public class UserService {
|
||||
|
||||
/**
|
||||
* search for user with given query
|
||||
*
|
||||
*
|
||||
* @param query string that will be matched to users name and surname
|
||||
* @return list opf results
|
||||
*/
|
||||
@ -168,7 +160,7 @@ public class UserService {
|
||||
|
||||
/**
|
||||
* get students sorted by their ranking
|
||||
*
|
||||
*
|
||||
* @return list of students
|
||||
*/
|
||||
public List<User> getStudentsSortedByRanking() {
|
||||
@ -177,4 +169,4 @@ public class UserService {
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -55,28 +55,14 @@ public class UsosApiService {
|
||||
|
||||
final OAuthRequest request = new OAuthRequest(Verb.GET, apiUrl + "/services/users/user?user_id=" + usosId);
|
||||
service.signRequest(new OAuth1AccessToken("", ""), request);
|
||||
System.out.println("PRZED TRY");
|
||||
try (Response response = service.execute(request)) {
|
||||
System.out.println("TRY");
|
||||
final String json = response.getBody();
|
||||
System.out.println(json == null);
|
||||
System.out.println(json == "null");
|
||||
System.out.println(json.equals("null"));
|
||||
System.out.println(json);
|
||||
if (!json.equals("null")){
|
||||
System.out.println(json);
|
||||
System.out.println(json.getClass());
|
||||
System.out.println("Przed Object");
|
||||
final ObjectMapper mapper = new ObjectMapper();
|
||||
System.out.println("Przed mapą");
|
||||
Map<String, String> map = mapper.readValue(json, new TypeReference<Map<String, String>>() {
|
||||
});
|
||||
System.out.println(map.size());
|
||||
System.out.println("FIELD");
|
||||
apiResponse.setName(map.get(NAME_FIELD));
|
||||
System.out.println(map.get(NAME_FIELD));
|
||||
apiResponse.setSurname(map.get(SURNAME_FIELD));
|
||||
System.out.println(map.get(SURNAME_FIELD));
|
||||
}
|
||||
}
|
||||
} catch (IOException | InterruptedException | ExecutionException e) {
|
||||
|
Loading…
Reference in New Issue
Block a user