Search in sources :

Example 41 with JSONObjectAdapterImpl

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

Example 42 with JSONObjectAdapterImpl

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);
    }
}
Also used : JSONObject(org.json.JSONObject) UserProfile(org.sagebionetworks.repo.model.UserProfile) 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 43 with JSONObjectAdapterImpl

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

Example 44 with JSONObjectAdapterImpl

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);
    }
}
Also used : JSONObject(org.json.JSONObject) SynapseException(org.sagebionetworks.client.exceptions.SynapseException) JSONObjectAdapter(org.sagebionetworks.schema.adapter.JSONObjectAdapter) PaginatedResults(org.sagebionetworks.repo.model.PaginatedResults) JSONObjectAdapterException(org.sagebionetworks.schema.adapter.JSONObjectAdapterException) MigratableObjectData(org.sagebionetworks.repo.model.MigratableObjectData) JSONObjectAdapterImpl(org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl)

Example 45 with JSONObjectAdapterImpl

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);
}
Also used : JSONObjectAdapter(org.sagebionetworks.schema.adapter.JSONObjectAdapter) ArrayList(java.util.ArrayList) JSONObjectAdapterImpl(org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl) Date(java.util.Date) Test(org.junit.Test)

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