Search in sources :

Example 6 with TaxonomyCompetence

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

the class TaxonomyCompetenceDAOTest method createTaxonomyCompetence.

@Test
public void createTaxonomyCompetence() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("competent-1");
    Taxonomy taxonomy = taxonomyDao.createTaxonomy("ID-24", "Competence", "", null);
    TaxonomyLevel level = taxonomyLevelDao.createTaxonomyLevel("ID-Level-1", "Competence level", "A very difficult competence", null, null, null, null, taxonomy);
    TaxonomyCompetence competence = taxonomyCompetenceDao.createTaxonomyCompetence(TaxonomyCompetenceTypes.have, level, id, null);
    dbInstance.commit();
    Assert.assertNotNull(competence);
    Assert.assertNotNull(competence.getCreationDate());
}
Also used : Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) TaxonomyCompetence(org.olat.modules.taxonomy.TaxonomyCompetence) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 7 with TaxonomyCompetence

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

the class TaxonomyCompetenceDAO method deleteCompetence.

public void deleteCompetence(TaxonomyCompetence competence) {
    TaxonomyCompetence reloadedCompetence = dbInstance.getCurrentEntityManager().getReference(TaxonomyCompetenceImpl.class, competence.getKey());
    dbInstance.getCurrentEntityManager().remove(reloadedCompetence);
}
Also used : TaxonomyCompetence(org.olat.modules.taxonomy.TaxonomyCompetence)

Example 8 with TaxonomyCompetence

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

the class TaxonomyTreeBuilder method computePermissions.

private void computePermissions(TaxonomyTreeNode root) {
    List<TaxonomyCompetence> competences = taxonomyService.getTaxonomyCompetences(taxonomy, identity, new Date());
    Map<TaxonomyLevel, List<TaxonomyCompetenceTypes>> levelToCompetences = new HashMap<>();
    for (TaxonomyCompetence competence : competences) {
        TaxonomyLevel level = competence.getTaxonomyLevel();
        if (levelToCompetences.containsKey(level)) {
            levelToCompetences.get(level).add(competence.getCompetenceType());
        } else {
            List<TaxonomyCompetenceTypes> types = new ArrayList<>(4);
            types.add(competence.getCompetenceType());
            levelToCompetences.put(level, types);
        }
    }
    computePermissionsRecursive(root, levelToCompetences);
    trimRecursive(root);
}
Also used : HashMap(java.util.HashMap) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TaxonomyCompetence(org.olat.modules.taxonomy.TaxonomyCompetence) TaxonomyCompetenceTypes(org.olat.modules.taxonomy.TaxonomyCompetenceTypes) Date(java.util.Date)

Example 9 with TaxonomyCompetence

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

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

the class TaxonomyCompetenceAuditLogDAOTest method auditLog.

@Test
public void auditLog() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("competent-1");
    Taxonomy taxonomy = taxonomyDao.createTaxonomy("ID-24", "Competence", "", null);
    TaxonomyLevel level = taxonomyLevelDao.createTaxonomyLevel("ID-Level-1", "Competence level", "A very difficult competence", null, null, null, null, taxonomy);
    TaxonomyCompetence competence = taxonomyCompetenceDao.createTaxonomyCompetence(TaxonomyCompetenceTypes.have, level, id, null);
    dbInstance.commit();
    String after = taxonomyCompetenceAuditLogDao.toXml(competence);
    taxonomyCompetenceAuditLogDao.auditLog(TaxonomyCompetenceAuditLog.Action.addCompetence, "Before", "After", "Message", taxonomy, competence, id, null);
    dbInstance.commit();
    Assert.assertNotNull(after);
}
Also used : Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) TaxonomyCompetence(org.olat.modules.taxonomy.TaxonomyCompetence) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Aggregations

TaxonomyCompetence (org.olat.modules.taxonomy.TaxonomyCompetence)50 TaxonomyLevel (org.olat.modules.taxonomy.TaxonomyLevel)38 Identity (org.olat.core.id.Identity)36 Taxonomy (org.olat.modules.taxonomy.Taxonomy)34 Test (org.junit.Test)26 Date (java.util.Date)10 ArrayList (java.util.ArrayList)8 Consumes (javax.ws.rs.Consumes)8 Path (javax.ws.rs.Path)8 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)8 GET (javax.ws.rs.GET)6 Produces (javax.ws.rs.Produces)6 TaxonomyLevelRefImpl (org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl)6 URI (java.net.URI)4 HttpResponse (org.apache.http.HttpResponse)4 TaxonomyCompetenceTypes (org.olat.modules.taxonomy.TaxonomyCompetenceTypes)4 HashMap (java.util.HashMap)2 List (java.util.List)2 DELETE (javax.ws.rs.DELETE)2 HttpDelete (org.apache.http.client.methods.HttpDelete)2