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