From ff994ce63bc68dddc520f210d6bdf4dc6308fd0c Mon Sep 17 00:00:00 2001 From: jendib Date: Sat, 9 May 2015 16:48:01 +0200 Subject: [PATCH] #13: Disable shared status in GET /document/list (too slow) --- .../docs/core/dao/jpa/DocumentDao.java | 3 +- .../docs/rest/resource/AppResource.java | 60 ------------------- 2 files changed, 2 insertions(+), 61 deletions(-) diff --git a/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/DocumentDao.java b/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/DocumentDao.java index b6c1bb14..be276d28 100644 --- a/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/DocumentDao.java +++ b/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/DocumentDao.java @@ -157,7 +157,8 @@ public class DocumentDao { List criteriaList = new ArrayList(); StringBuilder sb = new StringBuilder("select distinct d.DOC_ID_C c0, d.DOC_TITLE_C c1, d.DOC_DESCRIPTION_C c2, d.DOC_CREATEDATE_D c3, d.DOC_LANGUAGE_C c4, "); - sb.append(" (select count(s.SHA_ID_C) from T_SHARE s, T_ACL ac where ac.ACL_SOURCEID_C = d.DOC_ID_C and ac.ACL_TARGETID_C = s.SHA_ID_C and ac.ACL_DELETEDATE_D is null and s.SHA_DELETEDATE_D is null) c5, "); + // TODO Optimize me sb.append(" (select count(s.SHA_ID_C) from T_SHARE s, T_ACL ac where ac.ACL_SOURCEID_C = d.DOC_ID_C and ac.ACL_TARGETID_C = s.SHA_ID_C and ac.ACL_DELETEDATE_D is null and s.SHA_DELETEDATE_D is null) c5, "); + sb.append(" 0 as c5, "); sb.append(" (select count(f.FIL_ID_C) from T_FILE f where f.FIL_DELETEDATE_D is null and f.FIL_IDDOC_C = d.DOC_ID_C) c6 "); sb.append(" from T_DOCUMENT d "); diff --git a/docs-web/src/main/java/com/sismics/docs/rest/resource/AppResource.java b/docs-web/src/main/java/com/sismics/docs/rest/resource/AppResource.java index 5b74078a..4d94ac10 100644 --- a/docs-web/src/main/java/com/sismics/docs/rest/resource/AppResource.java +++ b/docs-web/src/main/java/com/sismics/docs/rest/resource/AppResource.java @@ -6,8 +6,6 @@ import java.util.List; import java.util.Map; import java.util.ResourceBundle; -import javax.persistence.EntityManager; -import javax.persistence.Query; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; @@ -22,14 +20,11 @@ import org.apache.log4j.Logger; import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONObject; -import com.sismics.docs.core.constant.PermType; -import com.sismics.docs.core.dao.jpa.AclDao; import com.sismics.docs.core.dao.jpa.DocumentDao; import com.sismics.docs.core.dao.jpa.FileDao; import com.sismics.docs.core.dao.jpa.criteria.DocumentCriteria; import com.sismics.docs.core.dao.jpa.dto.DocumentDto; import com.sismics.docs.core.model.context.AppContext; -import com.sismics.docs.core.model.jpa.Acl; import com.sismics.docs.core.model.jpa.File; import com.sismics.docs.core.util.ConfigUtil; import com.sismics.docs.core.util.DirectoryUtil; @@ -39,7 +34,6 @@ import com.sismics.docs.core.util.jpa.SortCriteria; import com.sismics.docs.rest.constant.BaseFunction; import com.sismics.rest.exception.ForbiddenClientException; import com.sismics.rest.exception.ServerException; -import com.sismics.util.context.ThreadLocalContext; import com.sismics.util.log4j.LogCriteria; import com.sismics.util.log4j.LogEntry; import com.sismics.util.log4j.MemoryAppender; @@ -212,58 +206,4 @@ public class AppResource extends BaseResource { response.put("status", "ok"); return Response.ok().entity(response).build(); } - - /** - * Rebuild ACLs. - * Set Read + Write on documents' creator. - * Loose all sharing. - * - * @return Response - * @throws JSONException - */ - @POST - @Path("batch/rebuild_acls") - @Produces(MediaType.APPLICATION_JSON) - public Response batchRebuildAcls() throws JSONException { - if (!authenticate()) { - throw new ForbiddenClientException(); - } - checkBaseFunction(BaseFunction.ADMIN); - - AclDao aclDao = new AclDao(); - EntityManager em = ThreadLocalContext.get().getEntityManager(); - em.createNativeQuery("truncate table T_ACL").executeUpdate(); - em.createNativeQuery("truncate table T_SHARE").executeUpdate(); - - Query q = em.createNativeQuery("select DOC_ID_C, DOC_IDUSER_C from T_DOCUMENT"); - @SuppressWarnings("unchecked") - List l = q.getResultList(); - for (Object[] o : l) { - String documentId = (String) o[0]; - String userId = (String) o[1]; - - // Create read ACL - Acl acl = new Acl(); - acl.setPerm(PermType.READ); - acl.setSourceId(documentId); - acl.setTargetId(userId); - System.out.println(acl); - aclDao.create(acl); - - // Create write ACL - acl = new Acl(); - acl.setPerm(PermType.WRITE); - acl.setSourceId(documentId); - acl.setTargetId(userId); - System.out.println(acl); - aclDao.create(acl); - } - - int mod = em.createNativeQuery("update T_FILE set FIL_IDUSER_C = (select DOC_IDUSER_C from T_DOCUMENT where DOC_ID_C = FIL_IDDOC_C) where FIL_IDDOC_C is not null").executeUpdate(); - - JSONObject response = new JSONObject(); - response.put("status", "ok"); - response.put("file_id_user_updated", mod); - return Response.ok().entity(response).build(); - } }