Search in sources :

Example 1 with NodeService

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

the class AdminWebScriptTest method testResidualProperties.

@Test
public // ALF-21950 We check now if the property belongs to the type of the node
void testResidualProperties() throws Exception {
    NodeBrowserPost nodeBrowserPost = new NodeBrowserPost();
    DictionaryService dictionaryService = mock(DictionaryService.class);
    NodeService nodeService = mock(NodeService.class);
    nodeBrowserPost.setDictionaryService(dictionaryService);
    nodeBrowserPost.setNodeService(nodeService);
    // make own class definition from origin type
    ClassDefinition classDefinition = mock(ClassDefinition.class);
    when(dictionaryService.getClass(any())).thenReturn(classDefinition);
    QName qnameResidualFalse1 = QName.createQName("testResidualProperties", "residualFalse1");
    QName qnameResidualFalse2 = QName.createQName("testResidualProperties", "residualFalse2");
    QName qnameResidualTrue1 = QName.createQName("testResidualProperties", "residualTrue1");
    QName qnameResidualTrue2 = QName.createQName("testResidualProperties", "residualTrue2");
    // Define residual False properties inside of class definition
    // That simulates the belonging of the properties to a given type of a node
    Map<QName, PropertyDefinition> properties = new HashMap<>();
    properties.put(qnameResidualFalse1, new SimplePropertyDefinition(false));
    properties.put(qnameResidualFalse2, new SimplePropertyDefinition(true));
    when(classDefinition.getProperties()).thenReturn(properties);
    when(dictionaryService.getProperty(eq(qnameResidualFalse1))).thenReturn(new SimplePropertyDefinition(false));
    when(dictionaryService.getProperty(eq(qnameResidualFalse2))).thenReturn(new SimplePropertyDefinition(true));
    when(dictionaryService.getProperty(eq(qnameResidualTrue1))).thenReturn(new SimplePropertyDefinition(true));
    when(dictionaryService.getProperty(eq(qnameResidualTrue2))).thenReturn(new SimplePropertyDefinition(false));
    // property found in definition so it is not residual
    String value = "abc";
    NodeBrowserPost.Property property = nodeBrowserPost.new Property(qnameResidualFalse1, value, null);
    assertFalse(property.getResidual());
    // property belongs to an aspect so it is not residual
    property = nodeBrowserPost.new Property(qnameResidualFalse2, value, null);
    assertFalse(property.getResidual());
    // property not found in definition but it is an aspect so it is not residual
    property = nodeBrowserPost.new Property(qnameResidualTrue1, value, null);
    assertFalse(property.getResidual());
    // property not found in definition so it is residual
    property = nodeBrowserPost.new Property(qnameResidualTrue2, value, null);
    assertTrue(property.getResidual());
}
Also used : DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) NodeService(org.alfresco.service.cmr.repository.NodeService) ClassDefinition(org.alfresco.service.cmr.dictionary.ClassDefinition) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) BaseWebScriptTest(org.alfresco.repo.web.scripts.BaseWebScriptTest) Test(org.junit.Test)

Example 2 with NodeService

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

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

the class ResultMapperTests method mockResultset.

private ResultSet mockResultset(String json) throws Exception {
    NodeService nodeService = mock(NodeService.class);
    JSONObject jsonObj = new JSONObject(new JSONTokener(json));
    SearchParameters sp = new SearchParameters();
    sp.setBulkFetchEnabled(false);
    ResultSet results = new SolrJSONResultSet(jsonObj, sp, nodeService, null, LimitBy.FINAL_SIZE, 10);
    return results;
}
Also used : JSONTokener(org.json.JSONTokener) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) JSONObject(org.json.JSONObject) NodeService(org.alfresco.service.cmr.repository.NodeService) ResultSet(org.alfresco.service.cmr.search.ResultSet) EmptyResultSet(org.alfresco.repo.search.EmptyResultSet) SolrJSONResultSet(org.alfresco.repo.search.impl.lucene.SolrJSONResultSet) SolrJSONResultSet(org.alfresco.repo.search.impl.lucene.SolrJSONResultSet)

Example 4 with NodeService

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

the class ResultMapperTests method mockResultset.

private ResultSet mockResultset(List<Long> archivedNodes, List<Long> versionNodes) throws JSONException {
    NodeService nodeService = mock(NodeService.class);
    when(nodeService.getNodeRef(any())).thenAnswer(new Answer<NodeRef>() {

        @Override
        public NodeRef answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            // If the DBID is in the list archivedNodes, instead of returning a noderef return achivestore noderef
            if (archivedNodes.contains(args[0]))
                return new NodeRef(StoreRef.STORE_REF_ARCHIVE_SPACESSTORE, GUID.generate());
            if (versionNodes.contains(args[0]))
                return new NodeRef(StoreMapper.STORE_REF_VERSION2_SPACESSTORE, GUID.generate() + args[0]);
            return new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, GUID.generate());
        }
    });
    SearchParameters sp = new SearchParameters();
    sp.setBulkFetchEnabled(false);
    JSONObject json = new JSONObject(new JSONTokener(JSON_REPONSE));
    ResultSet results = new SolrJSONResultSet(json, sp, nodeService, null, LimitBy.FINAL_SIZE, 10);
    return results;
}
Also used : JSONTokener(org.json.JSONTokener) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) JSONObject(org.json.JSONObject) InvocationOnMock(org.mockito.invocation.InvocationOnMock) NodeService(org.alfresco.service.cmr.repository.NodeService) ResultSet(org.alfresco.service.cmr.search.ResultSet) EmptyResultSet(org.alfresco.repo.search.EmptyResultSet) SolrJSONResultSet(org.alfresco.repo.search.impl.lucene.SolrJSONResultSet) SolrJSONResultSet(org.alfresco.repo.search.impl.lucene.SolrJSONResultSet)

Example 5 with NodeService

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

the class ResultMapperTests method setupTests.

@BeforeClass
public static void setupTests() throws Exception {
    Map<String, UserInfo> mapUserInfo = new HashMap<>();
    mapUserInfo.put(AuthenticationUtil.getSystemUserName(), new UserInfo(AuthenticationUtil.getSystemUserName(), "sys", "sys"));
    Map<QName, Serializable> nodeProps = new HashMap<>();
    NodesImpl nodes = mock(NodesImpl.class);
    ServiceRegistry sr = mock(ServiceRegistry.class);
    DeletedNodes deletedNodes = mock(DeletedNodes.class);
    nodes.setServiceRegistry(sr);
    VersionService versionService = mock(VersionService.class);
    VersionHistory versionHistory = mock(VersionHistory.class);
    Map<String, Serializable> versionProperties = new HashMap<>();
    versionProperties.put(Version.PROP_DESCRIPTION, "ver desc");
    versionProperties.put(Version2Model.PROP_VERSION_TYPE, "v type");
    when(versionHistory.getVersion(anyString())).thenAnswer(invocation -> {
        return new VersionImpl(versionProperties, new NodeRef(StoreMapper.STORE_REF_VERSION2_SPACESSTORE, GUID.generate()));
    });
    NodeService nodeService = mock(NodeService.class);
    when(versionService.getVersionHistory(notNull(NodeRef.class))).thenAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        NodeRef aNode = (NodeRef) args[0];
        return versionHistory;
    });
    when(nodeService.getProperties(notNull(NodeRef.class))).thenAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        NodeRef aNode = (NodeRef) args[0];
        if (StoreMapper.STORE_REF_VERSION2_SPACESSTORE.equals(aNode.getStoreRef())) {
            nodeProps.put(Version2Model.PROP_QNAME_FROZEN_NODE_REF, new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, FROZEN_ID + aNode.getId()));
            nodeProps.put(Version2Model.PROP_QNAME_VERSION_LABEL, FROZEN_VER);
        }
        return nodeProps;
    });
    when(sr.getVersionService()).thenReturn(versionService);
    when(sr.getNodeService()).thenReturn(nodeService);
    when(nodes.validateOrLookupNode(notNull(String.class), anyString())).thenAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        String aNode = (String) args[0];
        if (aNode.endsWith("" + VERSIONED_ID)) {
            throw new EntityNotFoundException("" + VERSIONED_ID);
        } else {
            return new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, aNode);
        }
    });
    // // NodeRef nodeRef = nodes.validateOrLookupNode(nodeId, null);
    when(nodes.getFolderOrDocument(notNull(NodeRef.class), any(), any(), any(), any())).thenAnswer(new Answer<Node>() {

        @Override
        public Node answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            NodeRef aNode = (NodeRef) args[0];
            if (StoreRef.STORE_REF_ARCHIVE_SPACESSTORE.equals(aNode.getStoreRef())) {
                // Return NULL if its from the archive store.
                return null;
            }
            return new Node(aNode, (NodeRef) args[1], nodeProps, mapUserInfo, sr);
        }
    });
    when(deletedNodes.getDeletedNode(notNull(String.class), any(), anyBoolean(), any())).thenAnswer(new Answer<Node>() {

        @Override
        public Node answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            String nodeId = (String) args[0];
            if (FROZEN_ID.equals(nodeId))
                throw new EntityNotFoundException(nodeId);
            NodeRef aNode = new NodeRef(StoreRef.STORE_REF_ARCHIVE_SPACESSTORE, nodeId);
            return new Node(aNode, new NodeRef(StoreRef.STORE_REF_ARCHIVE_SPACESSTORE, "unknown"), nodeProps, mapUserInfo, sr);
        }
    });
    PersonPropertyLookup propertyLookups = mock(PersonPropertyLookup.class);
    when(propertyLookups.supports()).thenReturn(Stream.of("creator", "modifier").collect(Collectors.toSet()));
    when(propertyLookups.lookup(notNull(String.class))).thenAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        String value = (String) args[0];
        if ("mjackson".equals(value))
            return "Michael Jackson";
        return null;
    });
    PropertyLookupRegistry propertyLookupRegistry = new PropertyLookupRegistry();
    propertyLookupRegistry.setLookups(Arrays.asList(propertyLookups));
    mapper = new ResultMapper();
    mapper.setNodes(nodes);
    mapper.setStoreMapper(new StoreMapper());
    mapper.setPropertyLookup(propertyLookupRegistry);
    mapper.setDeletedNodes(deletedNodes);
    mapper.setServiceRegistry(sr);
    NodeVersionsRelation nodeVersionsRelation = new NodeVersionsRelation();
    nodeVersionsRelation.setNodes(nodes);
    nodeVersionsRelation.setServiceRegistry(sr);
    nodeVersionsRelation.afterPropertiesSet();
    mapper.setNodeVersions(nodeVersionsRelation);
    helper = new SerializerTestHelper();
    searchMapper.setStoreMapper(new StoreMapper());
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) Node(org.alfresco.rest.api.model.Node) StoreMapper(org.alfresco.rest.api.search.impl.StoreMapper) VersionService(org.alfresco.service.cmr.version.VersionService) UserInfo(org.alfresco.rest.api.model.UserInfo) Matchers.anyString(org.mockito.Matchers.anyString) VersionImpl(org.alfresco.repo.version.common.VersionImpl) NodeRef(org.alfresco.service.cmr.repository.NodeRef) DeletedNodes(org.alfresco.rest.api.DeletedNodes) QName(org.alfresco.service.namespace.QName) PersonPropertyLookup(org.alfresco.rest.api.lookups.PersonPropertyLookup) NodeService(org.alfresco.service.cmr.repository.NodeService) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) VersionHistory(org.alfresco.service.cmr.version.VersionHistory) NodesImpl(org.alfresco.rest.api.impl.NodesImpl) PropertyLookupRegistry(org.alfresco.rest.api.lookups.PropertyLookupRegistry) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ResultMapper(org.alfresco.rest.api.search.impl.ResultMapper) JSONObject(org.json.JSONObject) ServiceRegistry(org.alfresco.service.ServiceRegistry) NodeVersionsRelation(org.alfresco.rest.api.nodes.NodeVersionsRelation) BeforeClass(org.junit.BeforeClass)

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