Search in sources :

Example 6 with TaxonomyLevelRefImpl

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

the class TaxonomyWebServiceTest method deleteTaxonomyLevel.

@Test
public void deleteTaxonomyLevel() throws IOException, URISyntaxException {
    Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Del-1", "Taxonomy on rest", "Delete is sad!", "DELETE-tax-1");
    TaxonomyLevel rootLevel = taxonomyService.createTaxonomyLevel("REST-Del-root", "Root level on rest", "Level", "Ext-55", null, null, taxonomy);
    TaxonomyLevel levelToDelete = taxonomyService.createTaxonomyLevel("REST-Del-u-1", "Sub level on rest", "Level", "Ext-56", null, rootLevel, taxonomy);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(taxonomy);
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    URI request = UriBuilder.fromUri(getContextURI()).path("taxonomy").path(taxonomy.getKey().toString()).path("levels").path(levelToDelete.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 deleted value
    TaxonomyLevel deletedLevel = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(levelToDelete.getKey()));
    Assert.assertNull(deletedLevel);
    TaxonomyLevel survivingRootLevel = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(rootLevel.getKey()));
    Assert.assertNotNull(survivingRootLevel);
}
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) TaxonomyLevelRefImpl(org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl) URI(java.net.URI) Test(org.junit.Test)

Example 7 with TaxonomyLevelRefImpl

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

the class TaxonomyLevelLibraryIndexer method checkAccess.

@Override
public boolean checkAccess(ContextEntry contextEntry, BusinessControl businessControl, Identity identity, Roles roles) {
    if (roles.isOLATAdmin())
        return true;
    if ("TaxonomyLevel".equals(contextEntry.getOLATResourceable().getResourceableTypeName())) {
        Long levelKey = contextEntry.getOLATResourceable().getResourceableId();
        TaxonomyLevel level = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(levelKey));
        TaxonomyTreeBuilder builder = new TaxonomyTreeBuilder(level.getTaxonomy(), identity, null, false, true, "Templates", null);
        TreeModel model = builder.buildTreeModel();
        List<TreeNode> flat = new ArrayList<>();
        TreeHelper.makeTreeFlat(model.getRootNode(), flat);
        for (TreeNode node : flat) {
            TaxonomyTreeNode taxonomyNode = (TaxonomyTreeNode) node;
            if (taxonomyNode.getType() == TaxonomyTreeNodeType.taxonomyLevel && level.equals(taxonomyNode.getTaxonomyLevel())) {
                if (taxonomyNode.isDocumentsLibraryEnabled() && taxonomyNode.isCanRead()) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : TreeModel(org.olat.core.gui.components.tree.TreeModel) TreeNode(org.olat.core.gui.components.tree.TreeNode) TaxonomyTreeNode(org.olat.modules.taxonomy.model.TaxonomyTreeNode) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) ArrayList(java.util.ArrayList) TaxonomyTreeNode(org.olat.modules.taxonomy.model.TaxonomyTreeNode) TaxonomyLevelRefImpl(org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl) TaxonomyTreeBuilder(org.olat.modules.taxonomy.manager.TaxonomyTreeBuilder)

Example 8 with TaxonomyLevelRefImpl

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

the class TaxonomyWebService method addTaxonomyLevelComptencesByIdentity.

private Response addTaxonomyLevelComptencesByIdentity(Long taxonomyLevelKey, TaxonomyCompetenceVO comptenceVo, Identity executor) {
    if (taxonomyLevelKey != null && comptenceVo.getTaxonomyLevelKey() != null && !taxonomyLevelKey.equals(comptenceVo.getTaxonomyLevelKey())) {
        return Response.serverError().status(Status.CONFLICT).build();
    }
    if (taxonomyLevelKey == null) {
        taxonomyLevelKey = comptenceVo.getTaxonomyLevelKey();
    }
    TaxonomyLevel level = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(new Long(taxonomyLevelKey)));
    if (level == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    Identity identity = securityManager.loadIdentityByKey(comptenceVo.getIdentityKey());
    if (identity == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    TaxonomyCompetence competence = null;
    List<TaxonomyCompetence> competences = taxonomyService.getTaxonomyLevelCompetences(level, identity);
    for (TaxonomyCompetence c : competences) {
        if (c.getCompetenceType().name().equals(comptenceVo.getTaxonomyCompetenceType())) {
            competence = c;
        }
    }
    if (competence == null) {
        TaxonomyCompetenceTypes competenceType = TaxonomyCompetenceTypes.valueOf(comptenceVo.getTaxonomyCompetenceType());
        competence = taxonomyService.addTaxonomyLevelCompetences(level, identity, competenceType, comptenceVo.getExpiration());
    } else {
        competence.setExpiration(comptenceVo.getExpiration());
        competence = taxonomyService.updateTaxonomyLevelCompetence(competence);
    }
    String after = taxonomyService.toAuditXml(competence);
    taxonomyService.auditLog(TaxonomyCompetenceAuditLog.Action.addCompetence, null, after, null, taxonomy, competence, identity, executor);
    return Response.ok(new TaxonomyCompetenceVO(competence)).build();
}
Also used : TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) TaxonomyLevelRefImpl(org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl) TaxonomyCompetence(org.olat.modules.taxonomy.TaxonomyCompetence) TaxonomyCompetenceTypes(org.olat.modules.taxonomy.TaxonomyCompetenceTypes) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) Identity(org.olat.core.id.Identity)

Example 9 with TaxonomyLevelRefImpl

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

the class TaxonomyWebService method deleteTaxonomyLevel.

/**
 * Delete the taxonomy level definitively.
 *
 * @response.representation.200.doc The level was successfully deleted
 * @response.representation.304.doc The level cannot be deleted and was not modified
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The level was not found
 * @response.representation.404.doc The level taxonomy doesn't match the taxonomy of the web service
 *
 * @param taxonomyKey The taxonomy tree
 * @param taxonomyLevelKey The level of the taxonomy to delete
 * @return Nothing
 */
@DELETE
@Path("levels/{taxonomyLevelKey}")
public Response deleteTaxonomyLevel(@PathParam("taxonomyLevelKey") String taxonomyLevelKey) {
    TaxonomyLevel level = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(new Long(taxonomyLevelKey)));
    if (level == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    if (level.getTaxonomy() != null && !level.getTaxonomy().equals(taxonomy)) {
        return Response.serverError().status(Status.CONFLICT).build();
    }
    boolean canDelete = taxonomyService.deleteTaxonomyLevel(level, null);
    if (canDelete) {
        return Response.ok().build();
    }
    return Response.notModified().build();
}
Also used : TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) TaxonomyLevelRefImpl(org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 10 with TaxonomyLevelRefImpl

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

the class TaxonomyWebService method getTaxonomyLevelComptences.

/**
 * Return the competences of users on the taxonomy level specified in the key in path.
 *
 * @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 taxonomyLevelKey The level of the taxonomy
 * @param httpRequest  The HTTP request
 * @return An array of competences
 */
@GET
@Path("levels/{taxonomyLevelKey}/competences")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getTaxonomyLevelComptences(@PathParam("taxonomyLevelKey") Long taxonomyLevelKey) {
    TaxonomyLevel level = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(new Long(taxonomyLevelKey)));
    if (level == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    List<TaxonomyCompetence> competences = taxonomyService.getTaxonomyLevelCompetences(level);
    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();
}
Also used : TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) ArrayList(java.util.ArrayList) TaxonomyLevelRefImpl(org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl) TaxonomyCompetence(org.olat.modules.taxonomy.TaxonomyCompetence) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

TaxonomyLevel (org.olat.modules.taxonomy.TaxonomyLevel)24 TaxonomyLevelRefImpl (org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl)24 Taxonomy (org.olat.modules.taxonomy.Taxonomy)10 URI (java.net.URI)8 Path (javax.ws.rs.Path)8 HttpResponse (org.apache.http.HttpResponse)8 Test (org.junit.Test)8 TaxonomyLevelType (org.olat.modules.taxonomy.TaxonomyLevelType)8 ArrayList (java.util.ArrayList)6 Consumes (javax.ws.rs.Consumes)6 Produces (javax.ws.rs.Produces)6 TaxonomyCompetence (org.olat.modules.taxonomy.TaxonomyCompetence)6 GET (javax.ws.rs.GET)4 HttpDelete (org.apache.http.client.methods.HttpDelete)4 HttpPut (org.apache.http.client.methods.HttpPut)4 Identity (org.olat.core.id.Identity)4 TaxonomyLevelTypeRefImpl (org.olat.modules.taxonomy.model.TaxonomyLevelTypeRefImpl)4 TaxonomyLevelVO (org.olat.modules.taxonomy.restapi.TaxonomyLevelVO)4 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)4 DELETE (javax.ws.rs.DELETE)2