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