1
0
mirror of https://github.com/sismics/docs.git synced 2025-12-28 17:11:41 +00:00

Tag colors (server)

This commit is contained in:
jendib
2013-08-07 23:45:47 +02:00
parent 1deda6e993
commit b2ab313d11
12 changed files with 90 additions and 13 deletions

View File

@@ -20,6 +20,7 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.apache.commons.lang.StringUtils;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
@@ -83,6 +84,7 @@ public class DocumentResource extends BaseResource {
JSONObject tag = new JSONObject();
tag.put("id", tagDto.getId());
tag.put("name", tagDto.getName());
tag.put("color", tagDto.getColor());
tags.add(tag);
}
document.put("tags", tags);
@@ -149,6 +151,7 @@ public class DocumentResource extends BaseResource {
JSONObject tag = new JSONObject();
tag.put("id", tagDto.getId());
tag.put("name", tagDto.getName());
tag.put("color", tagDto.getColor());
tags.add(tag);
}
document.put("tags", tags);
@@ -228,7 +231,7 @@ public class DocumentResource extends BaseResource {
}
// Validate input data
title = ValidationUtil.validateLength(title, "title", 1, 100, false);
title = ValidationUtil.validateLength(title, "title", 1, 100, true);
description = ValidationUtil.validateLength(description, "description", 0, 4000, true);
Date createDate = ValidationUtil.validateDate(createDateStr, "create_date", true);
@@ -242,10 +245,10 @@ public class DocumentResource extends BaseResource {
}
// Update the document
if (title != null) {
if (!StringUtils.isEmpty(title)) {
document.setTitle(title);
}
if (description != null) {
if (!StringUtils.isEmpty(description)) {
document.setDescription(description);
}
if (createDate != null) {

View File

@@ -15,6 +15,7 @@ import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.apache.commons.lang.StringUtils;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
@@ -54,6 +55,7 @@ public class TagResource extends BaseResource {
JSONObject item = new JSONObject();
item.put("id", tag.getId());
item.put("name", tag.getName());
item.put("color", tag.getColor());
items.add(item);
}
response.put("tags", items);
@@ -82,6 +84,7 @@ public class TagResource extends BaseResource {
JSONObject item = new JSONObject();
item.put("id", tagStatDto.getId());
item.put("name", tagStatDto.getName());
item.put("color", tagStatDto.getColor());
item.put("count", tagStatDto.getCount());
items.add(item);
}
@@ -99,13 +102,15 @@ public class TagResource extends BaseResource {
@PUT
@Produces(MediaType.APPLICATION_JSON)
public Response add(
@FormParam("name") String name) throws JSONException {
@FormParam("name") String name,
@FormParam("color") String color) throws JSONException {
if (!authenticate()) {
throw new ForbiddenClientException();
}
// Validate input data
name = ValidationUtil.validateLength(name, "name", 1, 36, false);
color = ValidationUtil.validateLength(color, "color", 6, 6, false);
// Get the tag
TagDao tagDao = new TagDao();
@@ -117,6 +122,7 @@ public class TagResource extends BaseResource {
// Create the tag
tag = new Tag();
tag.setName(name);
tag.setColor(color);
tag.setUserId(principal.getId());
String tagId = tagDao.create(tag);
@@ -137,13 +143,15 @@ public class TagResource extends BaseResource {
@Produces(MediaType.APPLICATION_JSON)
public Response update(
@PathParam("id") String id,
@FormParam("name") String name) throws JSONException {
@FormParam("name") String name,
@FormParam("color") String color) throws JSONException {
if (!authenticate()) {
throw new ForbiddenClientException();
}
// Validate input data
name = ValidationUtil.validateLength(name, "name", 1, 36, false);
name = ValidationUtil.validateLength(name, "name", 1, 36, true);
color = ValidationUtil.validateLength(color, "color", 6, 6, true);
// Get the tag
TagDao tagDao = new TagDao();
@@ -153,7 +161,12 @@ public class TagResource extends BaseResource {
}
// Update the tag
tag.setName(name);
if (!StringUtils.isEmpty(name)) {
tag.setName(name);
}
if (!StringUtils.isEmpty(color)) {
tag.setColor(color);
}
JSONObject response = new JSONObject();
response.put("id", id);