use of org.xwiki.model.reference.DocumentReference in project xwiki-platform by xwiki.
the class SendMailConfigClassDocumentConfigurationSourceTest method getPropertyWhenNoSendMailConfigClassXObject.
@Test
public void getPropertyWhenNoSendMailConfigClassXObject() throws Exception {
Cache<Object> cache = mock(Cache.class);
CacheManager cacheManager = this.mocker.getInstance(CacheManager.class);
when(cacheManager.createNewCache(any(CacheConfiguration.class))).thenReturn(cache);
WikiDescriptorManager wikiDescriptorManager = this.mocker.getInstance(WikiDescriptorManager.class);
when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("wiki");
LocalDocumentReference classReference = new LocalDocumentReference("Mail", "SendMailConfigClass");
XWikiDocument document = mock(XWikiDocument.class);
when(document.getXObject(classReference)).thenReturn(null);
DocumentReference documentReference = new DocumentReference("wiki", "Mail", "MailConfig");
XWiki xwiki = mock(XWiki.class);
when(xwiki.getDocument(eq(documentReference), any(XWikiContext.class))).thenReturn(document);
XWikiContext xcontext = mock(XWikiContext.class);
when(xcontext.getWiki()).thenReturn(xwiki);
Provider<XWikiContext> xcontextProvider = this.mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
when(xcontextProvider.get()).thenReturn(xcontext);
assertEquals("defaultValue", this.mocker.getComponentUnderTest().getProperty("key", "defaultValue"));
}
use of org.xwiki.model.reference.DocumentReference in project xwiki-platform by xwiki.
the class SendMailConfigClassDocumentConfigurationSourceTest method getPropertyWhenSendMailConfigClassXObjectExists.
@Test
public void getPropertyWhenSendMailConfigClassXObjectExists() throws Exception {
ConverterManager converterManager = this.mocker.getInstance(ConverterManager.class);
when(converterManager.convert(String.class, "value")).thenReturn("value");
Cache<Object> cache = mock(Cache.class);
CacheManager cacheManager = this.mocker.getInstance(CacheManager.class);
when(cacheManager.createNewCache(any(CacheConfiguration.class))).thenReturn(cache);
WikiDescriptorManager wikiDescriptorManager = this.mocker.getInstance(WikiDescriptorManager.class);
when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("wiki");
LocalDocumentReference classReference = new LocalDocumentReference("Mail", "SendMailConfigClass");
BaseProperty property = mock(BaseProperty.class);
when(property.toText()).thenReturn("value");
BaseObject object = mock(BaseObject.class);
when(object.getField("key")).thenReturn(property);
XWikiDocument document = mock(XWikiDocument.class);
when(document.getXObject(classReference)).thenReturn(object);
DocumentReference documentReference = new DocumentReference("wiki", "Mail", "MailConfig");
XWiki xwiki = mock(XWiki.class);
when(xwiki.getDocument(eq(documentReference), any(XWikiContext.class))).thenReturn(document);
XWikiContext xcontext = mock(XWikiContext.class);
when(xcontext.getWiki()).thenReturn(xwiki);
Provider<XWikiContext> xcontextProvider = this.mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
when(xcontextProvider.get()).thenReturn(xcontext);
assertEquals("value", this.mocker.getComponentUnderTest().getProperty("key", "defaultValue"));
}
use of org.xwiki.model.reference.DocumentReference in project xwiki-platform by xwiki.
the class GroupMimeMessageFactory method createMessage.
@Override
public Iterator<MimeMessage> createMessage(Object groupReferenceObject, Map<String, Object> parameters) throws MessagingException {
DocumentReference groupReference = getTypedSource(groupReferenceObject, DocumentReference.class);
// We verify that we have both a Factory hint specified but also the source for the Factory.
validateParameters(parameters, HINT, SOURCE);
// Extract from the passed parameters the MimeMessageFactory to use to create a single mail
String factoryHint = (String) parameters.get(HINT);
MimeMessageFactory factory = getInternalMimeMessageFactory(factoryHint);
GroupMimeMessageIterator iterator = new GroupMimeMessageIterator(groupReference, factory, parameters, this.componentManagerProvider.get());
return iterator;
}
use of org.xwiki.model.reference.DocumentReference in project xwiki-platform by xwiki.
the class AbstractTemplateMimeMessageFactory method createMessage.
@Override
public MimeMessage createMessage(Object templateReferenceObject, Map<String, Object> parameters) throws MessagingException {
DocumentReference templateReference = getTypedSource(templateReferenceObject, DocumentReference.class);
// Note: We don't create a Session here ATM since it's not required. The returned MimeMessage will be
// given a valid Session when it's deserialized from the mail content store for sending.
ExtendedMimeMessage message = new ExtendedMimeMessage();
// Handle optional "from" address.
Address from = this.converterManager.convert(Address.class, parameters.get("from"));
if (from != null) {
message.setFrom(from);
}
// Handle optional "to", "cc" and "bcc" addresses.
setRecipient(message, Message.RecipientType.TO, parameters.get("to"));
setRecipient(message, Message.RecipientType.CC, parameters.get("cc"));
setRecipient(message, Message.RecipientType.BCC, parameters.get("bcc"));
// Handle optional "type" parameter to set the mail type
// Set the Message type if passed in parameters
String type = (String) parameters.get("type");
if (type != null) {
message.setType(type);
}
// Handle the subject. Get it from the template
Map<String, Object> velocityVariables = (Map<String, Object>) parameters.get("velocityVariables");
Object localeValue = parameters.get("language");
String subject = getTemplateManager().evaluate(templateReference, "subject", velocityVariables, localeValue);
message.setSubject(subject);
// Add a default body part taken from the template.
Multipart multipart = new MimeMultipart("mixed");
multipart.addBodyPart(getMimeBodyPartFactory().create(templateReference, parameters));
message.setContent(multipart);
return message;
}
use of org.xwiki.model.reference.DocumentReference in project xwiki-platform by xwiki.
the class UsersMimeMessageIterator method createMessageInternal.
@Override
protected ExtendedMimeMessage createMessageInternal() throws MessagingException {
ExtendedMimeMessage mimeMessage;
DocumentReference userReference = users.get(this.position);
// If the user has no email address then return a null Mime Message so that it's skipped
Object emailObject = this.documentAccessBridge.getProperty(userReference, new DocumentReference(userReference.getWikiReference().getName(), "XWiki", "XWikiUsers"), "email");
if (emailObject != null) {
String email = emailObject.toString();
Map<String, Object> parameters = (Map<String, Object>) this.parameters.get("parameters");
mimeMessage = ExtendedMimeMessage.wrap(this.factory.createMessage(this.parameters.get("source"), parameters));
mimeMessage.addRecipient(Message.RecipientType.TO, InternetAddress.parse(email)[0]);
} else {
getLogger().warn("User [{}] has no email defined. Email has not been sent to that user.", userReference);
mimeMessage = null;
}
return mimeMessage;
}
Aggregations