Search in sources :

Example 1 with SearchService

use of org.alfresco.service.cmr.search.SearchService in project alfresco-remote-api by Alfresco.

the class SharedLinkApiTest method testSharedLinkFindIncludeNodeProperties.

@Test
public void testSharedLinkFindIncludeNodeProperties() throws Exception {
    QuickShareLinksImpl quickShareLinks = applicationContext.getBean("quickShareLinks", QuickShareLinksImpl.class);
    ServiceDescriptorRegistry serviceRegistry = applicationContext.getBean("ServiceRegistry", ServiceDescriptorRegistry.class);
    SearchService mockSearchService = mock(SearchService.class);
    serviceRegistry.setMockSearchService(mockSearchService);
    // As user 1 ...
    setRequestContext(user1);
    Paging paging = getPaging(0, 100);
    String content = "The quick brown fox jumps over the lazy dog.";
    String fileName1 = "fileOne_" + RUNID + ".txt";
    String fileName2 = "fileTwo_" + RUNID + ".txt";
    // As user 1 create 2 text files in -my- folder (i.e. User's Home)
    setRequestContext(user1);
    Map<String, String> file1Props = new HashMap<>();
    file1Props.put("cm:title", "File one title");
    file1Props.put("cm:lastThumbnailModification", "doclib:1549351708998");
    String file1Id = createTextFile(getMyNodeId(), fileName1, content, "UTF-8", file1Props).getId();
    String file2Id = createTextFile(getMyNodeId(), fileName2, content).getId();
    // Create shared links to file 1 and 2
    QuickShareLink body = new QuickShareLink();
    body.setNodeId(file1Id);
    HttpResponse response = post(URL_SHARED_LINKS, toJsonAsStringNonNull(body), 201);
    QuickShareLink resp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), QuickShareLink.class);
    String shared1Id = resp.getId();
    body = new QuickShareLink();
    body.setNodeId(file2Id);
    post(URL_SHARED_LINKS, toJsonAsStringNonNull(body), 201);
    // Lock text file 1
    LockInfo lockInfo = new LockInfo();
    lockInfo.setTimeToExpire(60);
    lockInfo.setType("FULL");
    lockInfo.setLifetime("PERSISTENT");
    post(getNodeOperationUrl(file1Id, "lock"), toJsonAsStringNonNull(lockInfo), null, 200);
    // Find shared links without include=properties
    ResultSet mockResultSet = mockResultSet(Arrays.asList(file1Id, file2Id));
    when(mockSearchService.query(any())).thenReturn(mockResultSet);
    quickShareLinks.afterPropertiesSet();
    response = getAll(URL_SHARED_LINKS, paging, null, 200);
    List<QuickShareLink> sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class);
    assertEquals(2, sharedLinks.size());
    QuickShareLink resQuickShareLink1 = sharedLinks.get(0);
    QuickShareLink resQuickShareLink2 = sharedLinks.get(1);
    assertNull("Properties were not requested therefore they should not be included", resQuickShareLink1.getProperties());
    assertNull("Properties were not requested therefore they should not be included", resQuickShareLink2.getProperties());
    // Find the shared links with include=properties
    mockResultSet = mockResultSet(Arrays.asList(file1Id, file2Id));
    when(mockSearchService.query(any())).thenReturn(mockResultSet);
    quickShareLinks.afterPropertiesSet();
    Map<String, String> params = new HashMap<>();
    params.put("include", "properties,allowableOperations");
    response = getAll(URL_SHARED_LINKS, paging, params, 200);
    sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class);
    assertEquals(2, sharedLinks.size());
    resQuickShareLink1 = sharedLinks.get(0);
    // Check the 1st shared link and properties (properties should include a title, lastThumbnailModification and lock info)
    assertEquals(shared1Id, resQuickShareLink1.getId());
    assertEquals(file1Id, resQuickShareLink1.getNodeId());
    Map<String, Object> resQuickShareLink1Props = resQuickShareLink1.getProperties();
    assertNotNull("Properties were requested to be included but are null.", resQuickShareLink1Props);
    assertNotNull("Properties should include cm:lockType", resQuickShareLink1Props.get("cm:lockType"));
    assertNotNull("Properties should include cm:lockOwner", resQuickShareLink1Props.get("cm:lockOwner"));
    assertNotNull("Properties should include cm:lockLifetime", resQuickShareLink1Props.get("cm:lockLifetime"));
    assertNotNull("Properties should include cm:title", resQuickShareLink1Props.get("cm:title"));
    assertNotNull("Properties should include cm:versionType", resQuickShareLink1Props.get("cm:versionType"));
    assertNotNull("Properties should include cm:versionLabel", resQuickShareLink1Props.get("cm:versionLabel"));
    assertNotNull("Properties should include cm:lastThumbnailModification", resQuickShareLink1Props.get("cm:lastThumbnailModification"));
    // Properties that should be excluded
    assertNull("Properties should NOT include cm:name", resQuickShareLink1Props.get("cm:name"));
    assertNull("Properties should NOT include qshare:sharedBy", resQuickShareLink1Props.get("qshare:sharedBy"));
    assertNull("Properties should NOT include qshare:sharedId", resQuickShareLink1Props.get("qshare:sharedId"));
    assertNull("Properties should NOT include cm:content", resQuickShareLink1Props.get("cm:content"));
    assertNull("Properties should NOT include cm:created", resQuickShareLink1Props.get("cm:created"));
    assertNull("Properties should NOT include cm:creator", resQuickShareLink1Props.get("cm:creator"));
    assertNull("Properties should NOT include cm:modifier", resQuickShareLink1Props.get("cm:modifier"));
    assertNull("Properties should NOT include cm:modified", resQuickShareLink1Props.get("cm:modified"));
    assertNull("Properties should NOT include cm:autoVersion", resQuickShareLink1Props.get("cm:autoVersion"));
    assertNull("Properties should NOT include cm:initialVersion", resQuickShareLink1Props.get("cm:initialVersion"));
    assertNull("Properties should NOT include cm:autoVersionOnUpdateProps", resQuickShareLink1Props.get("cm:autoVersionOnUpdateProps"));
    // System properties should be excluded
    boolean foundSysProp = resQuickShareLink1Props.keySet().stream().anyMatch((s) -> s.startsWith("sys:"));
    assertFalse("System properties should be excluded", foundSysProp);
    serviceRegistry.setMockSearchService(null);
    quickShareLinks.afterPropertiesSet();
}
Also used : HashMap(java.util.HashMap) Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) QuickShareLinksImpl(org.alfresco.rest.api.impl.QuickShareLinksImpl) ServiceDescriptorRegistry(org.alfresco.repo.service.ServiceDescriptorRegistry) SearchService(org.alfresco.service.cmr.search.SearchService) ResultSet(org.alfresco.service.cmr.search.ResultSet) LockInfo(org.alfresco.rest.api.model.LockInfo) QuickShareLink(org.alfresco.rest.api.model.QuickShareLink) Test(org.junit.Test)

Example 2 with SearchService

use of org.alfresco.service.cmr.search.SearchService 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 3 with SearchService

use of org.alfresco.service.cmr.search.SearchService 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 4 with SearchService

use of org.alfresco.service.cmr.search.SearchService in project acs-community-packaging by Alfresco.

the class ContextListener method contextInitialized.

/**
 * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
 */
public void contextInitialized(ServletContextEvent event) {
    // make sure that the spaces store in the repository exists
    this.servletContext = event.getServletContext();
    WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext);
    // If no context has been initialised, exit silently so config changes can be made
    if (ctx == null) {
        return;
    }
    ServiceRegistry registry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    TransactionService transactionService = registry.getTransactionService();
    NodeService nodeService = registry.getNodeService();
    SearchService searchService = registry.getSearchService();
    NamespaceService namespaceService = registry.getNamespaceService();
    AuthenticationContext authenticationContext = (AuthenticationContext) ctx.getBean("authenticationContext");
    // repo bootstrap code for our client
    UserTransaction tx = null;
    NodeRef companySpaceNodeRef = null;
    try {
        tx = transactionService.getUserTransaction();
        tx.begin();
        authenticationContext.setSystemUserAsCurrentUser();
        // get and setup the initial store ref and root path from config
        StoreRef storeRef = Repository.getStoreRef(servletContext);
        // get root path
        String rootPath = Application.getRootPath(servletContext);
        // Extract company space id and store it in the Application object
        companySpaceNodeRef = Repository.getCompanyRoot(nodeService, searchService, namespaceService, storeRef, rootPath);
        Application.setCompanyRootId(companySpaceNodeRef.getId());
        // commit the transaction
        tx.commit();
    } catch (Throwable e) {
        // rollback the transaction
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception ex) {
        }
        logger.error("Failed to initialise ", e);
        throw new AlfrescoRuntimeException("Failed to initialise ", e);
    } finally {
        try {
            authenticationContext.clearCurrentSecurityContext();
        } catch (Exception ex) {
        }
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) StoreRef(org.alfresco.service.cmr.repository.StoreRef) AuthenticationContext(org.alfresco.repo.security.authentication.AuthenticationContext) TransactionService(org.alfresco.service.transaction.TransactionService) NodeService(org.alfresco.service.cmr.repository.NodeService) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) WebApplicationContext(org.springframework.web.context.WebApplicationContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) NamespaceService(org.alfresco.service.namespace.NamespaceService) SearchService(org.alfresco.service.cmr.search.SearchService) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ServiceRegistry(org.alfresco.service.ServiceRegistry)

Example 5 with SearchService

use of org.alfresco.service.cmr.search.SearchService in project acs-community-packaging by Alfresco.

the class User method getUserPreferencesRef.

/**
 * Get or create the node used to store user preferences.
 * Utilises the 'configurable' aspect on the Person linked to this user.
 */
synchronized NodeRef getUserPreferencesRef(WebApplicationContext context) {
    final ServiceRegistry registry = (ServiceRegistry) context.getBean("ServiceRegistry");
    final NodeService nodeService = registry.getNodeService();
    final SearchService searchService = registry.getSearchService();
    final NamespaceService namespaceService = registry.getNamespaceService();
    final TransactionService txService = registry.getTransactionService();
    final ConfigurableService configurableService = (ConfigurableService) context.getBean("ConfigurableService");
    RetryingTransactionHelper txnHelper = registry.getTransactionService().getRetryingTransactionHelper();
    return txnHelper.doInTransaction(new RetryingTransactionCallback<NodeRef>() {

        public NodeRef execute() throws Throwable {
            NodeRef prefRef = null;
            NodeRef person = getPerson();
            if (nodeService.hasAspect(person, ApplicationModel.ASPECT_CONFIGURABLE) == false) {
                // if the repository is in read-only mode just return null
                if (txService.isReadOnly()) {
                    return null;
                } else {
                    // create the configuration folder for this Person node
                    configurableService.makeConfigurable(person);
                }
            }
            // target of the assoc is the configurations folder ref
            NodeRef configRef = configurableService.getConfigurationFolder(person);
            if (configRef == null) {
                throw new IllegalStateException("Unable to find associated 'configurations' folder for node: " + person);
            }
            String xpath = NamespaceService.APP_MODEL_PREFIX + ":" + "preferences";
            List<NodeRef> nodes = searchService.selectNodes(configRef, xpath, null, namespaceService, false);
            if (nodes.size() == 1) {
                prefRef = nodes.get(0);
            } else {
                // create the preferences Node for this user (if repo is not read-only)
                if (txService.isReadOnly() == false) {
                    ChildAssociationRef childRef = nodeService.createNode(configRef, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.APP_MODEL_1_0_URI, "preferences"), ContentModel.TYPE_CMOBJECT);
                    prefRef = childRef.getChildRef();
                }
            }
            return prefRef;
        }
    }, txService.isReadOnly());
}
Also used : TransactionService(org.alfresco.service.transaction.TransactionService) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) NodeService(org.alfresco.service.cmr.repository.NodeService) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) NamespaceService(org.alfresco.service.namespace.NamespaceService) SearchService(org.alfresco.service.cmr.search.SearchService) List(java.util.List) ServiceRegistry(org.alfresco.service.ServiceRegistry) ConfigurableService(org.alfresco.repo.configuration.ConfigurableService)

Aggregations

SearchService (org.alfresco.service.cmr.search.SearchService)11 NodeService (org.alfresco.service.cmr.repository.NodeService)7 NodeRef (org.alfresco.service.cmr.repository.NodeRef)6 TransactionService (org.alfresco.service.transaction.TransactionService)6 HashMap (java.util.HashMap)5 FileFolderService (org.alfresco.service.cmr.model.FileFolderService)5 NamespaceService (org.alfresco.service.namespace.NamespaceService)5 ResultSet (org.alfresco.service.cmr.search.ResultSet)4 Before (org.junit.Before)4 ServiceDescriptorRegistry (org.alfresco.repo.service.ServiceDescriptorRegistry)3 QuickShareLinksImpl (org.alfresco.rest.api.impl.QuickShareLinksImpl)3 QuickShareLink (org.alfresco.rest.api.model.QuickShareLink)3 HttpResponse (org.alfresco.rest.api.tests.client.HttpResponse)3 Paging (org.alfresco.rest.api.tests.client.PublicApiClient.Paging)3 Test (org.junit.Test)3 InputStream (java.io.InputStream)2 PublicApiClient (org.alfresco.rest.api.tests.client.PublicApiClient)2 Favourite (org.alfresco.rest.api.tests.client.data.Favourite)2 ServiceRegistry (org.alfresco.service.ServiceRegistry)2 LockService (org.alfresco.service.cmr.lock.LockService)2