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;
}
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);
}
}
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);
}
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();
}
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);
}
Aggregations