mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
RM - custom/dynamic model support for incremental updates to title/description
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@16152 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -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)
|
||||
|
@@ -754,6 +754,106 @@ public class DiffModelTest extends TestCase
|
||||
|
||||
"</model>";
|
||||
|
||||
public static final String MODEL6_XML =
|
||||
"<model name=\"test1:model6\" xmlns=\"http://www.alfresco.org/model/dictionary/1.0\">" +
|
||||
|
||||
" <description>Another description</description>" +
|
||||
" <author>Alfresco</author>" +
|
||||
" <published>2007-08-01</published>" +
|
||||
" <version>1.0</version>" +
|
||||
|
||||
" <imports>" +
|
||||
" <import uri=\"http://www.alfresco.org/model/dictionary/1.0\" prefix=\"d\"/>" +
|
||||
" </imports>" +
|
||||
|
||||
" <namespaces>" +
|
||||
" <namespace uri=\"http://www.alfresco.org/model/test1/1.0\" prefix=\"test1\"/>" +
|
||||
" </namespaces>" +
|
||||
|
||||
" <types>" +
|
||||
|
||||
" <type name=\"test1:type1\">" +
|
||||
" <title>Type1 Title</title>" +
|
||||
" <description>Type1 Description</description>" +
|
||||
" <properties>" +
|
||||
" <property name=\"test1:prop1\">" +
|
||||
" <title>Prop1 Title</title>" +
|
||||
" <description>Prop1 Description</description>" +
|
||||
" <type>d:text</type>" +
|
||||
" </property>" +
|
||||
" </properties>" +
|
||||
" </type>" +
|
||||
|
||||
" </types>" +
|
||||
|
||||
" <aspects>" +
|
||||
|
||||
" <aspect name=\"test1:aspect1\">" +
|
||||
" <title>Aspect1 Title</title>" +
|
||||
" <description>Aspect1 Description</description>" +
|
||||
" <properties>" +
|
||||
" <property name=\"test1:prop9\">" +
|
||||
" <title>Prop9 Title</title>" +
|
||||
" <description>Prop9 Description</description>" +
|
||||
" <type>d:text</type>" +
|
||||
" </property>" +
|
||||
" </properties>" +
|
||||
" </aspect>" +
|
||||
|
||||
" </aspects>" +
|
||||
|
||||
"</model>";
|
||||
|
||||
public static final String MODEL6_UPDATE1_XML =
|
||||
"<model name=\"test1:model6\" xmlns=\"http://www.alfresco.org/model/dictionary/1.0\">" +
|
||||
|
||||
" <description>Another description - UPDATE1</description>" +
|
||||
" <author>Alfresco - UPDATE1</author>" +
|
||||
" <published>2009-08-01</published>" +
|
||||
" <version>2.0</version>" +
|
||||
|
||||
" <imports>" +
|
||||
" <import uri=\"http://www.alfresco.org/model/dictionary/1.0\" prefix=\"d\"/>" +
|
||||
" </imports>" +
|
||||
|
||||
" <namespaces>" +
|
||||
" <namespace uri=\"http://www.alfresco.org/model/test1/1.0\" prefix=\"test1\"/>" +
|
||||
" </namespaces>" +
|
||||
|
||||
" <types>" +
|
||||
|
||||
" <type name=\"test1:type1\">" +
|
||||
" <title>Type1 Title - UPDATE1</title>" +
|
||||
" <description>Type1 Description - UPDATE1</description>" +
|
||||
" <properties>" +
|
||||
" <property name=\"test1:prop1\">" +
|
||||
" <title>Prop1 Title - UPDATE1</title>" +
|
||||
" <description>Prop1 Description - UPDATE1</description>" +
|
||||
" <type>d:text</type>" +
|
||||
" </property>" +
|
||||
" </properties>" +
|
||||
" </type>" +
|
||||
|
||||
" </types>" +
|
||||
|
||||
" <aspects>" +
|
||||
|
||||
" <aspect name=\"test1:aspect1\">" +
|
||||
" <title>Aspect1 Title</title>" +
|
||||
" <description>Aspect1 Description</description>" +
|
||||
" <properties>" +
|
||||
" <property name=\"test1:prop9\">" +
|
||||
" <title>Prop9 Title - UPDATE1</title>" +
|
||||
" <description>Prop9 Description - UPDATE1</description>" +
|
||||
" <type>d:text</type>" +
|
||||
" </property>" +
|
||||
" </properties>" +
|
||||
" </aspect>" +
|
||||
|
||||
" </aspects>" +
|
||||
|
||||
"</model>";
|
||||
|
||||
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<M2ModelDiff> 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());
|
||||
|
@@ -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<M2ModelDiff> diffAssocLists(Collection<AssociationDefinition> previousAssocs, Collection<AssociationDefinition> newAssocs)
|
||||
{
|
||||
List<M2ModelDiff> M2ModelDiffs = new ArrayList<M2ModelDiff>();
|
||||
|
||||
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<M2ModelDiff> diffAssocLists(Collection<AssociationDefinition> previousAssocs, Collection<AssociationDefinition> newAssocs)
|
||||
{
|
||||
List<M2ModelDiff> modelDiffs = new ArrayList<M2ModelDiff>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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<M2ModelDiff> 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;
|
||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user