use of de.tum.in.www1.artemis.exception.BitbucketException in project ArTEMiS by ls1intum.
the class BitbucketService method addUserToGroups.
/**
* Adds an Bitbucket user to (multiple) Bitbucket groups
*
* @param username The Bitbucket username
* @param groups Names of Bitbucket groups
* @throws BitbucketException
*/
public void addUserToGroups(String username, List<String> groups) throws BitbucketException {
HttpHeaders headers = HeaderUtil.createAuthorization(BITBUCKET_USER, BITBUCKET_PASSWORD);
Map<String, Object> body = new HashMap<>();
body.put("user", username);
body.put("groups", groups);
HttpEntity<?> entity = new HttpEntity<>(body, headers);
RestTemplate restTemplate = new RestTemplate();
log.debug("Adding Bitbucket user {} to groups {}", username, groups);
try {
restTemplate.exchange(BITBUCKET_SERVER_URL + "/rest/api/1.0/admin/users/add-groups", HttpMethod.POST, entity, Map.class);
} catch (HttpClientErrorException e) {
log.error("Could not add Bitbucket user " + username + " to groups" + groups, e);
throw new BitbucketException("Error while adding Bitbucket user to groups");
}
}
Aggregations