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();
}
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();
}
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();
}
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());
}
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();
}
Aggregations