Search in sources :

Example 31 with JSONObjectAdapterImpl

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

the class SynapseTest method testCreateAccessApproval.

@Test
public void testCreateAccessApproval() throws Exception {
    TermsOfUseAccessApproval aa = new TermsOfUseAccessApproval();
    aa.setEntityType(aa.getClass().getName());
    JSONObjectAdapter adapter = new JSONObjectAdapterImpl();
    aa.writeToJSONObject(adapter);
    StringEntity responseEntity = new StringEntity(adapter.toJSONString());
    when(mockResponse.getEntity()).thenReturn(responseEntity);
    synapse.createAccessApproval(aa);
}
Also used : StringEntity(org.apache.http.entity.StringEntity) JSONObjectAdapter(org.sagebionetworks.schema.adapter.JSONObjectAdapter) TermsOfUseAccessApproval(org.sagebionetworks.repo.model.TermsOfUseAccessApproval) JSONObjectAdapterImpl(org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl) Test(org.junit.Test)

Example 32 with JSONObjectAdapterImpl

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

the class SynapseTest method testGetEntityReferencedBy.

@Test
public void testGetEntityReferencedBy() throws Exception {
    Project proj2 = new Project();
    proj2.setId("5");
    proj2.setName("proj2");
    EntityHeader proj1Header = new EntityHeader();
    proj1Header.setId("id");
    proj1Header.setName("name");
    proj1Header.setType("type");
    List<EntityHeader> eHeaderList = new ArrayList<EntityHeader>();
    eHeaderList.add(proj1Header);
    PaginatedResults<EntityHeader> paginatedResult = new PaginatedResults<EntityHeader>();
    paginatedResult.setResults(eHeaderList);
    paginatedResult.setTotalNumberOfResults(1);
    paginatedResult.setPaging(new HashMap<String, String>());
    // setup mock
    JSONObjectAdapter adapter = new JSONObjectAdapterImpl();
    paginatedResult.writeToJSONObject(adapter);
    StringEntity responseEntity = new StringEntity(adapter.toJSONString());
    when(mockResponse.getEntity()).thenReturn(responseEntity);
    PaginatedResults<EntityHeader> realResults = synapse.getEntityReferencedBy(proj2);
    assertEquals(1, realResults.getTotalNumberOfResults());
    EntityHeader firstHeader = realResults.getResults().get(0);
    assertEquals(proj1Header, firstHeader);
}
Also used : Project(org.sagebionetworks.repo.model.Project) StringEntity(org.apache.http.entity.StringEntity) EntityHeader(org.sagebionetworks.repo.model.EntityHeader) PaginatedResults(org.sagebionetworks.repo.model.PaginatedResults) JSONObjectAdapter(org.sagebionetworks.schema.adapter.JSONObjectAdapter) ArrayList(java.util.ArrayList) JSONObjectAdapterImpl(org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl) Test(org.junit.Test)

Example 33 with JSONObjectAdapterImpl

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

the class SynapseTest method testCreateAccessRequirement.

@Test
public void testCreateAccessRequirement() throws Exception {
    TermsOfUseAccessRequirement ar = new TermsOfUseAccessRequirement();
    ar.setEntityType(ar.getClass().getName());
    ar.setEntityIds(new ArrayList<String>());
    ar.setAccessType(ACCESS_TYPE.DOWNLOAD);
    ar.setTermsOfUse("foo");
    JSONObjectAdapter adapter = new JSONObjectAdapterImpl();
    ar.writeToJSONObject(adapter);
    StringEntity responseEntity = new StringEntity(adapter.toJSONString());
    when(mockResponse.getEntity()).thenReturn(responseEntity);
    synapse.createAccessRequirement(ar);
}
Also used : TermsOfUseAccessRequirement(org.sagebionetworks.repo.model.TermsOfUseAccessRequirement) StringEntity(org.apache.http.entity.StringEntity) JSONObjectAdapter(org.sagebionetworks.schema.adapter.JSONObjectAdapter) JSONObjectAdapterImpl(org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl) Test(org.junit.Test)

Example 34 with JSONObjectAdapterImpl

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

the class Synapse method getUnmetAccessReqAccessRequirements.

public VariableContentPaginatedResults<AccessRequirement> getUnmetAccessReqAccessRequirements(String entityId) throws SynapseException {
    String uri = ENTITY + "/" + entityId + ACCESS_REQUIREMENT_UNFULFILLED;
    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)

Example 35 with JSONObjectAdapterImpl

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

the class Synapse method getAnnotations.

/**
 * Get the annotations for an entity.
 * @param entityId
 * @return
 * @throws SynapseException
 */
public Annotations getAnnotations(String entityId) throws SynapseException {
    String url = ENTITY_URI_PATH + "/" + entityId + "/annotations";
    JSONObject jsonObj = getEntity(url);
    JSONObjectAdapter adapter = new JSONObjectAdapterImpl(jsonObj);
    Annotations annos = new Annotations();
    try {
        annos.initializeFromJSONObject(adapter);
        return annos;
    } catch (JSONObjectAdapterException e) {
        throw new RuntimeException(e);
    }
}
Also used : Annotations(org.sagebionetworks.repo.model.Annotations) JSONObject(org.json.JSONObject) JSONObjectAdapter(org.sagebionetworks.schema.adapter.JSONObjectAdapter) 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