use of org.sagebionetworks.repo.model.PaginatedResults in project Synapse-Repository-Services by Sage-Bionetworks.
the class ServletTestHelper method deserializePaginatedResults.
public static <T extends JSONEntity> PaginatedResults<T> deserializePaginatedResults(String json, Class<T> clazz) {
try {
PaginatedResults<T> prs = new PaginatedResults<T>(clazz);
prs.initializeFromJSONObject(new JSONObjectAdapterImpl(json));
return prs;
} catch (JSONObjectAdapterException e) {
throw new RuntimeException(e);
}
}
use of org.sagebionetworks.repo.model.PaginatedResults in project Synapse-Repository-Services by Sage-Bionetworks.
the class EntityServiceImpl method getAllVersionsOfEntity.
@Override
public PaginatedResults<VersionInfo> getAllVersionsOfEntity(String userId, Integer offset, Integer limit, String entityId, HttpServletRequest request) throws DatastoreException, UnauthorizedException, NotFoundException {
if (offset == null) {
offset = 1;
}
if (limit == null) {
limit = 10;
}
ServiceConstants.validatePaginationParams((long) offset, (long) limit);
UserInfo userInfo = userManager.getUserInfo(userId);
QueryResults<VersionInfo> versions = entityManager.getVersionsOfEntity(userInfo, entityId, (long) offset - 1, (long) limit);
String urlPath = request.getRequestURL() == null ? "" : request.getRequestURL().toString();
return new PaginatedResults<VersionInfo>(urlPath, versions.getResults(), versions.getTotalNumberOfResults(), offset, limit, /*sort*/
null, /*descending*/
false);
}
use of org.sagebionetworks.repo.model.PaginatedResults in project Synapse-Repository-Services by Sage-Bionetworks.
the class EntityServiceImpl method getEntityReferences.
@Override
public PaginatedResults<EntityHeader> getEntityReferences(String userId, String entityId, Integer versionNumber, Integer offset, Integer limit, HttpServletRequest request) throws NotFoundException, DatastoreException {
UserInfo userInfo = userManager.getUserInfo(userId);
if (offset == null)
offset = 1;
if (limit == null)
limit = Integer.MAX_VALUE;
ServiceConstants.validatePaginationParams((long) offset, (long) limit);
QueryResults<EntityHeader> results = entityManager.getEntityReferences(userInfo, entityId, versionNumber, offset - 1, limit);
String urlPath = request.getRequestURL() == null ? "" : request.getRequestURL().toString();
return new PaginatedResults(urlPath, results.getResults(), results.getTotalNumberOfResults(), offset, limit, /*sort*/
null, /*ascending*/
true);
}
use of org.sagebionetworks.repo.model.PaginatedResults in project Synapse-Repository-Services by Sage-Bionetworks.
the class AdministrationServiceImpl method getAllBackupObjectsCounts.
/* (non-Javadoc)
* @see org.sagebionetworks.repo.web.service.AdministrationService#getAllBackupObjectsCounts(java.lang.String, java.lang.Integer, java.lang.Integer, java.lang.Boolean)
*/
@Override
public PaginatedResults<MigratableObjectCount> getAllBackupObjectsCounts(String userId) throws DatastoreException, UnauthorizedException, NotFoundException {
UserInfo userInfo = userManager.getUserInfo(userId);
if (!userInfo.isAdmin())
throw new UnauthorizedException("Only an administrator may access this service.");
QueryResults<MigratableObjectCount> queryResults = dependencyManager.getAllObjectsCounts();
PaginatedResults<MigratableObjectCount> result = new PaginatedResults<MigratableObjectCount>();
result.setResults(queryResults.getResults());
result.setTotalNumberOfResults(queryResults.getTotalNumberOfResults());
return result;
}
use of org.sagebionetworks.repo.model.PaginatedResults in project Synapse-Repository-Services by Sage-Bionetworks.
the class StorageUsageControllerTest method testItemizedUsage.
@Test
public void testItemizedUsage() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("GET");
request.addHeader("Accept", "application/json");
request.setRequestURI(UrlHelpers.STORAGE_DETAILS);
request.setParameter(AuthorizationConstants.USER_ID_PARAM, "0");
String aggregation = "storage_provider";
aggregation += ServiceConstants.AGGREGATION_DIMENSION_VALUE_SEPARATOR;
aggregation += "content_type";
request.setParameter(ServiceConstants.AGGREGATION_DIMENSION, aggregation);
MockHttpServletResponse response = new MockHttpServletResponse();
HttpServlet servlet = DispatchServletSingleton.getInstance();
servlet.service(request, response);
Assert.assertEquals(200, response.getStatus());
String jsonStr = response.getContentAsString();
JSONObjectAdapter adapter = new JSONObjectAdapterImpl(jsonStr);
PaginatedResults<StorageUsage> results = new PaginatedResults<StorageUsage>();
results.initializeFromJSONObject(adapter);
Assert.assertNotNull(results);
}
Aggregations