Search in sources :

Example 16 with QPoolService

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

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

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

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

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

the class QuestionItemIndexer method fullIndex.

@Override
public void fullIndex(LifeFullIndexer indexWriter) {
    QPoolService qpoolService = CoreSpringFactory.getImpl(QPoolService.class);
    QuestionItemDocumentFactory docFactory = CoreSpringFactory.getImpl(QuestionItemDocumentFactory.class);
    SearchResourceContext ctxt = new SearchResourceContext();
    IndexWriter writer = null;
    try {
        writer = indexWriter.getAndLockWriter();
        int counter = 0;
        List<QuestionItemFull> items;
        do {
            items = qpoolService.getAllItems(counter, BATCH_SIZE);
            for (QuestionItemFull item : items) {
                Document doc = docFactory.createDocument(ctxt, item);
                indexWriter.addDocument(doc, writer);
            }
            counter += items.size();
        } while (items.size() == BATCH_SIZE);
    } catch (Exception e) {
        log.error("", e);
    } finally {
        indexWriter.releaseWriter(writer);
    }
}
Also used : QuestionItemDocumentFactory(org.olat.modules.qpool.manager.QuestionItemDocumentFactory) QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) QPoolService(org.olat.modules.qpool.QPoolService) SearchResourceContext(org.olat.search.service.SearchResourceContext) IndexWriter(org.apache.lucene.index.IndexWriter) Document(org.apache.lucene.document.Document) QItemDocument(org.olat.modules.qpool.model.QItemDocument)

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