use of org.olat.basesecurity.model.IdentityRefImpl in project openolat by klemens.
the class GTACoachedParticipantListController method updateModel.
protected void updateModel(UserRequest ureq) {
RepositoryEntry entry = courseEnv.getCourseGroupManager().getCourseEntry();
List<TaskLight> tasks = gtaManager.getTasksLight(entry, gtaNode);
Map<Long, TaskLight> identityToTasks = new HashMap<>(tasks.size());
for (TaskLight task : tasks) {
if (task.getIdentityKey() != null) {
identityToTasks.put(task.getIdentityKey(), task);
}
}
List<IdentityMark> marks = gtaManager.getMarks(entry, gtaNode, ureq.getIdentity());
Map<Long, IdentityMark> identityToMarks = new HashMap<>(marks.size());
for (IdentityMark mark : marks) {
if (mark.getParticipant() != null) {
identityToMarks.put(mark.getParticipant().getKey(), mark);
}
}
List<AssessmentEntry> assessments = assessmentService.loadAssessmentEntriesBySubIdent(entry, gtaNode.getIdent());
Map<Long, AssessmentEntry> identityToAssessments = new HashMap<>(assessments.size());
for (AssessmentEntry assessment : assessments) {
if (assessment.getIdentity() != null) {
identityToAssessments.put(assessment.getIdentity().getKey(), assessment);
}
}
List<CoachedIdentityRow> rows = new ArrayList<>(assessableIdentities.size());
for (UserPropertiesRow assessableIdentity : assessableIdentities) {
IdentityMark mark = identityToMarks.get(assessableIdentity.getIdentityKey());
if (markedOnly && mark == null)
continue;
FormLink markLink = uifactory.addFormLink("mark_" + assessableIdentity.getIdentityKey(), "mark", "", null, null, Link.NONTRANSLATED);
markLink.setIconLeftCSS(mark != null ? Mark.MARK_CSS_LARGE : Mark.MARK_ADD_CSS_LARGE);
markLink.setUserObject(assessableIdentity.getIdentityKey());
TaskLight task = identityToTasks.get(assessableIdentity.getIdentityKey());
Date submissionDueDate = null;
if (task == null || task.getTaskStatus() == null || task.getTaskStatus() == TaskProcess.assignment) {
IdentityRef identityRef = new IdentityRefImpl(assessableIdentity.getIdentityKey());
DueDate dueDate = gtaManager.getSubmissionDueDate(task, identityRef, null, gtaNode, entry, true);
if (dueDate != null) {
submissionDueDate = dueDate.getDueDate();
}
}
Date syntheticSubmissionDate = null;
boolean hasSubmittedDocument = false;
if (task != null && task.getTaskStatus() != null && task.getTaskStatus() != TaskProcess.assignment && task.getTaskStatus() != TaskProcess.submit) {
syntheticSubmissionDate = getSyntheticSubmissionDate(task);
if (syntheticSubmissionDate != null) {
hasSubmittedDocument = hasSubmittedDocument(task);
}
}
int numSubmittedDocs = task != null && task.getSubmissionNumOfDocs() != null ? task.getSubmissionNumOfDocs() : 0;
AssessmentEntry assessment = identityToAssessments.get(assessableIdentity.getIdentityKey());
Boolean userVisibility = assessment != null ? assessment.getUserVisibility() : null;
BigDecimal score = assessment != null ? assessment.getScore() : null;
Boolean passed = assessment != null ? assessment.getPassed() : null;
rows.add(new CoachedIdentityRow(assessableIdentity, task, submissionDueDate, syntheticSubmissionDate, hasSubmittedDocument, markLink, userVisibility, score, passed, numSubmittedDocs));
}
tableModel.setObjects(rows);
tableEl.reset();
}
use of org.olat.basesecurity.model.IdentityRefImpl in project openolat by klemens.
the class LDAPLoginManagerImpl method doBatchSyncNewAndModifiedUsers.
private List<LDAPUser> doBatchSyncNewAndModifiedUsers(LdapContext ctx, String sinceSentence, Map<String, LDAPUser> dnToIdentityKeyMap, LDAPError errors) {
// Get new and modified users from LDAP
int count = 0;
List<LDAPUser> ldapUserList = ldapDao.getUserAttributesModifiedSince(lastSyncDate, ctx);
// Check for new and modified users
List<LDAPUser> newLdapUserList = new ArrayList<LDAPUser>();
Map<IdentityRef, Map<String, String>> changedMapIdentityMap = new HashMap<>();
for (LDAPUser ldapUser : ldapUserList) {
String user = null;
try {
Attributes userAttrs = ldapUser.getAttributes();
String uidProp = syncConfiguration.getOlatPropertyToLdapAttribute(LDAPConstants.LDAP_USER_IDENTIFYER);
user = getAttributeValue(userAttrs.get(uidProp));
Identity identity = findIdentityByLdapAuthentication(userAttrs, errors);
if (identity != null) {
Map<String, String> changedAttrMap = prepareUserPropertyForSync(userAttrs, identity);
if (changedAttrMap != null) {
changedMapIdentityMap.put(identity, changedAttrMap);
}
if (StringHelper.containsNonWhitespace(ldapUser.getDn())) {
dnToIdentityKeyMap.put(ldapUser.getDn(), ldapUser);
ldapUser.setCachedIdentity(new IdentityRefImpl(identity.getKey()));
}
} else if (errors.isEmpty()) {
String[] reqAttrs = syncConfiguration.checkRequestAttributes(userAttrs);
if (reqAttrs == null) {
newLdapUserList.add(ldapUser);
} else {
log.warn("LDAP batch sync: can't create user with username::" + user + " : missing required attributes::" + ArrayUtils.toString(reqAttrs), null);
}
} else {
log.warn(errors.get(), null);
}
} catch (Exception e) {
// catch here to go on with other users on exeptions!
log.error("some error occured in looping over set of changed user-attributes, actual user " + user + ". Will still continue with others.", e);
errors.insert("Cannot sync user: " + user);
} finally {
dbInstance.commit();
if (count % 10 == 0) {
dbInstance.closeSession();
}
}
if (count % 1000 == 0) {
log.info("Retrieve " + count + "/" + ldapUserList.size() + " users in LDAP server");
}
count++;
}
// sync existing users
if (changedMapIdentityMap == null || changedMapIdentityMap.isEmpty()) {
log.info("LDAP batch sync: no users to sync" + sinceSentence);
} else {
int syncCount = 0;
for (IdentityRef ident : changedMapIdentityMap.keySet()) {
// sync user is exception save, no try/catch needed
try {
syncCount++;
syncUser(changedMapIdentityMap.get(ident), ident);
} catch (Exception e) {
errors.insert("Cannot sync user: " + ident);
} finally {
dbInstance.commit();
if (syncCount % 20 == 0) {
dbInstance.closeSession();
}
}
if (syncCount % 1000 == 0) {
log.info("Update " + syncCount + "/" + changedMapIdentityMap.size() + " LDAP users");
}
}
log.info("LDAP batch sync: " + changedMapIdentityMap.size() + " users synced" + sinceSentence);
}
// create new users
if (newLdapUserList.isEmpty()) {
log.info("LDAP batch sync: no users to create" + sinceSentence);
} else {
int newCount = 0;
for (LDAPUser ldapUser : newLdapUserList) {
Attributes userAttrs = ldapUser.getAttributes();
try {
newCount++;
Identity identity = createAndPersistUser(userAttrs);
if (identity != null && StringHelper.containsNonWhitespace(ldapUser.getDn())) {
dnToIdentityKeyMap.put(ldapUser.getDn(), ldapUser);
ldapUser.setCachedIdentity(new IdentityRefImpl(identity.getKey()));
}
} catch (Exception e) {
// catch here to go on with other users on exeptions!
log.error("some error occured while creating new users, actual userAttribs " + userAttrs + ". Will still continue with others.", e);
} finally {
dbInstance.commit();
if (newCount % 20 == 0) {
dbInstance.closeSession();
}
}
if (newCount % 1000 == 0) {
log.info("Create " + count + "/" + newLdapUserList.size() + " LDAP users");
}
}
log.info("LDAP batch sync: " + newLdapUserList.size() + " users created" + sinceSentence);
}
dbInstance.commitAndCloseSession();
return ldapUserList;
}
use of org.olat.basesecurity.model.IdentityRefImpl in project OpenOLAT by OpenOLAT.
the class RepositoryEntryMembershipProcessor method processIdentityRemoved.
private void processIdentityRemoved(Long repoKey, Long identityKey) {
IdentityRef identity = new IdentityRefImpl(identityKey);
RepositoryEntryRef re = new RepositoryEntryRefImpl(repoKey);
List<String> remainingRoles = repositoryEntryRelationDao.getRoles(identity, re);
if (remainingRoles.isEmpty()) {
OLATResource resource = repositoryManager.lookupRepositoryEntryResource(repoKey);
notificationsManager.unsubscribeAllForIdentityAndResId(identity, resource.getResourceableId());
}
}
use of org.olat.basesecurity.model.IdentityRefImpl in project OpenOLAT by OpenOLAT.
the class GTACoachedParticipantListController method updateModel.
protected void updateModel(UserRequest ureq) {
RepositoryEntry entry = courseEnv.getCourseGroupManager().getCourseEntry();
List<TaskLight> tasks = gtaManager.getTasksLight(entry, gtaNode);
Map<Long, TaskLight> identityToTasks = new HashMap<>(tasks.size());
for (TaskLight task : tasks) {
if (task.getIdentityKey() != null) {
identityToTasks.put(task.getIdentityKey(), task);
}
}
List<IdentityMark> marks = gtaManager.getMarks(entry, gtaNode, ureq.getIdentity());
Map<Long, IdentityMark> identityToMarks = new HashMap<>(marks.size());
for (IdentityMark mark : marks) {
if (mark.getParticipant() != null) {
identityToMarks.put(mark.getParticipant().getKey(), mark);
}
}
List<AssessmentEntry> assessments = assessmentService.loadAssessmentEntriesBySubIdent(entry, gtaNode.getIdent());
Map<Long, AssessmentEntry> identityToAssessments = new HashMap<>(assessments.size());
for (AssessmentEntry assessment : assessments) {
if (assessment.getIdentity() != null) {
identityToAssessments.put(assessment.getIdentity().getKey(), assessment);
}
}
List<CoachedIdentityRow> rows = new ArrayList<>(assessableIdentities.size());
for (UserPropertiesRow assessableIdentity : assessableIdentities) {
IdentityMark mark = identityToMarks.get(assessableIdentity.getIdentityKey());
if (markedOnly && mark == null)
continue;
FormLink markLink = uifactory.addFormLink("mark_" + assessableIdentity.getIdentityKey(), "mark", "", null, null, Link.NONTRANSLATED);
markLink.setIconLeftCSS(mark != null ? Mark.MARK_CSS_LARGE : Mark.MARK_ADD_CSS_LARGE);
markLink.setUserObject(assessableIdentity.getIdentityKey());
TaskLight task = identityToTasks.get(assessableIdentity.getIdentityKey());
Date submissionDueDate = null;
if (task == null || task.getTaskStatus() == null || task.getTaskStatus() == TaskProcess.assignment) {
IdentityRef identityRef = new IdentityRefImpl(assessableIdentity.getIdentityKey());
DueDate dueDate = gtaManager.getSubmissionDueDate(task, identityRef, null, gtaNode, entry, true);
if (dueDate != null) {
submissionDueDate = dueDate.getDueDate();
}
}
Date syntheticSubmissionDate = null;
boolean hasSubmittedDocument = false;
if (task != null && task.getTaskStatus() != null && task.getTaskStatus() != TaskProcess.assignment && task.getTaskStatus() != TaskProcess.submit) {
syntheticSubmissionDate = getSyntheticSubmissionDate(task);
if (syntheticSubmissionDate != null) {
hasSubmittedDocument = hasSubmittedDocument(task);
}
}
int numSubmittedDocs = task != null && task.getSubmissionNumOfDocs() != null ? task.getSubmissionNumOfDocs() : 0;
AssessmentEntry assessment = identityToAssessments.get(assessableIdentity.getIdentityKey());
Boolean userVisibility = assessment != null ? assessment.getUserVisibility() : null;
BigDecimal score = assessment != null ? assessment.getScore() : null;
Boolean passed = assessment != null ? assessment.getPassed() : null;
rows.add(new CoachedIdentityRow(assessableIdentity, task, submissionDueDate, syntheticSubmissionDate, hasSubmittedDocument, markLink, userVisibility, score, passed, numSubmittedDocs));
}
tableModel.setObjects(rows);
tableEl.reset();
}
use of org.olat.basesecurity.model.IdentityRefImpl in project OpenOLAT by OpenOLAT.
the class IdentityListCourseNodeController method getSelectedIdentities.
@Override
public List<IdentityRef> getSelectedIdentities() {
Set<Integer> selections = tableEl.getMultiSelectedIndex();
List<AssessedIdentityElementRow> rows = new ArrayList<>(selections.size());
for (Integer i : selections) {
AssessedIdentityElementRow row = usersTableModel.getObject(i.intValue());
if (row != null && row.getAssessmentStatus() != AssessmentEntryStatus.done) {
rows.add(row);
}
}
if (rows == null || rows.isEmpty()) {
return Collections.emptyList();
}
List<IdentityRef> selectedIdentities = new ArrayList<>();
for (AssessedIdentityElementRow row : rows) {
selectedIdentities.add(new IdentityRefImpl(row.getIdentityKey()));
}
return selectedIdentities;
}
Aggregations