Search in sources :

Example 1 with RepositoryEntryShort

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();
}
Also used : RepositoryEntryShort(org.olat.repository.RepositoryEntryShort) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) BusinessGroupShort(org.olat.group.BusinessGroupShort)

Example 2 with RepositoryEntryShort

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;
}
Also used : Locale(java.util.Locale) User(org.olat.core.id.User) RepositoryEntryShort(org.olat.repository.RepositoryEntryShort) VelocityContext(org.apache.velocity.VelocityContext) Translator(org.olat.core.gui.translator.Translator) BusinessGroupService(org.olat.group.BusinessGroupService) MailTemplate(org.olat.core.util.mail.MailTemplate) Identity(org.olat.core.id.Identity) BusinessGroupListController(org.olat.group.ui.main.BusinessGroupListController)

Example 3 with RepositoryEntryShort

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>");
        }
    }
}
Also used : RepositoryEntryShort(org.olat.repository.RepositoryEntryShort) RepositoryEntry(org.olat.repository.RepositoryEntry)

Example 4 with RepositoryEntryShort

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();
}
Also used : RepositoryEntryShort(org.olat.repository.RepositoryEntryShort) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) BusinessGroupShort(org.olat.group.BusinessGroupShort)

Example 5 with RepositoryEntryShort

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);
}
Also used : RepositoryEntryShort(org.olat.repository.RepositoryEntryShort) BusinessGroup(org.olat.group.BusinessGroup) RepositoryEntry(org.olat.repository.RepositoryEntry) Test(org.junit.Test)

Aggregations

RepositoryEntryShort (org.olat.repository.RepositoryEntryShort)20 RepositoryEntry (org.olat.repository.RepositoryEntry)10 BusinessGroup (org.olat.group.BusinessGroup)8 ArrayList (java.util.ArrayList)4 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)4 BusinessGroupShort (org.olat.group.BusinessGroupShort)4 HashMap (java.util.HashMap)2 Locale (java.util.Locale)2 VelocityContext (org.apache.velocity.VelocityContext)2 Test (org.junit.Test)2 FlexiTableSearchEvent (org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableSearchEvent)2 SelectionEvent (org.olat.core.gui.components.form.flexible.impl.elements.table.SelectionEvent)2 Translator (org.olat.core.gui.translator.Translator)2 Identity (org.olat.core.id.Identity)2 User (org.olat.core.id.User)2 MailTemplate (org.olat.core.util.mail.MailTemplate)2 BusinessGroupRef (org.olat.group.BusinessGroupRef)2 BusinessGroupService (org.olat.group.BusinessGroupService)2 BusinessGroupRow (org.olat.group.model.BusinessGroupRow)2 BusinessGroupSelectionEvent (org.olat.group.model.BusinessGroupSelectionEvent)2