Search in sources :

Example 6 with TransactionService

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

the class DeleteSpaceDialog method finishImpl.

@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception {
    final boolean isAdmin = this.navigator.getCurrentUser().isAdmin();
    // get the space to delete
    Node node = this.browseBean.getActionSpace();
    if (node != null) {
        // force cache of name property so we can use it after the delete
        node.getName();
        if (logger.isDebugEnabled())
            logger.debug("Trying to delete space: " + node.getId() + " using delete mode: " + this.deleteMode);
        try {
            if (isAdmin && !this.executeRules) {
                Repository.getServiceRegistry(context).getRuleService().disableRules();
            }
            if (DELETE_ALL.equals(this.deleteMode)) {
                NodeRef nodeRef = node.getNodeRef();
                // Check the node still exists
                if (this.getNodeService().exists(nodeRef)) {
                    if (isAdmin && !this.archiveNodes) {
                        this.getNodeService().addAspect(node.getNodeRef(), ContentModel.ASPECT_TEMPORARY, null);
                    }
                    // ensure the node still exists before deleting
                    if (this.getNodeService().exists(node.getNodeRef())) {
                        this.getNodeService().deleteNode(node.getNodeRef());
                    }
                }
            } else {
                List<ChildAssociationRef> childRefs = this.getNodeService().getChildAssocs(node.getNodeRef(), ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
                List<NodeRef> deleteRefs = new ArrayList<NodeRef>(childRefs.size());
                for (ChildAssociationRef ref : childRefs) {
                    NodeRef nodeRef = ref.getChildRef();
                    if (this.getNodeService().exists(nodeRef)) {
                        if (DELETE_CONTENTS.equals(this.deleteMode)) {
                            deleteRefs.add(nodeRef);
                        } else {
                            // find it's type so we can see if it's a node we are interested in
                            QName type = this.getNodeService().getType(nodeRef);
                            // make sure the type is defined in the data dictionary
                            TypeDefinition typeDef = this.getDictionaryService().getType(type);
                            if (typeDef != null) {
                                if (DELETE_FOLDERS.equals(this.deleteMode)) {
                                    // look for folder type
                                    if (this.getDictionaryService().isSubClass(type, ContentModel.TYPE_FOLDER) == true && this.getDictionaryService().isSubClass(type, ContentModel.TYPE_SYSTEM_FOLDER) == false) {
                                        deleteRefs.add(nodeRef);
                                    }
                                } else if (DELETE_FILES.equals(this.deleteMode)) {
                                    // look for content file type
                                    if (this.getDictionaryService().isSubClass(type, ContentModel.TYPE_CONTENT)) {
                                        deleteRefs.add(nodeRef);
                                    }
                                }
                            }
                        }
                    }
                }
                // delete the list of refs
                TransactionService txService = Repository.getServiceRegistry(context).getTransactionService();
                for (NodeRef nodeRef : deleteRefs) {
                    UserTransaction tx = null;
                    try {
                        tx = txService.getNonPropagatingUserTransaction();
                        tx.begin();
                        if (isAdmin && !this.archiveNodes) {
                            this.getNodeService().addAspect(nodeRef, ContentModel.ASPECT_TEMPORARY, null);
                        }
                        // ensure the node still exists before deleting
                        if (this.getNodeService().exists(node.getNodeRef())) {
                            this.getNodeService().deleteNode(nodeRef);
                        }
                        tx.commit();
                    } catch (Throwable err) {
                        try {
                            if (tx != null) {
                                tx.rollback();
                            }
                        } catch (Exception ex) {
                        }
                    }
                }
            }
        } finally {
            if (isAdmin && !this.executeRules) {
                Repository.getServiceRegistry(context).getRuleService().enableRules();
            }
        }
    } else {
        logger.warn("WARNING: delete called without a current Space!");
    }
    return outcome;
}
Also used : UserTransaction(javax.transaction.UserTransaction) TransactionService(org.alfresco.service.transaction.TransactionService) QName(org.alfresco.service.namespace.QName) Node(org.alfresco.web.bean.repository.Node) ArrayList(java.util.ArrayList) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) NodeRef(org.alfresco.service.cmr.repository.NodeRef)

Example 7 with TransactionService

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

the class BaseActionEvaluator method evaluate.

public boolean evaluate(final Object obj) {
    if (obj instanceof Node) {
        RetryingTransactionCallback<Boolean> txnCallback = new RetryingTransactionCallback<Boolean>() {

            @Override
            public Boolean execute() throws Throwable {
                return evaluate((Node) obj);
            }
        };
        TransactionService txnService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getTransactionService();
        return txnService.getRetryingTransactionHelper().doInTransaction(txnCallback, true, true);
    } else {
        return true;
    }
}
Also used : TransactionService(org.alfresco.service.transaction.TransactionService) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) Node(org.alfresco.web.bean.repository.Node)

Example 8 with TransactionService

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

Example 9 with TransactionService

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

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

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