Search in sources :

Example 26 with Taxonomy

use of org.olat.modules.taxonomy.Taxonomy in project OpenOLAT by OpenOLAT.

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)

Example 27 with Taxonomy

use of org.olat.modules.taxonomy.Taxonomy in project OpenOLAT by OpenOLAT.

the class TaxonomyWebServiceTest method getTaxonomyLevelTypeAllowedSubTypes.

@Test
public void getTaxonomyLevelTypeAllowedSubTypes() throws IOException, URISyntaxException {
    Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Tax-4", "Taxonomy on rest", "Rest is cool", "Ext-tax-1");
    TaxonomyLevelType type = taxonomyService.createTaxonomyLevelType("REST-Type-4", "Type 4 on rest", "Type", "EXT-Type-4", taxonomy);
    TaxonomyLevelType subType1 = taxonomyService.createTaxonomyLevelType("REST-Type-4-1", "Type 4.1 on rest", "Type", "EXT-Type-4-1", taxonomy);
    TaxonomyLevelType subType2 = taxonomyService.createTaxonomyLevelType("REST-Type-4-2", "Type 4.2 on rest", "Type", "EXT-Type-4-2", taxonomy);
    dbInstance.commit();
    List<TaxonomyLevelType> subTypes = new ArrayList<>(2);
    subTypes.add(subType1);
    subTypes.add(subType2);
    type = taxonomyService.updateTaxonomyLevelType(type, subTypes);
    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("types").path(type.getKey().toString()).path("allowedSubTypes").build();
    HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    List<TaxonomyLevelTypeVO> typeVoList = parseTaxonomyLevelTypesArray(response.getEntity().getContent());
    Assert.assertNotNull(typeVoList);
    Assert.assertEquals(2, typeVoList.size());
    boolean found1 = false;
    boolean found2 = false;
    for (TaxonomyLevelTypeVO typeVo : typeVoList) {
        if (subType1.getKey().equals(typeVo.getKey())) {
            found1 = true;
        } else if (subType2.getKey().equals(typeVo.getKey())) {
            found2 = true;
        }
    }
    Assert.assertTrue(found1);
    Assert.assertTrue(found2);
}
Also used : TaxonomyLevelTypeVO(org.olat.modules.taxonomy.restapi.TaxonomyLevelTypeVO) Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) HttpGet(org.apache.http.client.methods.HttpGet) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 28 with Taxonomy

use of org.olat.modules.taxonomy.Taxonomy in project OpenOLAT by OpenOLAT.

the class TaxonomyWebServiceTest method getTaxonomyLevelComptences_byIdentity.

@Test
public void getTaxonomyLevelComptences_byIdentity() throws IOException, URISyntaxException {
    // prepare a level, 1 user and 1 competence
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("competence-4");
    Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Tax-7", "Taxonomy on rest", "Rest is cool", "Ext-tax-7");
    TaxonomyLevel level = taxonomyService.createTaxonomyLevel("REST-Tax-l-7", "Level 1 on rest", "Level", "Ext-7", null, null, taxonomy);
    taxonomyService.addTaxonomyLevelCompetences(level, id, TaxonomyCompetenceTypes.teach, null);
    dbInstance.commitAndCloseSession();
    // get the competences
    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(id.getKey().toString()).build();
    HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    List<TaxonomyCompetenceVO> competenceList = parseTaxonomyComptencesArray(response.getEntity().getContent());
    Assert.assertNotNull(competenceList);
    Assert.assertEquals(1, competenceList.size());
    TaxonomyCompetenceVO competence = competenceList.get(0);
    Assert.assertEquals(id.getKey(), competence.getIdentityKey());
    Assert.assertEquals(level.getKey(), competence.getTaxonomyLevelKey());
    Assert.assertEquals(TaxonomyCompetenceTypes.teach.name(), competence.getTaxonomyCompetenceType());
}
Also used : Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) Identity(org.olat.core.id.Identity) URI(java.net.URI) TaxonomyCompetenceVO(org.olat.modules.taxonomy.restapi.TaxonomyCompetenceVO) Test(org.junit.Test)

Example 29 with Taxonomy

use of org.olat.modules.taxonomy.Taxonomy in project OpenOLAT by OpenOLAT.

the class TaxonomyWebServiceTest method getTaxonomyComptencesByIdentity.

@Test
public void getTaxonomyComptencesByIdentity() throws IOException, URISyntaxException {
    // prepare a level, 2 users and 2 competences
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("competence-4");
    Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Tax-20", "Taxonomy on rest", "Rest is cool", "Ext-tax-7");
    TaxonomyLevel level1 = taxonomyService.createTaxonomyLevel("REST-Tax-l-21", "Level 1 on rest", "Level", "Ext-7", null, null, taxonomy);
    TaxonomyLevel level2 = taxonomyService.createTaxonomyLevel("REST-Tax-l-22", "Level 1 on rest", "Level", "Ext-7", null, null, taxonomy);
    taxonomyService.addTaxonomyLevelCompetences(level1, id, TaxonomyCompetenceTypes.teach, null);
    taxonomyService.addTaxonomyLevelCompetences(level2, id, TaxonomyCompetenceTypes.have, null);
    dbInstance.commitAndCloseSession();
    // get the competences
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    URI request = UriBuilder.fromUri(getContextURI()).path("taxonomy").path(taxonomy.getKey().toString()).path("competences").path(id.getKey().toString()).build();
    HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    List<TaxonomyCompetenceVO> competenceList = parseTaxonomyComptencesArray(response.getEntity().getContent());
    Assert.assertNotNull(competenceList);
    Assert.assertEquals(2, competenceList.size());
    boolean foundComptenceId1 = false;
    boolean foundComptenceId2 = false;
    for (TaxonomyCompetenceVO competence : competenceList) {
        if (competence.getTaxonomyLevelKey().equals(level1.getKey()) && competence.getIdentityKey().equals(id.getKey()) && TaxonomyCompetenceTypes.teach.name().equals(competence.getTaxonomyCompetenceType())) {
            foundComptenceId1 = true;
        } else if (competence.getTaxonomyLevelKey().equals(level2.getKey()) && competence.getIdentityKey().equals(id.getKey()) && TaxonomyCompetenceTypes.have.name().equals(competence.getTaxonomyCompetenceType())) {
            foundComptenceId2 = true;
        }
    }
    Assert.assertTrue(foundComptenceId1);
    Assert.assertTrue(foundComptenceId2);
}
Also used : Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) Identity(org.olat.core.id.Identity) URI(java.net.URI) TaxonomyCompetenceVO(org.olat.modules.taxonomy.restapi.TaxonomyCompetenceVO) Test(org.junit.Test)

Example 30 with Taxonomy

use of org.olat.modules.taxonomy.Taxonomy in project OpenOLAT by OpenOLAT.

the class QuestionPoolModule method initTaxonomy.

private void initTaxonomy() {
    if (!StringHelper.isLong(taxonomyQPoolKey)) {
        Taxonomy taxonomy = taxonomyDao.createTaxonomy(DEFAULT_TAXONOMY_QPOOL_IDENTIFIER, "Question pool", "taxonomy for the question pool", DEFAULT_TAXONOMY_QPOOL_IDENTIFIER);
        dbInstance.commitAndCloseSession();
        setTaxonomyQPoolKey(taxonomy.getKey().toString());
    }
}
Also used : Taxonomy(org.olat.modules.taxonomy.Taxonomy)

Aggregations

Taxonomy (org.olat.modules.taxonomy.Taxonomy)194 Test (org.junit.Test)132 TaxonomyLevel (org.olat.modules.taxonomy.TaxonomyLevel)122 Identity (org.olat.core.id.Identity)56 URI (java.net.URI)36 HttpResponse (org.apache.http.HttpResponse)36 TaxonomyCompetence (org.olat.modules.taxonomy.TaxonomyCompetence)36 TaxonomyLevelType (org.olat.modules.taxonomy.TaxonomyLevelType)34 Date (java.util.Date)22 HttpGet (org.apache.http.client.methods.HttpGet)16 ArrayList (java.util.ArrayList)14 TaxonomyService (org.olat.modules.taxonomy.TaxonomyService)14 TaxonomyRefImpl (org.olat.modules.taxonomy.model.TaxonomyRefImpl)14 HttpPut (org.apache.http.client.methods.HttpPut)12 HashMap (java.util.HashMap)10 List (java.util.List)10 VFSContainer (org.olat.core.util.vfs.VFSContainer)10 QuestionItemImpl (org.olat.modules.qpool.model.QuestionItemImpl)10 TaxonomyLevelTypeToType (org.olat.modules.taxonomy.TaxonomyLevelTypeToType)10 TaxonomyLevelRefImpl (org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl)10