From c398a3c4f5b152e751caf4bdd32e0c77c1a9be60 Mon Sep 17 00:00:00 2001 From: jendib Date: Thu, 5 May 2016 21:12:14 +0200 Subject: [PATCH] #83: Tag name duplicates now allowed --- .travis.yml | 9 +++++++++ .../docs/rest/resource/TagResource.java | 18 +++--------------- .../com/sismics/docs/rest/TestTagResource.java | 2 +- 3 files changed, 13 insertions(+), 16 deletions(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..8a2fd166 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +language: java +before_install: + - sudo apt-get -qq update + - sudo apt-get -y -q install tesseract-ocr tesseract-ocr-fra tesseract-ocr-jpn +env: + - TESSDATA_PREFIX=/usr/share/tesseract-ocr + - LC_NUMERIC=C +before_script: + - cd docs-parent \ No newline at end of file diff --git a/docs-web/src/main/java/com/sismics/docs/rest/resource/TagResource.java b/docs-web/src/main/java/com/sismics/docs/rest/resource/TagResource.java index ecf06573..63c3bf79 100644 --- a/docs-web/src/main/java/com/sismics/docs/rest/resource/TagResource.java +++ b/docs-web/src/main/java/com/sismics/docs/rest/resource/TagResource.java @@ -57,7 +57,7 @@ public class TagResource extends BaseResource { .add("id", tagDto.getId()) .add("name", tagDto.getName()) .add("color", tagDto.getColor()) - .add("parent", JsonUtil.nullable(tagDto.getParentId()))); + .add("parent", JsonUtil.nullable(tagDto.getParentId()))); // TODO Don't return the parent if it's not visible } JsonObjectBuilder response = Json.createObjectBuilder() @@ -120,18 +120,12 @@ public class TagResource extends BaseResource { throw new ClientException("SpacesNotAllowed", "Spaces are not allowed in tag name"); } - // Get the tag - TagDao tagDao = new TagDao(); - List tagDtoList = tagDao.findByCriteria(new TagCriteria().setUserId(principal.getId()).setName(name), null); - if (tagDtoList.size() > 0) { - throw new ClientException("AlreadyExistingTag", MessageFormat.format("Tag already exists: {0}", name)); - } - // Check the parent + TagDao tagDao = new TagDao(); if (StringUtils.isEmpty(parentId)) { parentId = null; } else { - tagDtoList = tagDao.findByCriteria(new TagCriteria().setUserId(principal.getId()).setId(parentId), null); + List tagDtoList = tagDao.findByCriteria(new TagCriteria().setUserId(principal.getId()).setId(parentId), null); if (tagDtoList.size() == 0) { throw new ClientException("ParentNotFound", MessageFormat.format("Parent not found: {0}", parentId)); } @@ -212,12 +206,6 @@ public class TagResource extends BaseResource { parentId = tagDtoList.get(0).getId(); } - // Check for name duplicate - tagDtoList = tagDao.findByCriteria(new TagCriteria().setUserId(principal.getId()).setName(name), null); - if (tagDtoList.size() > 0 && !tagDtoList.get(0).getId().equals(id)) { - throw new ClientException("AlreadyExistingTag", MessageFormat.format("Tag already exists: {0}", name)); - } - // Update the tag Tag tag = tagDao.getById(id); if (!StringUtils.isEmpty(name)) { diff --git a/docs-web/src/test/java/com/sismics/docs/rest/TestTagResource.java b/docs-web/src/test/java/com/sismics/docs/rest/TestTagResource.java index 597074da..f8b63729 100644 --- a/docs-web/src/test/java/com/sismics/docs/rest/TestTagResource.java +++ b/docs-web/src/test/java/com/sismics/docs/rest/TestTagResource.java @@ -55,7 +55,7 @@ public class TestTagResource extends BaseJerseyTest { Assert.assertEquals(Status.BAD_REQUEST, Status.fromStatusCode(response.getStatus())); // Create a document - json = target().path("/document").request() + target().path("/document").request() .cookie(TokenBasedSecurityFilter.COOKIE_NAME, tag1Token) .put(Entity.form(new Form() .param("title", "My super document 1")