use of com.xpn.xwiki.objects.classes.BaseClass in project xwiki-platform by xwiki.
the class XarExtensionHandlerTest method testUpgradeOnWiki.
@Test
public void testUpgradeOnWiki() throws Throwable {
install(this.localXarExtensiontId1, "wiki", this.contextUser);
verifyHasAdminRight(2);
// Do some local modifications
XWikiDocument deletedpage = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space", "deletedpage"), getXWikiContext());
this.oldcore.getSpyXWiki().deleteDocument(deletedpage, getXWikiContext());
XWikiDocument modifieddeletedpage = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space", "modifieddeletedpage"), getXWikiContext());
this.oldcore.getSpyXWiki().deleteDocument(modifieddeletedpage, getXWikiContext());
XWikiDocument pagewithobject = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space", "pagewithobject"), getXWikiContext());
pagewithobject.removeXObjects(new LocalDocumentReference("XWiki", "XWikiGroups"));
this.oldcore.getSpyXWiki().saveDocument(pagewithobject, getXWikiContext());
XWikiDocument deletedpagewithmodifications = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space1", "modified"), getXWikiContext());
deletedpagewithmodifications.setContent("modified content");
// upgrade
install(this.localXarExtensiontId2, "wiki", this.contextUser);
verifyHasAdminRight(3);
// validate
// samespace.samepage
XWikiDocument samepage = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "samespace", "samepage"), getXWikiContext());
Assert.assertFalse("Document samespace has been removed from the database", samepage.isNew());
Assert.assertEquals("Wrong versions", "1.1", samepage.getVersion());
// space.page
XWikiDocument modifiedpage = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space", "page"), getXWikiContext());
Assert.assertFalse("Document wiki.space.page has not been saved in the database", modifiedpage.isNew());
Assert.assertEquals("Wrong content", "content 2", modifiedpage.getContent());
Assert.assertEquals("Wrong author", this.contextUser, modifiedpage.getAuthorReference());
Assert.assertEquals("Wrong versions", "2.1", modifiedpage.getVersion());
Assert.assertEquals("Wrong version", Locale.ROOT, modifiedpage.getLocale());
Assert.assertEquals("Wrong customclass", "customclass2", modifiedpage.getCustomClass());
Assert.assertEquals("Wrong defaultTemplate", "defaultTemplate2", modifiedpage.getDefaultTemplate());
Assert.assertEquals("Wrong hidden", true, modifiedpage.isHidden());
Assert.assertEquals("Wrong ValidationScript", "validationScript2", modifiedpage.getValidationScript());
BaseClass baseClass = modifiedpage.getXClass();
Assert.assertNotNull(baseClass.getField("property"));
Assert.assertEquals("property", baseClass.getField("property").getName());
Assert.assertSame(NumberClass.class, baseClass.getField("property").getClass());
XWikiAttachment attachment = modifiedpage.getAttachment("attachment.txt");
Assert.assertNotNull(attachment);
Assert.assertEquals("attachment.txt", attachment.getFilename());
Assert.assertEquals(18, attachment.getContentLongSize(getXWikiContext()));
Assert.assertEquals("attachment content", IOUtils.toString(attachment.getContentInputStream(getXWikiContext()), StandardCharsets.UTF_8));
// space2.page2
XWikiDocument newPage = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space2", "page2"), getXWikiContext());
Assert.assertFalse("Document wiki:space2.page2 has not been saved in the database", newPage.isNew());
// space1.page1
XWikiDocument removedPage = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space1", "page1"), getXWikiContext());
Assert.assertTrue("Document wiki:space1.page1 has not been removed from the database", removedPage.isNew());
// space.deletedpage
deletedpage = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space", "deletedpage"), getXWikiContext());
Assert.assertTrue("Document wiki:space.deleted has been restored", deletedpage.isNew());
// space.modifieddeletedpage
modifieddeletedpage = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space", "modifieddeletedpage"), getXWikiContext());
Assert.assertTrue("Document wiki:space.modifieddeletedpage has been restored", modifieddeletedpage.isNew());
// space.pagewithobject
pagewithobject = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space", "pagewithobject"), getXWikiContext());
Assert.assertNull("Document wiki:space.pagewithobject does not contain an XWiki.XWikiGroups object", pagewithobject.getXObject(new LocalDocumentReference("XWiki", "XWikiGroups")));
// space1.modified
XWikiDocument space1modified = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space1", "modified"), getXWikiContext());
Assert.assertFalse("Document wiki:space.modified has been removed from the database", space1modified.isNew());
}
use of com.xpn.xwiki.objects.classes.BaseClass in project xwiki-platform by xwiki.
the class DocumentUnifiedDiffBuilder method isPrivateProperty.
private boolean isPrivateProperty(BaseProperty<?> property) {
BaseCollection<?> object = property == null ? null : property.getObject();
if (object != null) {
BaseClass xclass = object.getXClass(this.xcontextProvider.get());
if (xclass != null) {
PropertyClass propertyClass = (PropertyClass) xclass.get(property.getName());
String propertyType = propertyClass == null ? null : propertyClass.getClassType();
return "Password".equals(propertyType) || "Email".equals(propertyClass);
}
}
return false;
}
use of com.xpn.xwiki.objects.classes.BaseClass in project xwiki-platform by xwiki.
the class BaseCollection method toXML.
/**
* @deprecated since 9.0RC1, use {@link #toXML()} instead
*/
@Override
@Deprecated
public Element toXML(BaseClass bclass) {
// Set passed class in the context so that the input event generator finds it
XWikiContext xcontext = getXWikiContext();
BaseClass currentBaseClass;
DocumentReference classReference;
if (bclass != null && xcontext != null) {
classReference = bclass.getDocumentReference();
currentBaseClass = xcontext.getBaseClass(bclass.getDocumentReference());
xcontext.addBaseClass(bclass);
} else {
classReference = null;
currentBaseClass = null;
}
try {
return super.toXML();
} finally {
if (classReference != null) {
if (currentBaseClass != null) {
xcontext.addBaseClass(currentBaseClass);
} else {
xcontext.removeBaseClass(classReference);
}
}
}
}
use of com.xpn.xwiki.objects.classes.BaseClass in project xwiki-platform by xwiki.
the class BaseObject method getDiff.
@Override
public List<ObjectDiff> getDiff(Object oldEntity, XWikiContext context) {
ArrayList<ObjectDiff> difflist = new ArrayList<ObjectDiff>();
BaseObject oldObject = (BaseObject) oldEntity;
// Iterate over the new properties first, to handle changed and added objects
for (String propertyName : this.getPropertyList()) {
BaseProperty newProperty = (BaseProperty) this.getField(propertyName);
BaseProperty oldProperty = (BaseProperty) oldObject.getField(propertyName);
BaseClass bclass = getXClass(context);
PropertyClass pclass = (PropertyClass) ((bclass == null) ? null : bclass.getField(propertyName));
String propertyType = (pclass == null) ? "" : pclass.getClassType();
if (oldProperty == null) {
// The property exist in the new object, but not in the old one
if ((newProperty != null) && (!newProperty.toText().equals(""))) {
String newPropertyValue = (newProperty.getValue() instanceof String || pclass == null) ? newProperty.toText() : pclass.displayView(propertyName, this, context);
difflist.add(new ObjectDiff(getXClassReference(), getNumber(), getGuid(), ObjectDiff.ACTION_PROPERTYADDED, propertyName, propertyType, "", newPropertyValue));
}
} else if (!oldProperty.toText().equals(((newProperty == null) ? "" : newProperty.toText()))) {
// The property exists in both objects and is different
if (pclass != null) {
// Put the values as they would be displayed in the interface
String newPropertyValue = (newProperty.getValue() instanceof String) ? newProperty.toText() : pclass.displayView(propertyName, this, context);
String oldPropertyValue = (oldProperty.getValue() instanceof String) ? oldProperty.toText() : pclass.displayView(propertyName, oldObject, context);
difflist.add(new ObjectDiff(getXClassReference(), getNumber(), getGuid(), ObjectDiff.ACTION_PROPERTYCHANGED, propertyName, propertyType, oldPropertyValue, newPropertyValue));
} else {
// Cannot get property definition, so use the plain value
difflist.add(new ObjectDiff(getXClassReference(), getNumber(), getGuid(), ObjectDiff.ACTION_PROPERTYCHANGED, propertyName, propertyType, oldProperty.toText(), newProperty.toText()));
}
}
}
// Iterate over the old properties, in case there are some removed properties
for (String propertyName : oldObject.getPropertyList()) {
BaseProperty newProperty = (BaseProperty) this.getField(propertyName);
BaseProperty oldProperty = (BaseProperty) oldObject.getField(propertyName);
BaseClass bclass = getXClass(context);
PropertyClass pclass = (PropertyClass) ((bclass == null) ? null : bclass.getField(propertyName));
String propertyType = (pclass == null) ? "" : pclass.getClassType();
if (newProperty == null) {
// The property exists in the old object, but not in the new one
if ((oldProperty != null) && (!oldProperty.toText().equals(""))) {
if (pclass != null) {
// Put the values as they would be displayed in the interface
String oldPropertyValue = (oldProperty.getValue() instanceof String) ? oldProperty.toText() : pclass.displayView(propertyName, oldObject, context);
difflist.add(new ObjectDiff(oldObject.getXClassReference(), oldObject.getNumber(), oldObject.getGuid(), ObjectDiff.ACTION_PROPERTYREMOVED, propertyName, propertyType, oldPropertyValue, ""));
} else {
// Cannot get property definition, so use the plain value
difflist.add(new ObjectDiff(oldObject.getXClassReference(), oldObject.getNumber(), oldObject.getGuid(), ObjectDiff.ACTION_PROPERTYREMOVED, propertyName, propertyType, oldProperty.toText(), ""));
}
}
}
}
return difflist;
}
use of com.xpn.xwiki.objects.classes.BaseClass in project xwiki-platform by xwiki.
the class BaseObject method mergeField.
@Override
protected void mergeField(PropertyInterface currentElement, ElementInterface previousElement, ElementInterface newElement, MergeConfiguration configuration, XWikiContext context, MergeResult mergeResult) {
BaseClass baseClass = getXClass(context);
if (baseClass != null) {
PropertyClass propertyClass = (PropertyClass) baseClass.get(currentElement.getName());
if (propertyClass != null) {
try {
propertyClass.mergeProperty((BaseProperty) currentElement, (BaseProperty) previousElement, (BaseProperty) newElement, configuration, context, mergeResult);
} catch (Exception e) {
mergeResult.getLog().error("Failed to merge field [{}]", currentElement.getName(), e);
}
return;
}
}
super.mergeField(currentElement, previousElement, newElement, configuration, context, mergeResult);
}
Aggregations