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());
}
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();
}
}
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();
}
}
Aggregations