Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,6 @@ public void testUpdateProject_Success() {
Assert.assertEquals("another_name", updated.getName());
}

@Test(expected = BadRequestException.class)
public void testUpdateProject_DuplicatedName_Fail() {
Mockito.when(resourceRoleService.saveAll(Mockito.any())).thenReturn(listUserResourceRole(1L));
Project saved = projectService.create(getProject());
projectService.update(saved.getId(), saved);
}

@Test
public void testArchiveProject_Archived() throws InterruptedException {
Project saved = projectService.create(getProject());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import com.oceanbase.odc.core.shared.constant.ResourceType;
import com.oceanbase.odc.core.shared.exception.BadRequestException;
import com.oceanbase.odc.core.shared.exception.NotFoundException;
import com.oceanbase.odc.core.shared.exception.UnsupportedException;
import com.oceanbase.odc.metadb.collaboration.ProjectEntity;
import com.oceanbase.odc.metadb.collaboration.ProjectRepository;
import com.oceanbase.odc.metadb.collaboration.ProjectSpecs;
Expand Down Expand Up @@ -242,27 +243,18 @@ public Project getByIdentifier(@NotNull String uniqueIdentifier) {
@PreAuthenticate(hasAnyResourceRole = {"OWNER"}, resourceType = "ODC_PROJECT", indexOfIdParam = 0)
@Transactional(rollbackFor = Exception.class)
public Project update(@NotNull Long id, @NotNull Project project) {

ProjectEntity previous = repository.findByIdAndOrganizationId(id, currentOrganizationId())
.orElseThrow(() -> new NotFoundException(ResourceType.ODC_PROJECT, "id", id));
/**
* not allowed to update a built-in project or an archived project
*/
if (previous.getBuiltin() || previous.getArchived()) {
return entityToModel(previous,
resourceRoleService.listByResourceTypeAndId(ResourceType.ODC_PROJECT, previous.getId()));
throw new UnsupportedException(ErrorCodes.IllegalOperation, new Object[] {"builtin or archived project"},
"Operation on builtin or archived project is not allowed");
}
if (!Objects.equals(previous.getName(), project.getName())) {
checkNoDuplicateProject(project);
}

checkNoDuplicateProject(project);

previous.setLastModifierId(authenticationFacade.currentUserId());
previous.setDescription(project.getDescription());
previous.setName(project.getName());


/**
* save project
*/
ProjectEntity saved = repository.save(previous);
return entityToModel(saved,
resourceRoleService.listByResourceTypeAndId(ResourceType.ODC_PROJECT, saved.getId()));
Expand Down