Add REST endpoint to update an existing label

Bug: Issue 11522
Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: Ic50e7fc1cf4daedfb8c7f0ae6458a807146ade16
This commit is contained in:
Edwin Kempin
2019-10-25 13:28:46 +02:00
parent aa56f445d3
commit b5e8745db4
9 changed files with 1274 additions and 2 deletions

View File

@@ -18,9 +18,11 @@ import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
import com.google.gerrit.extensions.api.projects.LabelApi;
import com.google.gerrit.extensions.common.LabelDefinitionInfo;
import com.google.gerrit.extensions.common.LabelDefinitionInput;
import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.server.project.LabelResource;
import com.google.gerrit.server.restapi.project.GetLabel;
import com.google.gerrit.server.restapi.project.SetLabel;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
@@ -30,11 +32,13 @@ public class LabelApiImpl implements LabelApi {
}
private final GetLabel getLabel;
private final SetLabel setLabel;
private final LabelResource rsrc;
@Inject
LabelApiImpl(GetLabel getLabel, @Assisted LabelResource rsrc) {
LabelApiImpl(GetLabel getLabel, SetLabel setLabel, @Assisted LabelResource rsrc) {
this.getLabel = getLabel;
this.setLabel = setLabel;
this.rsrc = rsrc;
}
@@ -46,4 +50,13 @@ public class LabelApiImpl implements LabelApi {
throw asRestApiException("Cannot get label", e);
}
}
@Override
public LabelDefinitionInfo update(LabelDefinitionInput input) throws RestApiException {
try {
return setLabel.apply(rsrc, input).value();
} catch (Exception e) {
throw asRestApiException("Cannot update label", e);
}
}
}