Search in sources :

Example 1 with TaxonomyLevelRefImpl

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

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 2 with TaxonomyLevelRefImpl

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

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 3 with TaxonomyLevelRefImpl

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

the class TaxonomyWebServiceTest method updateTaxonomyLevel.

/**
 * Update level.
 *
 * @throws IOException
 * @throws URISyntaxException
 */
@Test
public void updateTaxonomyLevel() throws IOException, URISyntaxException {
    Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Tax-4", "Taxonomy on rest", "PUT is cool, yes!", "PUT-tax-2");
    TaxonomyLevel rootLevel = taxonomyService.createTaxonomyLevel("REST-Tax-u-1", "Root level on rest", "Level", "Ext-25", null, null, taxonomy);
    TaxonomyLevel levelToUpdate = taxonomyService.createTaxonomyLevel("REST-Tax-u-1", "Sub level on rest", "Level", "Ext-26", null, rootLevel, taxonomy);
    TaxonomyLevelType type = taxonomyService.createTaxonomyLevelType("Sub-type", "Type for a sub level", "All is in the title", "TYP-27", taxonomy);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(taxonomy);
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    TaxonomyLevelVO levelVo = new TaxonomyLevelVO();
    levelVo.setKey(levelToUpdate.getKey());
    levelVo.setIdentifier("Updated id");
    levelVo.setDisplayName("Updated name");
    levelVo.setDescription("Updated description");
    levelVo.setExternalId("Updated ext.");
    levelVo.setTypeKey(type.getKey());
    levelVo.setParentKey(rootLevel.getKey());
    URI request = UriBuilder.fromUri(getContextURI()).path("taxonomy").path(taxonomy.getKey().toString()).path("levels").build();
    HttpPut method = conn.createPut(request, MediaType.APPLICATION_JSON, true);
    conn.addJsonEntity(method, levelVo);
    HttpResponse response = conn.execute(method);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    // check the updated value
    TaxonomyLevelVO updatedTaxonomyLevelVo = conn.parse(response, TaxonomyLevelVO.class);
    Assert.assertNotNull(updatedTaxonomyLevelVo);
    Assert.assertEquals("Updated id", updatedTaxonomyLevelVo.getIdentifier());
    Assert.assertEquals("Updated name", updatedTaxonomyLevelVo.getDisplayName());
    Assert.assertEquals("Updated description", updatedTaxonomyLevelVo.getDescription());
    Assert.assertEquals("Updated ext.", updatedTaxonomyLevelVo.getExternalId());
    Assert.assertEquals(rootLevel.getKey(), updatedTaxonomyLevelVo.getParentKey());
    Assert.assertEquals(type.getKey(), updatedTaxonomyLevelVo.getTypeKey());
    // check the database
    TaxonomyLevel savedLevel = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(updatedTaxonomyLevelVo.getKey()));
    Assert.assertNotNull(savedLevel);
    Assert.assertEquals("Updated id", savedLevel.getIdentifier());
    Assert.assertEquals("Updated name", savedLevel.getDisplayName());
    Assert.assertEquals("Updated description", savedLevel.getDescription());
    Assert.assertEquals("Updated ext.", savedLevel.getExternalId());
    Assert.assertEquals(rootLevel.getKey(), savedLevel.getParent().getKey());
    Assert.assertEquals(type.getKey(), savedLevel.getType().getKey());
}
Also used : Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyLevelVO(org.olat.modules.taxonomy.restapi.TaxonomyLevelVO) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) HttpResponse(org.apache.http.HttpResponse) TaxonomyLevelRefImpl(org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 4 with TaxonomyLevelRefImpl

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

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 5 with TaxonomyLevelRefImpl

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

the class TaxonomyWebService method getTaxonomyLevelComptencesByIdentity.

/**
 * Return the competences of a specific user 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 identityKey The user
 * @param httpRequest  The HTTP request
 * @return An array of competences
 */
@GET
@Path("levels/{taxonomyLevelKey}/competences/{identityKey}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getTaxonomyLevelComptencesByIdentity(@PathParam("taxonomyLevelKey") Long taxonomyLevelKey, @PathParam("identityKey") Long identityKey) {
    TaxonomyLevel level = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(new Long(taxonomyLevelKey)));
    if (level == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    Identity identity = securityManager.loadIdentityByKey(identityKey);
    if (identity == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    List<TaxonomyCompetence> competences = taxonomyService.getTaxonomyLevelCompetences(level, 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();
}
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) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) Identity(org.olat.core.id.Identity) 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