diff --git a/src/main/java/org/wise/portal/presentation/web/controllers/tag/UserTagController.java b/src/main/java/org/wise/portal/presentation/web/controllers/tag/UserTagController.java index ad3d60122..e05cb15cd 100644 --- a/src/main/java/org/wise/portal/presentation/web/controllers/tag/UserTagController.java +++ b/src/main/java/org/wise/portal/presentation/web/controllers/tag/UserTagController.java @@ -38,7 +38,11 @@ public class UserTagController { protected ResponseEntity> createTag(Authentication auth, @RequestBody Map tag) { User user = userService.retrieveUserByUsername(auth.getName()); - UserTag userTag = userTagsService.createTag(user, (String) tag.get("text")); + String tagText = ((String) tag.get("text")).trim(); + if (userTagsService.hasTag(user, tagText)) { + return ResponseEntityGenerator.createError("tagAlreadyExists"); + } + UserTag userTag = userTagsService.createTag(user, tagText); return ResponseEntityGenerator.createSuccess(userTag.toMap()); } diff --git a/src/main/java/org/wise/portal/service/usertags/UserTagsService.java b/src/main/java/org/wise/portal/service/usertags/UserTagsService.java index d78a7ea56..02be2ca7b 100644 --- a/src/main/java/org/wise/portal/service/usertags/UserTagsService.java +++ b/src/main/java/org/wise/portal/service/usertags/UserTagsService.java @@ -17,6 +17,8 @@ public interface UserTagsService { Set getTags(User user, Project project); + Boolean hasTag(User user, String tag); + Boolean hasTag(User user, Project project, String tag); void applyTag(Project project, UserTag tag); diff --git a/src/main/java/org/wise/portal/service/usertags/impl/UserTagsServiceImpl.java b/src/main/java/org/wise/portal/service/usertags/impl/UserTagsServiceImpl.java index ed99f01b4..5d6219539 100644 --- a/src/main/java/org/wise/portal/service/usertags/impl/UserTagsServiceImpl.java +++ b/src/main/java/org/wise/portal/service/usertags/impl/UserTagsServiceImpl.java @@ -57,6 +57,12 @@ public Set getTags(User user, Project project) { .collect(Collectors.toSet()); } + @Override + public Boolean hasTag(User user, String tag) { + return getTags(user).stream() + .anyMatch(t -> t.getText().toLowerCase().equals(tag.toLowerCase())); + } + @Override public Boolean hasTag(User user, Project project, String tag) { MutableAclTargetObjectIdentity mutableObjectIdentity = getMutableObjectIdentity(project);