use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project acs-community-packaging by Alfresco.
the class BaseDetailsBean method reject.
/**
* Event handler called to handle the approve step of the simple workflow
*
* @param event The event that was triggered
*/
public void reject(ActionEvent event) {
UIActionLink link = (UIActionLink) event.getComponent();
Map<String, String> params = link.getParameterMap();
String id = params.get("id");
if (id == null || id.length() == 0) {
throw new AlfrescoRuntimeException("reject called without an id");
}
final NodeRef docNodeRef = new NodeRef(Repository.getStoreRef(), id);
try {
RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(FacesContext.getCurrentInstance());
RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>() {
public Object execute() throws Throwable {
// call the service to perform the reject
WorkflowUtil.reject(docNodeRef, getNodeService(), getCopyService());
return null;
}
};
txnHelper.doInTransaction(callback);
// if this was called via the node details dialog we need to reset the node
if (getNode() != null) {
getNode().reset();
}
// also make sure the UI will get refreshed
UIContextService.getInstance(FacesContext.getCurrentInstance()).notifyBeans();
} catch (Throwable e) {
// rollback the transaction
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR_WORKFLOW_REJECT), e.getMessage()), e);
ReportedException.throwIfNecessary(e);
}
}
use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project acs-community-packaging by Alfresco.
the class AdminNodeBrowseBean method submitSearch.
/**
* Action to submit search
*
* @return next action
*/
public String submitSearch() {
long start = System.currentTimeMillis();
RetryingTransactionCallback<String> searchCallback = new RetryingTransactionCallback<String>() {
public String execute() throws Throwable {
if (queryLanguage.equals("noderef")) {
// ensure node exists
NodeRef nodeRef = new NodeRef(query);
boolean exists = getNodeService().exists(nodeRef);
if (!exists) {
throw new AlfrescoRuntimeException("Node " + nodeRef + " does not exist.");
}
setNodeRef(nodeRef);
return "node";
} else if (queryLanguage.equals("selectnodes")) {
List<NodeRef> nodes = getSearchService().selectNodes(getNodeRef(), query, null, getNamespaceService(), false);
searchResults = new SearchResults(nodes);
return "search";
}
// perform search
searchResults = new SearchResults(getSearchService().query(getNodeRef().getStoreRef(), queryLanguage, query));
return "search";
}
};
try {
String result = getTransactionService().getRetryingTransactionHelper().doInTransaction(searchCallback, true);
this.searchElapsedTime = System.currentTimeMillis() - start;
return result;
} catch (Throwable e) {
FacesContext context = FacesContext.getCurrentInstance();
FacesMessage message = new FacesMessage();
message.setSeverity(FacesMessage.SEVERITY_ERROR);
message.setDetail("Search failed due to: " + e.toString());
context.addMessage("searchForm:query", message);
return "error";
}
}
use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project acs-community-packaging by Alfresco.
the class ImportDialog method performImport.
/**
* Performs the import operation using the current state of the bean
*
* @return The outcome
*/
public String performImport(final FacesContext context, String outcome) {
if (logger.isDebugEnabled())
logger.debug("Called import for file: " + this.file);
if (this.file != null && this.file.exists()) {
// check the file actually has contents
if (this.file.length() > 0) {
try {
RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(context);
RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>() {
public Object execute() throws Throwable {
// first of all we need to add the uploaded ACP/ZIP file to the repository
NodeRef acpNodeRef = addFileToRepository(context);
// build the action params map based on the bean's current state
Map<String, Serializable> params = new HashMap<String, Serializable>(2, 1.0f);
params.put(ImporterActionExecuter.PARAM_DESTINATION_FOLDER, browseBean.getActionSpace().getNodeRef());
params.put(ImporterActionExecuter.PARAM_ENCODING, encoding);
// build the action to execute
Action action = getActionService().createAction(ImporterActionExecuter.NAME, params);
if (action instanceof ImporterActionExecuter) {
((ImporterActionExecuter) action).setHighByteZip(highByteZip);
}
action.setExecuteAsynchronously(runInBackground);
// execute the action on the ACP file
getActionService().executeAction(action, acpNodeRef);
if (logger.isDebugEnabled()) {
logger.debug("Executed import action with action params of " + params);
}
return null;
}
};
txnHelper.doInTransaction(callback);
// reset the bean
reset();
} catch (Throwable e) {
if (e instanceof DuplicateChildNodeNameException) {
String name = ((DuplicateChildNodeNameException) e).getName();
String err_mess = MessageFormat.format(I18NUtil.getMessage(ERR_DUPLICATE_NAME), name);
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR), err_mess), e);
} else {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR), e.toString()), e);
}
outcome = null;
ReportedException.throwIfNecessary(e);
}
} else {
Utils.addErrorMessage(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR_EMPTY_FILE));
outcome = null;
}
} else {
Utils.addErrorMessage(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR_NO_FILE));
outcome = null;
}
return outcome;
}
use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project acs-community-packaging by Alfresco.
the class CreateCategoryDialog method finishCreate.
public String finishCreate() {
String outcome = DEFAULT_OUTCOME;
try {
FacesContext context = FacesContext.getCurrentInstance();
RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(context);
RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>() {
public Object execute() throws Throwable {
// create category using categoryservice
NodeRef ref;
if (getCategoryRef() == null || getCategoryRef().getId().equals("null")) {
ref = getCategoryService().createRootCategory(Repository.getStoreRef(), ContentModel.ASPECT_GEN_CLASSIFIABLE, getName());
} else {
ref = getCategoryService().createCategory(getCategoryRef(), getName());
}
// apply the titled aspect - for description
Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>(1, 1.0f);
titledProps.put(ContentModel.PROP_DESCRIPTION, getDescription());
getNodeService().addAspect(ref, ContentModel.ASPECT_TITLED, titledProps);
return null;
}
};
txnHelper.doInTransaction(callback);
} catch (Throwable err) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
outcome = null;
ReportedException.throwIfNecessary(err);
}
return outcome;
}
use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project acs-community-packaging by Alfresco.
the class InvokeCommand method execute.
// ///////////////////////////////////////////////////////////////////////////
public void execute(final FacesContext facesContext, final String expression, final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
ResponseWriter writer = null;
try {
final int indexOfDot = expression.indexOf('.');
final String variableName = expression.substring(0, indexOfDot);
final String methodName = expression.substring(indexOfDot + 1);
if (logger.isDebugEnabled())
logger.debug("Invoking method represented by " + expression + " on variable " + variableName + " with method " + methodName);
Object bean = null;
if (Application.inPortalServer()) {
// retrieve the managed bean, this is really weak but if the
// request comes from a portal server the bean we need to get
// is in the session with a prefix chosen by the portal vendor,
// to cover this scenario we have to go through the names of
// all the objects in the session to find the bean we want.
String beanNameSuffix = "?" + variableName;
Enumeration<?> enumNames = request.getSession().getAttributeNames();
while (enumNames.hasMoreElements()) {
String name = (String) enumNames.nextElement();
if (name.endsWith(beanNameSuffix)) {
bean = request.getSession().getAttribute(name);
if (logger.isDebugEnabled())
logger.debug("Found bean " + bean + " in the session");
break;
}
}
}
// if we don't have the bean yet try and get it via the variable resolver
if (bean == null) {
VariableResolver vr = facesContext.getApplication().getVariableResolver();
bean = vr.resolveVariable(facesContext, variableName);
if (logger.isDebugEnabled())
logger.debug("Created bean " + bean + " via the variable resolver");
}
final Method method = bean.getClass().getMethod(methodName);
final String responseMimetype = (method.isAnnotationPresent(ResponseMimetype.class) ? method.getAnnotation(ResponseMimetype.class).value() : MimetypeMap.MIMETYPE_XML);
if (logger.isDebugEnabled())
logger.debug("invoking method " + method + " with repsonse mimetype " + responseMimetype);
writer = this.setupResponseWriter(responseMimetype, response, facesContext);
// setup the transaction
RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(FacesContext.getCurrentInstance());
final Object beanFinal = bean;
RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>() {
public Object execute() throws Throwable {
// invoke the method
try {
method.invoke(beanFinal);
return null;
}// Let's prevent RuntimeExceptions being wrapped twice by unwrapping InvocationTargetExceptions
catch (InvocationTargetException e) {
if (e.getCause() != null) {
throw e.getCause();
}
throw e;
}
}
};
txnHelper.doInTransaction(callback);
} catch (EvaluationException e) {
Throwable err = e.getCause();
if (err == null) {
logger.error("Failed to execute method " + expression + ": " + e.getMessage(), e);
throw e;
} else {
logger.error("Failed to execute method " + expression + ": " + err.getMessage(), err);
if (err instanceof RuntimeException) {
throw (RuntimeException) err;
} else {
throw new AlfrescoRuntimeException("Failed to execute method " + expression + ": " + err.getMessage(), err);
}
}
} catch (RuntimeException err) {
logger.error("Failed to execute method " + expression + ": " + err.getMessage(), err);
throw err;
} catch (Exception err) {
logger.error("Failed to execute method " + expression + ": " + err.getMessage(), err);
throw new AlfrescoRuntimeException("Failed to execute method " + expression + ": " + err.getMessage(), err);
}
// force the output back to the client
writer.close();
}
Aggregations