Search in sources :

Example 41 with QuestionItem

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();
    }
}
Also used : QuestionItemAuditLogBuilder(org.olat.modules.qpool.QuestionItemAuditLogBuilder) QuestionItem(org.olat.modules.qpool.QuestionItem)

Example 42 with QuestionItem

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()));
    }
}
Also used : QuestionItemAuditLogBuilder(org.olat.modules.qpool.QuestionItemAuditLogBuilder) File(java.io.File) QuestionItem(org.olat.modules.qpool.QuestionItem)

Example 43 with QuestionItem

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();
}
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 44 with QuestionItem

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();
}
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 45 with QuestionItem

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

Aggregations

QuestionItem (org.olat.modules.qpool.QuestionItem)260 Test (org.junit.Test)160 Identity (org.olat.core.id.Identity)122 QItemType (org.olat.modules.qpool.model.QItemType)82 QuestionItemView (org.olat.modules.qpool.QuestionItemView)76 SearchQuestionItemParams (org.olat.modules.qpool.model.SearchQuestionItemParams)54 ArrayList (java.util.ArrayList)42 File (java.io.File)32 BusinessGroup (org.olat.group.BusinessGroup)32 QuestionItemAuditLogBuilder (org.olat.modules.qpool.QuestionItemAuditLogBuilder)32 QuestionItemImpl (org.olat.modules.qpool.model.QuestionItemImpl)30 QuestionItemShort (org.olat.modules.qpool.QuestionItemShort)28 URL (java.net.URL)24 Pool (org.olat.modules.qpool.Pool)20 QuestionItem2Pool (org.olat.modules.qpool.QuestionItem2Pool)16 QuestionItemCollection (org.olat.modules.qpool.QuestionItemCollection)16 QuestionItemFull (org.olat.modules.qpool.QuestionItemFull)14 VFSContainer (org.olat.core.util.vfs.VFSContainer)12 VFSItem (org.olat.core.util.vfs.VFSItem)12 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)12