use of org.olat.modules.qpool.QPoolService 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.QPoolService 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.QPoolService 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();
}
use of org.olat.modules.qpool.QPoolService in project OpenOLAT by OpenOLAT.
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 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;
}
Aggregations