Master mergerd

This commit is contained in:
Filip Izydorczyk 2021-01-13 15:53:29 +01:00
commit 1506270dec
12 changed files with 30 additions and 29 deletions

View File

View File

View File

@ -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,7 +72,7 @@ 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
@ -94,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
*/
@ -103,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
@ -116,7 +116,7 @@ public class UserService {
/**
* return user by given authority
*
*
* @param authority user usosId or email
* @return optional with user if found
*/
@ -130,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
*/
@ -160,7 +160,7 @@ public class UserService {
/**
* get students sorted by their ranking
*
*
* @return list of students
*/
public List<User> getStudentsSortedByRanking() {
@ -169,4 +169,4 @@ public class UserService {
}).collect(Collectors.toList());
}
}
}

View File

@ -43,32 +43,33 @@ public class UsosApiService {
/**
* /services/users/user
*
*
* @param usosId user id in usos
* @return UserApiResponse modle contatining desired values
*/
public UserApiResponse getUserData(String usosId) {
final UserApiResponse apiResponse = new UserApiResponse();
try {
final OAuth10aService service = new ServiceBuilder(apikey).apiSecret(apisecret)
.build(UsosOauth1Service.instance());
final UserApiResponse apiResponse = new UserApiResponse();
try {
final OAuth10aService service = new ServiceBuilder(apikey).apiSecret(apisecret)
.build(UsosOauth1Service.instance());
final OAuthRequest request = new OAuthRequest(Verb.GET, apiUrl + "/services/users/user?user_id=" + usosId);
service.signRequest(new OAuth1AccessToken("", ""), request);
final OAuthRequest request = new OAuthRequest(Verb.GET, apiUrl + "/services/users/user?user_id=" + usosId);
service.signRequest(new OAuth1AccessToken("", ""), request);
try (Response response = service.execute(request)) {
final String json = response.getBody();
if (!json.equals("null")){
final ObjectMapper mapper = new ObjectMapper();
Map<String, String> map = mapper.readValue(json, new TypeReference<Map<String, String>>() {
});
apiResponse.setName(map.get(NAME_FIELD));
apiResponse.setSurname(map.get(SURNAME_FIELD));
}
}
} catch (IOException | InterruptedException | ExecutionException e) {
e.printStackTrace();
}
try (Response response = service.execute(request)) {
final String json = response.getBody();
final ObjectMapper mapper = new ObjectMapper();
Map<String, String> map = mapper.readValue(json, new TypeReference<Map<String, String>>() {
});
apiResponse.setName(map.get(NAME_FIELD));
apiResponse.setSurname(map.get(SURNAME_FIELD));
}
} catch (IOException | InterruptedException | ExecutionException e) {
e.printStackTrace();
}
return apiResponse;
return apiResponse;
}
}