Search in sources :

Example 1 with PaginatedResults

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);
    }
}
Also used : PaginatedResults(org.sagebionetworks.repo.model.PaginatedResults) VariableContentPaginatedResults(org.sagebionetworks.repo.model.VariableContentPaginatedResults) JSONObjectAdapterException(org.sagebionetworks.schema.adapter.JSONObjectAdapterException) JSONObjectAdapterImpl(org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl)

Example 2 with PaginatedResults

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);
}
Also used : VersionInfo(org.sagebionetworks.repo.model.VersionInfo) PaginatedResults(org.sagebionetworks.repo.model.PaginatedResults) UserInfo(org.sagebionetworks.repo.model.UserInfo)

Example 3 with PaginatedResults

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);
}
Also used : EntityHeader(org.sagebionetworks.repo.model.EntityHeader) PaginatedResults(org.sagebionetworks.repo.model.PaginatedResults) UserInfo(org.sagebionetworks.repo.model.UserInfo)

Example 4 with PaginatedResults

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;
}
Also used : PaginatedResults(org.sagebionetworks.repo.model.PaginatedResults) UnauthorizedException(org.sagebionetworks.repo.model.UnauthorizedException) UserInfo(org.sagebionetworks.repo.model.UserInfo) MigratableObjectCount(org.sagebionetworks.repo.model.MigratableObjectCount)

Example 5 with PaginatedResults

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);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServlet(javax.servlet.http.HttpServlet) JSONObjectAdapter(org.sagebionetworks.schema.adapter.JSONObjectAdapter) PaginatedResults(org.sagebionetworks.repo.model.PaginatedResults) StorageUsage(org.sagebionetworks.repo.model.storage.StorageUsage) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) JSONObjectAdapterImpl(org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl) Test(org.junit.Test)

Aggregations

PaginatedResults (org.sagebionetworks.repo.model.PaginatedResults)22 JSONObjectAdapterImpl (org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl)10 UserInfo (org.sagebionetworks.repo.model.UserInfo)9 JSONObjectAdapter (org.sagebionetworks.schema.adapter.JSONObjectAdapter)9 JSONObjectAdapterException (org.sagebionetworks.schema.adapter.JSONObjectAdapterException)7 JSONObject (org.json.JSONObject)6 Test (org.junit.Test)5 SynapseException (org.sagebionetworks.client.exceptions.SynapseException)5 VariableContentPaginatedResults (org.sagebionetworks.repo.model.VariableContentPaginatedResults)5 EntityHeader (org.sagebionetworks.repo.model.EntityHeader)4 ArrayList (java.util.ArrayList)3 StringEntity (org.apache.http.entity.StringEntity)3 MigratableObjectCount (org.sagebionetworks.repo.model.MigratableObjectCount)3 MigratableObjectData (org.sagebionetworks.repo.model.MigratableObjectData)3 AccessRequirement (org.sagebionetworks.repo.model.AccessRequirement)2 UnauthorizedException (org.sagebionetworks.repo.model.UnauthorizedException)2 UserGroup (org.sagebionetworks.repo.model.UserGroup)2 UserProfile (org.sagebionetworks.repo.model.UserProfile)2 VersionInfo (org.sagebionetworks.repo.model.VersionInfo)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1