use of com.xpn.xwiki.objects.classes.PropertyClass in project xwiki-platform by xwiki.
the class TagPlugin method createTagProperty.
/**
* Create and add the main tag property to the provided tag object. The new property corresponds to the definition
* in the tag class, but in case of an error, the default type is a relational-stored list.
*
* @param tagObject the target tag object
* @param context the current request context
* @return the created property
* @see #TAG_PROPERTY
*/
private BaseProperty createTagProperty(BaseObject tagObject, XWikiContext context) {
BaseProperty tagProperty;
try {
BaseClass tagClass = context.getWiki().getClass(TAG_CLASS, context);
PropertyClass tagPropertyDefinition = (PropertyClass) tagClass.getField(TAG_PROPERTY);
tagProperty = tagPropertyDefinition.newProperty();
} catch (XWikiException ex) {
LOGGER.warn("Failed to properly create tag property for the tag object, creating a default one");
tagProperty = new DBStringListProperty();
}
tagProperty.setName(TAG_PROPERTY);
tagProperty.setObject(tagObject);
tagObject.safeput(TAG_PROPERTY, tagProperty);
return tagProperty;
}
use of com.xpn.xwiki.objects.classes.PropertyClass in project xwiki-platform by xwiki.
the class BaseCollection method getDiff.
public List<ObjectDiff> getDiff(Object oldObject, XWikiContext context) {
ArrayList<ObjectDiff> difflist = new ArrayList<ObjectDiff>();
BaseCollection oldCollection = (BaseCollection) oldObject;
// Iterate over the new properties first, to handle changed and added objects
for (Object key : this.getFields().keySet()) {
String propertyName = (String) key;
BaseProperty newProperty = (BaseProperty) this.getFields().get(propertyName);
BaseProperty oldProperty = (BaseProperty) oldCollection.getFields().get(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(""))) {
if (pclass != null) {
String newPropertyValue = (newProperty.getValue() instanceof String) ? newProperty.toText() : pclass.displayView(propertyName, this, context);
difflist.add(new ObjectDiff(getXClassReference(), getNumber(), "", 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, oldCollection, context);
difflist.add(new ObjectDiff(getXClassReference(), getNumber(), "", ObjectDiff.ACTION_PROPERTYCHANGED, propertyName, propertyType, oldPropertyValue, newPropertyValue));
} else {
// Cannot get property definition, so use the plain value
difflist.add(new ObjectDiff(getXClassReference(), getNumber(), "", ObjectDiff.ACTION_PROPERTYCHANGED, propertyName, propertyType, oldProperty.toText(), newProperty.toText()));
}
}
}
// Iterate over the old properties, in case there are some removed properties
for (Object key : oldCollection.getFields().keySet()) {
String propertyName = (String) key;
BaseProperty newProperty = (BaseProperty) this.getFields().get(propertyName);
BaseProperty oldProperty = (BaseProperty) oldCollection.getFields().get(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, oldCollection, context);
difflist.add(new ObjectDiff(oldCollection.getXClassReference(), oldCollection.getNumber(), "", ObjectDiff.ACTION_PROPERTYREMOVED, propertyName, propertyType, oldPropertyValue, ""));
} else {
// Cannot get property definition, so use the plain value
difflist.add(new ObjectDiff(oldCollection.getXClassReference(), oldCollection.getNumber(), "", ObjectDiff.ACTION_PROPERTYREMOVED, propertyName, propertyType, oldProperty.toText(), ""));
}
}
}
}
return difflist;
}
use of com.xpn.xwiki.objects.classes.PropertyClass in project xwiki-platform by xwiki.
the class BaseObject method set.
public void set(String fieldname, java.lang.Object value, XWikiContext context) {
BaseClass bclass = getXClass(context);
PropertyClass pclass = (PropertyClass) bclass.get(fieldname);
BaseProperty prop = (BaseProperty) safeget(fieldname);
if ((value instanceof String) && (pclass != null)) {
prop = pclass.fromString((String) value);
} else {
if ((prop == null) && (pclass != null)) {
prop = pclass.newProperty();
}
if (prop != null) {
prop.setValue(value);
}
}
if (prop != null) {
prop.setOwnerDocument(getOwnerDocument());
safeput(fieldname, prop);
}
}
use of com.xpn.xwiki.objects.classes.PropertyClass in project xwiki-platform by xwiki.
the class PropertyClassOutputFilterStream method onWikiClassPropertyField.
@Override
public void onWikiClassPropertyField(String name, String value, FilterEventParameters parameters) throws FilterException {
if (this.entity != null) {
PropertyClass propertyClass;
try {
propertyClass = (PropertyClass) this.currentClassPropertyMeta.get(name);
} catch (XWikiException e) {
throw new FilterException(String.format("Failed to get definition of field [%s] for property type [%s]", name, this.entity.getClassType()), e);
}
// Make sure the property is known
if (propertyClass == null) {
this.logger.warn("Unknown property meta class field [{}] for property type [{}]", name, this.entity.getClassType());
return;
}
BaseProperty<?> field = propertyClass.fromString(value);
this.entity.safeput(name, field);
}
}
use of com.xpn.xwiki.objects.classes.PropertyClass 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);
}
}
Aggregations