use of org.olat.modules.qpool.QPoolService in project OpenOLAT by OpenOLAT.
the class QuestionPoolWebService method importQuestionItem.
private QuestionItemVOes importQuestionItem(Identity owner, String filename, File tmpFile, String language, Identity executor) {
Locale locale = CoreSpringFactory.getImpl(I18nManager.class).getLocaleOrDefault(language);
QPoolService qpoolService = CoreSpringFactory.getImpl(QPoolService.class);
List<QuestionItem> items = qpoolService.importItems(owner, locale, filename, tmpFile);
for (QuestionItem item : items) {
QuestionItemAuditLogBuilder builder = qpoolService.createAuditLogBuilder(executor, Action.CREATE_QUESTION_ITEM_BY_IMPORT);
builder.withAfter(item);
qpoolService.persist(builder.create());
}
QuestionItemVOes voes = new QuestionItemVOes();
QuestionItemVO[] voArray = new QuestionItemVO[items.size()];
for (int i = items.size(); i-- > 0; ) {
voArray[i] = new QuestionItemVO(items.get(i));
}
voes.setQuestionItems(voArray);
voes.setTotalCount(items.size());
return voes;
}
use of org.olat.modules.qpool.QPoolService in project OpenOLAT by OpenOLAT.
the class QuestionPoolWebService method getAuthors.
/**
* Get all authors of the question item.
*
* @response.representation.200.qname {http://www.example.com}userVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The array of authors
* @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 httpRequest The HTTP request
* @return It returns an array of <code>UserVO</code>
*/
@GET
@Path("{itemKey}/authors")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getAuthors(@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<Identity> authorList = poolService.getAuthors(item);
int count = 0;
UserVO[] authors = new UserVO[authorList.size()];
for (Identity author : authorList) {
authors[count++] = UserVOFactory.get(author);
}
return Response.ok(authors).build();
}
use of org.olat.modules.qpool.QPoolService in project openolat by klemens.
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.QPoolService in project openolat by klemens.
the class QuestionPoolWebService method getAuthors.
/**
* Get all authors of the question item.
*
* @response.representation.200.qname {http://www.example.com}userVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The array of authors
* @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 httpRequest The HTTP request
* @return It returns an array of <code>UserVO</code>
*/
@GET
@Path("{itemKey}/authors")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getAuthors(@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<Identity> authorList = poolService.getAuthors(item);
int count = 0;
UserVO[] authors = new UserVO[authorList.size()];
for (Identity author : authorList) {
authors[count++] = UserVOFactory.get(author);
}
return Response.ok(authors).build();
}
use of org.olat.modules.qpool.QPoolService in project openolat by klemens.
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