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

@ -82,7 +82,7 @@ public class TagDao {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public List<TagDto> getByDocumentId(String documentId) { public List<TagDto> getByDocumentId(String documentId) {
EntityManager em = ThreadLocalContext.get().getEntityManager(); EntityManager em = ThreadLocalContext.get().getEntityManager();
StringBuilder sb = new StringBuilder("select t.TAG_ID_C, t.TAG_NAME_C from T_DOCUMENT_TAG dt "); StringBuilder sb = new StringBuilder("select t.TAG_ID_C, t.TAG_NAME_C, t.TAG_COLOR_C from T_DOCUMENT_TAG dt ");
sb.append(" join T_TAG t on t.TAG_ID_C = dt.DOT_IDTAG_C "); sb.append(" join T_TAG t on t.TAG_ID_C = dt.DOT_IDTAG_C ");
sb.append(" where dt.DOT_IDDOCUMENT_C = :documentId and t.TAG_DELETEDATE_D is null "); sb.append(" where dt.DOT_IDDOCUMENT_C = :documentId and t.TAG_DELETEDATE_D is null ");
sb.append(" order by t.TAG_NAME_C "); sb.append(" order by t.TAG_NAME_C ");
@ -99,6 +99,7 @@ public class TagDao {
TagDto tagDto = new TagDto(); TagDto tagDto = new TagDto();
tagDto.setId((String) o[i++]); tagDto.setId((String) o[i++]);
tagDto.setName((String) o[i++]); tagDto.setName((String) o[i++]);
tagDto.setColor((String) o[i++]);
tagDtoList.add(tagDto); tagDtoList.add(tagDto);
} }
return tagDtoList; return tagDtoList;
@ -112,7 +113,7 @@ public class TagDao {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public List<TagStatDto> getStats(String userId) { public List<TagStatDto> getStats(String userId) {
EntityManager em = ThreadLocalContext.get().getEntityManager(); EntityManager em = ThreadLocalContext.get().getEntityManager();
StringBuilder sb = new StringBuilder("select t.TAG_ID_C, t.TAG_NAME_C, count(d.DOC_ID_C) "); StringBuilder sb = new StringBuilder("select t.TAG_ID_C, t.TAG_NAME_C, t.TAG_COLOR_C, count(d.DOC_ID_C) ");
sb.append(" from T_TAG t "); sb.append(" from T_TAG t ");
sb.append(" left join T_DOCUMENT_TAG dt on t.TAG_ID_C = dt.DOT_IDTAG_C "); sb.append(" left join T_DOCUMENT_TAG dt on t.TAG_ID_C = dt.DOT_IDTAG_C ");
sb.append(" left join T_DOCUMENT d on d.DOC_ID_C = dt.DOT_IDDOCUMENT_C and d.DOC_DELETEDATE_D is null and d.DOC_IDUSER_C = :userId "); sb.append(" left join T_DOCUMENT d on d.DOC_ID_C = dt.DOT_IDDOCUMENT_C and d.DOC_DELETEDATE_D is null and d.DOC_IDUSER_C = :userId ");
@ -132,6 +133,7 @@ public class TagDao {
TagStatDto tagDto = new TagStatDto(); TagStatDto tagDto = new TagStatDto();
tagDto.setId((String) o[i++]); tagDto.setId((String) o[i++]);
tagDto.setName((String) o[i++]); tagDto.setName((String) o[i++]);
tagDto.setColor((String) o[i++]);
tagDto.setCount(((Number) o[i++]).intValue()); tagDto.setCount(((Number) o[i++]).intValue());
tagStatDtoList.add(tagDto); tagStatDtoList.add(tagDto);
} }

View File

@ -18,6 +18,11 @@ public class TagDto {
* Name. * Name.
*/ */
private String name; private String name;
/**
* Color.
*/
private String color;
/** /**
* Getter of id. * Getter of id.
@ -54,4 +59,22 @@ public class TagDto {
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
/**
* Getter of color.
*
* @return the color
*/
public String getColor() {
return color;
}
/**
* Setter of color.
*
* @param color color
*/
public void setColor(String color) {
this.color = color;
}
} }

View File

@ -47,6 +47,12 @@ public class Tag {
*/ */
@Column(name = "TAG_DELETEDATE_D") @Column(name = "TAG_DELETEDATE_D")
private Date deleteDate; private Date deleteDate;
/**
* Tag name.
*/
@Column(name = "TAG_COLOR_C", nullable = false, length = 6)
private String color;
/** /**
* Getter of id. * Getter of id.
@ -119,6 +125,24 @@ public class Tag {
public void setCreateDate(Date createDate) { public void setCreateDate(Date createDate) {
this.createDate = createDate; this.createDate = createDate;
} }
/**
* Getter of color.
*
* @return the color
*/
public String getColor() {
return color;
}
/**
* Setter of color.
*
* @param color color
*/
public void setColor(String color) {
this.color = color;
}
/** /**
* Getter of deleteDate. * Getter of deleteDate.

View File

@ -1 +1 @@
db.version=1 db.version=2

View File

@ -0,0 +1,3 @@
alter table T_TAG add column TAG_COLOR_C varchar(6) not null;
update T_TAG set TAG_COLOR_C = '3a87ad';
update T_CONFIG set CFG_VALUE_C='2' where CFG_ID_C='DB_VERSION';

View File

@ -1,2 +1,2 @@
- Users administration (client) - Users administration (client)
- Tag color (client/server) - Tag color (client)

View File

@ -1,3 +1,3 @@
api.current_version=${project.version} api.current_version=${project.version}
api.min_version=1.0 api.min_version=1.0
db.version=1 db.version=2

View File

@ -20,6 +20,7 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import org.apache.commons.lang.StringUtils;
import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONObject;
@ -83,6 +84,7 @@ public class DocumentResource extends BaseResource {
JSONObject tag = new JSONObject(); JSONObject tag = new JSONObject();
tag.put("id", tagDto.getId()); tag.put("id", tagDto.getId());
tag.put("name", tagDto.getName()); tag.put("name", tagDto.getName());
tag.put("color", tagDto.getColor());
tags.add(tag); tags.add(tag);
} }
document.put("tags", tags); document.put("tags", tags);
@ -149,6 +151,7 @@ public class DocumentResource extends BaseResource {
JSONObject tag = new JSONObject(); JSONObject tag = new JSONObject();
tag.put("id", tagDto.getId()); tag.put("id", tagDto.getId());
tag.put("name", tagDto.getName()); tag.put("name", tagDto.getName());
tag.put("color", tagDto.getColor());
tags.add(tag); tags.add(tag);
} }
document.put("tags", tags); document.put("tags", tags);
@ -228,7 +231,7 @@ public class DocumentResource extends BaseResource {
} }
// Validate input data // 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); description = ValidationUtil.validateLength(description, "description", 0, 4000, true);
Date createDate = ValidationUtil.validateDate(createDateStr, "create_date", true); Date createDate = ValidationUtil.validateDate(createDateStr, "create_date", true);
@ -242,10 +245,10 @@ public class DocumentResource extends BaseResource {
} }
// Update the document // Update the document
if (title != null) { if (!StringUtils.isEmpty(title)) {
document.setTitle(title); document.setTitle(title);
} }
if (description != null) { if (!StringUtils.isEmpty(description)) {
document.setDescription(description); document.setDescription(description);
} }
if (createDate != null) { 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.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import org.apache.commons.lang.StringUtils;
import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONObject;
@ -54,6 +55,7 @@ public class TagResource extends BaseResource {
JSONObject item = new JSONObject(); JSONObject item = new JSONObject();
item.put("id", tag.getId()); item.put("id", tag.getId());
item.put("name", tag.getName()); item.put("name", tag.getName());
item.put("color", tag.getColor());
items.add(item); items.add(item);
} }
response.put("tags", items); response.put("tags", items);
@ -82,6 +84,7 @@ public class TagResource extends BaseResource {
JSONObject item = new JSONObject(); JSONObject item = new JSONObject();
item.put("id", tagStatDto.getId()); item.put("id", tagStatDto.getId());
item.put("name", tagStatDto.getName()); item.put("name", tagStatDto.getName());
item.put("color", tagStatDto.getColor());
item.put("count", tagStatDto.getCount()); item.put("count", tagStatDto.getCount());
items.add(item); items.add(item);
} }
@ -99,13 +102,15 @@ public class TagResource extends BaseResource {
@PUT @PUT
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response add( public Response add(
@FormParam("name") String name) throws JSONException { @FormParam("name") String name,
@FormParam("color") String color) throws JSONException {
if (!authenticate()) { if (!authenticate()) {
throw new ForbiddenClientException(); throw new ForbiddenClientException();
} }
// Validate input data // Validate input data
name = ValidationUtil.validateLength(name, "name", 1, 36, false); name = ValidationUtil.validateLength(name, "name", 1, 36, false);
color = ValidationUtil.validateLength(color, "color", 6, 6, false);
// Get the tag // Get the tag
TagDao tagDao = new TagDao(); TagDao tagDao = new TagDao();
@ -117,6 +122,7 @@ public class TagResource extends BaseResource {
// Create the tag // Create the tag
tag = new Tag(); tag = new Tag();
tag.setName(name); tag.setName(name);
tag.setColor(color);
tag.setUserId(principal.getId()); tag.setUserId(principal.getId());
String tagId = tagDao.create(tag); String tagId = tagDao.create(tag);
@ -137,13 +143,15 @@ public class TagResource extends BaseResource {
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response update( public Response update(
@PathParam("id") String id, @PathParam("id") String id,
@FormParam("name") String name) throws JSONException { @FormParam("name") String name,
@FormParam("color") String color) throws JSONException {
if (!authenticate()) { if (!authenticate()) {
throw new ForbiddenClientException(); throw new ForbiddenClientException();
} }
// Validate input data // 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 // Get the tag
TagDao tagDao = new TagDao(); TagDao tagDao = new TagDao();
@ -153,7 +161,12 @@ public class TagResource extends BaseResource {
} }
// Update the tag // Update the tag
tag.setName(name); if (!StringUtils.isEmpty(name)) {
tag.setName(name);
}
if (!StringUtils.isEmpty(color)) {
tag.setColor(color);
}
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
response.put("id", id); response.put("id", id);

View File

@ -1,3 +1,3 @@
api.current_version=${project.version} api.current_version=${project.version}
api.min_version=1.0 api.min_version=1.0
db.version=1 db.version=2

View File

@ -38,6 +38,7 @@ public class TestDocumentResource extends BaseJerseyTest {
tagResource.addFilter(new CookieAuthenticationFilter(document1Token)); tagResource.addFilter(new CookieAuthenticationFilter(document1Token));
MultivaluedMapImpl postParams = new MultivaluedMapImpl(); MultivaluedMapImpl postParams = new MultivaluedMapImpl();
postParams.add("name", "Super tag"); postParams.add("name", "Super tag");
postParams.add("color", "ffff00");
ClientResponse response = tagResource.put(ClientResponse.class, postParams); ClientResponse response = tagResource.put(ClientResponse.class, postParams);
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus())); Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
@ -75,6 +76,7 @@ public class TestDocumentResource extends BaseJerseyTest {
Assert.assertEquals(1, tags.length()); Assert.assertEquals(1, tags.length());
Assert.assertEquals(tag1Id, tags.getJSONObject(0).getString("id")); Assert.assertEquals(tag1Id, tags.getJSONObject(0).getString("id"));
Assert.assertEquals("Super tag", tags.getJSONObject(0).getString("name")); Assert.assertEquals("Super tag", tags.getJSONObject(0).getString("name"));
Assert.assertEquals("ffff00", tags.getJSONObject(0).getString("color"));
// Search documents by query // Search documents by query
documentResource = resource().path("/document/list"); documentResource = resource().path("/document/list");
@ -141,6 +143,7 @@ public class TestDocumentResource extends BaseJerseyTest {
tagResource.addFilter(new CookieAuthenticationFilter(document1Token)); tagResource.addFilter(new CookieAuthenticationFilter(document1Token));
postParams = new MultivaluedMapImpl(); postParams = new MultivaluedMapImpl();
postParams.add("name", "Super tag 2"); postParams.add("name", "Super tag 2");
postParams.add("color", "00ffff");
response = tagResource.put(ClientResponse.class, postParams); response = tagResource.put(ClientResponse.class, postParams);
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus())); Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
json = response.getEntity(JSONObject.class); json = response.getEntity(JSONObject.class);

View File

@ -35,6 +35,7 @@ public class TestTagResource extends BaseJerseyTest {
tagResource.addFilter(new CookieAuthenticationFilter(tag1Token)); tagResource.addFilter(new CookieAuthenticationFilter(tag1Token));
MultivaluedMapImpl postParams = new MultivaluedMapImpl(); MultivaluedMapImpl postParams = new MultivaluedMapImpl();
postParams.add("name", "Tag 3"); postParams.add("name", "Tag 3");
postParams.add("color", "ff0000");
ClientResponse response = tagResource.put(ClientResponse.class, postParams); ClientResponse response = tagResource.put(ClientResponse.class, postParams);
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus())); Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
@ -46,6 +47,7 @@ public class TestTagResource extends BaseJerseyTest {
tagResource.addFilter(new CookieAuthenticationFilter(tag1Token)); tagResource.addFilter(new CookieAuthenticationFilter(tag1Token));
postParams = new MultivaluedMapImpl(); postParams = new MultivaluedMapImpl();
postParams.add("name", "Tag 4"); postParams.add("name", "Tag 4");
postParams.add("color", "00ff00");
response = tagResource.put(ClientResponse.class, postParams); response = tagResource.put(ClientResponse.class, postParams);
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus())); Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
json = response.getEntity(JSONObject.class); json = response.getEntity(JSONObject.class);
@ -91,12 +93,15 @@ public class TestTagResource extends BaseJerseyTest {
json = response.getEntity(JSONObject.class); json = response.getEntity(JSONObject.class);
JSONArray tags = json.getJSONArray("tags"); JSONArray tags = json.getJSONArray("tags");
Assert.assertTrue(tags.length() > 0); Assert.assertTrue(tags.length() > 0);
Assert.assertEquals("Tag 4", tags.getJSONObject(1).getString("name"));
Assert.assertEquals("00ff00", tags.getJSONObject(1).getString("color"));
// Update a tag // Update a tag
tagResource = resource().path("/tag/" + tag4Id); tagResource = resource().path("/tag/" + tag4Id);
tagResource.addFilter(new CookieAuthenticationFilter(tag1Token)); tagResource.addFilter(new CookieAuthenticationFilter(tag1Token));
postParams = new MultivaluedMapImpl(); postParams = new MultivaluedMapImpl();
postParams.add("name", "Updated name"); postParams.add("name", "Updated name");
postParams.add("color", "0000ff");
response = tagResource.post(ClientResponse.class, postParams); response = tagResource.post(ClientResponse.class, postParams);
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus())); Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
json = response.getEntity(JSONObject.class); json = response.getEntity(JSONObject.class);
@ -111,6 +116,7 @@ public class TestTagResource extends BaseJerseyTest {
tags = json.getJSONArray("tags"); tags = json.getJSONArray("tags");
Assert.assertTrue(tags.length() > 0); Assert.assertTrue(tags.length() > 0);
Assert.assertEquals("Updated name", tags.getJSONObject(1).getString("name")); Assert.assertEquals("Updated name", tags.getJSONObject(1).getString("name"));
Assert.assertEquals("0000ff", tags.getJSONObject(1).getString("color"));
// Deletes a tag // Deletes a tag
tagResource = resource().path("/tag/" + tag4Id); tagResource = resource().path("/tag/" + tag4Id);