use of com.google.gerrit.extensions.common.NameInput in project gerrit by GerritCodeReview.
the class SetAccountCommand method setAccount.
private void setAccount() throws Failure {
user = genericUserFactory.create(id);
rsrc = new AccountResource(user.asIdentifiedUser());
try {
for (String email : addEmails) {
addEmail(email);
}
for (String email : deleteEmails) {
deleteEmail(email);
}
if (preferredEmail != null) {
putPreferred(preferredEmail);
}
if (fullName != null) {
NameInput in = new NameInput();
in.name = fullName;
putName.apply(rsrc, in);
}
if (httpPassword != null || clearHttpPassword || generateHttpPassword) {
HttpPasswordInput in = new HttpPasswordInput();
in.httpPassword = httpPassword;
if (generateHttpPassword) {
in.generate = true;
}
Response<String> resp = putHttpPassword.apply(rsrc, in);
if (generateHttpPassword) {
stdout.print("New password: " + resp.value() + "\n");
}
}
if (active) {
putActive.apply(rsrc, null);
} else if (inactive) {
try {
deleteActive.apply(rsrc, null);
} catch (ResourceNotFoundException e) {
// user is already inactive
}
}
addSshKeys = readSshKey(addSshKeys);
if (!addSshKeys.isEmpty()) {
addSshKeys(addSshKeys);
}
deleteSshKeys = readSshKey(deleteSshKeys);
if (!deleteSshKeys.isEmpty()) {
deleteSshKeys(deleteSshKeys);
}
for (String externalId : externalIdsToDelete) {
deleteExternalId(externalId);
}
} catch (RestApiException e) {
throw die(e.getMessage());
} catch (Exception e) {
throw new Failure(1, "unavailable", e);
}
}
use of com.google.gerrit.extensions.common.NameInput in project gerrit by GerritCodeReview.
the class RenameGroupCommand method run.
@Override
protected void run() throws Failure {
enableGracefulStop();
try {
GroupResource rsrc = groups.parse(TopLevelResource.INSTANCE, IdString.fromDecoded(groupName));
NameInput input = new NameInput();
input.name = newGroupName;
putName.apply(rsrc, input);
} catch (RestApiException | IOException | ConfigInvalidException e) {
throw die(e);
}
}
use of com.google.gerrit.extensions.common.NameInput in project gerrit by GerritCodeReview.
the class AccountApiImpl method setName.
@Override
public void setName(String name) throws RestApiException {
NameInput input = new NameInput();
input.name = name;
try {
putName.apply(account, input);
} catch (Exception e) {
throw asRestApiException("Cannot set account name", e);
}
}
use of com.google.gerrit.extensions.common.NameInput in project gerrit by GerritCodeReview.
the class GroupApiImpl method name.
@Override
public void name(String name) throws RestApiException {
NameInput in = new NameInput();
in.name = name;
try {
putName.apply(rsrc, in);
} catch (Exception e) {
throw asRestApiException("Cannot put group name", e);
}
}
use of com.google.gerrit.extensions.common.NameInput in project gerrit by GerritCodeReview.
the class PutName method apply.
public Response<String> apply(IdentifiedUser user, NameInput input) throws MethodNotAllowedException, ResourceNotFoundException, IOException, ConfigInvalidException {
if (input == null) {
input = new NameInput();
}
Account.Id accountId = user.getAccountId();
if (realm.accountBelongsToRealm(externalIds.byAccount(accountId)) && !realm.allowsEdit(AccountFieldName.FULL_NAME)) {
throw new MethodNotAllowedException("realm does not allow editing name");
}
String newName = input.name;
AccountState accountState = accountsUpdateProvider.get().update("Set Full Name via API", accountId, u -> u.setFullName(newName)).orElseThrow(() -> new ResourceNotFoundException("account not found"));
return Strings.isNullOrEmpty(accountState.account().fullName()) ? Response.none() : Response.ok(accountState.account().fullName());
}
Aggregations