use of org.alfresco.error.AlfrescoRuntimeException in project acs-community-packaging by Alfresco.
the class UserProfileDialogCommand method execute.
/**
* @see org.alfresco.web.app.servlet.command.Command#execute(org.alfresco.service.ServiceRegistry, java.util.Map)
*/
public Object execute(ServiceRegistry serviceRegistry, Map<String, Object> properties) {
ServletContext sc = (ServletContext) properties.get(PROP_SERVLETCONTEXT);
ServletRequest req = (ServletRequest) properties.get(PROP_REQUEST);
ServletResponse res = (ServletResponse) properties.get(PROP_RESPONSE);
FacesContext fc = FacesHelper.getFacesContext(req, res, sc, "/jsp/close.jsp");
UsersDialog dialog = (UsersDialog) FacesHelper.getManagedBean(fc, UsersDialog.BEAN_NAME);
// setup dialog context from url args in properties map
String personId = (String) properties.get(PROP_PERSONID);
ParameterCheck.mandatoryString(PROP_PERSONID, personId);
dialog.setupUserAction(personId);
NavigationHandler navigationHandler = fc.getApplication().getNavigationHandler();
navigationHandler.handleNavigation(fc, null, "dialog:userProfile");
String viewId = fc.getViewRoot().getViewId();
try {
sc.getRequestDispatcher(BaseServlet.FACES_SERVLET + viewId).forward(req, res);
} catch (Exception e) {
throw new AlfrescoRuntimeException("Unable to forward to viewId: " + viewId, e);
}
return null;
}
use of org.alfresco.error.AlfrescoRuntimeException 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.error.AlfrescoRuntimeException 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.error.AlfrescoRuntimeException in project acs-community-packaging by Alfresco.
the class BaseActionWizard method initialiseActionHandlers.
/**
* Initialises the action handlers from the current configuration.
*/
protected void initialiseActionHandlers() {
if ((this.actionHandlers == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
ConfigService svc = Application.getConfigService(FacesContext.getCurrentInstance());
Config wizardCfg = svc.getConfig("Action Wizards");
if (wizardCfg != null) {
ConfigElement actionHandlerCfg = wizardCfg.getConfigElement("action-handlers");
if (actionHandlerCfg != null) {
this.actionHandlers = new HashMap<String, IHandler>(20);
// instantiate each handler and store in the map
for (ConfigElement child : actionHandlerCfg.getChildren()) {
String actionName = child.getAttribute("name");
String handlerClass = child.getAttribute("class");
if (actionName != null && actionName.length() > 0 && handlerClass != null && handlerClass.length() > 0) {
try {
@SuppressWarnings("unchecked") Class klass = Class.forName(handlerClass);
IHandler handler = (IHandler) klass.newInstance();
this.actionHandlers.put(actionName, handler);
} catch (Exception e) {
throw new AlfrescoRuntimeException("Failed to setup action handler for '" + actionName + "'", e);
}
}
}
} else {
logger.warn("Could not find 'action-handlers' configuration element");
}
} else {
logger.warn("Could not find 'Action Wizards' configuration section");
}
}
}
use of org.alfresco.error.AlfrescoRuntimeException in project acs-community-packaging by Alfresco.
the class AjaxServlet method service.
/**
* @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
protected void service(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
// set default character encoding for the response
response.setCharacterEncoding("utf-8");
response.setContentType("text/xml;charset=UTF-8");
long startTime = 0;
String uri = request.getRequestURI();
if (logger.isDebugEnabled()) {
final String queryString = request.getQueryString();
logger.debug("Processing URL: " + uri + ((queryString != null && queryString.length() > 0) ? ("?" + queryString) : ""));
}
// dump the request headers
if (headersLogger.isDebugEnabled()) {
final Enumeration<?> headers = request.getHeaderNames();
while (headers.hasMoreElements()) {
final String name = (String) headers.nextElement();
headersLogger.debug(name + ": " + request.getHeader(name));
}
}
try {
// Make sure the user is authenticated, if not throw an error to return the
// 500 Internal Server Error code back to the client
AuthenticationStatus status = servletAuthenticate(request, response, false);
if (status == AuthenticationStatus.Failure) {
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Access Denied: User not authenticated");
return;
}
setNoCacheHeaders(response);
uri = uri.substring(request.getContextPath().length() + "/".length());
final String[] tokens = uri.split("/");
if (tokens.length < 3) {
throw new AlfrescoRuntimeException("Servlet URL did not contain all required args: " + uri);
}
// retrieve the command from the URL
final String commandName = tokens[1];
// retrieve the binding expression from the URL
final String expression = tokens[2];
// setup the faces context
final FacesContext facesContext = FacesHelper.getFacesContext(request, response, getServletContext());
// start a timer
if (perfLogger.isDebugEnabled())
startTime = System.currentTimeMillis();
// instantiate the relevant command
AjaxCommand command = null;
if (Command.invoke.toString().equals(commandName)) {
command = new InvokeCommand();
} else if (Command.get.toString().equals(commandName)) {
command = new GetCommand();
} else {
throw new AlfrescoRuntimeException("Unrecognised command received: " + commandName);
}
// execute the command
command.execute(facesContext, expression, request, response);
} catch (RuntimeException error) {
handleError(response, error);
} finally {
// measure the time taken
if (perfLogger.isDebugEnabled()) {
perfLogger.debug("Time to execute command: " + (System.currentTimeMillis() - startTime) + "ms");
}
ContextHolder.setContext(null);
}
}
Aggregations