Search in sources :

Example 11 with TenantService

use of org.alfresco.repo.tenant.TenantService in project alfresco-repository by Alfresco.

the class DictionaryLoadDAOTest method setUp.

@Before
public void setUp() throws Exception {
    // register resource bundles for messages
    I18NUtil.registerResourceBundle(TEST_RESOURCE_MESSAGES);
    // Instantiate Dictionary Service
    TenantService tenantService = new MultiTServiceImpl();
    this.dictionaryDAO = new DictionaryDAOImpl();
    dictionaryDAO.setTenantService(tenantService);
    // TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>()
    // {
    // @Override
    // public Void doWork() throws Exception
    // {
    // dictionaryDAO.init();
    // return null;
    // }
    // }, "user1", "tenant1");
    initDictionaryCaches(dictionaryDAO, tenantService);
    new AuthenticationUtil().afterPropertiesSet();
    // Populate with appropriate models
    DictionaryBootstrap bootstrap = new DictionaryBootstrap();
    List<String> bootstrapModels = new ArrayList<String>();
    bootstrapModels.add("alfresco/model/dictionaryModel.xml");
    bootstrapModels.add("alfresco/model/systemModel.xml");
    bootstrapModels.add("alfresco/model/contentModel.xml");
    bootstrapModels.add("org/alfresco/repo/security/authentication/userModel.xml");
    bootstrapModels.add("alfresco/model/bpmModel.xml");
    bootstrapModels.add("alfresco/model/wcmModel.xml");
    bootstrapModels.add("alfresco/model/forumModel.xml");
    bootstrapModels.add("alfresco/model/imapModel.xml");
    bootstrapModels.add("alfresco/model/transferModel.xml");
    bootstrapModels.add("alfresco/model/applicationModel.xml");
    bootstrapModels.add("alfresco/model/wcmAppModel.xml");
    bootstrapModels.add("org/alfresco/repo/action/actionModel.xml");
    bootstrapModels.add("org/alfresco/repo/rule/ruleModel.xml");
    bootstrapModels.add("org/alfresco/repo/version/version_model.xml");
    bootstrapModels.add("org/alfresco/repo/version/version2_model.xml");
    bootstrapModels.add("alfresco/model/emailServerModel.xml");
    bootstrapModels.add("alfresco/model/calendarModel.xml");
    bootstrapModels.add("alfresco/model/deprecated/blogIntegrationModel.xml");
    bootstrapModels.add("alfresco/model/linksModel.xml");
    bootstrapModels.add("alfresco/model/remoteCredentialsModel.xml");
    bootstrapModels.add("alfresco/model/datalistModel.xml");
    bootstrapModels.add("alfresco/model/quickShareModel.xml");
    bootstrapModels.add("alfresco/model/surfModel.xml");
    bootstrapModels.add("alfresco/model/siteModel.xml");
    List<String> labels = new ArrayList<String>();
    bootstrap.setModels(bootstrapModels);
    bootstrap.setLabels(labels);
    bootstrap.setDictionaryDAO(dictionaryDAO);
    bootstrap.setTenantService(tenantService);
    bootstrap.bootstrap();
}
Also used : TenantService(org.alfresco.repo.tenant.TenantService) MultiTServiceImpl(org.alfresco.repo.tenant.MultiTServiceImpl) AuthenticationUtil(org.alfresco.repo.security.authentication.AuthenticationUtil) ArrayList(java.util.ArrayList) Before(org.junit.Before)

Example 12 with TenantService

use of org.alfresco.repo.tenant.TenantService in project alfresco-repository by Alfresco.

the class RepoDictionaryDAOTest method testADB159.

public void testADB159() throws Exception {
    // source dictionary
    TenantService tenantService = new SingleTServiceImpl();
    DictionaryDAOImpl dictionaryDAO = new DictionaryDAOImpl();
    dictionaryDAO.setTenantService(tenantService);
    initDictionaryCaches(dictionaryDAO, tenantService);
    // destination dictionary
    DictionaryDAOImpl dictionaryDAO2 = new DictionaryDAOImpl();
    dictionaryDAO2.setTenantService(tenantService);
    initDictionaryCaches(dictionaryDAO2, tenantService);
    List<String> models = new ArrayList<String>();
    models.add("alfresco/model/dictionaryModel.xml");
    models.add("alfresco/model/systemModel.xml");
    models.add("alfresco/model/contentModel.xml");
    models.add("alfresco/model/applicationModel.xml");
    models.add("org/alfresco/repo/security/authentication/userModel.xml");
    models.add("org/alfresco/repo/action/actionModel.xml");
    models.add("org/alfresco/repo/rule/ruleModel.xml");
    models.add("org/alfresco/repo/version/version_model.xml");
    // round-trip default models
    for (String bootstrapModel : models) {
        InputStream modelStream = getClass().getClassLoader().getResourceAsStream(bootstrapModel);
        if (modelStream == null) {
            throw new DictionaryException("Could not find bootstrap model " + bootstrapModel);
        }
        try {
            // parse model from xml
            M2Model model = M2Model.createModel(modelStream);
            dictionaryDAO.putModel(model);
            // regenerate xml from model
            ByteArrayOutputStream xml1 = new ByteArrayOutputStream();
            model.toXML(xml1);
            // register regenerated xml with other dictionary
            M2Model model2 = M2Model.createModel(new ByteArrayInputStream(xml1.toByteArray()));
            dictionaryDAO2.putModel(model2);
        } catch (DictionaryException e) {
            throw new DictionaryException("Could not import bootstrap model " + bootstrapModel, e);
        }
    }
    // specific test case
    M2Model model = M2Model.createModel("test:adb25");
    model.createNamespace(TEST_URL, "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:adb25");
    testType.setParentName("cm:" + ContentModel.TYPE_CONTENT.getLocalName());
    M2Property prop1 = testType.createProperty("test:prop1");
    prop1.setMandatory(false);
    prop1.setType("d:" + DataTypeDefinition.TEXT.getLocalName());
    prop1.setMultiValued(false);
    ByteArrayOutputStream xml1 = new ByteArrayOutputStream();
    model.toXML(xml1);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) SingleTServiceImpl(org.alfresco.repo.tenant.SingleTServiceImpl) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DictionaryException(org.alfresco.service.cmr.dictionary.DictionaryException) TenantService(org.alfresco.repo.tenant.TenantService) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 13 with TenantService

use of org.alfresco.repo.tenant.TenantService in project SearchServices by Alfresco.

the class SOLRAPIClientTest method setUp.

@Override
public void setUp() throws Exception {
    if (client == null) {
        TenantService tenantService = new SingleTServiceImpl();
        dictionaryDAO = new DictionaryDAOImpl();
        NamespaceDAO namespaceDAO = dictionaryDAO;
        dictionaryDAO.setTenantService(tenantService);
        CompiledModelsCache compiledModelsCache = new CompiledModelsCache();
        compiledModelsCache.setDictionaryDAO(dictionaryDAO);
        compiledModelsCache.setTenantService(tenantService);
        compiledModelsCache.setRegistry(new DefaultAsynchronouslyRefreshedCacheRegistry());
        TraceableThreadFactory threadFactory = new TraceableThreadFactory();
        threadFactory.setThreadDaemon(true);
        threadFactory.setThreadPriority(Thread.NORM_PRIORITY);
        ThreadPoolExecutor threadPoolExecutor = new DynamicallySizedThreadPoolExecutor(20, 20, 90, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), threadFactory, new ThreadPoolExecutor.CallerRunsPolicy());
        compiledModelsCache.setThreadPoolExecutor(threadPoolExecutor);
        dictionaryDAO.setDictionaryRegistryCache(compiledModelsCache);
        dictionaryDAO.setResourceClassLoader(getResourceClassLoader());
        dictionaryDAO.init();
        DictionaryComponent dictionaryComponent = new DictionaryComponent();
        dictionaryComponent.setDictionaryDAO(dictionaryDAO);
        dictionaryComponent.setMessageLookup(new StaticMessageLookup());
        // cmis dictionary
        CMISMapping cmisMapping = new CMISMapping();
        cmisMapping.setCmisVersion(CmisVersion.CMIS_1_0);
        DictionaryNamespaceComponent namespaceService = new DictionaryNamespaceComponent();
        namespaceService.setNamespaceDAO(namespaceDAO);
        cmisMapping.setNamespaceService(namespaceService);
        cmisMapping.setDictionaryService(dictionaryComponent);
        cmisMapping.afterPropertiesSet();
        cmisDictionaryService = new CMISStrictDictionaryService();
        cmisDictionaryService.setCmisMapping(cmisMapping);
        cmisDictionaryService.setDictionaryService(dictionaryComponent);
        cmisDictionaryService.setDictionaryDAO(dictionaryDAO);
        cmisDictionaryService.setSingletonCache(new MemoryCache<String, CMISDictionaryRegistry>());
        cmisDictionaryService.setTenantService(tenantService);
        cmisDictionaryService.init();
        RuntimePropertyLuceneBuilderMapping luceneBuilderMapping = new RuntimePropertyLuceneBuilderMapping();
        luceneBuilderMapping.setDictionaryService(dictionaryComponent);
        luceneBuilderMapping.setCmisDictionaryService(cmisDictionaryService);
        cmisDictionaryService.setPropertyLuceneBuilderMapping(luceneBuilderMapping);
        luceneBuilderMapping.afterPropertiesSet();
        // Load the key store from the classpath
        ClasspathKeyResourceLoader keyResourceLoader = new ClasspathKeyResourceLoader();
        client = new SOLRAPIClient(getRepoClient(keyResourceLoader), dictionaryComponent, dictionaryDAO);
        trackModels();
    }
}
Also used : NamespaceDAO(org.alfresco.repo.dictionary.NamespaceDAO) CMISMapping(org.alfresco.opencmis.mapping.CMISMapping) DictionaryDAOImpl(org.alfresco.repo.dictionary.DictionaryDAOImpl) RuntimePropertyLuceneBuilderMapping(org.alfresco.opencmis.mapping.RuntimePropertyLuceneBuilderMapping) DefaultAsynchronouslyRefreshedCacheRegistry(org.alfresco.util.cache.DefaultAsynchronouslyRefreshedCacheRegistry) SingleTServiceImpl(org.alfresco.repo.tenant.SingleTServiceImpl) CMISDictionaryRegistry(org.alfresco.opencmis.dictionary.CMISDictionaryRegistry) TraceableThreadFactory(org.alfresco.util.TraceableThreadFactory) CMISStrictDictionaryService(org.alfresco.opencmis.dictionary.CMISStrictDictionaryService) TenantService(org.alfresco.repo.tenant.TenantService) DynamicallySizedThreadPoolExecutor(org.alfresco.util.DynamicallySizedThreadPoolExecutor) DictionaryComponent(org.alfresco.repo.dictionary.DictionaryComponent) DictionaryNamespaceComponent(org.alfresco.repo.dictionary.DictionaryNamespaceComponent) StaticMessageLookup(org.alfresco.repo.i18n.StaticMessageLookup) CompiledModelsCache(org.alfresco.repo.dictionary.CompiledModelsCache) DynamicallySizedThreadPoolExecutor(org.alfresco.util.DynamicallySizedThreadPoolExecutor) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 14 with TenantService

use of org.alfresco.repo.tenant.TenantService in project alfresco-repository by Alfresco.

the class MTPolicyComponentTest method setUp.

@Override
protected void setUp() throws Exception {
    TenantService mockTenantService = mock(TenantService.class);
    when(mockTenantService.isEnabled()).thenReturn(true);
    when(mockTenantService.getCurrentUserDomain()).thenReturn("test.com");
    when(mockTenantService.getDomainUser(any(String.class), any(String.class))).thenReturn("System");
    when(mockTenantService.getBaseName(any(NodeRef.class))).thenReturn(new NodeRef(BASE_PROTOCOL, BASE_IDENTIFIER, BASE_ID));
    when(mockTenantService.getBaseName(any(StoreRef.class))).thenReturn(new StoreRef(BASE_PROTOCOL, BASE_IDENTIFIER));
    DictionaryDAOImpl dictionaryDAO = new DictionaryDAOImpl();
    dictionaryDAO.setTenantService(mockTenantService);
    initDictionaryCaches(dictionaryDAO, mockTenantService);
    DictionaryBootstrap bootstrap = new DictionaryBootstrap();
    List<String> bootstrapModels = new ArrayList<String>();
    bootstrapModels.add("alfresco/model/dictionaryModel.xml");
    bootstrapModels.add("alfresco/model/systemModel.xml");
    bootstrapModels.add("org/alfresco/repo/policy/policycomponenttest_model.xml");
    bootstrapModels.add(TEST_MODEL);
    bootstrap.setModels(bootstrapModels);
    bootstrap.setDictionaryDAO(dictionaryDAO);
    bootstrap.setTenantService(mockTenantService);
    bootstrap.bootstrap();
    DictionaryComponent dictionary = new DictionaryComponent();
    dictionary.setDictionaryDAO(dictionaryDAO);
    // Instantiate Policy Component
    PolicyComponentImpl x = new PolicyComponentImpl(dictionary);
    x.setTenantService(mockTenantService);
    policyComponent = x;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) StoreRef(org.alfresco.service.cmr.repository.StoreRef) TenantService(org.alfresco.repo.tenant.TenantService) DictionaryComponent(org.alfresco.repo.dictionary.DictionaryComponent) DictionaryDAOImpl(org.alfresco.repo.dictionary.DictionaryDAOImpl) DictionaryBootstrap(org.alfresco.repo.dictionary.DictionaryBootstrap) ArrayList(java.util.ArrayList)

Aggregations

TenantService (org.alfresco.repo.tenant.TenantService)14 ArrayList (java.util.ArrayList)9 SingleTServiceImpl (org.alfresco.repo.tenant.SingleTServiceImpl)7 DictionaryComponent (org.alfresco.repo.dictionary.DictionaryComponent)3 DictionaryDAOImpl (org.alfresco.repo.dictionary.DictionaryDAOImpl)3 StaticMessageLookup (org.alfresco.repo.i18n.StaticMessageLookup)3 DictionaryBootstrap (org.alfresco.repo.dictionary.DictionaryBootstrap)2 AuthenticationUtil (org.alfresco.repo.security.authentication.AuthenticationUtil)2 MultiTServiceImpl (org.alfresco.repo.tenant.MultiTServiceImpl)2 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 Before (org.junit.Before)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 CMISDictionaryRegistry (org.alfresco.opencmis.dictionary.CMISDictionaryRegistry)1 CMISStrictDictionaryService (org.alfresco.opencmis.dictionary.CMISStrictDictionaryService)1 CMISMapping (org.alfresco.opencmis.mapping.CMISMapping)1 RuntimePropertyLuceneBuilderMapping (org.alfresco.opencmis.mapping.RuntimePropertyLuceneBuilderMapping)1