Search in sources :

Example 16 with InfoMessage

use of org.olat.commons.info.InfoMessage in project OpenOLAT by OpenOLAT.

the class InfoCourseNode method cleanupOnDelete.

@Override
public /**
 * is called when deleting this node, clean up info-messages and subscriptions!
 */
void cleanupOnDelete(ICourse course) {
    super.cleanupOnDelete(course);
    // delete infoMessages and subscriptions (OLAT-6171)
    String resSubpath = getIdent();
    InfoMessageFrontendManager infoService = CoreSpringFactory.getImpl(InfoMessageFrontendManager.class);
    List<InfoMessage> messages = infoService.loadInfoMessageByResource(course, resSubpath, null, null, null, 0, 0);
    for (InfoMessage im : messages) {
        infoService.deleteInfoMessage(im);
    }
    final SubscriptionContext subscriptionContext = CourseModule.createTechnicalSubscriptionContext(course.getCourseEnvironment(), this);
    NotificationsManager notifManagar = NotificationsManager.getInstance();
    notifManagar.delete(subscriptionContext);
    super.cleanupOnDelete(course);
}
Also used : InfoMessageFrontendManager(org.olat.commons.info.InfoMessageFrontendManager) InfoMessage(org.olat.commons.info.InfoMessage) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext)

Example 17 with InfoMessage

use of org.olat.commons.info.InfoMessage in project openolat by klemens.

the class GroupInfoIndexer method doIndexInfos.

private void doIndexInfos(SearchResourceContext parentResourceContext, BusinessGroup businessGroup, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    List<InfoMessage> messages = infoMessageManager.loadInfoMessageByResource(businessGroup, InfoMessageFrontendManager.businessGroupResSubPath, null, null, null, 0, -1);
    for (InfoMessage message : messages) {
        SearchResourceContext searchResourceContext = new SearchResourceContext(parentResourceContext);
        OLATResourceable ores = OresHelper.createOLATResourceableInstance(InfoMessage.class, message.getKey());
        searchResourceContext.setBusinessControlFor(ores);
        Document document = InfoMessageDocument.createDocument(searchResourceContext, message);
        indexWriter.addDocument(document);
    }
}
Also used : SearchResourceContext(org.olat.search.service.SearchResourceContext) OLATResourceable(org.olat.core.id.OLATResourceable) InfoMessage(org.olat.commons.info.InfoMessage) Document(org.apache.lucene.document.Document) InfoMessageDocument(org.olat.search.service.document.InfoMessageDocument)

Example 18 with InfoMessage

use of org.olat.commons.info.InfoMessage in project openolat by klemens.

the class InfoCourseNodeIndexer method doIndexInfos.

private void doIndexInfos(SearchResourceContext parentResourceContext, ICourse course, CourseNode courseNode, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    List<InfoMessage> messages = infoMessageManager.loadInfoMessageByResource(course, courseNode.getIdent(), null, null, null, 0, -1);
    for (InfoMessage message : messages) {
        SearchResourceContext searchResourceContext = new SearchResourceContext(parentResourceContext);
        OLATResourceable ores = OresHelper.createOLATResourceableInstance(InfoMessage.class, message.getKey());
        searchResourceContext.setBusinessControlFor(ores);
        Document document = InfoMessageDocument.createDocument(searchResourceContext, message);
        indexWriter.addDocument(document);
    }
}
Also used : SearchResourceContext(org.olat.search.service.SearchResourceContext) OLATResourceable(org.olat.core.id.OLATResourceable) InfoMessage(org.olat.commons.info.InfoMessage) Document(org.apache.lucene.document.Document) InfoMessageDocument(org.olat.search.service.document.InfoMessageDocument) CourseNodeDocument(org.olat.search.service.document.CourseNodeDocument)

Example 19 with InfoMessage

use of org.olat.commons.info.InfoMessage in project openolat by klemens.

the class InfoMessageNotificationHandler method createSubscriptionInfo.

@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
    SubscriptionInfo si = null;
    Publisher p = subscriber.getPublisher();
    Date latestNews = p.getLatestNewsDate();
    // can't be loaded when already deleted
    if (NotificationsManager.getInstance().isPublisherValid(p) && compareDate.before(latestNews)) {
        try {
            final Long resId = subscriber.getPublisher().getResId();
            final String resName = subscriber.getPublisher().getResName();
            String resSubPath = subscriber.getPublisher().getSubidentifier();
            String displayName, notificationtitle;
            if ("BusinessGroup".equals(resName)) {
                BusinessGroupService groupService = CoreSpringFactory.getImpl(BusinessGroupService.class);
                BusinessGroup group = groupService.loadBusinessGroup(resId);
                displayName = group.getName();
                notificationtitle = "notification.title.group";
            } else {
                RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(OresHelper.createOLATResourceableInstance(resName, resId), false);
                if (re.getRepositoryEntryStatus().isClosed() || re.getRepositoryEntryStatus().isUnpublished()) {
                    return NotificationsManager.getInstance().getNoSubscriptionInfo();
                }
                displayName = re.getDisplayname();
                notificationtitle = "notification.title";
            }
            Translator translator = Util.createPackageTranslator(this.getClass(), locale);
            String title = translator.translate(notificationtitle, new String[] { displayName });
            si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(title, CSS_CLASS_ICON), null);
            OLATResourceable ores = OresHelper.createOLATResourceableInstance(resName, resId);
            List<InfoMessage> infos = infoMessageManager.loadInfoMessageByResource(ores, resSubPath, null, compareDate, null, 0, 0);
            for (InfoMessage info : infos) {
                Identity ident = info.getAuthor();
                String desc = translator.translate("notifications.entry", new String[] { info.getTitle(), NotificationHelper.getFormatedName(ident) });
                String tooltip = info.getMessage();
                String infoBusinessPath = info.getBusinessPath() + "[InfoMessage:" + info.getKey() + "]";
                String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(infoBusinessPath);
                Date dateInfo = info.getModificationDate() == null ? info.getCreationDate() : info.getModificationDate();
                SubscriptionListItem subListItem = new SubscriptionListItem(desc, tooltip, urlToSend, infoBusinessPath, dateInfo, CSS_CLASS_ICON);
                si.addSubscriptionListItem(subListItem);
            }
        } catch (Exception e) {
            log.error("Unexpected exception", e);
            si = NotificationsManager.getInstance().getNoSubscriptionInfo();
        }
    } else {
        si = NotificationsManager.getInstance().getNoSubscriptionInfo();
    }
    return si;
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) OLATResourceable(org.olat.core.id.OLATResourceable) SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo) Publisher(org.olat.core.commons.services.notifications.Publisher) RepositoryEntry(org.olat.repository.RepositoryEntry) TitleItem(org.olat.core.commons.services.notifications.model.TitleItem) Date(java.util.Date) SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) BusinessGroupService(org.olat.group.BusinessGroupService) Translator(org.olat.core.gui.translator.Translator) InfoMessage(org.olat.commons.info.InfoMessage) Identity(org.olat.core.id.Identity)

Example 20 with InfoMessage

use of org.olat.commons.info.InfoMessage in project openolat by klemens.

the class InfoMessagesWebService method createEmptyCourse.

/**
 * Creates a new info message
 * @response.representation.200.qname {http://www.example.com}infoMessageVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The info message
 * @response.representation.200.example {@link org.olat.commons.info.restapi.Examples#SAMPLE_INFOMESSAGEVO}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @param resName The OLAT Resourceable name
 * @param resId The OLAT Resourceable id
 * @param resSubPath The resource sub path (optional)
 * @param businessPath The business path
 * @param authorKey The identity key of the author
 * @param title The title
 * @param message The message
 * @param request The HTTP request
 * @return It returns the id of the newly info message
 */
@PUT
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response createEmptyCourse(@QueryParam("resName") final String resName, @QueryParam("resId") final Long resId, @QueryParam("resSubPath") String resSubPath, @QueryParam("businessPath") String businessPath, @QueryParam("authorKey") Long authorKey, @QueryParam("title") String title, @QueryParam("message") String message, @Context HttpServletRequest request) {
    if (!isAuthor(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    OLATResourceable ores = new OLATResourceable() {

        @Override
        public String getResourceableTypeName() {
            return resName;
        }

        @Override
        public Long getResourceableId() {
            return resId;
        }
    };
    Identity author;
    UserRequest ureq = getUserRequest(request);
    if (authorKey == null) {
        author = ureq.getIdentity();
    } else {
        BaseSecurity securityManager = BaseSecurityManager.getInstance();
        author = securityManager.loadIdentityByKey(authorKey, false);
        if (author == null) {
            return Response.serverError().status(Status.UNAUTHORIZED).build();
        }
    }
    InfoMessageFrontendManager messageManager = CoreSpringFactory.getImpl(InfoMessageFrontendManager.class);
    InfoMessage msg = messageManager.createInfoMessage(ores, resSubPath, businessPath, author);
    msg.setTitle(title);
    msg.setMessage(message);
    messageManager.sendInfoMessage(msg, null, ureq.getLocale(), ureq.getIdentity(), Collections.<Identity>emptyList());
    InfoMessageVO infoVO = new InfoMessageVO(msg);
    return Response.ok(infoVO).build();
}
Also used : InfoMessageFrontendManager(org.olat.commons.info.InfoMessageFrontendManager) OLATResourceable(org.olat.core.id.OLATResourceable) InfoMessage(org.olat.commons.info.InfoMessage) Identity(org.olat.core.id.Identity) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) BaseSecurity(org.olat.basesecurity.BaseSecurity) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Aggregations

InfoMessage (org.olat.commons.info.InfoMessage)24 OLATResourceable (org.olat.core.id.OLATResourceable)8 InfoMessageFrontendManager (org.olat.commons.info.InfoMessageFrontendManager)6 Identity (org.olat.core.id.Identity)6 ArrayList (java.util.ArrayList)4 Document (org.apache.lucene.document.Document)4 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)4 SearchResourceContext (org.olat.search.service.SearchResourceContext)4 InfoMessageDocument (org.olat.search.service.document.InfoMessageDocument)4 Date (java.util.Date)2 HashMap (java.util.HashMap)2 PUT (javax.ws.rs.PUT)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 BaseSecurity (org.olat.basesecurity.BaseSecurity)2 InfoMessageImpl (org.olat.commons.info.model.InfoMessageImpl)2 DBQuery (org.olat.core.commons.persistence.DBQuery)2 NotificationsManager (org.olat.core.commons.services.notifications.NotificationsManager)2 Publisher (org.olat.core.commons.services.notifications.Publisher)2 SubscriptionInfo (org.olat.core.commons.services.notifications.SubscriptionInfo)2