Search in sources :

Example 6 with StoreRef

use of org.alfresco.service.cmr.repository.StoreRef in project alfresco-remote-api by Alfresco.

the class UnlockMethodTest method setUpPreconditionForCheckedOutTest.

/**
 * Set up preconditions for unlock a checked out node
 */
protected void setUpPreconditionForCheckedOutTest() throws Exception {
    appContext = ApplicationContextHelper.getApplicationContext(new String[] { "classpath:alfresco/application-context.xml", "classpath:alfresco/web-scripts-application-context.xml", "classpath:alfresco/remote-api-context.xml" });
    // Set the services
    this.cociService = (CheckOutCheckInService) appContext.getBean("checkOutCheckInService");
    this.contentService = (ContentService) appContext.getBean("contentService");
    this.authenticationService = (MutableAuthenticationService) appContext.getBean("authenticationService");
    this.permissionService = (PermissionService) appContext.getBean("permissionService");
    this.transactionService = (TransactionService) appContext.getBean("TransactionService");
    this.nodeService = (NodeService) appContext.getBean("NodeService");
    // Authenticate as system to create initial test data set
    this.authenticationComponent = (AuthenticationComponent) appContext.getBean("authenticationComponent");
    this.authenticationComponent.setSystemUserAsCurrentUser();
    RetryingTransactionCallback<Void> createTestFileCallback = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            // Create the store and get the root node reference
            storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, TEST_STORE_IDENTIFIER);
            if (!nodeService.exists(storeRef)) {
                storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, TEST_STORE_IDENTIFIER);
            }
            rootNodeRef = nodeService.getRootNode(storeRef);
            // Create and authenticate the user
            userName = "webdavUnlockTest" + GUID.generate();
            TestWithUserUtils.createUser(userName, PWD, rootNodeRef, nodeService, authenticationService);
            permissionService.setPermission(rootNodeRef, userName, PermissionService.ALL_PERMISSIONS, true);
            TestWithUserUtils.authenticateUser(userName, PWD, rootNodeRef, authenticationService);
            userNodeRef = TestWithUserUtils.getCurrentUser(authenticationService);
            // create test file in test folder
            folderNodeRef = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("test"), ContentModel.TYPE_FOLDER, Collections.<QName, Serializable>singletonMap(ContentModel.PROP_NAME, "folder")).getChildRef();
            fileNodeRef = nodeService.createNode(folderNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName("test"), ContentModel.TYPE_CONTENT, Collections.<QName, Serializable>singletonMap(ContentModel.PROP_NAME, TEST_FILE_NAME)).getChildRef();
            ContentWriter contentWriter = contentService.getWriter(fileNodeRef, ContentModel.PROP_CONTENT, true);
            contentWriter.setMimetype("text/plain");
            contentWriter.setEncoding("UTF-8");
            contentWriter.putContent(CONTENT_1);
            // Check out test file
            fileWorkingCopyNodeRef = cociService.checkout(fileNodeRef);
            assertNotNull(fileWorkingCopyNodeRef);
            assertEquals(userNodeRef, nodeService.getProperty(fileNodeRef, ContentModel.PROP_LOCK_OWNER));
            return null;
        }
    };
    this.transactionService.getRetryingTransactionHelper().doInTransaction(createTestFileCallback);
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)

Example 7 with StoreRef

use of org.alfresco.service.cmr.repository.StoreRef in project alfresco-remote-api by Alfresco.

the class WebDAVHelperIntegrationTest method setUp.

@Before
public void setUp() {
    AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
    webDAVHelper = (WebDAVHelper) ctx.getBean("webDAVHelper");
    fileFolderService = (FileFolderService) ctx.getBean("FileFolderService");
    nodeService = (NodeService) ctx.getBean("NodeService");
    StoreRef storeRef = nodeService.createStore("workspace", "WebDAVHelperTest-" + UUID.randomUUID());
    rootNodeRef = nodeService.getRootNode(storeRef);
    rootFolder = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, ContentModel.ASSOC_CHILDREN, ContentModel.TYPE_FOLDER).getChildRef();
// eventPublisher = (EventPublisherForTestingOnly) ctx.getBean("eventPublisher");
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) Before(org.junit.Before)

Example 8 with StoreRef

use of org.alfresco.service.cmr.repository.StoreRef in project alfresco-remote-api by Alfresco.

the class WebDAVMethodTest method checkLockedNodeTestWork.

private void checkLockedNodeTestWork() throws WebDAVServerException {
    req = new MockHttpServletRequest();
    resp = new MockHttpServletResponse();
    String rootPath = "/app:company_home";
    String storeName = "workspace://SpacesStore";
    StoreRef storeRef = new StoreRef(storeName);
    NodeRef storeRootNodeRef = nodeService.getRootNode(storeRef);
    List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, rootPath, null, namespaceService, false);
    NodeRef defaultRootNode = nodeRefs.get(0);
    lockMethod = new LockMethod();
    NodeRef rootNodeRef = tenantService.getRootNode(nodeService, searchService, namespaceService, rootPath, defaultRootNode);
    String strPath = "/" + "testLockedNode" + GUID.generate();
    lockMethod.createExclusive = true;
    lockMethod.setDetails(req, resp, webDAVHelper, rootNodeRef);
    lockMethod.m_strPath = strPath;
    // Lock the node (will create a new one).
    transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Object>() {

        @Override
        public Object execute() throws Throwable {
            lockMethod.executeImpl();
            return null;
        }
    });
    // Prepare for PUT
    req.addHeader(WebDAV.HEADER_IF, "(<" + lockMethod.lockToken + ">)");
    putMethod = new PutMethod();
    putMethod.setDetails(req, resp, webDAVHelper, rootNodeRef);
    putMethod.parseRequestHeaders();
    putMethod.m_strPath = strPath;
    String content = "test content stream";
    req.setContent(content.getBytes());
    // Issue a put request
    transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Object>() {

        @Override
        public Object execute() throws Throwable {
            putMethod.executeImpl();
            return null;
        }
    });
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) NodeRef(org.alfresco.service.cmr.repository.NodeRef) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 9 with StoreRef

use of org.alfresco.service.cmr.repository.StoreRef in project alfresco-remote-api by Alfresco.

the class WebDAVMethodTest method expiryLockTest.

/* MNT-10555 Test */
@Test
public void expiryLockTest() {
    // ACE-4347 extra debug logging just for this test so we can see what's going on when it next fails
    Level repoWebdavSaveLogLevel = Logger.getLogger("org.alfresco.repo.webdav").getLevel();
    Logger.getLogger("org.alfresco.repo.webdav").setLevel(Level.ALL);
    Level webdavProtocolSaveLogLevel = Logger.getLogger("org.alfresco.webdav.protocol").getLevel();
    Logger.getLogger("org.alfresco.webdav.protocol").setLevel(Level.ALL);
    try {
        setUpApplicationContext();
        req = new MockHttpServletRequest();
        resp = new MockHttpServletResponse();
        String rootPath = "/app:company_home";
        StoreRef storeRef = new StoreRef("workspace://SpacesStore");
        NodeRef storeRootNodeRef = nodeService.getRootNode(storeRef);
        List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, rootPath, null, namespaceService, false);
        NodeRef defaultRootNode = nodeRefs.get(0);
        NodeRef rootNodeRef = tenantService.getRootNode(nodeService, searchService, namespaceService, rootPath, defaultRootNode);
        // Create test folder.
        NodeRef folderNodeRef = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName("test"), ContentModel.TYPE_FOLDER, Collections.<QName, Serializable>singletonMap(ContentModel.PROP_NAME, "WebDavMethodExpiryLockTest" + System.currentTimeMillis())).getChildRef();
        // Create test document.
        NodeRef nodeRef = nodeService.createNode(folderNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName("test"), ContentModel.TYPE_CONTENT, Collections.<QName, Serializable>singletonMap(ContentModel.PROP_NAME, "text.txt")).getChildRef();
        lockMethod = new LockMethod();
        lockMethod.createExclusive = true;
        lockMethod.m_timeoutDuration = 1;
        lockMethod.setDetails(req, resp, webDAVHelper, nodeRef);
        transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Object>() {

            @Override
            public Object execute() throws Throwable {
                try {
                    // LOCK document.
                    lockMethod.executeImpl();
                    // wait for the lock to expire up to 5 seconds
                    int timeout = 5;
                    while (timeout > 0 && !lockMethod.lockInfo.isExpired()) {
                        Thread.sleep(1000);
                        timeout--;
                    }
                    // LOCK against an expired lock.
                    lockMethod.executeImpl();
                } catch (WebDAVServerException e) {
                    logger.debug(e);
                    Assert.fail("Document was not locked again, when lock has expired.");
                }
                return null;
            }
        });
        // Remove test folder.
        nodeService.deleteNode(folderNodeRef);
    } finally {
        Logger.getLogger("org.alfresco.webdav.protocol").setLevel(webdavProtocolSaveLogLevel);
        Logger.getLogger("org.alfresco.repo.webdav").setLevel(repoWebdavSaveLogLevel);
    }
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) Serializable(java.io.Serializable) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) QName(org.alfresco.service.namespace.QName) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Level(org.apache.log4j.Level) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 10 with StoreRef

use of org.alfresco.service.cmr.repository.StoreRef in project alfresco-remote-api by Alfresco.

the class RuleServiceTest method createTestFolders.

private void createTestFolders() {
    StoreRef testStore = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, TEST_STORE_IDENTIFIER);
    if (!nodeService.exists(testStore)) {
        testStore = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, TEST_STORE_IDENTIFIER);
    }
    NodeRef rootNodeRef = nodeService.getRootNode(testStore);
    testWorkNodeRef = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}testnode"), ContentModel.TYPE_FOLDER).getChildRef();
    testNodeRef = fileFolderService.create(testWorkNodeRef, TEST_FOLDER, ContentModel.TYPE_FOLDER).getNodeRef();
    testNodeRef2 = fileFolderService.create(testWorkNodeRef, TEST_FOLDER_2, ContentModel.TYPE_FOLDER).getNodeRef();
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef)

Aggregations

StoreRef (org.alfresco.service.cmr.repository.StoreRef)67 NodeRef (org.alfresco.service.cmr.repository.NodeRef)50 HashMap (java.util.HashMap)18 QName (org.alfresco.service.namespace.QName)17 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)13 StringPropertyValue (org.alfresco.solr.client.StringPropertyValue)13 PropertyValue (org.alfresco.solr.client.PropertyValue)11 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)10 ArrayList (java.util.ArrayList)9 ContentPropertyValue (org.alfresco.solr.client.ContentPropertyValue)9 MLTextPropertyValue (org.alfresco.solr.client.MLTextPropertyValue)9 IOException (java.io.IOException)7 Date (java.util.Date)6 MultiPropertyValue (org.alfresco.solr.client.MultiPropertyValue)6 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)5 PermissionService (org.alfresco.service.cmr.security.PermissionService)5 SolrCore (org.apache.solr.core.SolrCore)5 StringTokenizer (java.util.StringTokenizer)4 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)4 ServiceRegistry (org.alfresco.service.ServiceRegistry)4