Search in sources :

Example 1 with SimpleCache

use of org.alfresco.repo.cache.SimpleCache in project alfresco-repository by Alfresco.

the class UpgradePasswordHashTest method setUp.

public void setUp() throws Exception {
    if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE) {
        throw new AlfrescoRuntimeException("A previous tests did not clean up transaction: " + AlfrescoTransactionSupport.getTransactionId());
    }
    serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
    SimpleCache<String, RepositoryAuthenticationDao.CacheEntry> authenticationCache = (SimpleCache<String, RepositoryAuthenticationDao.CacheEntry>) ctx.getBean("authenticationCache");
    SimpleCache<String, NodeRef> immutableSingletonCache = (SimpleCache<String, NodeRef>) ctx.getBean("immutableSingletonCache");
    TenantService tenantService = (TenantService) ctx.getBean("tenantService");
    compositePasswordEncoder = (CompositePasswordEncoder) ctx.getBean("compositePasswordEncoder");
    PolicyComponent policyComponent = (PolicyComponent) ctx.getBean("policyComponent");
    repositoryAuthenticationDao = new RepositoryAuthenticationDao();
    repositoryAuthenticationDao.setTransactionService(serviceRegistry.getTransactionService());
    repositoryAuthenticationDao.setAuthorityService(serviceRegistry.getAuthorityService());
    repositoryAuthenticationDao.setTenantService(tenantService);
    repositoryAuthenticationDao.setNodeService(serviceRegistry.getNodeService());
    repositoryAuthenticationDao.setNamespaceService(serviceRegistry.getNamespaceService());
    repositoryAuthenticationDao.setCompositePasswordEncoder(compositePasswordEncoder);
    repositoryAuthenticationDao.setPolicyComponent(policyComponent);
    repositoryAuthenticationDao.setAuthenticationCache(authenticationCache);
    repositoryAuthenticationDao.setSingletonCache(immutableSingletonCache);
    upgradePasswordHashWorker = (UpgradePasswordHashWorker) ctx.getBean("upgradePasswordHashWorker");
    nodeService = serviceRegistry.getNodeService();
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) TenantService(org.alfresco.repo.tenant.TenantService) PolicyComponent(org.alfresco.repo.policy.PolicyComponent) SimpleCache(org.alfresco.repo.cache.SimpleCache) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 2 with SimpleCache

use of org.alfresco.repo.cache.SimpleCache in project alfresco-repository by Alfresco.

the class FileSourceImporter method doImport.

@SuppressWarnings("unchecked")
public void doImport() {
    UserTransaction userTransaction = null;
    try {
        long start = System.nanoTime();
        userTransaction = transactionService.getUserTransaction();
        userTransaction.begin();
        authenticationContext.setSystemUserAsCurrentUser();
        if (clearAllChildren) {
            List<NodeRef> refs = searchService.selectNodes(nodeService.getRootNode(storeRef), path, null, namespacePrefixResolver, false);
            for (NodeRef ref : refs) {
                for (ChildAssociationRef car : nodeService.getChildAssocs(ref)) {
                    nodeService.deleteNode(car.getChildRef());
                }
            }
        }
        if (caches != null) {
            for (SimpleCache cache : caches) {
                cache.clear();
            }
        }
        Reader reader = new BufferedReader(new FileReader(fileLocation));
        Location location = new Location(storeRef);
        location.setPath(path);
        importerService.importView(reader, location, REPLACE_BINDING, null);
        reader.close();
        if (caches != null) {
            for (SimpleCache cache : caches) {
                cache.clear();
            }
        }
        userTransaction.commit();
        long end = System.nanoTime();
        s_logger.info("Imported " + fileLocation + " in " + ((end - start) / 1e9f) + " seconds");
    } catch (Throwable t) {
        try {
            if (userTransaction != null) {
                userTransaction.rollback();
            }
        } catch (Exception ex) {
        }
        try {
            authenticationContext.clearCurrentSecurityContext();
        } catch (Exception ex) {
        }
        throw new ExportSourceImporterException("Failed to import", t);
    } finally {
        authenticationContext.clearCurrentSecurityContext();
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) Reader(java.io.Reader) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SimpleCache(org.alfresco.repo.cache.SimpleCache) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) Location(org.alfresco.service.cmr.view.Location)

Example 3 with SimpleCache

use of org.alfresco.repo.cache.SimpleCache in project alfresco-repository by Alfresco.

the class ExportSourceImporter method doImport.

@SuppressWarnings("unchecked")
public void doImport() {
    UserTransaction userTransaction = null;
    try {
        AuthenticationUtil.pushAuthentication();
        userTransaction = transactionService.getUserTransaction();
        userTransaction.begin();
        AuthenticationUtil.setRunAsUserSystem();
        if (clearAllChildren) {
            logger.debug("clear all children");
            List<NodeRef> refs = searchService.selectNodes(nodeService.getRootNode(storeRef), path, null, namespacePrefixResolver, false);
            for (NodeRef ref : refs) {
                if (logger.isDebugEnabled()) {
                    logger.debug("clear node ref" + ref);
                }
                for (ChildAssociationRef car : nodeService.getChildAssocs(ref)) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("delete child" + car.getChildRef());
                    }
                    nodeService.deleteNode(car.getChildRef());
                }
            }
        }
        if (caches != null) {
            logger.debug("clearing caches");
            for (SimpleCache cache : caches) {
                cache.clear();
            }
        }
        File tempFile = TempFileProvider.createTempFile("ExportSourceImporter-", ".xml");
        Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(tempFile), "UTF-8"));
        XMLWriter xmlWriter = createXMLExporter(writer);
        exportSource.generateExport(xmlWriter);
        xmlWriter.close();
        Reader reader = new BufferedReader(new InputStreamReader(new FileInputStream(tempFile), "UTF-8"));
        Location location = new Location(storeRef);
        location.setPath(path);
        importerService.importView(reader, location, REPLACE_BINDING, null);
        reader.close();
        if (caches != null) {
            for (SimpleCache cache : caches) {
                cache.clear();
            }
        }
        logger.debug("about to commit");
        userTransaction.commit();
    } catch (Throwable t) {
        try {
            if (userTransaction != null) {
                logger.debug("rolling back due to exception", t);
                userTransaction.rollback();
            }
        } catch (Exception ex) {
            logger.debug("exception during rollback", ex);
        }
        throw new ExportSourceImporterException("Failed to import", t);
    } finally {
        AuthenticationUtil.popAuthentication();
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) InputStreamReader(java.io.InputStreamReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) XMLWriter(org.dom4j.io.XMLWriter) FileInputStream(java.io.FileInputStream) BufferedWriter(java.io.BufferedWriter) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SimpleCache(org.alfresco.repo.cache.SimpleCache) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) XMLWriter(org.dom4j.io.XMLWriter) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter) Writer(java.io.Writer) Location(org.alfresco.service.cmr.view.Location)

Aggregations

SimpleCache (org.alfresco.repo.cache.SimpleCache)3 NodeRef (org.alfresco.service.cmr.repository.NodeRef)3 BufferedReader (java.io.BufferedReader)2 Reader (java.io.Reader)2 UserTransaction (javax.transaction.UserTransaction)2 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)2 Location (org.alfresco.service.cmr.view.Location)2 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 FileReader (java.io.FileReader)1 InputStreamReader (java.io.InputStreamReader)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 PolicyComponent (org.alfresco.repo.policy.PolicyComponent)1 TenantService (org.alfresco.repo.tenant.TenantService)1 XMLWriter (org.dom4j.io.XMLWriter)1