org.alfresco.repo.dictionary.M2Model Java Examples

The following examples show how to use org.alfresco.repo.dictionary.M2Model. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractEnterpriseOpenCMISTCKTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void overrideVersionableAspectProperties(ApplicationContext ctx)
{
    final DictionaryDAO dictionaryDAO = (DictionaryDAO) ctx.getBean("dictionaryDAO");
    dictionaryDAO.removeModel(QName.createQName("cm:contentmodel"));
    M2Model contentModel = M2Model.createModel(getClass().getClassLoader().getResourceAsStream("alfresco/model/contentModel.xml"));

    M2Aspect versionableAspect = contentModel.getAspect("cm:versionable");
    M2Property prop = versionableAspect.getProperty("cm:initialVersion"); 
    prop.setDefaultValue(Boolean.FALSE.toString());
    prop = versionableAspect.getProperty("cm:autoVersion"); 
    prop.setDefaultValue(Boolean.FALSE.toString());
    prop = versionableAspect.getProperty("cm:autoVersionOnUpdateProps"); 
    prop.setDefaultValue(Boolean.FALSE.toString());

    dictionaryDAO.putModel(contentModel);
}
 
Example #2
Source File: SOLRAPIClientTest.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void loadModel(Map<String, M2Model> modelMap, HashSet<String> loadedModels, M2Model model)
{
    String modelName = model.getName();
    if (loadedModels.contains(modelName) == false)
    {
        for (M2Namespace importNamespace : model.getImports())
        {
            M2Model importedModel = modelMap.get(importNamespace.getUri());
            if (importedModel != null)
            {

                // Ensure that the imported model is loaded first
                loadModel(modelMap, loadedModels, importedModel);
            }
        }

        dictionaryDAO.putModelIgnoringConstraints(model);
        loadedModels.add(modelName);
    }
}
 
Example #3
Source File: PerformanceNodeServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Loads the test model required for building the node graphs
 */
public static DictionaryService loadModel(ApplicationContext applicationContext)
{
    DictionaryDAO dictionaryDao = (DictionaryDAO) applicationContext.getBean("dictionaryDAO");
    
    // load the system model
    ClassLoader cl = PerformanceNodeServiceTest.class.getClassLoader();
    InputStream modelStream = cl.getResourceAsStream("alfresco/model/contentModel.xml");
    assertNotNull(modelStream);
    M2Model model = M2Model.createModel(modelStream);
    dictionaryDao.putModel(model);
    
    // load the test model
    modelStream = cl.getResourceAsStream("org/alfresco/repo/node/BaseNodeServiceTest_model.xml");
    assertNotNull(modelStream);
    model = M2Model.createModel(modelStream);
    dictionaryDao.putModel(model);
    
    DictionaryComponent dictionary = new DictionaryComponent();
    dictionary.setDictionaryDAO(dictionaryDao);
    
    return dictionary;
}
 
Example #4
Source File: AlfrescoSolrDataModel.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
public boolean putModel(M2Model model)
{
    Set<String> errors = validateModel(model);
    if(errors.isEmpty())
    {
        modelErrors.remove(model.getName());
        dictionaryDAO.putModelIgnoringConstraints(model);
        return true;
    }
    else
    {
        if(!modelErrors.containsKey(model.getName()))
        {
            modelErrors.put(model.getName(), errors);
            log.warn(errors.iterator().next());
        }
        return false;
    }
}
 
Example #5
Source File: NodeRefPropertyMethodInterceptorTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Before
public void before() throws Exception
{
    mlAwareNodeService = (NodeService) applicationContext.getBean("mlAwareNodeService");
    nodeService = (NodeService) applicationContext.getBean("nodeService");
    dictionaryDAO = (DictionaryDAO) applicationContext.getBean("dictionaryDAO");

    authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent");

    authenticationComponent.setSystemUserAsCurrentUser();

    ClassLoader cl = BaseNodeServiceTest.class.getClassLoader();
    InputStream modelStream = cl.getResourceAsStream("org/alfresco/repo/node/NodeRefTestModel.xml");
    assertNotNull(modelStream);
    M2Model model = M2Model.createModel(modelStream);
    dictionaryDAO.putModel(model);

    StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
    rootNodeRef = nodeService.getRootNode(storeRef);

}
 
Example #6
Source File: DbNodeServiceImplPropagationTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Loads the test model required for building the node graphs
 */
public static DictionaryService loadModel(ApplicationContext applicationContext)
{
    DictionaryDAO dictionaryDao = (DictionaryDAO) applicationContext.getBean("dictionaryDAO");
    // load the system model
    ClassLoader cl = BaseNodeServiceTest.class.getClassLoader();
    InputStream modelStream = cl.getResourceAsStream("alfresco/model/contentModel.xml");
    assertNotNull(modelStream);
    M2Model model = M2Model.createModel(modelStream);
    dictionaryDao.putModel(model);
    // load the test model
    modelStream = cl.getResourceAsStream("org/alfresco/repo/node/BaseNodeServiceTest_model.xml");
    assertNotNull(modelStream);
    model = M2Model.createModel(modelStream);
    dictionaryDao.putModel(model);
    
    DictionaryComponent dictionary = new DictionaryComponent();
    dictionary.setDictionaryDAO(dictionaryDao);
    // done
    return dictionary;
}
 
Example #7
Source File: BaseNodeServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Loads the test model required for building the node graphs
 */
public static DictionaryService loadModel(ApplicationContext applicationContext)
{
    DictionaryDAO dictionaryDao = (DictionaryDAO) applicationContext.getBean("dictionaryDAO");
    // load the system model
    ClassLoader cl = BaseNodeServiceTest.class.getClassLoader();
    InputStream modelStream = cl.getResourceAsStream("alfresco/model/contentModel.xml");
    assertNotNull(modelStream);
    M2Model model = M2Model.createModel(modelStream);
    dictionaryDao.putModel(model);
    // load the test model
    modelStream = cl.getResourceAsStream("org/alfresco/repo/node/BaseNodeServiceTest_model.xml");
    assertNotNull(modelStream);
    model = M2Model.createModel(modelStream);
    dictionaryDao.putModel(model);
    
    DictionaryComponent dictionary = new DictionaryComponent();
    dictionary.setDictionaryDAO(dictionaryDao);
    // done
    return dictionary;
}
 
Example #8
Source File: AlfrescoSolrDataModel.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
private Set<String> validateModel(M2Model model)
{
    try
    {
        dictionaryDAO.getCompiledModel(QName.createQName(model.getName(), namespaceDAO));
    }
    catch (DictionaryException | NamespaceException exception)
    {
        // No model to diff
        return Collections.emptySet();
    }

    // namespace unknown - no model
    List<M2ModelDiff> modelDiffs = dictionaryDAO.diffModelIgnoringConstraints(model);
    return modelDiffs.stream()
            .filter(diff -> diff.getDiffType().equals(M2ModelDiff.DIFF_UPDATED))
            .map(diff ->
                    String.format("Model not updated: %s Failed to validate model update - found non-incrementally updated %s '%s'",
                            model.getName(),
                            diff.getElementType(),
                            diff.getElementName()))
            .collect(Collectors.toSet());
}
 
Example #9
Source File: ModelTracker.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void loadModel(Map<String, M2Model> modelMap, HashSet<String> loadedModels, M2Model model)
{
    String modelName = model.getName();
    if (!loadedModels.contains(modelName))
    {
        for (M2Namespace importNamespace : model.getImports())
        {
            M2Model importedModel = modelMap.get(importNamespace.getUri());
            if (importedModel != null)
            {

                // Ensure that the imported model is loaded first
                loadModel(modelMap, loadedModels, importedModel);
            }
        }

        if (this.infoSrv.putModel(model))
        {
            loadedModels.add(modelName);
        }
        LOGGER.info("Loading model {}", model.getName());
    }
}
 
Example #10
Source File: CustomModelsImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
private CustomModelDefinition updateModel(ModelDetails modelDetails, String errorMsg)
{
    M2Model m2Model = convertToM2Model(modelDetails);
    try
    {
        CustomModelDefinition modelDef = customModelService.updateCustomModel(modelDetails.getModel().getName(), m2Model, modelDetails.isActive());
        return modelDef;
    }
    catch (CustomModelConstraintException mce)
    {
        throw new ConstraintViolatedException(mce.getMessage());
    }
    catch (InvalidCustomModelException iex)
    {
        throw new InvalidArgumentException(iex.getMessage());
    }
    catch (Exception ex)
    {
        if (ex.getMessage() != null)
        {
            errorMsg = ex.getMessage();
        }
        throw new ApiException(errorMsg, ex);
    }
}
 
Example #11
Source File: ModelTrackerIT.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example #12
Source File: CustomModelUploadPost.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected CustomModel importModel(M2Model m2Model)
{
    CustomModel model = null;
    try
    {
        model = customModels.createCustomModel(m2Model);
    }
    catch (Exception ex)
    {
        int statusCode;
        if (ex instanceof ConstraintViolatedException)
        {
            statusCode = Status.STATUS_CONFLICT;
        }
        else if (ex instanceof InvalidArgumentException)
        {
            statusCode = Status.STATUS_BAD_REQUEST;
        }
        else
        {
            statusCode = Status.STATUS_INTERNAL_SERVER_ERROR;
        }
        String msg = ex.getMessage();
        // remove log numbers. regEx => match 8 or more integers
        msg = (msg != null) ? msg.replaceAll("\\d{8,}", "").trim() : "cmm.rest_api.model.import_failure";

        throw new WebScriptException(statusCode, msg);
    }

    return model;
}
 
Example #13
Source File: AlfrescoSolrDataModel.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Returns the Alfresco models associated with the current dictionary.
 *
 * @return the Alfresco models associated with the current dictionary.
 */
public List<AlfrescoModel> getAlfrescoModels()
{
    return dictionaryDAO.getModels().stream()
            .map(qname -> {
                M2Model m2Model = dictionaryDAO.getCompiledModel(qname).getM2Model();
                return new AlfrescoModel(
                        m2Model,
                        getDictionaryService(
                                CMISStrictDictionaryService.DEFAULT).getModel(qname).getChecksum(ModelDefinition.XMLBindingType.DEFAULT));})
            .collect(Collectors.toList());
}
 
Example #14
Source File: CustomModelsImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
private CustomModel createCustomModelImpl(CustomModel model, boolean basicModelOnly)
{
    M2Model m2Model = null;
    if (basicModelOnly)
    {
        m2Model = convertToM2Model(model, null, null, null);
    }
    else
    {
        m2Model = convertToM2Model(model, model.getTypes(), model.getAspects(), model.getConstraints());
    }

    boolean activate = ModelStatus.ACTIVE.equals(model.getStatus());
    try
    {
        CustomModelDefinition modelDefinition = customModelService.createCustomModel(m2Model, activate);
        return new CustomModel(modelDefinition);
    }
    catch (ModelExistsException me)
    {
        throw new ConstraintViolatedException(me.getMessage());
    }
    catch (CustomModelConstraintException ncx)
    {
        throw new ConstraintViolatedException(ncx.getMessage());
    }
    catch (InvalidCustomModelException iex)
    {
        throw new InvalidArgumentException(iex.getMessage());
    }
    catch (Exception e)
    {
        throw new ApiException("cmm.rest_api.model_invalid", e);
    }
}
 
Example #15
Source File: CustomModelsImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
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());
}
 
Example #16
Source File: CustomModelImportTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void testUploadModel_Invalid() throws Exception
{
    long timestamp = System.currentTimeMillis();
    final String modelName = getClass().getSimpleName() + timestamp;
    final String prefix = "prefix" + timestamp;
    final String uri = "uriNamespace" + timestamp;

    M2Model model = M2Model.createModel(prefix + QName.NAMESPACE_PREFIX + modelName);
    model.setAuthor("Admin");
    model.setDescription("Desc");

    ByteArrayOutputStream xml = new ByteArrayOutputStream();
    model.toXML(xml);
    ZipEntryContext context = new ZipEntryContext(modelName + ".xml", xml.toByteArray());
    File zipFile = createZip(context);

    PostRequest postRequest = buildMultipartPostRequest(zipFile);
    sendRequest(postRequest, 409); // no namespace has been defined

    // Create two namespaces
    model.createNamespace(uri, prefix);
    model.createNamespace(uri + "anotherUri", prefix + "anotherPrefix");
    xml = new ByteArrayOutputStream();
    model.toXML(xml);
    context = new ZipEntryContext(modelName + ".xml", xml.toByteArray());
    zipFile = createZip(context);

    postRequest = buildMultipartPostRequest(zipFile);
    sendRequest(postRequest, 409); // custom model can only have one namespace
}
 
Example #17
Source File: SOLRAPIClientTest.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void testGetModel() throws AuthenticationException, IOException, JSONException
{
    AlfrescoModel alfModel = client.getModel(CORENAME,QName.createQName("http://www.alfresco.org/model/content/1.0", "contentmodel"));
    M2Model model = alfModel.getModel();
    assertNotNull(model);
    assertEquals("Returned model has incorrect name", "cm:contentmodel", model.getName());
    assertNotNull(alfModel.getChecksum());
}
 
Example #18
Source File: SOLRAPIClient.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
public AlfrescoModel getModel(String coreName, QName modelName) throws AuthenticationException, IOException
{
    // If the model is new to the SOLR side the prefix will be unknown so we can not generate prefixes for the request!
    // Always use the full QName with explicit URI
    StringBuilder url = new StringBuilder(GET_MODEL);

    URLCodec encoder = new URLCodec();
    // must send the long name as we may not have the prefix registered
    url.append("?modelQName=").append(encoder.encode(modelName.toString(), "UTF-8"));
    
    GetRequest req = new GetRequest(url.toString());

    Response response = null;
    try
    {
        response = repositoryHttpClient.sendRequest(req);
        if(response.getStatus() != HttpStatus.SC_OK)
        {
            throw new AlfrescoRuntimeException(coreName + " GetModel return status is " + response.getStatus());
        }

        return new AlfrescoModel(M2Model.createModel(response.getContentAsStream()),
                Long.valueOf(response.getHeader(CHECKSUM_HEADER)));
    }
    finally
    {
        if(response != null)
        {
            response.release();
        }
    }
}
 
Example #19
Source File: TemporaryModels.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private QName loadModel(final M2Model model) {
       if (logger.isDebugEnabled())
       {
           logger.debug("Loading model: "+model.getName());
       }
       
       final DictionaryDAO dictionaryDAO = getDictionaryDAO();
	QName modelQName = dictionaryDAO.putModel(model);
	loadedModels.add(modelQName);
	return modelQName;
}
 
Example #20
Source File: ComparePropertyValueEvaluatorTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void createTestModel()
{
    M2Model model = M2Model.createModel("test:comparepropertyvalueevaluatortest");
    model.createNamespace(TEST_TYPE_NAMESPACE, "test");
    model.createImport(NamespaceService.DICTIONARY_MODEL_1_0_URI, NamespaceService.DICTIONARY_MODEL_PREFIX);
    model.createImport(NamespaceService.SYSTEM_MODEL_1_0_URI, NamespaceService.SYSTEM_MODEL_PREFIX);
    model.createImport(NamespaceService.CONTENT_MODEL_1_0_URI, NamespaceService.CONTENT_MODEL_PREFIX);

    M2Type testType = model.createType("test:" + TEST_TYPE_QNAME.getLocalName());
    testType.setParentName("cm:" + ContentModel.TYPE_CONTENT.getLocalName());
    
    M2Property prop1 = testType.createProperty("test:" + PROP_TEXT.getLocalName());
    prop1.setMandatory(false);
    prop1.setType("d:" + DataTypeDefinition.TEXT.getLocalName());
    prop1.setMultiValued(false);
    
    M2Property prop2 = testType.createProperty("test:" + PROP_INT.getLocalName());
    prop2.setMandatory(false);
    prop2.setType("d:" + DataTypeDefinition.INT.getLocalName());
    prop2.setMultiValued(false);
    
    M2Property prop3 = testType.createProperty("test:" + PROP_DATETIME.getLocalName());
    prop3.setMandatory(false);
    prop3.setType("d:" + DataTypeDefinition.DATETIME.getLocalName());
    prop3.setMultiValued(false);
    
    M2Property prop4 = testType.createProperty("test:" + PROP_NODEREF.getLocalName());
    prop4.setMandatory(false);
    prop4.setType("d:" + DataTypeDefinition.NODE_REF.getLocalName());
    prop4.setMultiValued(false);

    M2Property prop5 = testType.createProperty("test:" + PROP_MULTI_VALUE.getLocalName());
    prop5.setMandatory(false);
    prop5.setType("d:" + DataTypeDefinition.TEXT.getLocalName());
    prop5.setMultiValued(true);

    dictionaryDAO.putModel(model);
}
 
Example #21
Source File: DBQueryTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void loadTestModel()
{
    ClassLoader cl = BaseNodeServiceTest.class.getClassLoader();
    InputStream modelStream = cl.getResourceAsStream("org/alfresco/repo/search/impl/MetadataQueryTest_model.xml");
    assertNotNull(modelStream);
    model = M2Model.createModel(modelStream);
    dictionaryDAO.registerListener(this);
    dictionaryDAO.reset();
    assertNotNull(dictionaryDAO.getClass(TEST_SUPER_CONTENT_TYPE));
}
 
Example #22
Source File: RuleServiceCoverageTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Create the categories used in the tests
 */
private void createTestCategories()
{
    // Create the test model
    M2Model model = M2Model.createModel("test:rulecategory");
    model.createNamespace(TEST_NAMESPACE, "test");
    model.createImport(NamespaceService.DICTIONARY_MODEL_1_0_URI, "d");
    model.createImport(NamespaceService.CONTENT_MODEL_1_0_URI, NamespaceService.CONTENT_MODEL_PREFIX);
    
    // Create the region category
    regionCategorisationQName = QName.createQName(TEST_NAMESPACE, "region");
    M2Aspect generalCategorisation = model.createAspect("test:" + regionCategorisationQName.getLocalName());
    generalCategorisation.setParentName("cm:" + ContentModel.ASPECT_CLASSIFIABLE.getLocalName());
    M2Property genCatProp = generalCategorisation.createProperty("test:region");
    genCatProp.setIndexed(true);
    genCatProp.setIndexedAtomically(true);
    genCatProp.setMandatory(true);
    genCatProp.setMultiValued(true);
    genCatProp.setStoredInIndex(true);
    genCatProp.setIndexTokenisationMode(IndexTokenisationMode.TRUE);
    genCatProp.setType("d:" + DataTypeDefinition.CATEGORY.getLocalName());        

    // Save the mode
    dictionaryDAO.putModel(model);
    
    // Create the category value container and root
    catContainer = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(TEST_NAMESPACE, "categoryContainer"), ContentModel.TYPE_CONTAINER).getChildRef();
    catRoot = nodeService.createNode(catContainer, ContentModel.ASSOC_CHILDREN, QName.createQName(TEST_NAMESPACE, "categoryRoot"), ContentModel.TYPE_CATEGORYROOT).getChildRef();

    // Create the category values
    catRBase = nodeService.createNode(catRoot, ContentModel.ASSOC_CATEGORIES, QName.createQName(TEST_NAMESPACE, "region"), ContentModel.TYPE_CATEGORY).getChildRef();
    catROne = nodeService.createNode(catRBase, ContentModel.ASSOC_SUBCATEGORIES, QName.createQName(TEST_NAMESPACE, "Europe"), ContentModel.TYPE_CATEGORY).getChildRef();
    catRTwo = nodeService.createNode(catRBase, ContentModel.ASSOC_SUBCATEGORIES, QName.createQName(TEST_NAMESPACE, "RestOfWorld"), ContentModel.TYPE_CATEGORY).getChildRef();
    catRThree = nodeService.createNode(catRTwo, ContentModel.ASSOC_SUBCATEGORIES, QName.createQName(TEST_NAMESPACE, "US"), ContentModel.TYPE_CATEGORY).getChildRef();
}
 
Example #23
Source File: RhinoScriptTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void setUp() throws Exception
{
    super.setUp();
    ctx = ApplicationContextHelper.getApplicationContext();
    transactionService = (TransactionService)ctx.getBean("transactionComponent");
    contentService = (ContentService)ctx.getBean("contentService");
    nodeService = (NodeService)ctx.getBean("nodeService");
    scriptService = (ScriptService)ctx.getBean("scriptService");
    serviceRegistry = (ServiceRegistry)ctx.getBean("ServiceRegistry");
    
    this.authenticationComponent = (AuthenticationComponent)ctx.getBean("authenticationComponent");
    this.authenticationComponent.setSystemUserAsCurrentUser();
    
    DictionaryDAO dictionaryDao = (DictionaryDAO)ctx.getBean("dictionaryDAO");
    
    // load the system model
    ClassLoader cl = BaseNodeServiceTest.class.getClassLoader();
    InputStream modelStream = cl.getResourceAsStream("alfresco/model/contentModel.xml");
    assertNotNull(modelStream);
    M2Model model = M2Model.createModel(modelStream);
    dictionaryDao.putModel(model);
    
    // load the test model
    modelStream = cl.getResourceAsStream("org/alfresco/repo/node/BaseNodeServiceTest_model.xml");
    assertNotNull(modelStream);
    model = M2Model.createModel(modelStream);
    dictionaryDao.putModel(model);
    
    DictionaryComponent dictionary = new DictionaryComponent();
    dictionary.setDictionaryDAO(dictionaryDao);
    BaseNodeServiceTest.loadModel(ctx);
}
 
Example #24
Source File: ConcurrentNodeServiceSearchTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void setUp() throws Exception
{
    ctx = ApplicationContextHelper.getApplicationContext();
    DictionaryDAO dictionaryDao = (DictionaryDAO) ctx.getBean("dictionaryDAO");
    // load the system model
    ClassLoader cl = BaseNodeServiceTest.class.getClassLoader();
    InputStream modelStream = cl.getResourceAsStream("alfresco/model/systemModel.xml");
    assertNotNull(modelStream);
    M2Model model = M2Model.createModel(modelStream);
    dictionaryDao.putModel(model);
    // load the test model
    modelStream = cl.getResourceAsStream("org/alfresco/repo/node/BaseNodeServiceTest_model.xml");
    assertNotNull(modelStream);
    model = M2Model.createModel(modelStream);
    dictionaryDao.putModel(model);

    nodeService = (NodeService) ctx.getBean("dbNodeService");
    transactionService = (TransactionService) ctx.getBean("transactionComponent");
    this.authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");

    this.authenticationComponent.setSystemUserAsCurrentUser();

    // create a first store directly
    UserTransaction tx = transactionService.getUserTransaction();
    tx.begin();
    StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
    rootNodeRef = nodeService.getRootNode(storeRef);
    tx.commit();
}
 
Example #25
Source File: ConcurrentNodeServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void setUp() throws Exception
{
    ctx = ApplicationContextHelper.getApplicationContext();
    DictionaryDAO dictionaryDao = (DictionaryDAO) ctx.getBean("dictionaryDAO");
    // load the system model
    ClassLoader cl = BaseNodeServiceTest.class.getClassLoader();
    InputStream modelStream = cl.getResourceAsStream("alfresco/model/systemModel.xml");
    assertNotNull(modelStream);
    M2Model model = M2Model.createModel(modelStream);
    dictionaryDao.putModel(model);
    // load the test model
    modelStream = cl.getResourceAsStream("org/alfresco/repo/node/BaseNodeServiceTest_model.xml");
    assertNotNull(modelStream);
    model = M2Model.createModel(modelStream);
    dictionaryDao.putModel(model);

    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    nodeService = serviceRegistry.getNodeService();
    nodeDAO = (NodeDAO) ctx.getBean("nodeDAO");
    transactionService = serviceRegistry.getTransactionService();
    authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");

    this.authenticationComponent.setSystemUserAsCurrentUser();

    // create a first store directly
    RetryingTransactionCallback<Object> createRootNodeCallback =  new RetryingTransactionCallback<Object>()
    {
        public Object execute() throws Exception
        {
            StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_"
                    + System.currentTimeMillis());
            rootNodeRef = nodeService.getRootNode(storeRef);
            return null;
        }
    };
    transactionService.getRetryingTransactionHelper().doInTransaction(createRootNodeCallback);
}
 
Example #26
Source File: DbNodeServiceImplPropagationTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Before
public void before() throws Exception
{
    txnService = (TransactionService) applicationContext.getBean("transactionComponent");
    nodeDAO = (NodeDAO) applicationContext.getBean("nodeDAO");
    dialect = (Dialect) applicationContext.getBean("dialect");
    nodeService = (NodeService) applicationContext.getBean("dbNodeService");
    
    authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent");
    
    authenticationComponent.setSystemUserAsCurrentUser();
    
    DictionaryDAO dictionaryDao = (DictionaryDAO) applicationContext.getBean("dictionaryDAO");
    // load the system model
    ClassLoader cl = BaseNodeServiceTest.class.getClassLoader();
    InputStream modelStream = cl.getResourceAsStream("alfresco/model/contentModel.xml");
    assertNotNull(modelStream);
    M2Model model = M2Model.createModel(modelStream);
    dictionaryDao.putModel(model);
    // load the test model
    modelStream = cl.getResourceAsStream("org/alfresco/repo/node/BaseNodeServiceTest_model.xml");
    assertNotNull(modelStream);
    model = M2Model.createModel(modelStream);
    dictionaryDao.putModel(model);
    
    DictionaryComponent dictionary = new DictionaryComponent();
    dictionary.setDictionaryDAO(dictionaryDao);
    dictionaryService = loadModel(applicationContext);
    
    restartAuditableTxn();
}
 
Example #27
Source File: PerformanceNodeServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception
{
    applicationContext = ApplicationContextHelper.getApplicationContext();
    DictionaryDAO dictionaryDao = (DictionaryDAO) applicationContext.getBean("dictionaryDAO");
    
    // load the system model
    ClassLoader cl = PerformanceNodeServiceTest.class.getClassLoader();
    InputStream modelStream = cl.getResourceAsStream("alfresco/model/contentModel.xml");
    assertNotNull(modelStream);
    M2Model model = M2Model.createModel(modelStream);
    dictionaryDao.putModel(model);
    
    // load the test model
    modelStream = cl.getResourceAsStream("org/alfresco/repo/node/BaseNodeServiceTest_model.xml");
    assertNotNull(modelStream);
    model = M2Model.createModel(modelStream);
    dictionaryDao.putModel(model);
    
    DictionaryComponent dictionary = new DictionaryComponent();
    dictionary.setDictionaryDAO(dictionaryDao);
    dictionaryService = loadModel(applicationContext);
    
    nodeService = (NodeService) applicationContext.getBean("nodeService");
    txnService = (TransactionService) applicationContext.getBean("transactionComponent");
    contentService = (ContentService) applicationContext.getBean("contentService");
    
    // create a first store directly
    RetryingTransactionCallback<NodeRef> createStoreWork = new RetryingTransactionCallback<NodeRef>()
    {
        public NodeRef execute()
        {
            StoreRef storeRef = nodeService.createStore(
                    StoreRef.PROTOCOL_WORKSPACE,
                    "Test_" + System.nanoTime());
            return nodeService.getRootNode(storeRef);
        }
    };
    rootNodeRef = txnService.getRetryingTransactionHelper().doInTransaction(createStoreWork);
}
 
Example #28
Source File: TemporaryModels.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public QName loadModel(InputStream modelStream) 
{
    try
    {
        final M2Model model = M2Model.createModel(modelStream);
        
        return loadModel(model);
    }
    catch(DictionaryException e)
    {
        throw new DictionaryException("Could not import model", e);
    }
	
}
 
Example #29
Source File: CustomModelUploadPost.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected ImportResult processUpload(ZipFile zipFile, String filename) throws IOException
{
    if (zipFile.size() > 2)
    {
        throw new WebScriptException(Status.STATUS_BAD_REQUEST, "cmm.rest_api.model.import_invalid_zip_package");
    }

    CustomModel customModel = null;
    String shareExtModule = null;
    Enumeration<? extends ZipEntry> entries = zipFile.entries();
    while (entries.hasMoreElements())
    {
        ZipEntry entry = entries.nextElement();

        if (!entry.isDirectory())
        {
            final String entryName = entry.getName();
            try (InputStream input = new BufferedInputStream(zipFile.getInputStream(entry), BUFFER_SIZE))
            {
                if (!(entryName.endsWith(CustomModelServiceImpl.SHARE_EXT_MODULE_SUFFIX)) && customModel == null)
                {
                    try
                    {
                        M2Model m2Model = M2Model.createModel(input);
                        customModel = importModel(m2Model);
                    }
                    catch (DictionaryException ex)
                    {
                        if (shareExtModule == null)
                        {
                            // Get the input stream again, as the zip file doesn't support reset.
                            try (InputStream moduleInputStream = new BufferedInputStream(zipFile.getInputStream(entry), BUFFER_SIZE))
                            {
                                shareExtModule = getExtensionModule(moduleInputStream, entryName);
                            }

                            if (shareExtModule == null)
                            {
                                throw new WebScriptException(Status.STATUS_BAD_REQUEST, "cmm.rest_api.model.import_invalid_zip_entry_format", new Object[] { entryName });
                            }
                        }
                        else
                        {
                            throw new WebScriptException(Status.STATUS_BAD_REQUEST, "cmm.rest_api.model.import_invalid_model_entry", new Object[] { entryName });
                        }
                    }
                }
                else
                {
                    shareExtModule = getExtensionModule(input, entryName);
                    if (shareExtModule == null)
                    {
                        throw new WebScriptException(Status.STATUS_BAD_REQUEST, "cmm.rest_api.model.import_invalid_ext_module_entry", new Object[] { entryName });
                    }
                }
            }
        }
    }

    return new ImportResult(customModel, shareExtModule);
}
 
Example #30
Source File: CustomModelImportTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void testInvalidNumberOfZipEntries() throws Exception
{
    long timestamp = System.currentTimeMillis();
    String modelName = getClass().getSimpleName() + timestamp;
    String prefix = "prefix" + timestamp;
    String uri = "uriNamespace" + timestamp;

    // Model one
    M2Model modelOne = M2Model.createModel(prefix + QName.NAMESPACE_PREFIX + modelName);
    modelOne.createNamespace(uri, prefix);
    modelOne.setDescription("Model 1");
    ByteArrayOutputStream xml = new ByteArrayOutputStream();
    modelOne.toXML(xml);
    ZipEntryContext contextOne = new ZipEntryContext(modelName + ".xml", xml.toByteArray());

    // Model two
    modelName += "two";
    prefix += "two";
    uri += "two";
    M2Model modelTwo = M2Model.createModel(prefix + QName.NAMESPACE_PREFIX + modelName);
    modelTwo.createNamespace(uri, prefix);
    modelTwo.setDescription("Model 2");
    xml = new ByteArrayOutputStream();
    modelTwo.toXML(xml);
    ZipEntryContext contextTwo = new ZipEntryContext(modelName + ".xml", xml.toByteArray());

    // Model three
    modelName += "three";
    prefix += "three";
    uri += "three";
    M2Model modelThree = M2Model.createModel(prefix + QName.NAMESPACE_PREFIX + modelName);
    modelThree.createNamespace(uri, prefix);
    modelThree.setDescription("Model 3");
    xml = new ByteArrayOutputStream();
    modelThree.toXML(xml);
    ZipEntryContext contextThree = new ZipEntryContext(modelName + ".xml", xml.toByteArray());

    File zipFile = createZip(contextOne, contextTwo, contextThree);

    PostRequest postRequest = buildMultipartPostRequest(zipFile);
    sendRequest(postRequest, 400); // more than two zip entries
}