Search in sources :

Example 6 with RepositoryEntryLifecycleVO

use of org.olat.restapi.support.vo.RepositoryEntryLifecycleVO in project openolat by klemens.

the class RepositoryEntryResource method updateEntry.

@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response updateEntry(@PathParam("repoEntryKey") String repoEntryKey, RepositoryEntryVO vo, @Context HttpServletRequest request) {
    if (!RestSecurityHelper.isAuthor(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    final RepositoryEntry re = lookupRepositoryEntry(repoEntryKey);
    if (re == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    RepositoryEntryLifecycle lifecycle = null;
    RepositoryEntryLifecycleVO lifecycleVo = vo.getLifecycle();
    if (lifecycleVo != null) {
        RepositoryEntryLifecycleDAO lifecycleDao = CoreSpringFactory.getImpl(RepositoryEntryLifecycleDAO.class);
        if (lifecycleVo.getKey() != null) {
            lifecycle = lifecycleDao.loadById(lifecycleVo.getKey());
            if (lifecycle.isPrivateCycle()) {
                // check date
                String fromStr = lifecycleVo.getValidFrom();
                String toStr = lifecycleVo.getValidTo();
                String label = lifecycleVo.getLabel();
                String softKey = lifecycleVo.getSoftkey();
                Date from = ObjectFactory.parseDate(fromStr);
                Date to = ObjectFactory.parseDate(toStr);
                lifecycle.setLabel(label);
                lifecycle.setSoftKey(softKey);
                lifecycle.setValidFrom(from);
                lifecycle.setValidTo(to);
            }
        } else {
            String fromStr = lifecycleVo.getValidFrom();
            String toStr = lifecycleVo.getValidTo();
            String label = lifecycleVo.getLabel();
            String softKey = lifecycleVo.getSoftkey();
            Date from = ObjectFactory.parseDate(fromStr);
            Date to = ObjectFactory.parseDate(toStr);
            lifecycle = lifecycleDao.create(label, softKey, true, from, to);
        }
    }
    RepositoryEntry reloaded = repositoryManager.setDescriptionAndName(re, vo.getDisplayname(), vo.getDescription(), vo.getLocation(), vo.getAuthors(), vo.getExternalId(), vo.getExternalRef(), vo.getManagedFlags(), lifecycle);
    RepositoryEntryVO rvo = ObjectFactory.get(reloaded);
    return Response.ok(rvo).build();
}
Also used : RepositoryEntryVO(org.olat.restapi.support.vo.RepositoryEntryVO) RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) RepositoryEntry(org.olat.repository.RepositoryEntry) RepositoryEntryLifecycleVO(org.olat.restapi.support.vo.RepositoryEntryLifecycleVO) RepositoryEntryLifecycleDAO(org.olat.repository.manager.RepositoryEntryLifecycleDAO) Date(java.util.Date) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Example 7 with RepositoryEntryLifecycleVO

use of org.olat.restapi.support.vo.RepositoryEntryLifecycleVO in project OpenOLAT by OpenOLAT.

the class RepositoryEntryResource method updateEntry.

@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response updateEntry(@PathParam("repoEntryKey") String repoEntryKey, RepositoryEntryVO vo, @Context HttpServletRequest request) {
    if (!RestSecurityHelper.isAuthor(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    final RepositoryEntry re = lookupRepositoryEntry(repoEntryKey);
    if (re == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    RepositoryEntryLifecycle lifecycle = null;
    RepositoryEntryLifecycleVO lifecycleVo = vo.getLifecycle();
    if (lifecycleVo != null) {
        RepositoryEntryLifecycleDAO lifecycleDao = CoreSpringFactory.getImpl(RepositoryEntryLifecycleDAO.class);
        if (lifecycleVo.getKey() != null) {
            lifecycle = lifecycleDao.loadById(lifecycleVo.getKey());
            if (lifecycle.isPrivateCycle()) {
                // check date
                String fromStr = lifecycleVo.getValidFrom();
                String toStr = lifecycleVo.getValidTo();
                String label = lifecycleVo.getLabel();
                String softKey = lifecycleVo.getSoftkey();
                Date from = ObjectFactory.parseDate(fromStr);
                Date to = ObjectFactory.parseDate(toStr);
                lifecycle.setLabel(label);
                lifecycle.setSoftKey(softKey);
                lifecycle.setValidFrom(from);
                lifecycle.setValidTo(to);
            }
        } else {
            String fromStr = lifecycleVo.getValidFrom();
            String toStr = lifecycleVo.getValidTo();
            String label = lifecycleVo.getLabel();
            String softKey = lifecycleVo.getSoftkey();
            Date from = ObjectFactory.parseDate(fromStr);
            Date to = ObjectFactory.parseDate(toStr);
            lifecycle = lifecycleDao.create(label, softKey, true, from, to);
        }
    }
    RepositoryEntry reloaded = repositoryManager.setDescriptionAndName(re, vo.getDisplayname(), vo.getDescription(), vo.getLocation(), vo.getAuthors(), vo.getExternalId(), vo.getExternalRef(), vo.getManagedFlags(), lifecycle);
    RepositoryEntryVO rvo = ObjectFactory.get(reloaded);
    return Response.ok(rvo).build();
}
Also used : RepositoryEntryVO(org.olat.restapi.support.vo.RepositoryEntryVO) RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) RepositoryEntry(org.olat.repository.RepositoryEntry) RepositoryEntryLifecycleVO(org.olat.restapi.support.vo.RepositoryEntryLifecycleVO) RepositoryEntryLifecycleDAO(org.olat.repository.manager.RepositoryEntryLifecycleDAO) Date(java.util.Date) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Example 8 with RepositoryEntryLifecycleVO

use of org.olat.restapi.support.vo.RepositoryEntryLifecycleVO in project OpenOLAT by OpenOLAT.

the class ObjectFactory method get.

public static CourseVO get(RepositoryEntry re, ICourse course) {
    CourseVO vo = new CourseVO();
    vo.setKey(course.getResourceableId());
    vo.setDisplayName(re.getDisplayname());
    vo.setDescription(re.getDescription());
    vo.setTitle(course.getCourseTitle());
    vo.setEditorRootNodeId(course.getEditorTreeModel().getRootNode().getIdent());
    vo.setSoftKey(re.getSoftkey());
    vo.setRepoEntryKey(re.getKey());
    OLATResource resource = re.getOlatResource();
    if (resource != null) {
        vo.setOlatResourceKey(resource.getKey());
        vo.setOlatResourceId(resource.getResourceableId());
        vo.setOlatResourceTypeName(resource.getResourceableTypeName());
    }
    vo.setAuthors(re.getAuthors());
    vo.setLocation(re.getLocation());
    vo.setExternalId(re.getExternalId());
    vo.setExternalRef(re.getExternalRef());
    vo.setManagedFlags(re.getManagedFlagsString());
    if (re.getLifecycle() != null) {
        vo.setLifecycle(new RepositoryEntryLifecycleVO(re.getLifecycle()));
    }
    return vo;
}
Also used : CourseVO(org.olat.restapi.support.vo.CourseVO) OLATResource(org.olat.resource.OLATResource) RepositoryEntryLifecycleVO(org.olat.restapi.support.vo.RepositoryEntryLifecycleVO)

Example 9 with RepositoryEntryLifecycleVO

use of org.olat.restapi.support.vo.RepositoryEntryLifecycleVO in project OpenOLAT by OpenOLAT.

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;
}
Also used : RepositoryEntryVO(org.olat.restapi.support.vo.RepositoryEntryVO) OLATResource(org.olat.resource.OLATResource) RepositoryEntryLifecycleVO(org.olat.restapi.support.vo.RepositoryEntryLifecycleVO)

Example 10 with RepositoryEntryLifecycleVO

use of org.olat.restapi.support.vo.RepositoryEntryLifecycleVO in project OpenOLAT by OpenOLAT.

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)

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