use of org.olat.restapi.support.vo.RepositoryEntryLifecycleVO in project OpenOLAT by OpenOLAT.
the class RepositoryEntryLifecycleWebService method getPublicLifeCycles.
/**
* List all public lifecycles
* @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 uriInfo The URI information
* @param httpRequest The HTTP request
* @return
*/
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getPublicLifeCycles(@Context HttpServletRequest httpRequest) {
Roles roles = getRoles(httpRequest);
if (!roles.isInstitutionalResourceManager() && !roles.isOLATAdmin()) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
RepositoryEntryLifecycleDAO lifeCycleDao = CoreSpringFactory.getImpl(RepositoryEntryLifecycleDAO.class);
List<RepositoryEntryLifecycle> publicLifeCycles = lifeCycleDao.loadPublicLifecycle();
List<RepositoryEntryLifecycleVO> voList = new ArrayList<RepositoryEntryLifecycleVO>(publicLifeCycles.size());
for (RepositoryEntryLifecycle lifeCycle : publicLifeCycles) {
voList.add(new RepositoryEntryLifecycleVO(lifeCycle));
}
RepositoryEntryLifecycleVO[] voes = voList.toArray(new RepositoryEntryLifecycleVO[voList.size()]);
return Response.ok(voes).build();
}
use of org.olat.restapi.support.vo.RepositoryEntryLifecycleVO in project OpenOLAT by OpenOLAT.
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());
}
use of org.olat.restapi.support.vo.RepositoryEntryLifecycleVO 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());
}
use of org.olat.restapi.support.vo.RepositoryEntryLifecycleVO in project openolat by klemens.
the class RepositoryEntryLifecycleTest method testGetEntries.
@Test
public void testGetEntries() throws IOException, URISyntaxException {
// create a public life cycle
RepositoryEntryLifecycle reLifeCycle = reLifeCycleDao.create("REST life cycle", "Unique", false, null, null);
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.DATE, -2);
Date from = cal.getTime();
cal.add(Calendar.DATE, 5);
Date to = cal.getTime();
RepositoryEntryLifecycle limitLifeCycle = reLifeCycleDao.create("REST life cycle", "Unique", false, from, to);
dbInstance.commitAndCloseSession();
// retrieve the public life cycles
RestConnection conn = new RestConnection();
assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("repo/lifecycle").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<RepositoryEntryLifecycleVO> entryVoes = parseRepoArray(body);
assertNotNull(entryVoes);
int found = 0;
for (RepositoryEntryLifecycleVO entryVo : entryVoes) {
if (reLifeCycle.getKey().equals(entryVo.getKey())) {
found++;
} else if (limitLifeCycle.getKey().equals(entryVo.getKey())) {
found++;
}
}
conn.shutdown();
Assert.assertEquals(2, found);
}
use of org.olat.restapi.support.vo.RepositoryEntryLifecycleVO in project openolat by klemens.
the class RepositoryEntryLifecycleWebService method getPublicLifeCycles.
/**
* List all public lifecycles
* @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 uriInfo The URI information
* @param httpRequest The HTTP request
* @return
*/
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getPublicLifeCycles(@Context HttpServletRequest httpRequest) {
Roles roles = getRoles(httpRequest);
if (!roles.isInstitutionalResourceManager() && !roles.isOLATAdmin()) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
RepositoryEntryLifecycleDAO lifeCycleDao = CoreSpringFactory.getImpl(RepositoryEntryLifecycleDAO.class);
List<RepositoryEntryLifecycle> publicLifeCycles = lifeCycleDao.loadPublicLifecycle();
List<RepositoryEntryLifecycleVO> voList = new ArrayList<RepositoryEntryLifecycleVO>(publicLifeCycles.size());
for (RepositoryEntryLifecycle lifeCycle : publicLifeCycles) {
voList.add(new RepositoryEntryLifecycleVO(lifeCycle));
}
RepositoryEntryLifecycleVO[] voes = voList.toArray(new RepositoryEntryLifecycleVO[voList.size()]);
return Response.ok(voes).build();
}
Aggregations