Search in sources :

Example 61 with NodeRef

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

the class AbstractWorkflowRestApiTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    ApplicationContext appContext = getServer().getApplicationContext();
    namespaceService = (NamespaceService) appContext.getBean("NamespaceService");
    workflowService = (WorkflowService) appContext.getBean("WorkflowService");
    MutableAuthenticationService authenticationService = (MutableAuthenticationService) appContext.getBean("AuthenticationService");
    PersonService personService = (PersonService) appContext.getBean("PersonService");
    SearchService searchService = (SearchService) appContext.getBean("SearchService");
    FileFolderService fileFolderService = (FileFolderService) appContext.getBean("FileFolderService");
    nodeService = (NodeService) appContext.getBean("NodeService");
    // for the purposes of the tests make sure workflow engine is enabled/visible.
    WorkflowAdminServiceImpl workflowAdminService = (WorkflowAdminServiceImpl) appContext.getBean("workflowAdminService");
    this.wfTestHelper = new WorkflowTestHelper(workflowAdminService, getEngine(), true);
    AuthorityService authorityService = (AuthorityService) appContext.getBean("AuthorityService");
    personManager = new TestPersonManager(authenticationService, personService, nodeService);
    groupManager = new TestGroupManager(authorityService);
    authenticationComponent = (AuthenticationComponent) appContext.getBean("authenticationComponent");
    dictionaryService = (DictionaryService) appContext.getBean("dictionaryService");
    personManager.createPerson(USER1);
    personManager.createPerson(USER2);
    personManager.createPerson(USER3);
    authenticationComponent.setSystemUserAsCurrentUser();
    groupManager.addUserToGroup(GROUP, USER2);
    packageRef = workflowService.createPackage(null);
    NodeRef companyHome = searchService.selectNodes(nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE), COMPANY_HOME, null, namespaceService, false).get(0);
    contentNodeRef = fileFolderService.create(companyHome, TEST_CONTENT + System.currentTimeMillis(), ContentModel.TYPE_CONTENT).getNodeRef();
    authenticationComponent.clearCurrentSecurityContext();
}
Also used : TestPersonManager(org.alfresco.repo.security.person.TestPersonManager) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ApplicationContext(org.springframework.context.ApplicationContext) PersonService(org.alfresco.service.cmr.security.PersonService) SearchService(org.alfresco.service.cmr.search.SearchService) AuthorityService(org.alfresco.service.cmr.security.AuthorityService) WorkflowAdminServiceImpl(org.alfresco.repo.workflow.WorkflowAdminServiceImpl) FileFolderService(org.alfresco.service.cmr.model.FileFolderService) MutableAuthenticationService(org.alfresco.service.cmr.security.MutableAuthenticationService) WorkflowTestHelper(org.alfresco.repo.workflow.WorkflowTestHelper) TestGroupManager(org.alfresco.repo.security.person.TestGroupManager)

Example 62 with NodeRef

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

the class WorkflowModelBuilderTest method makeWorkflowInstance.

private WorkflowInstance makeWorkflowInstance(WorkflowTaskDefinition taskDefinition) {
    String id = "The id";
    boolean active = true;
    Date startDate = new Date();
    Date endDate = new Date();
    NodeRef initiator = person;
    WorkflowDefinition definition = new WorkflowDefinition("The Id", "The Name", "The Version", "The Title", "The Description", taskDefinition);
    return new WorkflowInstance(id, definition, "", initiator, workflowPackage, workflowPackage, active, startDate, endDate);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) WorkflowDefinition(org.alfresco.service.cmr.workflow.WorkflowDefinition) WorkflowInstance(org.alfresco.service.cmr.workflow.WorkflowInstance) Date(java.util.Date)

Example 63 with NodeRef

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

the class MoveMethodTest method canMoveFileUnlock.

@Test
public void canMoveFileUnlock() throws Exception {
    moveMethod = new MoveMethod() {

        @Override
        protected LockInfo checkNode(FileInfo fileInfo, boolean ignoreShared, boolean lockMethod) throws WebDAVServerException {
            LockInfoImpl lockInfo = new LockInfoImpl();
            lockInfo.setExclusiveLockToken("opaque-lock-token");
            lockInfo.setDepth(WebDAV.INFINITY);
            lockInfo.setScope(WebDAV.XML_EXCLUSIVE);
            return lockInfo;
        }

        @Override
        protected LockInfo checkNode(FileInfo fileInfo) throws WebDAVServerException {
            return checkNode(fileInfo, false, false);
        }
    };
    moveMethod.setDetails(req, resp, davHelper, rootNode);
    sourceFileInfo = Mockito.mock(FileInfo.class);
    when(sourceFileInfo.isFolder()).thenReturn(true);
    destPath = "/path/to/test.doc";
    moveMethod.m_strDestinationPath = destPath;
    sourcePath = "/path/from/test.doc";
    moveMethod.m_strPath = sourcePath;
    when(davHelper.getServiceRegistry()).thenReturn(mockServiceRegistry);
    when(mockServiceRegistry.getContentService()).thenReturn(mockContentService);
    List<String> sourcePathSplit = Arrays.asList("path", "from", "test.doc");
    when(davHelper.splitAllPaths(sourcePath)).thenReturn(sourcePathSplit);
    List<String> destPathSplit = Arrays.asList("path", "to", "dest.doc");
    when(davHelper.splitAllPaths(destPath)).thenReturn(destPathSplit);
    when(mockFileFolderService.resolveNamePath(rootNode, sourcePathSplit)).thenReturn(sourceFileInfo);
    FileInfo destFileInfo = Mockito.mock(FileInfo.class);
    when(mockFileFolderService.resolveNamePath(rootNode, destPathSplit)).thenReturn(destFileInfo);
    sourceParentNodeRef = new NodeRef("workspace://SpacesStore/parent1");
    destParentNodeRef = new NodeRef("workspace://SpacesStore/parent2");
    sourceNodeRef = new NodeRef("workspace://SpacesStore/sourcefile");
    moveMethod.moveOrCopy(sourceNodeRef, sourceParentNodeRef, destParentNodeRef, "test.doc");
    verify(mockFileFolderService).moveFrom(sourceNodeRef, sourceParentNodeRef, destParentNodeRef, "test.doc");
    verify(davLockService).unlock(sourceNodeRef);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) Test(org.junit.Test)

Example 64 with NodeRef

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

the class PutMethodTest method testPutContentToWorkingCopy.

/**
 * Putting a content to a working copy file
 * <p>
 * Create and check out a file by user1
 * <p>
 * Try to put the content to the working copy by user2
 *
 * See MNT-8614.
 */
@SuppressWarnings("deprecation")
@Test
public void testPutContentToWorkingCopy() throws Exception {
    FileInfo folder = fileFolderService.create(companyHomeNodeRef, "folder-" + GUID.generate(), ContentModel.TYPE_FOLDER);
    permissionService.setInheritParentPermissions(folder.getNodeRef(), false);
    permissionService.setPermission(folder.getNodeRef(), USER1_NAME, permissionService.getAllPermission(), true);
    AuthenticationUtil.setFullyAuthenticatedUser(USER1_NAME);
    FileInfo testFileInfo = fileFolderService.create(folder.getNodeRef(), "file-" + GUID.generate(), ContentModel.TYPE_CONTENT);
    NodeRef workingCopyNodeRef = checkOutCheckInService.checkout(testFileInfo.getNodeRef());
    String workingCopyName = fileFolderService.getFileInfo(workingCopyNodeRef).getName();
    String pathToWC = "/" + folder.getName() + "/" + workingCopyName;
    String pathToOriginal = "/" + folder.getName() + "/" + testFileInfo.getName();
    // Negative test, try to edit the WC without permissions.
    AuthenticationUtil.setFullyAuthenticatedUser(USER2_NAME);
    try {
        lockService.lock(workingCopyNodeRef, LockType.WRITE_LOCK);
    } catch (AccessDeniedException ade) {
    // expected
    }
    try {
        executeMethod(WebDAV.METHOD_LOCK, pathToWC, davLockInfoUser2File, null);
        fail("The LOCK execution should fail with a 401 error");
    } catch (WebDAVServerException wse) {
        // The execution failed and it is expected
        assertTrue("The status code was " + wse.getHttpStatusCode() + ", but should be " + HttpServletResponse.SC_UNAUTHORIZED, wse.getHttpStatusCode() == HttpServletResponse.SC_UNAUTHORIZED);
    } catch (Exception e) {
        fail("Unexpected exception occurred: " + (e.getCause() != null ? e.getCause().getMessage() : e.getMessage()));
    }
    // Construct IF HEADER
    String lockToken = workingCopyNodeRef.getId() + WebDAV.LOCK_TOKEN_SEPERATOR + USER2_NAME;
    String lockHeaderValue = "(<" + WebDAV.OPAQUE_LOCK_TOKEN + lockToken + ">)";
    HashMap<String, String> headers = new HashMap<String, String>();
    headers.put(WebDAV.HEADER_IF, lockHeaderValue);
    try {
        executeMethod(WebDAV.METHOD_PUT, pathToWC, testDataFile, headers);
        fail("The PUT execution should fail with a 423 error");
    } catch (WebDAVServerException wse) {
        // The execution failed and it is expected
        assertTrue("The status code was " + wse.getHttpStatusCode() + ", but should be " + HttpServletResponse.SC_UNAUTHORIZED, wse.getHttpStatusCode() == HttpServletResponse.SC_UNAUTHORIZED);
    } catch (Exception e) {
        fail("Unexpected exception occurred: " + (e.getCause() != null ? e.getCause().getMessage() : e.getMessage()));
    }
    // Positive test
    AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
    permissionService.setPermission(folder.getNodeRef(), USER2_NAME, permissionService.getAllPermission(), true);
    AuthenticationUtil.setFullyAuthenticatedUser(USER2_NAME);
    try {
        executeMethod(WebDAV.METHOD_LOCK, pathToWC, davLockInfoUser2File, null);
        assertEquals("File should be locked", LockStatus.LOCK_OWNER, lockService.getLockStatus(workingCopyNodeRef));
    } catch (Exception e) {
        fail("Failed to lock a file: " + (e.getCause() != null ? e.getCause().getMessage() : e.getMessage()));
    }
    headers = new HashMap<String, String>();
    headers.put(WebDAV.HEADER_IF, lockHeaderValue);
    try {
        executeMethod(WebDAV.METHOD_PUT, pathToWC, testDataFile, headers);
        assertTrue("File does not exist.", nodeService.exists(workingCopyNodeRef));
        assertEquals("Filename is not correct", workingCopyName, nodeService.getProperty(workingCopyNodeRef, ContentModel.PROP_NAME));
        assertTrue("Expected return status is " + HttpServletResponse.SC_NO_CONTENT + ", but returned is " + response.getStatus(), HttpServletResponse.SC_NO_CONTENT == response.getStatus());
        assertTrue("File should have NO_CONTENT aspect", nodeService.hasAspect(workingCopyNodeRef, ContentModel.ASPECT_NO_CONTENT));
        InputStream updatedFileIS = fileFolderService.getReader(workingCopyNodeRef).getContentInputStream();
        byte[] updatedFile = IOUtils.toByteArray(updatedFileIS);
        updatedFileIS.close();
        assertTrue("The content has to be equal", ArrayUtils.isEquals(testDataFile, updatedFile));
    } catch (Exception e) {
        fail("Failed to upload a file: " + (e.getCause() != null ? e.getCause().getMessage() : e.getMessage()));
    }
    headers = new HashMap<String, String>();
    headers.put(WebDAV.HEADER_LOCK_TOKEN, "<" + WebDAV.OPAQUE_LOCK_TOKEN + lockToken + ">");
    try {
        executeMethod(WebDAV.METHOD_UNLOCK, pathToWC, null, headers);
        assertTrue("Expected return status is " + HttpServletResponse.SC_NO_CONTENT + ", but returned is " + response.getStatus(), HttpServletResponse.SC_NO_CONTENT == response.getStatus());
        assertFalse("File should not have NO_CONTENT aspect", nodeService.hasAspect(workingCopyNodeRef, ContentModel.ASPECT_NO_CONTENT));
        assertEquals("File should be unlocked", LockStatus.NO_LOCK, lockService.getLockStatus(workingCopyNodeRef));
    } catch (Exception e) {
        fail("Failed to unlock a file: " + (e.getCause() != null ? e.getCause().getMessage() : e.getMessage()));
    }
    // Negative test try to lock or edit the original file
    AuthenticationUtil.setFullyAuthenticatedUser(USER2_NAME);
    try {
        lockService.lock(testFileInfo.getNodeRef(), LockType.WRITE_LOCK);
    } catch (UnableToAquireLockException uale) {
    // expected
    }
    try {
        executeMethod(WebDAV.METHOD_LOCK, pathToOriginal, davLockInfoUser2File, null);
        fail("The LOCK execution should fail with a 423 error");
    } catch (WebDAVServerException wse) {
        // The execution failed and it is expected
        assertTrue("The status code was " + wse.getHttpStatusCode() + ", but should be " + WebDAV.WEBDAV_SC_LOCKED, wse.getHttpStatusCode() == WebDAV.WEBDAV_SC_LOCKED);
    } catch (Exception e) {
        fail("Unexpected exception occurred: " + (e.getCause() != null ? e.getCause().getMessage() : e.getMessage()));
    }
    // Construct IF HEADER
    lockToken = testFileInfo.getNodeRef().getId() + WebDAV.LOCK_TOKEN_SEPERATOR + USER2_NAME;
    lockHeaderValue = "(<" + WebDAV.OPAQUE_LOCK_TOKEN + lockToken + ">)";
    headers = new HashMap<String, String>();
    headers.put(WebDAV.HEADER_IF, lockHeaderValue);
    try {
        executeMethod(WebDAV.METHOD_PUT, pathToOriginal, testDataFile, headers);
        fail("The PUT execution should fail with a 423 error");
    } catch (WebDAVServerException wse) {
        // The execution failed and it is expected
        assertTrue("The status code was " + wse.getHttpStatusCode() + ", but should be " + WebDAV.WEBDAV_SC_LOCKED, wse.getHttpStatusCode() == WebDAV.WEBDAV_SC_LOCKED);
    } catch (Exception e) {
        fail("Unexpected exception occurred: " + (e.getCause() != null ? e.getCause().getMessage() : e.getMessage()));
    }
    AuthenticationUtil.setFullyAuthenticatedUser(USER1_NAME);
    checkOutCheckInService.checkin(workingCopyNodeRef, null);
    AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
    nodeService.deleteNode(folder.getNodeRef());
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) FileInfo(org.alfresco.service.cmr.model.FileInfo) HashMap(java.util.HashMap) InputStream(java.io.InputStream) UnableToAquireLockException(org.alfresco.service.cmr.lock.UnableToAquireLockException) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) UnableToAquireLockException(org.alfresco.service.cmr.lock.UnableToAquireLockException) Test(org.junit.Test)

Example 65 with NodeRef

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

the class PutMethodTest method tearDown.

@After
public void tearDown() throws Exception {
    method = null;
    request = null;
    response = null;
    testDataFile = null;
    davLockInfoAdminFile = null;
    if (txn.getStatus() == Status.STATUS_MARKED_ROLLBACK) {
        txn.rollback();
    } else {
        txn.commit();
    }
    AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
    deleteUser(USER1_NAME);
    deleteUser(USER2_NAME);
    nodeService.deleteNode(versionableDoc);
    // As per MNT-10037 try to create a node and delete it in the next txn
    txn = transactionService.getUserTransaction();
    txn.begin();
    Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
    String nodeName = "leak-session-doc-" + GUID.generate();
    properties.put(ContentModel.PROP_NAME, nodeName);
    NodeRef nodeRef = nodeService.createNode(companyHomeNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(ContentModel.USER_MODEL_URI, nodeName), ContentModel.TYPE_CONTENT, properties).getChildRef();
    contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true).putContent("WebDAVTestContent");
    txn.commit();
    txn = transactionService.getUserTransaction();
    txn.begin();
    nodeService.deleteNode(nodeRef);
    txn.commit();
    AuthenticationUtil.clearCurrentSecurityContext();
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) After(org.junit.After)

Aggregations

NodeRef (org.alfresco.service.cmr.repository.NodeRef)1239 HashMap (java.util.HashMap)244 QName (org.alfresco.service.namespace.QName)242 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)209 Test (org.junit.Test)195 ArrayList (java.util.ArrayList)159 Serializable (java.io.Serializable)136 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)104 BaseUnitTest (org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest)101 FileInfo (org.alfresco.service.cmr.model.FileInfo)82 Map (java.util.Map)81 Node (org.alfresco.web.bean.repository.Node)81 JSONObject (org.json.JSONObject)80 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)74 FacesContext (javax.faces.context.FacesContext)61 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)59 List (java.util.List)58 IOException (java.io.IOException)55 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)52 Date (java.util.Date)51