diff --git a/src/main/java/org/olat/modules/taxonomy/manager/TaxonomyTreeBuilder.java b/src/main/java/org/olat/modules/taxonomy/manager/TaxonomyTreeBuilder.java index 11e3ebd75055247fefcd1aa68464fa31e942831e..2434a83506233e3da033d69b001fbf41d8380a6b 100644 --- a/src/main/java/org/olat/modules/taxonomy/manager/TaxonomyTreeBuilder.java +++ b/src/main/java/org/olat/modules/taxonomy/manager/TaxonomyTreeBuilder.java @@ -245,7 +245,6 @@ public class TaxonomyTreeBuilder { boolean subChildAllowed = trimRecursive(child); if(!subChildAllowed && !child.isCanRead() && !child.isCanWrite()) { node.remove(child); - System.out.println(child.getTitle()); } else { someAllowed |= true; } diff --git a/src/main/java/org/olat/modules/taxonomy/restapi/TaxonomyWebService.java b/src/main/java/org/olat/modules/taxonomy/restapi/TaxonomyWebService.java index 3fe897cbd8e69fb7c201af9c525e640e050ebb04..f735937732a0932f0d838a98c7883d7c0a667387 100644 --- a/src/main/java/org/olat/modules/taxonomy/restapi/TaxonomyWebService.java +++ b/src/main/java/org/olat/modules/taxonomy/restapi/TaxonomyWebService.java @@ -34,6 +34,7 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.Context; +import javax.ws.rs.core.EntityTag; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; @@ -209,6 +210,37 @@ public class TaxonomyWebService { return Response.ok(competenceVOes.toArray(new TaxonomyCompetenceVO[competenceVOes.size()])).build(); } + /** + * Return the competences of a specific user in the taxonomy tree. + * + * @response.representation.200.qname {http://www.example.com}taxonomyCompetenceVO + * @response.representation.200.mediaType application/xml, application/json + * @response.representation.200.doc An array of competences + * @response.representation.200.example {@link org.olat.modules.taxonomy.restapi.Examples#SAMPLE_TAXONOMYCOMPETENCEVO} + * @response.representation.401.doc The roles of the authenticated user are not sufficient + * @param taxonomyKey The taxonomy tree + * @param identityKey The user + * @param httpRequest The HTTP request + * @return An array of competences + */ + @GET + @Path("competences/{identityKey}") + @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public Response getTaxonomyComptencesByIdentity(@PathParam("identityKey") Long identityKey) { + Identity identity = securityManager.loadIdentityByKey(identityKey); + if(identity == null) { + return Response.serverError().status(Status.NOT_FOUND).build(); + } + + List<TaxonomyCompetence> competences = taxonomyService.getTaxonomyCompetences(identity); + List<TaxonomyCompetenceVO> competenceVOes = new ArrayList<>(competences.size()); + for(TaxonomyCompetence competence:competences) { + competenceVOes.add(new TaxonomyCompetenceVO(competence)); + } + return Response.ok(competenceVOes.toArray(new TaxonomyCompetenceVO[competenceVOes.size()])).build(); + } + /** * Return the competences of a specific user on the taxonomy level * specified in the key in path. @@ -256,6 +288,7 @@ public class TaxonomyWebService { * @response.representation.200.example {@link org.olat.modules.taxonomy.restapi.Examples#SAMPLE_TAXONOMYCOMPETENCEVO} * @response.representation.401.doc The roles of the authenticated user are not sufficient * @response.representation.404.doc The taxonomy level type to update was not found + * @response.representation.409.doc The taxonomy level key of the competence doesn't match the one in URL * @param taxonomyKey The taxonomy tree * @param taxonomyLevelKey The taxonomy level * @param comptenceVo The competence to add or update @@ -292,7 +325,8 @@ public class TaxonomyWebService { List<TaxonomyCompetence> competences = taxonomyService.getTaxonomyLevelCompetences(level, identity); for(TaxonomyCompetence competence:competences) { if(competence.getCompetenceType().name().equals(comptenceVo.getTaxonomyCompetenceType())) { - return Response.ok(new TaxonomyCompetenceVO(competence)).status(Status.NOT_MODIFIED).build(); + EntityTag tag = new EntityTag(competence.getKey().toString()); + return Response.notModified(tag).build(); } } diff --git a/src/test/java/org/olat/restapi/TaxonomyWebServiceTest.java b/src/test/java/org/olat/restapi/TaxonomyWebServiceTest.java index 9dc77786961b0dca0628fcf57487e2b69f7ebb01..8221d6bd53609f14d353b7ec1212b7c65bef49e2 100644 --- a/src/test/java/org/olat/restapi/TaxonomyWebServiceTest.java +++ b/src/test/java/org/olat/restapi/TaxonomyWebServiceTest.java @@ -534,10 +534,50 @@ public class TaxonomyWebServiceTest extends OlatJerseyTestCase { } @Test - public void getTaxonomyLevelComptences_byIdentity() + public void getTaxonomyComptencesByIdentity() throws IOException, URISyntaxException { // prepare a level, 2 users and 2 competences Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("competence-4"); + Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Tax-20", "Taxonomy on rest", "Rest is cool", "Ext-tax-7"); + TaxonomyLevel level1 = taxonomyService.createTaxonomyLevel("REST-Tax-l-21", "Level 1 on rest", "Level", "Ext-7", null, null, taxonomy); + TaxonomyLevel level2 = taxonomyService.createTaxonomyLevel("REST-Tax-l-22", "Level 1 on rest", "Level", "Ext-7", null, null, taxonomy); + taxonomyService.addTaxonomyLevelCompetences(level1, id, TaxonomyCompetenceTypes.teach); + taxonomyService.addTaxonomyLevelCompetences(level2, id, TaxonomyCompetenceTypes.have); + dbInstance.commitAndCloseSession(); + + // get the competences + RestConnection conn = new RestConnection(); + Assert.assertTrue(conn.login("administrator", "openolat")); + + URI request = UriBuilder.fromUri(getContextURI()).path("taxonomy").path(taxonomy.getKey().toString()) + .path("competences").path(id.getKey().toString()).build(); + HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true); + HttpResponse response = conn.execute(method); + Assert.assertEquals(200, response.getStatusLine().getStatusCode()); + List<TaxonomyCompetenceVO> competenceList = parseTaxonomyComptencesArray(response.getEntity().getContent()); + Assert.assertNotNull(competenceList); + Assert.assertEquals(2, competenceList.size()); + + boolean foundComptenceId1 = false; + boolean foundComptenceId2 = false; + for(TaxonomyCompetenceVO competence:competenceList) { + if(competence.getTaxonomyLevelKey().equals(level1.getKey()) && competence.getIdentityKey().equals(id.getKey()) + && TaxonomyCompetenceTypes.teach.name().equals(competence.getTaxonomyCompetenceType())) { + foundComptenceId1 = true; + } else if(competence.getTaxonomyLevelKey().equals(level2.getKey()) && competence.getIdentityKey().equals(id.getKey()) + && TaxonomyCompetenceTypes.have.name().equals(competence.getTaxonomyCompetenceType())) { + foundComptenceId2 = true; + } + } + Assert.assertTrue(foundComptenceId1); + Assert.assertTrue(foundComptenceId2); + } + + @Test + public void getTaxonomyLevelComptences_byIdentity() + throws IOException, URISyntaxException { + // prepare a level, 1 user and 1 competence + Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("competence-4"); Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Tax-7", "Taxonomy on rest", "Rest is cool", "Ext-tax-7"); TaxonomyLevel level = taxonomyService.createTaxonomyLevel("REST-Tax-l-7", "Level 1 on rest", "Level", "Ext-7", null, null, taxonomy); taxonomyService.addTaxonomyLevelCompetences(level, id, TaxonomyCompetenceTypes.teach);