Search in sources :

Example 86 with TaxonomyLevelType

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

the class TaxonomyWebServiceTest method allowTaxonomyLevelTypeAllowedSubType.

@Test
public void allowTaxonomyLevelTypeAllowedSubType() 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();
    type = taxonomyService.updateTaxonomyLevelType(type, Collections.singletonList(subType1));
    dbInstance.commitAndCloseSession();
    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").path(subType2.getKey().toString()).build();
    HttpPut method = conn.createPut(request, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    EntityUtils.consume(response.getEntity());
    TaxonomyLevelType reloadedType = taxonomyService.getTaxonomyLevelType(type);
    Set<TaxonomyLevelTypeToType> typeToTypes = reloadedType.getAllowedTaxonomyLevelSubTypes();
    Assert.assertEquals(2, typeToTypes.size());
    boolean found1 = false;
    boolean found2 = false;
    for (TaxonomyLevelTypeToType typeToType : typeToTypes) {
        TaxonomyLevelType subType = typeToType.getAllowedSubTaxonomyLevelType();
        if (subType1.getKey().equals(subType.getKey())) {
            found1 = true;
        } else if (subType2.getKey().equals(subType.getKey())) {
            found2 = true;
        }
    }
    Assert.assertTrue(found1);
    Assert.assertTrue(found2);
}
Also used : Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) HttpResponse(org.apache.http.HttpResponse) TaxonomyLevelTypeToType(org.olat.modules.taxonomy.TaxonomyLevelTypeToType) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 87 with TaxonomyLevelType

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

the class TaxonomyWebServiceTest method updateTaxonomyLevel.

/**
 * Update level.
 *
 * @throws IOException
 * @throws URISyntaxException
 */
@Test
public void updateTaxonomyLevel() throws IOException, URISyntaxException {
    Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Tax-4", "Taxonomy on rest", "PUT is cool, yes!", "PUT-tax-2");
    TaxonomyLevel rootLevel = taxonomyService.createTaxonomyLevel("REST-Tax-u-1", "Root level on rest", "Level", "Ext-25", null, null, taxonomy);
    TaxonomyLevel levelToUpdate = taxonomyService.createTaxonomyLevel("REST-Tax-u-1", "Sub level on rest", "Level", "Ext-26", null, rootLevel, taxonomy);
    TaxonomyLevelType type = taxonomyService.createTaxonomyLevelType("Sub-type", "Type for a sub level", "All is in the title", "TYP-27", taxonomy);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(taxonomy);
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    TaxonomyLevelVO levelVo = new TaxonomyLevelVO();
    levelVo.setKey(levelToUpdate.getKey());
    levelVo.setIdentifier("Updated id");
    levelVo.setDisplayName("Updated name");
    levelVo.setDescription("Updated description");
    levelVo.setExternalId("Updated ext.");
    levelVo.setTypeKey(type.getKey());
    levelVo.setParentKey(rootLevel.getKey());
    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 updated value
    TaxonomyLevelVO updatedTaxonomyLevelVo = conn.parse(response, TaxonomyLevelVO.class);
    Assert.assertNotNull(updatedTaxonomyLevelVo);
    Assert.assertEquals("Updated id", updatedTaxonomyLevelVo.getIdentifier());
    Assert.assertEquals("Updated name", updatedTaxonomyLevelVo.getDisplayName());
    Assert.assertEquals("Updated description", updatedTaxonomyLevelVo.getDescription());
    Assert.assertEquals("Updated ext.", updatedTaxonomyLevelVo.getExternalId());
    Assert.assertEquals(rootLevel.getKey(), updatedTaxonomyLevelVo.getParentKey());
    Assert.assertEquals(type.getKey(), updatedTaxonomyLevelVo.getTypeKey());
    // check the database
    TaxonomyLevel savedLevel = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(updatedTaxonomyLevelVo.getKey()));
    Assert.assertNotNull(savedLevel);
    Assert.assertEquals("Updated id", savedLevel.getIdentifier());
    Assert.assertEquals("Updated name", savedLevel.getDisplayName());
    Assert.assertEquals("Updated description", savedLevel.getDescription());
    Assert.assertEquals("Updated ext.", savedLevel.getExternalId());
    Assert.assertEquals(rootLevel.getKey(), savedLevel.getParent().getKey());
    Assert.assertEquals(type.getKey(), savedLevel.getType().getKey());
}
Also used : Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyLevelVO(org.olat.modules.taxonomy.restapi.TaxonomyLevelVO) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) HttpResponse(org.apache.http.HttpResponse) TaxonomyLevelRefImpl(org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 88 with TaxonomyLevelType

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

the class TaxonomyLevelTypeDAO method cloneTaxonomyLevelType.

public TaxonomyLevelType cloneTaxonomyLevelType(TaxonomyLevelTypeRef typeRef) {
    TaxonomyLevelType reloadedType = loadTaxonomyLevelTypeByKey(typeRef.getKey());
    TaxonomyLevelTypeImpl type = new TaxonomyLevelTypeImpl();
    type.setCreationDate(new Date());
    type.setLastModified(type.getCreationDate());
    type.setIdentifier(reloadedType.getIdentifier() + " (Copy)");
    type.setDisplayName(reloadedType.getDisplayName());
    type.setDescription(reloadedType.getDescription());
    type.setExternalId("");
    // default settings
    type.setDocumentsLibraryManageCompetenceEnabled(reloadedType.isDocumentsLibraryManageCompetenceEnabled());
    type.setDocumentsLibraryTeachCompetenceReadEnabled(reloadedType.isDocumentsLibraryTargetCompetenceReadEnabled());
    type.setDocumentsLibraryTeachCompetenceReadParentLevels(reloadedType.getDocumentsLibraryTeachCompetenceReadParentLevels());
    type.setDocumentsLibraryTeachCompetenceWriteEnabled(reloadedType.isDocumentsLibraryTeachCompetenceWriteEnabled());
    type.setDocumentsLibraryHaveCompetenceReadEnabled(reloadedType.isDocumentsLibraryHaveCompetenceReadEnabled());
    type.setDocumentsLibraryTargetCompetenceReadEnabled(reloadedType.isDocumentsLibraryTargetCompetenceReadEnabled());
    // root
    type.setTaxonomy(reloadedType.getTaxonomy());
    dbInstance.getCurrentEntityManager().persist(type);
    return type;
}
Also used : TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) TaxonomyLevelTypeImpl(org.olat.modules.taxonomy.model.TaxonomyLevelTypeImpl) Date(java.util.Date)

Example 89 with TaxonomyLevelType

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

the class TaxonomyLevelTypeDAO method deleteTaxonomyLevelType.

public boolean deleteTaxonomyLevelType(TaxonomyLevelTypeRef levelType) {
    TaxonomyLevelType reloadedLevel = dbInstance.getCurrentEntityManager().getReference(TaxonomyLevelTypeImpl.class, levelType.getKey());
    dbInstance.getCurrentEntityManager().remove(reloadedLevel);
    return true;
}
Also used : TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType)

Example 90 with TaxonomyLevelType

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

the class TaxonomyLevelDAOTest method createAndLoadTaxonomyLevel_withType.

@Test
public void createAndLoadTaxonomyLevel_withType() {
    Taxonomy taxonomy = taxonomyDao.createTaxonomy("ID-103", "Typed taxonomy", null, null);
    TaxonomyLevelType type = taxonomyLevelTypeDao.createTaxonomyLevelType("Type-t", "A type", "Typed", "TYP-T", taxonomy);
    TaxonomyLevel level = taxonomyLevelDao.createTaxonomyLevel("ID-Level-0", "A taxonomy level", "A basic level", null, null, null, type, taxonomy);
    dbInstance.commitAndCloseSession();
    TaxonomyLevel reloadedLevel = taxonomyLevelDao.loadByKey(level.getKey());
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(reloadedLevel);
    Assert.assertNotNull(reloadedLevel.getKey());
    Assert.assertEquals(level, reloadedLevel);
    Assert.assertEquals(taxonomy, reloadedLevel.getTaxonomy());
    Assert.assertEquals(type, reloadedLevel.getType());
}
Also used : Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) Test(org.junit.Test)

Aggregations

TaxonomyLevelType (org.olat.modules.taxonomy.TaxonomyLevelType)92 Test (org.junit.Test)40 Taxonomy (org.olat.modules.taxonomy.Taxonomy)32 TaxonomyLevel (org.olat.modules.taxonomy.TaxonomyLevel)32 ArrayList (java.util.ArrayList)26 Identity (org.olat.core.id.Identity)20 TaxonomyLevelTypeToType (org.olat.modules.taxonomy.TaxonomyLevelTypeToType)16 URI (java.net.URI)14 HttpResponse (org.apache.http.HttpResponse)14 TaxonomyLevelTypeRefImpl (org.olat.modules.taxonomy.model.TaxonomyLevelTypeRefImpl)14 Path (javax.ws.rs.Path)12 List (java.util.List)10 Produces (javax.ws.rs.Produces)10 Collectors (java.util.stream.Collectors)8 TaxonomyLevelRefImpl (org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 PUT (javax.ws.rs.PUT)6 HttpGet (org.apache.http.client.methods.HttpGet)6 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)6