Skip to content
Snippets Groups Projects
Commit e32a54db authored by srosse's avatar srosse
Browse files

OO-3055, OO-3047: enhance REST API...

parent bc757777
No related branches found
No related tags found
No related merge requests found
...@@ -245,7 +245,6 @@ public class TaxonomyTreeBuilder { ...@@ -245,7 +245,6 @@ public class TaxonomyTreeBuilder {
boolean subChildAllowed = trimRecursive(child); boolean subChildAllowed = trimRecursive(child);
if(!subChildAllowed && !child.isCanRead() && !child.isCanWrite()) { if(!subChildAllowed && !child.isCanRead() && !child.isCanWrite()) {
node.remove(child); node.remove(child);
System.out.println(child.getTitle());
} else { } else {
someAllowed |= true; someAllowed |= true;
} }
......
...@@ -34,6 +34,7 @@ import javax.ws.rs.Path; ...@@ -34,6 +34,7 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
import javax.ws.rs.core.EntityTag;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.Response.Status;
...@@ -209,6 +210,37 @@ public class TaxonomyWebService { ...@@ -209,6 +210,37 @@ public class TaxonomyWebService {
return Response.ok(competenceVOes.toArray(new TaxonomyCompetenceVO[competenceVOes.size()])).build(); 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 * Return the competences of a specific user on the taxonomy level
* specified in the key in path. * specified in the key in path.
...@@ -256,6 +288,7 @@ public class TaxonomyWebService { ...@@ -256,6 +288,7 @@ public class TaxonomyWebService {
* @response.representation.200.example {@link org.olat.modules.taxonomy.restapi.Examples#SAMPLE_TAXONOMYCOMPETENCEVO} * @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.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.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 taxonomyKey The taxonomy tree
* @param taxonomyLevelKey The taxonomy level * @param taxonomyLevelKey The taxonomy level
* @param comptenceVo The competence to add or update * @param comptenceVo The competence to add or update
...@@ -292,7 +325,8 @@ public class TaxonomyWebService { ...@@ -292,7 +325,8 @@ public class TaxonomyWebService {
List<TaxonomyCompetence> competences = taxonomyService.getTaxonomyLevelCompetences(level, identity); List<TaxonomyCompetence> competences = taxonomyService.getTaxonomyLevelCompetences(level, identity);
for(TaxonomyCompetence competence:competences) { for(TaxonomyCompetence competence:competences) {
if(competence.getCompetenceType().name().equals(comptenceVo.getTaxonomyCompetenceType())) { 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();
} }
} }
......
...@@ -534,10 +534,50 @@ public class TaxonomyWebServiceTest extends OlatJerseyTestCase { ...@@ -534,10 +534,50 @@ public class TaxonomyWebServiceTest extends OlatJerseyTestCase {
} }
@Test @Test
public void getTaxonomyLevelComptences_byIdentity() public void getTaxonomyComptencesByIdentity()
throws IOException, URISyntaxException { throws IOException, URISyntaxException {
// prepare a level, 2 users and 2 competences // prepare a level, 2 users and 2 competences
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("competence-4"); 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"); 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); TaxonomyLevel level = taxonomyService.createTaxonomyLevel("REST-Tax-l-7", "Level 1 on rest", "Level", "Ext-7", null, null, taxonomy);
taxonomyService.addTaxonomyLevelCompetences(level, id, TaxonomyCompetenceTypes.teach); taxonomyService.addTaxonomyLevelCompetences(level, id, TaxonomyCompetenceTypes.teach);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment