Search in sources :

Example 41 with MultiUserEvent

use of org.olat.core.util.event.MultiUserEvent in project openolat by klemens.

the class InfoMessageManager method setInfoMessage.

/**
 * @param message The new info message that will show up on the login screen
 * Synchronized to prevent two users creating or updating the info message property
 * at the same time
 */
public void setInfoMessage(final String message) {
    // o_clusterOK synchronized
    OLATResourceable ores = OresHelper.createOLATResourceableInstance(INFO_MSG, KEY);
    coordinatorManager.getCoordinator().getSyncer().doInSync(ores, new SyncerExecutor() {

        public void execute() {
            PropertyManager pm = PropertyManager.getInstance();
            Property p = pm.findProperty(null, null, null, "_o3_", INFO_MSG);
            if (p == null) {
                p = pm.createPropertyInstance(null, null, null, "_o3_", INFO_MSG, null, null, null, "");
                pm.saveProperty(p);
            }
            p.setTextValue(message);
            // set Message in RAM
            InfoMessageManager.infoMessage = message;
            pm.updateProperty(p);
        }
    });
    // end syncerCallback
    EventBus eb = coordinatorManager.getCoordinator().getEventBus();
    MultiUserEvent mue = new MultiUserEvent(message);
    eb.fireEventToListenersOf(mue, INFO_MESSAGE_ORES);
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) PropertyManager(org.olat.properties.PropertyManager) SyncerExecutor(org.olat.core.util.coordinate.SyncerExecutor) EventBus(org.olat.core.util.event.EventBus) Property(org.olat.properties.Property) MultiUserEvent(org.olat.core.util.event.MultiUserEvent)

Example 42 with MultiUserEvent

use of org.olat.core.util.event.MultiUserEvent in project openolat by klemens.

the class InfoMessageFrontendManagerImpl method sendInfoMessage.

@Override
public boolean sendInfoMessage(InfoMessage infoMessage, MailFormatter mailFormatter, Locale locale, Identity from, List<Identity> tos) {
    infoMessageManager.saveInfoMessage(infoMessage);
    boolean send = false;
    if (tos != null && !tos.isEmpty()) {
        Set<Long> identityKeySet = new HashSet<Long>();
        ContactList contactList = new ContactList("Infos");
        for (Identity to : tos) {
            if (identityKeySet.contains(to.getKey()))
                continue;
            contactList.add(to);
            identityKeySet.add(to.getKey());
        }
        try {
            String subject = null;
            String body = null;
            if (mailFormatter != null) {
                subject = mailFormatter.getSubject(infoMessage);
                body = mailFormatter.getBody(infoMessage);
            }
            if (!StringHelper.containsNonWhitespace(subject)) {
                subject = infoMessage.getTitle();
            }
            if (!StringHelper.containsNonWhitespace(body)) {
                body = infoMessage.getMessage();
            }
            File attachment = null;
            if (StringHelper.containsNonWhitespace(infoMessage.getAttachmentPath())) {
                File root = getStoragePath().getBasefile();
                attachment = new File(root, infoMessage.getAttachmentPath());
            }
            MailContext context = new MailContextImpl(mailFormatter.getBusinessPath());
            MailBundle bundle = new MailBundle();
            bundle.setContext(context);
            bundle.setFromId(from);
            bundle.setContactList(contactList);
            if (attachment != null) {
                bundle.setContent(subject, body, attachment);
            } else {
                bundle.setContent(subject, body);
            }
            MailerResult result = mailManager.sendMessage(bundle);
            send = result.isSuccessful();
        } catch (Exception e) {
            log.error("Cannot send info messages", e);
        }
    }
    infoSubscriptionManager.markPublisherNews(infoMessage.getOLATResourceable(), infoMessage.getResSubPath());
    MultiUserEvent mue = new MultiUserEvent("new_info_message");
    coordinatorManager.getCoordinator().getEventBus().fireEventToListenersOf(mue, oresFrontend);
    return send;
}
Also used : MailContextImpl(org.olat.core.util.mail.MailContextImpl) MailContext(org.olat.core.util.mail.MailContext) MailerResult(org.olat.core.util.mail.MailerResult) ContactList(org.olat.core.util.mail.ContactList) IOException(java.io.IOException) Identity(org.olat.core.id.Identity) MailBundle(org.olat.core.util.mail.MailBundle) File(java.io.File) MultiUserEvent(org.olat.core.util.event.MultiUserEvent) HashSet(java.util.HashSet)

Example 43 with MultiUserEvent

use of org.olat.core.util.event.MultiUserEvent in project openolat by klemens.

the class PublishProcess method changeGeneralAccess.

public void changeGeneralAccess(Identity author, int access, boolean membersOnly) {
    RepositoryManager.getInstance().setAccess(repositoryEntry, access, membersOnly);
    MultiUserEvent modifiedEvent = new EntryChangedEvent(repositoryEntry, author, Change.modifiedAtPublish, "publish");
    CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(modifiedEvent, repositoryEntry);
}
Also used : EntryChangedEvent(org.olat.repository.controllers.EntryChangedEvent) MultiUserEvent(org.olat.core.util.event.MultiUserEvent)

Example 44 with MultiUserEvent

use of org.olat.core.util.event.MultiUserEvent in project openolat by klemens.

the class PublishProcess method changeAccessAndProperties.

public void changeAccessAndProperties(Identity author, CourseAccessAndProperties accessAndProps) {
    RepositoryManager manager = RepositoryManager.getInstance();
    manager.setAccessAndProperties(accessAndProps.getRepositoryEntry(), accessAndProps.getAccess(), accessAndProps.isMembersOnly(), accessAndProps.isCanCopy(), accessAndProps.isCanReference(), accessAndProps.isCanDownload());
    manager.setLeaveSetting(accessAndProps.getRepositoryEntry(), accessAndProps.getSetting());
    List<OfferAccess> offerAccess = accessAndProps.getOfferAccess();
    // 1: add new and update existing offerings
    ACService acService = CoreSpringFactory.getImpl(ACService.class);
    for (OfferAccess newLink : offerAccess) {
        if (accessAndProps.getConfirmationEmail() != null) {
            Offer offer = newLink.getOffer();
            boolean confirmation = accessAndProps.getConfirmationEmail().booleanValue();
            if (offer.isConfirmationEmail() != confirmation) {
                offer.setConfirmationEmail(confirmation);
                if (offer.getKey() != null) {
                    offer = acService.save(offer);
                }
            }
        }
        acService.saveOfferAccess(newLink);
    }
    // 2: remove offerings not available anymore
    List<OfferAccess> deletedOfferAccess = accessAndProps.getDeletedOfferAccess();
    for (OfferAccess deletedLink : deletedOfferAccess) {
        acService.deletedLinkToMethod(deletedLink);
    }
    MultiUserEvent modifiedEvent = new EntryChangedEvent(repositoryEntry, author, Change.modifiedAtPublish, "publish");
    CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(modifiedEvent, repositoryEntry);
    CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(modifiedEvent, RepositoryService.REPOSITORY_EVENT_ORES);
}
Also used : OfferAccess(org.olat.resource.accesscontrol.OfferAccess) Offer(org.olat.resource.accesscontrol.Offer) EntryChangedEvent(org.olat.repository.controllers.EntryChangedEvent) ACService(org.olat.resource.accesscontrol.ACService) RepositoryManager(org.olat.repository.RepositoryManager) MultiUserEvent(org.olat.core.util.event.MultiUserEvent)

Example 45 with MultiUserEvent

use of org.olat.core.util.event.MultiUserEvent in project openolat by klemens.

the class QuickPublishController method doAutoPublish.

private boolean doAutoPublish() {
    ICourse course = CourseFactory.loadCourse(courseOres);
    CourseEditorTreeModel cetm = course.getEditorTreeModel();
    PublishProcess publishProcess = PublishProcess.getInstance(course, cetm, getLocale());
    PublishTreeModel publishTreeModel = publishProcess.getPublishTreeModel();
    if (publishTreeModel.hasPublishableChanges()) {
        List<String> nodeToPublish = new ArrayList<String>();
        visitPublishModel(publishTreeModel.getRootNode(), publishTreeModel, nodeToPublish);
        // only add selection if changes were possible
        for (Iterator<String> selectionIt = nodeToPublish.iterator(); selectionIt.hasNext(); ) {
            String ident = selectionIt.next();
            TreeNode node = publishProcess.getPublishTreeModel().getNodeById(ident);
            if (!publishTreeModel.isSelectable(node)) {
                selectionIt.remove();
            }
        }
        publishProcess.createPublishSetFor(nodeToPublish);
        PublishSetInformations set = publishProcess.testPublishSet(getLocale());
        StatusDescription[] status = set.getWarnings();
        // publish not possible when there are errors
        StringBuilder errMsg = new StringBuilder();
        for (int i = 0; i < status.length; i++) {
            if (status[i].isError()) {
                errMsg.append(status[i].getLongDescription(getLocale()));
                logError("Status error by publish: " + status[i].getLongDescription(getLocale()), null);
            }
        }
        if (errMsg.length() > 0) {
            getWindowControl().setWarning(errMsg.toString());
            return false;
        }
        PublishEvents publishEvents = publishProcess.getPublishEvents();
        try {
            publishProcess.applyPublishSet(getIdentity(), getLocale(), false);
        } catch (Exception e) {
            logError("", e);
        }
        if (publishEvents.getPostPublishingEvents().size() > 0) {
            for (MultiUserEvent event : publishEvents.getPostPublishingEvents()) {
                CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(event, courseOres);
            }
        }
    }
    return true;
}
Also used : CourseEditorTreeModel(org.olat.course.tree.CourseEditorTreeModel) PublishTreeModel(org.olat.course.tree.PublishTreeModel) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) TreeNode(org.olat.core.gui.components.tree.TreeNode) MultiUserEvent(org.olat.core.util.event.MultiUserEvent)

Aggregations

MultiUserEvent (org.olat.core.util.event.MultiUserEvent)48 OLATResourceable (org.olat.core.id.OLATResourceable)16 EntryChangedEvent (org.olat.repository.controllers.EntryChangedEvent)10 ArrayList (java.util.ArrayList)8 File (java.io.File)6 Date (java.util.Date)6 HashSet (java.util.HashSet)6 Identity (org.olat.core.id.Identity)6 SyncerExecutor (org.olat.core.util.coordinate.SyncerExecutor)6 EventBus (org.olat.core.util.event.EventBus)6 List (java.util.List)4 Locale (java.util.Locale)4 Publisher (org.olat.core.commons.services.notifications.Publisher)4 Subscriber (org.olat.core.commons.services.notifications.Subscriber)4 ICourse (org.olat.course.ICourse)3 IOException (java.io.IOException)2 Collection (java.util.Collection)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 JMSException (javax.jms.JMSException)2 ObjectMessage (javax.jms.ObjectMessage)2