Search in sources :

Example 1 with InfoMessageFrontendManager

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

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)

Example 2 with InfoMessageFrontendManager

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

the class InfoMessagesWebService method getInfoMessageWebservice.

@Path("{infoMessageKey}")
public InfoMessageWebService getInfoMessageWebservice(@PathParam("infoMessageKey") Long infoMessageKey) {
    InfoMessageFrontendManager messageManager = CoreSpringFactory.getImpl(InfoMessageFrontendManager.class);
    InfoMessage msg = messageManager.loadInfoMessage(infoMessageKey);
    return new InfoMessageWebService(msg);
}
Also used : InfoMessageFrontendManager(org.olat.commons.info.InfoMessageFrontendManager) InfoMessage(org.olat.commons.info.InfoMessage) Path(javax.ws.rs.Path)

Example 3 with InfoMessageFrontendManager

use of org.olat.commons.info.InfoMessageFrontendManager 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 4 with InfoMessageFrontendManager

use of org.olat.commons.info.InfoMessageFrontendManager 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)

Example 5 with InfoMessageFrontendManager

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

the class InfoMessagesWebService method getInfoMessageWebservice.

@Path("{infoMessageKey}")
public InfoMessageWebService getInfoMessageWebservice(@PathParam("infoMessageKey") Long infoMessageKey) {
    InfoMessageFrontendManager messageManager = CoreSpringFactory.getImpl(InfoMessageFrontendManager.class);
    InfoMessage msg = messageManager.loadInfoMessage(infoMessageKey);
    return new InfoMessageWebService(msg);
}
Also used : InfoMessageFrontendManager(org.olat.commons.info.InfoMessageFrontendManager) InfoMessage(org.olat.commons.info.InfoMessage) Path(javax.ws.rs.Path)

Aggregations

InfoMessage (org.olat.commons.info.InfoMessage)6 InfoMessageFrontendManager (org.olat.commons.info.InfoMessageFrontendManager)6 PUT (javax.ws.rs.PUT)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 BaseSecurity (org.olat.basesecurity.BaseSecurity)2 NotificationsManager (org.olat.core.commons.services.notifications.NotificationsManager)2 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)2 UserRequest (org.olat.core.gui.UserRequest)2 Identity (org.olat.core.id.Identity)2 OLATResourceable (org.olat.core.id.OLATResourceable)2 RestSecurityHelper.getUserRequest (org.olat.restapi.security.RestSecurityHelper.getUserRequest)2