Search in sources :

Example 41 with TaxonomyLevel

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

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

Example 43 with TaxonomyLevel

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

the class DeleteTaxonomyLevelController method initForm.

private void initForm(FormItemContainer formLayout, UserRequest ureq) {
    StringBuilder sb = new StringBuilder();
    for (TaxonomyLevel level : levels) {
        if (sb.length() > 0)
            sb.append(", ");
        sb.append(StringHelper.escapeHtml(level.getDisplayName()));
    }
    if (formLayout instanceof FormLayoutContainer) {
        FormLayoutContainer layoutCont = (FormLayoutContainer) formLayout;
        String text = translate("confirmation.delete.level", new String[] { sb.toString() });
        layoutCont.contextPut("msg", text);
        layoutCont.contextPut("msgForList", translate("error.delete.num"));
        buildDangerMessage(layoutCont);
    }
    List<String> keyList = new ArrayList<>();
    List<String> valueList = new ArrayList<>();
    keyList.add("-");
    valueList.add("-");
    buildMergeToSelection(treeModel.getRootNode(), "", keyList, valueList);
    mergeToEl = uifactory.addDropdownSingleselect("mergeto", "merge.to", formLayout, keyList.toArray(new String[keyList.size()]), valueList.toArray(new String[valueList.size()]), null);
    mergeToEl.setEscapeHtml(false);
    uifactory.addFormCancelButton("cancel", formLayout, ureq, getWindowControl());
    uifactory.addFormSubmitButton("delete", formLayout);
}
Also used : TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)

Example 44 with TaxonomyLevel

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

the class DeleteTaxonomyLevelController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    StringBuilder sb = new StringBuilder();
    if (levels.size() > 1) {
        Collections.sort(levels, new TaxonomyLevelDepthComparator());
    }
    TaxonomyLevel mergeTo = null;
    if (mergeToEl.isOneSelected() && !"-".equals(mergeToEl.getSelectedKey())) {
        String selectedNodeKey = mergeToEl.getSelectedKey();
        TreeNode selectedNode = treeModel.getNodeById(selectedNodeKey);
        mergeTo = (TaxonomyLevel) selectedNode.getUserObject();
    }
    for (TaxonomyLevel level : levels) {
        TaxonomyLevel taxonomyLevel = taxonomyService.getTaxonomyLevel(level);
        if (taxonomyService.deleteTaxonomyLevel(taxonomyLevel, mergeTo)) {
            if (sb.length() > 0)
                sb.append(", ");
            sb.append(StringHelper.escapeHtml(taxonomyLevel.getDisplayName()));
        }
    }
    // commit before sending event
    dbInstance.commit();
    fireEvent(ureq, new DeleteTaxonomyLevelEvent());
    showInfo("confirm.deleted.level", new String[] { sb.toString() });
    fireEvent(ureq, Event.DONE_EVENT);
}
Also used : TaxonomyLevelDepthComparator(org.olat.modules.taxonomy.ui.component.TaxonomyLevelDepthComparator) TreeNode(org.olat.core.gui.components.tree.TreeNode) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) DeleteTaxonomyLevelEvent(org.olat.modules.taxonomy.ui.events.DeleteTaxonomyLevelEvent)

Example 45 with TaxonomyLevel

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

the class IdentityCompetencesController method doAddTaxonomyLevelsAsCompetence.

private void doAddTaxonomyLevelsAsCompetence(TaxonomyLevel selectedLevel, TaxonomyCompetenceTypes competenceType) {
    if (selectedLevel == null) {
        showWarning("warning.atleastone.level.competence");
    } else {
        boolean found = false;
        List<TaxonomyCompetence> currentCompetences = taxonomyService.getTaxonomyCompetences(assessedIdentity, competenceType);
        for (TaxonomyCompetence currentCompetence : currentCompetences) {
            if (selectedLevel.equals(currentCompetence.getTaxonomyLevel())) {
                found = true;
            }
        }
        if (!found) {
            TaxonomyLevel taxonomyLevel = taxonomyService.getTaxonomyLevel(selectedLevel);
            Taxonomy taxonomy = taxonomyLevel.getTaxonomy();
            TaxonomyCompetence competence = taxonomyService.addTaxonomyLevelCompetences(taxonomyLevel, assessedIdentity, competenceType, null);
            String after = taxonomyService.toAuditXml(competence);
            taxonomyService.auditLog(TaxonomyCompetenceAuditLog.Action.addCompetence, null, after, null, taxonomy, competence, assessedIdentity, getIdentity());
        }
        loadModel();
        tableEl.reset(true, true, true);
    }
}
Also used : Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) TaxonomyCompetence(org.olat.modules.taxonomy.TaxonomyCompetence)

Aggregations

TaxonomyLevel (org.olat.modules.taxonomy.TaxonomyLevel)238 Taxonomy (org.olat.modules.taxonomy.Taxonomy)122 Test (org.junit.Test)106 Identity (org.olat.core.id.Identity)58 ArrayList (java.util.ArrayList)40 TaxonomyCompetence (org.olat.modules.taxonomy.TaxonomyCompetence)40 TaxonomyLevelType (org.olat.modules.taxonomy.TaxonomyLevelType)34 Date (java.util.Date)24 TaxonomyLevelRefImpl (org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl)24 URI (java.net.URI)22 HttpResponse (org.apache.http.HttpResponse)22 TreeNode (org.olat.core.gui.components.tree.TreeNode)22 GenericTreeNode (org.olat.core.gui.components.tree.GenericTreeNode)18 QuestionItemImpl (org.olat.modules.qpool.model.QuestionItemImpl)16 HashMap (java.util.HashMap)14 List (java.util.List)14 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)12 TaxonomyCompetenceTypes (org.olat.modules.taxonomy.TaxonomyCompetenceTypes)12 TaxonomyTreeNode (org.olat.modules.taxonomy.model.TaxonomyTreeNode)12 Path (javax.ws.rs.Path)10