use of org.olat.repository.RepositoryEntryShort in project OpenOLAT by OpenOLAT.
the class BusinessGroupRelationDAO method findShortRepositoryEntries.
public List<RepositoryEntryShort> findShortRepositoryEntries(Collection<BusinessGroupShort> groups, int firstResult, int maxResults) {
if (groups == null || groups.isEmpty()) {
return Collections.emptyList();
}
StringBuilder sb = new StringBuilder();
sb.append("select new org.olat.group.model.BGRepositoryEntryShortImpl(v.key, v.displayname) from ").append(RepositoryEntry.class.getName()).append(" as v ").append(" inner join v.olatResource as ores ").append(" inner join v.groups as relGroup").append(" where exists (").append(" select bgi from businessgroup as bgi where bgi.baseGroup=relGroup.group and bgi.key in (:groupKeys)").append(" )");
TypedQuery<RepositoryEntryShort> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), RepositoryEntryShort.class);
query.setFirstResult(firstResult);
if (maxResults > 0) {
query.setMaxResults(maxResults);
}
List<Long> groupKeys = new ArrayList<Long>();
for (BusinessGroupShort group : groups) {
groupKeys.add(group.getKey());
}
query.setParameter("groupKeys", groupKeys);
query.setHint("org.hibernate.cacheable", Boolean.TRUE);
return query.getResultList();
}
use of org.olat.repository.RepositoryEntryShort in project OpenOLAT by OpenOLAT.
the class BGMailHelper method createMailTemplate.
/**
* Internal helper - does all the magic
*
* @param group
* @param actor
* @param subjectKey
* @param bodyKey
* @return
*/
private static MailTemplate createMailTemplate(BusinessGroupShort group, Identity actor, String subjectKey, String bodyKey) {
// get some data about the actor and fetch the translated subject / body via i18n module
String[] bodyArgs = null;
String lang = null;
if (actor != null) {
lang = actor.getUser().getPreferences().getLanguage();
}
Locale locale = I18nManager.getInstance().getLocaleOrDefault(lang);
if (actor != null) {
bodyArgs = new String[] { actor.getUser().getProperty(UserConstants.FIRSTNAME, null), actor.getUser().getProperty(UserConstants.LASTNAME, null), UserManager.getInstance().getUserDisplayEmail(actor, locale), // 2x for compatibility with old i18m properties
UserManager.getInstance().getUserDisplayEmail(actor, locale) };
}
Translator trans = Util.createPackageTranslator(BGMailHelper.class, locale, Util.createPackageTranslator(BusinessGroupListController.class, locale));
String subject = trans.translate(subjectKey);
String body = trans.translate(bodyKey, bodyArgs);
// build learning resources as list of url as string
final BGMailTemplateInfos infos;
if (group != null) {
BusinessGroupService businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class);
List<RepositoryEntryShort> repoEntries = businessGroupService.findShortRepositoryEntries(Collections.singletonList(group), 0, -1);
infos = getTemplateInfos(group, repoEntries);
subject = subject.replace("$groupname", infos.getGroupName());
body = body.replace("$groupname", infos.getGroupNameWithUrl());
body = body.replace("$groupdescription", infos.getGroupDescription());
if (StringHelper.containsNonWhitespace(infos.getCourseList())) {
body = body.replace("$courselist", infos.getCourseList());
} else {
body = body.replace("$courselist", trans.translate("notification.mail.no.ressource", null));
}
} else {
infos = new BGMailTemplateInfos("", "", "", "");
}
// create a mail template which all these data
MailTemplate mailTempl = new MailTemplate(subject, body, null) {
@Override
public void putVariablesInMailContext(VelocityContext context, Identity identity) {
// Put user variables into velocity context
User user = identity.getUser();
context.put("firstname", user.getProperty(UserConstants.FIRSTNAME, null));
context.put("lastname", user.getProperty(UserConstants.LASTNAME, null));
// the email of the user, needs to stay named 'login'
context.put("login", user.getProperty(UserConstants.EMAIL, null));
// Put variables from greater context
context.put("groupname", infos.getGroupNameWithUrl());
context.put("groupdescription", infos.getGroupDescription());
if (StringHelper.containsNonWhitespace(infos.getCourseList())) {
context.put("courselist", infos.getCourseList());
} else {
context.put("courselist", trans.translate("notification.mail.no.ressource", null));
}
context.put("courselistempty", trans.translate("notification.mail.no.ressource", null));
}
};
return mailTempl;
}
use of org.olat.repository.RepositoryEntryShort in project openolat by klemens.
the class RepositoryEntryIconRenderer method render.
@Override
public void render(StringOutput sb, Renderer renderer, Object val, Locale locale, int alignment, String action) {
if (renderer == null) {
// render for export
} else {
String type = "";
String cssClass = "";
boolean managed = false;
if (val instanceof RepositoryEntryShort) {
RepositoryEntryShort re = (RepositoryEntryShort) val;
cssClass = RepositoyUIFactory.getIconCssClass(re);
String typeName = re.getResourceType();
type = NewControllerFactory.translateResourceableTypeName(typeName, locale);
} else if (val instanceof RepositoryEntry) {
RepositoryEntry re = (RepositoryEntry) val;
cssClass = RepositoyUIFactory.getIconCssClass(re);
managed = StringHelper.containsNonWhitespace(re.getManagedFlagsString());
String typeName = re.getOlatResource().getResourceableTypeName();
type = NewControllerFactory.translateResourceableTypeName(typeName, locale);
}
sb.append("<i class='o_icon ").append(cssClass).append("'");
if (StringHelper.containsNonWhitespace(type)) {
sb.append(" title=\"");
sb.append(StringEscapeUtils.escapeHtml(type));
}
sb.append("\"> </i>");
if (managed) {
sb.append(" <i class='o_icon o_icon_managed'> </i>");
}
}
}
use of org.olat.repository.RepositoryEntryShort in project openolat by klemens.
the class BusinessGroupRelationDAO method findShortRepositoryEntries.
public List<RepositoryEntryShort> findShortRepositoryEntries(Collection<BusinessGroupShort> groups, int firstResult, int maxResults) {
if (groups == null || groups.isEmpty()) {
return Collections.emptyList();
}
StringBuilder sb = new StringBuilder();
sb.append("select new org.olat.group.model.BGRepositoryEntryShortImpl(v.key, v.displayname) from ").append(RepositoryEntry.class.getName()).append(" as v ").append(" inner join v.olatResource as ores ").append(" inner join v.groups as relGroup").append(" where exists (").append(" select bgi from businessgroup as bgi where bgi.baseGroup=relGroup.group and bgi.key in (:groupKeys)").append(" )");
TypedQuery<RepositoryEntryShort> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), RepositoryEntryShort.class);
query.setFirstResult(firstResult);
if (maxResults > 0) {
query.setMaxResults(maxResults);
}
List<Long> groupKeys = new ArrayList<Long>();
for (BusinessGroupShort group : groups) {
groupKeys.add(group.getKey());
}
query.setParameter("groupKeys", groupKeys);
query.setHint("org.hibernate.cacheable", Boolean.TRUE);
return query.getResultList();
}
use of org.olat.repository.RepositoryEntryShort in project openolat by klemens.
the class BusinessGroupRelationDAOTest method findShortRepositoryEntries.
@Test
public void findShortRepositoryEntries() {
// create 3 entries and 1 group
RepositoryEntry re1 = JunitTestHelper.createAndPersistRepositoryEntry();
RepositoryEntry re2 = JunitTestHelper.createAndPersistRepositoryEntry();
RepositoryEntry re3 = JunitTestHelper.createAndPersistRepositoryEntry();
BusinessGroup group = businessGroupDao.createAndPersist(null, "rel-repo", "rel-repo-desc", 0, 10, true, false, false, false, false);
dbInstance.commitAndCloseSession();
businessGroupRelationDao.addRelationToResource(group, re1);
businessGroupRelationDao.addRelationToResource(group, re2);
businessGroupRelationDao.addRelationToResource(group, re3);
dbInstance.commitAndCloseSession();
// check with empty list of groups
List<RepositoryEntryShort> emptyRelations = businessGroupRelationDao.findShortRepositoryEntries(Collections.<BusinessGroupShort>emptyList(), 0, -1);
Assert.assertNotNull(emptyRelations);
Assert.assertEquals(0, emptyRelations.size());
List<RepositoryEntryShort> repoEntries = businessGroupRelationDao.findShortRepositoryEntries(Collections.<BusinessGroupShort>singletonList(group), 0, -1);
Assert.assertNotNull(repoEntries);
Assert.assertEquals(3, repoEntries.size());
int count = 0;
for (RepositoryEntryShort repoEntry : repoEntries) {
if (repoEntry.getKey().equals(re1.getKey()) || repoEntry.getKey().equals(re2.getKey()) || repoEntry.getKey().equals(re3.getKey())) {
count++;
}
}
Assert.assertEquals(3, count);
}
Aggregations