Search in sources :

Example 1 with ActionService

use of org.alfresco.service.cmr.action.ActionService in project alfresco-remote-api by Alfresco.

the class PutMethodTest method setUp.

@Before
public void setUp() throws Exception {
    searchService = ctx.getBean("SearchService", SearchService.class);
    fileFolderService = ctx.getBean("FileFolderService", FileFolderService.class);
    nodeService = ctx.getBean("NodeService", NodeService.class);
    transactionService = ctx.getBean("transactionService", TransactionService.class);
    webDAVHelper = ctx.getBean("webDAVHelper", WebDAVHelper.class);
    authenticationService = ctx.getBean("authenticationService", MutableAuthenticationService.class);
    personService = ctx.getBean("PersonService", PersonService.class);
    lockService = ctx.getBean("LockService", LockService.class);
    contentService = ctx.getBean("contentService", ContentService.class);
    checkOutCheckInService = ctx.getBean("CheckOutCheckInService", CheckOutCheckInService.class);
    permissionService = ctx.getBean("PermissionService", PermissionService.class);
    namespaceService = ctx.getBean("namespaceService", NamespaceService.class);
    actionService = ctx.getBean("ActionService", ActionService.class);
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    repositoryHelper = (Repository) ctx.getBean("repositoryHelper");
    companyHomeNodeRef = repositoryHelper.getCompanyHome();
    txn = transactionService.getUserTransaction();
    txn.begin();
    createUser(USER1_NAME);
    createUser(USER2_NAME);
    InputStream testDataIS = getClass().getClassLoader().getResourceAsStream(TEST_DATA_FILE_NAME);
    InputStream davLockInfoAdminIS = getClass().getClassLoader().getResourceAsStream(DAV_LOCK_INFO_ADMIN);
    InputStream davLockInfoUser2IS = getClass().getClassLoader().getResourceAsStream(DAV_LOCK_INFO_USER2);
    testDataFile = IOUtils.toByteArray(testDataIS);
    davLockInfoAdminFile = IOUtils.toByteArray(davLockInfoAdminIS);
    davLockInfoUser2File = IOUtils.toByteArray(davLockInfoUser2IS);
    testDataIS.close();
    davLockInfoAdminIS.close();
    davLockInfoUser2IS.close();
    // Create a test file with versionable aspect and content
    Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
    versionableDocName = "doc-" + GUID.generate();
    properties.put(ContentModel.PROP_NAME, versionableDocName);
    versionableDoc = nodeService.createNode(companyHomeNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(ContentModel.USER_MODEL_URI, versionableDocName), ContentModel.TYPE_CONTENT, properties).getChildRef();
    contentService.getWriter(versionableDoc, ContentModel.PROP_CONTENT, true).putContent("WebDAVTestContent");
    nodeService.addAspect(versionableDoc, ContentModel.ASPECT_VERSIONABLE, null);
    txn.commit();
    txn = transactionService.getUserTransaction();
    txn.begin();
}
Also used : Serializable(java.io.Serializable) TransactionService(org.alfresco.service.transaction.TransactionService) LockService(org.alfresco.service.cmr.lock.LockService) HashMap(java.util.HashMap) InputStream(java.io.InputStream) QName(org.alfresco.service.namespace.QName) NodeService(org.alfresco.service.cmr.repository.NodeService) PersonService(org.alfresco.service.cmr.security.PersonService) FileFolderService(org.alfresco.service.cmr.model.FileFolderService) ContentService(org.alfresco.service.cmr.repository.ContentService) MutableAuthenticationService(org.alfresco.service.cmr.security.MutableAuthenticationService) PermissionService(org.alfresco.service.cmr.security.PermissionService) CheckOutCheckInService(org.alfresco.service.cmr.coci.CheckOutCheckInService) NamespaceService(org.alfresco.service.namespace.NamespaceService) SearchService(org.alfresco.service.cmr.search.SearchService) ActionService(org.alfresco.service.cmr.action.ActionService) Before(org.junit.Before)

Example 2 with ActionService

use of org.alfresco.service.cmr.action.ActionService in project alfresco-remote-api by Alfresco.

the class PutMethodTest method testPutNullContent.

/**
 * Negative test to check that a temp file will be deleted from the repo if writing the content fails
 */
@Test
public void testPutNullContent() throws Exception {
    String fileName = "file-" + GUID.generate();
    NodeRef fileNoderef = null;
    // Lock the node
    try {
        executeMethod(WebDAV.METHOD_LOCK, fileName, davLockInfoAdminFile, null);
        List<NodeRef> refs = searchService.selectNodes(nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE), "/app:company_home/cm:" + fileName, null, namespaceService, false);
        fileNoderef = refs.get(0);
    } catch (Exception e) {
        throw new RuntimeException("Failed to lock a file", e);
    }
    txn.commit();
    txn = transactionService.getUserTransaction();
    txn.begin();
    // Construct IF HEADER
    String lockToken = fileNoderef.getId() + WebDAV.LOCK_TOKEN_SEPERATOR + AuthenticationUtil.getAdminUserName();
    String lockHeaderValue = "(<" + WebDAV.OPAQUE_LOCK_TOKEN + lockToken + ">)";
    HashMap<String, String> headers = new HashMap<String, String>();
    headers.put(WebDAV.HEADER_IF, lockHeaderValue);
    // Simulate any failure during the content write
    // null content is no longer null in MockHttpServletRequest (Spring 5)
    ActionService mockActionService = mock(ActionService.class);
    when(mockActionService.createAction(ContentMetadataExtracter.EXECUTOR_NAME)).thenThrow(new AlfrescoRuntimeException("Negative test"));
    try {
        webDAVHelper.setActionService(mockActionService);
        // setting a null content
        executeMethod(WebDAV.METHOD_PUT, fileName, null, headers);
        fail("The execution should fail.");
    } catch (WebDAVServerException wse) {
        if (nodeService.exists(fileNoderef)) {
            nodeService.deleteNode(fileNoderef);
            fail("File exist, but should not.");
        }
    } catch (Exception e) {
        throw new RuntimeException("Failed to upload a file", e);
    } finally {
        webDAVHelper.setActionService(actionService);
    }
    if (fileNoderef != null && nodeService.exists(fileNoderef)) {
        nodeService.deleteNode(fileNoderef);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) HashMap(java.util.HashMap) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) UnableToAquireLockException(org.alfresco.service.cmr.lock.UnableToAquireLockException) ActionService(org.alfresco.service.cmr.action.ActionService) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)2 ActionService (org.alfresco.service.cmr.action.ActionService)2 InputStream (java.io.InputStream)1 Serializable (java.io.Serializable)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)1 CheckOutCheckInService (org.alfresco.service.cmr.coci.CheckOutCheckInService)1 LockService (org.alfresco.service.cmr.lock.LockService)1 UnableToAquireLockException (org.alfresco.service.cmr.lock.UnableToAquireLockException)1 FileFolderService (org.alfresco.service.cmr.model.FileFolderService)1 ContentService (org.alfresco.service.cmr.repository.ContentService)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 NodeService (org.alfresco.service.cmr.repository.NodeService)1 SearchService (org.alfresco.service.cmr.search.SearchService)1 MutableAuthenticationService (org.alfresco.service.cmr.security.MutableAuthenticationService)1 PermissionService (org.alfresco.service.cmr.security.PermissionService)1 PersonService (org.alfresco.service.cmr.security.PersonService)1 NamespaceService (org.alfresco.service.namespace.NamespaceService)1 QName (org.alfresco.service.namespace.QName)1 TransactionService (org.alfresco.service.transaction.TransactionService)1