Search in sources :

Example 6 with CatalogEntry

use of org.olat.repository.CatalogEntry in project OpenOLAT by OpenOLAT.

the class CatalogTest method testUpdateAndMoveCatalogEntryJson.

@Test
public void testUpdateAndMoveCatalogEntryJson() throws IOException, URISyntaxException {
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("administrator", "openolat"));
    CatalogEntryVO entry = new CatalogEntryVO();
    entry.setName("Entry-2-moved-down");
    entry.setDescription("Entry-description-2-moved-down");
    entry.setType(CatalogEntry.TYPE_NODE);
    URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entryToMove2.getKey().toString()).queryParam("newParentKey", subEntry13move.getKey().toString()).build();
    HttpPost method = conn.createPost(uri, MediaType.APPLICATION_JSON);
    method.addHeader("Content-Type", MediaType.APPLICATION_JSON);
    conn.addJsonEntity(method, entry);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    CatalogEntryVO vo = conn.parse(response, CatalogEntryVO.class);
    assertNotNull(vo);
    CatalogEntry updatedEntry = catalogManager.loadCatalogEntry(entryToMove2);
    assertEquals("Entry-2-moved-down", updatedEntry.getName());
    assertEquals("Entry-description-2-moved-down", updatedEntry.getDescription());
    assertNotNull(updatedEntry.getParent());
    assertTrue(updatedEntry.getParent().equalsByPersistableKey(subEntry13move));
    conn.shutdown();
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) CatalogEntryVO(org.olat.restapi.support.vo.CatalogEntryVO) CatalogEntry(org.olat.repository.CatalogEntry) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 7 with CatalogEntry

use of org.olat.repository.CatalogEntry in project OpenOLAT by OpenOLAT.

the class CatalogTest method testPutCategoryJson.

@Test
public void testPutCategoryJson() throws IOException, URISyntaxException {
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("administrator", "openolat"));
    CatalogEntryVO subEntry = new CatalogEntryVO();
    subEntry.setName("Sub-entry-1");
    subEntry.setDescription("Sub-entry-description-1");
    subEntry.setType(CatalogEntry.TYPE_NODE);
    URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entry1.getKey().toString()).build();
    HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
    method.addHeader("Content-Type", MediaType.APPLICATION_JSON);
    conn.addJsonEntity(method, subEntry);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    CatalogEntryVO vo = conn.parse(response, CatalogEntryVO.class);
    assertNotNull(vo);
    List<CatalogEntry> children = catalogManager.getChildrenOf(entry1);
    boolean saved = false;
    for (CatalogEntry child : children) {
        if (vo.getKey().equals(child.getKey())) {
            saved = true;
            break;
        }
    }
    assertTrue(saved);
    conn.shutdown();
}
Also used : CatalogEntryVO(org.olat.restapi.support.vo.CatalogEntryVO) CatalogEntry(org.olat.repository.CatalogEntry) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 8 with CatalogEntry

use of org.olat.repository.CatalogEntry in project OpenOLAT by OpenOLAT.

the class CatalogTest method testPutCatalogEntryQuery.

@Test
public void testPutCatalogEntryQuery() throws IOException, URISyntaxException {
    RepositoryEntry re = createRepository("put-cat-entry-query", 6458439l);
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("administrator", "openolat"));
    URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entry1.getKey().toString()).queryParam("name", "Sub-entry-2").queryParam("description", "Sub-entry-description-2").queryParam("type", String.valueOf(CatalogEntry.TYPE_NODE)).queryParam("repoEntryKey", re.getKey().toString()).build();
    HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    CatalogEntryVO vo = conn.parse(response, CatalogEntryVO.class);
    assertNotNull(vo);
    List<CatalogEntry> children = catalogManager.getChildrenOf(entry1);
    CatalogEntry ce = null;
    for (CatalogEntry child : children) {
        if (vo.getKey().equals(child.getKey())) {
            ce = child;
            break;
        }
    }
    assertNotNull(ce);
    assertNotNull(ce.getRepositoryEntry());
    assertEquals(re.getKey(), ce.getRepositoryEntry().getKey());
    conn.shutdown();
}
Also used : CatalogEntryVO(org.olat.restapi.support.vo.CatalogEntryVO) CatalogEntry(org.olat.repository.CatalogEntry) HttpResponse(org.apache.http.HttpResponse) RepositoryEntry(org.olat.repository.RepositoryEntry) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 9 with CatalogEntry

use of org.olat.repository.CatalogEntry in project OpenOLAT by OpenOLAT.

the class RepositoryServiceImplTest method deleteCourseSoftly.

@Test
public void deleteCourseSoftly() {
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("re-soft-");
    Identity coachGroup = JunitTestHelper.createAndPersistIdentityAsRndUser("re-soft-");
    Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("re-soft-");
    Identity initialAuthor = JunitTestHelper.createAndPersistIdentityAsRndUser("auth-del-1");
    RepositoryEntry re = JunitTestHelper.deployDemoCourse(initialAuthor);
    dbInstance.commitAndCloseSession();
    // add business group
    BusinessGroup group = businessGroupService.createBusinessGroup(coachGroup, "Relation 1", "tg", null, null, false, false, re);
    businessGroupService.addResourceTo(group, re);
    dbInstance.commit();
    // catalog
    List<CatalogEntry> rootEntries = catalogManager.getRootCatalogEntries();
    CatalogEntry catEntry = catalogManager.createCatalogEntry();
    catEntry.setName("Soft");
    catEntry.setRepositoryEntry(re);
    catEntry.setParent(rootEntries.get(0));
    catEntry.setOwnerGroup(securityManager.createAndPersistSecurityGroup());
    catalogManager.saveCatalogEntry(catEntry);
    dbInstance.commit();
    // check the catalog
    List<CatalogEntry> catEntries = catalogManager.getCatalogCategoriesFor(re);
    Assert.assertNotNull(catEntries);
    Assert.assertEquals(1, catEntries.size());
    // add owner, coach...
    repositoryEntryRelationDao.addRole(coach, re, GroupRoles.coach.name());
    repositoryEntryRelationDao.addRole(participant, re, GroupRoles.participant.name());
    dbInstance.commit();
    // kill it softly like A. Keys
    repositoryService.deleteSoftly(re, initialAuthor, false);
    dbInstance.commit();
    // check that the members are removed
    List<Identity> coachAndParticipants = repositoryEntryRelationDao.getMembers(re, RepositoryEntryRelationType.both, GroupRoles.coach.name(), GroupRoles.participant.name());
    Assert.assertNotNull(coachAndParticipants);
    Assert.assertEquals(0, coachAndParticipants.size());
    // check the relations between course and business groups
    SearchBusinessGroupParams params = new SearchBusinessGroupParams();
    List<BusinessGroup> groups = businessGroupService.findBusinessGroups(params, re, 0, -1);
    Assert.assertNotNull(groups);
    Assert.assertEquals(0, groups.size());
    // check the catalog
    List<CatalogEntry> removedCatEntries = catalogManager.getCatalogCategoriesFor(re);
    Assert.assertNotNull(removedCatEntries);
    Assert.assertEquals(0, removedCatEntries.size());
    RepositoryEntry reloadEntry = repositoryService.loadByKey(re.getKey());
    Assert.assertNotNull(reloadEntry);
    Assert.assertEquals(0, reloadEntry.getAccess());
    Assert.assertNotNull(reloadEntry.getDeletionDate());
    Assert.assertEquals(initialAuthor, reloadEntry.getDeletedBy());
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) CatalogEntry(org.olat.repository.CatalogEntry) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) Test(org.junit.Test)

Example 10 with CatalogEntry

use of org.olat.repository.CatalogEntry in project OpenOLAT by OpenOLAT.

the class CatalogWebService method getOwner.

/**
 * Retrieves data of an owner of the local sub tree
 * @response.representation.200.qname {http://www.example.com}userVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The catalog entry
 * @response.representation.200.example {@link org.olat.user.restapi.Examples#SAMPLE_USERVOes}
 * @response.representation.401.doc Not authorized
 * @response.representation.404.doc The path could not be resolved to a valid catalog entry
 * @param path The path
 * @Param identityKey The id of the user
 * @param httpRquest The HTTP request
 * @return The response
 */
@GET
@Path("{path:.*}/owners/{identityKey}")
public Response getOwner(@PathParam("path") List<PathSegment> path, @PathParam("identityKey") Long identityKey, @Context HttpServletRequest httpRequest) {
    Long key = getCatalogEntryKeyFromPath(path);
    if (key == null) {
        return Response.serverError().status(Status.NOT_ACCEPTABLE).build();
    }
    CatalogEntry ce = catalogManager.loadCatalogEntry(key);
    if (ce == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    if (!isAuthor(httpRequest) && !canAdminSubTree(ce, httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    SecurityGroup sg = ce.getOwnerGroup();
    if (sg == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    List<Identity> ids = BaseSecurityManager.getInstance().getIdentitiesOfSecurityGroup(sg);
    UserVO vo = null;
    for (Identity id : ids) {
        if (id.getKey().equals(identityKey)) {
            vo = UserVOFactory.get(id);
            break;
        }
    }
    if (vo == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    return Response.ok(vo).build();
}
Also used : UserVO(org.olat.user.restapi.UserVO) CatalogEntry(org.olat.repository.CatalogEntry) SecurityGroup(org.olat.basesecurity.SecurityGroup) Identity(org.olat.core.id.Identity) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

CatalogEntry (org.olat.repository.CatalogEntry)122 Test (org.junit.Test)30 CatalogEntryVO (org.olat.restapi.support.vo.CatalogEntryVO)30 URI (java.net.URI)28 HttpResponse (org.apache.http.HttpResponse)28 Identity (org.olat.core.id.Identity)28 ArrayList (java.util.ArrayList)20 Path (javax.ws.rs.Path)18 SecurityGroup (org.olat.basesecurity.SecurityGroup)18 RepositoryEntry (org.olat.repository.RepositoryEntry)18 Produces (javax.ws.rs.Produces)14 HttpPut (org.apache.http.client.methods.HttpPut)12 GET (javax.ws.rs.GET)10 WebApplicationException (javax.ws.rs.WebApplicationException)10 HttpPost (org.apache.http.client.methods.HttpPost)10 OLATResourceable (org.olat.core.id.OLATResourceable)10 ContextEntry (org.olat.core.id.context.ContextEntry)10 LockResult (org.olat.core.util.coordinate.LockResult)10 CatalogManager (org.olat.repository.manager.CatalogManager)8 Link (org.olat.core.gui.components.link.Link)6