@Override public boolean apply(ElementInterface newElement, boolean clean) { boolean modified = super.apply(newElement, clean); BaseClass newBaseClass = (BaseClass) newElement; if (!StringUtils.equals(getCustomClass(), newBaseClass.getCustomClass())) { setCustomClass(newBaseClass.getCustomClass()); modified = true; } if (!StringUtils.equals(getCustomMapping(), newBaseClass.getCustomMapping())) { setCustomMapping(newBaseClass.getCustomMapping()); modified = true; } if (!StringUtils.equals(getDefaultWeb(), newBaseClass.getDefaultWeb())) { setDefaultWeb(newBaseClass.getDefaultWeb()); modified = true; } if (!StringUtils.equals(getDefaultViewSheet(), newBaseClass.getDefaultViewSheet())) { setDefaultViewSheet(newBaseClass.getDefaultViewSheet()); modified = true; } if (!StringUtils.equals(getDefaultEditSheet(), newBaseClass.getDefaultEditSheet())) { setDefaultEditSheet(newBaseClass.getDefaultEditSheet()); modified = true; } if (!StringUtils.equals(getNameField(), newBaseClass.getNameField())) { setNameField(newBaseClass.getNameField()); modified = true; } return modified; }
@Override public boolean equals(Object obj) { // Same Java object, they sure are equal if (this == obj) { return true; } if (!super.equals(obj)) { return false; } BaseClass bclass = (BaseClass) obj; if (!getCustomClass().equals(bclass.getCustomClass())) { return false; } if (!getCustomMapping().equals(bclass.getCustomMapping())) { return false; } if (!getDefaultViewSheet().equals(bclass.getDefaultViewSheet())) { return false; } if (!getDefaultEditSheet().equals(bclass.getDefaultEditSheet())) { return false; } if (!getDefaultWeb().equals(bclass.getDefaultWeb())) { return false; } if (!getValidationScript().equals(bclass.getValidationScript())) { return false; } if (!getNameField().equals(bclass.getNameField())) { return false; } return true; }
@Override public void write( BaseClass xclass, Object filter, BaseClassFilter xclassFilter, DocumentInstanceInputProperties properties) throws FilterException { // WikiClass FilterEventParameters classParameters = new FilterEventParameters(); 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); }
@Override public void merge( ElementInterface previousElement, ElementInterface newElement, MergeConfiguration configuration, XWikiContext context, MergeResult mergeResult) { BaseClass previousClass = (BaseClass) previousElement; BaseClass newClass = (BaseClass) newElement; setCustomClass( MergeUtils.mergeCharacters( previousClass.getCustomClass(), newClass.getCustomClass(), getCustomClass(), mergeResult)); setCustomMapping( MergeUtils.mergeCharacters( previousClass.getCustomMapping(), newClass.getCustomMapping(), getCustomMapping(), mergeResult)); setDefaultWeb( MergeUtils.mergeCharacters( previousClass.getDefaultWeb(), newClass.getDefaultWeb(), getDefaultWeb(), mergeResult)); setDefaultViewSheet( MergeUtils.mergeCharacters( previousClass.getDefaultViewSheet(), newClass.getDefaultViewSheet(), getDefaultViewSheet(), mergeResult)); setDefaultEditSheet( MergeUtils.mergeCharacters( previousClass.getDefaultEditSheet(), newClass.getDefaultEditSheet(), getDefaultEditSheet(), mergeResult)); setNameField( MergeUtils.mergeCharacters( previousClass.getNameField(), newClass.getNameField(), getNameField(), mergeResult)); // Properties List<ObjectDiff> classDiff = newClass.getDiff(previousClass, context); for (ObjectDiff diff : classDiff) { PropertyClass propertyResult = (PropertyClass) getField(diff.getPropName()); PropertyClass previousProperty = (PropertyClass) previousClass.getField(diff.getPropName()); PropertyClass newProperty = (PropertyClass) newClass.getField(diff.getPropName()); if (diff.getAction() == ObjectDiff.ACTION_PROPERTYADDED) { if (propertyResult == null) { // Add if none has been added by user already addField( diff.getPropName(), configuration.isProvidedVersionsModifiables() ? newClass.getField(diff.getPropName()) : newClass.getField(diff.getPropName()).clone()); mergeResult.setModified(true); } else if (!propertyResult.equals(newProperty)) { // XXX: collision between DB and new: property to add but already exists in the DB mergeResult .getLog() .error("Collision found on class property [{}]", newProperty.getReference()); } } else if (diff.getAction() == ObjectDiff.ACTION_PROPERTYREMOVED) { if (propertyResult != null) { if (propertyResult.equals(previousProperty)) { // Delete if it's the same as previous one removeField(diff.getPropName()); mergeResult.setModified(true); } else { // XXX: collision between DB and new: property to remove but not the same as previous // version mergeResult .getLog() .error("Collision found on class property [{}]", previousProperty.getReference()); } } else { // Already removed from DB, lets assume the user is prescient mergeResult .getLog() .warn("Object property [{}] already removed", previousProperty.getReference()); } } else if (diff.getAction() == ObjectDiff.ACTION_PROPERTYCHANGED) { if (propertyResult != null) { if (propertyResult.equals(previousProperty)) { // Let some automatic migration take care of that modification between DB and new addField(diff.getPropName(), newClass.getField(diff.getPropName())); mergeResult.setModified(true); } else if (!propertyResult.equals(newProperty)) { propertyResult.merge( previousProperty, newProperty, configuration, context, mergeResult); } } else { // XXX: collision between DB and new: property to modify but does not exists in DB // Lets assume it's a mistake to fix mergeResult .getLog() .warn("Collision found on class property [{}]", newProperty.getReference()); addField(diff.getPropName(), newClass.getField(diff.getPropName())); mergeResult.setModified(true); } } } }