Search in sources :

Example 56 with StoreRef

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

the class StreamContent method createObjectReferenceFromUrl.

protected ObjectReference createObjectReferenceFromUrl(Map<String, String> args, Map<String, String> templateArgs) {
    String objectId = args.get("noderef");
    if (objectId != null) {
        return new ObjectReference(objectId);
    }
    StoreRef storeRef = null;
    String store_type = templateArgs.get("store_type");
    String store_id = templateArgs.get("store_id");
    if (store_type != null && store_id != null) {
        storeRef = new StoreRef(store_type, store_id);
    }
    String id = templateArgs.get("id");
    if (storeRef != null && id != null) {
        return new ObjectReference(storeRef, id);
    }
    String nodepath = templateArgs.get("nodepath");
    if (nodepath == null) {
        nodepath = args.get("nodepath");
    }
    if (storeRef != null && nodepath != null) {
        return new ObjectReference(storeRef, nodepath.split("/"));
    }
    return null;
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef)

Example 57 with StoreRef

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

the class NodeArchiveServiceRestApiTest method createTestStoreAndGetRootNode.

private NodeRef createTestStoreAndGetRootNode() {
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    StoreRef workStoreRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, getName() + System.currentTimeMillis());
    workStoreRootNodeRef = nodeService.getRootNode(workStoreRef);
    StoreRef archiveStoreRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "archive" + getName() + System.currentTimeMillis());
    archiveMap.put(workStoreRef, archiveStoreRef);
    createdStores.add(workStoreRef);
    createdStores.add(archiveStoreRef);
    return workStoreRootNodeRef;
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef)

Example 58 with StoreRef

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

the class NodeArchiveServiceRestApiTest method tearDown.

@Override
public void tearDown() throws Exception {
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    super.tearDown();
    // Tidy up any test nodes that are hanging around.
    transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {

        public Void execute() throws Throwable {
            AuthenticationUtil.runAs(new RunAsWork<Void>() {

                public Void doWork() throws Exception {
                    for (NodeRef nodeRef : createdNodes) {
                        if (nodeRef != null && nodeService.exists(nodeRef)) {
                            nodeService.deleteNode(nodeRef);
                        }
                    }
                    for (StoreRef store : createdStores) {
                        if (store != null && nodeService.exists(store)) {
                            nodeService.deleteStore(store);
                        }
                    }
                    return null;
                }
            }, AuthenticationUtil.getSystemUserName());
            return null;
        }
    });
    // Delete users
    for (String userName : this.createdPeople) {
        personService.deletePerson(userName);
    }
    // Clear the lists
    this.createdPeople.clear();
    this.createdNodes.clear();
    this.createdStores.clear();
    AuthenticationUtil.clearCurrentSecurityContext();
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) StoreRef(org.alfresco.service.cmr.repository.StoreRef) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) RunAsWork(org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork)

Example 59 with StoreRef

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

the class WebDAVMethodTest method checkLockedNodeTestTenantWork.

private void checkLockedNodeTestTenantWork() throws Exception {
    req = new MockHttpServletRequest();
    resp = new MockHttpServletResponse();
    String rootPath = "/app:company_home";
    String storeName = "workspace://SpacesStore";
    StoreRef storeRef = new StoreRef(storeName);
    NodeRef storeRootNodeRef = nodeService.getRootNode(storeRef);
    List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, rootPath, null, namespaceService, false);
    NodeRef defaultRootNode = nodeRefs.get(0);
    lockMethod = new LockMethod();
    NodeRef rootNodeRef = tenantService.getRootNode(nodeService, searchService, namespaceService, rootPath, defaultRootNode);
    String strPath = "/" + "testLockedNode" + GUID.generate();
    lockMethod.createExclusive = true;
    lockMethod.setDetails(req, resp, webDAVHelper, rootNodeRef);
    lockMethod.m_strPath = strPath;
    // Lock the node (will create a new one).
    transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Object>() {

        @Override
        public Object execute() throws Throwable {
            lockMethod.executeImpl();
            return null;
        }
    });
    // Prepare for DELETE
    String corruptedLockToken = lockMethod.lockToken + "corr";
    req.addHeader(WebDAV.HEADER_IF, "(<" + corruptedLockToken + ">)");
    deleteMethod = new DeleteMethod();
    deleteMethod.setDetails(req, resp, webDAVHelper, rootNodeRef);
    deleteMethod.parseRequestHeaders();
    deleteMethod.m_strPath = strPath;
    // can't be deleted with corrupted lockTocken
    try {
        transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Object>() {

            @Override
            public Object execute() throws Throwable {
                deleteMethod.executeImpl();
                return null;
            }
        });
        fail("Locked node shouldn't be deleted");
    } catch (Exception e) {
        if (!(e.getCause() instanceof WebDAVServerException)) {
            throw e;
        }
    }
    req = new MockHttpServletRequest();
    req.addHeader(WebDAV.HEADER_LOCK_TOKEN, lockMethod.lockToken);
    unlockMethod = new UnlockMethod();
    unlockMethod.setDetails(req, resp, webDAVHelper, rootNodeRef);
    unlockMethod.parseRequestHeaders();
    unlockMethod.m_strPath = strPath;
    // unlock the node
    try {
        transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Object>() {

            @Override
            public Object execute() throws Throwable {
                unlockMethod.executeImpl();
                return null;
            }
        });
    } catch (Exception e) {
        fail("Locked node should be unlocked with correct lockTocken " + e.getCause());
    }
    // Lock it again
    transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Object>() {

        @Override
        public Object execute() throws Throwable {
            lockMethod.executeImpl();
            return null;
        }
    });
    req.addHeader(WebDAV.HEADER_IF, "(<" + lockMethod.lockToken + ">)");
    deleteMethod = new DeleteMethod();
    deleteMethod.setDetails(req, resp, webDAVHelper, rootNodeRef);
    deleteMethod.parseRequestHeaders();
    deleteMethod.m_strPath = strPath;
    // can be deleted with correct lockTocken
    try {
        transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Object>() {

            @Override
            public Object execute() throws Throwable {
                deleteMethod.executeImpl();
                return null;
            }
        });
    } catch (Exception e) {
        fail("Locked node should be deleted with correct lockTocken " + e.getCause());
    }
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) NodeRef(org.alfresco.service.cmr.repository.NodeRef) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 60 with StoreRef

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

the class NodeLocatorWebScriptTest method makeUrl.

private String makeUrl(NodeRef node, String locatorName) {
    StoreRef storeRef = node.getStoreRef();
    StringBuilder url = new StringBuilder("/api/");
    url.append(storeRef.getProtocol()).append("/").append(storeRef.getIdentifier()).append("/").append(node.getId()).append("/").append("nodelocator").append("/").append(locatorName);
    return url.toString();
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef)

Aggregations

StoreRef (org.alfresco.service.cmr.repository.StoreRef)67 NodeRef (org.alfresco.service.cmr.repository.NodeRef)50 HashMap (java.util.HashMap)18 QName (org.alfresco.service.namespace.QName)17 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)13 StringPropertyValue (org.alfresco.solr.client.StringPropertyValue)13 PropertyValue (org.alfresco.solr.client.PropertyValue)11 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)10 ArrayList (java.util.ArrayList)9 ContentPropertyValue (org.alfresco.solr.client.ContentPropertyValue)9 MLTextPropertyValue (org.alfresco.solr.client.MLTextPropertyValue)9 IOException (java.io.IOException)7 Date (java.util.Date)6 MultiPropertyValue (org.alfresco.solr.client.MultiPropertyValue)6 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)5 PermissionService (org.alfresco.service.cmr.security.PermissionService)5 SolrCore (org.apache.solr.core.SolrCore)5 StringTokenizer (java.util.StringTokenizer)4 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)4 ServiceRegistry (org.alfresco.service.ServiceRegistry)4