use of org.alfresco.repo.dictionary.M2Namespace in project SearchServices by Alfresco.
the class ModelTracker method loadPersistedModels.
/**
*/
private void loadPersistedModels() {
HashMap<String, M2Model> modelMap = new HashMap<String, M2Model>();
if (alfrescoModelDir.exists() && alfrescoModelDir.isDirectory()) {
// A filter for XML files
FileFilter filter = new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.isFile() && pathname.getName().endsWith(".xml");
}
};
// List XML files
for (File file : alfrescoModelDir.listFiles(filter)) {
InputStream modelStream = null;
M2Model model;
try {
modelStream = new FileInputStream(file);
model = M2Model.createModel(modelStream);
} catch (IOException e) {
throw new AlfrescoRuntimeException("File not found: " + file, e);
} finally {
if (modelStream != null) {
try {
modelStream.close();
} catch (Exception e) {
}
}
}
// Model successfully loaded
for (M2Namespace namespace : model.getNamespaces()) {
modelMap.put(namespace.getUri(), model);
}
}
}
// Load the models ensuring that they are loaded in the correct order
HashSet<String> loadedModels = new HashSet<String>();
for (M2Model model : modelMap.values()) {
loadModel(modelMap, loadedModels, model);
}
if (modelMap.size() > 0) {
AlfrescoSolrDataModel.getInstance().afterInitModels();
}
}
use of org.alfresco.repo.dictionary.M2Namespace 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;
}
}
use of org.alfresco.repo.dictionary.M2Namespace in project alfresco-remote-api by Alfresco.
the class CustomModelsImpl method validateImportedM2Model.
private void validateImportedM2Model(M2Model m2Model) {
List<M2Namespace> namespaces = m2Model.getNamespaces();
if (namespaces.size() > 1) {
throw new ConstraintViolatedException(I18NUtil.getMessage("cmm.rest_api.model.import_namespace_multiple_found", namespaces.size()));
} else if (namespaces.isEmpty()) {
throw new ConstraintViolatedException("cmm.rest_api.model.import_namespace_undefined");
}
checkUnsupportedModelElements(m2Model.getTypes());
checkUnsupportedModelElements(m2Model.getAspects());
}
Aggregations