Search in sources :

Example 51 with RepositoryService

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();
}
Also used : ErrorList(org.olat.repository.ErrorList) RepositoryEntry(org.olat.repository.RepositoryEntry) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) RepositoryService(org.olat.repository.RepositoryService) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces)

Example 52 with RepositoryService

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();
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) CollaborationTools(org.olat.collaboration.CollaborationTools) RepositoryEntry(org.olat.repository.RepositoryEntry) RepositoryService(org.olat.repository.RepositoryService) Before(org.junit.Before)

Example 53 with RepositoryService

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;
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) RepositoryEntry(org.olat.repository.RepositoryEntry) RepositoryService(org.olat.repository.RepositoryService) Before(org.junit.Before)

Example 54 with RepositoryService

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())));
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) ColumnDescriptor(org.olat.core.gui.components.table.ColumnDescriptor) RepositoryService(org.olat.repository.RepositoryService) CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) DefaultColumnDescriptor(org.olat.core.gui.components.table.DefaultColumnDescriptor) WindowControl(org.olat.core.gui.control.WindowControl) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) RepositoryEntry(org.olat.repository.RepositoryEntry) Component(org.olat.core.gui.components.Component) Collectors(java.util.stream.Collectors) ModuleConfiguration(org.olat.modules.ModuleConfiguration) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Event(org.olat.core.gui.control.Event) BasicController(org.olat.core.gui.control.controller.BasicController) CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) DefaultTableDataModel(org.olat.core.gui.components.table.DefaultTableDataModel) List(java.util.List) Identity(org.olat.core.id.Identity) UserRequest(org.olat.core.gui.UserRequest) TableGuiConfiguration(org.olat.core.gui.components.table.TableGuiConfiguration) TableController(org.olat.core.gui.components.table.TableController) CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) HashSet(java.util.HashSet)

Example 55 with RepositoryService

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();
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) ForumManager(org.olat.modules.fo.manager.ForumManager) CollaborationTools(org.olat.collaboration.CollaborationTools) OLATResourceManager(org.olat.resource.OLATResourceManager) RepositoryEntry(org.olat.repository.RepositoryEntry) NarrowedPropertyManager(org.olat.properties.NarrowedPropertyManager) Property(org.olat.properties.Property) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) RepositoryService(org.olat.repository.RepositoryService) Forum(org.olat.modules.fo.Forum) Before(org.junit.Before)

Aggregations

RepositoryService (org.olat.repository.RepositoryService)76 RepositoryEntry (org.olat.repository.RepositoryEntry)72 OLATResource (org.olat.resource.OLATResource)32 Identity (org.olat.core.id.Identity)20 Produces (javax.ws.rs.Produces)18 Path (javax.ws.rs.Path)16 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)14 File (java.io.File)12 OLATResourceable (org.olat.core.id.OLATResourceable)12 GET (javax.ws.rs.GET)10 UserRequest (org.olat.core.gui.UserRequest)8 WindowControl (org.olat.core.gui.control.WindowControl)8 ICourse (org.olat.course.ICourse)8 RepositoryHandler (org.olat.repository.handlers.RepositoryHandler)8 UserVO (org.olat.user.restapi.UserVO)7 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 Before (org.junit.Before)6 VFSContainer (org.olat.core.util.vfs.VFSContainer)6 GlossaryResource (org.olat.fileresource.types.GlossaryResource)6