use of org.olat.repository.RepositoryService in project OpenOLAT by OpenOLAT.
the class RepositoryEntryResource method deleteCourse.
/**
* Delete a resource by id
*
* @response.representation.200.doc The metadatas of the deleted resource
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The course not found
* @param courseId The course resourceable's id
* @param request The HTTP request
* @return It returns the XML representation of the <code>Structure</code>
* object representing the course.
*/
@DELETE
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response deleteCourse(@PathParam("repoEntryKey") String repoEntryKey, @Context HttpServletRequest request) {
if (!isAuthor(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
RepositoryEntry re = lookupRepositoryEntry(repoEntryKey);
if (re == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
} else if (!isAuthorEditor(re, request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
UserRequest ureq = getUserRequest(request);
RepositoryService rs = CoreSpringFactory.getImpl(RepositoryService.class);
ErrorList errors = rs.deletePermanently(re, ureq.getIdentity(), ureq.getUserSession().getRoles(), ureq.getLocale());
if (errors.hasErrors()) {
return Response.serverError().status(500).build();
}
ThreadLocalUserActivityLogger.log(LearningResourceLoggingAction.LEARNING_RESOURCE_DELETE, getClass(), LoggingResourceable.wrap(re, OlatResourceableType.genRepoEntry));
return Response.ok().build();
}
use of org.olat.repository.RepositoryService in project OpenOLAT by OpenOLAT.
the class GroupFoldersTest method setUp.
/**
* Set up a course with learn group and group area
* EXACTLY THE SAME AS GroupMgmTest
* @see org.olat.test.OlatJerseyTestCase#setUp()
*/
@Before
@Override
public void setUp() throws Exception {
super.setUp();
conn = new RestConnection();
// create a course with learn group
owner1 = JunitTestHelper.createAndPersistIdentityAsUser("rest-one");
owner2 = JunitTestHelper.createAndPersistIdentityAsUser("rest-two");
part1 = JunitTestHelper.createAndPersistIdentityAsUser("rest-four");
part2 = JunitTestHelper.createAndPersistIdentityAsUser("rest-five");
// create course and persist as OLATResourceImpl
OLATResourceable resourceable = OresHelper.createOLATResourceableInstance("junitcourse", System.currentTimeMillis());
course = OLATResourceManager.getInstance().findOrPersistResourceable(resourceable);
RepositoryService rs = CoreSpringFactory.getImpl(RepositoryService.class);
RepositoryEntry re = rs.create("administrator", "-", "rest-re", null, course);
repositoryService.update(re);
DBFactory.getInstance().commit();
// create learn group
// 1) context one: learning groups
RepositoryEntry c1 = JunitTestHelper.createAndPersistRepositoryEntry();
// create groups without waiting list
g1 = businessGroupService.createBusinessGroup(null, "rest-g1", null, 0, 10, false, false, c1);
g2 = businessGroupService.createBusinessGroup(null, "rest-g2", null, 0, 10, false, false, c1);
DBFactory.getInstance().commitAndCloseSession();
// permission to see owners and participants
businessGroupService.updateDisplayMembers(g1, false, false, false, false, false, false, false);
businessGroupService.updateDisplayMembers(g2, true, true, false, false, false, false, false);
// members g1
businessGroupRelationDao.addRole(owner1, g1, GroupRoles.coach.name());
businessGroupRelationDao.addRole(owner2, g1, GroupRoles.coach.name());
businessGroupRelationDao.addRole(part1, g1, GroupRoles.participant.name());
businessGroupRelationDao.addRole(part2, g1, GroupRoles.participant.name());
// members g2
businessGroupRelationDao.addRole(owner1, g2, GroupRoles.coach.name());
businessGroupRelationDao.addRole(part1, g2, GroupRoles.participant.name());
// 3) collaboration tools
CollaborationTools collabTools1 = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(g1);
collabTools1.setToolEnabled(CollaborationTools.TOOL_FOLDER, true);
CollaborationTools collabTools2 = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(g2);
collabTools2.setToolEnabled(CollaborationTools.TOOL_FOLDER, true);
// simulate user clicks
DBFactory.getInstance().commitAndCloseSession();
}
use of org.olat.repository.RepositoryService in project OpenOLAT by OpenOLAT.
the class ContactsTest method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
if (initialized)
return;
// create a course with learn group
owner1 = JunitTestHelper.createAndPersistIdentityAsUser("rest-contacts-one");
owner2 = JunitTestHelper.createAndPersistIdentityAsUser("rest-contacts-two");
owner3 = JunitTestHelper.createAndPersistIdentityAsUser("rest-contacts-three");
part1 = JunitTestHelper.createAndPersistIdentityAsUser("rest-contacts-four");
part2 = JunitTestHelper.createAndPersistIdentityAsUser("rest-contacts-five");
part3 = JunitTestHelper.createAndPersistIdentityAsUser("rest-contacts-six");
// create course and persist as OLATResourceImpl
OLATResourceable resourceable = OresHelper.createOLATResourceableInstance("junitcourse", System.currentTimeMillis());
course = OLATResourceManager.getInstance().findOrPersistResourceable(resourceable);
RepositoryService rs = CoreSpringFactory.getImpl(RepositoryService.class);
RepositoryEntry re = rs.create("administrator", "-", "rest-re", null, course);
rs.update(re);
DBFactory.getInstance().commit();
// create learn group
// 1) context one: learning groups
RepositoryEntry c1 = JunitTestHelper.createAndPersistRepositoryEntry();
// create groups without waiting list
g1 = businessGroupService.createBusinessGroup(null, "rest-g1", null, 0, 10, false, false, c1);
g2 = businessGroupService.createBusinessGroup(null, "rest-g2", null, 0, 10, false, false, c1);
DBFactory.getInstance().commit();
// permission to see owners and participants
businessGroupService.updateDisplayMembers(g1, false, false, false, false, false, false, false);
businessGroupService.updateDisplayMembers(g2, true, true, false, false, false, false, false);
// members g1
businessGroupRelationDao.addRole(owner1, g1, GroupRoles.coach.name());
businessGroupRelationDao.addRole(owner2, g1, GroupRoles.coach.name());
businessGroupRelationDao.addRole(part1, g1, GroupRoles.participant.name());
businessGroupRelationDao.addRole(part2, g1, GroupRoles.participant.name());
// members g2
businessGroupRelationDao.addRole(owner1, g2, GroupRoles.coach.name());
businessGroupRelationDao.addRole(part1, g2, GroupRoles.participant.name());
// 2) context two: right groups
RepositoryEntry c2 = JunitTestHelper.createAndPersistRepositoryEntry();
// groups
g3 = businessGroupService.createBusinessGroup(null, "rest-g3", null, -1, -1, false, false, c2);
g4 = businessGroupService.createBusinessGroup(null, "rest-g4", null, -1, -1, false, false, c2);
DBFactory.getInstance().commit();
businessGroupService.updateDisplayMembers(g3, false, true, false, false, false, false, false);
businessGroupService.updateDisplayMembers(g4, false, true, false, false, false, false, false);
// members -> default participants are visible
businessGroupRelationDao.addRole(owner1, g3, GroupRoles.participant.name());
businessGroupRelationDao.addRole(part3, g3, GroupRoles.participant.name());
businessGroupRelationDao.addRole(owner2, g4, GroupRoles.participant.name());
businessGroupRelationDao.addRole(part3, g4, GroupRoles.participant.name());
// simulate user clicks
DBFactory.getInstance().commitAndCloseSession();
initialized = true;
}
use of org.olat.repository.RepositoryService in project OpenOLAT by OpenOLAT.
the class MembersPeekViewController method readFormData.
protected void readFormData(ModuleConfiguration config) {
CourseGroupManager cgm = courseEnv.getCourseGroupManager();
RepositoryEntry courseRepositoryEntry = courseEnv.getCourseGroupManager().getCourseEntry();
List<Identity> owners = MembersHelpers.getOwners(repositoryService, courseRepositoryEntry);
List<Identity> coaches = new ArrayList<>();
MembersHelpers.addCoaches(config, cgm, businessGroupService, coaches);
List<Identity> participants = new ArrayList<>();
MembersHelpers.addParticipants(config, cgm, businessGroupService, participants);
Set<Long> duplicateCatcher = new HashSet<Long>();
List<Identity> filteredOwners = owners.stream().filter(ident -> {
if (duplicateCatcher.contains(ident.getKey())) {
return false;
}
duplicateCatcher.add(ident.getKey());
return true;
}).collect(Collectors.toList());
List<Identity> filteredCoaches = coaches.stream().filter(ident -> {
if (duplicateCatcher.contains(ident.getKey())) {
return false;
}
duplicateCatcher.add(ident.getKey());
return true;
}).collect(Collectors.toList());
List<Identity> filteredParticipants = participants.stream().filter(ident -> {
if (duplicateCatcher.contains(ident.getKey())) {
return false;
}
duplicateCatcher.add(ident.getKey());
return true;
}).collect(Collectors.toList());
entries.add(new Row(translate("members.owners"), Integer.toString(filteredOwners.size())));
entries.add(new Row(translate("members.coaches"), Integer.toString(filteredCoaches.size())));
entries.add(new Row(translate("members.participants"), Integer.toString(filteredParticipants.size())));
}
use of org.olat.repository.RepositoryService in project OpenOLAT by OpenOLAT.
the class GroupMgmtTest method setUp.
/**
* Set up a course with learn group and group area
* @see org.olat.test.OlatJerseyTestCase#setUp()
*/
@Before
@Override
public void setUp() throws Exception {
super.setUp();
conn = new RestConnection();
// create a course with learn group
owner1 = JunitTestHelper.createAndPersistIdentityAsUser("rest-one");
owner2 = JunitTestHelper.createAndPersistIdentityAsUser("rest-two");
owner3 = JunitTestHelper.createAndPersistIdentityAsUser("rest-three");
part1 = JunitTestHelper.createAndPersistIdentityAsUser("rest-four");
part2 = JunitTestHelper.createAndPersistIdentityAsUser("rest-five");
part3 = JunitTestHelper.createAndPersistIdentityAsUser("rest-six");
OLATResourceManager rm = OLATResourceManager.getInstance();
// create course and persist as OLATResourceImpl
OLATResourceable resourceable = OresHelper.createOLATResourceableInstance("junitcourse", System.currentTimeMillis());
course = rm.findOrPersistResourceable(resourceable);
RepositoryService rs = CoreSpringFactory.getImpl(RepositoryService.class);
RepositoryEntry re = rs.create("administrator", "-", "rest-re", null, course);
DBFactory.getInstance().commit();
assertNotNull(re);
// create learn group
// 1) context one: learning groups
RepositoryEntry c1 = JunitTestHelper.createAndPersistRepositoryEntry();
// create groups without waiting list
g1 = businessGroupService.createBusinessGroup(null, "rest-g1", null, 0, 10, false, false, c1);
g2 = businessGroupService.createBusinessGroup(null, "rest-g2", null, 0, 10, false, false, c1);
DBFactory.getInstance().commit();
// permission to see owners and participants
businessGroupService.updateDisplayMembers(g1, false, false, false, false, false, false, false);
businessGroupService.updateDisplayMembers(g2, true, true, false, false, false, false, false);
// members g1
businessGroupRelationDao.addRole(owner1, g1, GroupRoles.coach.name());
businessGroupRelationDao.addRole(owner2, g1, GroupRoles.coach.name());
businessGroupRelationDao.addRole(part1, g1, GroupRoles.participant.name());
businessGroupRelationDao.addRole(part2, g1, GroupRoles.participant.name());
// members g2
businessGroupRelationDao.addRole(owner1, g2, GroupRoles.coach.name());
businessGroupRelationDao.addRole(part1, g2, GroupRoles.participant.name());
// 2) context two: right groups
RepositoryEntry c2 = JunitTestHelper.createAndPersistRepositoryEntry();
// groups
g3 = businessGroupService.createBusinessGroup(null, "rest-g3", null, -1, -1, false, false, c2);
g4 = businessGroupService.createBusinessGroup(null, "rest-g4", null, -1, -1, false, false, c2);
DBFactory.getInstance().commit();
// members
businessGroupRelationDao.addRole(owner1, g3, GroupRoles.participant.name());
businessGroupRelationDao.addRole(owner2, g4, GroupRoles.participant.name());
// 3) collaboration tools
CollaborationTools collabTools1 = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(g1);
collabTools1.setToolEnabled(CollaborationTools.TOOL_FORUM, true);
collabTools1.setToolEnabled(CollaborationTools.TOOL_WIKI, true);
collabTools1.saveNews("<p>Hello world</p>");
try {
collabTools1.createForumController(null, null, true, false, null);
} catch (Exception e) {
// will fail but generate the forum key
}
CollaborationTools collabTools2 = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(g2);
collabTools2.setToolEnabled(CollaborationTools.TOOL_FORUM, true);
// simulate user clicks
DBFactory.getInstance().closeSession();
// 4) fill forum for g1
NarrowedPropertyManager npm = NarrowedPropertyManager.getInstance(g1);
Property forumKeyProperty = npm.findProperty(null, null, CollaborationTools.PROP_CAT_BG_COLLABTOOLS, CollaborationTools.KEY_FORUM);
ForumManager fm = ForumManager.getInstance();
Forum forum = fm.loadForum(forumKeyProperty.getLongValue());
m1 = fm.createMessage(forum, owner1, false);
m1.setTitle("Thread-1");
m1.setBody("Body of Thread-1");
fm.addTopMessage(m1);
m2 = fm.createMessage(forum, owner2, false);
m2.setTitle("Thread-2");
m2.setBody("Body of Thread-2");
fm.addTopMessage(m2);
DBFactory.getInstance().intermediateCommit();
m3 = fm.createMessage(forum, owner3, false);
m3.setTitle("Message-1.1");
m3.setBody("Body of Message-1.1");
fm.replyToMessage(m3, m1);
m4 = fm.createMessage(forum, part1, false);
m4.setTitle("Message-1.1.1");
m4.setBody("Body of Message-1.1.1");
fm.replyToMessage(m4, m3);
m5 = fm.createMessage(forum, part2, false);
m5.setTitle("Message-1.2");
m5.setBody("Body of Message-1.2");
fm.replyToMessage(m5, m1);
DBFactory.getInstance().intermediateCommit();
}
Aggregations