Search in sources :

Example 81 with FacesContext

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

the class CreateRuleWizard method addCondition.

/**
 * Adds the condition just setup by the user to the list of conditions for the rule
 */
public void addCondition() {
    FacesContext context = FacesContext.getCurrentInstance();
    if (logger.isDebugEnabled())
        logger.debug("Adding Condition '" + selectedCondition + "'");
    IHandler handler = this.conditionHandlers.get(this.selectedCondition);
    // this is called from the actions page so there must be a handler
    // present so there's no need to check for null
    String summary = handler.generateSummary(context, this, this.currentConditionProperties);
    if (summary != null) {
        this.currentConditionProperties.put(PROP_CONDITION_SUMMARY, summary);
    }
    if (logger.isDebugEnabled())
        logger.debug("Generated Summary - [" + summary + "] + selectedCondition " + this.selectedCondition);
    if (this.editingCondition == false) {
        this.allConditionsPropertiesList.add(this.currentConditionProperties);
    }
    // reset the action drop down
    this.selectedCondition = null;
    // refresh the wizard
    goToPage(context, this.returnViewId);
}
Also used : FacesContext(javax.faces.context.FacesContext) IHandler(org.alfresco.web.bean.actions.IHandler)

Example 82 with FacesContext

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

the class EmailSpaceUsersDialog method getUsersGroups.

/**
 * Return the List of objects representing the Users and Groups invited to this space.
 * The picker is then responsible for rendering a view to represent those users and groups
 * which allows the users to select and deselect users and groups, also to expand groups
 * to show sub-groups and users.
 *
 * @return List of Map objects representing the users/groups assigned to the current space
 */
public List<Map> getUsersGroups() {
    if (this.usersGroups == null) {
        FacesContext context = FacesContext.getCurrentInstance();
        UserTransaction tx = null;
        try {
            tx = Repository.getUserTransaction(context, true);
            tx.begin();
            // Return all the permissions set against the current node for any authentication
            // instance (user/group), walking the parent space inheritance chain.
            // Then combine them into a single list for each authentication found.
            final String currentAuthority = Application.getCurrentUser(context).getUserName();
            Map<String, List<String>> permissionMap = AuthenticationUtil.runAs(new RunAsWork<Map<String, List<String>>>() {

                public Map<String, List<String>> doWork() throws Exception {
                    NodeRef spaceRef = getSpace().getNodeRef();
                    Map<String, List<String>> permissionMap = new HashMap<String, List<String>>(8, 1.0f);
                    while (spaceRef != null) {
                        Set<AccessPermission> permissions = getPermissionService().getAllSetPermissions(spaceRef);
                        for (AccessPermission permission : permissions) {
                            // we are only interested in Allow and not Guest/Everyone/owner
                            if (permission.getAccessStatus() == AccessStatus.ALLOWED && (permission.getAuthorityType() == AuthorityType.USER || permission.getAuthorityType() == AuthorityType.GROUP)) {
                                String authority = permission.getAuthority();
                                if (currentAuthority.equals(authority) == false) {
                                    List<String> userPermissions = permissionMap.get(authority);
                                    if (userPermissions == null) {
                                        // create for first time
                                        userPermissions = new ArrayList<String>(4);
                                        permissionMap.put(authority, userPermissions);
                                    }
                                    // add the permission name for this authority
                                    userPermissions.add(permission.getPermission());
                                }
                            }
                        }
                        // walk parent inheritance chain until root or no longer inherits
                        if (getPermissionService().getInheritParentPermissions(spaceRef)) {
                            spaceRef = getNodeService().getPrimaryParent(spaceRef).getParentRef();
                        } else {
                            spaceRef = null;
                        }
                    }
                    return permissionMap;
                }
            }, AuthenticationUtil.SYSTEM_USER_NAME);
            // create the structure as a linked list for fast insert/removal of items
            this.usersGroups = new LinkedList<Map>();
            // node represented by it and use that for our list databinding object
            for (String authority : permissionMap.keySet()) {
                Map node = buildAuthorityMap(authority, UserMembersBean.roleListToString(context, permissionMap.get(authority)));
                if (node != null) {
                    this.usersGroups.add(node);
                }
            }
            // commit the transaction
            tx.commit();
        } catch (InvalidNodeRefException refErr) {
            Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, Repository.ERROR_NODEREF), new Object[] { refErr.getNodeRef() }));
            this.usersGroups = Collections.<Map>emptyList();
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception tex) {
            }
        } catch (Throwable err) {
            Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, Repository.ERROR_GENERIC), err.getMessage()), err);
            this.usersGroups = Collections.<Map>emptyList();
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception tex) {
            }
        }
    }
    return this.usersGroups;
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) HashSet(java.util.HashSet) Set(java.util.Set) AccessPermission(org.alfresco.service.cmr.security.AccessPermission) ArrayList(java.util.ArrayList) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 83 with FacesContext

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

the class UsersDialog method getViewItems.

public List<UIListItem> getViewItems() {
    FacesContext context = FacesContext.getCurrentInstance();
    List<UIListItem> items = new ArrayList<UIListItem>(1);
    UIListItem item1 = new UIListItem();
    item1.setValue(VIEW_DETAILS);
    item1.setLabel(Application.getMessage(context, LABEL_VIEW_DETAILS));
    items.add(item1);
    return items;
}
Also used : FacesContext(javax.faces.context.FacesContext) UIListItem(org.alfresco.web.ui.common.component.UIListItem) ArrayList(java.util.ArrayList)

Example 84 with FacesContext

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

the class UsersDialog method deleteOK.

/**
 * Action handler called when the OK button is clicked on the Delete User page
 */
public String deleteOK() {
    FacesContext context = FacesContext.getCurrentInstance();
    try {
        String userName = (String) properties.getPerson().getProperties().get("userName");
        // delete the associated Person
        properties.getPersonService().deletePerson(userName);
        // re-do the search to refresh the list
        search();
    } catch (Throwable e) {
        // rollback the transaction
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, ERROR_DELETE), e.getMessage()), e);
        ReportedException.throwIfNecessary(e);
    }
    return DIALOG_CLOSE;
}
Also used : FacesContext(javax.faces.context.FacesContext)

Example 85 with FacesContext

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

the class BaseInviteUsersWizard method getMaximumUsersMsg.

/**
 * @return Message to display when the maximum number of users have been returned
 */
public String getMaximumUsersMsg() {
    FacesContext context = FacesContext.getCurrentInstance();
    String pattern = Application.getMessage(context, MSG_MAX_USERS);
    String msg = MessageFormat.format(pattern, Application.getClientConfig(context).getInviteUsersMaxResults());
    return Utils.encode(msg);
}
Also used : FacesContext(javax.faces.context.FacesContext)

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