use of org.olat.restapi.support.vo.RepositoryEntryVOes in project OpenOLAT by OpenOLAT.
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);
}
}
use of org.olat.restapi.support.vo.RepositoryEntryVOes in project OpenOLAT by OpenOLAT.
the class RepositoryEntriesTest method testGetEntriesWithPaging.
@Test
public void testGetEntriesWithPaging() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
assertTrue(conn.login("administrator", "openolat"));
URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("entries").queryParam("start", "0").queryParam("limit", "25").build();
HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON + ";pagingspec=1.0", true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
RepositoryEntryVOes entryVoes = conn.parse(response, RepositoryEntryVOes.class);
assertNotNull(entryVoes);
assertNotNull(entryVoes.getRepositoryEntries());
assertTrue(entryVoes.getRepositoryEntries().length <= 25);
assertTrue(entryVoes.getTotalCount() >= entryVoes.getRepositoryEntries().length);
conn.shutdown();
}
use of org.olat.restapi.support.vo.RepositoryEntryVOes in project openolat by klemens.
the class RepositoryEntriesTest method testGetEntriesWithPaging.
@Test
public void testGetEntriesWithPaging() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
assertTrue(conn.login("administrator", "openolat"));
URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("entries").queryParam("start", "0").queryParam("limit", "25").build();
HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON + ";pagingspec=1.0", true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
RepositoryEntryVOes entryVoes = conn.parse(response, RepositoryEntryVOes.class);
assertNotNull(entryVoes);
assertNotNull(entryVoes.getRepositoryEntries());
assertTrue(entryVoes.getRepositoryEntries().length <= 25);
assertTrue(entryVoes.getTotalCount() >= entryVoes.getRepositoryEntries().length);
conn.shutdown();
}
use of org.olat.restapi.support.vo.RepositoryEntryVOes 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