Search in sources :

Example 1 with TransactionService

use of org.alfresco.service.transaction.TransactionService in project acs-community-packaging by Alfresco.

the class DownloadContentServlet method doGet.

/**
 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 */
protected void doGet(final HttpServletRequest req, final HttpServletResponse res) throws ServletException, IOException {
    if (logger.isDebugEnabled()) {
        String queryString = req.getQueryString();
        logger.debug("Authenticating (GET) request to URL: " + req.getRequestURI() + ((queryString != null && queryString.length() > 0) ? ("?" + queryString) : ""));
    }
    AuthenticationStatus status = servletAuthenticate(req, res);
    if (status == AuthenticationStatus.Failure) {
        return;
    }
    ServiceRegistry serviceRegistry = getServiceRegistry(getServletContext());
    TransactionService transactionService = serviceRegistry.getTransactionService();
    RetryingTransactionCallback<Void> processCallback = new RetryingTransactionCallback<Void>() {

        public Void execute() throws Throwable {
            processDownloadRequest(req, res, true, true);
            return null;
        }
    };
    transactionService.getRetryingTransactionHelper().doInTransaction(processCallback, true);
}
Also used : TransactionService(org.alfresco.service.transaction.TransactionService) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) ServiceRegistry(org.alfresco.service.ServiceRegistry)

Example 2 with TransactionService

use of org.alfresco.service.transaction.TransactionService in project acs-community-packaging by Alfresco.

the class DownloadContentServlet method doHead.

/* (non-Javadoc)
    * @see javax.servlet.http.HttpServlet#doHead(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
    */
@Override
protected void doHead(final HttpServletRequest req, final HttpServletResponse res) throws ServletException, IOException {
    if (logger.isDebugEnabled()) {
        String queryString = req.getQueryString();
        logger.debug("Authenticating (HEAD) request to URL: " + req.getRequestURI() + ((queryString != null && queryString.length() > 0) ? ("?" + queryString) : ""));
    }
    AuthenticationStatus status = servletAuthenticate(req, res);
    if (status == AuthenticationStatus.Failure) {
        return;
    }
    ServiceRegistry serviceRegistry = getServiceRegistry(getServletContext());
    TransactionService transactionService = serviceRegistry.getTransactionService();
    RetryingTransactionCallback<Void> processCallback = new RetryingTransactionCallback<Void>() {

        public Void execute() throws Throwable {
            processDownloadRequest(req, res, true, false);
            return null;
        }
    };
    transactionService.getRetryingTransactionHelper().doInTransaction(processCallback, true);
}
Also used : TransactionService(org.alfresco.service.transaction.TransactionService) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) ServiceRegistry(org.alfresco.service.ServiceRegistry)

Example 3 with TransactionService

use of org.alfresco.service.transaction.TransactionService in project records-management by Alfresco.

the class FreezeServiceImpl method hasFrozenChildren.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.freeze.FreezeService#hasFrozenChildren(org.alfresco.service.cmr.repository.NodeRef)
 */
@Override
public boolean hasFrozenChildren(final NodeRef nodeRef) {
    ParameterCheck.mandatory("nodeRef", nodeRef);
    boolean result = false;
    // check that we are dealing with a record folder
    if (isRecordFolder(nodeRef)) {
        int heldCount = 0;
        if (nodeService.hasAspect(nodeRef, ASPECT_HELD_CHILDREN)) {
            heldCount = (Integer) getInternalNodeService().getProperty(nodeRef, PROP_HELD_CHILDREN_COUNT);
        } else {
            final TransactionService transactionService = (TransactionService) applicationContext.getBean("transactionService");
            heldCount = AuthenticationUtil.runAsSystem(new RunAsWork<Integer>() {

                @Override
                public Integer doWork() {
                    return transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Integer>() {

                        public Integer execute() throws Throwable {
                            int heldCount = 0;
                            // NOTE: this process remains to 'patch' older systems to improve performance next time around
                            List<ChildAssociationRef> childAssocs = getInternalNodeService().getChildAssocs(nodeRef, ContentModel.ASSOC_CONTAINS, null);
                            if (childAssocs != null && !childAssocs.isEmpty()) {
                                for (ChildAssociationRef childAssociationRef : childAssocs) {
                                    NodeRef record = childAssociationRef.getChildRef();
                                    if (childAssociationRef.isPrimary() && isRecord(record) && isFrozen(record)) {
                                        heldCount++;
                                    }
                                }
                            }
                            // add aspect and set count
                            Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
                            props.put(PROP_HELD_CHILDREN_COUNT, heldCount);
                            getInternalNodeService().addAspect(nodeRef, ASPECT_HELD_CHILDREN, props);
                            return heldCount;
                        }
                    }, false, true);
                }
            });
        }
        // true if more than one child held
        result = (heldCount > 0);
    }
    return result;
}
Also used : Serializable(java.io.Serializable) TransactionService(org.alfresco.service.transaction.TransactionService) RunAsWork(org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork) QName(org.alfresco.service.namespace.QName) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with TransactionService

use of org.alfresco.service.transaction.TransactionService 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 5 with TransactionService

use of org.alfresco.service.transaction.TransactionService 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)

Aggregations

TransactionService (org.alfresco.service.transaction.TransactionService)12 NodeRef (org.alfresco.service.cmr.repository.NodeRef)6 NodeService (org.alfresco.service.cmr.repository.NodeService)6 SearchService (org.alfresco.service.cmr.search.SearchService)6 NamespaceService (org.alfresco.service.namespace.NamespaceService)5 Before (org.junit.Before)5 ServiceRegistry (org.alfresco.service.ServiceRegistry)4 FileFolderService (org.alfresco.service.cmr.model.FileFolderService)4 HashMap (java.util.HashMap)3 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)3 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)3 QName (org.alfresco.service.namespace.QName)3 InputStream (java.io.InputStream)2 Serializable (java.io.Serializable)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 UserTransaction (javax.transaction.UserTransaction)2 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)2 LockService (org.alfresco.service.cmr.lock.LockService)2 ContentService (org.alfresco.service.cmr.repository.ContentService)2