本文整理汇总了Java中com.google.gerrit.extensions.restapi.Response类的典型用法代码示例。如果您正苦于以下问题:Java Response类的具体用法?Java Response怎么用?Java Response使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Response类属于com.google.gerrit.extensions.restapi包,在下文中一共展示了Response类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: apply
import com.google.gerrit.extensions.restapi.Response; //导入依赖的package包/类
@Override
public Response<?> apply(RevisionResource revision, VerifyInput input)
throws AuthException, BadRequestException, UnprocessableEntityException,
OrmException, IOException {
if (input.verifications == null) {
throw new BadRequestException("Missing verifications field");
}
try (CiDb db = schemaFactory.open()) {
// Only needed for Google Megastore (that we don't use yet)
db.patchSetVerifications().beginTransaction(null);
boolean dirty = false;
try {
dirty |= updateLabels(revision, db, input.verifications);
if (dirty) {
db.commit();
}
} finally {
db.rollback();
}
}
return Response.none();
}
示例2: applyAsync
import com.google.gerrit.extensions.restapi.Response; //导入依赖的package包/类
private Response.Accepted applyAsync(Project.NameKey project, Input input) {
Runnable job =
new Runnable() {
@Override
public void run() {
runGC(project, input, null);
}
@Override
public String toString() {
return "Run "
+ (input.aggressive ? "aggressive " : "")
+ "garbage collection on project "
+ project.get();
}
};
@SuppressWarnings("unchecked")
WorkQueue.Task<Void> task = (WorkQueue.Task<Void>) workQueue.getDefaultQueue().submit(job);
String location =
canonicalUrl.get() + "a/config/server/tasks/" + IdGenerator.format(task.getTaskId());
return Response.accepted(location);
}
示例3: apply
import com.google.gerrit.extensions.restapi.Response; //导入依赖的package包/类
@Override
public Response<PluginInfo> apply(TopLevelResource resource, InstallPluginInput input)
throws RestApiException, IOException {
loader.checkRemoteAdminEnabled();
try {
try (InputStream in = openStream(input)) {
String pluginName = loader.installPluginFromStream(name, in);
PluginInfo info = ListPlugins.toPluginInfo(loader.get(pluginName));
return created ? Response.created(info) : Response.ok(info);
}
} catch (PluginInstallException e) {
StringWriter buf = new StringWriter();
buf.write(String.format("cannot install %s", name));
if (e.getCause() instanceof ZipException) {
buf.write(": ");
buf.write(e.getCause().getMessage());
} else {
buf.write(":\n");
PrintWriter pw = new PrintWriter(buf);
e.printStackTrace(pw);
pw.flush();
}
throw new BadRequestException(buf.toString());
}
}
示例4: apply
import com.google.gerrit.extensions.restapi.Response; //导入依赖的package包/类
@Override
public Response<?> apply(GroupResource rsrc, Input input)
throws IOException, AuthException, UnprocessableEntityException {
if (!rsrc.getControl().isOwner()) {
throw new AuthException("not allowed to index group");
}
AccountGroup.UUID groupUuid = rsrc.getGroup().getGroupUUID();
if (!rsrc.isInternalGroup()) {
throw new UnprocessableEntityException(
String.format("External Group Not Allowed: %s", groupUuid.get()));
}
Optional<InternalGroup> group = groupCache.get(groupUuid);
// evicting the group from the cache, reindexes the group
if (group.isPresent()) {
groupCache.evict(group.get().getGroupUUID(), group.get().getId(), group.get().getNameKey());
}
return Response.none();
}
示例5: apply
import com.google.gerrit.extensions.restapi.Response; //导入依赖的package包/类
@Override
public Response<String> apply(AccountResource rsrc, HttpPasswordInput input)
throws AuthException, ResourceNotFoundException, ResourceConflictException, OrmException,
IOException, ConfigInvalidException, PermissionBackendException {
if (self.get() != rsrc.getUser()) {
permissionBackend.user(self).check(GlobalPermission.ADMINISTRATE_SERVER);
}
if (input == null) {
input = new HttpPasswordInput();
}
input.httpPassword = Strings.emptyToNull(input.httpPassword);
String newPassword;
if (input.generate) {
newPassword = generate();
} else if (input.httpPassword == null) {
newPassword = null;
} else {
// Only administrators can explicitly set the password.
permissionBackend.user(self).check(GlobalPermission.ADMINISTRATE_SERVER);
newPassword = input.httpPassword;
}
return apply(rsrc.getUser(), newPassword);
}
示例6: apply
import com.google.gerrit.extensions.restapi.Response; //导入依赖的package包/类
public Response<String> apply(IdentifiedUser user, String email)
throws ResourceNotFoundException, IOException, ConfigInvalidException {
AtomicBoolean alreadyPreferred = new AtomicBoolean(false);
Account account =
accountsUpdate
.create()
.update(
user.getAccountId(),
a -> {
if (email.equals(a.getPreferredEmail())) {
alreadyPreferred.set(true);
} else {
a.setPreferredEmail(email);
}
});
if (account == null) {
throw new ResourceNotFoundException("account not found");
}
return alreadyPreferred.get() ? Response.ok("") : Response.created("");
}
示例7: apply
import com.google.gerrit.extensions.restapi.Response; //导入依赖的package包/类
@Override
public Response<EmailInfo> apply(AccountResource rsrc, EmailInput input)
throws AuthException, BadRequestException, ResourceConflictException,
ResourceNotFoundException, OrmException, EmailException, MethodNotAllowedException,
IOException, ConfigInvalidException, PermissionBackendException {
if (self.get() != rsrc.getUser() || input.noConfirmation) {
permissionBackend.user(self).check(GlobalPermission.MODIFY_ACCOUNT);
}
if (input == null) {
input = new EmailInput();
}
if (!validator.isValid(email)) {
throw new BadRequestException("invalid email address");
}
if (!realm.allowsEdit(AccountFieldName.REGISTER_NEW_EMAIL)) {
throw new MethodNotAllowedException("realm does not allow adding emails");
}
return apply(rsrc.getUser(), input);
}
示例8: deactivate
import com.google.gerrit.extensions.restapi.Response; //导入依赖的package包/类
public Response<?> deactivate(Account.Id accountId)
throws RestApiException, IOException, ConfigInvalidException {
AtomicBoolean alreadyInactive = new AtomicBoolean(false);
Account account =
accountsUpdate
.create()
.update(
accountId,
a -> {
if (!a.isActive()) {
alreadyInactive.set(true);
} else {
a.setActive(false);
}
});
if (account == null) {
throw new ResourceNotFoundException("account not found");
}
if (alreadyInactive.get()) {
throw new ResourceConflictException("account not active");
}
return Response.none();
}
示例9: activate
import com.google.gerrit.extensions.restapi.Response; //导入依赖的package包/类
public Response<String> activate(Account.Id accountId)
throws ResourceNotFoundException, IOException, ConfigInvalidException {
AtomicBoolean alreadyActive = new AtomicBoolean(false);
Account account =
accountsUpdate
.create()
.update(
accountId,
a -> {
if (a.isActive()) {
alreadyActive.set(true);
} else {
a.setActive(true);
}
});
if (account == null) {
throw new ResourceNotFoundException("account not found");
}
return alreadyActive.get() ? Response.ok("") : Response.created("");
}
示例10: apply
import com.google.gerrit.extensions.restapi.Response; //导入依赖的package包/类
public Response<String> apply(IdentifiedUser user, NameInput input)
throws MethodNotAllowedException, ResourceNotFoundException, IOException,
ConfigInvalidException {
if (input == null) {
input = new NameInput();
}
if (!realm.allowsEdit(AccountFieldName.FULL_NAME)) {
throw new MethodNotAllowedException("realm does not allow editing name");
}
String newName = input.name;
Account account =
accountsUpdate.create().update(user.getAccountId(), a -> a.setFullName(newName));
if (account == null) {
throw new ResourceNotFoundException("account not found");
}
return Strings.isNullOrEmpty(account.getFullName())
? Response.none()
: Response.ok(account.getFullName());
}
示例11: applyImpl
import com.google.gerrit.extensions.restapi.Response; //导入依赖的package包/类
@Override
protected Response<?> applyImpl(
BatchUpdate.Factory updateFactory, ChangeResource rsrc, PublishChangeEditInput in)
throws IOException, OrmException, RestApiException, UpdateException, ConfigInvalidException,
NoSuchProjectException {
contributorAgreementsChecker.check(rsrc.getProject(), rsrc.getUser());
Optional<ChangeEdit> edit = editUtil.byChange(rsrc.getNotes(), rsrc.getUser());
if (!edit.isPresent()) {
throw new ResourceConflictException(
String.format("no edit exists for change %s", rsrc.getChange().getChangeId()));
}
if (in == null) {
in = new PublishChangeEditInput();
}
editUtil.publish(
updateFactory,
rsrc.getNotes(),
rsrc.getUser(),
edit.get(),
in.notify,
notifyUtil.resolveAccounts(in.notifyDetails));
return Response.none();
}
示例12: apply
import com.google.gerrit.extensions.restapi.Response; //导入依赖的package包/类
public Response<String> apply(IdentifiedUser user, StatusInput input)
throws ResourceNotFoundException, IOException, ConfigInvalidException {
if (input == null) {
input = new StatusInput();
}
String newStatus = input.status;
Account account =
accountsUpdate
.create()
.update(user.getAccountId(), a -> a.setStatus(Strings.nullToEmpty(newStatus)));
if (account == null) {
throw new ResourceNotFoundException("account not found");
}
return Strings.isNullOrEmpty(account.getStatus())
? Response.none()
: Response.ok(account.getStatus());
}
示例13: apply
import com.google.gerrit.extensions.restapi.Response; //导入依赖的package包/类
@Override
public Response<?> apply(AccountResource rsrc, List<ProjectWatchInfo> input)
throws AuthException, UnprocessableEntityException, OrmException, IOException,
ConfigInvalidException, PermissionBackendException {
if (self.get() != rsrc.getUser()) {
permissionBackend.user(self).check(GlobalPermission.ADMINISTRATE_SERVER);
}
if (input == null) {
return Response.none();
}
Account.Id accountId = rsrc.getUser().getAccountId();
watchConfig.deleteProjectWatches(
accountId,
input
.stream()
.filter(Objects::nonNull)
.map(w -> ProjectWatchKey.create(new Project.NameKey(w.project), w.filter))
.collect(toList()));
accountCache.evict(accountId);
return Response.none();
}
示例14: apply
import com.google.gerrit.extensions.restapi.Response; //导入依赖的package包/类
@Override
public Response<String> apply(ConfigResource rsrc, Input input)
throws AuthException, BadRequestException, UnprocessableEntityException,
PermissionBackendException {
if (input == null || input.operation == null) {
throw new BadRequestException("operation must be specified");
}
switch (input.operation) {
case FLUSH_ALL:
if (input.caches != null) {
throw new BadRequestException(
"specifying caches is not allowed for operation 'FLUSH_ALL'");
}
flushAll();
return Response.ok("");
case FLUSH:
if (input.caches == null || input.caches.isEmpty()) {
throw new BadRequestException("caches must be specified for operation 'FLUSH'");
}
flush(input.caches);
return Response.ok("");
default:
throw new BadRequestException("unsupported operation: " + input.operation);
}
}
示例15: importAccount
import com.google.gerrit.extensions.restapi.Response; //导入依赖的package包/类
public Account.Id importAccount(String login, String name, String email)
throws IOException, BadRequestException, ResourceConflictException,
UnprocessableEntityException, OrmException, ConfigInvalidException {
CreateAccount createAccount = createAccountFactory.create(login);
AccountInput accountInput = new AccountInput();
accountInput.email = email;
accountInput.username = login;
accountInput.name = MoreObjects.firstNonNull(name, login);
Response<AccountInfo> accountResponse =
createAccount.apply(TopLevelResource.INSTANCE, accountInput);
if (accountResponse.statusCode() != HttpStatus.SC_CREATED) {
throw new IOException(
"Cannot import GitHub account "
+ login
+ ": HTTP Status "
+ accountResponse.statusCode());
}
Id accountId = new Account.Id(accountResponse.value()._accountId.intValue());
externalIdsUpdateServer
.create()
.insert(ExternalId.create(ExternalId.SCHEME_GERRIT, login, accountId));
return accountId;
}