use of org.olat.modules.qpool.QuestionItem in project OpenOLAT by OpenOLAT.
the class QuestionPoolMainEditorController method doCopyToMy.
private void doCopyToMy(QuestionItemShort item) {
List<QuestionItem> copiedItems = qpoolService.copyItems(getIdentity(), singletonList(item));
for (QuestionItem copy : copiedItems) {
QuestionItemAuditLogBuilder builder = qpoolService.createAuditLogBuilder(getIdentity(), Action.CREATE_QUESTION_ITEM_BY_COPY);
builder.withAfter(copy);
qpoolService.persist(builder.create());
}
showInfo("item.copied", Integer.toString(copiedItems.size()));
if (currentCtrl instanceof QuestionsController) {
((QuestionsController) currentCtrl).updateSource();
}
}
use of org.olat.modules.qpool.QuestionItem in project OpenOLAT by OpenOLAT.
the class ImportController method formOK.
@Override
protected void formOK(UserRequest ureq) {
String filename = fileEl.getUploadFileName();
File file = fileEl.getUploadFile();
List<QuestionItem> importItems = qpoolService.importItems(getIdentity(), getLocale(), filename, file);
if (importItems == null || importItems.isEmpty()) {
fireEvent(ureq, Event.DONE_EVENT);
showWarning("import.failed");
} else {
boolean editable = editableEl == null ? true : editableEl.isSelected(0);
source.postImport(importItems, editable);
for (QuestionItem item : importItems) {
QuestionItemAuditLogBuilder builder = qpoolService.createAuditLogBuilder(getIdentity(), Action.CREATE_QUESTION_ITEM_BY_IMPORT);
builder.withAfter(item);
qpoolService.persist(builder.create());
}
fireEvent(ureq, Event.DONE_EVENT);
showInfo("import.success", Integer.toString(importItems.size()));
}
}
use of org.olat.modules.qpool.QuestionItem 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();
}
use of org.olat.modules.qpool.QuestionItem 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();
}
use of org.olat.modules.qpool.QuestionItem 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();
}
Aggregations