Search in sources :

Example 1 with RepositoryEntryLifecycleDAO

use of org.olat.repository.manager.RepositoryEntryLifecycleDAO 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 RepositoryEntryLifecycleDAO

use of org.olat.repository.manager.RepositoryEntryLifecycleDAO 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)

Example 3 with RepositoryEntryLifecycleDAO

use of org.olat.repository.manager.RepositoryEntryLifecycleDAO 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 4 with RepositoryEntryLifecycleDAO

use of org.olat.repository.manager.RepositoryEntryLifecycleDAO 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)

Aggregations

Produces (javax.ws.rs.Produces)4 RepositoryEntryLifecycleDAO (org.olat.repository.manager.RepositoryEntryLifecycleDAO)4 RepositoryEntryLifecycle (org.olat.repository.model.RepositoryEntryLifecycle)4 RepositoryEntryLifecycleVO (org.olat.restapi.support.vo.RepositoryEntryLifecycleVO)4 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 Consumes (javax.ws.rs.Consumes)2 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2 Roles (org.olat.core.id.Roles)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2 RestSecurityHelper.getRoles (org.olat.restapi.security.RestSecurityHelper.getRoles)2 RepositoryEntryVO (org.olat.restapi.support.vo.RepositoryEntryVO)2