use of com.xpn.xwiki.objects.classes.PropertyClass 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.PropertyClass 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.PropertyClass 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);
}
use of com.xpn.xwiki.objects.classes.PropertyClass in project xwiki-platform by xwiki.
the class XWikiHibernateStore method isValidCustomMapping.
private boolean isValidCustomMapping(BaseClass bclass, Configuration config) {
PersistentClass mapping = config.getClassMapping(bclass.getName());
if (mapping == null) {
return true;
}
Iterator it = mapping.getPropertyIterator();
while (it.hasNext()) {
Property hibprop = (Property) it.next();
String propname = hibprop.getName();
PropertyClass propclass = (PropertyClass) bclass.getField(propname);
if (propclass == null) {
this.logger.warn("Mapping contains invalid field name [{}]", propname);
return false;
}
boolean result = isValidColumnType(hibprop.getValue().getType().getName(), propclass.getClassName());
if (result == false) {
this.logger.warn("Mapping contains invalid type in field [{}]", propname);
return false;
}
}
return true;
}
use of com.xpn.xwiki.objects.classes.PropertyClass in project xwiki-platform by xwiki.
the class BaseClassEventGenerator method write.
@Override
public void write(BaseClass xclass, Object filter, BaseClassFilter xclassFilter, DocumentInstanceInputProperties properties) throws FilterException {
// WikiClass
FilterEventParameters classParameters = new FilterEventParameters();
classParameters.put(WikiClassFilter.PARAMETER_NAME, xclass.getName());
classParameters.put(WikiClassFilter.PARAMETER_CUSTOMCLASS, xclass.getCustomClass());
classParameters.put(WikiClassFilter.PARAMETER_CUSTOMMAPPING, xclass.getCustomMapping());
classParameters.put(WikiClassFilter.PARAMETER_DEFAULTSPACE, xclass.getDefaultWeb());
classParameters.put(WikiClassFilter.PARAMETER_NAMEFIELD, xclass.getNameField());
classParameters.put(WikiClassFilter.PARAMETER_SHEET_DEFAULTEDIT, xclass.getDefaultEditSheet());
classParameters.put(WikiClassFilter.PARAMETER_SHEET_DEFAULTVIEW, xclass.getDefaultViewSheet());
classParameters.put(WikiClassFilter.PARAMETER_VALIDATIONSCRIPT, xclass.getValidationScript());
xclassFilter.beginWikiClass(classParameters);
// Properties
// Iterate over values sorted by field name so that the values are
// exported to XML in a consistent order.
Iterator<PropertyClass> it = xclass.getSortedIterator();
while (it.hasNext()) {
PropertyClass xclassProperty = it.next();
((PropertyClassEventGenerator) this.propertyEventGenerator).write(xclassProperty, filter, xclassFilter, properties);
}
// /WikiClass
xclassFilter.endWikiClass(classParameters);
}
Aggregations