Skip to content
Snippets Groups Projects
Commit e2bd0d8a authored by gnaegi's avatar gnaegi
Browse files

Merge with 47d367bf47833dfdf192cddefee651a06974a28b

parents 6cf2d149 67f9a617
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
......
......@@ -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();
}
}
......
......@@ -378,7 +378,11 @@ public class RepositoryServiceImpl implements RepositoryService {
public RepositoryEntry restoreRepositoryEntry(RepositoryEntry entry) {
RepositoryEntry reloadedRe = repositoryEntryDAO.loadForUpdate(entry);
reloadedRe.setAccess(RepositoryEntry.ACC_OWNERS);
reloadedRe.setStatusCode(RepositoryEntryStatus.REPOSITORY_STATUS_CLOSED);
if("CourseModule".equals(reloadedRe.getOlatResource().getResourceableTypeName())) {
reloadedRe.setStatusCode(RepositoryEntryStatus.REPOSITORY_STATUS_CLOSED);
} else {
reloadedRe.setStatusCode(RepositoryEntryStatus.REPOSITORY_STATUS_OPEN);
}
reloadedRe = dbInstance.getCurrentEntityManager().merge(reloadedRe);
dbInstance.commit();
return reloadedRe;
......
......@@ -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);
......
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