Search in sources :

Example 11 with QPoolService

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

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)

Example 12 with QPoolService

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

the class QuestionPoolWebService method getAuthors.

/**
 * Get all authors of the question item.
 *
 * @response.representation.200.qname {http://www.example.com}userVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The array of authors
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The question item not found
 * @param itemKey The question item identifier
 * @param httpRequest The HTTP request
 * @return It returns an array of <code>UserVO</code>
 */
@GET
@Path("{itemKey}/authors")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getAuthors(@PathParam("itemKey") Long itemKey, @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);
    int count = 0;
    UserVO[] authors = new UserVO[authorList.size()];
    for (Identity author : authorList) {
        authors[count++] = UserVOFactory.get(author);
    }
    return Response.ok(authors).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 13 with QPoolService

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

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 14 with QPoolService

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

the class QuestionPoolWebService method getAuthors.

/**
 * Get all authors of the question item.
 *
 * @response.representation.200.qname {http://www.example.com}userVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The array of authors
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The question item not found
 * @param itemKey The question item identifier
 * @param httpRequest The HTTP request
 * @return It returns an array of <code>UserVO</code>
 */
@GET
@Path("{itemKey}/authors")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getAuthors(@PathParam("itemKey") Long itemKey, @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);
    int count = 0;
    UserVO[] authors = new UserVO[authorList.size()];
    for (Identity author : authorList) {
        authors[count++] = UserVOFactory.get(author);
    }
    return Response.ok(authors).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 15 with QPoolService

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

the class QuestionPoolWebService method deleteQuestionItem.

/**
 * Delete a question item by id.
 *
 * @response.representation.200.doc Nothing
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The question item not found
 * @param itemKey The question item identifier
 * @param request The HTTP request
 * @return Nothing
 */
@DELETE
@Path("{itemKey}")
public Response deleteQuestionItem(@PathParam("itemKey") Long itemKey, @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<QuestionItem> itemToDelete = Collections.singletonList(item);
    poolService.deleteItems(itemToDelete);
    Identity identity = RestSecurityHelper.getUserRequest(request).getIdentity();
    QuestionItemAuditLogBuilder builder = poolService.createAuditLogBuilder(identity, Action.DELETE_QUESTION_ITEM);
    builder.withBefore(item);
    poolService.persist(builder.create());
    return Response.ok().build();
}
Also used : QuestionItemAuditLogBuilder(org.olat.modules.qpool.QuestionItemAuditLogBuilder) QPoolService(org.olat.modules.qpool.QPoolService) Identity(org.olat.core.id.Identity) QuestionItem(org.olat.modules.qpool.QuestionItem) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

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