use of com.xpn.xwiki.objects.classes.BaseClass in project celements-blog by celements.
the class AddBlogDateValidationMigratorTest method testMigrate.
@Test
public void testMigrate() throws Exception {
XWikiDocument docMock = createMockAndAddToDefault(XWikiDocument.class);
DocumentReference docRef = new DocumentReference(context.getDatabase(), "XWiki", "ArticleClass");
expect(xwiki.getDocument(eq(docRef), same(context))).andReturn(docMock).once();
BaseClass bClass = new BaseClass();
bClass.addDateField("publishdate", "publishdate", "dd.MM.yyyy HH:mm", 0);
bClass.addDateField("archivedate", "archivedate", "dd.MM.yyyy HH:mm", 0);
expect(docMock.getXClass()).andReturn(bClass).once();
xwiki.saveDocument(docMock, context);
expectLastCall();
replayDefault();
migrator.migrate(null, context);
verifyDefault();
assertTrue(((DateClass) bClass.get("publishdate")).getValidationRegExp().length() > 0);
assertTrue(((DateClass) bClass.get("archivedate")).getValidationRegExp().length() > 0);
assertEquals("cel_blog_validation_publishdate", ((DateClass) bClass.get("publishdate")).getValidationMessage());
assertEquals("cel_blog_validation_archivedate", ((DateClass) bClass.get("archivedate")).getValidationMessage());
assertEquals(((DateClass) bClass.get("publishdate")).getDateFormat(), "dd.MM.yyyy HH:mm");
assertEquals(((DateClass) bClass.get("archivedate")).getDateFormat(), "dd.MM.yyyy HH:mm");
}
use of com.xpn.xwiki.objects.classes.BaseClass in project celements-blog by celements.
the class BlogClasses method getBlogConfigClass.
BaseClass getBlogConfigClass() throws XWikiException {
XWikiDocument doc;
XWiki xwiki = getContext().getWiki();
boolean needsUpdate = false;
DocumentReference blogConfigClassRef = getBlogConfigClassRef(getContext().getDatabase());
try {
doc = xwiki.getDocument(blogConfigClassRef, getContext());
} catch (Exception e) {
doc = new XWikiDocument(blogConfigClassRef);
needsUpdate = true;
}
BaseClass bclass = doc.getXClass();
bclass.setXClassReference(blogConfigClassRef);
needsUpdate |= bclass.addBooleanField(PROPERTY_BLOG_CONFIG_IS_SUBSCRIBABLE, PROPERTY_BLOG_CONFIG_IS_SUBSCRIBABLE, "yesno");
needsUpdate |= bclass.addTextField(PROPERTY_BLOG_CONFIG_SUBSCRIBE_TO, PROPERTY_BLOG_CONFIG_SUBSCRIBE_TO, 30);
needsUpdate |= bclass.addNumberField("art_per_page", "art_per_page", 5, "integer");
needsUpdate |= bclass.addBooleanField("is_newsletter", "is_newsletter", "yesno");
needsUpdate |= bclass.addTextField("from_address", "from_address", 30);
needsUpdate |= bclass.addTextField("reply_to_address", "reply_to_address", 30);
needsUpdate |= bclass.addBooleanField("unsubscribe_info", "unsubscribe_info", "yesno");
needsUpdate |= bclass.addTextField("template", "template", 30);
needsUpdate |= bclass.addStaticListField("blogeditor", "blogeditor", 1, false, "plain|wysiwyg", "select");
needsUpdate |= bclass.addTextField(PROPERTY_BLOG_CONFIG_BLOGSPACE, PROPERTY_BLOG_CONFIG_BLOGSPACE, 30);
needsUpdate |= bclass.addStaticListField("viewtype", "viewtype", 1, false, "title|extract|full", "select");
needsUpdate |= bclass.addBooleanField("has_comments", "has_comments", "yesno");
needsUpdate |= bclass.addNumberField(PROPERTY_BLOG_CONFIG_MAX_NUM_CHARS_FIELD, "max number of characters in extract", 5, "integer");
setContentAndSaveClassDocument(doc, needsUpdate);
return bclass;
}
use of com.xpn.xwiki.objects.classes.BaseClass in project celements-blog by celements.
the class BlogClasses method getArticleClass.
BaseClass getArticleClass() throws XWikiException {
XWikiDocument doc;
XWiki xwiki = getContext().getWiki();
boolean needsUpdate = false;
DocumentReference articleClassRef = getArticleClassRef(getContext().getDatabase());
try {
doc = xwiki.getDocument(articleClassRef, getContext());
} catch (Exception e) {
doc = new XWikiDocument(articleClassRef);
needsUpdate = true;
}
BaseClass bclass = doc.getXClass();
bclass.setXClassReference(articleClassRef);
needsUpdate |= bclass.addTextAreaField("extract", "extract", 80, 15);
needsUpdate |= bclass.addTextAreaField("title", "title", 80, 15);
// category
needsUpdate |= bclass.addTextAreaField("content", "content", 80, 15);
needsUpdate |= bclass.addNumberField("id", "id", 30, "integer");
needsUpdate |= bclass.addTextField(PROPERTY_ARTICLE_LANG, PROPERTY_ARTICLE_LANG, 30);
needsUpdate |= bclass.addTextField("blogeditor", "blogeditor", 30);
needsUpdate |= addDateField(bclass, PROPERTY_ARTICLE_PUBLISH_DATE, PROPERTY_ARTICLE_PUBLISH_DATE, "dd.MM.yyyy HH:mm", 0, 0, getRegexDate(false, true), "cel_blog_validation_publishdate");
needsUpdate |= bclass.addBooleanField("hasComments", "hasComments", "yesno");
needsUpdate |= addDateField(bclass, PROPERTY_ARTICLE_ARCHIVE_DATE, PROPERTY_ARTICLE_ARCHIVE_DATE, "dd.MM.yyyy HH:mm", 0, 0, getRegexDate(true, true), "cel_blog_validation_archivedate");
needsUpdate |= bclass.addBooleanField(PROPERTY_ARTICLE_IS_SUBSCRIBABLE, PROPERTY_ARTICLE_IS_SUBSCRIBABLE, "yesno");
setContentAndSaveClassDocument(doc, needsUpdate);
return bclass;
}
use of com.xpn.xwiki.objects.classes.BaseClass in project celements-blog by celements.
the class BlogClasses method getNewsletterReceiverClass.
BaseClass getNewsletterReceiverClass() throws XWikiException {
XWikiDocument doc;
XWiki xwiki = getContext().getWiki();
boolean needsUpdate = false;
DocumentReference newsletterReceiverClassRef = getNewsletterReceiverClassRef(getContext().getDatabase());
try {
doc = xwiki.getDocument(newsletterReceiverClassRef, getContext());
} catch (XWikiException e) {
LOGGER.error(e);
doc = new XWikiDocument(newsletterReceiverClassRef);
needsUpdate = true;
}
BaseClass bclass = doc.getXClass();
bclass.setXClassReference(newsletterReceiverClassRef);
needsUpdate |= bclass.addTextField("email", "E-Mail", 30);
needsUpdate |= bclass.addTextField("language", "Language code (ISO 639-1)", 30);
needsUpdate |= bclass.addBooleanField("isactive", "Is Active", "yesno");
needsUpdate |= bclass.addTextField("subscribed", "Subscribed to Newsletter(s) - " + "separated by ','", 30);
if (!"internal".equals(bclass.getCustomMapping())) {
needsUpdate = true;
bclass.setCustomMapping("internal");
}
setContentAndSaveClassDocument(doc, needsUpdate);
return bclass;
}
use of com.xpn.xwiki.objects.classes.BaseClass in project celements-blog by celements.
the class BlogClasses method getReceiverEMailClass.
BaseClass getReceiverEMailClass() throws XWikiException {
XWikiDocument doc;
XWiki xwiki = getContext().getWiki();
boolean needsUpdate = false;
DocumentReference receiverEMailClassRef = getReceiverEMailClassRef(getContext().getDatabase());
try {
doc = xwiki.getDocument(receiverEMailClassRef, getContext());
} catch (Exception e) {
doc = new XWikiDocument(receiverEMailClassRef);
needsUpdate = true;
}
BaseClass bclass = doc.getXClass();
bclass.setXClassReference(receiverEMailClassRef);
needsUpdate |= bclass.addTextField("email", "email", 30);
needsUpdate |= bclass.addBooleanField("is_active", "is_active", "yesno");
needsUpdate |= bclass.addStaticListField("address_type", "address_type", 1, false, "to|cc|bcc", "select");
setContentAndSaveClassDocument(doc, needsUpdate);
return bclass;
}
Aggregations