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