Skip to content

Commit

Permalink
Merge pull request #4594 from nscuro/issue-4593
Browse files Browse the repository at this point in the history
  • Loading branch information
nscuro authored Jan 28, 2025
2 parents 57b5cc3 + 761f849 commit 9bef0c9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,17 @@ public boolean bind(final NotificationRule notificationRule, final Collection<Ta
return callInTransaction(() -> {
boolean modified = false;

if (notificationRule.getTags() == null) {
notificationRule.setTags(new ArrayList<>());
}

if (!keepExisting) {
for (final Tag existingTag : notificationRule.getTags()) {
if (!tags.contains(existingTag)) {
notificationRule.getTags().remove(existingTag);
existingTag.getNotificationRules().remove(notificationRule);
if (existingTag.getNotificationRules() != null) {
existingTag.getNotificationRules().remove(notificationRule);
}
modified = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -841,11 +841,17 @@ public boolean bind(final Policy policy, final Collection<Tag> tags, final boole
return callInTransaction(() -> {
boolean modified = false;

if (policy.getTags() == null) {
policy.setTags(new ArrayList<>());
}

if (!keepExisting) {
for (final Tag existingTag : policy.getTags()) {
if (!tags.contains(existingTag)) {
policy.getTags().remove(existingTag);
existingTag.getPolicies().remove(policy);
if (existingTag.getPolicies() != null) {
existingTag.getPolicies().remove(policy);
}
modified = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1382,11 +1382,17 @@ public boolean bind(final Project project, final Collection<Tag> tags, final boo
return callInTransaction(() -> {
boolean modified = false;

if (project.getTags() == null) {
project.setTags(new ArrayList<>());
}

if (!keepExisting) {
for (final Tag existingTag : project.getTags()) {
if (!tags.contains(existingTag)) {
project.getTags().remove(existingTag);
existingTag.getProjects().remove(project);
if (existingTag.getProjects() != null) {
existingTag.getProjects().remove(project);
}
modified = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,14 +475,21 @@ public void getProjectByUnknownTagTest() {

@Test
public void createProjectTest(){
Project project = new Project();
project.setName("Acme Example");
project.setVersion("1.0");
project.setDescription("Test project");
Response response = jersey.target(V1_PROJECT)
.request()
.header(X_API_KEY, apiKey)
.put(Entity.entity(project, MediaType.APPLICATION_JSON));
.put(Entity.json("""
{
"name": "Acme Example",
"version": "1.0",
"description": "Test project",
"tags": [
{
"name": "foo"
}
]
}
"""));
Assert.assertEquals(201, response.getStatus(), 0);
JsonObject json = parseJsonObject(response);
Assert.assertNotNull(json);
Expand All @@ -491,6 +498,8 @@ public void createProjectTest(){
Assert.assertEquals("Test project", json.getString("description"));
Assert.assertTrue(json.getBoolean("active"));
Assert.assertTrue(UuidUtil.isValidUUID(json.getString("uuid")));
assertThat(json.getJsonArray("tags").getValuesAs(JsonObject.class)).satisfiesExactly(
jsonObject -> assertThat(jsonObject.getString("name")).isEqualTo("foo"));
}

@Test
Expand Down

0 comments on commit 9bef0c9

Please sign in to comment.