Search in sources :

Example 21 with PropertyClass

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;
}
Also used : BaseClass(com.xpn.xwiki.objects.classes.BaseClass) PropertyClass(com.xpn.xwiki.objects.classes.PropertyClass)

Example 22 with PropertyClass

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;
}
Also used : ArrayList(java.util.ArrayList) BaseClass(com.xpn.xwiki.objects.classes.BaseClass) PropertyClass(com.xpn.xwiki.objects.classes.PropertyClass)

Example 23 with PropertyClass

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);
}
Also used : BaseClass(com.xpn.xwiki.objects.classes.BaseClass) PropertyClass(com.xpn.xwiki.objects.classes.PropertyClass) XWikiException(com.xpn.xwiki.XWikiException)

Example 24 with PropertyClass

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;
}
Also used : Iterator(java.util.Iterator) Property(org.hibernate.mapping.Property) LargeStringProperty(com.xpn.xwiki.objects.LargeStringProperty) StringProperty(com.xpn.xwiki.objects.StringProperty) ListProperty(com.xpn.xwiki.objects.ListProperty) BaseProperty(com.xpn.xwiki.objects.BaseProperty) BaseStringProperty(com.xpn.xwiki.objects.BaseStringProperty) PropertyClass(com.xpn.xwiki.objects.classes.PropertyClass) PersistentClass(org.hibernate.mapping.PersistentClass)

Example 25 with PropertyClass

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);
}
Also used : FilterEventParameters(org.xwiki.filter.FilterEventParameters) PropertyClass(com.xpn.xwiki.objects.classes.PropertyClass)

Aggregations

PropertyClass (com.xpn.xwiki.objects.classes.PropertyClass)28 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)16 XWikiException (com.xpn.xwiki.XWikiException)8 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)7 BaseObject (com.xpn.xwiki.objects.BaseObject)5 BaseProperty (com.xpn.xwiki.objects.BaseProperty)5 ToString (org.suigeneris.jrcs.util.ToString)5 XWiki (com.xpn.xwiki.XWiki)4 ArrayList (java.util.ArrayList)4 QueryException (org.xwiki.query.QueryException)4 XWikiContext (com.xpn.xwiki.XWikiContext)3 IOException (java.io.IOException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 DifferentiationFailedException (org.suigeneris.jrcs.diff.DifferentiationFailedException)3 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)3 ExecutionContextException (org.xwiki.context.ExecutionContextException)3 MissingParserException (org.xwiki.rendering.parser.MissingParserException)3 ParseException (org.xwiki.rendering.parser.ParseException)3 TransformationException (org.xwiki.rendering.transformation.TransformationException)3 HashMap (java.util.HashMap)2