Search in sources :

Example 11 with M2Model

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;
}
Also used : HashMap(java.util.HashMap) M2Property(org.alfresco.repo.dictionary.M2Property) M2Model(org.alfresco.repo.dictionary.M2Model) ArrayList(java.util.ArrayList) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) M2Aspect(org.alfresco.repo.dictionary.M2Aspect) M2ClassAssociation(org.alfresco.repo.dictionary.M2ClassAssociation)

Example 12 with M2Model

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;
}
Also used : InputStream(java.io.InputStream) ContentReader(org.alfresco.service.cmr.repository.ContentReader) M2Model(org.alfresco.repo.dictionary.M2Model) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) IOException(java.io.IOException)

Example 13 with M2Model

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;
}
Also used : QName(org.alfresco.service.namespace.QName) M2Model(org.alfresco.repo.dictionary.M2Model) ArrayList(java.util.ArrayList) AlfrescoModel(org.alfresco.solr.client.AlfrescoModel)

Example 14 with M2Model

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;
}
Also used : NamespaceDAO(org.alfresco.repo.dictionary.NamespaceDAO) QName(org.alfresco.service.namespace.QName) M2Model(org.alfresco.repo.dictionary.M2Model) AlfrescoModelDiff(org.alfresco.solr.client.AlfrescoModelDiff) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Matchers.anyString(org.mockito.Matchers.anyString) AlfrescoModel(org.alfresco.solr.client.AlfrescoModel) TYPE(org.alfresco.solr.client.AlfrescoModelDiff.TYPE)

Example 15 with M2Model

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());
}
Also used : InputStream(java.io.InputStream) M2Model(org.alfresco.repo.dictionary.M2Model) Test(org.junit.Test)

Aggregations

M2Model (org.alfresco.repo.dictionary.M2Model)32 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)18 NodeRef (org.alfresco.service.cmr.repository.NodeRef)15 M2Aspect (org.alfresco.repo.dictionary.M2Aspect)10 QName (org.alfresco.service.namespace.QName)10 ParameterCheck.mandatoryString (org.springframework.extensions.surf.util.ParameterCheck.mandatoryString)10 M2Property (org.alfresco.repo.dictionary.M2Property)8 InputStream (java.io.InputStream)6 M2Constraint (org.alfresco.repo.dictionary.M2Constraint)6 File (java.io.File)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 M2ClassAssociation (org.alfresco.repo.dictionary.M2ClassAssociation)4 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 ArrayList (java.util.ArrayList)3 ZipFile (java.util.zip.ZipFile)3 AlfrescoModel (org.alfresco.solr.client.AlfrescoModel)3 HashSet (java.util.HashSet)2 M2Namespace (org.alfresco.repo.dictionary.M2Namespace)2