Search in sources :

Example 21 with TaxonomyCompetence

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

the class TaxonomyCompetenceDAOTest method deleteCompetencesByIdentity.

@Test
public void deleteCompetencesByIdentity() {
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("competent-6");
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("competent-6");
    Taxonomy taxonomy1 = taxonomyDao.createTaxonomy("ID-30", "Competence", "", null);
    Taxonomy taxonomy2 = taxonomyDao.createTaxonomy("ID-31", "Competence", "", null);
    TaxonomyLevel levelA = taxonomyLevelDao.createTaxonomyLevel("ID-Level-A", "Competence level", "A competence", null, null, null, null, taxonomy1);
    TaxonomyLevel levelB = taxonomyLevelDao.createTaxonomyLevel("ID-Level-B", "Competence level", "B competence", null, null, null, null, taxonomy1);
    TaxonomyLevel levelC = taxonomyLevelDao.createTaxonomyLevel("ID-Level-C", "Competence level", "C competence", null, null, null, null, taxonomy2);
    taxonomyCompetenceDao.createTaxonomyCompetence(TaxonomyCompetenceTypes.target, levelA, id1, null);
    taxonomyCompetenceDao.createTaxonomyCompetence(TaxonomyCompetenceTypes.have, levelB, id1, null);
    taxonomyCompetenceDao.createTaxonomyCompetence(TaxonomyCompetenceTypes.target, levelC, id1, null);
    taxonomyCompetenceDao.createTaxonomyCompetence(TaxonomyCompetenceTypes.target, levelA, id2, null);
    dbInstance.commitAndCloseSession();
    int deleteCompetences = taxonomyCompetenceDao.deleteCompetences(id1);
    Assert.assertEquals(3, deleteCompetences);
    List<TaxonomyCompetence> competencesID1 = taxonomyCompetenceDao.getCompetences(id1);
    Assert.assertEquals(0, competencesID1.size());
    List<TaxonomyCompetence> competencesID2 = taxonomyCompetenceDao.getCompetences(id2);
    Assert.assertEquals(1, competencesID2.size());
}
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 22 with TaxonomyCompetence

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

use of org.olat.modules.taxonomy.TaxonomyCompetence 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());
}
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 24 with TaxonomyCompetence

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

the class IdentityCompetencesController method doRemoveCompetence.

private void doRemoveCompetence(IdentityCompetenceRow row) {
    Taxonomy taxonomy = row.getTaxonomy();
    TaxonomyCompetence competence = row.getCompetence();
    String before = taxonomyService.toAuditXml(competence);
    taxonomyService.removeTaxonomyLevelCompetence(competence);
    taxonomyService.auditLog(TaxonomyCompetenceAuditLog.Action.removeCompetence, before, null, null, taxonomy, competence, assessedIdentity, getIdentity());
    loadModel();
    tableEl.reset(true, true, true);
    String competenceTypeName = translate(row.getCompetenceType().name());
    String levelDisplayName = StringHelper.escapeHtml(row.getTaxonomyLevel().getDisplayName());
    showInfo("confirm.removed.competence", new String[] { competenceTypeName, levelDisplayName });
}
Also used : Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyCompetence(org.olat.modules.taxonomy.TaxonomyCompetence)

Example 25 with TaxonomyCompetence

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

the class IdentityCompetencesController method doAddTaxonomyLevelsAsCompetence.

private void doAddTaxonomyLevelsAsCompetence(TaxonomyLevel selectedLevel, TaxonomyCompetenceTypes competenceType) {
    if (selectedLevel == null) {
        showWarning("warning.atleastone.level.competence");
    } else {
        boolean found = false;
        List<TaxonomyCompetence> currentCompetences = taxonomyService.getTaxonomyCompetences(assessedIdentity, competenceType);
        for (TaxonomyCompetence currentCompetence : currentCompetences) {
            if (selectedLevel.equals(currentCompetence.getTaxonomyLevel())) {
                found = true;
            }
        }
        if (!found) {
            TaxonomyLevel taxonomyLevel = taxonomyService.getTaxonomyLevel(selectedLevel);
            Taxonomy taxonomy = taxonomyLevel.getTaxonomy();
            TaxonomyCompetence competence = taxonomyService.addTaxonomyLevelCompetences(taxonomyLevel, assessedIdentity, competenceType, null);
            String after = taxonomyService.toAuditXml(competence);
            taxonomyService.auditLog(TaxonomyCompetenceAuditLog.Action.addCompetence, null, after, null, taxonomy, competence, assessedIdentity, getIdentity());
        }
        loadModel();
        tableEl.reset(true, true, true);
    }
}
Also used : Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) TaxonomyCompetence(org.olat.modules.taxonomy.TaxonomyCompetence)

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