use of org.olat.restapi.support.vo.RepositoryEntryVO in project OpenOLAT by OpenOLAT.
the class RepositoryEntriesTest method testUpdateRepositoryEntry.
@Test
public void testUpdateRepositoryEntry() 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");
repoVo.setExternalId("New external ID");
repoVo.setExternalRef("New external ref");
repoVo.setManagedFlags("booking,delete");
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", updatedVo.getDisplayname());
Assert.assertEquals("New external ID", updatedVo.getExternalId());
Assert.assertEquals("New external ref", updatedVo.getExternalRef());
Assert.assertEquals("booking,delete", updatedVo.getManagedFlags());
conn.shutdown();
RepositoryEntry reloadedRe = repositoryManager.lookupRepositoryEntry(re.getKey());
assertNotNull(reloadedRe);
Assert.assertEquals("New display name", reloadedRe.getDisplayname());
Assert.assertEquals("New external ID", reloadedRe.getExternalId());
Assert.assertEquals("New external ref", reloadedRe.getExternalRef());
Assert.assertEquals("booking,delete", reloadedRe.getManagedFlagsString());
}
use of org.olat.restapi.support.vo.RepositoryEntryVO in project OpenOLAT by OpenOLAT.
the class RepositoryEntriesTest method testImportTest.
@Test
public void testImportTest() throws IOException, URISyntaxException {
URL cpUrl = RepositoryEntriesTest.class.getResource("qti-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", "qti-demo.zip").addTextBody("resourcename", "QTI demo").addTextBody("displayname", "QTI 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("QTI demo", re.getDisplayname());
log.info(re.getOlatResource().getResourceableTypeName());
conn.shutdown();
}
use of org.olat.restapi.support.vo.RepositoryEntryVO in project openolat by klemens.
the class ObjectFactory method get.
public static RepositoryEntryVO get(RepositoryEntry entry) {
RepositoryEntryVO vo = new RepositoryEntryVO();
vo.setKey(entry.getKey());
vo.setSoftkey(entry.getSoftkey());
vo.setResourcename(entry.getResourcename());
vo.setDisplayname(entry.getDisplayname());
vo.setDescription(entry.getDescription());
vo.setAuthors(entry.getAuthors());
vo.setLocation(entry.getLocation());
vo.setResourceableId(entry.getResourceableId());
vo.setResourceableTypeName(entry.getResourceableTypeName());
OLATResource resource = entry.getOlatResource();
if (resource != null) {
vo.setOlatResourceKey(resource.getKey());
vo.setOlatResourceId(resource.getResourceableId());
vo.setOlatResourceTypeName(resource.getResourceableTypeName());
}
vo.setExternalId(entry.getExternalId());
vo.setExternalRef(entry.getExternalRef());
vo.setManagedFlags(entry.getManagedFlagsString());
if (entry.getLifecycle() != null) {
vo.setLifecycle(new RepositoryEntryLifecycleVO(entry.getLifecycle()));
}
return vo;
}
use of org.olat.restapi.support.vo.RepositoryEntryVO in project openolat by klemens.
the class RepositoryEntriesTest method testGetEntry.
@Test
public void testGetEntry() throws IOException, URISyntaxException {
RepositoryEntry re = createRepository("Test GET repo entry");
RestConnection conn = new RestConnection();
assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("repo/entries/" + re.getKey()).build();
HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
RepositoryEntryVO entryVo = conn.parse(response, RepositoryEntryVO.class);
assertNotNull(entryVo);
conn.shutdown();
}
use of org.olat.restapi.support.vo.RepositoryEntryVO in project openolat by klemens.
the class RepositoryEntriesTest method testImportWiki.
@Test
public void testImportWiki() throws IOException, URISyntaxException {
URL cpUrl = RepositoryEntriesTest.class.getResource("wiki-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", "wiki-demo.zip").addTextBody("resourcename", "Wiki demo").addTextBody("displayname", "Wiki 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("Wiki demo", re.getDisplayname());
log.info(re.getOlatResource().getResourceableTypeName());
conn.shutdown();
}
Aggregations