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);
}
}
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);
}
}
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);
}
}
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);
}
}
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();
}
Aggregations