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