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);
}
}
}
}
Aggregations