Search in sources :

Example 1 with TaxonomyCompetenceTypes

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

the class TaxonomyCompetenceDAO method hasCompetenceByTaxonomy.

public boolean hasCompetenceByTaxonomy(TaxonomyRef taxonomy, IdentityRef identity, Date date, TaxonomyCompetenceTypes... competences) {
    List<String> competenceList = new ArrayList<>(5);
    if (competences != null && competences.length > 0 && competences[0] != null) {
        for (TaxonomyCompetenceTypes competence : competences) {
            competenceList.add(competence.name());
        }
    }
    StringBuilder sb = new StringBuilder(256);
    sb.append("select competence.key from ctaxonomycompetence competence").append(" inner join competence.taxonomyLevel taxonomyLevel").append(" where taxonomyLevel.taxonomy.key=:taxonomyKey and competence.identity.key=:identityKey").append(" and (competence.expiration is null or competence.expiration>=:date)");
    if (competenceList.size() > 0) {
        sb.append(" and competence.type in (:types)");
    }
    TypedQuery<Long> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Long.class).setParameter("taxonomyKey", taxonomy.getKey()).setParameter("identityKey", identity.getKey()).setParameter("date", CalendarUtils.removeTime(date)).setFirstResult(0).setMaxResults(1);
    if (competenceList.size() > 0) {
        query.setParameter("types", competenceList);
    }
    List<Long> keys = query.getResultList();
    return keys != null && keys.size() > 0 && keys.get(0) != null && keys.get(0).intValue() > 0;
}
Also used : ArrayList(java.util.ArrayList) TaxonomyCompetenceTypes(org.olat.modules.taxonomy.TaxonomyCompetenceTypes)

Example 2 with TaxonomyCompetenceTypes

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

the class EditTaxonomyCompetenceController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    String fullName = userManager.getUserDisplayName(competence.getIdentity());
    uifactory.addStaticTextElement("taxonomy.competence.fullName", fullName, formLayout);
    TaxonomyCompetenceTypes competenceType = competence.getCompetenceType();
    String type = translate(competenceType.name());
    uifactory.addStaticTextElement("taxonomy.competence.type", type, formLayout);
    TaxonomyLevelManagedFlag marker = TaxonomyLevelManagedFlag.getCorrespondingFlag(competenceType);
    expirationEl = uifactory.addDateChooser("taxonomy.competence.expiration", competence.getExpiration(), formLayout);
    expirationEl.setEnabled(!TaxonomyLevelManagedFlag.isManaged(taxonomyLevel, marker));
    FormLayoutContainer buttonsCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
    formLayout.add(buttonsCont);
    uifactory.addFormCancelButton("cancel", buttonsCont, ureq, getWindowControl());
    if (expirationEl.isEnabled()) {
        // save only if there is something to update
        uifactory.addFormSubmitButton("save", buttonsCont);
    }
}
Also used : FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) TaxonomyCompetenceTypes(org.olat.modules.taxonomy.TaxonomyCompetenceTypes) TaxonomyLevelManagedFlag(org.olat.modules.taxonomy.TaxonomyLevelManagedFlag)

Example 3 with TaxonomyCompetenceTypes

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

the class TaxonomyTreeBuilder method computePermissions.

private void computePermissions(TaxonomyTreeNode root) {
    List<TaxonomyCompetence> competences = taxonomyService.getTaxonomyCompetences(taxonomy, identity, new Date());
    Map<TaxonomyLevel, List<TaxonomyCompetenceTypes>> levelToCompetences = new HashMap<>();
    for (TaxonomyCompetence competence : competences) {
        TaxonomyLevel level = competence.getTaxonomyLevel();
        if (levelToCompetences.containsKey(level)) {
            levelToCompetences.get(level).add(competence.getCompetenceType());
        } else {
            List<TaxonomyCompetenceTypes> types = new ArrayList<>(4);
            types.add(competence.getCompetenceType());
            levelToCompetences.put(level, types);
        }
    }
    computePermissionsRecursive(root, levelToCompetences);
    trimRecursive(root);
}
Also used : HashMap(java.util.HashMap) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TaxonomyCompetence(org.olat.modules.taxonomy.TaxonomyCompetence) TaxonomyCompetenceTypes(org.olat.modules.taxonomy.TaxonomyCompetenceTypes) Date(java.util.Date)

Example 4 with TaxonomyCompetenceTypes

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

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

the class TaxonomyLevelCompetenceController method event.

@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    if (userSearchCtrl == source) {
        if (event instanceof SingleIdentityChosenEvent) {
            SingleIdentityChosenEvent singleEvent = (SingleIdentityChosenEvent) event;
            Identity choosenIdentity = singleEvent.getChosenIdentity();
            if (choosenIdentity != null) {
                List<Identity> toAdd = Collections.singletonList(choosenIdentity);
                doAddCompetence(toAdd, (TaxonomyCompetenceTypes) userSearchCtrl.getUserObject());
                loadModel();
            }
        } else if (event instanceof MultiIdentityChosenEvent) {
            MultiIdentityChosenEvent multiEvent = (MultiIdentityChosenEvent) event;
            List<Identity> toAdd = multiEvent.getChosenIdentities();
            if (toAdd.size() > 0) {
                doAddCompetence(toAdd, (TaxonomyCompetenceTypes) userSearchCtrl.getUserObject());
                loadModel();
            }
        }
        cmc.deactivate();
        cleanUp();
    } else if (confirmDeleteDialog == source) {
        if (DialogBoxUIFactory.isOkEvent(event) || DialogBoxUIFactory.isYesEvent(event)) {
            @SuppressWarnings("unchecked") List<TaxonomyLevelCompetenceRow> selectedRows = (List<TaxonomyLevelCompetenceRow>) confirmDeleteDialog.getUserObject();
            doRemoveCompetences(selectedRows);
        }
    } else if (editCompetenceCtrl == source) {
        if (event == Event.DONE_EVENT || event == Event.CHANGED_EVENT) {
            loadModel();
            tableEl.reset(false, false, true);
        }
        cmc.deactivate();
        cleanUp();
    } else if (addCompetencesCallout == source) {
        cleanUp();
    } else if (cmc == source) {
        cleanUp();
    }
    super.event(ureq, source, event);
}
Also used : SingleIdentityChosenEvent(org.olat.basesecurity.events.SingleIdentityChosenEvent) List(java.util.List) ArrayList(java.util.ArrayList) TaxonomyCompetenceTypes(org.olat.modules.taxonomy.TaxonomyCompetenceTypes) Identity(org.olat.core.id.Identity) MultiIdentityChosenEvent(org.olat.basesecurity.events.MultiIdentityChosenEvent)

Aggregations

TaxonomyCompetenceTypes (org.olat.modules.taxonomy.TaxonomyCompetenceTypes)18 ArrayList (java.util.ArrayList)8 TaxonomyLevel (org.olat.modules.taxonomy.TaxonomyLevel)8 List (java.util.List)6 Date (java.util.Date)4 Identity (org.olat.core.id.Identity)4 TaxonomyCompetence (org.olat.modules.taxonomy.TaxonomyCompetence)4 TaxonomyLevelManagedFlag (org.olat.modules.taxonomy.TaxonomyLevelManagedFlag)4 HashMap (java.util.HashMap)2 MultiIdentityChosenEvent (org.olat.basesecurity.events.MultiIdentityChosenEvent)2 SingleIdentityChosenEvent (org.olat.basesecurity.events.SingleIdentityChosenEvent)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2 Roles (org.olat.core.id.Roles)2 UserSession (org.olat.core.util.UserSession)2 TaxonomyLevelType (org.olat.modules.taxonomy.TaxonomyLevelType)2 TaxonomyRef (org.olat.modules.taxonomy.TaxonomyRef)2 TaxonomyLevelRefImpl (org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl)2 TaxonomyRefImpl (org.olat.modules.taxonomy.model.TaxonomyRefImpl)2 TaxonomyTreeNode (org.olat.modules.taxonomy.model.TaxonomyTreeNode)2 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)2