diff --git a/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/TagDao.java b/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/TagDao.java index 83c97365..eb54b7e6 100644 --- a/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/TagDao.java +++ b/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/TagDao.java @@ -84,43 +84,6 @@ public class TagDao { } } - /** - * Returns stats on tags. - * - * @param userId User ID - * @return Stats by tag - */ - @SuppressWarnings("unchecked") - public List getStats(String userId) { - EntityManager em = ThreadLocalContext.get().getEntityManager(); - StringBuilder sb = new StringBuilder("select t.TAG_ID_C, t.TAG_NAME_C, t.TAG_COLOR_C, t.TAG_IDPARENT_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 and dt.DOT_DELETEDATE_D is null "); - 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(" where t.TAG_IDUSER_C = :userId and t.TAG_DELETEDATE_D is null "); - sb.append(" group by t.TAG_ID_C "); - sb.append(" order by t.TAG_NAME_C "); - - // Perform the query - Query q = em.createNativeQuery(sb.toString()); - q.setParameter("userId", userId); - List l = q.getResultList(); - - // Assemble results - List tagStatDtoList = new ArrayList<>(); - for (Object[] o : l) { - int i = 0; - TagStatDto tagDto = new TagStatDto(); - tagDto.setId((String) o[i++]); - tagDto.setName((String) o[i++]); - tagDto.setColor((String) o[i++]); - tagDto.setParentId((String) o[i++]); - tagDto.setCount(((Number) o[i]).intValue()); - tagStatDtoList.add(tagDto); - } - return tagStatDtoList; - } - /** * Creates a new tag. * 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 11eab035..8d508538 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 @@ -1,29 +1,26 @@ package com.sismics.docs.rest.resource; -import java.text.MessageFormat; -import java.util.List; +import com.sismics.docs.core.constant.PermType; +import com.sismics.docs.core.dao.jpa.AclDao; +import com.sismics.docs.core.dao.jpa.TagDao; +import com.sismics.docs.core.dao.jpa.criteria.TagCriteria; +import com.sismics.docs.core.dao.jpa.dto.TagDto; +import com.sismics.docs.core.model.jpa.Acl; +import com.sismics.docs.core.model.jpa.Tag; +import com.sismics.docs.core.util.jpa.SortCriteria; +import com.sismics.rest.exception.ClientException; +import com.sismics.rest.exception.ForbiddenClientException; +import com.sismics.rest.util.JsonUtil; +import com.sismics.rest.util.ValidationUtil; +import org.apache.commons.lang.StringUtils; import javax.json.Json; import javax.json.JsonArrayBuilder; import javax.json.JsonObjectBuilder; import javax.ws.rs.*; import javax.ws.rs.core.Response; - -import com.sismics.docs.core.constant.PermType; -import com.sismics.docs.core.dao.jpa.AclDao; -import com.sismics.docs.core.dao.jpa.criteria.TagCriteria; -import com.sismics.docs.core.dao.jpa.dto.TagDto; -import com.sismics.docs.core.model.jpa.Acl; -import com.sismics.docs.core.util.jpa.SortCriteria; -import org.apache.commons.lang.StringUtils; - -import com.sismics.docs.core.dao.jpa.TagDao; -import com.sismics.docs.core.dao.jpa.dto.TagStatDto; -import com.sismics.docs.core.model.jpa.Tag; -import com.sismics.rest.exception.ClientException; -import com.sismics.rest.exception.ForbiddenClientException; -import com.sismics.rest.util.JsonUtil; -import com.sismics.rest.util.ValidationUtil; +import java.text.MessageFormat; +import java.util.List; /** * Tag REST resources. @@ -59,36 +56,7 @@ public class TagResource extends BaseResource { .add("tags", items); return Response.ok().entity(response.build()).build(); } - - /** - * Returns stats on tags. - * - * @return Response - */ - @GET - @Path("/stats") - public Response stats() { - if (!authenticate()) { - throw new ForbiddenClientException(); - } - - TagDao tagDao = new TagDao(); - List tagStatDtoList = tagDao.getStats(principal.getId()); - JsonArrayBuilder items = Json.createArrayBuilder(); - for (TagStatDto tagStatDto : tagStatDtoList) { - items.add(Json.createObjectBuilder() - .add("id", tagStatDto.getId()) - .add("name", tagStatDto.getName()) - .add("color", tagStatDto.getColor()) - .add("parent", JsonUtil.nullable(tagStatDto.getParentId())) - .add("count", tagStatDto.getCount())); - } - - JsonObjectBuilder response = Json.createObjectBuilder() - .add("stats", items); - return Response.ok().entity(response.build()).build(); - } - + /** * Creates a new tag. * 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 f8b63729..eceac45d 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 @@ -115,15 +115,6 @@ public class TestTagResource extends BaseJerseyTest { Assert.assertEquals(1, tags.size()); Assert.assertEquals(tag4Id, tags.getJsonObject(0).getString("id")); - // Get tag stats - json = target().path("/tag/stats").request() - .cookie(TokenBasedSecurityFilter.COOKIE_NAME, tag1Token) - .get(JsonObject.class); - JsonArray stats = json.getJsonArray("stats"); - Assert.assertTrue(stats.size() == 2); - Assert.assertEquals(1, stats.getJsonObject(0).getInt("count")); - Assert.assertEquals(1, stats.getJsonObject(1).getInt("count")); - // Get all tags json = target().path("/tag/list").request() .cookie(TokenBasedSecurityFilter.COOKIE_NAME, tag1Token)