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
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ kotlin-stdlibJdk8 = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", versio
commons-compress = { module = "org.apache.commons:commons-compress", version = "1.21" }
jersey-common = { module = "org.glassfish.jersey.core:jersey-common", version = "2.34" }

slf4j-log4jimpl = { module = "org.apache.logging.log4j:log4j-slf4j-impl", version = "2.15.0" }
slf4j-log4jimpl = { module = "org.apache.logging.log4j:log4j-slf4j-impl", version = "2.16.0" }
slf4j-api = { module = "org.slf4j:slf4j-api", version = "1.7.30" }


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
Expand Down Expand Up @@ -246,7 +247,7 @@ public void updateLabel(
responseObserver.onError(new StatusRuntimeException(Status.INVALID_ARGUMENT));
return;
}
if (isDuplicateKey(requestContext, updateLabelData.getKey())) {
if (isDuplicateKey(requestContext, request.getId(), updateLabelData.getKey())) {
responseObserver.onError(new StatusRuntimeException(Status.ALREADY_EXISTS));
return;
}
Expand Down Expand Up @@ -301,6 +302,11 @@ public void deleteLabel(
}
}

private boolean isDuplicateKey(RequestContext requestContext, String id, String key) {
return Optional.ofNullable(getLabelsMap(requestContext).get(key)).stream()
.anyMatch(label -> !label.getId().equals(id));
}

private boolean isDuplicateKey(RequestContext requestContext, String key) {
return getLabelsMap(requestContext).containsKey(key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,19 @@ void test_updateLabel() {
.build());
});
assertEquals(Status.ALREADY_EXISTS, Status.fromThrowable(exception1));
// Updating the labels by appending the keys of labels with a "new"

// Updating the labels by adding description
List<Label> updateLabelsList =
createdLabelsList.stream()
.map(
label ->
Label.newBuilder()
.setId(label.getId())
.setData(
LabelData.newBuilder().setKey(label.getData().getKey() + "new").build())
LabelData.newBuilder()
.setKey(label.getData().getKey())
.setDescription("description")
.build())
.build())
.collect(Collectors.toList());
List<Label> updatedLabelsList =
Expand All @@ -278,6 +282,36 @@ void test_updateLabel() {
})
.collect(Collectors.toList());
assertEquals(updateLabelsList, updatedLabelsList);

// Updating the labels by appending the keys of labels with a "new"
updateLabelsList =
createdLabelsList.stream()
.map(
label ->
Label.newBuilder()
.setId(label.getId())
.setData(
LabelData.newBuilder()
.setKey(label.getData().getKey() + "new")
.setDescription("description")
.build())
.build())
.collect(Collectors.toList());
updatedLabelsList =
updateLabelsList.stream()
.map(
updateLabel -> {
UpdateLabelResponse response =
labelConfigStub.updateLabel(
UpdateLabelRequest.newBuilder()
.setId(updateLabel.getId())
.setData(updateLabel.getData())
.build());
return response.getLabel();
})
.collect(Collectors.toList());
assertEquals(updateLabelsList, updatedLabelsList);

// Updating a label that does not exist
Throwable exception =
assertThrows(
Expand Down