Search in sources :

Example 26 with CatalogEntryVO

use of org.olat.restapi.support.vo.CatalogEntryVO in project OpenOLAT by OpenOLAT.

the class CatalogWebService method toArray.

private CatalogEntryVO[] toArray(List<CatalogEntry> entries) {
    int count = 0;
    CatalogEntryVO[] entryVOes = new CatalogEntryVO[entries.size()];
    for (CatalogEntry entry : entries) {
        entryVOes[count++] = get(entry);
    }
    return entryVOes;
}
Also used : CatalogEntryVO(org.olat.restapi.support.vo.CatalogEntryVO) CatalogEntry(org.olat.repository.CatalogEntry)

Example 27 with CatalogEntryVO

use of org.olat.restapi.support.vo.CatalogEntryVO in project OpenOLAT by OpenOLAT.

the class CatalogTest method testPutCatalogEntryJson.

@Test
public void testPutCatalogEntryJson() throws IOException, URISyntaxException {
    RepositoryEntry re = createRepository("put-cat-entry-json", 6458438l);
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("administrator", "openolat"));
    CatalogEntryVO subEntry = new CatalogEntryVO();
    subEntry.setName("Sub-entry-1");
    subEntry.setDescription("Sub-entry-description-1");
    subEntry.setType(CatalogEntry.TYPE_NODE);
    subEntry.setRepositoryEntryKey(re.getKey());
    URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entry1.getKey().toString()).build();
    HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
    method.addHeader("Content-Type", MediaType.APPLICATION_JSON);
    conn.addJsonEntity(method, subEntry);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    CatalogEntryVO vo = conn.parse(response, CatalogEntryVO.class);
    assertNotNull(vo);
    List<CatalogEntry> children = catalogManager.getChildrenOf(entry1);
    CatalogEntry ce = null;
    for (CatalogEntry child : children) {
        if (vo.getKey().equals(child.getKey())) {
            ce = child;
            break;
        }
    }
    assertNotNull(ce);
    assertNotNull(ce.getRepositoryEntry());
    assertEquals(re.getKey(), ce.getRepositoryEntry().getKey());
    conn.shutdown();
}
Also used : CatalogEntryVO(org.olat.restapi.support.vo.CatalogEntryVO) CatalogEntry(org.olat.repository.CatalogEntry) HttpResponse(org.apache.http.HttpResponse) RepositoryEntry(org.olat.repository.RepositoryEntry) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 28 with CatalogEntryVO

use of org.olat.restapi.support.vo.CatalogEntryVO in project OpenOLAT by OpenOLAT.

the class CatalogTest method testPutCategoryQuery.

@Test
public void testPutCategoryQuery() throws IOException, URISyntaxException {
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("administrator", "openolat"));
    URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entry1.getKey().toString()).queryParam("name", "Sub-entry-2").queryParam("description", "Sub-entry-description-2").queryParam("type", String.valueOf(CatalogEntry.TYPE_NODE)).build();
    HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    CatalogEntryVO vo = conn.parse(response, CatalogEntryVO.class);
    assertNotNull(vo);
    List<CatalogEntry> children = catalogManager.getChildrenOf(entry1);
    boolean saved = false;
    for (CatalogEntry child : children) {
        if (vo.getKey().equals(child.getKey())) {
            saved = true;
            break;
        }
    }
    assertTrue(saved);
    conn.shutdown();
}
Also used : CatalogEntryVO(org.olat.restapi.support.vo.CatalogEntryVO) CatalogEntry(org.olat.repository.CatalogEntry) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 29 with CatalogEntryVO

use of org.olat.restapi.support.vo.CatalogEntryVO in project OpenOLAT by OpenOLAT.

the class CatalogTest method testMoveCatalogEntryForm.

@Test
public void testMoveCatalogEntryForm() throws IOException, URISyntaxException {
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("administrator", "openolat"));
    URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entryToMove1.getKey().toString()).build();
    HttpPost method = conn.createPost(uri, MediaType.APPLICATION_JSON);
    conn.addEntity(method, new BasicNameValuePair("newParentKey", subEntry13move.getKey().toString()));
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    CatalogEntryVO vo = conn.parse(response, CatalogEntryVO.class);
    assertNotNull(vo);
    CatalogEntry updatedEntry = catalogManager.loadCatalogEntry(entryToMove1);
    assertEquals("Entry-1-to-move", updatedEntry.getName());
    assertEquals("Entry-description-1-to-move", updatedEntry.getDescription());
    assertNotNull(updatedEntry.getParent());
    assertTrue(updatedEntry.getParent().equalsByPersistableKey(subEntry13move));
    conn.shutdown();
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) CatalogEntryVO(org.olat.restapi.support.vo.CatalogEntryVO) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) CatalogEntry(org.olat.repository.CatalogEntry) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 30 with CatalogEntryVO

use of org.olat.restapi.support.vo.CatalogEntryVO in project OpenOLAT by OpenOLAT.

the class CatalogTest method testUpdateCatalogEntryQuery.

@Test
public void testUpdateCatalogEntryQuery() throws IOException, URISyntaxException {
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("administrator", "openolat"));
    URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entry2.getKey().toString()).build();
    HttpPost method = conn.createPost(uri, MediaType.APPLICATION_JSON);
    conn.addEntity(method, new BasicNameValuePair("name", "Entry-2-b"), new BasicNameValuePair("description", "Entry-description-2-b"), new BasicNameValuePair("type", String.valueOf(CatalogEntry.TYPE_NODE)));
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    CatalogEntryVO vo = conn.parse(response, CatalogEntryVO.class);
    assertNotNull(vo);
    CatalogEntry updatedEntry = catalogManager.loadCatalogEntry(entry2);
    assertEquals("Entry-2-b", updatedEntry.getName());
    assertEquals("Entry-description-2-b", updatedEntry.getDescription());
    conn.shutdown();
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) CatalogEntryVO(org.olat.restapi.support.vo.CatalogEntryVO) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) CatalogEntry(org.olat.repository.CatalogEntry) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Aggregations

CatalogEntryVO (org.olat.restapi.support.vo.CatalogEntryVO)44 CatalogEntry (org.olat.repository.CatalogEntry)30 URI (java.net.URI)24 HttpResponse (org.apache.http.HttpResponse)24 Test (org.junit.Test)24 Produces (javax.ws.rs.Produces)16 Path (javax.ws.rs.Path)14 HttpPost (org.apache.http.client.methods.HttpPost)10 HttpPut (org.apache.http.client.methods.HttpPut)8 Consumes (javax.ws.rs.Consumes)6 GET (javax.ws.rs.GET)6 POST (javax.ws.rs.POST)6 HttpGet (org.apache.http.client.methods.HttpGet)6 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)6 RepositoryEntry (org.olat.repository.RepositoryEntry)6 InputStream (java.io.InputStream)4 PUT (javax.ws.rs.PUT)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 Identity (org.olat.core.id.Identity)4 LockResult (org.olat.core.util.coordinate.LockResult)4