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());
}
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);
}
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);
}
}
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);
}
}
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);
}
}
Aggregations