Search in sources :

Example 16 with RepositoryEntryVO

use of org.olat.restapi.support.vo.RepositoryEntryVO in project openolat by klemens.

the class RepositoryEntriesTest method testGetEntries.

@Test
public void testGetEntries() throws IOException, URISyntaxException {
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("administrator", "openolat"));
    URI request = UriBuilder.fromUri(getContextURI()).path("repo/entries").build();
    HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    InputStream body = response.getEntity().getContent();
    List<RepositoryEntryVO> entryVoes = parseRepoArray(body);
    assertNotNull(entryVoes);
    conn.shutdown();
}
Also used : RepositoryEntryVO(org.olat.restapi.support.vo.RepositoryEntryVO) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 17 with RepositoryEntryVO

use of org.olat.restapi.support.vo.RepositoryEntryVO in project openolat by klemens.

the class RepositoryEntriesTest method testImportQuestionnaire.

@Test
public void testImportQuestionnaire() throws IOException, URISyntaxException {
    URL cpUrl = RepositoryEntriesTest.class.getResource("questionnaire-demo.zip");
    assertNotNull(cpUrl);
    File cp = new File(cpUrl.toURI());
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("administrator", "openolat"));
    URI request = UriBuilder.fromUri(getContextURI()).path("repo/entries").build();
    HttpPut method = conn.createPut(request, MediaType.APPLICATION_JSON, true);
    HttpEntity entity = MultipartEntityBuilder.create().setMode(HttpMultipartMode.BROWSER_COMPATIBLE).addBinaryBody("file", cp, ContentType.APPLICATION_OCTET_STREAM, cp.getName()).addTextBody("filename", "questionnaire-demo.zip").addTextBody("resourcename", "Questionnaire demo").addTextBody("displayname", "Questionnaire demo").build();
    method.setEntity(entity);
    HttpResponse response = conn.execute(method);
    assertTrue(response.getStatusLine().getStatusCode() == 200 || response.getStatusLine().getStatusCode() == 201);
    RepositoryEntryVO vo = conn.parse(response, RepositoryEntryVO.class);
    assertNotNull(vo);
    Long key = vo.getKey();
    RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(key);
    assertNotNull(re);
    assertNotNull(re.getOlatResource());
    assertEquals("Questionnaire demo", re.getDisplayname());
    log.info(re.getOlatResource().getResourceableTypeName());
    conn.shutdown();
}
Also used : RepositoryEntryVO(org.olat.restapi.support.vo.RepositoryEntryVO) HttpEntity(org.apache.http.HttpEntity) HttpResponse(org.apache.http.HttpResponse) RepositoryEntry(org.olat.repository.RepositoryEntry) File(java.io.File) URI(java.net.URI) URL(java.net.URL) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 18 with RepositoryEntryVO

use of org.olat.restapi.support.vo.RepositoryEntryVO in project openolat by klemens.

the class RepositoryEntriesTest method testUpdateRepositoryEntry_lifecycle.

@Test
public void testUpdateRepositoryEntry_lifecycle() throws IOException, URISyntaxException {
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
    dbInstance.commitAndCloseSession();
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("administrator", "openolat"));
    RepositoryEntryVO repoVo = new RepositoryEntryVO();
    repoVo.setKey(re.getKey());
    repoVo.setDisplayname("New display name bis");
    repoVo.setExternalId("New external ID bis");
    repoVo.setExternalRef("New external ref bis");
    repoVo.setManagedFlags("all");
    RepositoryEntryLifecycleVO cycleVo = new RepositoryEntryLifecycleVO();
    cycleVo.setLabel("Cycle");
    cycleVo.setSoftkey("The secret cycle");
    cycleVo.setValidFrom(ObjectFactory.formatDate(new Date()));
    cycleVo.setValidTo(ObjectFactory.formatDate(new Date()));
    repoVo.setLifecycle(cycleVo);
    URI request = UriBuilder.fromUri(getContextURI()).path("repo/entries").path(re.getKey().toString()).build();
    HttpPost method = conn.createPost(request, MediaType.APPLICATION_JSON);
    conn.addJsonEntity(method, repoVo);
    HttpResponse response = conn.execute(method);
    assertTrue(response.getStatusLine().getStatusCode() == 200 || response.getStatusLine().getStatusCode() == 201);
    RepositoryEntryVO updatedVo = conn.parse(response, RepositoryEntryVO.class);
    assertNotNull(updatedVo);
    Assert.assertEquals("New display name bis", updatedVo.getDisplayname());
    Assert.assertEquals("New external ID bis", updatedVo.getExternalId());
    Assert.assertEquals("New external ref bis", updatedVo.getExternalRef());
    Assert.assertEquals("all", updatedVo.getManagedFlags());
    Assert.assertNotNull(updatedVo.getLifecycle());
    Assert.assertEquals("Cycle", updatedVo.getLifecycle().getLabel());
    Assert.assertEquals("The secret cycle", updatedVo.getLifecycle().getSoftkey());
    Assert.assertNotNull(updatedVo.getLifecycle().getValidFrom());
    Assert.assertNotNull(updatedVo.getLifecycle().getValidTo());
    conn.shutdown();
    RepositoryEntry reloadedRe = repositoryManager.lookupRepositoryEntry(re.getKey());
    assertNotNull(reloadedRe);
    Assert.assertEquals("New display name bis", reloadedRe.getDisplayname());
    Assert.assertEquals("New external ID bis", reloadedRe.getExternalId());
    Assert.assertEquals("New external ref bis", reloadedRe.getExternalRef());
    Assert.assertEquals("all", reloadedRe.getManagedFlagsString());
    Assert.assertNotNull(reloadedRe.getLifecycle());
    Assert.assertEquals("Cycle", reloadedRe.getLifecycle().getLabel());
    Assert.assertEquals("The secret cycle", reloadedRe.getLifecycle().getSoftKey());
    Assert.assertNotNull(reloadedRe.getLifecycle().getValidFrom());
    Assert.assertNotNull(reloadedRe.getLifecycle().getValidTo());
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) RepositoryEntryVO(org.olat.restapi.support.vo.RepositoryEntryVO) HttpResponse(org.apache.http.HttpResponse) RepositoryEntry(org.olat.repository.RepositoryEntry) RepositoryEntryLifecycleVO(org.olat.restapi.support.vo.RepositoryEntryLifecycleVO) URI(java.net.URI) Date(java.util.Date) Test(org.junit.Test)

Example 19 with RepositoryEntryVO

use of org.olat.restapi.support.vo.RepositoryEntryVO in project openolat by klemens.

the class RepositoryEntriesTest method testImportCp.

@Test
public void testImportCp() throws IOException, URISyntaxException {
    URL cpUrl = RepositoryEntriesTest.class.getResource("cp-demo.zip");
    assertNotNull(cpUrl);
    File cp = new File(cpUrl.toURI());
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("administrator", "openolat"));
    URI request = UriBuilder.fromUri(getContextURI()).path("repo/entries").build();
    HttpPut method = conn.createPut(request, MediaType.APPLICATION_JSON, true);
    HttpEntity entity = MultipartEntityBuilder.create().setMode(HttpMultipartMode.BROWSER_COMPATIBLE).addBinaryBody("file", cp, ContentType.APPLICATION_OCTET_STREAM, cp.getName()).addTextBody("filename", "cp-demo.zip").addTextBody("resourcename", "CP demo").addTextBody("displayname", "CP demo").addTextBody("access", "3").build();
    method.setEntity(entity);
    HttpResponse response = conn.execute(method);
    assertTrue(response.getStatusLine().getStatusCode() == 200 || response.getStatusLine().getStatusCode() == 201);
    RepositoryEntryVO vo = conn.parse(response, RepositoryEntryVO.class);
    assertNotNull(vo);
    Long key = vo.getKey();
    RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(key);
    assertNotNull(re);
    assertNotNull(re.getOlatResource());
    assertEquals("CP demo", re.getDisplayname());
    assertEquals(RepositoryEntry.ACC_USERS, re.getAccess());
    conn.shutdown();
}
Also used : RepositoryEntryVO(org.olat.restapi.support.vo.RepositoryEntryVO) HttpEntity(org.apache.http.HttpEntity) HttpResponse(org.apache.http.HttpResponse) RepositoryEntry(org.olat.repository.RepositoryEntry) File(java.io.File) URI(java.net.URI) URL(java.net.URL) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 20 with RepositoryEntryVO

use of org.olat.restapi.support.vo.RepositoryEntryVO in project openolat by klemens.

the class RepositoryEntriesResource method toArrayOfVOes.

private RepositoryEntryVO[] toArrayOfVOes(List<RepositoryEntry> coursRepos) {
    int i = 0;
    RepositoryEntryVO[] entryVOs = new RepositoryEntryVO[coursRepos.size()];
    for (RepositoryEntry repoE : coursRepos) {
        entryVOs[i++] = ObjectFactory.get(repoE);
    }
    return entryVOs;
}
Also used : RepositoryEntryVO(org.olat.restapi.support.vo.RepositoryEntryVO) RepositoryEntry(org.olat.repository.RepositoryEntry)

Aggregations

RepositoryEntryVO (org.olat.restapi.support.vo.RepositoryEntryVO)42 RepositoryEntry (org.olat.repository.RepositoryEntry)36 URI (java.net.URI)26 HttpResponse (org.apache.http.HttpResponse)26 Test (org.junit.Test)24 File (java.io.File)16 HttpEntity (org.apache.http.HttpEntity)14 HttpPut (org.apache.http.client.methods.HttpPut)14 URL (java.net.URL)12 Produces (javax.ws.rs.Produces)12 HttpGet (org.apache.http.client.methods.HttpGet)10 Identity (org.olat.core.id.Identity)8 Date (java.util.Date)6 GET (javax.ws.rs.GET)6 WebApplicationException (javax.ws.rs.WebApplicationException)6 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)6 RepositoryEntryLifecycleVO (org.olat.restapi.support.vo.RepositoryEntryLifecycleVO)6 Consumes (javax.ws.rs.Consumes)5 HttpPost (org.apache.http.client.methods.HttpPost)4 Roles (org.olat.core.id.Roles)4