Search in sources :

Example 76 with TaxonomyLevel

use of org.olat.modules.taxonomy.TaxonomyLevel in project openolat by klemens.

the class QPoolTaxonomyTreeBuilderTest method createLevelsOfClassicSchoolTaxonomy.

private List<TaxonomyLevel> createLevelsOfClassicSchoolTaxonomy() {
    List<TaxonomyLevel> levels = new ArrayList<>();
    TaxonomyLevel math = new TestableTaxonomyLevel(MATH_KEY, MATH, null);
    levels.add(math);
    TaxonomyLevel geom = new TestableTaxonomyLevel(GEOM_KEY, GEOM, math);
    levels.add(geom);
    TaxonomyLevel algebra = new TestableTaxonomyLevel(ALGEBRA_KEY, ALGEBRA, math);
    levels.add(algebra);
    TaxonomyLevel language = new TestableTaxonomyLevel(LANGUAGE_KEY, LANGUAGE, null);
    levels.add(language);
    TaxonomyLevel english = new TestableTaxonomyLevel(ENGLISH_KEY, ENGLISH, language);
    levels.add(english);
    TaxonomyLevel hindi = new TestableTaxonomyLevel(HINDI_KEY, HINDI, language);
    levels.add(hindi);
    TaxonomyLevel russian = new TestableTaxonomyLevel(RUSSIAN_KEY, RUSSIAN, language);
    levels.add(russian);
    TaxonomyLevel latin = new TestableTaxonomyLevel(LATIN_KEY, LATIN, language);
    levels.add(latin);
    return levels;
}
Also used : TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) ArrayList(java.util.ArrayList)

Example 77 with TaxonomyLevel

use of org.olat.modules.taxonomy.TaxonomyLevel in project openolat by klemens.

the class TaxonomyWebServiceTest method putTaxonomyLevel_rootLevel.

@Test
public void putTaxonomyLevel_rootLevel() throws IOException, URISyntaxException {
    Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Tax-2", "Taxonomy on rest", "PUT is cool", "PUT-tax-1");
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(taxonomy);
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    String uid = UUID.randomUUID().toString();
    TaxonomyLevelVO levelVo = new TaxonomyLevelVO();
    levelVo.setIdentifier(uid);
    levelVo.setDisplayName("PUT root level");
    levelVo.setDescription("Try to PUT a root level");
    levelVo.setExternalId("EXT-190");
    URI request = UriBuilder.fromUri(getContextURI()).path("taxonomy").path(taxonomy.getKey().toString()).path("levels").build();
    HttpPut method = conn.createPut(request, MediaType.APPLICATION_JSON, true);
    conn.addJsonEntity(method, levelVo);
    HttpResponse response = conn.execute(method);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    // check the returned value
    TaxonomyLevelVO newTaxonomyLevelVo = conn.parse(response, TaxonomyLevelVO.class);
    Assert.assertNotNull(newTaxonomyLevelVo);
    Assert.assertNotNull(newTaxonomyLevelVo.getKey());
    Assert.assertEquals(uid, newTaxonomyLevelVo.getIdentifier());
    Assert.assertEquals("PUT root level", newTaxonomyLevelVo.getDisplayName());
    Assert.assertEquals("Try to PUT a root level", newTaxonomyLevelVo.getDescription());
    Assert.assertEquals("EXT-190", newTaxonomyLevelVo.getExternalId());
    // check the database
    List<TaxonomyLevel> levels = taxonomyService.getTaxonomyLevels(taxonomy);
    Assert.assertNotNull(levels);
    Assert.assertEquals(1, levels.size());
    TaxonomyLevel savedLevel = levels.get(0);
    Assert.assertEquals(newTaxonomyLevelVo.getKey(), savedLevel.getKey());
    Assert.assertEquals(uid, savedLevel.getIdentifier());
    Assert.assertEquals("PUT root level", savedLevel.getDisplayName());
    Assert.assertEquals("Try to PUT a root level", savedLevel.getDescription());
    Assert.assertEquals("EXT-190", savedLevel.getExternalId());
}
Also used : Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyLevelVO(org.olat.modules.taxonomy.restapi.TaxonomyLevelVO) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 78 with TaxonomyLevel

use of org.olat.modules.taxonomy.TaxonomyLevel in project openolat by klemens.

the class TaxonomyWebServiceTest method putTaxonomyLevelComptence.

@Test
public void putTaxonomyLevelComptence() throws IOException, URISyntaxException {
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("competence-4");
    Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Tax-8", "Taxonomy on rest", "PUT is cool, yes!", "PUT-tax-2");
    TaxonomyLevel level = taxonomyService.createTaxonomyLevel("REST-Tax-r-8", "Root level on rest", "Level", "Ext-23", null, null, taxonomy);
    dbInstance.commitAndCloseSession();
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    TaxonomyCompetenceVO competenceVo = new TaxonomyCompetenceVO();
    competenceVo.setIdentityKey(id.getKey());
    competenceVo.setTaxonomyCompetenceType(TaxonomyCompetenceTypes.target.name());
    competenceVo.setTaxonomyLevelKey(level.getKey());
    URI request = UriBuilder.fromUri(getContextURI()).path("taxonomy").path(taxonomy.getKey().toString()).path("levels").path(level.getKey().toString()).path("competences").build();
    HttpPut method = conn.createPut(request, MediaType.APPLICATION_JSON, true);
    conn.addJsonEntity(method, competenceVo);
    HttpResponse response = conn.execute(method);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    // check the returned value
    TaxonomyCompetenceVO newTaxonomyCompetenceVo = conn.parse(response, TaxonomyCompetenceVO.class);
    Assert.assertNotNull(newTaxonomyCompetenceVo);
    Assert.assertNotNull(newTaxonomyCompetenceVo.getKey());
    Assert.assertEquals(id.getKey(), newTaxonomyCompetenceVo.getIdentityKey());
    Assert.assertEquals(TaxonomyCompetenceTypes.target.name(), newTaxonomyCompetenceVo.getTaxonomyCompetenceType());
    Assert.assertEquals(level.getKey(), newTaxonomyCompetenceVo.getTaxonomyLevelKey());
    // check the database
    List<TaxonomyCompetence> competences = taxonomyService.getTaxonomyCompetences(id, TaxonomyCompetenceTypes.target);
    Assert.assertNotNull(competences);
    Assert.assertEquals(1, competences.size());
    TaxonomyCompetence competence = competences.get(0);
    Assert.assertEquals(id, competence.getIdentity());
    Assert.assertEquals(level, competence.getTaxonomyLevel());
    Assert.assertEquals(TaxonomyCompetenceTypes.target, competence.getCompetenceType());
}
Also used : Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) HttpResponse(org.apache.http.HttpResponse) TaxonomyCompetence(org.olat.modules.taxonomy.TaxonomyCompetence) Identity(org.olat.core.id.Identity) URI(java.net.URI) TaxonomyCompetenceVO(org.olat.modules.taxonomy.restapi.TaxonomyCompetenceVO) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 79 with TaxonomyLevel

use of org.olat.modules.taxonomy.TaxonomyLevel in project openolat by klemens.

the class TaxonomyWebServiceTest method deleteTaxonomyLevel.

@Test
public void deleteTaxonomyLevel() throws IOException, URISyntaxException {
    Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Del-1", "Taxonomy on rest", "Delete is sad!", "DELETE-tax-1");
    TaxonomyLevel rootLevel = taxonomyService.createTaxonomyLevel("REST-Del-root", "Root level on rest", "Level", "Ext-55", null, null, taxonomy);
    TaxonomyLevel levelToDelete = taxonomyService.createTaxonomyLevel("REST-Del-u-1", "Sub level on rest", "Level", "Ext-56", null, rootLevel, taxonomy);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(taxonomy);
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    URI request = UriBuilder.fromUri(getContextURI()).path("taxonomy").path(taxonomy.getKey().toString()).path("levels").path(levelToDelete.getKey().toString()).build();
    HttpDelete method = conn.createDelete(request, MediaType.APPLICATION_JSON);
    HttpResponse response = conn.execute(method);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    EntityUtils.consume(response.getEntity());
    // check the deleted value
    TaxonomyLevel deletedLevel = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(levelToDelete.getKey()));
    Assert.assertNull(deletedLevel);
    TaxonomyLevel survivingRootLevel = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(rootLevel.getKey()));
    Assert.assertNotNull(survivingRootLevel);
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) HttpResponse(org.apache.http.HttpResponse) TaxonomyLevelRefImpl(org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl) URI(java.net.URI) Test(org.junit.Test)

Example 80 with TaxonomyLevel

use of org.olat.modules.taxonomy.TaxonomyLevel in project openolat by klemens.

the class TaxonomyWebServiceTest method removeTaxonomyLevelCompetence.

@Test
public void removeTaxonomyLevelCompetence() throws IOException, URISyntaxException {
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("competence-4");
    Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Tax-8", "Taxonomy on rest", "PUT is cool, yes!", "PUT-tax-2");
    TaxonomyLevel level = taxonomyService.createTaxonomyLevel("REST-Tax-r-8", "Root level on rest", "Level", "Ext-23", null, null, taxonomy);
    TaxonomyCompetence competence = taxonomyService.addTaxonomyLevelCompetences(level, id, TaxonomyCompetenceTypes.target, null);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(competence);
    // make sure we have something to delete
    TaxonomyCompetence reloadedCompetence = taxonomyService.getTaxonomyCompetence(competence);
    Assert.assertNotNull(reloadedCompetence);
    dbInstance.commitAndCloseSession();
    // remove the competence
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    URI request = UriBuilder.fromUri(getContextURI()).path("taxonomy").path(taxonomy.getKey().toString()).path("levels").path(level.getKey().toString()).path("competences").path(competence.getKey().toString()).build();
    HttpDelete method = conn.createDelete(request, MediaType.APPLICATION_JSON);
    HttpResponse response = conn.execute(method);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    EntityUtils.consume(response.getEntity());
    // check the database
    List<TaxonomyCompetence> competences = taxonomyService.getTaxonomyCompetences(id, TaxonomyCompetenceTypes.target);
    Assert.assertNotNull(competences);
    Assert.assertEquals(0, competences.size());
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) HttpResponse(org.apache.http.HttpResponse) TaxonomyCompetence(org.olat.modules.taxonomy.TaxonomyCompetence) Identity(org.olat.core.id.Identity) URI(java.net.URI) Test(org.junit.Test)

Aggregations

TaxonomyLevel (org.olat.modules.taxonomy.TaxonomyLevel)238 Taxonomy (org.olat.modules.taxonomy.Taxonomy)122 Test (org.junit.Test)106 Identity (org.olat.core.id.Identity)58 ArrayList (java.util.ArrayList)40 TaxonomyCompetence (org.olat.modules.taxonomy.TaxonomyCompetence)40 TaxonomyLevelType (org.olat.modules.taxonomy.TaxonomyLevelType)34 Date (java.util.Date)24 TaxonomyLevelRefImpl (org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl)24 URI (java.net.URI)22 HttpResponse (org.apache.http.HttpResponse)22 TreeNode (org.olat.core.gui.components.tree.TreeNode)22 GenericTreeNode (org.olat.core.gui.components.tree.GenericTreeNode)18 QuestionItemImpl (org.olat.modules.qpool.model.QuestionItemImpl)16 HashMap (java.util.HashMap)14 List (java.util.List)14 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)12 TaxonomyCompetenceTypes (org.olat.modules.taxonomy.TaxonomyCompetenceTypes)12 TaxonomyTreeNode (org.olat.modules.taxonomy.model.TaxonomyTreeNode)12 Path (javax.ws.rs.Path)10