Search in sources :

Example 1 with AlfrescoRuntimeException

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;
}
Also used : ServletRequest(javax.servlet.ServletRequest) ServletResponse(javax.servlet.ServletResponse) FacesContext(javax.faces.context.FacesContext) ServletContext(javax.servlet.ServletContext) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) NavigationHandler(javax.faces.application.NavigationHandler) UsersDialog(org.alfresco.web.bean.users.UsersDialog) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 2 with AlfrescoRuntimeException

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);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) UIActionLink(org.alfresco.web.ui.common.component.UIActionLink) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 3 with AlfrescoRuntimeException

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";
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FacesContext(javax.faces.context.FacesContext) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ArrayList(java.util.ArrayList) List(java.util.List) FacesMessage(javax.faces.application.FacesMessage)

Example 4 with AlfrescoRuntimeException

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");
        }
    }
}
Also used : ConfigService(org.springframework.extensions.config.ConfigService) ConfigElement(org.springframework.extensions.config.ConfigElement) Config(org.springframework.extensions.config.Config) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 5 with AlfrescoRuntimeException

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);
    }
}
Also used : AuthenticationStatus(org.alfresco.web.app.servlet.AuthenticationStatus) FacesContext(javax.faces.context.FacesContext) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Aggregations

AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)553 NodeRef (org.alfresco.service.cmr.repository.NodeRef)204 QName (org.alfresco.service.namespace.QName)106 HashMap (java.util.HashMap)81 IOException (java.io.IOException)77 Serializable (java.io.Serializable)76 ArrayList (java.util.ArrayList)65 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)48 Map (java.util.Map)41 StoreRef (org.alfresco.service.cmr.repository.StoreRef)41 JSONException (org.json.JSONException)35 InputStream (java.io.InputStream)31 HashSet (java.util.HashSet)29 JSONObject (org.json.JSONObject)28 Date (java.util.Date)27 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)27 Test (org.junit.Test)26 File (java.io.File)25 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)24 ContentReader (org.alfresco.service.cmr.repository.ContentReader)21