#83: Tag name duplicates now allowed

This commit is contained in:
jendib 2016-05-05 21:12:14 +02:00
parent 27027ec412
commit c398a3c4f5
3 changed files with 13 additions and 16 deletions

9
.travis.yml Normal file
View File

@ -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

View File

@ -57,7 +57,7 @@ public class TagResource extends BaseResource {
.add("id", tagDto.getId()) .add("id", tagDto.getId())
.add("name", tagDto.getName()) .add("name", tagDto.getName())
.add("color", tagDto.getColor()) .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() JsonObjectBuilder response = Json.createObjectBuilder()
@ -120,18 +120,12 @@ public class TagResource extends BaseResource {
throw new ClientException("SpacesNotAllowed", "Spaces are not allowed in tag name"); throw new ClientException("SpacesNotAllowed", "Spaces are not allowed in tag name");
} }
// Get the tag
TagDao tagDao = new TagDao();
List<TagDto> 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 // Check the parent
TagDao tagDao = new TagDao();
if (StringUtils.isEmpty(parentId)) { if (StringUtils.isEmpty(parentId)) {
parentId = null; parentId = null;
} else { } else {
tagDtoList = tagDao.findByCriteria(new TagCriteria().setUserId(principal.getId()).setId(parentId), null); List<TagDto> tagDtoList = tagDao.findByCriteria(new TagCriteria().setUserId(principal.getId()).setId(parentId), null);
if (tagDtoList.size() == 0) { if (tagDtoList.size() == 0) {
throw new ClientException("ParentNotFound", MessageFormat.format("Parent not found: {0}", parentId)); 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(); 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 // Update the tag
Tag tag = tagDao.getById(id); Tag tag = tagDao.getById(id);
if (!StringUtils.isEmpty(name)) { if (!StringUtils.isEmpty(name)) {

View File

@ -55,7 +55,7 @@ public class TestTagResource extends BaseJerseyTest {
Assert.assertEquals(Status.BAD_REQUEST, Status.fromStatusCode(response.getStatus())); Assert.assertEquals(Status.BAD_REQUEST, Status.fromStatusCode(response.getStatus()));
// Create a document // Create a document
json = target().path("/document").request() target().path("/document").request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, tag1Token) .cookie(TokenBasedSecurityFilter.COOKIE_NAME, tag1Token)
.put(Entity.form(new Form() .put(Entity.form(new Form()
.param("title", "My super document 1") .param("title", "My super document 1")