Search in sources :

Example 11 with SubscriptionInfoVO

use of org.olat.core.commons.services.notifications.restapi.vo.SubscriptionInfoVO in project OpenOLAT by OpenOLAT.

the class NotificationsTest method testGetNotifications.

@Test
public void testGetNotifications() throws IOException, URISyntaxException {
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("rest-notifications-test-1", "A6B7C8"));
    URI request = UriBuilder.fromUri(getContextURI()).path("notifications").build();
    HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    InputStream body = response.getEntity().getContent();
    List<SubscriptionInfoVO> infos = parseUserArray(body);
    assertNotNull(infos);
    assertFalse(infos.isEmpty());
    SubscriptionInfoVO infoVO = infos.get(0);
    assertNotNull(infoVO);
    assertNotNull(infoVO.getKey());
    assertNotNull("User", infoVO.getType());
    assertNotNull(infoVO.getTitle());
    assertNotNull(infoVO.getItems());
    assertFalse(infoVO.getItems().isEmpty());
    conn.shutdown();
}
Also used : SubscriptionInfoVO(org.olat.core.commons.services.notifications.restapi.vo.SubscriptionInfoVO) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 12 with SubscriptionInfoVO

use of org.olat.core.commons.services.notifications.restapi.vo.SubscriptionInfoVO in project OpenOLAT by OpenOLAT.

the class NotificationsTest method testGetUserNotifications.

@Test
public void testGetUserNotifications() throws IOException, URISyntaxException {
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("rest-notifications-test-1", "A6B7C8"));
    UriBuilder request = UriBuilder.fromUri(getContextURI()).path("notifications").queryParam("type", "User");
    HttpGet method = conn.createGet(request.build(), MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    InputStream body = response.getEntity().getContent();
    List<SubscriptionInfoVO> infos = parseUserArray(body);
    assertNotNull(infos);
    assertFalse(infos.isEmpty());
    SubscriptionInfoVO infoVO = infos.get(0);
    assertNotNull(infoVO);
    assertNotNull(infoVO.getKey());
    assertNotNull("User", infoVO.getType());
    assertNotNull(infoVO.getTitle());
    assertNotNull(infoVO.getItems());
    assertFalse(infoVO.getItems().isEmpty());
    conn.shutdown();
}
Also used : SubscriptionInfoVO(org.olat.core.commons.services.notifications.restapi.vo.SubscriptionInfoVO) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) UriBuilder(javax.ws.rs.core.UriBuilder) Test(org.junit.Test)

Example 13 with SubscriptionInfoVO

use of org.olat.core.commons.services.notifications.restapi.vo.SubscriptionInfoVO in project OpenOLAT by OpenOLAT.

the class NotificationsTest method testGetNoNotifications.

@Test
public void testGetNoNotifications() throws IOException, URISyntaxException {
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("rest-notifications-test-3", "A6B7C8"));
    URI request = UriBuilder.fromUri(getContextURI()).path("/notifications").build();
    HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    InputStream body = response.getEntity().getContent();
    List<SubscriptionInfoVO> infos = parseUserArray(body);
    assertNotNull(infos);
    assertTrue(infos.isEmpty());
    conn.shutdown();
}
Also used : SubscriptionInfoVO(org.olat.core.commons.services.notifications.restapi.vo.SubscriptionInfoVO) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 14 with SubscriptionInfoVO

use of org.olat.core.commons.services.notifications.restapi.vo.SubscriptionInfoVO in project OpenOLAT by OpenOLAT.

the class NotificationsWebService method createSubscriptionInfoVO.

private SubscriptionInfoVO createSubscriptionInfoVO(Publisher publisher, SubscriptionInfo info) {
    SubscriptionInfoVO infoVO = new SubscriptionInfoVO(info);
    if (info.getSubscriptionListItems() != null && !info.getSubscriptionListItems().isEmpty()) {
        List<SubscriptionListItemVO> itemVOes = new ArrayList<SubscriptionListItemVO>(info.getSubscriptionListItems().size());
        String publisherType = publisher.getType();
        String resourceType = publisher.getResName();
        for (SubscriptionListItem item : info.getSubscriptionListItems()) {
            SubscriptionListItemVO itemVO = new SubscriptionListItemVO(item);
            // resource specific
            if ("BusinessGroup".equals(resourceType)) {
                itemVO.setGroupKey(publisher.getResId());
            } else if ("CourseModule".equals(resourceType)) {
                itemVO.setCourseKey(publisher.getResId());
                itemVO.setCourseNodeId(publisher.getSubidentifier());
            }
            // publisher specififc
            if ("Forum".equals(publisherType)) {
                // extract the message id
                List<ContextEntry> ces = BusinessControlFactory.getInstance().createCEListFromString(item.getBusinessPath());
                if (ces.size() > 0) {
                    ContextEntry lastCe = ces.get(ces.size() - 1);
                    if ("Message".equals(lastCe.getOLATResourceable().getResourceableTypeName())) {
                        itemVO.setMessageKey(lastCe.getOLATResourceable().getResourceableId());
                    }
                }
            } else if ("FolderModule".equals(publisherType)) {
                List<ContextEntry> ces = BusinessControlFactory.getInstance().createCEListFromString(item.getBusinessPath());
                if (ces.size() > 0) {
                    ContextEntry lastCe = ces.get(ces.size() - 1);
                    if (lastCe.getOLATResourceable().getResourceableTypeName().startsWith("path=")) {
                        String path = BusinessControlFactory.getInstance().getPath(lastCe);
                        itemVO.setPath(path);
                    }
                }
            }
            itemVOes.add(itemVO);
        }
        infoVO.setItems(itemVOes);
    }
    return infoVO;
}
Also used : SubscriptionInfoVO(org.olat.core.commons.services.notifications.restapi.vo.SubscriptionInfoVO) SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) SubscriptionListItemVO(org.olat.core.commons.services.notifications.restapi.vo.SubscriptionListItemVO) ContextEntry(org.olat.core.id.context.ContextEntry)

Example 15 with SubscriptionInfoVO

use of org.olat.core.commons.services.notifications.restapi.vo.SubscriptionInfoVO in project OpenOLAT by OpenOLAT.

the class NotificationsWebService method getNotifications.

/**
 * Retrieves the notification of the logged in user.
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The notifications
 * @response.representation.200.example {@link org.olat.core.commons.services.notifications.restapi.vo.Examples#SAMPLE_INFOVOes}
 * @response.representation.404.doc The identity not found
 * @param date The date (optional)
 * @param type The type of notifications (User, Forum...) (optional)
 * @param httpRequest The HTTP request
 * @return an xml or json representation of a the user being search. The xml
 *         correspond to a <code>SubscriptionInfoVO</code>. <code>SubscriptionInfoVO</code>
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getNotifications(@QueryParam("date") String date, @QueryParam("type") String type, @Context HttpServletRequest httpRequest) {
    Identity identity = RestSecurityHelper.getIdentity(httpRequest);
    Locale locale = RestSecurityHelper.getLocale(httpRequest);
    Date compareDate;
    if (StringHelper.containsNonWhitespace(date)) {
        compareDate = parseDate(date, locale);
    } else {
        NotificationsManager man = NotificationsManager.getInstance();
        compareDate = man.getCompareDateFromInterval(man.getUserIntervalOrDefault(identity));
    }
    List<String> types = new ArrayList<String>(1);
    if (StringHelper.containsNonWhitespace(type)) {
        types.add(type);
    }
    Map<Subscriber, SubscriptionInfo> subsInfoMap = NotificationHelper.getSubscriptionMap(identity, locale, true, compareDate, types);
    List<SubscriptionInfoVO> voes = new ArrayList<SubscriptionInfoVO>();
    for (Map.Entry<Subscriber, SubscriptionInfo> entry : subsInfoMap.entrySet()) {
        SubscriptionInfo info = entry.getValue();
        if (info.hasNews()) {
            Subscriber subscriber = entry.getKey();
            voes.add(createSubscriptionInfoVO(subscriber.getPublisher(), info));
        }
    }
    SubscriptionInfoVO[] voesArr = new SubscriptionInfoVO[voes.size()];
    voes.toArray(voesArr);
    return Response.ok(voesArr).build();
}
Also used : Locale(java.util.Locale) ArrayList(java.util.ArrayList) SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo) Date(java.util.Date) RestSecurityHelper.parseDate(org.olat.restapi.security.RestSecurityHelper.parseDate) SubscriptionInfoVO(org.olat.core.commons.services.notifications.restapi.vo.SubscriptionInfoVO) Subscriber(org.olat.core.commons.services.notifications.Subscriber) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) Identity(org.olat.core.id.Identity) Map(java.util.Map) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

SubscriptionInfoVO (org.olat.core.commons.services.notifications.restapi.vo.SubscriptionInfoVO)22 HttpResponse (org.apache.http.HttpResponse)18 HttpGet (org.apache.http.client.methods.HttpGet)18 Test (org.junit.Test)18 UriBuilder (javax.ws.rs.core.UriBuilder)12 SubscriptionListItemVO (org.olat.core.commons.services.notifications.restapi.vo.SubscriptionListItemVO)10 Identity (org.olat.core.id.Identity)10 InputStream (java.io.InputStream)8 PublisherData (org.olat.core.commons.services.notifications.PublisherData)8 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)8 URI (java.net.URI)6 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 CollaborationTools (org.olat.collaboration.CollaborationTools)4 ICourse (org.olat.course.ICourse)4 CourseNodeConfiguration (org.olat.course.nodes.CourseNodeConfiguration)4 BusinessGroup (org.olat.group.BusinessGroup)4 Forum (org.olat.modules.fo.Forum)4 Message (org.olat.modules.fo.Message)4 RepositoryEntry (org.olat.repository.RepositoryEntry)4