Search in sources :

Example 26 with TaxonomyCompetence

use of org.olat.modules.taxonomy.TaxonomyCompetence 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 27 with TaxonomyCompetence

use of org.olat.modules.taxonomy.TaxonomyCompetence 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)

Example 28 with TaxonomyCompetence

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

the class TaxonomyCompetenceDAO method deleteCompetence.

public void deleteCompetence(TaxonomyCompetence competence) {
    TaxonomyCompetence reloadedCompetence = dbInstance.getCurrentEntityManager().getReference(TaxonomyCompetenceImpl.class, competence.getKey());
    dbInstance.getCurrentEntityManager().remove(reloadedCompetence);
}
Also used : TaxonomyCompetence(org.olat.modules.taxonomy.TaxonomyCompetence)

Example 29 with TaxonomyCompetence

use of org.olat.modules.taxonomy.TaxonomyCompetence in project OpenOLAT by OpenOLAT.

the class TaxonomyWebService method getTaxonomyComptencesByIdentity.

/**
 * 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();
}
Also used : ArrayList(java.util.ArrayList) 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)

Example 30 with TaxonomyCompetence

use of org.olat.modules.taxonomy.TaxonomyCompetence in project OpenOLAT by OpenOLAT.

the class TaxonomyWebService method removeTaxonomyLevelCompetence.

/**
 * Remove a competence.
 *
 * @response.representation.200.doc The competence was removed sucessfully
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The competence was not found
 * @param taxonomyKey The taxonomy tree
 * @param taxonomyLevelKey The taxonomy level
 * @param competenceKey The competence to remove
 * @param httpRequest  The HTTP request
 * @return Nothing
 */
@DELETE
@Path("levels/{taxonomyLevelKey}/competences/{competenceKey}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response removeTaxonomyLevelCompetence(@PathParam("taxonomyLevelKey") Long taxonomyLevelKey, @PathParam("competenceKey") Long competenceKey, @Context HttpServletRequest httpRequest) {
    Identity executor = getIdentity(httpRequest);
    TaxonomyCompetence competence = taxonomyService.getTaxonomyCompetence(new TaxonomyCompetenceRefImpl(competenceKey));
    if (competence == null || !competence.getTaxonomyLevel().getKey().equals(taxonomyLevelKey)) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    String before = taxonomyService.toAuditXml(competence);
    taxonomyService.removeTaxonomyLevelCompetence(competence);
    taxonomyService.auditLog(TaxonomyCompetenceAuditLog.Action.removeCompetence, before, null, null, taxonomy, competence, competence.getIdentity(), executor);
    return Response.ok().build();
}
Also used : TaxonomyCompetenceRefImpl(org.olat.modules.taxonomy.model.TaxonomyCompetenceRefImpl) 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) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes)

Aggregations

TaxonomyCompetence (org.olat.modules.taxonomy.TaxonomyCompetence)50 TaxonomyLevel (org.olat.modules.taxonomy.TaxonomyLevel)38 Identity (org.olat.core.id.Identity)36 Taxonomy (org.olat.modules.taxonomy.Taxonomy)34 Test (org.junit.Test)26 Date (java.util.Date)10 ArrayList (java.util.ArrayList)8 Consumes (javax.ws.rs.Consumes)8 Path (javax.ws.rs.Path)8 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)8 GET (javax.ws.rs.GET)6 Produces (javax.ws.rs.Produces)6 TaxonomyLevelRefImpl (org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl)6 URI (java.net.URI)4 HttpResponse (org.apache.http.HttpResponse)4 TaxonomyCompetenceTypes (org.olat.modules.taxonomy.TaxonomyCompetenceTypes)4 HashMap (java.util.HashMap)2 List (java.util.List)2 DELETE (javax.ws.rs.DELETE)2 HttpDelete (org.apache.http.client.methods.HttpDelete)2