Source:
<code>public List<ContentDTO> getAvailableNotificationsForUser(final RegisteredUserDTO user) throws ContentManagerException, SegueDatabaseException { Map<Entry<BooleanOperator, String>, List<String>> fieldsToMatch = Maps.newHashMap(); List<String> newArrayList = Lists.newArrayList(); newArrayList.add("notification"); fieldsToMatch.put(immutableEntry(BooleanOperator.AND, Constants.TYPE_FIELDNAME), newArrayList); ResultsWrapper<ContentDTO> allContentNotifications = this.contentManager .findByFieldNames(this.contentIndex, fieldsToMatch, 0, -1); Map<String, IUserNotification> listOfRecordedNotifications = getMapOfRecordedNotifications(user); List<ContentDTO> resultsToReturn = Lists.newArrayList(); for (ContentDTO c : allContentNotifications.getResults()) { IUserNotification record = listOfRecordedNotifications.get(c.getId()); if (!(c instanceof NotificationDTO)) { continue; } NotificationDTO notification = (NotificationDTO) c; if (notification.getExpiry() != null && new Date().after(notification.getExpiry())) { continue; } <START> if (c.getTags().iterator().next().equals(user.getRole().toString().toLowerCase())) { <END> if (null == record) { resultsToReturn.add(c); } else if (record.getStatus().equals(NotificationStatus.POSTPONED)) { Calendar postPoneExpiry = Calendar.getInstance(); postPoneExpiry.setTime(record.getCreated()); postPoneExpiry.add(Calendar.SECOND, Constants.NUMBER_SECONDS_IN_ONE_DAY); if (new Date().after(postPoneExpiry.getTime())) { resultsToReturn.add(c); } } else { continue; } } } return resultsToReturn; }</code><technical_language>This is right do this. if is tagged student teacher? another tag role tag? is tagged shown everyone? I java if (c.getTags() != null && !c.getTags().contains(user.getRole().name().toLowerCase())) { // Skip irrelevant notifications continue; } skip expired do things</technical_language>

Target:
public List<ContentDTO> getAvailableNotificationsForUser(final RegisteredUserDTO user) throws ContentManagerException, SegueDatabaseException { Map<Entry<BooleanOperator, String>, List<String>> fieldsToMatch = Maps.newHashMap(); List<String> newArrayList = Lists.newArrayList(); newArrayList.add("notification"); fieldsToMatch.put(immutableEntry(BooleanOperator.AND, Constants.TYPE_FIELDNAME), newArrayList); ResultsWrapper<ContentDTO> allContentNotifications = this.contentManager .findByFieldNames(this.contentIndex, fieldsToMatch, 0, -1); Map<String, IUserNotification> listOfRecordedNotifications = getMapOfRecordedNotifications(user); List<ContentDTO> resultsToReturn = Lists.newArrayList(); for (ContentDTO c : allContentNotifications.getResults()) { IUserNotification record = listOfRecordedNotifications.get(c.getId()); if (!(c instanceof NotificationDTO)) { continue; } NotificationDTO notification = (NotificationDTO) c; if (notification.getExpiry() != null && new Date().after(notification.getExpiry())) { continue; } String roleTag = user.getRole().name().toLowerCase(); if (null == c.getTags() || !c.getTags().contains(roleTag)) { continue; } if (null == record) { resultsToReturn.add(c); } else if (record.getStatus().equals(NotificationStatus.POSTPONED)) { Calendar postPoneExpiry = Calendar.getInstance(); postPoneExpiry.setTime(record.getCreated()); postPoneExpiry.add(Calendar.SECOND, Constants.NUMBER_SECONDS_IN_ONE_DAY); if (new Date().after(postPoneExpiry.getTime())) { resultsToReturn.add(c); } } else { continue; } } return resultsToReturn; }