Search in sources :

Example 16 with Repository

use of org.alfresco.repo.model.Repository in project alfresco-repository by Alfresco.

the class ScriptNodeTest method testCreateFolderPath.

@Test
public void testCreateFolderPath() {
    Repository repositoryHelper = (Repository) APP_CONTEXT_INIT.getApplicationContext().getBean("repositoryHelper");
    NodeRef companyHome = repositoryHelper.getCompanyHome();
    NodeRef folderNodeRef = testNodes.createNode(companyHome, "foldertest1", ContentModel.TYPE_FOLDER, AuthenticationUtil.getFullyAuthenticatedUser());
    assertNotNull(folderNodeRef);
    ScriptNode folderNode = new ScriptNode(folderNodeRef, SERVICE_REGISTRY);
    // create a simple path of depth one - does not exist yet
    assertNotNull(folderNode.createFolderPath("One"));
    // create a simple path of depth one - does exist (which should be ignored and continue - createFolderPath() emulates 'mkdir -p' behaviour)
    assertNotNull(folderNode.createFolderPath("One"));
    // create depth path - none of which exists
    assertNotNull(folderNode.createFolderPath("A/B"));
    // create depth path - all of which exists
    assertNotNull(folderNode.createFolderPath("A/B"));
    // create depth path - some of which exists
    assertNotNull(folderNode.createFolderPath("A/B/C"));
    // test last child is returned as the result
    NodeRef folderARef = NODE_SERVICE.getChildByName(folderNodeRef, ContentModel.ASSOC_CONTAINS, "A");
    NodeRef folderBRef = NODE_SERVICE.getChildByName(folderARef, ContentModel.ASSOC_CONTAINS, "B");
    assertEquals(folderBRef, folderNode.createFolderPath("A/B").getNodeRef());
    // test case where folder should not should be created - under a content node
    NodeRef contentNodeRef = testNodes.createNode(folderNodeRef, "CONTENT", ContentModel.TYPE_CONTENT, AuthenticationUtil.getFullyAuthenticatedUser());
    assertNotNull(contentNodeRef);
    try {
        folderNode.createFolderPath("CONTENT/A");
        fail("Should not be able to create folder path when all nodes are not subtypes of cm:folder");
    } catch (ScriptException se1) {
    // expected
    }
    // test string edge cases
    try {
        assertNotNull(folderNode.createFolderPath("/A/B"));
        fail("Leading slash not expected");
    } catch (Throwable e1) {
    // expected
    }
    try {
        assertNotNull(folderNode.createFolderPath("A/B/"));
        fail("Trailing slash not expected");
    } catch (Throwable e2) {
    // expected
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ScriptException(org.alfresco.scripts.ScriptException) Repository(org.alfresco.repo.model.Repository) ActivitiScriptNode(org.alfresco.repo.workflow.activiti.ActivitiScriptNode) Test(org.junit.Test)

Example 17 with Repository

use of org.alfresco.repo.model.Repository in project alfresco-repository by Alfresco.

the class ScriptNodeTest method testContentDataCreation.

/**
 * MNT-15798 - Content Data should be created only when it has a binary, not as a side effect of getters on ScriptNode.
 */
@Test
public void testContentDataCreation() {
    Repository repositoryHelper = (Repository) APP_CONTEXT_INIT.getApplicationContext().getBean("repositoryHelper");
    NodeRef companyHome = repositoryHelper.getCompanyHome();
    NodeRef newNode1 = testNodes.createNode(companyHome, "theTestContent1", ContentModel.TYPE_CONTENT, AuthenticationUtil.getFullyAuthenticatedUser());
    // test on content data
    ScriptNode sn = new ScriptNode(newNode1, SERVICE_REGISTRY);
    sn.setScope(getScope());
    ContentData contentData = (ContentData) NODE_SERVICE.getProperty(newNode1, ContentModel.PROP_CONTENT);
    assertNull(contentData);
    sn.setMimetype(MimetypeMap.MIMETYPE_PDF);
    sn.save();
    contentData = (ContentData) NODE_SERVICE.getProperty(newNode1, ContentModel.PROP_CONTENT);
    assertNull(contentData);
    sn.setContent("Marks to prove it.");
    sn.save();
    contentData = (ContentData) NODE_SERVICE.getProperty(newNode1, ContentModel.PROP_CONTENT);
    assertNotNull(contentData);
    assertEquals(true, ContentData.hasContent(contentData));
    // test on ScriptContentData
    NodeRef newNode2 = testNodes.createNode(companyHome, "theTestContent2.txt", ContentModel.TYPE_CONTENT, AuthenticationUtil.getFullyAuthenticatedUser());
    ScriptNode sn2 = new ScriptNode(newNode2, SERVICE_REGISTRY);
    sn2.setScope(getScope());
    ScriptContentData scd = sn2.new ScriptContentData(null, ContentModel.PROP_CONTENT);
    // set the "mocked" script content data on the script node
    sn2.getProperties().put(ContentModel.PROP_CONTENT.toString(), scd);
    assertEquals(false, scd.isDirty());
    scd.guessMimetype("theTestContent2.pdf");
    assertEquals(false, scd.isDirty());
    scd.setMimetype("text/plain");
    assertEquals(false, scd.isDirty());
    scd.setEncoding("UTF-8");
    assertEquals(false, scd.isDirty());
    sn2.save();
    contentData = (ContentData) NODE_SERVICE.getProperty(newNode2, ContentModel.PROP_CONTENT);
    assertNull(contentData);
    scd.setContent("Marks to prove it.");
    assertEquals(true, scd.isDirty());
    scd.setEncoding("ISO-8859-1");
    assertEquals(true, scd.isDirty());
    sn2.save();
    contentData = (ContentData) NODE_SERVICE.getProperty(newNode2, ContentModel.PROP_CONTENT);
    assertNotNull(contentData);
    NODE_SERVICE.removeProperty(newNode1, ContentModel.PROP_CONTENT);
    NODE_SERVICE.removeProperty(newNode2, ContentModel.PROP_CONTENT);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Repository(org.alfresco.repo.model.Repository) ScriptContentData(org.alfresco.repo.jscript.ScriptNode.ScriptContentData) ContentData(org.alfresco.service.cmr.repository.ContentData) ScriptContentData(org.alfresco.repo.jscript.ScriptNode.ScriptContentData) ActivitiScriptNode(org.alfresco.repo.workflow.activiti.ActivitiScriptNode) Test(org.junit.Test)

Example 18 with Repository

use of org.alfresco.repo.model.Repository in project alfresco-repository by Alfresco.

the class DownloadServiceIntegrationTest method createContent.

/**
 * Create the test content
 */
@Before
public void createContent() {
    allEntries = new TreeSet<String>();
    AuthenticationUtil.setRunAsUserSystem();
    Repository repositoryHelper = (Repository) APP_CONTEXT_INIT.getApplicationContext().getBean("repositoryHelper");
    NodeRef COMPANY_HOME = repositoryHelper.getCompanyHome();
    // Create some static test content
    rootFolder = testNodes.createNode(COMPANY_HOME, "rootFolder", ContentModel.TYPE_FOLDER, AuthenticationUtil.getAdminUserName());
    allEntries.add("rootFolder/");
    rootFile = testNodes.createNodeWithTextContent(COMPANY_HOME, "rootFile.txt", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName(), "Root file content");
    allEntries.add("rootFile.txt");
    testNodes.createNodeWithTextContent(rootFolder, "level1File.txt", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName(), "Level 1 file content");
    allEntries.add("rootFolder/level1File.txt");
    level1Folder1 = testNodes.createNode(rootFolder, "level1Folder1", ContentModel.TYPE_FOLDER, AuthenticationUtil.getAdminUserName());
    allEntries.add("rootFolder/level1Folder1/");
    level1Folder2 = testNodes.createNode(rootFolder, "level1Folder2", ContentModel.TYPE_FOLDER, AuthenticationUtil.getAdminUserName());
    allEntries.add("rootFolder/level1Folder2/");
    testNodes.createNode(rootFolder, "level1EmptyFolder", ContentModel.TYPE_FOLDER, AuthenticationUtil.getAdminUserName());
    allEntries.add("rootFolder/level1EmptyFolder/");
    testNodes.createNodeWithTextContent(level1Folder1, "level2File.txt", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName(), "Level 2 file content");
    allEntries.add("rootFolder/level1Folder1/level2File.txt");
    testNodes.createNodeWithTextContent(level1Folder2, "level2File.txt", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName(), "Level 2 file content");
    allEntries.add("rootFolder/level1Folder2/level2File.txt");
    secondaryNode = testNodes.createNodeWithTextContent(COMPANY_HOME, "secondaryNodeFile.txt", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName(), "Secondary node");
    ChildAssociationRef assoc = NODE_SERVICE.addChild(rootFolder, secondaryNode, ContentModel.ASSOC_CONTAINS, ContentModel.ASSOC_CONTAINS);
    Assert.assertFalse(assoc.isPrimary());
    allEntries.add("rootFolder/secondaryNodeFile.txt");
    fileToCheckout = testNodes.createNodeWithTextContent(level1Folder2, "fileToCheckout.txt", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName(), "Level 2 file content");
    // Add the lock and version aspects to the created node
    NODE_SERVICE.addAspect(fileToCheckout, ContentModel.ASPECT_VERSIONABLE, null);
    NODE_SERVICE.addAspect(fileToCheckout, ContentModel.ASPECT_LOCKABLE, null);
    allEntries.add("rootFolder/level1Folder2/fileToCheckout.txt");
    PERMISSION_SERVICE.setPermission(level1Folder2, TEST_USER.getUsername(), PermissionService.ALL_PERMISSIONS, true);
    PERMISSION_SERVICE.setPermission(fileToCheckout, TEST_USER.getUsername(), PermissionService.ALL_PERMISSIONS, true);
    // MNT-21671 Download as zip does not include custom folders.
    // deploy custom model
    final String modelFileName1 = "model-MNT-21671.xml";
    InputStream modelStream = null;
    try {
        modelStream = new ByteArrayInputStream(CUSTOM_FOLDER_MODEL_XML.getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    REPO_ADMIN_SERVICE.deployModel(modelStream, modelFileName1);
    final QName customFolderType = QName.createQName("{custom.model}folderx");
    testNodes.createNode(rootFolder, "level1CustomFolder", customFolderType, AuthenticationUtil.getAdminUserName());
    allEntries.add("rootFolder/level1CustomFolder/");
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Repository(org.alfresco.repo.model.Repository) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipArchiveInputStream(org.apache.commons.compress.archivers.zip.ZipArchiveInputStream) InputStream(java.io.InputStream) QName(org.alfresco.service.namespace.QName) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) Before(org.junit.Before)

Example 19 with Repository

use of org.alfresco.repo.model.Repository in project alfresco-repository by Alfresco.

the class AbstractWorkflowServiceIntegrationTest method before.

@SuppressWarnings("deprecation")
@Before
public void before() throws Exception {
    serviceRegistry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
    this.workflowService = serviceRegistry.getWorkflowService();
    this.authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent");
    this.nodeService = serviceRegistry.getNodeService();
    this.historyService = (HistoryService) applicationContext.getBean("activitiHistoryService");
    Repository repositoryHelper = (Repository) applicationContext.getBean("repositoryHelper");
    this.companyHome = repositoryHelper.getCompanyHome();
    try {
        this.transactionService = (TransactionServiceImpl) serviceRegistry.getTransactionService();
    } catch (ClassCastException e) {
        throw new AlfrescoRuntimeException("The AbstractWorkflowServiceIntegrationTest needs direct access to the TransactionServiceImpl");
    }
    MutableAuthenticationService authenticationService = serviceRegistry.getAuthenticationService();
    AuthorityService authorityService = serviceRegistry.getAuthorityService();
    PersonService personService = serviceRegistry.getPersonService();
    authenticationComponent.setSystemUserAsCurrentUser();
    WorkflowAdminServiceImpl workflowAdminService = (WorkflowAdminServiceImpl) applicationContext.getBean(WorkflowAdminServiceImpl.NAME);
    this.wfTestHelper = new WorkflowTestHelper(workflowAdminService, getEngine(), true);
    // create test users
    this.personManager = new TestPersonManager(authenticationService, personService, nodeService);
    this.groupManager = new TestGroupManager(authorityService);
    personManager.createPerson(USER1);
    personManager.createPerson(USER2);
    personManager.createPerson(USER3);
    personManager.createPerson(USER4);
    // create test groups
    groupManager.addGroupToParent(GROUP, SUB_GROUP);
    // add users to groups
    groupManager.addUserToGroup(GROUP, USER1);
    groupManager.addUserToGroup(SUB_GROUP, USER2);
    personManager.setUser(USER1);
}
Also used : TestPersonManager(org.alfresco.repo.security.person.TestPersonManager) Repository(org.alfresco.repo.model.Repository) AuthorityService(org.alfresco.service.cmr.security.AuthorityService) PersonService(org.alfresco.service.cmr.security.PersonService) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) MutableAuthenticationService(org.alfresco.service.cmr.security.MutableAuthenticationService) TestGroupManager(org.alfresco.repo.security.person.TestGroupManager) Before(org.junit.Before)

Example 20 with Repository

use of org.alfresco.repo.model.Repository in project alfresco-repository by Alfresco.

the class RuleServiceIntegrationTest method setupTest.

@BeforeClass
public static void setupTest() throws Exception {
    SERVICE_REGISTRY = (ServiceRegistry) APP_CONTEXT_INIT.getApplicationContext().getBean(ServiceRegistry.SERVICE_REGISTRY);
    NODE_SERVICE = SERVICE_REGISTRY.getNodeService();
    TRANSACTION_HELPER = SERVICE_REGISTRY.getTransactionService().getRetryingTransactionHelper();
    ACTION_SERVICE = SERVICE_REGISTRY.getActionService();
    RULE_SERVICE = SERVICE_REGISTRY.getRuleService();
    CONTENT_SERVICE = SERVICE_REGISTRY.getContentService();
    MAIL_ACTION_EXECUTER = APP_CONTEXT_INIT.getApplicationContext().getBean("OutboundSMTP", ApplicationContextFactory.class).getApplicationContext().getBean("mail", MailActionExecuter.class);
    WAS_IN_TEST_MODE = MAIL_ACTION_EXECUTER.isTestMode();
    MAIL_ACTION_EXECUTER.setTestMode(true);
    Repository repositoryHelper = (Repository) APP_CONTEXT_INIT.getApplicationContext().getBean("repositoryHelper");
    COMPANY_HOME = repositoryHelper.getCompanyHome();
    // Create some static test content
    TEST_FOLDER = STATIC_TEST_NODES.createNode(COMPANY_HOME, "testFolder", ContentModel.TYPE_FOLDER, AuthenticationUtil.getAdminUserName());
}
Also used : ApplicationContextFactory(org.alfresco.repo.management.subsystems.ApplicationContextFactory) MailActionExecuter(org.alfresco.repo.action.executer.MailActionExecuter) Repository(org.alfresco.repo.model.Repository) BeforeClass(org.junit.BeforeClass)

Aggregations

Repository (org.alfresco.repo.model.Repository)24 NodeRef (org.alfresco.service.cmr.repository.NodeRef)10 Before (org.junit.Before)6 Test (org.junit.Test)6 ActivitiScriptNode (org.alfresco.repo.workflow.activiti.ActivitiScriptNode)5 NodeService (org.alfresco.service.cmr.repository.NodeService)4 BeforeClass (org.junit.BeforeClass)4 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)3 ServiceRegistry (org.alfresco.service.ServiceRegistry)3 ContentService (org.alfresco.service.cmr.repository.ContentService)3 PersonService (org.alfresco.service.cmr.security.PersonService)3 QName (org.alfresco.service.namespace.QName)3 ScriptContentData (org.alfresco.repo.jscript.ScriptNode.ScriptContentData)2 AuthenticationComponent (org.alfresco.repo.security.authentication.AuthenticationComponent)2 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)2 ScriptException (org.alfresco.scripts.ScriptException)2 FileFolderService (org.alfresco.service.cmr.model.FileFolderService)2 ContentData (org.alfresco.service.cmr.repository.ContentData)2 MutableAuthenticationService (org.alfresco.service.cmr.security.MutableAuthenticationService)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1