use of org.olat.core.commons.services.notifications.restapi.vo.SubscriptionInfoVO in project openolat by klemens.
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();
}
use of org.olat.core.commons.services.notifications.restapi.vo.SubscriptionInfoVO in project openolat by klemens.
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;
}
Aggregations