Search in sources :

Example 36 with JSONObjectAdapterImpl

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

the class Synapse method search.

public SearchResults search(SearchQuery searchQuery) throws SynapseException, UnsupportedEncodingException, JSONObjectAdapterException {
    SearchResults searchResults = null;
    String uri = "/search";
    String jsonBody = EntityFactory.createJSONStringForEntity(searchQuery);
    JSONObject obj = signAndDispatchSynapseRequest(repoEndpoint, uri, "POST", jsonBody, defaultPOSTPUTHeaders);
    if (obj != null) {
        JSONObjectAdapter adapter = new JSONObjectAdapterImpl(obj);
        searchResults = new SearchResults(adapter);
    }
    return searchResults;
}
Also used : JSONObject(org.json.JSONObject) JSONObjectAdapter(org.sagebionetworks.schema.adapter.JSONObjectAdapter) SearchResults(org.sagebionetworks.repo.model.search.SearchResults) JSONObjectAdapterImpl(org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl)

Example 37 with JSONObjectAdapterImpl

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

the class Synapse method getEntityTypeBatch.

public BatchResults<EntityHeader> getEntityTypeBatch(List<String> entityIds) throws SynapseException {
    // TODO move UrlHelpers someplace shared so that we can UrlHelpers.ENTITY_TYPE
    String url = ENTITY_URI_PATH + "/type";
    url += "?" + ServiceConstants.BATCH_PARAM + "=" + StringUtils.join(entityIds, ServiceConstants.BATCH_PARAM_VALUE_SEPARATOR);
    JSONObject jsonObj = getEntity(url);
    JSONObjectAdapter adapter = new JSONObjectAdapterImpl(jsonObj);
    BatchResults<EntityHeader> results = new BatchResults<EntityHeader>(EntityHeader.class);
    try {
        results.initializeFromJSONObject(adapter);
        return results;
    } catch (JSONObjectAdapterException e) {
        throw new RuntimeException(e);
    }
}
Also used : EntityHeader(org.sagebionetworks.repo.model.EntityHeader) JSONObject(org.json.JSONObject) JSONObjectAdapter(org.sagebionetworks.schema.adapter.JSONObjectAdapter) JSONObjectAdapterException(org.sagebionetworks.schema.adapter.JSONObjectAdapterException) BatchResults(org.sagebionetworks.repo.model.BatchResults) JSONObjectAdapterImpl(org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl)

Example 38 with JSONObjectAdapterImpl

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

the class Synapse method getUsersEntityPermissions.

/**
 * Get the current user's permission for a given entity.
 * @param entityId
 * @return
 * @throws SynapseException
 */
public UserEntityPermissions getUsersEntityPermissions(String entityId) throws SynapseException {
    String url = ENTITY_URI_PATH + "/" + entityId + "/permissions";
    JSONObject jsonObj = getEntity(url);
    JSONObjectAdapter adapter = new JSONObjectAdapterImpl(jsonObj);
    UserEntityPermissions uep = new UserEntityPermissions();
    try {
        uep.initializeFromJSONObject(adapter);
        return uep;
    } 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) JSONObjectAdapterImpl(org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl) UserEntityPermissions(org.sagebionetworks.repo.model.auth.UserEntityPermissions)

Example 39 with JSONObjectAdapterImpl

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

the class Synapse method getEntityPath.

/**
 * Get the hierarchical path to this entity via its id and urlPrefix
 * @param entityId
 * @param urlPrefix
 * @return
 * @throws SynapseException
 */
public EntityPath getEntityPath(String entityId) throws SynapseException {
    String url = ENTITY_URI_PATH + "/" + entityId + "/path";
    JSONObject jsonObj = getEntity(url);
    JSONObjectAdapter adapter = new JSONObjectAdapterImpl(jsonObj);
    EntityPath path = new EntityPath();
    try {
        path.initializeFromJSONObject(adapter);
        return path;
    } catch (JSONObjectAdapterException e) {
        throw new RuntimeException(e);
    }
}
Also used : EntityPath(org.sagebionetworks.repo.model.EntityPath) 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 40 with JSONObjectAdapterImpl

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

the class Synapse method getEntityReferencedBy.

/**
 * Get the hierarchical path to this entity via its id and urlPrefix
 * @param entityId
 * @param urlPrefix
 * @return
 * @throws SynapseException
 */
public PaginatedResults<EntityHeader> getEntityReferencedBy(String entityId, String targetVersion) throws SynapseException {
    String url = ENTITY_URI_PATH + "/" + entityId;
    if (targetVersion != null) {
        url += "/version/" + targetVersion;
    }
    url += "/referencedby";
    JSONObject jsonObj = getEntity(url);
    JSONObjectAdapter adapter = new JSONObjectAdapterImpl(jsonObj);
    PaginatedResults<EntityHeader> results = new PaginatedResults<EntityHeader>(EntityHeader.class);
    try {
        results.initializeFromJSONObject(adapter);
        return results;
    } catch (JSONObjectAdapterException e) {
        throw new RuntimeException(e);
    }
}
Also used : EntityHeader(org.sagebionetworks.repo.model.EntityHeader) JSONObject(org.json.JSONObject) 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)

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