Document count in GET /app, TODO

This commit is contained in:
jendib 2013-08-01 13:36:15 +02:00
parent 4d50b220a2
commit 9e5459cafe
4 changed files with 56 additions and 17 deletions

View File

@ -1,2 +1,3 @@
- Server side reordering files - Reordering files (server)
- GET /app/stats to display general data (server/client) - GET /app/stats to display general data (server/client)
- User settings

View File

@ -17,9 +17,13 @@ import org.apache.log4j.Logger;
import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONObject;
import com.sismics.docs.core.dao.jpa.DocumentDao;
import com.sismics.docs.core.dao.jpa.criteria.DocumentCriteria;
import com.sismics.docs.core.dao.jpa.dto.DocumentDto;
import com.sismics.docs.core.util.ConfigUtil; import com.sismics.docs.core.util.ConfigUtil;
import com.sismics.docs.core.util.jpa.PaginatedList; import com.sismics.docs.core.util.jpa.PaginatedList;
import com.sismics.docs.core.util.jpa.PaginatedLists; import com.sismics.docs.core.util.jpa.PaginatedLists;
import com.sismics.docs.core.util.jpa.SortCriteria;
import com.sismics.docs.rest.constant.BaseFunction; import com.sismics.docs.rest.constant.BaseFunction;
import com.sismics.rest.exception.ForbiddenClientException; import com.sismics.rest.exception.ForbiddenClientException;
import com.sismics.rest.exception.ServerException; import com.sismics.rest.exception.ServerException;
@ -42,16 +46,32 @@ public class AppResource extends BaseResource {
*/ */
@GET @GET
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response version() throws JSONException { public Response info() throws JSONException {
if (!authenticate()) {
throw new ForbiddenClientException();
}
ResourceBundle configBundle = ConfigUtil.getConfigBundle(); ResourceBundle configBundle = ConfigUtil.getConfigBundle();
String currentVersion = configBundle.getString("api.current_version"); String currentVersion = configBundle.getString("api.current_version");
String minVersion = configBundle.getString("api.min_version"); String minVersion = configBundle.getString("api.min_version");
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
// Specific data
DocumentDao documentDao = new DocumentDao();
PaginatedList<DocumentDto> paginatedList = PaginatedLists.create(1, 0);
SortCriteria sortCriteria = new SortCriteria(0, true);
DocumentCriteria documentCriteria = new DocumentCriteria();
documentCriteria.setUserId(principal.getId());
documentDao.findByCriteria(paginatedList, documentCriteria, sortCriteria);
response.put("document_count", paginatedList.getResultCount());
// General data
response.put("current_version", currentVersion.replace("-SNAPSHOT", "")); response.put("current_version", currentVersion.replace("-SNAPSHOT", ""));
response.put("min_version", minVersion); response.put("min_version", minVersion);
response.put("total_memory", Runtime.getRuntime().totalMemory()); response.put("total_memory", Runtime.getRuntime().totalMemory());
response.put("free_memory", Runtime.getRuntime().freeMemory()); response.put("free_memory", Runtime.getRuntime().freeMemory());
return Response.ok().entity(response).build(); return Response.ok().entity(response).build();
} }

View File

@ -1,3 +1,4 @@
// Documents list
.table-documents { .table-documents {
thead th { thead th {
cursor: pointer; cursor: pointer;
@ -9,6 +10,7 @@
} }
} }
// File thumbnails
.thumbnail-file { .thumbnail-file {
cursor: pointer; cursor: pointer;
} }
@ -21,6 +23,7 @@
overflow: visible; overflow: visible;
} }
// Fields bound to datepicker
input[readonly][datepicker-popup] { input[readonly][datepicker-popup] {
cursor: pointer; cursor: pointer;
} }
@ -29,21 +32,30 @@ input[readonly][datepicker-popup] {
.inline-edit { .inline-edit {
cursor: pointer; cursor: pointer;
display: block; display: block;
}
.inline-edit span { span {
display: block; display: block;
} }
.inline-edit input { input {
display: none; display: none;
margin-bottom: 0; margin-bottom: 0;
} }
.inline-edit.active span { &.active {
span {
display: none; display: none;
} }
.inline-edit.active input { input {
display: inline-block; display: inline-block;
} }
}
}
// Pagination
.pagination {
ul > li {
cursor: pointer;
}
}

View File

@ -26,8 +26,13 @@ public class TestAppResource extends BaseJerseyTest {
*/ */
@Test @Test
public void testAppResource() throws JSONException { public void testAppResource() throws JSONException {
// Login app1
clientUtil.createUser("app1");
String app1Token = clientUtil.login("app1");
// Check the application info // Check the application info
WebResource appResource = resource().path("/app"); WebResource appResource = resource().path("/app");
appResource.addFilter(new CookieAuthenticationFilter(app1Token));
ClientResponse response = appResource.get(ClientResponse.class); ClientResponse response = appResource.get(ClientResponse.class);
response = appResource.get(ClientResponse.class); response = appResource.get(ClientResponse.class);
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus())); Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
@ -40,6 +45,7 @@ public class TestAppResource extends BaseJerseyTest {
Assert.assertTrue(freeMemory > 0); Assert.assertTrue(freeMemory > 0);
Long totalMemory = json.getLong("total_memory"); Long totalMemory = json.getLong("total_memory");
Assert.assertTrue(totalMemory > 0 && totalMemory > freeMemory); Assert.assertTrue(totalMemory > 0 && totalMemory > freeMemory);
Assert.assertEquals(0, json.getInt("document_count"));
} }
/** /**