ALF-8990: RSOLR 032: Model track and build from SOLR

- SOLR tracking now reflects all models loaded and changed on the repo to which it points 
- model tracking and related fixes
- model XML now round trips for Boolean properties :-)
- upgraded to latest version of jibx - 1.2.3
- added API to load models and not class load constraint extensions (does not affect the generated model XML only constraint enforcement)
- removed solr specific m2 model binding
- fixed SOLR tracking test

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28714 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Andrew Hind
2011-06-30 09:18:46 +00:00
parent b4fbb4cac6
commit 1d8438e7bf
6 changed files with 63 additions and 9 deletions

View File

@@ -1222,6 +1222,7 @@
<property name="nodeDAO" ref="nodeDAO"/>
<property name="qnameDAO" ref="qnameDAO"/>
<property name="solrDAO" ref="solrDAO" />
<property name="dictionaryDAO" ref="dictionaryDAO" />
</bean>
<!-- -->

View File

@@ -669,7 +669,7 @@ public class DictionaryModelType implements ContentServicePolicies.OnContentUpda
}
// Try and compile the model
CompiledModel compiledModel= m2Model.compile(dictionaryDAO, namespaceDAO);
CompiledModel compiledModel= m2Model.compile(dictionaryDAO, namespaceDAO, true);
ModelDefinition modelDefinition = compiledModel.getModelDefinition();
// Update the meta data for the model

View File

@@ -15,7 +15,7 @@ public class AlfrescoModel
protected AlfrescoModel(ModelDefinition modelDef)
{
this.modelDef = modelDef;
this.checksum = modelDef.getChecksum(ModelDefinition.XMLBindingType.SOLR);
this.checksum = modelDef.getChecksum(ModelDefinition.XMLBindingType.DEFAULT);
}
public ModelDefinition getModelDef()

View File

@@ -16,12 +16,19 @@ public class AlfrescoModelDiff
NEW, CHANGED, REMOVED;
};
private QName modelName;
private String modelName;
private TYPE type;
private Long oldChecksum;
private Long newChecksum;
public AlfrescoModelDiff(QName modelName, TYPE type, Long oldChecksum, Long newChecksum)
/**
* use full model name or it will be converted to the prefix form - as we are requesting the model it may not be on the other side - so the namespace is unknown.
* @param modelName
* @param type
* @param oldChecksum
* @param newChecksum
*/
public AlfrescoModelDiff(String modelName, TYPE type, Long oldChecksum, Long newChecksum)
{
super();
this.modelName = modelName;
@@ -29,8 +36,13 @@ public class AlfrescoModelDiff
this.oldChecksum = oldChecksum;
this.newChecksum = newChecksum;
}
public AlfrescoModelDiff(QName modelName, TYPE type, Long oldChecksum, Long newChecksum)
{
this(modelName.toString(), type, oldChecksum, newChecksum);
}
public QName getModelName()
public String getModelName()
{
return modelName;
}

View File

@@ -18,6 +18,10 @@
*/
package org.alfresco.repo.solr;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
@@ -28,18 +32,22 @@ import java.util.Map;
import java.util.Set;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.dictionary.CompiledModel;
import org.alfresco.repo.dictionary.DictionaryDAO;
import org.alfresco.repo.dictionary.DictionaryDAOImpl;
import org.alfresco.repo.domain.node.Node;
import org.alfresco.repo.domain.node.NodeDAO;
import org.alfresco.repo.domain.node.NodeDAO.ChildAssocRefQueryCallback;
import org.alfresco.repo.domain.qname.QNameDAO;
import org.alfresco.repo.domain.solr.SOLRDAO;
import org.alfresco.repo.solr.AlfrescoModelDiff.TYPE;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.service.cmr.dictionary.AspectDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.ModelDefinition;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.dictionary.ModelDefinition.XMLBindingType;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.NodeRef;
@@ -50,6 +58,7 @@ import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.Pair;
import org.alfresco.util.PropertyCheck;
import org.alfresco.util.TempFileProvider;
/**
* Component providing data for SOLR tracking
@@ -102,6 +111,13 @@ public class SOLRTrackingComponentImpl implements SOLRTrackingComponent
this.dictionaryService = dictionaryService;
}
public void setDictionaryDAO(DictionaryDAO dictionaryDAO)
{
this.dictionaryDAO = dictionaryDAO;
}
/**
* Initialize
*/
@@ -114,6 +130,7 @@ public class SOLRTrackingComponentImpl implements SOLRTrackingComponent
PropertyCheck.mandatory(this, "ownableService", ownableService);
PropertyCheck.mandatory(this, "tenantService", tenantService);
PropertyCheck.mandatory(this, "dictionaryService", dictionaryService);
PropertyCheck.mandatory(this, "dictionaryDAO", dictionaryDAO);
}
@Override
@@ -581,6 +598,30 @@ public class SOLRTrackingComponentImpl implements SOLRTrackingComponent
}
}
// for(AlfrescoModelDiff diff : diffs)
// {
// if(diff.getType() != TYPE.REMOVED)
// {
// CompiledModel cm = ((DictionaryDAOImpl)dictionaryDAO).getCompiledModel(QName.createQName(diff.getModelName()));
// File file = TempFileProvider.createTempFile(cm.getM2Model().getChecksum(XMLBindingType.DEFAULT)+ cm.getM2Model().getNamespaces().get(0).getPrefix(), ".xml");
// FileOutputStream os;
// try
// {
// os = new FileOutputStream(file);
// cm.getM2Model().toXML(os);
// os.flush();
// os.close();
//
// }
// catch (IOException e)
// {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
//
// }
return diffs;
}

View File

@@ -340,7 +340,7 @@ public class SOLRTrackingComponentTest extends TestCase
assertEquals("Unexpected number of changed models", 0, diffResults1.getChangedModels().size());
assertEquals("Unexpected number of removed models", 0, diffResults1.getRemovedModels().size());
AlfrescoModelDiff diff = diffResults1.getNewModels().get(0);
assertEquals("Unexpected model name change", QName.createQName(testModel.getName(), namespaceService), diff.getModelName());
assertEquals("Unexpected model name change", QName.createQName(testModel.getName(), namespaceService).toString(), diff.getModelName());
// get current checksum for the test model
Long testModelChecksum = tracker.getChecksum(QName.createQName(testModel.getName(), namespaceService));
@@ -359,7 +359,7 @@ public class SOLRTrackingComponentTest extends TestCase
assertEquals("Expected detection of changed testmodel", 1, changedModels.size());
AlfrescoModelDiff changedModel = changedModels.get(0);
assertEquals("Unexpected changed model name", QName.createQName(testModel.getName(), namespaceService),
assertEquals("Unexpected changed model name", QName.createQName(testModel.getName(), namespaceService).toString(),
changedModel.getModelName());
assertNotNull("", changedModel.getOldChecksum().longValue());
assertEquals("Old checksum value is incorrect", testModelChecksum.longValue(), changedModel.getOldChecksum().longValue());
@@ -372,7 +372,7 @@ public class SOLRTrackingComponentTest extends TestCase
ModelDiffResults diffResults3 = tracker.diff();
List<AlfrescoModelDiff> removedModels = diffResults3.getRemovedModels();
assertEquals("Expected 1 removed model", 1, removedModels.size());
QName removedModelName = removedModels.get(0).getModelName();
QName removedModelName = QName.createQName(removedModels.get(0).getModelName());
String removedModelNamespace = removedModelName.getNamespaceURI();
String removedModelLocalName = removedModelName.getLocalName();
assertEquals("Removed model namespace is incorrect", "http://www.alfresco.org/model/solrtest/1.0", removedModelNamespace);
@@ -427,7 +427,7 @@ public class SOLRTrackingComponentTest extends TestCase
if(diff.getType().equals(AlfrescoModelDiff.TYPE.NEW))
{
newModels.add(diff);
trackedModels.put(diff.getModelName(), diff.getNewChecksum());
trackedModels.put(QName.createQName(diff.getModelName()), diff.getNewChecksum());
}
else if(diff.getType().equals(AlfrescoModelDiff.TYPE.CHANGED))
{