use of org.xwiki.model.reference.ClassPropertyReference in project xwiki-platform by xwiki.
the class XClassMigratorListener method migrate.
private void migrate(PropertyClass newPropertyClass, String documentName, XWikiContext xcontext) throws XWikiException {
BaseProperty newProperty = newPropertyClass.newProperty();
ClassPropertyReference propertyReference = newPropertyClass.getReference();
EntityReference classReference = propertyReference.extractReference(EntityType.DOCUMENT);
XWikiDocument document = xcontext.getWiki().getDocument(this.resolver.resolve(documentName, classReference), xcontext);
boolean modified = false;
for (BaseObject xobject : document.getXObjects(classReference)) {
BaseProperty property = (BaseProperty) xobject.getField(propertyReference.getName());
// If the existing field is of different kind than what is produced by the new class property
if (property != null && property.getClass() != newProperty.getClass()) {
BaseProperty<?> convertedProperty = this.propertyConverter.convertProperty(property, newPropertyClass);
// Set new field
if (convertedProperty != null) {
// Mark old field for removal, only if the conversion was successful, to avoid losing data.
xobject.removeField(propertyReference.getName());
// Don't set the new property if it's null (it means the property is not set).
xobject.safeput(propertyReference.getName(), convertedProperty);
modified = true;
}
}
}
// If anything changed save the document
if (modified) {
xcontext.getWiki().saveDocument(document, "Migrated property [" + propertyReference.getName() + "] from class [" + this.localSerializer.serialize(classReference) + "]", xcontext);
}
}
use of org.xwiki.model.reference.ClassPropertyReference in project xwiki-platform by xwiki.
the class DocumentUnifiedDiffBuilder method addClassPropertyDiff.
private void addClassPropertyDiff(PropertyClass previousProperty, PropertyClass nextProperty, DocumentUnifiedDiff documentDiff) {
ClassPropertyReference previousReference = getClassPropertyVersionReference(previousProperty, documentDiff.getPreviousReference());
ClassPropertyReference nextReference = getClassPropertyVersionReference(nextProperty, documentDiff.getNextReference());
EntityUnifiedDiff<ClassPropertyReference> classPropertyDiff = new EntityUnifiedDiff<>(previousReference, nextReference);
// Catch a property type change.
maybeAddDiff(classPropertyDiff, "type", previousProperty == null ? null : previousProperty.getClassType(), nextProperty == null ? null : nextProperty.getClassType());
addObjectDiff(previousProperty == null ? new PropertyClass() : previousProperty, nextProperty == null ? new PropertyClass() : nextProperty, classPropertyDiff);
// The property name is already specified by the previous / next reference.
classPropertyDiff.remove("name");
// This meta property is not used (there's no UI to change it).
classPropertyDiff.remove("unmodifiable");
if (classPropertyDiff.size() > 0) {
documentDiff.getClassPropertyDiffs().add(classPropertyDiff);
}
}
use of org.xwiki.model.reference.ClassPropertyReference in project xwiki-platform by xwiki.
the class ClassPropertiesTreeNode method getChildren.
@Override
protected List<String> getChildren(DocumentReference documentReference, int offset, int limit) throws Exception {
XWikiContext xcontext = this.xcontextProvider.get();
XWikiDocument document = xcontext.getWiki().getDocument(documentReference, xcontext);
List<String> properties = new ArrayList<String>(document.getXClass().getPropertyList());
Collections.sort(properties);
List<String> children = new ArrayList<String>();
for (String property : subList(properties, offset, limit)) {
children.add(serialize(new ClassPropertyReference(property, documentReference)));
}
return children;
}
use of org.xwiki.model.reference.ClassPropertyReference in project xwiki-platform by xwiki.
the class DBListClassPropertyValuesProviderTest method getValuesForMissingProperty.
@Test
public void getValuesForMissingProperty() throws Exception {
ClassPropertyReference propertyReference = new ClassPropertyReference("status", this.classReference);
when(this.entityReferenceSerializer.serialize(propertyReference)).thenReturn("status reference");
try {
this.mocker.getComponentUnderTest().getValues(propertyReference, 0);
fail();
} catch (XWikiRestException expected) {
assertEquals("Property [status reference] not found.", expected.getMessage());
}
}
use of org.xwiki.model.reference.ClassPropertyReference in project xwiki-platform by xwiki.
the class DBListClassPropertyValuesProviderTest method getValuesAllowed.
@Test
public void getValuesAllowed() throws Exception {
ClassPropertyReference propertyReference = new ClassPropertyReference("category", this.classReference);
DocumentReference authorReference = this.dbListClass.getOwnerDocument().getAuthorReference();
PropertyValues values = new PropertyValues();
when(this.authorExecutor.call(any(), eq(authorReference))).thenReturn(values);
assertSame(values, this.mocker.getComponentUnderTest().getValues(propertyReference, 3));
assertSame(values, this.mocker.getComponentUnderTest().getValues(propertyReference, 0, "text"));
}
Aggregations