use of com.erudika.para.core.User in project scoold by Erudika.
the class ScooldUtils method sendNewPostNotifications.
@SuppressWarnings("unchecked")
public void sendNewPostNotifications(Post question, HttpServletRequest req) {
if (question == null) {
return;
}
// the current user - same as utils.getAuthUser(req)
Profile postAuthor = question.getAuthor() != null ? question.getAuthor() : pc.read(question.getCreatorid());
if (!question.getType().equals(Utils.type(UnapprovedQuestion.class))) {
if (!isNewPostNotificationAllowed()) {
return;
}
Map<String, Object> model = new HashMap<String, Object>();
Map<String, String> lang = getLang(req);
String name = postAuthor.getName();
String body = Utils.markdownToHtml(question.getBody());
String picture = Utils.formatMessage("<img src='{0}' width='25'>", escapeHtmlAttribute(avatarRepository.getLink(postAuthor, AvatarFormat.Square25)));
String postURL = getServerURL() + question.getPostLink(false, false);
String tagsString = Optional.ofNullable(question.getTags()).orElse(Collections.emptyList()).stream().map(t -> "<span class=\"tag\">" + escapeHtml(t) + "</span>").collect(Collectors.joining(" "));
String subject = Utils.formatMessage(lang.get("notification.newposts.subject"), name, Utils.abbreviate(question.getTitle(), 255));
model.put("subject", escapeHtml(subject));
model.put("logourl", getSmallLogoUrl());
model.put("heading", Utils.formatMessage(lang.get("notification.newposts.heading"), picture, escapeHtml(name)));
model.put("body", Utils.formatMessage("<h2><a href='{0}'>{1}</a></h2><div>{2}</div><br>{3}", postURL, escapeHtml(question.getTitle()), body, tagsString));
Set<String> emails = new HashSet<String>(getNotificationSubscribers(EMAIL_ALERTS_PREFIX + "new_post_subscribers"));
emails.addAll(getFavTagsSubscribers(question.getTags()));
sendEmailsToSubscribersInSpace(emails, question.getSpace(), subject, compileEmailTemplate(model));
} else if (postsNeedApproval() && question instanceof UnapprovedQuestion) {
Report rep = new Report();
rep.setDescription("New question awaiting approval");
rep.setSubType(Report.ReportType.OTHER);
rep.setLink(question.getPostLink(false, false));
rep.setAuthorName(postAuthor.getName());
rep.create();
}
}
use of com.erudika.para.core.User in project scoold by Erudika.
the class ScooldUtils method getFavTagsSubscribers.
private Set<String> getFavTagsSubscribers(List<String> tags) {
if (!tags.isEmpty()) {
Set<String> emails = new LinkedHashSet<>();
// find all user objects even if there are more than 10000 users in the system
Pager pager = new Pager(1, "_docid", false, Config.MAX_ITEMS_PER_PAGE);
List<Profile> profiles;
do {
profiles = pc.findQuery(Utils.type(Profile.class), "properties.favtags:(" + tags.stream().map(t -> "\"".concat(t).concat("\"")).distinct().collect(Collectors.joining(" ")) + ") AND properties.favtagsEmailsEnabled:true", pager);
if (!profiles.isEmpty()) {
List<User> users = pc.readAll(profiles.stream().map(p -> p.getCreatorid()).distinct().collect(Collectors.toList()));
users.stream().forEach(u -> emails.add(u.getEmail()));
}
} while (!profiles.isEmpty());
return emails;
}
return Collections.emptySet();
}
use of com.erudika.para.core.User in project scoold by Erudika.
the class AdminController method importUsersFromSO.
private void importUsersFromSO(List<Map<String, Object>> objs, List<ParaObject> toImport) throws ParseException {
logger.info("Importing {} users...", objs.size());
for (Map<String, Object> obj : objs) {
User u = new User();
u.setId("user_" + (Integer) obj.get("id"));
u.setTimestamp(DateUtils.parseDate((String) obj.get("creationDate"), soDateFormat1, soDateFormat2).getTime());
u.setActive(true);
u.setCreatorid(((Integer) obj.get("accountId")).toString());
u.setGroups("admin".equalsIgnoreCase((String) obj.get("userTypeId")) ? User.Groups.ADMINS.toString() : User.Groups.USERS.toString());
u.setEmail(u.getId() + "@scoold.com");
u.setIdentifier(u.getEmail());
u.setName((String) obj.get("realName"));
String lastLogin = (String) obj.get("lastLoginDate");
u.setUpdated(StringUtils.isBlank(lastLogin) ? null : DateUtils.parseDate(lastLogin, soDateFormat1, soDateFormat2).getTime());
u.setPicture((String) obj.get("profileImageUrl"));
u.setPassword(Utils.generateSecurityToken(10));
Profile p = Profile.fromUser(u);
p.setVotes((Integer) obj.get("reputation"));
p.setAboutme((String) obj.getOrDefault("title", ""));
p.setLastseen(u.getUpdated());
toImport.add(u);
toImport.add(p);
}
pc.createAll(toImport);
}
use of com.erudika.para.core.User in project scoold by Erudika.
the class GravatarAvatarRepositoryTest method setUp.
@Before
public void setUp() {
this.profile = new Profile();
this.profile.setUser(new User());
this.defaultRepository = new DefaultAvatarRepository();
this.gravatarGenerator = new GravatarAvatarGenerator();
this.repository = new GravatarAvatarRepository(gravatarGenerator, defaultRepository);
}
use of com.erudika.para.core.User in project scoold by Erudika.
the class SigninController method loginWithIdToken.
private void loginWithIdToken(String jwt, HttpServletRequest req, HttpServletResponse res) {
User u = pc.signIn("passwordless", jwt, false);
if (u != null) {
setAuthCookie(u.getPassword(), req, res);
onAuthSuccess(u, req, res);
}
}
Aggregations