Search in sources :

Example 1 with RepositoryEntryLifecycleVO

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();
}
Also used : RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) ArrayList(java.util.ArrayList) RestSecurityHelper.getRoles(org.olat.restapi.security.RestSecurityHelper.getRoles) Roles(org.olat.core.id.Roles) RepositoryEntryLifecycleVO(org.olat.restapi.support.vo.RepositoryEntryLifecycleVO) RepositoryEntryLifecycleDAO(org.olat.repository.manager.RepositoryEntryLifecycleDAO) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with RepositoryEntryLifecycleVO

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());
}
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 3 with RepositoryEntryLifecycleVO

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());
}
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 4 with RepositoryEntryLifecycleVO

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);
}
Also used : RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) InputStream(java.io.InputStream) Calendar(java.util.Calendar) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) RepositoryEntryLifecycleVO(org.olat.restapi.support.vo.RepositoryEntryLifecycleVO) URI(java.net.URI) Date(java.util.Date) Test(org.junit.Test)

Example 5 with RepositoryEntryLifecycleVO

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();
}
Also used : RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) ArrayList(java.util.ArrayList) RestSecurityHelper.getRoles(org.olat.restapi.security.RestSecurityHelper.getRoles) Roles(org.olat.core.id.Roles) RepositoryEntryLifecycleVO(org.olat.restapi.support.vo.RepositoryEntryLifecycleVO) RepositoryEntryLifecycleDAO(org.olat.repository.manager.RepositoryEntryLifecycleDAO) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

RepositoryEntryLifecycleVO (org.olat.restapi.support.vo.RepositoryEntryLifecycleVO)12 Date (java.util.Date)6 RepositoryEntryLifecycle (org.olat.repository.model.RepositoryEntryLifecycle)6 RepositoryEntryVO (org.olat.restapi.support.vo.RepositoryEntryVO)6 URI (java.net.URI)4 Produces (javax.ws.rs.Produces)4 HttpResponse (org.apache.http.HttpResponse)4 Test (org.junit.Test)4 RepositoryEntry (org.olat.repository.RepositoryEntry)4 RepositoryEntryLifecycleDAO (org.olat.repository.manager.RepositoryEntryLifecycleDAO)4 OLATResource (org.olat.resource.OLATResource)4 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 Calendar (java.util.Calendar)2 Consumes (javax.ws.rs.Consumes)2 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2 HttpGet (org.apache.http.client.methods.HttpGet)2 HttpPost (org.apache.http.client.methods.HttpPost)2 Roles (org.olat.core.id.Roles)2