Search in sources :

Example 36 with MultiUserEvent

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

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 37 with MultiUserEvent

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

the class RepositoryEditDescriptionController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    if (licenseModule.isEnabled(licenseHandler)) {
        if (licenseEl != null && licenseEl.isOneSelected()) {
            String licenseTypeKey = licenseEl.getSelectedKey();
            LicenseType licneseType = licenseService.loadLicenseTypeByKey(licenseTypeKey);
            license.setLicenseType(licneseType);
        }
        String licensor = null;
        String freetext = null;
        if (licensorEl != null && licensorEl.isVisible()) {
            licensor = StringHelper.containsNonWhitespace(licensorEl.getValue()) ? licensorEl.getValue() : null;
        }
        if (licenseFreetextEl != null && licenseFreetextEl.isVisible()) {
            freetext = StringHelper.containsNonWhitespace(licenseFreetextEl.getValue()) ? licenseFreetextEl.getValue() : null;
        }
        license.setLicensor(licensor);
        license.setFreetext(freetext);
        license = licenseService.update(license);
        licensorEl.setValue(license.getLicensor());
        licenseFreetextEl.setValue(license.getFreetext());
    }
    File uploadedImage = fileUpload.getUploadFile();
    if (uploadedImage != null && uploadedImage.exists()) {
        VFSContainer tmpHome = new LocalFolderImpl(new File(WebappHelper.getTmpDir()));
        VFSContainer container = tmpHome.createChildContainer(UUID.randomUUID().toString());
        // give it it's real name and extension
        VFSLeaf newFile = fileUpload.moveUploadFileTo(container);
        boolean ok = repositoryManager.setImage(newFile, repositoryEntry);
        if (!ok) {
            showWarning("cif.error.image");
        } else {
            VFSLeaf image = repositoryManager.getImage(repositoryEntry);
            if (image instanceof LocalFileImpl) {
                fileUpload.setInitialFile(((LocalFileImpl) image).getBasefile());
            }
        }
        container.delete();
    }
    File uploadedMovie = movieUpload.getUploadFile();
    if (uploadedMovie != null && uploadedMovie.exists()) {
        VFSContainer m = (VFSContainer) mediaContainer.resolve("media");
        VFSLeaf newFile = movieUpload.moveUploadFileTo(m);
        if (newFile == null) {
            showWarning("cif.error.movie");
        } else {
            String filename = movieUpload.getUploadFileName();
            String extension = FileUtils.getFileSuffix(filename);
            newFile.rename(repositoryEntry.getKey() + "." + extension);
        }
    }
    String displayname = displayName.getValue().trim();
    repositoryEntry.setDisplayname(displayname);
    String mainLanguage = language.getValue();
    if (StringHelper.containsNonWhitespace(mainLanguage)) {
        repositoryEntry.setMainLanguage(mainLanguage);
    } else {
        repositoryEntry.setMainLanguage(null);
    }
    if (dateTypesEl != null) {
        String type = "none";
        if (dateTypesEl.isOneSelected()) {
            type = dateTypesEl.getSelectedKey();
        }
        if ("none".equals(type)) {
            repositoryEntry.setLifecycle(null);
        } else if ("public".equals(type)) {
            String key = publicDatesEl.getSelectedKey();
            if (StringHelper.isLong(key)) {
                Long cycleKey = Long.parseLong(key);
                RepositoryEntryLifecycle cycle = lifecycleDao.loadById(cycleKey);
                repositoryEntry.setLifecycle(cycle);
            }
        } else if ("private".equals(type)) {
            Date start = startDateEl.getDate();
            Date end = endDateEl.getDate();
            RepositoryEntryLifecycle cycle = repositoryEntry.getLifecycle();
            if (cycle == null || !cycle.isPrivateCycle()) {
                String softKey = "lf_" + repositoryEntry.getSoftkey();
                cycle = lifecycleDao.create(displayname, softKey, true, start, end);
            } else {
                cycle.setValidFrom(start);
                cycle.setValidTo(end);
                cycle = lifecycleDao.updateLifecycle(cycle);
            }
            repositoryEntry.setLifecycle(cycle);
        }
    }
    if (externalRef != null && externalRef.isEnabled()) {
        String ref = externalRef.getValue().trim();
        repositoryEntry.setExternalRef(ref);
    }
    String desc = description.getValue().trim();
    repositoryEntry.setDescription(desc);
    if (authors != null) {
        String auth = authors.getValue().trim();
        repositoryEntry.setAuthors(auth);
    }
    if (objectives != null) {
        String obj = objectives.getValue().trim();
        repositoryEntry.setObjectives(obj);
    }
    if (requirements != null) {
        String req = requirements.getValue().trim();
        repositoryEntry.setRequirements(req);
    }
    if (credits != null) {
        String cred = credits.getValue().trim();
        repositoryEntry.setCredits(cred);
    }
    if (expenditureOfWork != null) {
        String exp = expenditureOfWork.getValue().trim();
        repositoryEntry.setExpenditureOfWork(exp);
    }
    if (location != null) {
        String loc = location.getValue().trim();
        repositoryEntry.setLocation(loc);
    }
    repositoryEntry = repositoryManager.setDescriptionAndName(repositoryEntry, repositoryEntry.getDisplayname(), repositoryEntry.getExternalRef(), repositoryEntry.getAuthors(), repositoryEntry.getDescription(), repositoryEntry.getObjectives(), repositoryEntry.getRequirements(), repositoryEntry.getCredits(), repositoryEntry.getMainLanguage(), repositoryEntry.getLocation(), repositoryEntry.getExpenditureOfWork(), repositoryEntry.getLifecycle());
    if (repositoryEntry == null) {
        showWarning("repositoryentry.not.existing");
        fireEvent(ureq, Event.CLOSE_EVENT);
    } else {
        fireEvent(ureq, Event.CHANGED_EVENT);
        MultiUserEvent modifiedEvent = new EntryChangedEvent(repositoryEntry, getIdentity(), Change.modifiedDescription, "authoring");
        CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(modifiedEvent, RepositoryService.REPOSITORY_EVENT_ORES);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) Date(java.util.Date) LicenseType(org.olat.core.commons.services.license.LicenseType) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl) EntryChangedEvent(org.olat.repository.controllers.EntryChangedEvent) RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) File(java.io.File) MultiUserEvent(org.olat.core.util.event.MultiUserEvent)

Example 38 with MultiUserEvent

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

the class JMSTest method testSendReceive.

@Test
public void testSendReceive() {
    // enable test only if we have the cluster configuration enabled.
    // this test requires that an JMS Provider is running
    // (see file serviceconfig/org/olat/core/_spring/coreextconfig.xml)
    EventBus bus = CoordinatorManager.getInstance().getCoordinator().getEventBus();
    if (bus instanceof ClusterEventBus) {
        Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("jms");
        // send and wait some time until a message should arrive at the latest.
        final OLATResourceable ores = OresHelper.createOLATResourceableInstance("hellojms", new Long(123));
        final CountDownLatch doneSignal = new CountDownLatch(1);
        bus.registerFor(new GenericEventListener() {

            @Override
            public void event(Event event) {
                log.audit("Event received: " + event);
                doneSignal.countDown();
            }
        }, id, ores);
        MultiUserEvent mue = new MultiUserEvent("amuecommand");
        bus.fireEventToListenersOf(mue, ores);
        try {
            boolean interrupt = doneSignal.await(5, TimeUnit.SECONDS);
            assertTrue("Test takes too long (more than 5s)", interrupt);
        } catch (InterruptedException e) {
            fail("" + e.getMessage());
        }
    }
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) MultiUserEvent(org.olat.core.util.event.MultiUserEvent) Event(org.olat.core.gui.control.Event) EventBus(org.olat.core.util.event.EventBus) GenericEventListener(org.olat.core.util.event.GenericEventListener) Identity(org.olat.core.id.Identity) CountDownLatch(java.util.concurrent.CountDownLatch) MultiUserEvent(org.olat.core.util.event.MultiUserEvent) Test(org.junit.Test)

Example 39 with MultiUserEvent

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

the class CatalogManager method notifyReferencedRepositoryEntryChanges.

/**
 * @param re
 */
public void notifyReferencedRepositoryEntryChanges(RepositoryEntry re) {
    // inform anybody interested about this change
    MultiUserEvent modifiedEvent = new EntryChangedEvent(re, null, Change.modifiedDescription, "CatalogManager");
    CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(modifiedEvent, re);
}
Also used : EntryChangedEvent(org.olat.repository.controllers.EntryChangedEvent) MultiUserEvent(org.olat.core.util.event.MultiUserEvent)

Example 40 with MultiUserEvent

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

the class InfoMessageManager method event.

public void event(Event event) {
    if (event instanceof MultiUserEvent) {
        MultiUserEvent mue = (MultiUserEvent) event;
        // do not use setInfoMessage(..) this event comes in from another node, where the infomessage was set.
        InfoMessageManager.infoMessage = mue.getCommand();
    }
}
Also used : 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