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();
}
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();
}
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();
}
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;
}
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();
}
Aggregations