diff --git a/source/java/org/alfresco/repo/dictionary/DictionaryDAOImpl.java b/source/java/org/alfresco/repo/dictionary/DictionaryDAOImpl.java
index ce7edaf234..dd85ed1b9c 100644
--- a/source/java/org/alfresco/repo/dictionary/DictionaryDAOImpl.java
+++ b/source/java/org/alfresco/repo/dictionary/DictionaryDAOImpl.java
@@ -1111,6 +1111,18 @@ public class DictionaryDAOImpl implements DictionaryDAO
/**
* Return diffs between two compiled models.
*
+ * note:
+ * - checks classes (types & aspects) for incremental updates
+ * - checks properties for incremental updates, but does not include the diffs
+ * - checks assocs & child assocs for incremental updates, but does not include the diffs
+ * - incremental updates include changes in title/description, property default value, etc
+ * - ignores changes in model definition except name (ie. title, description, author, published date, version are treated as an incremental update)
+ *
+ * TODO
+ * - imports
+ * - namespace
+ * - datatypes
+ * - constraints (including property constraints - references and inline)
*
* @param model
* @return model diffs (if any)
diff --git a/source/java/org/alfresco/repo/dictionary/DiffModelTest.java b/source/java/org/alfresco/repo/dictionary/DiffModelTest.java
index 2d4491577d..3c25ab89c0 100755
--- a/source/java/org/alfresco/repo/dictionary/DiffModelTest.java
+++ b/source/java/org/alfresco/repo/dictionary/DiffModelTest.java
@@ -754,6 +754,106 @@ public class DiffModelTest extends TestCase
"";
+ public static final String MODEL6_XML =
+ "" +
+
+ " Another description" +
+ " Alfresco" +
+ " 2007-08-01" +
+ " 1.0" +
+
+ " " +
+ " " +
+ " " +
+
+ " " +
+ " " +
+ " " +
+
+ " " +
+
+ " " +
+ " Type1 Title" +
+ " Type1 Description" +
+ " " +
+ " " +
+ " Prop1 Title" +
+ " Prop1 Description" +
+ " d:text" +
+ " " +
+ " " +
+ " " +
+
+ " " +
+
+ " " +
+
+ " " +
+ " Aspect1 Title" +
+ " Aspect1 Description" +
+ " " +
+ " " +
+ " Prop9 Title" +
+ " Prop9 Description" +
+ " d:text" +
+ " " +
+ " " +
+ " " +
+
+ " " +
+
+ "";
+
+ public static final String MODEL6_UPDATE1_XML =
+ "" +
+
+ " Another description - UPDATE1" +
+ " Alfresco - UPDATE1" +
+ " 2009-08-01" +
+ " 2.0" +
+
+ " " +
+ " " +
+ " " +
+
+ " " +
+ " " +
+ " " +
+
+ " " +
+
+ " " +
+ " Type1 Title - UPDATE1" +
+ " Type1 Description - UPDATE1" +
+ " " +
+ " " +
+ " Prop1 Title - UPDATE1" +
+ " Prop1 Description - UPDATE1" +
+ " d:text" +
+ " " +
+ " " +
+ " " +
+
+ " " +
+
+ " " +
+
+ " " +
+ " Aspect1 Title" +
+ " Aspect1 Description" +
+ " " +
+ " " +
+ " Prop9 Title - UPDATE1" +
+ " Prop9 Description - UPDATE1" +
+ " d:text" +
+ " " +
+ " " +
+ " " +
+
+ " " +
+
+ "";
+
private DictionaryDAOImpl dictionaryDAO;
/**
@@ -998,6 +1098,31 @@ public class DiffModelTest extends TestCase
}
+ public void testIncUpdateTitleDescription()
+ {
+ ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(MODEL6_XML.getBytes());
+ M2Model model = M2Model.createModel(byteArrayInputStream);
+ QName modelName = dictionaryDAO.putModel(model);
+ CompiledModel previousVersion = dictionaryDAO.getCompiledModel(modelName);
+
+ byteArrayInputStream = new ByteArrayInputStream(MODEL6_UPDATE1_XML.getBytes());
+ model = M2Model.createModel(byteArrayInputStream);
+ modelName = dictionaryDAO.putModel(model);
+ CompiledModel newVersion = dictionaryDAO.getCompiledModel(modelName);
+
+ List modelDiffs = dictionaryDAO.diffModel(previousVersion, newVersion);
+
+ for (M2ModelDiff modelDiff : modelDiffs)
+ {
+ System.out.println(modelDiff.toString());
+ }
+
+ assertEquals(2, modelDiffs.size());
+
+ assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_TYPE, M2ModelDiff.DIFF_UPDATED_INC));
+ assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_ASPECT, M2ModelDiff.DIFF_UPDATED_INC));
+ }
+
public void testNonIncUpdatePropertiesRemoved()
{
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(MODEL2_EXTRA_PROPERTIES_XML.getBytes());
diff --git a/source/java/org/alfresco/repo/dictionary/M2AssociationDefinition.java b/source/java/org/alfresco/repo/dictionary/M2AssociationDefinition.java
index 5d142db7c6..863da2e2fe 100644
--- a/source/java/org/alfresco/repo/dictionary/M2AssociationDefinition.java
+++ b/source/java/org/alfresco/repo/dictionary/M2AssociationDefinition.java
@@ -1,306 +1,370 @@
-/*
- * Copyright (C) 2005-2007 Alfresco Software Limited.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-
- * As a special exception to the terms and conditions of version 2.0 of
- * the GPL, you may redistribute this Program in connection with Free/Libre
- * and Open Source Software ("FLOSS") applications as described in Alfresco's
- * FLOSS exception. You should have recieved a copy of the text describing
- * the FLOSS exception, and it is also available here:
- * http://www.alfresco.com/legal/licensing"
- */
-package org.alfresco.repo.dictionary;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import org.alfresco.service.cmr.dictionary.AssociationDefinition;
-import org.alfresco.service.cmr.dictionary.ClassDefinition;
-import org.alfresco.service.cmr.dictionary.DictionaryException;
-import org.alfresco.service.cmr.dictionary.ModelDefinition;
-import org.alfresco.service.namespace.NamespacePrefixResolver;
-import org.alfresco.service.namespace.QName;
-
-
-/**
- * Compiled Association Definition.
- *
- * @author David Caruana
- */
-/*package*/ class M2AssociationDefinition implements AssociationDefinition
-{
-
- private ClassDefinition classDef;
- private M2ClassAssociation assoc;
- private QName name;
- private QName targetClassName;
- private ClassDefinition targetClass;
- private QName sourceRoleName;
- private QName targetRoleName;
-
-
- /**
- * Construct
- *
- * @param m2Association association definition
- * @return the definition
- */
- /*package*/ M2AssociationDefinition(ClassDefinition classDef, M2ClassAssociation assoc, NamespacePrefixResolver resolver)
- {
- this.classDef = classDef;
- this.assoc = assoc;
-
- // Resolve names
- this.name = QName.createQName(assoc.getName(), resolver);
- this.targetClassName = QName.createQName(assoc.getTargetClassName(), resolver);
- this.sourceRoleName = QName.createQName(assoc.getSourceRoleName(), resolver);
- this.targetRoleName = QName.createQName(assoc.getTargetRoleName(), resolver);
- }
-
- @Override
- public String toString()
- {
- // note: currently used for model 'diffs'
- StringBuilder sb = new StringBuilder(56);
- sb.append("Association")
- .append("[ class=").append(classDef)
- .append(", name=").append(name)
- .append(", target class=").append(targetClassName)
- .append(", source role=").append(sourceRoleName)
- .append(", target role=").append(targetRoleName)
- .append("]");
- return sb.toString();
- }
-
-
- /*package*/ M2ClassAssociation getM2Association()
- {
- return assoc;
- }
-
-
- /*package*/ void resolveDependencies(ModelQuery query)
- {
- if (targetClassName == null)
- {
- throw new DictionaryException("Target class of association " + name.toPrefixString() + " must be specified");
- }
- targetClass = query.getClass(targetClassName);
- if (targetClass == null)
- {
- throw new DictionaryException("Target class " + targetClassName.toPrefixString() + " of association " + name.toPrefixString() + " is not found");
- }
- }
-
-
- /* (non-Javadoc)
- * @see org.alfresco.service.cmr.dictionary.AssociationDefinition#getModel()
- */
- public ModelDefinition getModel()
- {
- return classDef.getModel();
- }
-
-
- /* (non-Javadoc)
- * @see org.alfresco.repo.dictionary.AssociationDefinition#getName()
- */
- public QName getName()
- {
- return name;
- }
-
-
- /* (non-Javadoc)
- * @see org.alfresco.repo.dictionary.AssociationDefinition#isChild()
- */
- public boolean isChild()
- {
- return (assoc instanceof M2ChildAssociation);
- }
-
-
- /* (non-Javadoc)
- * @see org.alfresco.repo.dictionary.AssociationDefinition#getTitle()
- */
- public String getTitle()
- {
- String value = M2Label.getLabel(classDef.getModel(), "association", name, "title");
- if (value == null)
- {
- value = assoc.getTitle();
- }
- return value;
- }
-
-
- /* (non-Javadoc)
- * @see org.alfresco.repo.dictionary.AssociationDefinition#getDescription()
- */
- public String getDescription()
- {
- String value = M2Label.getLabel(classDef.getModel(), "association", name, "description");
- if (value == null)
- {
- value = assoc.getDescription();
- }
- return value;
- }
-
-
- /* (non-Javadoc)
- * @see org.alfresco.repo.dictionary.AssociationDefinition#isProtected()
- */
- public boolean isProtected()
- {
- return assoc.isProtected();
- }
-
-
- /* (non-Javadoc)
- * @see org.alfresco.repo.dictionary.AssociationDefinition#getSourceClass()
- */
- public ClassDefinition getSourceClass()
- {
- return classDef;
- }
-
-
- /* (non-Javadoc)
- * @see org.alfresco.repo.dictionary.AssociationDefinition#getSourceRoleName()
- */
- public QName getSourceRoleName()
- {
- return sourceRoleName;
- }
-
-
- /* (non-Javadoc)
- * @see org.alfresco.repo.dictionary.AssociationDefinition#isSourceMandatory()
- */
- public boolean isSourceMandatory()
- {
- return assoc.isSourceMandatory();
- }
-
-
- /* (non-Javadoc)
- * @see org.alfresco.repo.dictionary.AssociationDefinition#isSourceMany()
- */
- public boolean isSourceMany()
- {
- return assoc.isSourceMany();
- }
-
-
- /* (non-Javadoc)
- * @see org.alfresco.repo.dictionary.AssociationDefinition#getTargetClass()
- */
- public ClassDefinition getTargetClass()
- {
- return targetClass;
- }
-
-
- /* (non-Javadoc)
- * @see org.alfresco.repo.dictionary.AssociationDefinition#getTargetRoleName()
- */
- public QName getTargetRoleName()
- {
- return targetRoleName;
- }
-
-
- /* (non-Javadoc)
- * @see org.alfresco.repo.dictionary.AssociationDefinition#isTargetMandatory()
- */
- public boolean isTargetMandatory()
- {
- return assoc.isTargetMandatory();
- }
-
-
- /* (non-Javadoc)
- * @see org.alfresco.service.cmr.dictionary.AssociationDefinition#isTargetMandatoryEnforced()
- */
- public boolean isTargetMandatoryEnforced()
- {
- return assoc.isTargetMandatoryEnforced();
- }
-
-
- /* (non-Javadoc)
- * @see org.alfresco.repo.dictionary.AssociationDefinition#isTargetMany()
- */
- public boolean isTargetMany()
- {
- return assoc.isTargetMany();
- }
-
- /*package*/ static Collection diffAssocLists(Collection previousAssocs, Collection newAssocs)
- {
- List M2ModelDiffs = new ArrayList();
-
- for (AssociationDefinition previousAssoc : previousAssocs)
- {
- boolean found = false;
- for (AssociationDefinition newAssoc : newAssocs)
- {
- if (newAssoc.getName().equals(previousAssoc.getName()))
- {
- // TODO currently uses toString() to check whether changed - could override equals()
- if ((((M2AssociationDefinition)previousAssoc).toString()).equals(((M2AssociationDefinition)newAssoc).toString()))
- {
- M2ModelDiffs.add(new M2ModelDiff(newAssoc.getName(), M2ModelDiff.TYPE_ASSOCIATION, M2ModelDiff.DIFF_UNCHANGED));
- }
- else
- {
- M2ModelDiffs.add(new M2ModelDiff(newAssoc.getName(), M2ModelDiff.TYPE_ASSOCIATION, M2ModelDiff.DIFF_UPDATED));
- }
- found = true;
- break;
- }
- }
-
- if (! found)
- {
- M2ModelDiffs.add(new M2ModelDiff(previousAssoc.getName(), M2ModelDiff.TYPE_ASSOCIATION, M2ModelDiff.DIFF_DELETED));
- }
- }
-
- for (AssociationDefinition newAssoc : newAssocs)
- {
- boolean found = false;
- for (AssociationDefinition previousAssoc : previousAssocs)
- {
- if (newAssoc.getName().equals(previousAssoc.getName()))
- {
- found = true;
- break;
- }
- }
-
- if (! found)
- {
- M2ModelDiffs.add(new M2ModelDiff(newAssoc.getName(), M2ModelDiff.TYPE_ASSOCIATION, M2ModelDiff.DIFF_CREATED));
- }
- }
-
- return M2ModelDiffs;
- }
-
-}
+/*
+ * Copyright (C) 2005-2009 Alfresco Software Limited.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ * As a special exception to the terms and conditions of version 2.0 of
+ * the GPL, you may redistribute this Program in connection with Free/Libre
+ * and Open Source Software ("FLOSS") applications as described in Alfresco's
+ * FLOSS exception. You should have recieved a copy of the text describing
+ * the FLOSS exception, and it is also available here:
+ * http://www.alfresco.com/legal/licensing"
+ */
+package org.alfresco.repo.dictionary;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.alfresco.service.cmr.dictionary.AssociationDefinition;
+import org.alfresco.service.cmr.dictionary.ClassDefinition;
+import org.alfresco.service.cmr.dictionary.DictionaryException;
+import org.alfresco.service.cmr.dictionary.ModelDefinition;
+import org.alfresco.service.namespace.NamespacePrefixResolver;
+import org.alfresco.service.namespace.QName;
+import org.alfresco.util.EqualsHelper;
+
+
+/**
+ * Compiled Association Definition.
+ *
+ * @author David Caruana
+ */
+/*package*/ class M2AssociationDefinition implements AssociationDefinition
+{
+
+ private ClassDefinition classDef;
+ private M2ClassAssociation assoc;
+ private QName name;
+ private QName targetClassName;
+ private ClassDefinition targetClass;
+ private QName sourceRoleName;
+ private QName targetRoleName;
+
+
+ /**
+ * Construct
+ *
+ * @param m2Association association definition
+ * @return the definition
+ */
+ /*package*/ M2AssociationDefinition(ClassDefinition classDef, M2ClassAssociation assoc, NamespacePrefixResolver resolver)
+ {
+ this.classDef = classDef;
+ this.assoc = assoc;
+
+ // Resolve names
+ this.name = QName.createQName(assoc.getName(), resolver);
+ this.targetClassName = QName.createQName(assoc.getTargetClassName(), resolver);
+ this.sourceRoleName = QName.createQName(assoc.getSourceRoleName(), resolver);
+ this.targetRoleName = QName.createQName(assoc.getTargetRoleName(), resolver);
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder sb = new StringBuilder(56);
+ sb.append("Association")
+ .append("[ class=").append(classDef)
+ .append(", name=").append(name)
+ .append(", target class=").append(targetClassName)
+ .append(", source role=").append(sourceRoleName)
+ .append(", target role=").append(targetRoleName)
+ .append("]");
+ return sb.toString();
+ }
+
+
+ /*package*/ M2ClassAssociation getM2Association()
+ {
+ return assoc;
+ }
+
+
+ /*package*/ void resolveDependencies(ModelQuery query)
+ {
+ if (targetClassName == null)
+ {
+ throw new DictionaryException("Target class of association " + name.toPrefixString() + " must be specified");
+ }
+ targetClass = query.getClass(targetClassName);
+ if (targetClass == null)
+ {
+ throw new DictionaryException("Target class " + targetClassName.toPrefixString() + " of association " + name.toPrefixString() + " is not found");
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.alfresco.service.cmr.dictionary.AssociationDefinition#getModel()
+ */
+ public ModelDefinition getModel()
+ {
+ return classDef.getModel();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.alfresco.repo.dictionary.AssociationDefinition#getName()
+ */
+ public QName getName()
+ {
+ return name;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.alfresco.repo.dictionary.AssociationDefinition#isChild()
+ */
+ public boolean isChild()
+ {
+ return (assoc instanceof M2ChildAssociation);
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.alfresco.repo.dictionary.AssociationDefinition#getTitle()
+ */
+ public String getTitle()
+ {
+ String value = M2Label.getLabel(classDef.getModel(), "association", name, "title");
+ if (value == null)
+ {
+ value = assoc.getTitle();
+ }
+ return value;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.alfresco.repo.dictionary.AssociationDefinition#getDescription()
+ */
+ public String getDescription()
+ {
+ String value = M2Label.getLabel(classDef.getModel(), "association", name, "description");
+ if (value == null)
+ {
+ value = assoc.getDescription();
+ }
+ return value;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.alfresco.repo.dictionary.AssociationDefinition#isProtected()
+ */
+ public boolean isProtected()
+ {
+ return assoc.isProtected();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.alfresco.repo.dictionary.AssociationDefinition#getSourceClass()
+ */
+ public ClassDefinition getSourceClass()
+ {
+ return classDef;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.alfresco.repo.dictionary.AssociationDefinition#getSourceRoleName()
+ */
+ public QName getSourceRoleName()
+ {
+ return sourceRoleName;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.alfresco.repo.dictionary.AssociationDefinition#isSourceMandatory()
+ */
+ public boolean isSourceMandatory()
+ {
+ return assoc.isSourceMandatory();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.alfresco.repo.dictionary.AssociationDefinition#isSourceMany()
+ */
+ public boolean isSourceMany()
+ {
+ return assoc.isSourceMany();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.alfresco.repo.dictionary.AssociationDefinition#getTargetClass()
+ */
+ public ClassDefinition getTargetClass()
+ {
+ return targetClass;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.alfresco.repo.dictionary.AssociationDefinition#getTargetRoleName()
+ */
+ public QName getTargetRoleName()
+ {
+ return targetRoleName;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.alfresco.repo.dictionary.AssociationDefinition#isTargetMandatory()
+ */
+ public boolean isTargetMandatory()
+ {
+ return assoc.isTargetMandatory();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.alfresco.service.cmr.dictionary.AssociationDefinition#isTargetMandatoryEnforced()
+ */
+ public boolean isTargetMandatoryEnforced()
+ {
+ return assoc.isTargetMandatoryEnforced();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.alfresco.repo.dictionary.AssociationDefinition#isTargetMany()
+ */
+ public boolean isTargetMany()
+ {
+ return assoc.isTargetMany();
+ }
+
+ /* package */ M2ModelDiff diffAssoc(AssociationDefinition assocDef)
+ {
+ M2ModelDiff modelDiff = null;
+ boolean isUpdated = false;
+ boolean isUpdatedIncrementally = false;
+
+ if (this == assocDef)
+ {
+ modelDiff = new M2ModelDiff(name, M2ModelDiff.TYPE_ASSOCIATION, M2ModelDiff.DIFF_UNCHANGED);
+ return modelDiff;
+ }
+
+ // check name - cannot be null
+ if (! name.equals(assocDef.getName()))
+ {
+ isUpdated = true;
+ }
+
+ // check title
+ if (! EqualsHelper.nullSafeEquals(getTitle(), assocDef.getTitle(), false))
+ {
+ isUpdatedIncrementally = true;
+ }
+
+ // check description
+ if (! EqualsHelper.nullSafeEquals(getDescription(), assocDef.getDescription(), false))
+ {
+ isUpdatedIncrementally = true;
+ }
+
+ // check source class qname
+ if (! EqualsHelper.nullSafeEquals(getSourceClass().getName(), assocDef.getSourceClass().getName()))
+ {
+ isUpdated = true;
+ }
+
+ // check source role qname
+ if (! EqualsHelper.nullSafeEquals(getSourceRoleName(), assocDef.getSourceRoleName()))
+ {
+ isUpdated = true;
+ }
+
+ // check target class qname
+ if (! EqualsHelper.nullSafeEquals(getTargetClass().getName(), assocDef.getTargetClass().getName()))
+ {
+ isUpdated = true;
+ }
+
+ // check target role qname
+ if (! EqualsHelper.nullSafeEquals(getTargetRoleName(), assocDef.getTargetRoleName()))
+ {
+ isUpdated = true;
+ }
+
+ // TODO - additional checks - is... (x7)
+
+ if (isUpdated)
+ {
+ modelDiff = new M2ModelDiff(name, M2ModelDiff.TYPE_ASSOCIATION, M2ModelDiff.DIFF_UPDATED);
+ }
+ else if (isUpdatedIncrementally)
+ {
+ modelDiff = new M2ModelDiff(name, M2ModelDiff.TYPE_ASSOCIATION, M2ModelDiff.DIFF_UPDATED_INC);
+ }
+ else
+ {
+ modelDiff = new M2ModelDiff(name, M2ModelDiff.TYPE_ASSOCIATION, M2ModelDiff.DIFF_UNCHANGED);
+ }
+
+ return modelDiff;
+ }
+
+ /*package*/ static Collection diffAssocLists(Collection previousAssocs, Collection newAssocs)
+ {
+ List modelDiffs = new ArrayList();
+
+ for (AssociationDefinition previousAssoc : previousAssocs)
+ {
+ boolean found = false;
+ for (AssociationDefinition newAssoc : newAssocs)
+ {
+ if (newAssoc.getName().equals(previousAssoc.getName()))
+ {
+ modelDiffs.add(((M2AssociationDefinition)previousAssoc).diffAssoc(newAssoc));
+ found = true;
+ break;
+ }
+ }
+
+ if (! found)
+ {
+ modelDiffs.add(new M2ModelDiff(previousAssoc.getName(), M2ModelDiff.TYPE_ASSOCIATION, M2ModelDiff.DIFF_DELETED));
+ }
+ }
+
+ for (AssociationDefinition newAssoc : newAssocs)
+ {
+ boolean found = false;
+ for (AssociationDefinition previousAssoc : previousAssocs)
+ {
+ if (newAssoc.getName().equals(previousAssoc.getName()))
+ {
+ found = true;
+ break;
+ }
+ }
+
+ if (! found)
+ {
+ modelDiffs.add(new M2ModelDiff(newAssoc.getName(), M2ModelDiff.TYPE_ASSOCIATION, M2ModelDiff.DIFF_CREATED));
+ }
+ }
+
+ return modelDiffs;
+ }
+
+}
diff --git a/source/java/org/alfresco/repo/dictionary/M2ClassDefinition.java b/source/java/org/alfresco/repo/dictionary/M2ClassDefinition.java
index 957e2c6245..8eeee1e82b 100644
--- a/source/java/org/alfresco/repo/dictionary/M2ClassDefinition.java
+++ b/source/java/org/alfresco/repo/dictionary/M2ClassDefinition.java
@@ -44,6 +44,7 @@ import org.alfresco.service.cmr.dictionary.ModelDefinition;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.namespace.NamespacePrefixResolver;
import org.alfresco.service.namespace.QName;
+import org.alfresco.util.EqualsHelper;
/**
@@ -478,11 +479,9 @@ import org.alfresco.service.namespace.QName;
* return differences in class definition
*
* note:
- * - ignores changes in model title, description, author, published date, version
- * - ignores changes in default values
* - checks properties for incremental updates, but does not include the diffs
* - checks assocs & child assocs for incremental updates, but does not include the diffs
- * - does not check default values
+ * - incremental updates include changes in title/description, property default value, etc
*/
/* package */ List diffClass(ClassDefinition classDef)
{
@@ -497,6 +496,18 @@ import org.alfresco.service.namespace.QName;
// check name - cannot be null
if (! name.equals(classDef.getName()))
+ {
+ isUpdated = true;
+ }
+
+ // check title
+ if (! EqualsHelper.nullSafeEquals(getTitle(), classDef.getTitle(), false))
+ {
+ isUpdatedIncrementally = true;
+ }
+
+ // check description
+ if (! EqualsHelper.nullSafeEquals(getDescription(), classDef.getDescription(), false))
{
isUpdatedIncrementally = true;
}
@@ -682,7 +693,7 @@ import org.alfresco.service.namespace.QName;
if (! found)
{
modelDiffs.add(new M2ModelDiff(newClass.getName(), M2ModelDiffType, M2ModelDiff.DIFF_CREATED));
- }
+ }
}
return modelDiffs;
diff --git a/source/java/org/alfresco/repo/dictionary/M2PropertyDefinition.java b/source/java/org/alfresco/repo/dictionary/M2PropertyDefinition.java
index 9255d85da8..80a2e11b3f 100644
--- a/source/java/org/alfresco/repo/dictionary/M2PropertyDefinition.java
+++ b/source/java/org/alfresco/repo/dictionary/M2PropertyDefinition.java
@@ -1,455 +1,567 @@
-/*
- * Copyright (C) 2005-2007 Alfresco Software Limited.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-
- * As a special exception to the terms and conditions of version 2.0 of
- * the GPL, you may redistribute this Program in connection with Free/Libre
- * and Open Source Software ("FLOSS") applications as described in Alfresco's
- * FLOSS exception. You should have recieved a copy of the text describing
- * the FLOSS exception, and it is also available here:
- * http://www.alfresco.com/legal/licensing"
- */
-package org.alfresco.repo.dictionary;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.alfresco.service.cmr.dictionary.ClassDefinition;
-import org.alfresco.service.cmr.dictionary.ConstraintDefinition;
-import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
-import org.alfresco.service.cmr.dictionary.DictionaryException;
-import org.alfresco.service.cmr.dictionary.ModelDefinition;
-import org.alfresco.service.cmr.dictionary.PropertyDefinition;
-import org.alfresco.service.namespace.NamespacePrefixResolver;
-import org.alfresco.service.namespace.QName;
-
-
-/**
- * Compiled Property Definition
- *
- * @author David Caruana
- */
-/*package*/ class M2PropertyDefinition implements PropertyDefinition
-{
- private ClassDefinition classDef;
- private M2Property m2Property;
- private QName name;
- private QName propertyTypeName;
- private DataTypeDefinition dataType;
- private List constraintDefs = Collections.emptyList();
-
- /*package*/ M2PropertyDefinition(
- ClassDefinition classDef,
- M2Property m2Property,
- NamespacePrefixResolver prefixResolver)
- {
- this.classDef = classDef;
- this.m2Property = m2Property;
-
- // Resolve Names
- this.name = QName.createQName(m2Property.getName(), prefixResolver);
- this.propertyTypeName = QName.createQName(m2Property.getType(), prefixResolver);
- }
-
-
- /*package*/ M2PropertyDefinition(
- ClassDefinition classDef,
- PropertyDefinition propertyDef,
- M2PropertyOverride override,
- NamespacePrefixResolver prefixResolver,
- Map modelConstraints)
- {
- this.classDef = classDef;
- this.m2Property = createOverriddenProperty(propertyDef, override, prefixResolver, modelConstraints);
- this.name = propertyDef.getName();
- this.dataType = propertyDef.getDataType();
- this.propertyTypeName = this.dataType.getName();
- }
-
-
- /*package*/ void resolveDependencies(
- ModelQuery query,
- NamespacePrefixResolver prefixResolver,
- Map modelConstraints)
- {
- if (propertyTypeName == null)
- {
- throw new DictionaryException(
- "d_dictionary.property.err.property_type_not_specified",
- name.toPrefixString());
- }
- dataType = query.getDataType(propertyTypeName);
- if (dataType == null)
- {
- throw new DictionaryException(
- "d_dictionary.property.err.property_type_not_found",
- propertyTypeName.toPrefixString(), name.toPrefixString());
- }
-
- // ensure content properties are not multi-valued
- if (propertyTypeName.equals(DataTypeDefinition.CONTENT) && isMultiValued())
- {
- throw new DictionaryException("d_dictionary.property.err.single_valued_content");
- }
-
- // Construct constraints
- constraintDefs = buildConstraints(
- m2Property.getConstraints(),
- this,
- prefixResolver,
- modelConstraints);
- }
-
- private static List buildConstraints(
- List m2constraints,
- M2PropertyDefinition m2PropertyDef,
- NamespacePrefixResolver prefixResolver,
- Map modelConstraints)
- {
- List constraints = new ArrayList(5);
- Map constraintsByQName = new HashMap(7);
- for (M2Constraint constraint : m2constraints)
- {
- ConstraintDefinition def = new M2ConstraintDefinition(m2PropertyDef, constraint, prefixResolver);
- QName qname = def.getName();
- if (constraintsByQName.containsKey(qname))
- {
- throw new DictionaryException(
- "d_dictionary.property.err.duplicate_constraint_on_property",
- def.getName().toPrefixString(), m2PropertyDef.name.toPrefixString());
- }
- else if (modelConstraints.containsKey(qname))
- {
- throw new DictionaryException(
- "d_dictionary.model.err.duplicate_constraint_on_model",
- def.getName().toPrefixString());
- }
- constraintsByQName.put(qname, def);
- constraints.add(def);
- modelConstraints.put(qname, def);
- }
- // done
- return constraints;
- }
-
- /**
- * Create a property definition whose values are overridden
- *
- * @param propertyDef the property definition to override
- * @param override the overridden values
- * @return the property definition
- */
- private M2Property createOverriddenProperty(
- PropertyDefinition propertyDef,
- M2PropertyOverride override,
- NamespacePrefixResolver prefixResolver,
- Map modelConstraints)
- {
- M2Property property = new M2Property();
- property.setOverride(true);
-
- // Process Default Value
- String defaultValue = override.getDefaultValue();
- property.setDefaultValue(defaultValue == null ? propertyDef.getDefaultValue() : defaultValue);
-
- // Process Mandatory Value
- Boolean isOverrideMandatory = override.isMandatory();
- boolean isOverrideMandatoryEnforced = override.isMandatoryEnforced();
- if (isOverrideMandatory != null && propertyDef.isMandatory())
- {
- // the override specified whether the property should be mandatory or not
- // check that the mandatory enforcement is not relaxed
- if (!isOverrideMandatory)
- {
- throw new DictionaryException(
- "d_dictionary.property.err.cannot_relax_mandatory",
- propertyDef.getName().toPrefixString());
- }
- else if (!isOverrideMandatoryEnforced && propertyDef.isMandatoryEnforced())
- {
- throw new DictionaryException(
- "d_dictionary.property.err.cannot_relax_mandatory_enforcement",
- propertyDef.getName().toPrefixString());
- }
- }
- property.setMandatory(isOverrideMandatory == null ? propertyDef.isMandatory() : isOverrideMandatory);
- property.setMandatoryEnforced(isOverrideMandatoryEnforced);
-
- // inherit or override constraints
- List overrideConstraints = override.getConstraints();
- if (overrideConstraints != null)
- {
- constraintDefs = buildConstraints(
- overrideConstraints,
- (M2PropertyDefinition) propertyDef,
- prefixResolver,
- modelConstraints);
- }
- else
- {
- this.constraintDefs = propertyDef.getConstraints();
- }
-
- // Copy all other properties as they are
- property.setDescription(propertyDef.getDescription());
- property.setIndexed(propertyDef.isIndexed());
- property.setIndexedAtomically(propertyDef.isIndexedAtomically());
- property.setMultiValued(propertyDef.isMultiValued());
- property.setProtected(propertyDef.isProtected());
- property.setStoredInIndex(propertyDef.isStoredInIndex());
- property.setTitle(propertyDef.getTitle());
- property.setIndexTokenisationMode(propertyDef.getIndexTokenisationMode());
-
- return property;
- }
-
- /**
- * @see #getName()
- */
- @Override
- public String toString()
- {
- // note: currently used for model 'diffs'
- StringBuffer sb = new StringBuffer();
- sb.append("Name: " + getName() + "\n");
- sb.append("Title: " + getTitle() + "\n");
- sb.append("Description: " + getDescription() + "\n");
- sb.append("Default Value: " + getDefaultValue() + "\n");
- sb.append("DataType Name: " + getDataType().getName() + "\n");
- sb.append("ContainerClass Name: " + getContainerClass().getName() + "\n");
- sb.append("isMultiValued: " + isMultiValued() + "\n");
- sb.append("isMandatory: " + isMandatory() + "\n");
- sb.append("isMandatoryEnforced: " + isMandatoryEnforced() + "\n");
- sb.append("isProtected: " + isProtected() + "\n");
- sb.append("isIndexed: " + isIndexed() + "\n");
- sb.append("isStoredInIndex: " + isStoredInIndex() + "\n");
- sb.append("isIndexedAtomically: " + isIndexedAtomically() + "\n");
- sb.append("indexTokenisationMode: " + getIndexTokenisationMode() + "\n");
-
- return sb.toString();
- }
-
- /* (non-Javadoc)
- * @see org.alfresco.service.cmr.dictionary.PropertyDefinition#getModel()
- */
- public ModelDefinition getModel()
- {
- return classDef.getModel();
- }
-
- /* (non-Javadoc)
- * @see org.alfresco.repo.dictionary.PropertyDefinition#getName()
- */
- public QName getName()
- {
- return name;
- }
-
-
- /* (non-Javadoc)
- * @see org.alfresco.repo.dictionary.PropertyDefinition#getTitle()
- */
- public String getTitle()
- {
- String value = M2Label.getLabel(classDef.getModel(), "property", name, "title");
- if (value == null)
- {
- value = m2Property.getTitle();
- }
- return value;
- }
-
-
- /* (non-Javadoc)
- * @see org.alfresco.repo.dictionary.PropertyDefinition#getDescription()
- */
- public String getDescription()
- {
- String value = M2Label.getLabel(classDef.getModel(), "property", name, "description");
- if (value == null)
- {
- value = m2Property.getDescription();
- }
- return value;
- }
-
-
- /* (non-Javadoc)
- * @see org.alfresco.repo.dictionary.PropertyDefinition#getDefaultValue()
- */
- public String getDefaultValue()
- {
- return m2Property.getDefaultValue();
- }
-
-
- /* (non-Javadoc)
- * @see org.alfresco.repo.dictionary.PropertyDefinition#getPropertyType()
- */
- public DataTypeDefinition getDataType()
- {
- return dataType;
- }
-
-
- /* (non-Javadoc)
- * @see org.alfresco.repo.dictionary.PropertyDefinition#getContainerClass()
- */
- public ClassDefinition getContainerClass()
- {
- return classDef;
- }
-
- /*
- * (non-Javadoc)
- * @see org.alfresco.service.cmr.dictionary.PropertyDefinition#isOverride()
- */
- public boolean isOverride()
- {
- return m2Property.isOverride();
- }
-
- /* (non-Javadoc)
- * @see org.alfresco.repo.dictionary.PropertyDefinition#isMultiValued()
- */
- public boolean isMultiValued()
- {
- return m2Property.isMultiValued();
- }
-
-
- /* (non-Javadoc)
- * @see org.alfresco.repo.dictionary.PropertyDefinition#isMandatory()
- */
- public boolean isMandatory()
- {
- return m2Property.isMandatory();
- }
-
- public boolean isMandatoryEnforced()
- {
- return m2Property.isMandatoryEnforced();
- }
-
- /* (non-Javadoc)
- * @see org.alfresco.repo.dictionary.PropertyDefinition#isProtected()
- */
- public boolean isProtected()
- {
- return m2Property.isProtected();
- }
-
-
- /* (non-Javadoc)
- * @see org.alfresco.repo.dictionary.PropertyDefinition#isIndexed()
- */
- public boolean isIndexed()
- {
- return m2Property.isIndexed();
- }
-
-
- /* (non-Javadoc)
- * @see org.alfresco.repo.dictionary.PropertyDefinition#isStoredInIndex()
- */
- public boolean isStoredInIndex()
- {
- return m2Property.isStoredInIndex();
- }
-
-
- /* (non-Javadoc)
- * @see org.alfresco.repo.dictionary.PropertyDefinition#isIndexedAtomically()
- */
- public boolean isIndexedAtomically()
- {
- return m2Property.isIndexedAtomically();
- }
-
-
- /* (non-Javadoc)
- * @see org.alfresco.repo.dictionary.PropertyDefinition#isTokenisedInIndex()
- */
- public IndexTokenisationMode getIndexTokenisationMode()
- {
- return m2Property.getIndexTokenisationMode();
- }
-
-
- /* (non-Javadoc)
- * @see org.alfresco.service.cmr.dictionary.PropertyDefinition#getConstraints()
- */
- public List getConstraints()
- {
- return constraintDefs;
- }
-
- /*package*/ static Collection diffPropertyLists(Collection previousProperties, Collection newProperties)
- {
- List M2ModelDiffs = new ArrayList();
-
- for (PropertyDefinition previousProperty : previousProperties)
- {
- boolean found = false;
- for (PropertyDefinition newProperty : newProperties)
- {
- if (newProperty.getName().equals(previousProperty.getName()))
- {
- // TODO currently uses toString() to check whether changed - could override equals()
- if ((((M2PropertyDefinition)previousProperty).toString()).equals(((M2PropertyDefinition)newProperty).toString()))
- {
- M2ModelDiffs.add(new M2ModelDiff(newProperty.getName(), M2ModelDiff.TYPE_PROPERTY, M2ModelDiff.DIFF_UNCHANGED));
- }
- else
- {
- M2ModelDiffs.add(new M2ModelDiff(newProperty.getName(), M2ModelDiff.TYPE_PROPERTY, M2ModelDiff.DIFF_UPDATED));
- }
- found = true;
- break;
- }
- }
-
- if (! found)
- {
- M2ModelDiffs.add(new M2ModelDiff(previousProperty.getName(), M2ModelDiff.TYPE_PROPERTY, M2ModelDiff.DIFF_DELETED));
- }
- }
-
- for (PropertyDefinition newProperty : newProperties)
- {
- boolean found = false;
- for (PropertyDefinition previousProperty : previousProperties)
- {
- if (newProperty.getName().equals(previousProperty.getName()))
- {
- found = true;
- break;
- }
- }
-
- if (! found)
- {
- M2ModelDiffs.add(new M2ModelDiff(newProperty.getName(), M2ModelDiff.TYPE_PROPERTY, M2ModelDiff.DIFF_CREATED));
- }
- }
-
- return M2ModelDiffs;
- }
-}
+/*
+ * Copyright (C) 2005-2009 Alfresco Software Limited.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ * As a special exception to the terms and conditions of version 2.0 of
+ * the GPL, you may redistribute this Program in connection with Free/Libre
+ * and Open Source Software ("FLOSS") applications as described in Alfresco's
+ * FLOSS exception. You should have recieved a copy of the text describing
+ * the FLOSS exception, and it is also available here:
+ * http://www.alfresco.com/legal/licensing"
+ */
+package org.alfresco.repo.dictionary;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.alfresco.service.cmr.dictionary.ClassDefinition;
+import org.alfresco.service.cmr.dictionary.ConstraintDefinition;
+import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
+import org.alfresco.service.cmr.dictionary.DictionaryException;
+import org.alfresco.service.cmr.dictionary.ModelDefinition;
+import org.alfresco.service.cmr.dictionary.PropertyDefinition;
+import org.alfresco.service.namespace.NamespacePrefixResolver;
+import org.alfresco.service.namespace.QName;
+import org.alfresco.util.EqualsHelper;
+
+
+/**
+ * Compiled Property Definition
+ *
+ * @author David Caruana
+ */
+/*package*/ class M2PropertyDefinition implements PropertyDefinition
+{
+ private ClassDefinition classDef;
+ private M2Property m2Property;
+ private QName name;
+ private QName propertyTypeName;
+ private DataTypeDefinition dataType;
+ private List constraintDefs = Collections.emptyList();
+
+ /*package*/ M2PropertyDefinition(
+ ClassDefinition classDef,
+ M2Property m2Property,
+ NamespacePrefixResolver prefixResolver)
+ {
+ this.classDef = classDef;
+ this.m2Property = m2Property;
+
+ // Resolve Names
+ this.name = QName.createQName(m2Property.getName(), prefixResolver);
+ this.propertyTypeName = QName.createQName(m2Property.getType(), prefixResolver);
+ }
+
+
+ /*package*/ M2PropertyDefinition(
+ ClassDefinition classDef,
+ PropertyDefinition propertyDef,
+ M2PropertyOverride override,
+ NamespacePrefixResolver prefixResolver,
+ Map modelConstraints)
+ {
+ this.classDef = classDef;
+ this.m2Property = createOverriddenProperty(propertyDef, override, prefixResolver, modelConstraints);
+ this.name = propertyDef.getName();
+ this.dataType = propertyDef.getDataType();
+ this.propertyTypeName = this.dataType.getName();
+ }
+
+
+ /*package*/ void resolveDependencies(
+ ModelQuery query,
+ NamespacePrefixResolver prefixResolver,
+ Map modelConstraints)
+ {
+ if (propertyTypeName == null)
+ {
+ throw new DictionaryException(
+ "d_dictionary.property.err.property_type_not_specified",
+ name.toPrefixString());
+ }
+ dataType = query.getDataType(propertyTypeName);
+ if (dataType == null)
+ {
+ throw new DictionaryException(
+ "d_dictionary.property.err.property_type_not_found",
+ propertyTypeName.toPrefixString(), name.toPrefixString());
+ }
+
+ // ensure content properties are not multi-valued
+ if (propertyTypeName.equals(DataTypeDefinition.CONTENT) && isMultiValued())
+ {
+ throw new DictionaryException("d_dictionary.property.err.single_valued_content");
+ }
+
+ // Construct constraints
+ constraintDefs = buildConstraints(
+ m2Property.getConstraints(),
+ this,
+ prefixResolver,
+ modelConstraints);
+ }
+
+ private static List buildConstraints(
+ List m2constraints,
+ M2PropertyDefinition m2PropertyDef,
+ NamespacePrefixResolver prefixResolver,
+ Map modelConstraints)
+ {
+ List constraints = new ArrayList(5);
+ Map constraintsByQName = new HashMap(7);
+ for (M2Constraint constraint : m2constraints)
+ {
+ ConstraintDefinition def = new M2ConstraintDefinition(m2PropertyDef, constraint, prefixResolver);
+ QName qname = def.getName();
+ if (constraintsByQName.containsKey(qname))
+ {
+ throw new DictionaryException(
+ "d_dictionary.property.err.duplicate_constraint_on_property",
+ def.getName().toPrefixString(), m2PropertyDef.name.toPrefixString());
+ }
+ else if (modelConstraints.containsKey(qname))
+ {
+ throw new DictionaryException(
+ "d_dictionary.model.err.duplicate_constraint_on_model",
+ def.getName().toPrefixString());
+ }
+ constraintsByQName.put(qname, def);
+ constraints.add(def);
+ modelConstraints.put(qname, def);
+ }
+ // done
+ return constraints;
+ }
+
+ /**
+ * Create a property definition whose values are overridden
+ *
+ * @param propertyDef the property definition to override
+ * @param override the overridden values
+ * @return the property definition
+ */
+ private M2Property createOverriddenProperty(
+ PropertyDefinition propertyDef,
+ M2PropertyOverride override,
+ NamespacePrefixResolver prefixResolver,
+ Map modelConstraints)
+ {
+ M2Property property = new M2Property();
+ property.setOverride(true);
+
+ // Process Default Value
+ String defaultValue = override.getDefaultValue();
+ property.setDefaultValue(defaultValue == null ? propertyDef.getDefaultValue() : defaultValue);
+
+ // Process Mandatory Value
+ Boolean isOverrideMandatory = override.isMandatory();
+ boolean isOverrideMandatoryEnforced = override.isMandatoryEnforced();
+ if (isOverrideMandatory != null && propertyDef.isMandatory())
+ {
+ // the override specified whether the property should be mandatory or not
+ // check that the mandatory enforcement is not relaxed
+ if (!isOverrideMandatory)
+ {
+ throw new DictionaryException(
+ "d_dictionary.property.err.cannot_relax_mandatory",
+ propertyDef.getName().toPrefixString());
+ }
+ else if (!isOverrideMandatoryEnforced && propertyDef.isMandatoryEnforced())
+ {
+ throw new DictionaryException(
+ "d_dictionary.property.err.cannot_relax_mandatory_enforcement",
+ propertyDef.getName().toPrefixString());
+ }
+ }
+ property.setMandatory(isOverrideMandatory == null ? propertyDef.isMandatory() : isOverrideMandatory);
+ property.setMandatoryEnforced(isOverrideMandatoryEnforced);
+
+ // inherit or override constraints
+ List overrideConstraints = override.getConstraints();
+ if (overrideConstraints != null)
+ {
+ constraintDefs = buildConstraints(
+ overrideConstraints,
+ (M2PropertyDefinition) propertyDef,
+ prefixResolver,
+ modelConstraints);
+ }
+ else
+ {
+ this.constraintDefs = propertyDef.getConstraints();
+ }
+
+ // Copy all other properties as they are
+ property.setDescription(propertyDef.getDescription());
+ property.setIndexed(propertyDef.isIndexed());
+ property.setIndexedAtomically(propertyDef.isIndexedAtomically());
+ property.setMultiValued(propertyDef.isMultiValued());
+ property.setProtected(propertyDef.isProtected());
+ property.setStoredInIndex(propertyDef.isStoredInIndex());
+ property.setTitle(propertyDef.getTitle());
+ property.setIndexTokenisationMode(propertyDef.getIndexTokenisationMode());
+
+ return property;
+ }
+
+ /**
+ * @see #getName()
+ */
+ @Override
+ public String toString()
+ {
+ StringBuffer sb = new StringBuffer();
+ sb.append("Name: " + getName() + "\n");
+ sb.append("Title: " + getTitle() + "\n");
+ sb.append("Description: " + getDescription() + "\n");
+ sb.append("Default Value: " + getDefaultValue() + "\n");
+ sb.append("DataType Name: " + getDataType().getName() + "\n");
+ sb.append("ContainerClass Name: " + getContainerClass().getName() + "\n");
+ sb.append("isMultiValued: " + isMultiValued() + "\n");
+ sb.append("isMandatory: " + isMandatory() + "\n");
+ sb.append("isMandatoryEnforced: " + isMandatoryEnforced() + "\n");
+ sb.append("isProtected: " + isProtected() + "\n");
+ sb.append("isIndexed: " + isIndexed() + "\n");
+ sb.append("isStoredInIndex: " + isStoredInIndex() + "\n");
+ sb.append("isIndexedAtomically: " + isIndexedAtomically() + "\n");
+ sb.append("indexTokenisationMode: " + getIndexTokenisationMode() + "\n");
+
+ return sb.toString();
+ }
+
+ /* (non-Javadoc)
+ * @see org.alfresco.service.cmr.dictionary.PropertyDefinition#getModel()
+ */
+ public ModelDefinition getModel()
+ {
+ return classDef.getModel();
+ }
+
+ /* (non-Javadoc)
+ * @see org.alfresco.repo.dictionary.PropertyDefinition#getName()
+ */
+ public QName getName()
+ {
+ return name;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.alfresco.repo.dictionary.PropertyDefinition#getTitle()
+ */
+ public String getTitle()
+ {
+ String value = M2Label.getLabel(classDef.getModel(), "property", name, "title");
+ if (value == null)
+ {
+ value = m2Property.getTitle();
+ }
+ return value;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.alfresco.repo.dictionary.PropertyDefinition#getDescription()
+ */
+ public String getDescription()
+ {
+ String value = M2Label.getLabel(classDef.getModel(), "property", name, "description");
+ if (value == null)
+ {
+ value = m2Property.getDescription();
+ }
+ return value;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.alfresco.repo.dictionary.PropertyDefinition#getDefaultValue()
+ */
+ public String getDefaultValue()
+ {
+ return m2Property.getDefaultValue();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.alfresco.repo.dictionary.PropertyDefinition#getPropertyType()
+ */
+ public DataTypeDefinition getDataType()
+ {
+ return dataType;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.alfresco.repo.dictionary.PropertyDefinition#getContainerClass()
+ */
+ public ClassDefinition getContainerClass()
+ {
+ return classDef;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.alfresco.service.cmr.dictionary.PropertyDefinition#isOverride()
+ */
+ public boolean isOverride()
+ {
+ return m2Property.isOverride();
+ }
+
+ /* (non-Javadoc)
+ * @see org.alfresco.repo.dictionary.PropertyDefinition#isMultiValued()
+ */
+ public boolean isMultiValued()
+ {
+ return m2Property.isMultiValued();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.alfresco.repo.dictionary.PropertyDefinition#isMandatory()
+ */
+ public boolean isMandatory()
+ {
+ return m2Property.isMandatory();
+ }
+
+ public boolean isMandatoryEnforced()
+ {
+ return m2Property.isMandatoryEnforced();
+ }
+
+ /* (non-Javadoc)
+ * @see org.alfresco.repo.dictionary.PropertyDefinition#isProtected()
+ */
+ public boolean isProtected()
+ {
+ return m2Property.isProtected();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.alfresco.repo.dictionary.PropertyDefinition#isIndexed()
+ */
+ public boolean isIndexed()
+ {
+ return m2Property.isIndexed();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.alfresco.repo.dictionary.PropertyDefinition#isStoredInIndex()
+ */
+ public boolean isStoredInIndex()
+ {
+ return m2Property.isStoredInIndex();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.alfresco.repo.dictionary.PropertyDefinition#isIndexedAtomically()
+ */
+ public boolean isIndexedAtomically()
+ {
+ return m2Property.isIndexedAtomically();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.alfresco.repo.dictionary.PropertyDefinition#isTokenisedInIndex()
+ */
+ public IndexTokenisationMode getIndexTokenisationMode()
+ {
+ return m2Property.getIndexTokenisationMode();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.alfresco.service.cmr.dictionary.PropertyDefinition#getConstraints()
+ */
+ public List getConstraints()
+ {
+ return constraintDefs;
+ }
+
+ /* package */ M2ModelDiff diffProperty(PropertyDefinition propDef)
+ {
+ M2ModelDiff modelDiff = null;
+ boolean isUpdated = false;
+ boolean isUpdatedIncrementally = false;
+
+ if (this == propDef)
+ {
+ modelDiff = new M2ModelDiff(name, M2ModelDiff.TYPE_PROPERTY, M2ModelDiff.DIFF_UNCHANGED);
+ return modelDiff;
+ }
+
+ // check name - cannot be null
+ if (! name.equals(propDef.getName()))
+ {
+ isUpdated = true;
+ }
+
+ // check title
+ if (! EqualsHelper.nullSafeEquals(getTitle(), propDef.getTitle(), false))
+ {
+ isUpdatedIncrementally = true;
+ }
+
+ // check description
+ if (! EqualsHelper.nullSafeEquals(getDescription(), propDef.getDescription(), false))
+ {
+ isUpdatedIncrementally = true;
+ }
+
+ // check default value
+ if (! EqualsHelper.nullSafeEquals(getDefaultValue(), propDef.getDefaultValue(), false))
+ {
+ isUpdatedIncrementally = true;
+ }
+
+ // check datatype qname (TODO check datatype defs separately)
+ if (! EqualsHelper.nullSafeEquals(getDataType().getName(), propDef.getDataType().getName()))
+ {
+ isUpdated = true;
+ }
+
+ // check container class qname
+ if (! EqualsHelper.nullSafeEquals(getContainerClass().getName(), propDef.getContainerClass().getName()))
+ {
+ isUpdated = true;
+ }
+
+ // check multi-valued
+ if (isMultiValued() != propDef.isMultiValued())
+ {
+ isUpdated = true;
+ }
+
+ // check mandatory
+ if (isMandatory() != propDef.isMandatory())
+ {
+ isUpdated = true;
+ }
+
+ // check mandatory enforced
+ if (isMandatoryEnforced() != propDef.isMandatoryEnforced())
+ {
+ isUpdated = true;
+ }
+
+ // check protected
+ if (isProtected() != propDef.isProtected())
+ {
+ isUpdated = true;
+ }
+
+ // check indexed
+ if (isIndexed() != propDef.isIndexed())
+ {
+ isUpdated = true;
+ }
+
+ // check stored in index
+ if (isStoredInIndex() != propDef.isStoredInIndex())
+ {
+ isUpdated = true;
+ }
+
+ // check auto index
+ if (isIndexedAtomically() != propDef.isIndexedAtomically())
+ {
+ isUpdated = true;
+ }
+
+ // check override
+ if (isOverride() != propDef.isOverride())
+ {
+ isUpdated = true;
+ }
+
+ // check index tokenisation mode
+ if (! EqualsHelper.nullSafeEquals(getIndexTokenisationMode().toString(), propDef.getIndexTokenisationMode().toString(), false))
+ {
+ isUpdated = true;
+ }
+
+ // TODO - check prop constraints (inline and referenced)
+
+ if (isUpdated)
+ {
+ modelDiff = new M2ModelDiff(name, M2ModelDiff.TYPE_PROPERTY, M2ModelDiff.DIFF_UPDATED);
+ }
+ else if (isUpdatedIncrementally)
+ {
+ modelDiff = new M2ModelDiff(name, M2ModelDiff.TYPE_PROPERTY, M2ModelDiff.DIFF_UPDATED_INC);
+ }
+ else
+ {
+ modelDiff = new M2ModelDiff(name, M2ModelDiff.TYPE_PROPERTY, M2ModelDiff.DIFF_UNCHANGED);
+ }
+
+ return modelDiff;
+ }
+
+ /*package*/ static Collection diffPropertyLists(Collection previousProperties, Collection newProperties)
+ {
+ List modelDiffs = new ArrayList();
+
+ for (PropertyDefinition previousProperty : previousProperties)
+ {
+ boolean found = false;
+ for (PropertyDefinition newProperty : newProperties)
+ {
+ if (newProperty.getName().equals(previousProperty.getName()))
+ {
+ modelDiffs.add(((M2PropertyDefinition)previousProperty).diffProperty(newProperty));
+ found = true;
+ break;
+ }
+ }
+
+ if (! found)
+ {
+ modelDiffs.add(new M2ModelDiff(previousProperty.getName(), M2ModelDiff.TYPE_PROPERTY, M2ModelDiff.DIFF_DELETED));
+ }
+ }
+
+ for (PropertyDefinition newProperty : newProperties)
+ {
+ boolean found = false;
+ for (PropertyDefinition previousProperty : previousProperties)
+ {
+ if (newProperty.getName().equals(previousProperty.getName()))
+ {
+ found = true;
+ break;
+ }
+ }
+
+ if (! found)
+ {
+ modelDiffs.add(new M2ModelDiff(newProperty.getName(), M2ModelDiff.TYPE_PROPERTY, M2ModelDiff.DIFF_CREATED));
+ }
+ }
+
+ return modelDiffs;
+ }
+}