use of org.alfresco.repo.dictionary.M2Model in project records-management by Alfresco.
the class ApplyDodCertModelFixesGet method executeImpl.
@Override
public Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
LOGGER.info("Applying webscript-based patches to RM custom model in the repo.");
M2Model customModel = readCustomContentModel();
if (customModel == null) {
final String msg = "Custom content model could not be read";
LOGGER.error(msg);
throw new AlfrescoRuntimeException(msg);
}
String customAspectName = ASPECT_CUSTOM_ASSOCIATIONS.toPrefixString(namespaceService);
M2Aspect customAssocsAspect = customModel.getAspect(customAspectName);
if (customAssocsAspect == null) {
final String msg = "Unknown aspect: " + customAspectName;
LOGGER.error(msg);
throw new AlfrescoRuntimeException(msg);
}
// MOB-1573. All custom references should have many-many multiplicity.
LOGGER.info("MOB-1573. All custom references should have many-many multiplicity.");
for (M2ClassAssociation classAssoc : customAssocsAspect.getAssociations()) {
classAssoc.setSourceMany(true);
classAssoc.setTargetMany(true);
}
// MOB-1621. Custom fields should be created as untokenized by default.
LOGGER.info("MOB-1621. Custom fields should be created as untokenized by default.");
List<String> allCustomPropertiesAspects = new ArrayList<String>(4);
allCustomPropertiesAspects.add(RMC_CUSTOM_RECORD_SERIES_PROPERTIES);
allCustomPropertiesAspects.add(RMC_CUSTOM_RECORD_CATEGORY_PROPERTIES);
allCustomPropertiesAspects.add(RMC_CUSTOM_RECORD_FOLDER_PROPERTIES);
allCustomPropertiesAspects.add(RMC_CUSTOM_RECORD_PROPERTIES);
for (String aspectName : allCustomPropertiesAspects) {
M2Aspect aspectObj = customModel.getAspect(aspectName);
List<M2Property> customProperties = aspectObj.getProperties();
for (M2Property propertyObj : customProperties) {
propertyObj.setIndexed(true);
propertyObj.setIndexedAtomically(true);
propertyObj.setStoredInIndex(false);
propertyObj.setIndexTokenisationMode(IndexTokenisationMode.FALSE);
}
}
writeCustomContentModel(customModel);
LOGGER.info("Completed application of webscript-based patches to RM custom model in the repo.");
Map<String, Object> model = new HashMap<String, Object>(1, 1.0f);
model.put("success", true);
return model;
}
use of org.alfresco.repo.dictionary.M2Model in project records-management by Alfresco.
the class ApplyDodCertModelFixesGet method readCustomContentModel.
private M2Model readCustomContentModel() {
ContentReader reader = this.contentService.getReader(RM_CUSTOM_MODEL_NODE_REF, ContentModel.TYPE_CONTENT);
if (!reader.exists()) {
throw new AlfrescoRuntimeException("RM CustomModel has no content.");
}
InputStream contentIn = null;
M2Model deserializedModel = null;
try {
contentIn = reader.getContentInputStream();
deserializedModel = M2Model.createModel(contentIn);
} finally {
try {
if (contentIn != null) {
contentIn.close();
}
} catch (IOException ignored) {
// Intentionally empty.`
}
}
return deserializedModel;
}
use of org.alfresco.repo.dictionary.M2Model 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.repo.dictionary.M2Model 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.repo.dictionary.M2Model in project SearchServices by Alfresco.
the class SolrDataModelTest method smokeTestCMISModel.
@Test
public void smokeTestCMISModel() {
AlfrescoSolrDataModel dataModel = new AlfrescoSolrDataModel();
// load test model containing content properties multiple
ClassLoader cl = SolrDataModelTest.class.getClassLoader();
InputStream modelStream = cl.getResourceAsStream("alfresco/model/dictionaryModel.xml");
assertNotNull(modelStream);
M2Model model = M2Model.createModel(modelStream);
dataModel.putModel(model);
modelStream = cl.getResourceAsStream("alfresco/model/cmisModel.xml");
assertNotNull(modelStream);
model = M2Model.createModel(modelStream);
dataModel.putModel(model);
assertEquals(2, dataModel.getAlfrescoModels().size());
assertEquals(1, dataModel.getIndexedFieldNamesForProperty(OBJECT_ID).getFields().size());
assertEquals(4, dataModel.getIndexedFieldNamesForProperty(NAME).getFields().size());
assertEquals(1, dataModel.getIndexedFieldNamesForProperty(CREATION_DATE).getFields().size());
assertEquals(0, dataModel.getIndexedFieldNamesForProperty(IS_IMMUTABLE).getFields().size());
assertEquals(0, dataModel.getIndexedFieldNamesForProperty(IS_PRIVATE_WOKING_COPY).getFields().size());
assertEquals(1, dataModel.getIndexedFieldNamesForProperty(CONTENT_STREAM_LENGTH).getFields().size());
assertEquals(1, dataModel.getQueryableFields(OBJECT_ID, null, FieldUse.FACET).getFields().size());
assertEquals(1, dataModel.getQueryableFields(OBJECT_ID, null, FieldUse.COMPLETION).getFields().size());
assertEquals(1, dataModel.getQueryableFields(OBJECT_ID, null, FieldUse.FTS).getFields().size());
assertEquals(1, dataModel.getQueryableFields(OBJECT_ID, null, FieldUse.ID).getFields().size());
assertEquals(1, dataModel.getQueryableFields(OBJECT_ID, null, FieldUse.MULTI_FACET).getFields().size());
assertEquals(1, dataModel.getQueryableFields(OBJECT_ID, null, FieldUse.SORT).getFields().size());
assertEquals(1, dataModel.getQueryableFields(OBJECT_ID, null, FieldUse.STATS).getFields().size());
assertEquals(1, dataModel.getQueryableFields(OBJECT_ID, null, FieldUse.SUGGESTION).getFields().size());
assertEquals(1, dataModel.getQueryableFields(NAME, null, FieldUse.FACET).getFields().size());
assertEquals(1, dataModel.getQueryableFields(NAME, null, FieldUse.COMPLETION).getFields().size());
assertEquals(1, dataModel.getQueryableFields(NAME, null, FieldUse.FTS).getFields().size());
assertEquals(2, dataModel.getQueryableFields(NAME, null, FieldUse.ID).getFields().size());
assertEquals(1, dataModel.getQueryableFields(NAME, null, FieldUse.MULTI_FACET).getFields().size());
assertEquals(1, dataModel.getQueryableFields(NAME, null, FieldUse.SORT).getFields().size());
assertEquals(1, dataModel.getQueryableFields(NAME, null, FieldUse.STATS).getFields().size());
assertEquals(1, dataModel.getQueryableFields(NAME, null, FieldUse.SUGGESTION).getFields().size());
assertEquals(1, dataModel.getQueryableFields(CREATION_DATE, null, FieldUse.FACET).getFields().size());
assertEquals(1, dataModel.getQueryableFields(CREATION_DATE, null, FieldUse.COMPLETION).getFields().size());
assertEquals(1, dataModel.getQueryableFields(CREATION_DATE, null, FieldUse.FTS).getFields().size());
assertEquals(1, dataModel.getQueryableFields(CREATION_DATE, null, FieldUse.ID).getFields().size());
assertEquals(1, dataModel.getQueryableFields(CREATION_DATE, null, FieldUse.MULTI_FACET).getFields().size());
assertEquals(1, dataModel.getQueryableFields(CREATION_DATE, null, FieldUse.SORT).getFields().size());
assertEquals(1, dataModel.getQueryableFields(CREATION_DATE, null, FieldUse.STATS).getFields().size());
assertEquals(1, dataModel.getQueryableFields(CREATION_DATE, null, FieldUse.SUGGESTION).getFields().size());
assertEquals(1, dataModel.getQueryableFields(IS_PRIVATE_WOKING_COPY, null, FieldUse.FACET).getFields().size());
assertEquals(1, dataModel.getQueryableFields(IS_PRIVATE_WOKING_COPY, null, FieldUse.COMPLETION).getFields().size());
assertEquals(1, dataModel.getQueryableFields(IS_PRIVATE_WOKING_COPY, null, FieldUse.FTS).getFields().size());
assertEquals(1, dataModel.getQueryableFields(IS_PRIVATE_WOKING_COPY, null, FieldUse.ID).getFields().size());
assertEquals(1, dataModel.getQueryableFields(IS_PRIVATE_WOKING_COPY, null, FieldUse.MULTI_FACET).getFields().size());
assertEquals(1, dataModel.getQueryableFields(IS_PRIVATE_WOKING_COPY, null, FieldUse.SORT).getFields().size());
assertEquals(1, dataModel.getQueryableFields(IS_PRIVATE_WOKING_COPY, null, FieldUse.STATS).getFields().size());
assertEquals(1, dataModel.getQueryableFields(IS_PRIVATE_WOKING_COPY, null, FieldUse.SUGGESTION).getFields().size());
assertEquals(1, dataModel.getQueryableFields(CONTENT_STREAM_LENGTH, null, FieldUse.FACET).getFields().size());
assertEquals(1, dataModel.getQueryableFields(CONTENT_STREAM_LENGTH, null, FieldUse.COMPLETION).getFields().size());
assertEquals(1, dataModel.getQueryableFields(CONTENT_STREAM_LENGTH, null, FieldUse.FTS).getFields().size());
assertEquals(1, dataModel.getQueryableFields(CONTENT_STREAM_LENGTH, null, FieldUse.ID).getFields().size());
assertEquals(1, dataModel.getQueryableFields(CONTENT_STREAM_LENGTH, null, FieldUse.MULTI_FACET).getFields().size());
assertEquals(1, dataModel.getQueryableFields(CONTENT_STREAM_LENGTH, null, FieldUse.SORT).getFields().size());
assertEquals(1, dataModel.getQueryableFields(CONTENT_STREAM_LENGTH, null, FieldUse.STATS).getFields().size());
assertEquals(1, dataModel.getQueryableFields(CONTENT_STREAM_LENGTH, null, FieldUse.SUGGESTION).getFields().size());
}
Aggregations