use of org.olat.basesecurity.IdentityRef in project openolat by klemens.
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;
}
use of org.olat.basesecurity.IdentityRef in project openolat by klemens.
the class IdentityListCourseNodeController method doUpdateCompletion.
private void doUpdateCompletion(Double completion, AssessmentRunStatus status, AssessedIdentityElementRow row) {
row.getCurrentCompletion().setCompletion(completion);
boolean endedRow = row.getCurrentCompletion().isEnded();
boolean endedEvent = status != null && AssessmentRunStatus.done.equals(status);
row.getCurrentCompletion().setEnded(endedEvent);
if (endedEvent && !endedRow) {
IdentityRef assessedIdentity = new IdentityRefImpl(row.getIdentityKey());
AssessmentEntry assessmentEntry = assessmentToolManager.getAssessmentEntries(assessedIdentity, courseEntry, courseNode.getIdent());
row.setAssessmentEntry(assessmentEntry);
tableEl.getComponent().setDirty(true);
}
}
use of org.olat.basesecurity.IdentityRef 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.IdentityRef 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.IdentityRef in project OpenOLAT by OpenOLAT.
the class RepositoryEntryAuthorQueries method createViewQuery.
protected <T> TypedQuery<T> createViewQuery(SearchAuthorRepositoryEntryViewParams params, Class<T> type) {
IdentityRef identity = params.getIdentity();
Roles roles = params.getRoles();
List<String> resourceTypes = params.getResourceTypes();
boolean oracle = "oracle".equals(dbInstance.getDbVendor());
boolean admin = (roles != null && (roles.isInstitutionalResourceManager() || roles.isOLATAdmin()));
boolean count = Number.class.equals(type);
boolean needIdentity = false;
StringBuilder sb = new StringBuilder();
if (count) {
sb.append("select count(v.key) ").append(" from repositoryentry as v").append(" inner join v.olatResource as res").append(" left join v.lifecycle as lifecycle");
} else {
sb.append("select v, ");
if (params.getMarked() != null && params.getMarked().booleanValue()) {
sb.append(" 1 as marks,");
} else {
sb.append(" (select count(mark.key) from ").append(MarkImpl.class.getName()).append(" as mark ").append(" where mark.creator.key=:identityKey and mark.resId=v.key and mark.resName='RepositoryEntry'").append(" ) as marks,");
needIdentity = true;
}
sb.append(" (select count(offer.key) from acoffer as offer ").append(" where offer.resource.key=res.key and offer.valid=true").append(" ) as offers,").append(" (select count(ref.key) from references as ref ").append(" where ref.target.key=res.key").append(" ) as references").append(" from repositoryentry as v").append(" inner join ").append(oracle ? "" : "fetch").append(" v.olatResource as res").append(" inner join fetch v.statistics as stats").append(" left join fetch v.lifecycle as lifecycle ");
if (params.isDeleted()) {
sb.append(" left join fetch v.deletedBy as deletedBy").append(" left join fetch deletedBy.user as deletedByUser");
}
}
sb.append(" where");
if (params.isOwnedResourcesOnly()) {
needIdentity = true;
sb.append(" v.key in (select rel.entry.key from repoentrytogroup as rel, bgroupmember as membership").append(" where rel.group.key=membership.group.key and membership.identity.key=:identityKey").append(" and membership.role='").append(GroupRoles.owner.name()).append("'").append(" )");
if (params.isDeleted()) {
sb.append(" and v.access=").append(RepositoryEntry.DELETED);
} else {
sb.append(" and v.access>=").append(RepositoryEntry.ACC_OWNERS);
}
} else if (admin) {
if (params.isDeleted()) {
sb.append(" v.access=").append(RepositoryEntry.DELETED);
} else {
sb.append(" v.access>=").append(RepositoryEntry.ACC_OWNERS);
}
} else {
needIdentity = true;
sb.append(" (v.access>=").append(RepositoryEntry.ACC_OWNERS_AUTHORS).append(" or (v.access=").append(RepositoryEntry.ACC_OWNERS).append(" and v.key in (select rel.entry.key from repoentrytogroup as rel, bgroupmember as membership").append(" where rel.group.key=membership.group.key and membership.identity.key=:identityKey").append(" and membership.role='").append(GroupRoles.owner.name()).append("'").append(" )").append(" ))");
}
if (params.getClosed() != null) {
if (params.getClosed().booleanValue()) {
sb.append(" and v.statusCode>0");
} else {
sb.append(" and v.statusCode=0");
}
}
if (params.getResourceUsage() != null && params.getResourceUsage() != ResourceUsage.all) {
sb.append(" and res.resName!='CourseModule' and");
if (params.getResourceUsage() == ResourceUsage.notUsed) {
sb.append(" not");
}
sb.append(" exists (select ref.key from references as ref where ref.target.key=res.key)");
}
if (params.getRepoEntryKeys() != null && params.getRepoEntryKeys().size() > 0) {
sb.append(" and v.key in (:repoEntryKeys)");
}
if (params.isResourceTypesDefined()) {
sb.append(" and res.resName in (:resourcetypes)");
}
if (params.getMarked() != null && params.getMarked().booleanValue()) {
needIdentity = true;
sb.append(" and exists (select mark2.key from ").append(MarkImpl.class.getName()).append(" as mark2 ").append(" where mark2.creator.key=:identityKey and mark2.resId=v.key and mark2.resName='RepositoryEntry'").append(" )");
}
if (params.isLicenseTypeDefined()) {
sb.append(" and exists (");
sb.append(" select license.key from license as license");
sb.append(" where license.resId=res.resId and license.resName=res.resName");
sb.append(" and license.licenseType.key in (:licenseTypeKeys))");
}
String author = params.getAuthor();
if (StringHelper.containsNonWhitespace(author)) {
// fuzzy author search
author = PersistenceHelper.makeFuzzyQueryString(author);
sb.append(" and v.key in (select rel.entry.key from repoentrytogroup as rel, bgroupmember as membership, ").append(IdentityImpl.class.getName()).append(" as identity, ").append(UserImpl.class.getName()).append(" as user").append(" where rel.group.key=membership.group.key and membership.identity.key=identity.key and user.identity.key=identity.key").append(" and membership.role='").append(GroupRoles.owner.name()).append("'").append(" and (");
PersistenceHelper.appendFuzzyLike(sb, "user.firstName", "author", dbInstance.getDbVendor());
sb.append(" or ");
PersistenceHelper.appendFuzzyLike(sb, "user.lastName", "author", dbInstance.getDbVendor());
sb.append(" or ");
PersistenceHelper.appendFuzzyLike(sb, "identity.name", "author", dbInstance.getDbVendor());
sb.append(" ))");
}
String displayname = params.getDisplayname();
if (StringHelper.containsNonWhitespace(displayname)) {
// displayName = '%' + displayName.replace('*', '%') + '%';
// query.append(" and v.displayname like :displayname");
displayname = PersistenceHelper.makeFuzzyQueryString(displayname);
sb.append(" and ");
PersistenceHelper.appendFuzzyLike(sb, "v.displayname", "displayname", dbInstance.getDbVendor());
}
String desc = params.getDescription();
if (StringHelper.containsNonWhitespace(desc)) {
// desc = '%' + desc.replace('*', '%') + '%';
// query.append(" and v.description like :desc");
desc = PersistenceHelper.makeFuzzyQueryString(desc);
sb.append(" and ");
PersistenceHelper.appendFuzzyLike(sb, "v.description", "desc", dbInstance.getDbVendor());
}
Long id = null;
String refs = null;
String fuzzyRefs = null;
if (StringHelper.containsNonWhitespace(params.getIdAndRefs())) {
refs = params.getIdAndRefs();
fuzzyRefs = PersistenceHelper.makeFuzzyQueryString(refs);
sb.append(" and (v.externalId=:ref or ");
PersistenceHelper.appendFuzzyLike(sb, "v.externalRef", "fuzzyRefs", dbInstance.getDbVendor());
sb.append(" or v.softkey=:ref");
if (StringHelper.isLong(refs)) {
try {
id = Long.parseLong(refs);
sb.append(" or v.key=:vKey or res.resId=:vKey");
} catch (NumberFormatException e) {
//
}
}
sb.append(")");
}
// quick search
Long quickId = null;
String quickRefs = null;
String quickText = null;
if (StringHelper.containsNonWhitespace(params.getIdRefsAndTitle())) {
quickRefs = params.getIdRefsAndTitle();
sb.append(" and (v.externalId=:quickRef or ");
PersistenceHelper.appendFuzzyLike(sb, "v.externalRef", "quickText", dbInstance.getDbVendor());
sb.append(" or v.softkey=:quickRef or ");
quickText = PersistenceHelper.makeFuzzyQueryString(quickRefs);
PersistenceHelper.appendFuzzyLike(sb, "v.displayname", "quickText", dbInstance.getDbVendor());
if (StringHelper.isLong(quickRefs)) {
try {
quickId = Long.parseLong(quickRefs);
sb.append(" or v.key=:quickVKey or res.resId=:quickVKey");
} catch (NumberFormatException e) {
//
}
}
sb.append(")");
}
if (!count) {
appendAuthorViewOrderBy(params, sb);
}
TypedQuery<T> dbQuery = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), type);
if (params.getRepoEntryKeys() != null && params.getRepoEntryKeys().size() > 0) {
dbQuery.setParameter("repoEntryKeys", params.getRepoEntryKeys());
}
if (params.isResourceTypesDefined()) {
dbQuery.setParameter("resourcetypes", resourceTypes);
}
if (id != null) {
dbQuery.setParameter("vKey", id);
}
if (refs != null) {
dbQuery.setParameter("ref", refs);
}
if (fuzzyRefs != null) {
dbQuery.setParameter("fuzzyRefs", fuzzyRefs);
}
if (quickId != null) {
dbQuery.setParameter("quickVKey", quickId);
}
if (quickRefs != null) {
dbQuery.setParameter("quickRef", quickRefs);
}
if (quickText != null) {
dbQuery.setParameter("quickText", quickText);
}
if (StringHelper.containsNonWhitespace(author)) {
// fuzzy author search
dbQuery.setParameter("author", author);
}
if (StringHelper.containsNonWhitespace(displayname)) {
dbQuery.setParameter("displayname", displayname);
}
if (StringHelper.containsNonWhitespace(desc)) {
dbQuery.setParameter("desc", desc);
}
if (needIdentity) {
dbQuery.setParameter("identityKey", identity.getKey());
}
if (params.isLicenseTypeDefined()) {
dbQuery.setParameter("licenseTypeKeys", params.getLicenseTypeKeys());
}
return dbQuery;
}
Aggregations