mirror of
https://github.com/sismics/docs.git
synced 2024-11-22 05:57:57 +01:00
Tag colors (server)
This commit is contained in:
parent
1deda6e993
commit
b2ab313d11
@ -82,7 +82,7 @@ public class TagDao {
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<TagDto> getByDocumentId(String documentId) {
|
||||
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(" where dt.DOT_IDDOCUMENT_C = :documentId and t.TAG_DELETEDATE_D is null ");
|
||||
sb.append(" order by t.TAG_NAME_C ");
|
||||
@ -99,6 +99,7 @@ public class TagDao {
|
||||
TagDto tagDto = new TagDto();
|
||||
tagDto.setId((String) o[i++]);
|
||||
tagDto.setName((String) o[i++]);
|
||||
tagDto.setColor((String) o[i++]);
|
||||
tagDtoList.add(tagDto);
|
||||
}
|
||||
return tagDtoList;
|
||||
@ -112,7 +113,7 @@ public class TagDao {
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<TagStatDto> getStats(String userId) {
|
||||
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(" 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 ");
|
||||
@ -132,6 +133,7 @@ public class TagDao {
|
||||
TagStatDto tagDto = new TagStatDto();
|
||||
tagDto.setId((String) o[i++]);
|
||||
tagDto.setName((String) o[i++]);
|
||||
tagDto.setColor((String) o[i++]);
|
||||
tagDto.setCount(((Number) o[i++]).intValue());
|
||||
tagStatDtoList.add(tagDto);
|
||||
}
|
||||
|
@ -19,6 +19,11 @@ public class TagDto {
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* Color.
|
||||
*/
|
||||
private String color;
|
||||
|
||||
/**
|
||||
* Getter of id.
|
||||
*
|
||||
@ -54,4 +59,22 @@ public class TagDto {
|
||||
public void setName(String 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;
|
||||
}
|
||||
}
|
||||
|
@ -48,6 +48,12 @@ public class Tag {
|
||||
@Column(name = "TAG_DELETEDATE_D")
|
||||
private Date deleteDate;
|
||||
|
||||
/**
|
||||
* Tag name.
|
||||
*/
|
||||
@Column(name = "TAG_COLOR_C", nullable = false, length = 6)
|
||||
private String color;
|
||||
|
||||
/**
|
||||
* Getter of id.
|
||||
*
|
||||
@ -120,6 +126,24 @@ public class Tag {
|
||||
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.
|
||||
*
|
||||
|
@ -1 +1 @@
|
||||
db.version=1
|
||||
db.version=2
|
@ -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';
|
@ -1,2 +1,2 @@
|
||||
- Users administration (client)
|
||||
- Tag color (client/server)
|
||||
- Tag color (client)
|
||||
|
@ -1,3 +1,3 @@
|
||||
api.current_version=${project.version}
|
||||
api.min_version=1.0
|
||||
db.version=1
|
||||
db.version=2
|
@ -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) {
|
||||
|
@ -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
|
||||
if (!StringUtils.isEmpty(name)) {
|
||||
tag.setName(name);
|
||||
}
|
||||
if (!StringUtils.isEmpty(color)) {
|
||||
tag.setColor(color);
|
||||
}
|
||||
|
||||
JSONObject response = new JSONObject();
|
||||
response.put("id", id);
|
||||
|
@ -1,3 +1,3 @@
|
||||
api.current_version=${project.version}
|
||||
api.min_version=1.0
|
||||
db.version=1
|
||||
db.version=2
|
@ -38,6 +38,7 @@ public class TestDocumentResource extends BaseJerseyTest {
|
||||
tagResource.addFilter(new CookieAuthenticationFilter(document1Token));
|
||||
MultivaluedMapImpl postParams = new MultivaluedMapImpl();
|
||||
postParams.add("name", "Super tag");
|
||||
postParams.add("color", "ffff00");
|
||||
ClientResponse response = tagResource.put(ClientResponse.class, postParams);
|
||||
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
||||
JSONObject json = response.getEntity(JSONObject.class);
|
||||
@ -75,6 +76,7 @@ public class TestDocumentResource extends BaseJerseyTest {
|
||||
Assert.assertEquals(1, tags.length());
|
||||
Assert.assertEquals(tag1Id, tags.getJSONObject(0).getString("id"));
|
||||
Assert.assertEquals("Super tag", tags.getJSONObject(0).getString("name"));
|
||||
Assert.assertEquals("ffff00", tags.getJSONObject(0).getString("color"));
|
||||
|
||||
// Search documents by query
|
||||
documentResource = resource().path("/document/list");
|
||||
@ -141,6 +143,7 @@ public class TestDocumentResource extends BaseJerseyTest {
|
||||
tagResource.addFilter(new CookieAuthenticationFilter(document1Token));
|
||||
postParams = new MultivaluedMapImpl();
|
||||
postParams.add("name", "Super tag 2");
|
||||
postParams.add("color", "00ffff");
|
||||
response = tagResource.put(ClientResponse.class, postParams);
|
||||
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
||||
json = response.getEntity(JSONObject.class);
|
||||
|
@ -35,6 +35,7 @@ public class TestTagResource extends BaseJerseyTest {
|
||||
tagResource.addFilter(new CookieAuthenticationFilter(tag1Token));
|
||||
MultivaluedMapImpl postParams = new MultivaluedMapImpl();
|
||||
postParams.add("name", "Tag 3");
|
||||
postParams.add("color", "ff0000");
|
||||
ClientResponse response = tagResource.put(ClientResponse.class, postParams);
|
||||
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
||||
JSONObject json = response.getEntity(JSONObject.class);
|
||||
@ -46,6 +47,7 @@ public class TestTagResource extends BaseJerseyTest {
|
||||
tagResource.addFilter(new CookieAuthenticationFilter(tag1Token));
|
||||
postParams = new MultivaluedMapImpl();
|
||||
postParams.add("name", "Tag 4");
|
||||
postParams.add("color", "00ff00");
|
||||
response = tagResource.put(ClientResponse.class, postParams);
|
||||
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
||||
json = response.getEntity(JSONObject.class);
|
||||
@ -91,12 +93,15 @@ public class TestTagResource extends BaseJerseyTest {
|
||||
json = response.getEntity(JSONObject.class);
|
||||
JSONArray tags = json.getJSONArray("tags");
|
||||
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
|
||||
tagResource = resource().path("/tag/" + tag4Id);
|
||||
tagResource.addFilter(new CookieAuthenticationFilter(tag1Token));
|
||||
postParams = new MultivaluedMapImpl();
|
||||
postParams.add("name", "Updated name");
|
||||
postParams.add("color", "0000ff");
|
||||
response = tagResource.post(ClientResponse.class, postParams);
|
||||
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
||||
json = response.getEntity(JSONObject.class);
|
||||
@ -111,6 +116,7 @@ public class TestTagResource extends BaseJerseyTest {
|
||||
tags = json.getJSONArray("tags");
|
||||
Assert.assertTrue(tags.length() > 0);
|
||||
Assert.assertEquals("Updated name", tags.getJSONObject(1).getString("name"));
|
||||
Assert.assertEquals("0000ff", tags.getJSONObject(1).getString("color"));
|
||||
|
||||
// Deletes a tag
|
||||
tagResource = resource().path("/tag/" + tag4Id);
|
||||
|
Loading…
Reference in New Issue
Block a user