Search in sources :

Example 1 with XClassPropertyUpdatedEvent

use of com.xpn.xwiki.internal.event.XClassPropertyUpdatedEvent in project xwiki-platform by xwiki.

the class XClassMigratorListener method onEvent.

@Override
public void onEvent(Event event, Object source, Object data) {
    XClassPropertyUpdatedEvent propertyEvent = (XClassPropertyUpdatedEvent) event;
    XWikiDocument newDocument = (XWikiDocument) source;
    XWikiDocument previousDocument = newDocument.getOriginalDocument();
    PropertyClass newPropertyClass = (PropertyClass) newDocument.getXClass().getField(propertyEvent.getReference().getName());
    PropertyClass previousPropertyClass = (PropertyClass) previousDocument.getXClass().getField(propertyEvent.getReference().getName());
    if (newPropertyClass != null && previousPropertyClass != null) {
        BaseProperty newProperty = newPropertyClass.newProperty();
        BaseProperty previousProperty = previousPropertyClass.newProperty();
        // New and previous class property generate different kind of properties
        if (newProperty.getClass() != previousProperty.getClass()) {
            try {
                migrate(newPropertyClass);
            } catch (QueryException e) {
                this.logger.error("Failed to migrate XClass property [{}]", newPropertyClass.getReference(), e);
            }
        }
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) QueryException(org.xwiki.query.QueryException) XClassPropertyUpdatedEvent(com.xpn.xwiki.internal.event.XClassPropertyUpdatedEvent) BaseProperty(com.xpn.xwiki.objects.BaseProperty) PropertyClass(com.xpn.xwiki.objects.classes.PropertyClass)

Aggregations

XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 XClassPropertyUpdatedEvent (com.xpn.xwiki.internal.event.XClassPropertyUpdatedEvent)1 BaseProperty (com.xpn.xwiki.objects.BaseProperty)1 PropertyClass (com.xpn.xwiki.objects.classes.PropertyClass)1 QueryException (org.xwiki.query.QueryException)1