private List<Content> extractContentsForUser(UserDetails user, String eMail, List<Content> contents,
Map<String, List<String>> profileAttributes, NewsletterReport newsletterReport) throws ApsSystemException {
NewsletterConfig config = this.getConfig();
List<Content> userContents = new ArrayList<Content>();
String username = user.getUsername();
IUserProfile profile = (IUserProfile) user.getProfile();
if (profile != null) {
String allContentsAttribute = config.getAllContentsAttributeName();
boolean allContents = false;
if (null != allContentsAttribute) {
Boolean value = (Boolean) profile.getValue(allContentsAttribute);
allContents = value != null && value.booleanValue();
}
List<String> groupNames = this.extractUserGroupNames(user);
boolean isGroupAdmin = groupNames.contains(Group.ADMINS_GROUP_NAME);
for (int i=0; i<contents.size(); i++) {
Content content = contents.get(i);
String contentId = content.getId();
List<String> contentProfileAttributes = profileAttributes.get(contentId);
ContentReport contentReport = newsletterReport.getContentReport(contentId);
if (contentReport != null && (isGroupAdmin || this.checkUserAllowedOnContent(groupNames, content))) {
if (allContents) {
userContents.add(content);
contentReport.addRecipient(username, eMail);
} else if (contentProfileAttributes!=null && contentProfileAttributes.size() > 0) {
for (String profileAttrName : contentProfileAttributes) {
Boolean value = (Boolean) profile.getValue(profileAttrName);
if (value != null && value.booleanValue()) {
userContents.add(content);
contentReport.addRecipient(username, eMail);
break;
}