Search in sources :

Example 66 with Taxonomy

use of org.olat.modules.taxonomy.Taxonomy 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 67 with Taxonomy

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

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 68 with Taxonomy

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

the class TaxonomyWebServiceTest method getTaxonomyLevelType.

@Test
public void getTaxonomyLevelType() throws IOException, URISyntaxException {
    Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Tax-2", "Taxonomy on rest", "Rest is cool", "Ext-tax-1");
    TaxonomyLevelType type = taxonomyService.createTaxonomyLevelType("REST-Type-3", "Type 3 on rest", "Type", "EXT-Type-3", 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("types").path(type.getKey().toString()).build();
    HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    TaxonomyLevelTypeVO typeVo = conn.parse(response, TaxonomyLevelTypeVO.class);
    Assert.assertNotNull(typeVo);
}
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) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 69 with Taxonomy

use of org.olat.modules.taxonomy.Taxonomy 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 70 with Taxonomy

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

the class TaxonomyWebServiceTest method getTaxonomy.

@Test
public void getTaxonomy() throws IOException, URISyntaxException {
    Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Tax-1", "Taxonomy on rest", "Rest is cool", "Ext-tax-1");
    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()).build();
    HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    TaxonomyVO taxonomyVO = conn.parse(response, TaxonomyVO.class);
    Assert.assertNotNull(taxonomyVO);
    Assert.assertEquals(taxonomy.getKey(), taxonomyVO.getKey());
    Assert.assertEquals("REST-Tax-1", taxonomyVO.getIdentifier());
    Assert.assertEquals("Taxonomy on rest", taxonomyVO.getDisplayName());
    Assert.assertEquals("Rest is cool", taxonomyVO.getDescription());
    Assert.assertEquals("Ext-tax-1", taxonomyVO.getExternalId());
}
Also used : Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyVO(org.olat.modules.taxonomy.restapi.TaxonomyVO) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

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