Fixed problem

Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
Marcin Woźniak 2021-01-09 17:35:53 +01:00
parent 3335155cd8
commit b0a1d929e4
Signed by: y0rune
GPG Key ID: F204C385F57EB348
2 changed files with 9 additions and 31 deletions

View File

@ -32,7 +32,7 @@ public class UserService {
/** /**
* checks if user exist and return him or creates new one with student role * checks if user exist and return him or creates new one with student role
* otherwise * otherwise
* *
* @param email user email in usos * @param email user email in usos
* @param usosId user id in usos * @param usosId user id in usos
* @return user entity instace containing changes saved in database * @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 * checks if user exist and creates new one if doesn't
* *
* @param email user email in usos * @param email user email in usos
* @param usosId user id in usos * @param usosId user id in usos
* @param roleIfNotExist role to be set in case user is not in database yet * @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 * 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 * attemp to obtain these from usos api and saves changes in database
* *
* @param authority user we want to login * @param authority user we want to login
* @return user with changed values after save in db * @return user with changed values after save in db
* @throws UserNotFoundException throwed if user doesn't exist * @throws UserNotFoundException throwed if user doesn't exist
*/ */
public User login(User authority) throws UserNotFoundException { public User login(User authority) throws UserNotFoundException {
final String token = UUID.randomUUID().toString(); final String token = UUID.randomUUID().toString();
System.out.println(token);
if ((authority.getName() == null || authority.getSurname() == null) && authority.getUsosId() != null) { if ((authority.getName() == null || authority.getSurname() == null) && authority.getUsosId() != null) {
System.out.println("IF");
final UserApiResponse resp = this.service.getUserData(authority.getUsosId()); final UserApiResponse resp = this.service.getUserData(authority.getUsosId());
System.out.println("W IFIE");
authority.updateWithUsosData(resp); authority.updateWithUsosData(resp);
System.out.println("PRAWIE WYCHODZE Z IFA");
} }
try { try {
System.out.println("TRY!!!!");
authority.setToken(token); authority.setToken(token);
System.out.println(authority.getToken());
System.out.println(authority.getName());
System.out.println(authority.getSurname());
this.repo.save(authority); this.repo.save(authority);
} catch (Exception e) { } catch (Exception e) {
throw new UserNotFoundException(e.getMessage()); throw new UserNotFoundException(e.getMessage());
@ -102,7 +94,7 @@ public class UserService {
/** /**
* sacves user to databse and return instatnce with id * sacves user to databse and return instatnce with id
* *
* @param user to be saved * @param user to be saved
* @return instatnce with bd id * @return instatnce with bd id
*/ */
@ -111,7 +103,7 @@ public class UserService {
} }
/** /**
* *
* @param email of user to be find * @param email of user to be find
* @return user with given mail * @return user with given mail
* @throws UserNotFoundException throwed if user doesn't exist * @throws UserNotFoundException throwed if user doesn't exist
@ -124,7 +116,7 @@ public class UserService {
/** /**
* return user by given authority * return user by given authority
* *
* @param authority user usosId or email * @param authority user usosId or email
* @return optional with user if found * @return optional with user if found
*/ */
@ -138,7 +130,7 @@ public class UserService {
/** /**
* search for user with given query * search for user with given query
* *
* @param query string that will be matched to users name and surname * @param query string that will be matched to users name and surname
* @return list opf results * @return list opf results
*/ */
@ -168,7 +160,7 @@ public class UserService {
/** /**
* get students sorted by their ranking * get students sorted by their ranking
* *
* @return list of students * @return list of students
*/ */
public List<User> getStudentsSortedByRanking() { public List<User> getStudentsSortedByRanking() {
@ -177,4 +169,4 @@ public class UserService {
}).collect(Collectors.toList()); }).collect(Collectors.toList());
} }
} }

View File

@ -55,28 +55,14 @@ public class UsosApiService {
final OAuthRequest request = new OAuthRequest(Verb.GET, apiUrl + "/services/users/user?user_id=" + usosId); final OAuthRequest request = new OAuthRequest(Verb.GET, apiUrl + "/services/users/user?user_id=" + usosId);
service.signRequest(new OAuth1AccessToken("", ""), request); service.signRequest(new OAuth1AccessToken("", ""), request);
System.out.println("PRZED TRY");
try (Response response = service.execute(request)) { try (Response response = service.execute(request)) {
System.out.println("TRY");
final String json = response.getBody(); 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")){ if (!json.equals("null")){
System.out.println(json);
System.out.println(json.getClass());
System.out.println("Przed Object");
final ObjectMapper mapper = new ObjectMapper(); final ObjectMapper mapper = new ObjectMapper();
System.out.println("Przed mapą");
Map<String, String> map = mapper.readValue(json, new TypeReference<Map<String, String>>() { 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)); apiResponse.setName(map.get(NAME_FIELD));
System.out.println(map.get(NAME_FIELD));
apiResponse.setSurname(map.get(SURNAME_FIELD)); apiResponse.setSurname(map.get(SURNAME_FIELD));
System.out.println(map.get(SURNAME_FIELD));
} }
} }
} catch (IOException | InterruptedException | ExecutionException e) { } catch (IOException | InterruptedException | ExecutionException e) {