Search in sources :

Example 11 with JSONObjectAdapterImpl

use of org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl in project Synapse-Repository-Services by Sage-Bionetworks.

the class StorageUsageControllerTest method testAggregatedTotals.

@Test
public void testAggregatedTotals() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setMethod("GET");
    request.addHeader("Accept", "application/json");
    request.setRequestURI(UrlHelpers.STORAGE_SUMMARY + "/0");
    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);
    StorageUsageSummaryList sus = new StorageUsageSummaryList();
    sus.initializeFromJSONObject(adapter);
    Assert.assertNotNull(sus);
    Assert.assertEquals(0L, sus.getTotalSize().longValue());
    Assert.assertEquals(0, sus.getSummaryList().size());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServlet(javax.servlet.http.HttpServlet) JSONObjectAdapter(org.sagebionetworks.schema.adapter.JSONObjectAdapter) StorageUsageSummaryList(org.sagebionetworks.repo.model.storage.StorageUsageSummaryList) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) JSONObjectAdapterImpl(org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl) Test(org.junit.Test)

Example 12 with JSONObjectAdapterImpl

use of org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl 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)

Example 13 with JSONObjectAdapterImpl

use of org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl in project Synapse-Repository-Services by Sage-Bionetworks.

the class Synapse method getEntityBundle.

/**
 * Get a bundle of information about an entity in a single call.
 *
 * @param entityId
 * @param partsMask
 * @return
 * @throws SynapseException
 */
public EntityBundle getEntityBundle(String entityId, int partsMask) throws SynapseException {
    if (entityId == null)
        throw new IllegalArgumentException("EntityId cannot be null");
    String url = ENTITY_URI_PATH + "/" + entityId + ENTITY_BUNDLE_PATH + partsMask;
    JSONObject jsonObj = getEntity(url);
    JSONObjectAdapter adapter = new JSONObjectAdapterImpl(jsonObj);
    try {
        EntityBundle eb = new EntityBundle();
        eb.initializeFromJSONObject(adapter);
        return eb;
    } catch (JSONObjectAdapterException e1) {
        throw new RuntimeException(e1);
    }
}
Also used : JSONObject(org.json.JSONObject) JSONObjectAdapter(org.sagebionetworks.schema.adapter.JSONObjectAdapter) EntityBundle(org.sagebionetworks.repo.model.EntityBundle) JSONObjectAdapterException(org.sagebionetworks.schema.adapter.JSONObjectAdapterException) JSONObjectAdapterImpl(org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl)

Example 14 with JSONObjectAdapterImpl

use of org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl in project Synapse-Repository-Services by Sage-Bionetworks.

the class Synapse method getEntityVersions.

/**
 * @param entityId
 * @return
 * @throws SynapseException
 */
public PaginatedResults<VersionInfo> getEntityVersions(String entityId, int offset, int limit) throws SynapseException {
    if (entityId == null)
        throw new IllegalArgumentException("EntityId cannot be null");
    String url = ENTITY_URI_PATH + "/" + entityId + REPO_SUFFIX_VERSION + "?" + OFFSET + "=" + offset + "&limit=" + limit;
    JSONObject jsonObj = getEntity(url);
    JSONObjectAdapter adapter = new JSONObjectAdapterImpl(jsonObj);
    PaginatedResults<VersionInfo> results = new PaginatedResults<VersionInfo>(VersionInfo.class);
    try {
        results.initializeFromJSONObject(adapter);
        return results;
    } catch (JSONObjectAdapterException e) {
        throw new SynapseException(e);
    }
}
Also used : VersionInfo(org.sagebionetworks.repo.model.VersionInfo) SynapseVersionInfo(org.sagebionetworks.repo.model.versionInfo.SynapseVersionInfo) JSONObject(org.json.JSONObject) SynapseException(org.sagebionetworks.client.exceptions.SynapseException) JSONObjectAdapter(org.sagebionetworks.schema.adapter.JSONObjectAdapter) 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 15 with JSONObjectAdapterImpl

use of org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl in project Synapse-Repository-Services by Sage-Bionetworks.

the class Synapse method getAccessRequirements.

public VariableContentPaginatedResults<AccessRequirement> getAccessRequirements(String entityId) throws SynapseException {
    String uri = ENTITY + "/" + entityId + ACCESS_REQUIREMENT;
    JSONObject jsonAccessRequirements = getEntity(uri);
    JSONObjectAdapter adapter = new JSONObjectAdapterImpl(jsonAccessRequirements);
    VariableContentPaginatedResults<AccessRequirement> results = new VariableContentPaginatedResults<AccessRequirement>();
    try {
        results.initializeFromJSONObject(adapter);
        return results;
    } catch (JSONObjectAdapterException e) {
        throw new SynapseException(e);
    }
}
Also used : JSONObject(org.json.JSONObject) SynapseException(org.sagebionetworks.client.exceptions.SynapseException) JSONObjectAdapter(org.sagebionetworks.schema.adapter.JSONObjectAdapter) JSONObjectAdapterException(org.sagebionetworks.schema.adapter.JSONObjectAdapterException) VariableContentPaginatedResults(org.sagebionetworks.repo.model.VariableContentPaginatedResults) JSONObjectAdapterImpl(org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl) AccessRequirement(org.sagebionetworks.repo.model.AccessRequirement)

Aggregations

JSONObjectAdapterImpl (org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl)62 JSONObjectAdapter (org.sagebionetworks.schema.adapter.JSONObjectAdapter)49 Test (org.junit.Test)30 JSONObjectAdapterException (org.sagebionetworks.schema.adapter.JSONObjectAdapterException)24 JSONObject (org.json.JSONObject)19 ArrayList (java.util.ArrayList)15 Date (java.util.Date)12 ObjectSchema (org.sagebionetworks.schema.ObjectSchema)11 PaginatedResults (org.sagebionetworks.repo.model.PaginatedResults)10 SynapseException (org.sagebionetworks.client.exceptions.SynapseException)9 VariableContentPaginatedResults (org.sagebionetworks.repo.model.VariableContentPaginatedResults)7 EntityHeader (org.sagebionetworks.repo.model.EntityHeader)6 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)6 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)6 StringEntity (org.apache.http.entity.StringEntity)5 EntityBundle (org.sagebionetworks.repo.model.EntityBundle)5 UserProfile (org.sagebionetworks.repo.model.UserProfile)5 AccessRequirement (org.sagebionetworks.repo.model.AccessRequirement)4 Annotations (org.sagebionetworks.repo.model.Annotations)4 HttpServlet (javax.servlet.http.HttpServlet)3