Search in sources :

Example 1 with QPoolService

use of org.olat.modules.qpool.QPoolService in project OpenOLAT by OpenOLAT.

the class QuestionPoolWebService method removeAuthor.

/**
 * Remove an author to the question item.
 *
 * @response.representation.200.doc The user was successfully removed as author of the question item
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The question item or the user not found
 * @param itemKey The question item identifier
 * @param identityKey The user identifier
 * @param httpRequest The HTTP request
 * @return It returns 200  if the user is removed as author of the question item
 */
@DELETE
@Path("{itemKey}/authors/{identityKey}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response removeAuthor(@PathParam("itemKey") Long itemKey, @PathParam("identityKey") Long identityKey, @Context HttpServletRequest httpRequest) {
    if (!isQuestionPoolManager(httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    QPoolService poolService = CoreSpringFactory.getImpl(QPoolService.class);
    QuestionItem item = poolService.loadItemById(itemKey);
    if (item == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
    Identity author = securityManager.loadIdentityByKey(identityKey, false);
    if (author == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    List<Identity> authors = Collections.singletonList(author);
    List<QuestionItemShort> items = Collections.singletonList(item);
    poolService.removeAuthors(authors, items);
    return Response.ok().build();
}
Also used : QPoolService(org.olat.modules.qpool.QPoolService) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) Identity(org.olat.core.id.Identity) QuestionItem(org.olat.modules.qpool.QuestionItem) BaseSecurity(org.olat.basesecurity.BaseSecurity) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces)

Example 2 with QPoolService

use of org.olat.modules.qpool.QPoolService in project OpenOLAT by OpenOLAT.

the class QuestionPoolWebService method addAuthor.

/**
 * Add an author to the question item.
 *
 * @response.representation.200.doc The user is an author of the question item
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The question item or the user not found
 * @param itemKey The question item identifier
 * @param identityKey The user identifier
 * @param httpRequest The HTTP request
 * @return It returns 200  if the user is added as author of the question item
 */
@PUT
@Path("{itemKey}/authors/{identityKey}")
public Response addAuthor(@PathParam("itemKey") Long itemKey, @PathParam("identityKey") Long identityKey, @Context HttpServletRequest httpRequest) {
    if (!isQuestionPoolManager(httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    QPoolService poolService = CoreSpringFactory.getImpl(QPoolService.class);
    QuestionItem item = poolService.loadItemById(itemKey);
    if (item == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
    Identity author = securityManager.loadIdentityByKey(identityKey, false);
    if (author == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    List<Identity> authors = Collections.singletonList(author);
    List<QuestionItemShort> items = Collections.singletonList(item);
    poolService.addAuthors(authors, items);
    return Response.ok().build();
}
Also used : QPoolService(org.olat.modules.qpool.QPoolService) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) Identity(org.olat.core.id.Identity) QuestionItem(org.olat.modules.qpool.QuestionItem) BaseSecurity(org.olat.basesecurity.BaseSecurity) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 3 with QPoolService

use of org.olat.modules.qpool.QPoolService in project OpenOLAT by OpenOLAT.

the class QuestionPoolWebService method getAuthor.

/**
 * Get this specific author of the quesiton item.
 *
 * @response.representation.200.qname {http://www.example.com}userVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The author
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The question item not found or the user is not an author of the course
 * @param itemKey The question item identifier
 * @param identityKey The user identifier
 * @param httpRequest The HTTP request
 * @return It returns an <code>UserVO</code>
 */
@GET
@Path("{itemKey}/authors/{identityKey}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getAuthor(@PathParam("itemKey") Long itemKey, @PathParam("identityKey") Long identityKey, @Context HttpServletRequest request) {
    if (!isQuestionPoolManager(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    QPoolService poolService = CoreSpringFactory.getImpl(QPoolService.class);
    QuestionItem item = poolService.loadItemById(itemKey);
    if (item == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    List<Identity> authorList = poolService.getAuthors(item);
    for (Identity author : authorList) {
        if (author.getKey().equals(identityKey)) {
            UserVO authorVo = UserVOFactory.get(author);
            return Response.ok(authorVo).build();
        }
    }
    return Response.serverError().status(Status.NOT_FOUND).build();
}
Also used : QPoolService(org.olat.modules.qpool.QPoolService) UserVO(org.olat.user.restapi.UserVO) Identity(org.olat.core.id.Identity) QuestionItem(org.olat.modules.qpool.QuestionItem) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with QPoolService

use of org.olat.modules.qpool.QPoolService in project OpenOLAT by OpenOLAT.

the class ExportQItemResource method prepare.

@Override
public void prepare(HttpServletResponse hres) {
    try {
        hres.setCharacterEncoding(encoding);
    } catch (Exception e) {
        log.error("", e);
    }
    String label = item.getTitle();
    String file = StringHelper.transformDisplayNameToFileSystemName(label) + ".zip";
    String encodedFileName = StringHelper.urlEncodeUTF8(file);
    hres.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + encodedFileName);
    hres.setHeader("Content-Description", encodedFileName);
    try (ZipOutputStream zout = new ZipOutputStream(hres.getOutputStream())) {
        zout.setLevel(9);
        Set<String> names = new HashSet<>();
        QPoolService qpoolService = CoreSpringFactory.getImpl(QPoolService.class);
        qpoolService.exportItem(item, zout, locale, names);
    } catch (IOException e) {
        log.error("", e);
    }
}
Also used : QPoolService(org.olat.modules.qpool.QPoolService) ZipOutputStream(java.util.zip.ZipOutputStream) IOException(java.io.IOException) IOException(java.io.IOException) HashSet(java.util.HashSet)

Example 5 with QPoolService

use of org.olat.modules.qpool.QPoolService in project openolat by klemens.

the class QuestionPoolWebService method importQuestionItem.

private QuestionItemVOes importQuestionItem(Identity owner, String filename, File tmpFile, String language, Identity executor) {
    Locale locale = CoreSpringFactory.getImpl(I18nManager.class).getLocaleOrDefault(language);
    QPoolService qpoolService = CoreSpringFactory.getImpl(QPoolService.class);
    List<QuestionItem> items = qpoolService.importItems(owner, locale, filename, tmpFile);
    for (QuestionItem item : items) {
        QuestionItemAuditLogBuilder builder = qpoolService.createAuditLogBuilder(executor, Action.CREATE_QUESTION_ITEM_BY_IMPORT);
        builder.withAfter(item);
        qpoolService.persist(builder.create());
    }
    QuestionItemVOes voes = new QuestionItemVOes();
    QuestionItemVO[] voArray = new QuestionItemVO[items.size()];
    for (int i = items.size(); i-- > 0; ) {
        voArray[i] = new QuestionItemVO(items.get(i));
    }
    voes.setQuestionItems(voArray);
    voes.setTotalCount(items.size());
    return voes;
}
Also used : Locale(java.util.Locale) QuestionItemAuditLogBuilder(org.olat.modules.qpool.QuestionItemAuditLogBuilder) QPoolService(org.olat.modules.qpool.QPoolService) QuestionItem(org.olat.modules.qpool.QuestionItem) I18nManager(org.olat.core.util.i18n.I18nManager)

Aggregations

QPoolService (org.olat.modules.qpool.QPoolService)18 QuestionItem (org.olat.modules.qpool.QuestionItem)12 Path (javax.ws.rs.Path)10 Identity (org.olat.core.id.Identity)10 Produces (javax.ws.rs.Produces)6 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 ZipOutputStream (java.util.zip.ZipOutputStream)4 DELETE (javax.ws.rs.DELETE)4 GET (javax.ws.rs.GET)4 BaseSecurity (org.olat.basesecurity.BaseSecurity)4 QuestionItemAuditLogBuilder (org.olat.modules.qpool.QuestionItemAuditLogBuilder)4 QuestionItemFull (org.olat.modules.qpool.QuestionItemFull)4 QuestionItemShort (org.olat.modules.qpool.QuestionItemShort)4 UserVO (org.olat.user.restapi.UserVO)4 Locale (java.util.Locale)2 PUT (javax.ws.rs.PUT)2 Document (org.apache.lucene.document.Document)2 IndexWriter (org.apache.lucene.index.IndexWriter)2 I18nManager (org.olat.core.util.i18n.I18nManager)2