use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.
the class DefaultAttachmentConverter method convert.
@Override
public List<Attachment> convert(List<XWikiAttachment> attachments) {
XWikiContext xwikiContext = getXWikiContext();
List<Attachment> attachmentList = new ArrayList<>();
for (XWikiAttachment attachment : attachments) {
attachmentList.add(new Attachment(new Document(attachment.getDoc(), xwikiContext), attachment, xwikiContext));
}
return attachmentList;
}
use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.
the class DefaultMailTemplateManager method getMailObjectsCount.
private int getMailObjectsCount(DocumentReference templateReference, DocumentReference mailClassReference) throws MessagingException {
XWikiContext context = this.xwikiContextProvider.get();
int objectsCount;
try {
List<BaseObject> objects = context.getWiki().getDocument(templateReference, context).getXObjects(mailClassReference);
if (objects != null) {
objectsCount = objects.size();
} else {
objectsCount = 0;
}
} catch (XWikiException e) {
throw new MessagingException(String.format("Failed to find number of [%s] objects in Document [%s]", mailClassReference, templateReference), e);
}
return objectsCount;
}
use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.
the class SendMailRunnable method prepareContextForQueueItem.
private void prepareContextForQueueItem(SendMailQueueItem mailItem) {
// Set the current wiki in the context. This is needed for example to be able to locate the configuration
// properties when processing the mail queue items (in waitSendWaitTime()).
XWikiContext xcontext = this.contextProvider.get();
xcontext.setWikiId(mailItem.getWikiId());
}
use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.
the class DefaultModelBridge method setStartDateForUser.
@Override
public void setStartDateForUser(DocumentReference userReference, Date startDate) throws NotificationException {
try {
XWikiContext context = contextProvider.get();
XWiki xwiki = context.getWiki();
XWikiDocument document = xwiki.getDocument(userReference, context);
List<BaseObject> objects = document.getXObjects(NOTIFICATION_PREFERENCE_CLASS);
if (objects != null) {
for (BaseObject object : objects) {
if (object != null) {
object.setDateValue(START_DATE_FIELD, startDate);
}
}
}
// Make this change a minor edit so it's not displayed, by default, in notifications
xwiki.saveDocument(document, NOTIFICATION_START_DATE_UPDATE_COMMENT, true, context);
} catch (Exception e) {
throw new NotificationException(String.format(SET_USER_START_DATE_ERROR_MESSAGE, userReference), e);
}
}
use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.
the class DefaultModelBridge method getNotificationPreferences.
private List<NotificationPreference> getNotificationPreferences(DocumentReference document, String providerHint) throws NotificationException {
XWikiContext context = contextProvider.get();
XWiki xwiki = context.getWiki();
final DocumentReference notificationPreferencesClass = NOTIFICATION_PREFERENCE_CLASS.setWikiReference(document.getWikiReference());
List<NotificationPreference> preferences = new ArrayList<>();
try {
XWikiDocument doc = xwiki.getDocument(document, context);
List<BaseObject> preferencesObj = doc.getXObjects(notificationPreferencesClass);
if (preferencesObj != null) {
for (BaseObject obj : preferencesObj) {
if (obj != null) {
String objFormat = obj.getStringValue(FORMAT_FIELD);
Date objStartDate = obj.getDateValue(START_DATE_FIELD);
Map<NotificationPreferenceProperty, Object> properties = extractNotificationPreferenceProperties(obj);
notificationPreferenceBuilder.prepare();
notificationPreferenceBuilder.setProperties(properties);
notificationPreferenceBuilder.setStartDate((objStartDate != null) ? objStartDate : doc.getCreationDate());
notificationPreferenceBuilder.setFormat(StringUtils.isNotBlank(objFormat) ? NotificationFormat.valueOf(objFormat.toUpperCase()) : NotificationFormat.ALERT);
notificationPreferenceBuilder.setTarget(document);
notificationPreferenceBuilder.setProviderHint(providerHint);
notificationPreferenceBuilder.setEnabled(obj.getIntValue(NOTIFICATION_ENABLED_FIELD, 0) != 0);
notificationPreferenceBuilder.setCategory(NotificationPreferenceCategory.DEFAULT);
preferences.add(notificationPreferenceBuilder.build());
}
}
}
} catch (Exception e) {
throw new NotificationException(String.format("Failed to get the notification preferences from the document [%s].", document), e);
}
return preferences;
}
Aggregations