use of org.apache.commons.lang3.builder.ToStringStyleTest.Person in project commons-lang by apache.
the class MultiLineToStringStyleTest method testPerson.
@Test
public void testPerson() {
final Person p = new Person();
p.name = "Jane Doe";
p.age = 25;
p.smoker = true;
final String pBaseStr = p.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(p));
assertEquals(pBaseStr + "[" + System.lineSeparator() + " name=Jane Doe" + System.lineSeparator() + " age=25" + System.lineSeparator() + " smoker=true" + System.lineSeparator() + "]", new ToStringBuilder(p).append("name", p.name).append("age", p.age).append("smoker", p.smoker).toString());
}
use of org.apache.commons.lang3.builder.ToStringStyleTest.Person in project commons-lang by apache.
the class NoClassNameToStringStyleTest method testPerson.
@Test
public void testPerson() {
final Person p = new Person();
p.name = "John Q. Public";
p.age = 45;
p.smoker = true;
assertEquals("[name=John Q. Public,age=45,smoker=true]", new ToStringBuilder(p).append("name", p.name).append("age", p.age).append("smoker", p.smoker).toString());
}
use of org.apache.commons.lang3.builder.ToStringStyleTest.Person in project cas by apereo.
the class CoreAuthenticationUtils method buildPrincipalResolutionContext.
/**
* New PrincipalResolutionContext.
*
* @param principalFactory the principal factory
* @param attributeRepository the attribute repository
* @param attributeMerger the attribute merger
* @param personDirectory the person directory properties
* @return the resolver
*/
public static PrincipalResolutionContext buildPrincipalResolutionContext(final PrincipalFactory principalFactory, final IPersonAttributeDao attributeRepository, final IAttributeMerger attributeMerger, final PersonDirectoryPrincipalResolverProperties... personDirectory) {
val transformers = Arrays.stream(personDirectory).map(p -> PrincipalNameTransformerUtils.newPrincipalNameTransformer(p.getPrincipalTransformation())).collect(Collectors.toList());
val transformer = new ChainingPrincipalNameTransformer(transformers);
return PrincipalResolutionContext.builder().attributeRepository(attributeRepository).attributeMerger(attributeMerger).principalFactory(principalFactory).returnNullIfNoAttributes(Arrays.stream(personDirectory).filter(p -> p.getReturnNull() != TriStateBoolean.UNDEFINED).map(p -> p.getReturnNull().toBoolean()).findFirst().orElse(Boolean.FALSE)).principalAttributeNames(Arrays.stream(personDirectory).map(PersonDirectoryPrincipalResolverProperties::getPrincipalAttribute).filter(StringUtils::isNotBlank).findFirst().orElse(StringUtils.EMPTY)).principalNameTransformer(transformer).useCurrentPrincipalId(Arrays.stream(personDirectory).filter(p -> p.getUseExistingPrincipalId() != TriStateBoolean.UNDEFINED).map(p -> p.getUseExistingPrincipalId().toBoolean()).findFirst().orElse(Boolean.FALSE)).resolveAttributes(Arrays.stream(personDirectory).filter(p -> p.getAttributeResolutionEnabled() != TriStateBoolean.UNDEFINED).map(p -> p.getAttributeResolutionEnabled().toBoolean()).findFirst().orElse(Boolean.TRUE)).activeAttributeRepositoryIdentifiers(Arrays.stream(personDirectory).filter(p -> StringUtils.isNotBlank(p.getActiveAttributeRepositoryIds())).map(p -> org.springframework.util.StringUtils.commaDelimitedListToSet(p.getActiveAttributeRepositoryIds())).filter(p -> !p.isEmpty()).findFirst().orElse(Collections.EMPTY_SET)).build();
}
use of org.apache.commons.lang3.builder.ToStringStyleTest.Person in project cas by apereo.
the class SendForgotUsernameInstructionsAction method sendForgotUsernameEmailToAccount.
/**
* Send forgot username email to account.
*
* @param query the query
* @param requestContext the request context
* @return the boolean
*/
protected boolean sendForgotUsernameEmailToAccount(final PasswordManagementQuery query, final RequestContext requestContext) {
val parameters = CollectionUtils.<String, Object>wrap("email", query.getEmail());
val credential = new BasicIdentifiableCredential();
credential.setId(query.getUsername());
val person = principalResolver.resolve(credential);
FunctionUtils.doIf(person != null && !person.getClass().equals(NullPrincipal.class), principal -> {
parameters.put("principal", principal);
requestContext.getFlashScope().put(Principal.class.getName(), person);
}).accept(person);
val reset = casProperties.getAuthn().getPm().getForgotUsername().getMail();
val request = WebUtils.getHttpServletRequestFromExternalWebflowContext(requestContext);
val body = EmailMessageBodyBuilder.builder().properties(reset).locale(Optional.ofNullable(request.getLocale())).parameters(parameters).build().produce();
return this.communicationsManager.email(reset, query.getEmail(), body);
}
use of org.apache.commons.lang3.builder.ToStringStyleTest.Person in project scoold by Erudika.
the class ScooldUtils method sendCommentNotifications.
public void sendCommentNotifications(Post parentPost, Comment comment, Profile commentAuthor, HttpServletRequest req) {
// send email notification to author of post except when the comment is by the same person
if (parentPost != null && comment != null) {
// parent author is not current user (authUser)
parentPost.setAuthor(pc.read(Profile.id(parentPost.getCreatorid())));
Map<String, Object> payload = new LinkedHashMap<>(ParaObjectUtils.getAnnotatedFields(comment, false));
payload.put("parent", parentPost);
payload.put("author", commentAuthor);
triggerHookEvent("comment.create", payload);
// get the last 5-6 commentators who want to be notified - https://github.com/Erudika/scoold/issues/201
Pager p = new Pager(1, Config._TIMESTAMP, false, 5);
boolean isCommentatorThePostAuthor = StringUtils.equals(parentPost.getCreatorid(), comment.getCreatorid());
Set<String> last5ids = pc.findChildren(parentPost, Utils.type(Comment.class), "!(" + Config._CREATORID + ":\"" + comment.getCreatorid() + "\")", p).stream().map(c -> c.getCreatorid()).distinct().collect(Collectors.toSet());
if (!isCommentatorThePostAuthor && !last5ids.contains(parentPost.getCreatorid())) {
last5ids = new HashSet<>(last5ids);
last5ids.add(parentPost.getCreatorid());
}
Map<String, String> lang = getLang(req);
List<Profile> last5commentators = pc.readAll(new ArrayList<>(last5ids));
last5commentators = last5commentators.stream().filter(u -> u.getCommentEmailsEnabled()).collect(Collectors.toList());
pc.readAll(last5commentators.stream().map(u -> u.getCreatorid()).collect(Collectors.toList())).forEach(author -> {
if (isCommentNotificationAllowed()) {
Map<String, Object> model = new HashMap<String, Object>();
String name = commentAuthor.getName();
String body = Utils.markdownToHtml(comment.getComment());
String pic = Utils.formatMessage("<img src='{0}' width='25'>", escapeHtmlAttribute(avatarRepository.getLink(commentAuthor, AvatarFormat.Square25)));
String postURL = getServerURL() + parentPost.getPostLink(false, false);
String subject = Utils.formatMessage(lang.get("notification.comment.subject"), name, parentPost.getTitle());
model.put("subject", escapeHtml(subject));
model.put("logourl", getSmallLogoUrl());
model.put("heading", Utils.formatMessage(lang.get("notification.comment.heading"), Utils.formatMessage("<a href='{0}'>{1}</a>", postURL, escapeHtml(parentPost.getTitle()))));
model.put("body", Utils.formatMessage("<h2>{0} {1}:</h2><div class='panel'>{2}</div>", pic, escapeHtml(name), body));
emailer.sendEmail(Arrays.asList(((User) author).getEmail()), subject, compileEmailTemplate(model));
}
});
}
}
Aggregations