Java Code Examples for org.alfresco.service.ServiceRegistry#getTransactionService()

The following examples show how to use org.alfresco.service.ServiceRegistry#getTransactionService() . 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: PeopleTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void setUp() throws Exception
{
    MockitoAnnotations.initMocks(this);

    ctx = ApplicationContextHelper.getApplicationContext();
    people = (People) ctx.getBean("peopleScript");
    serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
    transactionService = serviceRegistry.getTransactionService();
    personService = serviceRegistry.getPersonService();

    ServiceRegistry mockServiceRegistry = spy(serviceRegistry);
    people.setServiceRegistry(mockServiceRegistry);
    doReturn(mockSearchService).when(mockServiceRegistry).getSearchService();
    when(mockSearchService.query(any())).thenReturn(mockResultSet);
    when(mockResultSet.getNodeRefs()).thenReturn(mockResultSetNodeRefs);

    AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
    createUsers();

    // Start a transaction
    txn = transactionService.getUserTransaction();
    txn.begin();
}
 
Example 2
Source File: DifferrentMimeTypeTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Before
public void setUp() throws Exception
{
    ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
    serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    mimetypeService = serviceRegistry.getMimetypeService();
    transformerDebug = (TransformerDebug) ctx.getBean("transformerDebug");
    transformerConfig = (TransformerConfig) ctx.getBean("transformerConfig");
    registry = (ContentTransformerRegistry) ctx.getBean("contentTransformerRegistry");
    transactionService = serviceRegistry.getTransactionService();
    repositoryHelper = (Repository) ctx.getBean("repositoryHelper");
    nodeService = serviceRegistry.getNodeService();
    contentService = serviceRegistry.getContentService();
    
    assertNotNull("MimetypeMap not present", this.mimetypeService);
    assertNotNull("ServiceRegistry not present", serviceRegistry);
    assertNotNull("TransformerDebug not present", transformerDebug);
    assertNotNull("TransformerConfig not present", transformerConfig);
    assertNotNull("transactionService not present", transactionService);
    assertNotNull("repositoryHelper not present", repositoryHelper);
    assertNotNull("nodeService not present", nodeService);
    assertNotNull("contentService not present", contentService);
}
 
Example 3
Source File: CannedQueryDAOTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@BeforeClass public static void setup() throws Exception
{

    ServiceRegistry serviceRegistry = (ServiceRegistry) APP_CONTEXT_INIT.getApplicationContext().getBean(ServiceRegistry.SERVICE_REGISTRY);
    transactionService = serviceRegistry.getTransactionService();
    txnHelper = transactionService.getRetryingTransactionHelper();
    
    cannedQueryDAO = (CannedQueryDAO) APP_CONTEXT_INIT.getApplicationContext().getBean("cannedQueryDAO");
    cannedQueryDAOForTesting = (CannedQueryDAO) APP_CONTEXT_INIT.getApplicationContext().getBean("cannedQueryDAOForTesting");
    mimetypeDAO = (MimetypeDAO) APP_CONTEXT_INIT.getApplicationContext().getBean("mimetypeDAO");

    RetryingTransactionCallback<String> createMimetypeCallback = new RetryingTransactionCallback<String>()
    {
        @Override
        public String execute() throws Throwable
        {
            String mimetypePrefix = GUID.generate();
            mimetypeDAO.getOrCreateMimetype(mimetypePrefix + "-aaa");
            mimetypeDAO.getOrCreateMimetype(mimetypePrefix + "-bbb");
            return mimetypePrefix;
        }
    };
    mimetypePrefix = txnHelper.doInTransaction(createMimetypeCallback);
}
 
Example 4
Source File: GetMethodRegressionTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Before
public void setUp() throws Exception
{
    applicationContext = ApplicationContextHelper.getApplicationContext();
    ServiceRegistry registry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
    davHelper = (WebDAVHelper) applicationContext.getBean(WebDAVHelper.BEAN_NAME);
    auditRegistry = (AuditModelRegistryImpl) applicationContext.getBean(AUDIT_REGISTRY_BEAN_NAME);

    auditService = registry.getAuditService();
    fileFolderService = registry.getFileFolderService();
    transactionService = registry.getTransactionService();

    testingMethod = new GetMethod();
    mockResponse = new MockHttpServletResponse();

    restartTransaction(TransactionActionEnum.ACTION_NONE);
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());

    companyHomeNodeRef = registry.getNodeLocatorService().getNode(CompanyHomeNodeLocator.NAME, null, null);
    rootTestFolder = fileFolderService.create(companyHomeNodeRef, ROOT_TEST_FOLDER_NAME, ContentModel.TYPE_FOLDER).getNodeRef();
}
 
Example 5
Source File: JobLockServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void setUp() throws Exception
{
    ctx = ApplicationContextHelper.getApplicationContext();
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    transactionService = serviceRegistry.getTransactionService();
    txnHelper = transactionService.getRetryingTransactionHelper();
    
    jobLockService = (JobLockService) ctx.getBean("jobLockService");
    
    // Get the test name
    String testName = getName();
    // Build lock names for the test
    lockA = QName.createQName(NAMESPACE, "a-" + testName);
    lockAA = QName.createQName(NAMESPACE, "a-" + testName + ".a-" + testName);
    lockAAA = QName.createQName(NAMESPACE, "a-" + testName + ".a-" + testName + ".a-" + testName);
    lockAAB = QName.createQName(NAMESPACE, "a-" + testName + ".a-" + testName + ".b-" + testName);
    lockAAC = QName.createQName(NAMESPACE, "a-" + testName + ".a-" + testName + ".c-" + testName);
    lockAB = QName.createQName(NAMESPACE, "a-" + testName + ".b-" + testName);
    lockABA = QName.createQName(NAMESPACE, "a-" + testName + ".b-" + testName + ".a-" + testName);
    lockABB = QName.createQName(NAMESPACE, "a-" + testName + ".b-" + testName + ".b-" + testName);
    lockABC = QName.createQName(NAMESPACE, "a-" + testName + ".b-" + testName + ".c-" + testName);
}
 
Example 6
Source File: NodePropertyHelperTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void setUp()
{
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    DictionaryService dictionaryService = serviceRegistry.getDictionaryService();
    QNameDAO qnameDAO = (QNameDAO) ctx.getBean("qnameDAO");
    LocaleDAO localeDAO = (LocaleDAO) ctx.getBean("localeDAO");
    ContentDataDAO contentDataDAO = (ContentDataDAO) ctx.getBean("contentDataDAO");

    helper = new NodePropertyHelper(dictionaryService, qnameDAO, localeDAO, contentDataDAO);
    transactionService = serviceRegistry.getTransactionService();
    txnHelper = transactionService.getRetryingTransactionHelper();
    txnHelper.setMinRetryWaitMs(10);
    txnHelper.setRetryWaitIncrementMs(10);
    txnHelper.setMaxRetryWaitMs(50);
}
 
Example 7
Source File: SOLRTrackingComponentTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Before
public void before() throws Exception
{
    ServiceRegistry serviceRegistry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
    transactionService = serviceRegistry.getTransactionService();
    txnHelper = transactionService.getRetryingTransactionHelper();

    solrTrackingComponent = (SOLRTrackingComponent) applicationContext.getBean("solrTrackingComponent");
    nodeDAO = (NodeDAO)applicationContext.getBean("nodeDAO");
    qnameDAO = (QNameDAO) applicationContext.getBean("qnameDAO");
    dictionaryDAO =  (DictionaryDAO)applicationContext.getBean("dictionaryDAO");
    nodeService = (NodeService)applicationContext.getBean("NodeService");
    fileFolderService = (FileFolderService)applicationContext.getBean("FileFolderService");
    dictionaryService = serviceRegistry.getDictionaryService();
    namespaceService = serviceRegistry.getNamespaceService();
    authenticationComponent = (AuthenticationComponent)applicationContext.getBean("authenticationComponent");

    dbNodeService = (DbNodeServiceImpl)applicationContext.getBean("dbNodeService");
    dbNodeService.setEnableTimestampPropagation(false);

    authenticationComponent.setSystemUserAsCurrentUser();

    storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, getName() + System.currentTimeMillis());
    rootNodeRef = nodeService.getRootNode(storeRef);
}
 
Example 8
Source File: TransactionCleanupTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
  @Before
  public void before()
  {
  	ServiceRegistry serviceRegistry = (ServiceRegistry)ctx.getBean("ServiceRegistry");
      NamespaceService namespaceService = serviceRegistry.getNamespaceService();
this.transactionService = serviceRegistry.getTransactionService();
this.authenticationService = (MutableAuthenticationService)ctx.getBean("authenticationService");
this.nodeService = serviceRegistry.getNodeService();
this.searchService = serviceRegistry.getSearchService();
this.nodeDAO = (NodeDAO)ctx.getBean("nodeDAO");
this.nodesCache = (SimpleCache<Serializable, Serializable>) ctx.getBean("node.nodesSharedCache");
      this.worker = (DeletedNodeCleanupWorker)ctx.getBean("nodeCleanup.deletedNodeCleanup");
      this.worker.setMinPurgeAgeDays(0);

  	this.helper = transactionService.getRetryingTransactionHelper();
      authenticationService.authenticate("admin", "admin".toCharArray());
      
StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
NodeRef storeRoot = nodeService.getRootNode(storeRef);
List<NodeRef> nodeRefs = searchService.selectNodes(
        storeRoot, "/app:company_home", null, namespaceService, false);
final NodeRef companyHome = nodeRefs.get(0);

  	RetryingTransactionHelper.RetryingTransactionCallback<NodeRef> createNode = new RetryingTransactionHelper.RetryingTransactionCallback<NodeRef>()
  	{
	@Override
	public NodeRef execute() throws Throwable
	{
		return nodeService.createNode(companyHome, ContentModel.ASSOC_CONTAINS, QName.createQName("test", GUID.generate()), ContentModel.TYPE_CONTENT).getChildRef();
	}
  	};
  	this.nodeRef1 = helper.doInTransaction(createNode, false, true);
  	this.nodeRef2 = helper.doInTransaction(createNode, false, true);
  	this.nodeRef3 = helper.doInTransaction(createNode, false, true);
  	this.nodeRef4 = helper.doInTransaction(createNode, false, true);
  	this.nodeRef5 = helper.doInTransaction(createNode, false, true);
  }
 
Example 9
Source File: ScriptAction.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Construct
 * 
 * @param action
 *            Alfresco action
 */
public ScriptAction(ServiceRegistry services, Action action, ActionDefinition actionDef)
{
    this.services = services;
    this.actionService = services.getActionService();
    this.namespaceService = services.getNamespaceService();
    this.transactionService = services.getTransactionService();
    
    this.action = action;
    this.actionDef = actionDef;
    this.converter = new ActionValueConverter();
}
 
Example 10
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 11
Source File: AbstractJodConverterBasedTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
* This test relies upon customised OpenOffice.org subsystems being available.
* The OOoDirect subsystem (usually enabled by default) is disabled and the
* OOoJodconverter subsystem (usually disabled by default) is enabled.
* @throws Exception
*/
  @BeforeClass
  public static void initServicesAndRestartOOoSubsystems() throws Exception
  {
  	if (log.isDebugEnabled())
  	{
  		log.debug("initServicesAndRestartOOoSubsystems");
  	}
  	
  	repositoryHelper = (Repository) ctx.getBean("repositoryHelper");
      serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
      contentService = serviceRegistry.getContentService();
      nodeService = serviceRegistry.getNodeService();
      thumbnailService = serviceRegistry.getThumbnailService();
      transactionService = serviceRegistry.getTransactionService();
      
      AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
      
      oooJodcSubsystem = (ChildApplicationContextFactory) ctx.getBean("OOoJodconverter");

  	// Stop the OOoJodconverter subsystem and restart it with test settings i.e. enabled.
  	// Also a pool of 3 JodConverter instances, just for fun.
      if (log.isDebugEnabled())
      {
      	log.debug("Enabling OOoJodconverter");
      }
oooJodcSubsystem.stop();
oooJodcSubsystem.setProperty("jodconverter.enabled", "true");
oooJodcSubsystem.setProperty("jodconverter.portNumbers", "2022, 2023, 2024");
oooJodcSubsystem.start();
  }
 
Example 12
Source File: ComponentsTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception
{
    serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    authenticationComponent = (AuthenticationComponent) ctx.getBean("AuthenticationComponent");
    transactionService = serviceRegistry.getTransactionService();
    nodeService = serviceRegistry.getNodeService();
    
    // Run as system user
    authenticationComponent.setSystemUserAsCurrentUser();
    
    // Start a transaction
    txn = transactionService.getUserTransaction();
}
 
Example 13
Source File: SearcherComponentTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Before
public void setUp() throws Exception
{
    dialect = (Dialect) applicationContext.getBean("dialect");
    if (dialect instanceof PostgreSQLDialect)
    {
        // Note: PostgreSQL does not support \u0000 char embedded in a string
        // http://archives.postgresql.org/pgsql-jdbc/2007-02/msg00115.php
        COMPLEX_LOCAL_NAME = COMPLEX_LOCAL_NAME_NO_U0000;
    }

    serviceRegistry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
    transactionService = serviceRegistry.getTransactionService();
    dictionaryService = BaseNodeServiceTest.loadModel(applicationContext);
    nodeService = serviceRegistry.getNodeService();

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

    // get the indexer and searcher factory
    IndexerAndSearcher indexerAndSearcher = (IndexerAndSearcher) applicationContext.getBean("indexerAndSearcherFactory");
    searcher = new SearcherComponent();
    searcher.setIndexerAndSearcherFactory(indexerAndSearcher);
    // create a test workspace
    StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, getName()
            + "_" + System.currentTimeMillis());
    rootNodeRef = nodeService.getRootNode(storeRef);
    // begin a transaction
    txn = transactionService.getUserTransaction();
    txn.begin();
}
 
Example 14
Source File: MetadataEncryptorTests.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
    public void setUp() throws Exception
    {
        ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
        transactionService = serviceRegistry.getTransactionService();
//        txnHelper = transactionService.getRetryingTransactionHelper();
        metadataEncryptor = (MetadataEncryptor)ctx.getBean("metadataEncryptor");
        nodeService = serviceRegistry.getNodeService();
        tenantService = (TenantService)ctx.getBean("tenantService");
        dictionaryDAO = (DictionaryDAO)ctx.getBean("dictionaryDAO");

        AuthenticationUtil.setRunAsUserSystem();
        
        DictionaryBootstrap bootstrap = new DictionaryBootstrap();
        List<String> bootstrapModels = new ArrayList<String>();
        bootstrapModels.add("alfresco/model/dictionaryModel.xml");
        bootstrapModels.add(TEST_MODEL);
//        List<String> labels = new ArrayList<String>();
//        labels.add(TEST_BUNDLE);
        bootstrap.setModels(bootstrapModels);
//        bootstrap.setLabels(labels);
        bootstrap.setDictionaryDAO(dictionaryDAO);
        bootstrap.setTenantService(tenantService);
        bootstrap.bootstrap();
        
        // 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 = transactionService.getRetryingTransactionHelper().doInTransaction(createStoreWork);
    }
 
Example 15
Source File: DocumentLinkServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void setUp() throws Exception
{
    ctx = ApplicationContextHelper.getApplicationContext();
    // Set up the services
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
    transactionService = serviceRegistry.getTransactionService();
    documentLinkService = serviceRegistry.getDocumentLinkService();
    permissionService = serviceRegistry.getPermissionService();
    personService = serviceRegistry.getPersonService();
    siteService = serviceRegistry.getSiteService();
    fileFolderService = serviceRegistry.getFileFolderService();
    nodeService = serviceRegistry.getNodeService();
    cociService = serviceRegistry.getCheckOutCheckInService();

    // Start the transaction
    txn = transactionService.getUserTransaction();
    txn.begin();

    // Authenticate
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());

    /* Create the test user */
    Map<QName, Serializable> props = new HashMap<QName, Serializable>();
    props.put(ContentModel.PROP_USERNAME, TEST_USER);
    personService.createPerson(props);

    /*
     * Create the working test root 1 to which the user has read/write
     * permission
     */
    site1 = siteService.createSite("site1", GUID.generate(), "myTitle", "myDescription", SiteVisibility.PUBLIC).getNodeRef();
    permissionService.setPermission(site1, TEST_USER, PermissionService.ALL_PERMISSIONS, true);
    site1Folder1 = fileFolderService.create(site1, site1Folder1Name, ContentModel.TYPE_FOLDER).getNodeRef();
    site1File1 = fileFolderService.create(site1Folder1, site1File1Name, ContentModel.TYPE_CONTENT).getNodeRef();
    site1File2 = fileFolderService.create(site1Folder1, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef();
    site1Folder2 = fileFolderService.create(site1, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
    site1Folder3 = fileFolderService.create(site1, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
    // create a link of site1File1 in site1Folder3 to test regular deletion
     documentLinkService.createDocumentLink(site1File2, site1Folder3);

    /* Create the working test root 2 to which the user has no permission */
    NodeRef site2 = siteService.createSite("site2", GUID.generate(), "myTitle", "myDescription", SiteVisibility.PRIVATE).getNodeRef();
    permissionService.setPermission(site2, TEST_USER, PermissionService.ALL_PERMISSIONS, false);
    site2File = fileFolderService.create(site2, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef();
    site2Folder1 = fileFolderService.create(site2, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
    site2Folder2 = fileFolderService.create(site2, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
    // Create a link of site1File1 in site2Folder2 to test the deletion
    // without permission
    linkOfFile1Site2 = documentLinkService.createDocumentLink(site1File2, site2Folder2);
}
 
Example 16
Source File: FileFolderServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void setUp() throws Exception
{
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
    transactionService = serviceRegistry.getTransactionService();
    nodeService = serviceRegistry.getNodeService();
    fileFolderService = serviceRegistry.getFileFolderService();
    permissionService = serviceRegistry.getPermissionService();
    authenticationService = (MutableAuthenticationService) ctx.getBean("AuthenticationService");
    dictionaryDAO = (DictionaryDAO) ctx.getBean("dictionaryDAO");
    tenantService = (TenantService) ctx.getBean("tenantService");
    cociService = serviceRegistry.getCheckOutCheckInService();
    
    // start the transaction
    txn = transactionService.getUserTransaction();
    txn.begin();

    // downgrade integrity
    IntegrityChecker.setWarnInTransaction();

    // authenticate
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());

    // create a test store
    StoreRef storeRef = nodeService
            .createStore(StoreRef.PROTOCOL_WORKSPACE, getName() + System.currentTimeMillis());
    rootNodeRef = nodeService.getRootNode(storeRef);

    // create a folder to import into
    workingRootNodeRef = nodeService.createNode(
            rootNodeRef,
            ContentModel.ASSOC_CHILDREN,
            QName.createQName(NamespaceService.ALFRESCO_URI, "working root"),
            ContentModel.TYPE_FOLDER).getChildRef();

    // import the test data
    ImporterService importerService = serviceRegistry.getImporterService();
    Location importLocation = new Location(workingRootNodeRef);
    InputStream is = getClass().getClassLoader().getResourceAsStream(IMPORT_VIEW);
    if (is == null)
    {
        throw new NullPointerException("Test resource not found: " + IMPORT_VIEW);
    }
    Reader reader = new InputStreamReader(is);
    importerService.importView(reader, importLocation, null, null);

    // Load test model
    DictionaryBootstrap bootstrap = new DictionaryBootstrap();
    List<String> bootstrapModels = new ArrayList<String>();
    bootstrapModels.add("org/alfresco/repo/model/filefolder/testModel.xml");
    List<String> labels = new ArrayList<String>();
    bootstrap.setModels(bootstrapModels);
    bootstrap.setLabels(labels);
    bootstrap.setDictionaryDAO(dictionaryDAO);
    bootstrap.setTenantService(tenantService);
    bootstrap.bootstrap();
    
    workingRootNodeRef1 = nodeService.createNode(
            rootNodeRef,
            ContentModel.ASSOC_CHILDREN,
            QName.createQName(NamespaceService.ALFRESCO_URI, "working root1"),
            QName.createQName("http://www.alfresco.org/test/filefoldertest/1.0", "folder")).getChildRef();
    nodeService.createNode(
            workingRootNodeRef1,
            ContentModel.ASSOC_CONTAINS,
            QName.createQName(NamespaceService.ALFRESCO_URI, "node1"),
            ContentModel.TYPE_CONTENT).getChildRef();
    nodeService.createNode(
            workingRootNodeRef1,
            QName.createQName("http://www.alfresco.org/test/filefoldertest/1.0", "contains1"),
            QName.createQName(NamespaceService.ALFRESCO_URI, "node2"),
            ContentModel.TYPE_CONTENT).getChildRef();
    
    // Make sure we hit the MLTranslationInterceptor, which is part of the Foundation API
    // See MNT-9114: FileFolderService method not registered in MLTranslationInterceptor
    I18NUtil.setContentLocale(Locale.ENGLISH);
}
 
Example 17
Source File: VirtualizationIntegrationTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Before
public void setUp() throws Exception
{
    ctx = ApplicationContextHelper.getApplicationContext(CONFIG_LOCATIONS);;
    
    virtualizationConfigTestBootstrap = ctx.getBean(VIRTUALIZATION_CONFIG_TEST_BOOTSTRAP_BEAN_ID,
                                                    VirtualizationConfigTestBootstrap.class);

    // Get the required services
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");

    transactionService = serviceRegistry.getTransactionService();
    retryingTransactionHelper = serviceRegistry.getRetryingTransactionHelper();
    nodeService = serviceRegistry.getNodeService();
    contentService = serviceRegistry.getContentService();
    fileAndFolderService = serviceRegistry.getFileFolderService();
    permissionService = serviceRegistry.getPermissionService();

    authenticationComponent = ctx.getBean("authenticationComponent",
                                          AuthenticationComponent.class);

    environment = ctx.getBean("actualEnvironment",
                              ActualEnvironment.class);

    typeAndAspectsFormProcessor = ctx.getBean("typeAndAspectsFormProcessor",
                                              TypeAndAspectsFormProcessor.class);

    constraints = ctx.getBean("systemTemplateLocations",
                              SystemTemplateLocationsConstraint.class);

    Repository repository = ctx.getBean("repositoryHelper",
                                        Repository.class);

    if (!virtualizationConfigTestBootstrap.areVirtualFoldersEnabled())
    {
        // "use the force" and enable virtual folders
        SpringExtensionBundle vfBundle = ctx.getBean("smartFoldersBundle",
                                                     SpringExtensionBundle.class);
        vfBundle.start();
    }
    else
    {
        logger.info("Virtual folders are spring-enabled.");
    }

    this.authenticationComponent.setSystemUserAsCurrentUser();

    // start the transaction
    txn = transactionService.getUserTransaction();
    txn.begin();

    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    companyHomeNodeRef = repository.getCompanyHome();
    testRootFolder = fileAndFolderService.create(companyHomeNodeRef,
                                                 TEST_ROOT_FOLDER_NAME,
                                                 ContentModel.TYPE_FOLDER);

    virtualFolder1NodeRef = createVirtualizedFolder(testRootFolder.getNodeRef(),
                                                    VIRTUAL_FOLDER_1_NAME,
                                                    TEST_TEMPLATE_1_JSON_SYS_PATH);
    rootNodeRef = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
    setupMocks();
}
 
Example 18
Source File: IncompleteNodeTaggerTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setUp() throws Exception
{
    ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
    DictionaryDAO dictionaryDao = (DictionaryDAO) ctx.getBean("dictionaryDAO");
    ClassLoader cl = BaseNodeServiceTest.class.getClassLoader();
    // load the test model
    InputStream modelStream = cl.getResourceAsStream("org/alfresco/repo/node/integrity/IntegrityTest_model.xml");
    assertNotNull(modelStream);
    M2Model model = M2Model.createModel(modelStream);
    dictionaryDao.putModel(model);

    tagger = (IncompleteNodeTagger) ctx.getBean("incompleteNodeTagger");

    serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    nodeService = serviceRegistry.getNodeService();
    authenticationService = serviceRegistry.getAuthenticationService();
    permissionService = serviceRegistry.getPermissionService();
    this.authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    
    this.authenticationComponent.setSystemUserAsCurrentUser();
    
    String user = getName();
    if (!authenticationService.authenticationExists(user))
    {
        authenticationService.createAuthentication(user, user.toCharArray());
    }
    
    // begin a transaction
    TransactionService transactionService = serviceRegistry.getTransactionService();
    txn = transactionService.getUserTransaction();
    txn.begin();
    StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, getName());
    if (!nodeService.exists(storeRef))
    {
        nodeService.createStore(storeRef.getProtocol(), storeRef.getIdentifier());
        rootNodeRef = nodeService.getRootNode(storeRef);
        // Make sure our user can do everything
        permissionService.setPermission(rootNodeRef, user, PermissionService.ALL_PERMISSIONS, true);
    }
    else
    {
        rootNodeRef = nodeService.getRootNode(storeRef);
    }
    
    properties = new PropertyMap();
    properties.put(IntegrityTest.TEST_PROP_TEXT_C, "abc");
    
    // Authenticate as a test-specific user
    authenticationComponent.setCurrentUser(user);
}
 
Example 19
Source File: AuditComponentTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void setUp() throws Exception
{
    auditModelRegistry = (AuditModelRegistryImpl) ctx.getBean("auditModel.modelRegistry");
    //MNT-10807 : Auditing does not take into account audit.filter.alfresco-access.transaction.user
    UserAuditFilter userAuditFilter = new UserAuditFilter();
    userAuditFilter.setUserFilterPattern("~System;~null;.*");
    userAuditFilter.afterPropertiesSet();
    auditComponent = (AuditComponentImpl) ctx.getBean("auditComponent");
    auditComponent.setUserAuditFilter(userAuditFilter);
    serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    auditService = serviceRegistry.getAuditService();
    transactionService = serviceRegistry.getTransactionService();
    transactionServiceImpl = (TransactionServiceImpl) ctx.getBean("transactionService");
    nodeService = serviceRegistry.getNodeService();
    fileFolderService = serviceRegistry.getFileFolderService();
    
    // Register the test model
    URL testModelUrl = ResourceUtils.getURL("classpath:alfresco/testaudit/alfresco-audit-test.xml");
    auditModelRegistry.registerModel(testModelUrl);
    auditModelRegistry.loadAuditModels();
    
    RunAsWork<NodeRef> testRunAs = new RunAsWork<NodeRef>()
    {
        public NodeRef doWork() throws Exception
        {
            return nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
        }
    };
    nodeRef = AuthenticationUtil.runAs(testRunAs, AuthenticationUtil.getSystemUserName());

    // Authenticate
    user = "User-" + getName();
    AuthenticationUtil.setFullyAuthenticatedUser(user);

    final RetryingTransactionCallback<Void> resetDisabledPathsCallback = new RetryingTransactionCallback<Void>()
    {
        public Void execute() throws Throwable
        {
            auditComponent.resetDisabledPaths(APPLICATION_TEST);
            auditComponent.resetDisabledPaths(APPLICATION_ACTIONS_TEST);
            return null;
        }
    };
    transactionService.getRetryingTransactionHelper().doInTransaction(resetDisabledPathsCallback);
}
 
Example 20
Source File: AlfrescoTransactionSupportTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Before
public void setUp() throws Exception
{
    serviceRegistry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
    transactionService = serviceRegistry.getTransactionService();
}