Search in sources :

Example 6 with QPoolService

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

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

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

the class ExportQItemsZipResource method prepare.

@Override
public void prepare(HttpServletResponse hres) {
    try {
        hres.setCharacterEncoding(encoding);
    } catch (Exception e) {
        log.error("", e);
    }
    String label = "ExportItems";
    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);
        for (QuestionItemFull item : items) {
            qpoolService.exportItem(item, zout, locale, names);
        }
    } catch (IOException e) {
        log.error("", e);
    }
}
Also used : QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) QPoolService(org.olat.modules.qpool.QPoolService) ZipOutputStream(java.util.zip.ZipOutputStream) IOException(java.io.IOException) IOException(java.io.IOException) HashSet(java.util.HashSet)

Example 8 with QPoolService

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

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)

Example 9 with QPoolService

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

the class ExportQItemsZipResource method prepare.

@Override
public void prepare(HttpServletResponse hres) {
    try {
        hres.setCharacterEncoding(encoding);
    } catch (Exception e) {
        log.error("", e);
    }
    String label = "ExportItems";
    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);
        for (QuestionItemFull item : items) {
            qpoolService.exportItem(item, zout, locale, names);
        }
    } catch (IOException e) {
        log.error("", e);
    }
}
Also used : QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) QPoolService(org.olat.modules.qpool.QPoolService) ZipOutputStream(java.util.zip.ZipOutputStream) IOException(java.io.IOException) IOException(java.io.IOException) HashSet(java.util.HashSet)

Example 10 with QPoolService

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

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