use of org.alfresco.solr.client.AlfrescoModel in project SearchServices by Alfresco.
the class AlfrescoSolrDataModel method getAlfrescoModels.
/**
* @return List<AlfrescoModel>
*/
public List<AlfrescoModel> getAlfrescoModels() {
ArrayList<AlfrescoModel> answer = new ArrayList<AlfrescoModel>();
for (QName modelName : dictionaryDAO.getModels()) {
M2Model m2Model = dictionaryDAO.getCompiledModel(modelName).getM2Model();
answer.add(new AlfrescoModel(m2Model, getDictionaryService(CMISStrictDictionaryService.DEFAULT).getModel(modelName).getChecksum(ModelDefinition.XMLBindingType.DEFAULT)));
}
return answer;
}
use of org.alfresco.solr.client.AlfrescoModel in project SearchServices by Alfresco.
the class ModelTrackerTest method setUpTestTrackModels.
@SuppressWarnings("unchecked")
private String setUpTestTrackModels() throws AuthenticationException, IOException, JSONException {
QName modelName = QName.createQName("qname");
TYPE type = TYPE.CHANGED;
Long oldChecksum = new Long(0);
Long newChecksum = new Long(1);
AlfrescoModelDiff diff = new AlfrescoModelDiff(modelName, type, oldChecksum, newChecksum);
List<AlfrescoModelDiff> modelDiffs = new ArrayList<>();
modelDiffs.add(diff);
when(this.repositoryClient.getModelsDiff(any(String.class), any(List.class))).thenReturn(modelDiffs);
final String name = "a model name";
M2Model model = M2Model.createModel(name);
M2Model spiedModel = spy(model);
model.createNamespace("uri", "prefix");
AlfrescoModel alfrescoModel = new AlfrescoModel(spiedModel, newChecksum);
when(this.repositoryClient.getModel(any(String.class), eq(modelName))).thenReturn(alfrescoModel);
NamespaceDAO namespaceDao = mock(NamespaceDAO.class);
Collection<String> values = new ArrayList<>();
values.add("prefix");
when(namespaceDao.getPrefixes(anyString())).thenReturn(values);
when(this.srv.getNamespaceDAO()).thenReturn(namespaceDao);
when(this.srv.getM2Model(modelName)).thenReturn(spiedModel);
when(this.srv.putModel(spiedModel)).thenReturn(true);
return name;
}
use of org.alfresco.solr.client.AlfrescoModel in project SearchServices by Alfresco.
the class ModelTracker method trackModelsImpl.
/**
* Tracks models. Reflects changes and updates on disk copy
*
* @throws AuthenticationException
* @throws IOException
* @throws JSONException
*/
private void trackModelsImpl() throws AuthenticationException, IOException, JSONException {
long start = System.nanoTime();
List<AlfrescoModelDiff> modelDiffs = client.getModelsDiff(coreName, this.infoSrv.getAlfrescoModels());
HashMap<String, M2Model> modelMap = new HashMap<String, M2Model>();
for (AlfrescoModelDiff modelDiff : modelDiffs) {
switch(modelDiff.getType()) {
case CHANGED:
AlfrescoModel changedModel = client.getModel(coreName, modelDiff.getModelName());
for (M2Namespace namespace : changedModel.getModel().getNamespaces()) {
modelMap.put(namespace.getUri(), changedModel.getModel());
}
break;
case NEW:
AlfrescoModel newModel = client.getModel(coreName, modelDiff.getModelName());
for (M2Namespace namespace : newModel.getModel().getNamespaces()) {
modelMap.put(namespace.getUri(), newModel.getModel());
}
break;
case REMOVED:
// We need to know the prefix for the uri to delete them
break;
}
}
HashSet<String> loadedModels = new HashSet<String>();
for (M2Model model : modelMap.values()) {
loadModel(modelMap, loadedModels, model);
}
if (loadedModels.size() > 0) {
this.infoSrv.afterInitModels();
}
for (AlfrescoModelDiff modelDiff : modelDiffs) {
switch(modelDiff.getType()) {
case CHANGED:
removeMatchingModels(alfrescoModelDir, modelDiff.getModelName());
M2Model changedModel = this.infoSrv.getM2Model(modelDiff.getModelName());
File changedFile = new File(alfrescoModelDir, getModelFileName(changedModel));
FileOutputStream cos = new FileOutputStream(changedFile);
changedModel.toXML(cos);
cos.flush();
cos.close();
break;
case NEW:
M2Model newModel = this.infoSrv.getM2Model(modelDiff.getModelName());
// add on file
File newFile = new File(alfrescoModelDir, getModelFileName(newModel));
FileOutputStream nos = new FileOutputStream(newFile);
newModel.toXML(nos);
nos.flush();
nos.close();
break;
case REMOVED:
// This will remove the model from the dictionary on completion
try {
removeMatchingModels(alfrescoModelDir, modelDiff.getModelName());
} finally {
AlfrescoSolrDataModel.getInstance().removeModel(modelDiff.getModelName());
}
break;
}
}
long end = System.nanoTime();
trackerStats.addModelTime(end - start);
if (true == runPostModelLoadInit) {
for (Object key : props.keySet()) {
String stringKey = (String) key;
if (stringKey.startsWith("alfresco.index.store")) {
StoreRef store = new StoreRef(props.getProperty(stringKey));
indexedStores.add(store);
}
if (stringKey.startsWith("alfresco.ignore.store")) {
StoreRef store = new StoreRef(props.getProperty(stringKey));
ignoredStores.add(store);
}
if (stringKey.startsWith("alfresco.index.tenant")) {
indexedTenants.add(props.getProperty(stringKey));
}
if (stringKey.startsWith("alfresco.ignore.tenant")) {
ignoredTenants.add(props.getProperty(stringKey));
}
if (stringKey.startsWith("alfresco.index.datatype")) {
QName qname = expandQName(props.getProperty(stringKey));
indexedDataTypes.add(qname);
}
if (stringKey.startsWith("alfresco.ignore.datatype")) {
QName qname = expandQName(props.getProperty(stringKey));
ignoredDataTypes.add(qname);
}
if (stringKey.startsWith("alfresco.index.type")) {
QName qname = expandQName(props.getProperty(stringKey));
indexedTypes.add(qname);
}
if (stringKey.startsWith("alfresco.ignore.type")) {
QName qname = expandQName(props.getProperty(stringKey));
ignoredTypes.add(qname);
}
if (stringKey.startsWith("alfresco.index.aspect")) {
QName qname = expandQName(props.getProperty(stringKey));
indexedAspects.add(qname);
}
if (stringKey.startsWith("alfresco.ignore.aspect")) {
QName qname = expandQName(props.getProperty(stringKey));
ignoredAspects.add(qname);
}
if (stringKey.startsWith("alfresco.index.field")) {
String name = expandName(props.getProperty(stringKey));
indexedFields.add(name);
}
if (stringKey.startsWith("alfresco.ignore.field")) {
String name = expandName(props.getProperty(stringKey));
ignoredFields.add(name);
}
}
runPostModelLoadInit = false;
}
}
Aggregations