use of com.google.gerrit.exceptions.DuplicateKeyException in project gerrit by GerritCodeReview.
the class PutName method renameGroup.
private void renameGroup(GroupDescription.Internal group, String newName) throws ResourceConflictException, ResourceNotFoundException, IOException, ConfigInvalidException {
AccountGroup.UUID groupUuid = group.getGroupUUID();
GroupDelta groupDelta = GroupDelta.builder().setName(AccountGroup.nameKey(newName)).build();
try {
groupsUpdateProvider.get().updateGroup(groupUuid, groupDelta);
} catch (NoSuchGroupException e) {
throw new ResourceNotFoundException(String.format("Group %s not found", groupUuid), e);
} catch (DuplicateKeyException e) {
throw new ResourceConflictException("group with name " + newName + " already exists", e);
}
}
use of com.google.gerrit.exceptions.DuplicateKeyException in project gerrit by GerritCodeReview.
the class GroupNameNotesTest method groupCannotBeRenamedToNameOfAnotherGroup.
@Test
public void groupCannotBeRenamedToNameOfAnotherGroup() throws Exception {
createGroup(groupUuid, groupName);
AccountGroup.UUID anotherGroupUuid = AccountGroup.uuid("admins-ABC");
AccountGroup.NameKey anotherGroupName = AccountGroup.nameKey("admins");
createGroup(anotherGroupUuid, anotherGroupName);
DuplicateKeyException thrown = assertThrows(DuplicateKeyException.class, () -> GroupNameNotes.forRename(allUsersName, repo, groupUuid, groupName, anotherGroupName));
assertThat(thrown).hasMessageThat().contains(anotherGroupName.get());
}
use of com.google.gerrit.exceptions.DuplicateKeyException in project gerrit by GerritCodeReview.
the class GroupNameNotesTest method newGroupMustNotReuseNameOfAnotherGroup.
@Test
public void newGroupMustNotReuseNameOfAnotherGroup() throws Exception {
createGroup(groupUuid, groupName);
AccountGroup.UUID anotherGroupUuid = AccountGroup.uuid("AnotherGroup");
DuplicateKeyException thrown = assertThrows(DuplicateKeyException.class, () -> GroupNameNotes.forNewGroup(allUsersName, repo, anotherGroupUuid, groupName));
assertThat(thrown).hasMessageThat().contains(groupName.get());
}
use of com.google.gerrit.exceptions.DuplicateKeyException in project gerrit by GerritCodeReview.
the class JdbcAccountPatchReviewStore method markReviewed.
@Override
public void markReviewed(PatchSet.Id psId, Account.Id accountId, Collection<String> paths) {
if (paths == null || paths.isEmpty()) {
return;
}
try (TraceTimer ignored = TraceContext.newTimer("Mark files as reviewed", Metadata.builder().patchSetId(psId.get()).accountId(accountId.get()).resourceCount(paths.size()).build());
Connection con = ds.getConnection();
PreparedStatement stmt = con.prepareStatement("INSERT INTO account_patch_reviews " + "(account_id, change_id, patch_set_id, file_name) VALUES " + "(?, ?, ?, ?)")) {
for (String path : paths) {
stmt.setInt(1, accountId.get());
stmt.setInt(2, psId.changeId().get());
stmt.setInt(3, psId.get());
stmt.setString(4, path);
stmt.addBatch();
}
stmt.executeBatch();
} catch (SQLException e) {
StorageException ormException = convertError("insert", e);
if (ormException instanceof DuplicateKeyException) {
return;
}
throw ormException;
}
}
use of com.google.gerrit.exceptions.DuplicateKeyException in project gerrit by GerritCodeReview.
the class AccountConfig method getNewAccount.
/**
* Creates a new account.
*
* @return the new account
* @throws DuplicateKeyException if the user branch already exists
*/
Account getNewAccount(Instant registeredOn) throws DuplicateKeyException {
checkLoaded();
if (revision != null) {
throw new DuplicateKeyException(String.format("account %s already exists", accountId));
}
this.loadedAccountProperties = Optional.of(new AccountProperties(accountId, registeredOn, new Config(), null));
return loadedAccountProperties.map(AccountProperties::getAccount).get();
}
Aggregations