use of org.olat.modules.qpool.QuestionItemShort 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.QuestionItemShort 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.QuestionItemShort in project openolat by klemens.
the class QuestionPoolServiceTest method createCollection.
@Test
public void createCollection() {
// create an user with 2 items
QItemType fibType = qItemTypeDao.loadByType(QuestionType.FIB.name());
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Coll-Owner-3-" + UUID.randomUUID().toString());
QuestionItem item1 = questionDao.createAndPersist(id, "NGC 92", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, fibType);
QuestionItem item2 = questionDao.createAndPersist(id, "NGC 97", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, fibType);
dbInstance.commit();
// load the items of the collection
List<QuestionItemShort> items = new ArrayList<>();
items.add(item1);
items.add(item2);
QuestionItemCollection newColl = qpoolService.createCollection(id, "My private collection", items);
Assert.assertNotNull(newColl);
Assert.assertEquals("My private collection", newColl.getName());
// check if it's alright
dbInstance.commit();
SearchQuestionItemParams params = new SearchQuestionItemParams(id, null);
// retrieve the list of items in the collection
int numOfItemsInCollection = qpoolService.countItemsOfCollection(newColl, params);
Assert.assertEquals(2, numOfItemsInCollection);
ResultInfos<QuestionItemView> itemsOfCollection = qpoolService.getItemsOfCollection(newColl, params, 0, -1);
Assert.assertNotNull(itemsOfCollection);
Assert.assertEquals(2, itemsOfCollection.getObjects().size());
List<Long> itemKeys = new ArrayList<>();
for (QuestionItemView item : itemsOfCollection.getObjects()) {
itemKeys.add(item.getKey());
}
Assert.assertTrue(itemKeys.contains(item1.getKey()));
Assert.assertTrue(itemKeys.contains(item2.getKey()));
}
use of org.olat.modules.qpool.QuestionItemShort in project openolat by klemens.
the class MetadataBulkChangeController method formOK.
@Override
protected void formOK(UserRequest ureq) {
updatedItems = new ArrayList<>();
for (QuestionItemShort item : items) {
QuestionItem fullItem = qpoolService.loadItemById(item.getKey());
if (fullItem instanceof QuestionItemImpl) {
QuestionItemImpl itemImpl = (QuestionItemImpl) fullItem;
QuestionItemAuditLogBuilder builder = qpoolService.createAuditLogBuilder(getIdentity(), Action.UPDATE_QUESTION_ITEM_METADATA);
builder.withBefore(itemImpl);
formOKGeneral(itemImpl);
formOKQuestion(itemImpl);
formOKTechnical(itemImpl);
formOKRights(itemImpl);
QuestionItem merged = qpoolService.updateItem(itemImpl);
builder.withAfter(itemImpl);
qpoolService.persist(builder.create());
updatedItems.add(merged);
}
}
fireEvent(ureq, Event.DONE_EVENT);
}
use of org.olat.modules.qpool.QuestionItemShort in project openolat by klemens.
the class RightsMetadataEditController method event.
@Override
protected void event(UserRequest ureq, Controller source, Event event) {
if (source == groupController) {
if (event instanceof IdentitiesAddEvent) {
IdentitiesAddEvent identitiesAddedEvent = (IdentitiesAddEvent) event;
List<Identity> list = identitiesAddedEvent.getAddIdentities();
qpoolService.addAuthors(list, Collections.<QuestionItemShort>singletonList(item));
identitiesAddedEvent.getAddedIdentities().addAll(list);
} else if (event instanceof IdentitiesRemoveEvent) {
IdentitiesRemoveEvent identitiesRemoveEvent = (IdentitiesRemoveEvent) event;
List<Identity> list = identitiesRemoveEvent.getRemovedIdentities();
qpoolService.removeAuthors(list, Collections.<QuestionItemShort>singletonList(item));
}
reloadAuthors();
// cmc.deactivate();
// cleanUp();
} else if (source == cmc) {
fireEvent(ureq, new QItemEdited(item));
cleanUp();
}
super.event(ureq, source, event);
}
Aggregations