Search in sources :

Example 46 with FacesContext

use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.

the class TaskInfoBean method getModel.

// ------------------------------------------------------------------------------
// Helper methods
private Map<String, Object> getModel(WorkflowTask task) {
    FacesContext context = FacesContext.getCurrentInstance();
    Map<String, Object> model = new HashMap<String, Object>(8, 1.0f);
    I18NUtil.registerResourceBundle("alfresco.messages.webclient");
    // create template api methods and objects
    model.put("date", new Date());
    model.put("msg", new I18NMessageMethod());
    model.put("url", new BaseTemplateContentServlet.URLHelper(context));
    model.put("locale", I18NUtil.getLocale());
    model.put("task", new Workflow.WorkflowTaskItem(Repository.getServiceRegistry(context), this.imageResolver, task));
    return model;
}
Also used : FacesContext(javax.faces.context.FacesContext) I18NMessageMethod(org.alfresco.repo.template.I18NMessageMethod) HashMap(java.util.HashMap) BaseTemplateContentServlet(org.alfresco.web.app.servlet.BaseTemplateContentServlet) Workflow(org.alfresco.repo.template.Workflow) Date(java.util.Date)

Example 47 with FacesContext

use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.

the class TaskInfoBean method sendTaskResources.

/**
 * Returns the resource list for the workflow task identified by the 'taskId'
 * parameter found in the ExternalContext.
 * <p>
 * The result is the formatted HTML to show on the client.
 */
public void sendTaskResources() throws IOException {
    FacesContext context = FacesContext.getCurrentInstance();
    ResponseWriter out = context.getResponseWriter();
    String taskId = (String) context.getExternalContext().getRequestParameterMap().get("taskId");
    if (taskId == null || taskId.length() == 0) {
        throw new IllegalArgumentException("'taskId' parameter is missing");
    }
    WorkflowTask task = this.getWorkflowService().getTaskById(taskId);
    if (task != null) {
        Repository.getServiceRegistry(context).getTemplateService().processTemplate("/alfresco/templates/client/task_resource_panel.ftl", getModel(task), out);
    } else {
        out.write("<span class='errorMessage'>Task could not be found.</span>");
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) ResponseWriter(javax.faces.context.ResponseWriter) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask)

Example 48 with FacesContext

use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.

the class CategoriesDialog method getCategories.

/**
 * @return The list of categories Nodes to display. Returns the list root categories or the
 *         list of sub-categories for the current category if set.
 */
public List<Node> getCategories() {
    List<Node> categories;
    UserTransaction tx = null;
    try {
        FacesContext context = FacesContext.getCurrentInstance();
        tx = Repository.getUserTransaction(context, true);
        tx.begin();
        Collection<ChildAssociationRef> refs;
        if (getCategoryRef() == null) {
            // root categories
            refs = getCategoryService().getCategories(Repository.getStoreRef(), ContentModel.ASPECT_GEN_CLASSIFIABLE, Depth.IMMEDIATE);
        } else {
            // sub-categories of an existing category
            refs = getCategoryService().getChildren(getCategoryRef(), Mode.SUB_CATEGORIES, Depth.IMMEDIATE);
        }
        categories = new ArrayList<Node>(refs.size());
        for (ChildAssociationRef child : refs) {
            Node categoryNode = new Node(child.getChildRef());
            // force early props init within transaction
            categoryNode.getProperties();
            categories.add(categoryNode);
        }
        // commit the transaction
        tx.commit();
    } catch (InvalidNodeRefException refErr) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { refErr.getNodeRef() }));
        categories = Collections.<Node>emptyList();
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception tex) {
        }
    } catch (Throwable err) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
        categories = Collections.<Node>emptyList();
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception tex) {
        }
    }
    return categories;
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) Node(org.alfresco.web.bean.repository.Node) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException)

Example 49 with FacesContext

use of javax.faces.context.FacesContext 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;
}
Also used : FacesContext(javax.faces.context.FacesContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName)

Example 50 with FacesContext

use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.

the class LoginBean method login.

// ------------------------------------------------------------------------------
// Action event methods
/**
 * Login action handler
 *
 * @return outcome view name
 */
public String login() {
    String outcome = null;
    FacesContext fc = FacesContext.getCurrentInstance();
    if (this.username != null && this.username.length() != 0 && this.password != null && this.password.length() != 0) {
        try {
            // Perform a full session invalidation to ensure no cached data is left around
            // - important if the login page has been accessed directly rather than via the Login/out action links
            logout();
            // Authenticate via the authentication service, then save the details of user in an object
            // in the session - this is used by the servlet filter etc. on each page to check for login
            this.getAuthenticationService().authenticate(this.username, this.password.toCharArray());
            // Set the user name as stored by the back end
            this.username = this.getAuthenticationService().getCurrentUserName();
            // setup User object and Home space ID
            User user = new User(this.username, this.getAuthenticationService().getCurrentTicket(), getPersonService().getPerson(this.username));
            NodeRef homeSpaceRef = (NodeRef) this.getNodeService().getProperty(getPersonService().getPerson(this.username), ContentModel.PROP_HOMEFOLDER);
            // check that the home space node exists - else user cannot login
            if (homeSpaceRef == null || this.getNodeService().exists(homeSpaceRef) == false) {
                throw new InvalidNodeRefException(homeSpaceRef);
            }
            user.setHomeSpaceId(homeSpaceRef.getId());
            // put the User object in the Session - the authentication servlet will then allow
            // the app to continue without redirecting to the login page
            Application.setCurrentUser(fc, user);
            // Save the current username to cookie
            AuthenticationHelper.setUsernameCookie((HttpServletRequest) fc.getExternalContext().getRequest(), (HttpServletResponse) fc.getExternalContext().getResponse(), this.username);
            // Programatically retrieve the LoginOutcomeBean from JSF
            LoginOutcomeBean loginOutcomeBean = (LoginOutcomeBean) fc.getApplication().createValueBinding("#{LoginOutcomeBean}").getValue(fc);
            // if a redirect URL has been provided then use that
            // this allows servlets etc. to provide a URL to return too after a successful login
            String redirectURL = loginOutcomeBean.getRedirectURL();
            // ALF-10312: Validate we are redirecting within this web app
            if (redirectURL != null && !redirectURL.isEmpty() && !redirectURL.startsWith(fc.getExternalContext().getRequestContextPath())) {
                if (logger.isWarnEnabled())
                    logger.warn("Security violation. Unable to redirect to external location: " + redirectURL);
                redirectURL = null;
            }
            if (redirectURL != null && redirectURL.length() > 0) {
                if (logger.isDebugEnabled())
                    logger.debug("Redirect URL found: " + redirectURL);
                try {
                    fc.getExternalContext().redirect(redirectURL);
                    fc.responseComplete();
                    return null;
                } catch (IOException ioErr) {
                    logger.warn("Unable to redirect to url: " + redirectURL, ioErr);
                }
            } else {
                // special case to handle jump to My Alfresco page initially
                // note: to enable MT runtime client config customization, need to re-init NavigationBean
                // in context of tenant login page
                this.navigator.initFromClientConfig();
                if (NavigationBean.LOCATION_MYALFRESCO.equals(this.preferences.getStartLocation())) {
                    return "myalfresco";
                } else {
                    // generally this will navigate to the generic browse screen
                    return "success";
                }
            }
        } catch (AuthenticationDisallowedException aerr) {
            Utils.addErrorMessage(Application.getMessage(fc, MSG_ERROR_LOGIN_DISALLOWED));
        } catch (AuthenticationMaxUsersException aerr) {
            Utils.addErrorMessage(Application.getMessage(fc, MSG_ERROR_LOGIN_MAXUSERS));
        } catch (AuthenticationException aerr) {
            Utils.addErrorMessage(Application.getMessage(fc, MSG_ERROR_UNKNOWN_USER));
        } catch (InvalidNodeRefException refErr) {
            String msg;
            if (refErr.getNodeRef() != null) {
                msg = refErr.getNodeRef().toString();
            } else {
                msg = Application.getMessage(fc, MSG_NONE);
            }
            Utils.addErrorMessage(MessageFormat.format(Application.getMessage(fc, Repository.ERROR_NOHOME), msg));
        }
    } else {
        Utils.addErrorMessage(Application.getMessage(fc, MSG_ERROR_MISSING));
    }
    return outcome;
}
Also used : FacesContext(javax.faces.context.FacesContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) User(org.alfresco.web.bean.repository.User) AuthenticationException(org.alfresco.repo.security.authentication.AuthenticationException) AuthenticationDisallowedException(org.alfresco.repo.security.authentication.AuthenticationDisallowedException) AuthenticationMaxUsersException(org.alfresco.repo.security.authentication.AuthenticationMaxUsersException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) IOException(java.io.IOException)

Aggregations

FacesContext (javax.faces.context.FacesContext)361 NodeRef (org.alfresco.service.cmr.repository.NodeRef)61 Node (org.alfresco.web.bean.repository.Node)44 UserTransaction (javax.transaction.UserTransaction)43 ArrayList (java.util.ArrayList)33 HashMap (java.util.HashMap)28 IOException (java.io.IOException)27 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)27 ExternalContext (javax.faces.context.ExternalContext)26 SelectItem (javax.faces.model.SelectItem)26 QName (org.alfresco.service.namespace.QName)25 FacesMessage (javax.faces.application.FacesMessage)24 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)22 Map (java.util.Map)21 ResourceBundle (java.util.ResourceBundle)20 HttpServletResponse (javax.servlet.http.HttpServletResponse)19 MapNode (org.alfresco.web.bean.repository.MapNode)18 UIViewRoot (javax.faces.component.UIViewRoot)17 HttpServletRequest (javax.servlet.http.HttpServletRequest)16 Serializable (java.io.Serializable)15