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());
}
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());
}
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());
}
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 });
}
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);
}
}
Aggregations