use of org.olat.restapi.support.vo.RepositoryEntryVO in project openolat by klemens.
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 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 klemens.
the class RepositoryEntriesTest method testGetEntry_managed.
@Test
public void testGetEntry_managed() throws IOException, URISyntaxException {
RepositoryEntry re = createRepository("Test GET repo entry");
re.setManagedFlagsString("all");
re = dbInstance.getCurrentEntityManager().merge(re);
dbInstance.commitAndCloseSession();
RestConnection conn = new RestConnection();
assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("repo").path("entries").queryParam("managed", "true").build();
HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
List<RepositoryEntryVO> entryVoes = parseRepoArray(response.getEntity().getContent());
Assert.assertNotNull(entryVoes);
Assert.assertFalse(entryVoes.isEmpty());
// only repo entries with managed flags
for (RepositoryEntryVO entryVo : entryVoes) {
Assert.assertNotNull(entryVo.getManagedFlags());
Assert.assertTrue(entryVo.getManagedFlags().length() > 0);
}
conn.shutdown();
}
use of org.olat.restapi.support.vo.RepositoryEntryVO in project openolat by klemens.
the class RepositoryEntriesTest method testImportBlog.
@Test
public void testImportBlog() throws IOException, URISyntaxException {
URL cpUrl = RepositoryEntriesTest.class.getResource("blog-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", "blog-demo.zip").addTextBody("resourcename", "Blog demo").addTextBody("displayname", "Blog 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("Blog 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 RepositoryEntriesResource method getEntries.
/**
* List all entries in the OLAT repository
* @response.representation.200.qname {http://www.example.com}repositoryEntryVO
* @response.representation.200.mediaType text/plain, text/html, application/xml, application/json
* @response.representation.200.doc List all entries in the repository
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_REPOENTRYVOes}
* @param start (optional)
* @param limit (optional)
* @param managed (optional)
* @param externalId External ID (optional)
* @param externalRef External reference number (optional)
* @param resourceType The resource type (CourseModule) (optional)
* @param httpRequest The HTTP request
* @param request The RESt request
* @return
*/
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getEntries(@QueryParam("start") @DefaultValue("0") Integer start, @QueryParam("limit") @DefaultValue("25") Integer limit, @QueryParam("managed") Boolean managed, @QueryParam("externalId") String externalId, @QueryParam("externalRef") String externalRef, @QueryParam("resourceType") String resourceType, @Context HttpServletRequest httpRequest, @Context Request request) {
try {
// list of courses open for everybody
Roles roles = getRoles(httpRequest);
Identity identity = getIdentity(httpRequest);
RepositoryManager rm = RepositoryManager.getInstance();
SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(identity, roles);
params.setManaged(managed);
if (StringHelper.containsNonWhitespace(externalId)) {
params.setExternalId(externalId);
}
if (StringHelper.containsNonWhitespace(externalRef)) {
params.setExternalRef(externalRef);
}
if (StringHelper.containsNonWhitespace(resourceType)) {
params.setResourceTypes(Collections.singletonList(resourceType));
}
if (MediaTypeVariants.isPaged(httpRequest, request)) {
int totalCount = rm.countGenericANDQueryWithRolesRestriction(params);
List<RepositoryEntry> res = rm.genericANDQueryWithRolesRestriction(params, start, limit, true);
RepositoryEntryVOes voes = new RepositoryEntryVOes();
voes.setRepositoryEntries(toArrayOfVOes(res));
voes.setTotalCount(totalCount);
return Response.ok(voes).build();
} else {
List<RepositoryEntry> res = rm.genericANDQueryWithRolesRestriction(params, 0, -1, false);
RepositoryEntryVO[] voes = toArrayOfVOes(res);
return Response.ok(voes).build();
}
} catch (Exception e) {
throw new WebApplicationException(e);
}
}
Aggregations