use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project acs-community-packaging by Alfresco.
the class CreateDiscussionDialog method createTopic.
// ------------------------------------------------------------------------------
// Helper methods
/**
* Creates a topic for the node with the given id
*
* @param id The id of the node to discuss
*/
protected void createTopic(final String id) {
RetryingTransactionCallback<NodeRef> createTopicCallback = new RetryingTransactionCallback<NodeRef>() {
public NodeRef execute() throws Throwable {
NodeRef forumNodeRef = null;
discussingNodeRef = new NodeRef(Repository.getStoreRef(), id);
if (getNodeService().hasAspect(discussingNodeRef, ForumModel.ASPECT_DISCUSSABLE)) {
throw new AlfrescoRuntimeException("createDiscussion called for an object that already has a discussion!");
}
// Add the discussable aspect
getNodeService().addAspect(discussingNodeRef, ForumModel.ASPECT_DISCUSSABLE, null);
// The discussion aspect create the necessary child
List<ChildAssociationRef> destChildren = getNodeService().getChildAssocs(discussingNodeRef, ForumModel.ASSOC_DISCUSSION, RegexQNamePattern.MATCH_ALL);
// Take the first one
if (destChildren.size() == 0) {
// Drop the aspect and recreate it. This should not happen, but just in case ...
getNodeService().removeAspect(discussingNodeRef, ForumModel.ASPECT_DISCUSSABLE);
getNodeService().addAspect(discussingNodeRef, ForumModel.ASPECT_DISCUSSABLE, null);
// The discussion aspect create the necessary child
destChildren = getNodeService().getChildAssocs(discussingNodeRef, ForumModel.ASSOC_DISCUSSION, RegexQNamePattern.MATCH_ALL);
}
if (destChildren.size() == 0) {
throw new AlfrescoRuntimeException("The discussable aspect behaviour is not creating a topic");
} else {
// We just take the first one
ChildAssociationRef discussionAssoc = destChildren.get(0);
forumNodeRef = discussionAssoc.getChildRef();
}
if (logger.isDebugEnabled())
logger.debug("created forum for content: " + discussingNodeRef.toString());
return forumNodeRef;
}
};
FacesContext context = FacesContext.getCurrentInstance();
NodeRef forumNodeRef = null;
try {
forumNodeRef = getTransactionService().getRetryingTransactionHelper().doInTransaction(createTopicCallback, false);
} catch (InvalidNodeRefException refErr) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { id }));
throw new AbortProcessingException("Invalid node reference");
} catch (Throwable e) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, Repository.ERROR_GENERIC), e.getMessage()), e);
ReportedException.throwIfNecessary(e);
}
// finally setup the context for the forum we just created
if (forumNodeRef != null) {
this.browseBean.clickSpace(forumNodeRef);
}
}
use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project acs-community-packaging by Alfresco.
the class CheckinCheckoutDialog method updateFileOK.
/**
* Action called upon completion of the Update File page
*/
public String updateFileOK(final FacesContext context, String outcome) {
// NOTE: for update the document node _is_ the working document!
final Node node = property.getDocument();
if (node != null && this.getFileName() != null) {
try {
RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(FacesContext.getCurrentInstance());
RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>() {
public Object execute() throws Throwable {
if (logger.isDebugEnabled())
logger.debug("Trying to update content node Id: " + node.getId());
// get an updating writer that we can use to modify the content on the current node
ContentWriter writer = property.getContentService().getWriter(node.getNodeRef(), ContentModel.PROP_CONTENT, true);
// also update the mime type in case a different type of file is uploaded
String mimeType = Repository.getMimeTypeForFileName(context, property.getFileName());
writer.setMimetype(mimeType);
writer.putContent(property.getFile());
return null;
}
};
txnHelper.doInTransaction(callback);
// clear action context
property.setDocument(null);
resetState();
outcome = AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
} catch (Throwable err) {
Utils.addErrorMessage(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR_UPDATE) + err.getMessage(), err);
ReportedException.throwIfNecessary(err);
}
} else {
logger.warn("WARNING: updateFileOK called without a current Document!");
}
return outcome;
}
use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback 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.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback 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.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project records-management by Alfresco.
the class UnfiledRecordFolderChildrenRelation method create.
@Override
@WebApiDescription(title = "Create one (or more) nodes as children of a unfiled record folder identified by 'unfiledRecordFolderId'")
public List<UnfiledRecordFolderChild> create(String unfiledRecordFolderId, final List<UnfiledRecordFolderChild> nodeInfos, Parameters parameters) {
checkNotBlank("unfiledRecordFolderId", unfiledRecordFolderId);
mandatory("nodeInfos", nodeInfos);
mandatory("parameters", parameters);
NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(unfiledRecordFolderId, RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER);
// Create the children
RetryingTransactionCallback<List<NodeRef>> callback = new RetryingTransactionCallback<List<NodeRef>>() {
public List<NodeRef> execute() {
List<NodeRef> createdNodes = new LinkedList<>();
for (UnfiledRecordFolderChild nodeInfo : nodeInfos) {
NodeRef nodeParent;
if (StringUtils.isNoneBlank(nodeInfo.getRelativePath())) {
nodeParent = apiUtils.lookupAndValidateRelativePath(parentNodeRef, nodeInfo.getRelativePath(), RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER);
} else {
nodeParent = parentNodeRef;
}
NodeRef newNodeRef = apiUtils.createRMNode(nodeParent, nodeInfo, parameters);
createdNodes.add(newNodeRef);
}
return createdNodes;
}
};
List<NodeRef> createdNodes = transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
// Get the nodes info
List<UnfiledRecordFolderChild> result = new LinkedList<>();
Map<String, UserInfo> mapUserInfo = new HashMap<>();
for (NodeRef newNodeRef : createdNodes) {
FileInfo info = fileFolderService.getFileInfo(newNodeRef);
apiUtils.postActivity(info, parentNodeRef, ActivityType.FILE_ADDED);
result.add(nodesModelFactory.createUnfiledRecordFolderChild(info, parameters, mapUserInfo, false));
}
return result;
}
Aggregations