use of org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl in project Synapse-Repository-Services by Sage-Bionetworks.
the class Synapse method getEntityByIdForVersion.
/**
* Get a specific version of an entity using its ID an version number.
* @param entityId
* @param versionNumber
* @return the entity
* @throws SynapseException
*/
public Entity getEntityByIdForVersion(String entityId, Long versionNumber) throws SynapseException {
if (entityId == null)
throw new IllegalArgumentException("EntityId cannot be null");
String url = ENTITY_URI_PATH + "/" + entityId;
if (versionNumber != null) {
url += REPO_SUFFIX_VERSION + "/" + versionNumber;
}
JSONObject jsonObj = getEntity(url);
JSONObjectAdapter adapter = new JSONObjectAdapterImpl(jsonObj);
// Get the type from the object
if (!adapter.has("entityType"))
throw new RuntimeException("EntityType returned was null!");
try {
String entityType = adapter.getString("entityType");
Entity entity = (Entity) autoGenFactory.newInstance(entityType);
entity.initializeFromJSONObject(adapter);
return entity;
} 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 getUsers.
public PaginatedResults<UserProfile> getUsers(int offset, int limit) throws SynapseException {
String uri = "/user?" + OFFSET + "=" + offset + "&limit=" + limit;
JSONObject jsonUsers = getEntity(uri);
JSONObjectAdapter adapter = new JSONObjectAdapterImpl(jsonUsers);
PaginatedResults<UserProfile> results = new PaginatedResults<UserProfile>(UserProfile.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 getGroups.
public PaginatedResults<UserGroup> getGroups(int offset, int limit) throws SynapseException {
String uri = "/userGroup?" + OFFSET + "=" + offset + "&limit=" + limit;
JSONObject jsonUsers = getEntity(uri);
JSONObjectAdapter adapter = new JSONObjectAdapterImpl(jsonUsers);
PaginatedResults<UserGroup> results = new PaginatedResults<UserGroup>(UserGroup.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 SynapseAdministration method getAllMigratableObjectsPaginated.
public PaginatedResults<MigratableObjectData> getAllMigratableObjectsPaginated(long offset, long limit, boolean includeDependencies) throws JSONObjectAdapterException, SynapseException {
String uri = GET_ALL_BACKUP_OBJECTS + "?" + ServiceConstants.PAGINATION_OFFSET_PARAM + "=" + offset + "&" + ServiceConstants.PAGINATION_LIMIT_PARAM + "=" + limit + "&" + INCLUDE_DEPENDENCIES_PARAM + "=" + includeDependencies;
JSONObject jsonUsers = getEntity(uri);
JSONObjectAdapter adapter = new JSONObjectAdapterImpl(jsonUsers);
PaginatedResults<MigratableObjectData> results = new PaginatedResults<MigratableObjectData>(MigratableObjectData.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 RObjectTest method testRoundTripRObject.
@Test
public void testRoundTripRObject() throws JSONObjectAdapterException {
RObject l1 = new RObject();
JSONObjectAdapter adapter1 = new JSONObjectAdapterImpl();
JSONObjectAdapter adapter2 = new JSONObjectAdapterImpl();
Date d = new Date();
l1.setAccessControlList("/acl");
l1.setAnnotations("/annotations");
l1.setCreatedBy("createdBy");
l1.setCreatedOn(d);
l1.setDescription("description");
l1.setEtag("1");
l1.setId("1");
l1.setModifiedBy("modifiedBy");
l1.setModifiedOn(d);
l1.setName("name");
l1.setParentId("0");
l1.setUri("uri");
l1.setVersionComment("versionComment");
l1.setVersionLabel("versionLabel");
l1.setVersionNumber(1L);
l1.setVersionUrl("/versions/1");
l1.setVersions("/versions");
l1.setContentType("text");
l1.setMd5("01234567890123456789012345678901");
List<LocationData> ll = new ArrayList<LocationData>();
LocationData l = new LocationData();
l.setPath("path");
l.setType(LocationTypeNames.sage);
ll.add(l);
l1.setLocations(ll);
l1.setS3Token("S3token");
l1.setRObjectType("dataframe");
adapter1 = l1.writeToJSONObject(adapter1);
String s = adapter1.toJSONString();
adapter2 = new JSONObjectAdapterImpl(s);
RObject l2 = new RObject(adapter2);
assertEquals(l1, l2);
}
Aggregations