Search in sources :

Example 46 with NodeService

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

the class WorkflowModelBuilderTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    namespaceService = new NamespaceServiceMemoryImpl();
    namespaceService.registerNamespace("test", URI);
    namespaceService.registerNamespace(NamespaceService.CONTENT_MODEL_PREFIX, NamespaceService.CONTENT_MODEL_1_0_URI);
    namespaceService.registerNamespace(NamespaceService.BPM_MODEL_PREFIX, NamespaceService.BPM_MODEL_1_0_URI);
    personService = mock(PersonService.class);
    when(personService.getPerson(userName)).thenReturn(person);
    when(personService.personExists(userName)).thenReturn(true);
    nodeService = mock(NodeService.class);
    Map<QName, Serializable> personProps = new HashMap<QName, Serializable>();
    personProps.put(ContentModel.PROP_USERNAME, userName);
    personProps.put(ContentModel.PROP_FIRSTNAME, firstName);
    personProps.put(ContentModel.PROP_LASTNAME, lastName);
    when(nodeService.getProperties(person)).thenReturn(personProps);
    when(nodeService.getProperty(person, ContentModel.PROP_USERNAME)).thenReturn(userName);
    when(nodeService.getProperty(person, ContentModel.PROP_FIRSTNAME)).thenReturn(firstName);
    when(nodeService.getProperty(person, ContentModel.PROP_LASTNAME)).thenReturn(lastName);
    workflowService = mock(WorkflowService.class);
    dictionaryService = mock(DictionaryService.class);
    authenticationService = mock(AuthenticationService.class);
    builder = new WorkflowModelBuilder(namespaceService, nodeService, authenticationService, personService, workflowService, dictionaryService);
}
Also used : Serializable(java.io.Serializable) DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) HashMap(java.util.HashMap) WorkflowService(org.alfresco.service.cmr.workflow.WorkflowService) QName(org.alfresco.service.namespace.QName) NamespaceServiceMemoryImpl(org.alfresco.service.namespace.NamespaceServiceMemoryImpl) PersonService(org.alfresco.service.cmr.security.PersonService) NodeService(org.alfresco.service.cmr.repository.NodeService) AuthenticationService(org.alfresco.service.cmr.security.AuthenticationService)

Example 47 with NodeService

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

the class MoveMethodTest method setUp.

@Before
public void setUp() throws Exception {
    req = new MockHttpServletRequest();
    resp = new MockHttpServletResponse();
    rootNode = new NodeRef("workspace://SpacesStore/node1");
    moveMethod = new MoveMethod() {

        @Override
        protected LockInfo checkNode(FileInfo fileInfo, boolean ignoreShared, boolean lockMethod) throws WebDAVServerException {
            return new LockInfoImpl();
        }

        @Override
        protected LockInfo checkNode(FileInfo fileInfo) throws WebDAVServerException {
            return new LockInfoImpl();
        }
    };
    moveMethod.setDetails(req, resp, davHelper, rootNode);
    sourceFileInfo = Mockito.mock(FileInfo.class);
    when(sourceFileInfo.isFolder()).thenReturn(true);
    destPath = "/path/to/dest.doc";
    moveMethod.m_strDestinationPath = destPath;
    sourcePath = "/path/to/source.doc";
    moveMethod.m_strPath = sourcePath;
    when(davHelper.getFileFolderService()).thenReturn(mockFileFolderService);
    List<String> sourcePathSplit = Arrays.asList("path", "to", "source.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/parent");
    destParentNodeRef = new NodeRef("workspace://SpacesStore/parent");
    sourceNodeRef = new NodeRef("workspace://SpacesStore/sourcefile");
    when(davHelper.getLockService()).thenReturn(davLockService);
    searchService = ctx.getBean("SearchService", SearchService.class);
    fileFolderService = ctx.getBean("FileFolderService", FileFolderService.class);
    nodeService = ctx.getBean("NodeService", NodeService.class);
    transactionService = ctx.getBean("transactionService", TransactionService.class);
    contentService = ctx.getBean("contentService", ContentService.class);
    webDAVHelper = ctx.getBean("webDAVHelper", WebDAVHelper.class);
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    repositoryHelper = (Repository) ctx.getBean("repositoryHelper");
    companyHomeNodeRef = repositoryHelper.getCompanyHome();
}
Also used : TransactionService(org.alfresco.service.transaction.TransactionService) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) NodeService(org.alfresco.service.cmr.repository.NodeService) FileFolderService(org.alfresco.service.cmr.model.FileFolderService) ContentService(org.alfresco.service.cmr.repository.ContentService) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) SearchService(org.alfresco.service.cmr.search.SearchService) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Before(org.junit.Before)

Example 48 with NodeService

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

the class WebDAVonContentUpdateTest 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);
    lockService = ctx.getBean("LockService", LockService.class);
    policyComponent = ctx.getBean("policyComponent", PolicyComponent.class);
    namespaceService = ctx.getBean("namespaceService", NamespaceService.class);
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    repositoryHelper = (Repository) ctx.getBean("repositoryHelper");
    companyHomeNodeRef = repositoryHelper.getCompanyHome();
    InputStream testDataIS = getClass().getClassLoader().getResourceAsStream(TEST_DATA_FILE_NAME);
    InputStream davLockInfoIS = getClass().getClassLoader().getResourceAsStream(DAV_LOCK_INFO_XML);
    testDataFile = IOUtils.toByteArray(testDataIS);
    davLockInfoFile = IOUtils.toByteArray(davLockInfoIS);
    testDataIS.close();
    davLockInfoIS.close();
    txn = transactionService.getUserTransaction();
    txn.begin();
}
Also used : PolicyComponent(org.alfresco.repo.policy.PolicyComponent) TransactionService(org.alfresco.service.transaction.TransactionService) LockService(org.alfresco.service.cmr.lock.LockService) NamespaceService(org.alfresco.service.namespace.NamespaceService) InputStream(java.io.InputStream) SearchService(org.alfresco.service.cmr.search.SearchService) NodeService(org.alfresco.service.cmr.repository.NodeService) FileFolderService(org.alfresco.service.cmr.model.FileFolderService) Before(org.junit.Before)

Example 49 with NodeService

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

the class DownloadRestApiTest method setUp.

public void setUp() {
    // Resolve required services
    authenticationService = getServer().getApplicationContext().getBean("AuthenticationService", MutableAuthenticationService.class);
    authenticationComponent = getServer().getApplicationContext().getBean("authenticationComponent", AuthenticationComponent.class);
    contentService = getServer().getApplicationContext().getBean("ContentService", ContentService.class);
    nodeService = getServer().getApplicationContext().getBean("NodeService", NodeService.class);
    personService = getServer().getApplicationContext().getBean("PersonService", PersonService.class);
    // Authenticate as user
    this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
    // if user with given user name doesn't already exist then create user
    if (this.authenticationService.authenticationExists(TEST_USERNAME) == false) {
        // create user
        this.authenticationService.createAuthentication(TEST_USERNAME, "password".toCharArray());
        // create person properties
        PropertyMap personProps = new PropertyMap();
        personProps.put(ContentModel.PROP_USERNAME, TEST_USERNAME);
        personProps.put(ContentModel.PROP_FIRSTNAME, "FirstName123");
        personProps.put(ContentModel.PROP_LASTNAME, "LastName123");
        personProps.put(ContentModel.PROP_EMAIL, "FirstName123.LastName123@email.com");
        personProps.put(ContentModel.PROP_JOBTITLE, "JobTitle123");
        personProps.put(ContentModel.PROP_JOBTITLE, "Organisation123");
        // create person node for user
        this.personService.createPerson(personProps);
    }
    Repository repositoryHelper = (Repository) getServer().getApplicationContext().getBean("repositoryHelper");
    NodeRef companyHome = repositoryHelper.getCompanyHome();
    // Create some static test content
    rootFolder = createNode(companyHome, "rootFolder", ContentModel.TYPE_FOLDER, AuthenticationUtil.getAdminUserName());
    rootFile = createNodeWithTextContent(companyHome, "rootFile", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName(), "Root file content");
    level1File = createNodeWithTextContent(rootFolder, "level1File", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName(), "Level 1 file content");
    level1Folder = createNode(rootFolder, "level1Folder", ContentModel.TYPE_FOLDER, AuthenticationUtil.getAdminUserName());
    level2File = createNodeWithTextContent(level1Folder, "level2File", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName(), "Level 2 file content");
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Repository(org.alfresco.repo.model.Repository) PropertyMap(org.alfresco.util.PropertyMap) AuthenticationComponent(org.alfresco.repo.security.authentication.AuthenticationComponent) NodeService(org.alfresco.service.cmr.repository.NodeService) PersonService(org.alfresco.service.cmr.security.PersonService) ContentService(org.alfresco.service.cmr.repository.ContentService) MutableAuthenticationService(org.alfresco.service.cmr.security.MutableAuthenticationService)

Example 50 with NodeService

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

the class TestCustomConstraint method testCreateConstraintAndAddToProperty.

@Test
public void testCreateConstraintAndAddToProperty() throws Exception {
    setRequestContext(customModelAdmin);
    String modelName = "testModelConstraint" + System.currentTimeMillis();
    final Pair<String, String> namespacePair = getTestNamespaceUriPrefixPair();
    // Create the model as a Model Administrator
    createCustomModel(modelName, namespacePair, ModelStatus.DRAFT);
    // Create RegEx constraint
    String regExConstraintName = "testFileNameRegEx" + System.currentTimeMillis();
    CustomModelConstraint regExConstraint = new CustomModelConstraint();
    regExConstraint.setName(regExConstraintName);
    regExConstraint.setType("REGEX");
    regExConstraint.setTitle("test RegEx title");
    regExConstraint.setDescription("test RegEx desc");
    // Create the RegEx constraint's parameters
    List<CustomModelNamedValue> parameters = new ArrayList<>(2);
    parameters.add(buildNamedValue("expression", "(.*[\\\"\\*\\\\\\>\\<\\?\\/\\:\\|]+.*)|(.*[\\.]?.*[\\.]+$)|(.*[ ]+$)"));
    parameters.add(buildNamedValue("requiresMatch", "false"));
    // Add the parameters into the constraint
    regExConstraint.setParameters(parameters);
    // Create constraint as a Model Administrator
    post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(regExConstraint), 201);
    // Retrieve the created constraint
    HttpResponse response = getSingle("cmm/" + modelName + "/constraints", regExConstraintName, 200);
    CustomModelConstraint returnedConstraint = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModelConstraint.class);
    // Retrieve all the model's constraints
    Paging paging = getPaging(0, Integer.MAX_VALUE);
    response = getAll("cmm/" + modelName + "/constraints", paging, 200);
    List<CustomModelConstraint> constraints = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), CustomModelConstraint.class);
    assertEquals(1, constraints.size());
    // Create aspect
    String aspectName = "testAspect1" + System.currentTimeMillis();
    createTypeAspect(CustomAspect.class, modelName, aspectName, "title", "desc", null);
    // Update the Aspect by adding property
    CustomAspect payload = new CustomAspect();
    payload.setName(aspectName);
    final String aspectPropName = "testAspect1Prop1" + System.currentTimeMillis();
    CustomModelProperty aspectProp = new CustomModelProperty();
    aspectProp.setName(aspectPropName);
    aspectProp.setTitle("property title");
    aspectProp.setDataType("d:text");
    // Add the constraint ref
    aspectProp.setConstraintRefs(Arrays.asList(returnedConstraint.getPrefixedName()));
    List<CustomModelProperty> props = new ArrayList<>(1);
    props.add(aspectProp);
    payload.setProperties(props);
    // Create the property
    put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 200);
    // Activate the model
    CustomModel updatePayload = new CustomModel();
    updatePayload.setStatus(ModelStatus.ACTIVE);
    put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 200);
    // Retrieve all the model's constraints
    // Test to see if the API took care of duplicate constraints when referencing a constraint within a property.
    response = getAll("cmm/" + modelName + "/constraints", paging, 200);
    constraints = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), CustomModelConstraint.class);
    assertEquals(1, constraints.size());
    // Test RegEx constrain enforcement
    {
        final NodeService nodeService = repoService.getNodeService();
        final QName aspectQName = QName.createQName("{" + namespacePair.getFirst() + "}" + aspectName);
        TestNetwork testNetwork = getTestFixture().getRandomNetwork();
        TestPerson person = testNetwork.createUser();
        final String siteName = "site" + System.currentTimeMillis();
        TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

            @Override
            public Void doWork() throws Exception {
                SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE);
                TestSite site = repoService.createSite(null, siteInfo);
                NodeRef nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc", "Test Content");
                nodeService.addAspect(nodeRef, aspectQName, null);
                assertTrue(nodeService.hasAspect(nodeRef, aspectQName));
                try {
                    QName propQName = QName.createQName("{" + namespacePair.getFirst() + "}" + aspectPropName);
                    nodeService.setProperty(nodeRef, propQName, "Invalid$Char.");
                    fail("Invalid property value. Should have caused integrity violations.");
                } catch (Exception e) {
                // Expected
                }
                // Permanently remove model from repository
                nodeService.addAspect(nodeRef, ContentModel.ASPECT_TEMPORARY, null);
                nodeService.deleteNode(nodeRef);
                return null;
            }
        }, person.getId(), testNetwork.getId());
    }
    setRequestContext(customModelAdmin);
    // Deactivate the model
    updatePayload = new CustomModel();
    updatePayload.setStatus(ModelStatus.DRAFT);
    put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 200);
    // Test update the namespace prefix (test to see if the API updates the constraints refs with this new prefix)
    CustomModel updateModelPayload = new CustomModel();
    String modifiedPrefix = namespacePair.getSecond() + "Modified";
    updateModelPayload.setNamespacePrefix(modifiedPrefix);
    updateModelPayload.setNamespaceUri(namespacePair.getFirst());
    response = put("cmm", modelName, RestApiUtil.toJsonAsString(updateModelPayload), null, 200);
    CustomModel returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class);
    assertEquals(modifiedPrefix, returnedModel.getNamespacePrefix());
    assertEquals("The namespace URI shouldn't have changed.", namespacePair.getFirst(), returnedModel.getNamespaceUri());
    // Test update the namespace URI
    updateModelPayload = new CustomModel();
    updateModelPayload.setNamespacePrefix(modifiedPrefix);
    String modifiedURI = namespacePair.getFirst() + "Modified";
    updateModelPayload.setNamespaceUri(modifiedURI);
    response = put("cmm", modelName, RestApiUtil.toJsonAsString(updateModelPayload), null, 200);
    returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class);
    assertEquals(modifiedURI, returnedModel.getNamespaceUri());
    assertEquals("The namespace prefix shouldn't have changed.", modifiedPrefix, returnedModel.getNamespacePrefix());
}
Also used : QName(org.alfresco.service.namespace.QName) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) NodeService(org.alfresco.service.cmr.repository.NodeService) ArrayList(java.util.ArrayList) CustomAspect(org.alfresco.rest.api.model.CustomAspect) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) CustomModelProperty(org.alfresco.rest.api.model.CustomModelProperty) CustomModel(org.alfresco.rest.api.model.CustomModel) ConstraintException(org.alfresco.service.cmr.dictionary.ConstraintException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) CustomModelNamedValue(org.alfresco.rest.api.model.CustomModelNamedValue) SiteInformation(org.alfresco.rest.api.tests.RepoService.SiteInformation) TenantRunAsWork(org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) CustomModelConstraint(org.alfresco.rest.api.model.CustomModelConstraint) Test(org.junit.Test)

Aggregations

NodeService (org.alfresco.service.cmr.repository.NodeService)53 NodeRef (org.alfresco.service.cmr.repository.NodeRef)36 QName (org.alfresco.service.namespace.QName)15 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)11 ResponseWriter (javax.faces.context.ResponseWriter)10 IOException (java.io.IOException)8 UserTransaction (javax.transaction.UserTransaction)8 ServiceRegistry (org.alfresco.service.ServiceRegistry)8 DictionaryService (org.alfresco.service.cmr.dictionary.DictionaryService)8 Serializable (java.io.Serializable)7 HashMap (java.util.HashMap)7 FileFolderService (org.alfresco.service.cmr.model.FileFolderService)7 PermissionService (org.alfresco.service.cmr.security.PermissionService)7 PersonService (org.alfresco.service.cmr.security.PersonService)7 SearchService (org.alfresco.service.cmr.search.SearchService)6 ArrayList (java.util.ArrayList)5 ResourceBundle (java.util.ResourceBundle)5 FileInfo (org.alfresco.service.cmr.model.FileInfo)5 Path (org.alfresco.service.cmr.repository.Path)5 TransactionService (org.alfresco.service.transaction.TransactionService)5