Search in sources :

Example 46 with UserTransaction

use of javax.transaction.UserTransaction in project acs-community-packaging by Alfresco.

the class BaseAssociationEditor method getAvailableOptions.

/**
 * Retrieves the available options for the current association
 *
 * @param context Faces Context
 * @param contains The contains part of the query
 */
protected void getAvailableOptions(FacesContext context, String contains) {
    AssociationDefinition assocDef = getAssociationDefinition(context);
    if (assocDef != null) {
        // find and show all the available options for the current association
        String type = assocDef.getTargetClass().getName().toString();
        if (type.equals(ContentModel.TYPE_AUTHORITY_CONTAINER.toString())) {
            UserTransaction tx = null;
            try {
                tx = Repository.getUserTransaction(context, true);
                tx.begin();
                String safeContains = null;
                if (contains != null && contains.length() > 0) {
                    safeContains = Utils.remove(contains.trim(), "\"");
                    safeContains = safeContains.toLowerCase();
                }
                // get all available groups
                AuthorityService authorityService = Repository.getServiceRegistry(context).getAuthorityService();
                Set<String> groups = authorityService.getAllAuthoritiesInZone(AuthorityService.ZONE_APP_DEFAULT, AuthorityType.GROUP);
                this.availableOptions = new ArrayList<NodeRef>(groups.size());
                // get the NodeRef for each matching group
                AuthorityDAO authorityDAO = (AuthorityDAO) FacesContextUtils.getRequiredWebApplicationContext(context).getBean("authorityDAO");
                if (authorityDAO != null) {
                    List<String> matchingGroups = new ArrayList<String>();
                    String groupDisplayName;
                    for (String group : groups) {
                        // get display name, if not present strip prefix from group id
                        groupDisplayName = authorityService.getAuthorityDisplayName(group);
                        if (groupDisplayName == null || groupDisplayName.length() == 0) {
                            groupDisplayName = group.substring(PermissionService.GROUP_PREFIX.length());
                        }
                        // otherwise just add the group name to the sorted set
                        if (safeContains != null) {
                            if (groupDisplayName.toLowerCase().indexOf(safeContains) != -1) {
                                matchingGroups.add(group);
                            }
                        } else {
                            matchingGroups.add(group);
                        }
                    }
                    // sort the group names
                    Collections.sort(matchingGroups, new SimpleStringComparator());
                    // go through the sorted set and get the NodeRef for each group
                    for (String groupName : matchingGroups) {
                        NodeRef groupRef = authorityDAO.getAuthorityNodeRefOrNull(groupName);
                        if (groupRef != null) {
                            this.availableOptions.add(groupRef);
                        }
                    }
                }
                // commit the transaction
                tx.commit();
            } catch (Throwable err) {
                Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, Repository.ERROR_GENERIC), err.getMessage()), err);
                this.availableOptions = Collections.<NodeRef>emptyList();
                try {
                    if (tx != null) {
                        tx.rollback();
                    }
                } catch (Exception tex) {
                }
            }
        } else if (type.equals(ContentModel.TYPE_PERSON.toString())) {
            List<Pair<QName, String>> filter = (contains != null && contains.trim().length() > 0) ? Utils.generatePersonFilter(contains.trim()) : null;
            // Always sort by last name, then first name
            List<Pair<QName, Boolean>> sort = new ArrayList<Pair<QName, Boolean>>();
            sort.add(new Pair<QName, Boolean>(ContentModel.PROP_LASTNAME, true));
            sort.add(new Pair<QName, Boolean>(ContentModel.PROP_FIRSTNAME, true));
            // Log the filtering
            if (logger.isDebugEnabled())
                logger.debug("Query filter: " + filter);
            // How many to limit too?
            int maxResults = Application.getClientConfig(context).getSelectorsSearchMaxResults();
            if (maxResults <= 0) {
                maxResults = Utils.getPersonMaxResults();
            }
            List<PersonInfo> persons = Repository.getServiceRegistry(context).getPersonService().getPeople(filter, true, sort, new PagingRequest(maxResults, null)).getPage();
            // Save the results
            List<NodeRef> nodes = new ArrayList<NodeRef>(persons.size());
            for (PersonInfo person : persons) {
                nodes.add(person.getNodeRef());
            }
            this.availableOptions = nodes;
        } else {
            // for all other types/aspects perform a lucene search
            StringBuilder query = new StringBuilder("+TYPE:\"");
            if (assocDef.getTargetClass().isAspect()) {
                query = new StringBuilder("+ASPECT:\"");
            } else {
                query = new StringBuilder("+TYPE:\"");
            }
            query.append(type);
            query.append("\"");
            if (contains != null && contains.trim().length() != 0) {
                String safeContains = null;
                if (contains != null && contains.length() > 0) {
                    safeContains = Utils.remove(contains.trim(), "\"");
                    safeContains = safeContains.toLowerCase();
                }
                query.append(" AND +@");
                String nameAttr = Repository.escapeQName(QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "name"));
                query.append(nameAttr);
                query.append(":\"*" + safeContains + "*\"");
            }
            int maxResults = Application.getClientConfig(context).getSelectorsSearchMaxResults();
            if (logger.isDebugEnabled()) {
                logger.debug("Query: " + query.toString());
                logger.debug("Max results size: " + maxResults);
            }
            SearchParameters searchParams = new SearchParameters();
            searchParams.addStore(Repository.getStoreRef());
            searchParams.setLanguage(SearchService.LANGUAGE_LUCENE);
            searchParams.setQuery(query.toString());
            if (maxResults > 0) {
                searchParams.setLimit(maxResults);
                searchParams.setLimitBy(LimitBy.FINAL_SIZE);
            }
            ResultSet results = null;
            try {
                results = Repository.getServiceRegistry(context).getSearchService().query(searchParams);
                this.availableOptions = results.getNodeRefs();
            } catch (SearcherException se) {
                logger.info("Search failed for: " + query, se);
                Utils.addErrorMessage(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_QUERY));
            } finally {
                if (results != null) {
                    results.close();
                }
            }
        }
        if (logger.isDebugEnabled())
            logger.debug("Found " + this.availableOptions.size() + " available options");
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) PersonInfo(org.alfresco.service.cmr.security.PersonService.PersonInfo) QName(org.alfresco.service.namespace.QName) AuthorityService(org.alfresco.service.cmr.security.AuthorityService) ArrayList(java.util.ArrayList) AuthorityDAO(org.alfresco.repo.security.authority.AuthorityDAO) SearcherException(org.alfresco.repo.search.SearcherException) AbortProcessingException(javax.faces.event.AbortProcessingException) IOException(java.io.IOException) PagingRequest(org.alfresco.query.PagingRequest) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) SearcherException(org.alfresco.repo.search.SearcherException) ResultSet(org.alfresco.service.cmr.search.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List) Pair(org.alfresco.util.Pair)

Example 47 with UserTransaction

use of javax.transaction.UserTransaction in project acs-community-packaging by Alfresco.

the class UINavigator method broadcast.

/**
 * @see javax.faces.component.UIInput#broadcast(javax.faces.event.FacesEvent)
 */
public void broadcast(FacesEvent event) throws AbortProcessingException {
    if (event instanceof NavigatorEvent) {
        FacesContext context = FacesContext.getCurrentInstance();
        NavigatorEvent navEvent = (NavigatorEvent) event;
        // node or panel selected?
        switch(navEvent.getMode()) {
            case PANEL_SELECTED:
                {
                    String panelSelected = navEvent.getItem();
                    // a panel was selected, setup the context to make the panel
                    // the focus
                    NavigationBean nb = (NavigationBean) FacesHelper.getManagedBean(context, NavigationBean.BEAN_NAME);
                    if (nb != null) {
                        try {
                            if (logger.isDebugEnabled())
                                logger.debug("Selecting panel: " + panelSelected);
                            nb.processToolbarLocation(panelSelected, true);
                        } catch (InvalidNodeRefException refErr) {
                            Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NOHOME), Application.getCurrentUser(context).getHomeSpaceId()), refErr);
                        } catch (Exception err) {
                            Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
                        }
                    }
                    break;
                }
            case NODE_SELECTED:
                {
                    // a node was clicked in the tree
                    boolean nodeExists = true;
                    NodeRef nodeClicked = new NodeRef(navEvent.getItem());
                    // make sure the node exists still before navigating to it
                    UserTransaction tx = null;
                    try {
                        tx = Repository.getUserTransaction(context, true);
                        tx.begin();
                        NodeService nodeSvc = Repository.getServiceRegistry(context).getNodeService();
                        nodeExists = nodeSvc.exists(nodeClicked);
                        tx.commit();
                    } catch (Throwable err) {
                        try {
                            if (tx != null) {
                                tx.rollback();
                            }
                        } catch (Exception tex) {
                        }
                    }
                    if (nodeExists) {
                        // setup the context to make the node the current node
                        BrowseBean bb = (BrowseBean) FacesHelper.getManagedBean(context, BrowseBean.BEAN_NAME);
                        if (bb != null) {
                            if (logger.isDebugEnabled())
                                logger.debug("Selected node: " + nodeClicked);
                            bb.clickSpace(nodeClicked);
                        }
                    } else {
                        String msg = Application.getMessage(context, "navigator_node_deleted");
                        Utils.addErrorMessage(msg);
                    }
                    break;
                }
        }
    } else {
        super.broadcast(event);
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) NavigationBean(org.alfresco.web.bean.NavigationBean) BrowseBean(org.alfresco.web.bean.BrowseBean) NodeService(org.alfresco.service.cmr.repository.NodeService) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) AbortProcessingException(javax.faces.event.AbortProcessingException) IOException(java.io.IOException)

Example 48 with UserTransaction

use of javax.transaction.UserTransaction in project acs-community-packaging by Alfresco.

the class UIAjaxTagPicker method encodeBegin.

@SuppressWarnings("unchecked")
@Override
public /**
 * @see javax.faces.component.UIComponentBase#encodeBegin(javax.faces.context.FacesContext)
 */
void encodeBegin(FacesContext fc) throws IOException {
    if (isRendered() == false) {
        return;
    }
    ResponseWriter out = fc.getResponseWriter();
    String formClientId = Utils.getParentForm(fc, this).getClientId(fc);
    Map attrs = this.getAttributes();
    ResourceBundle msg = Application.getBundle(fc);
    // get values from submitted value or none selected
    String selectedValues = null;
    String selectedNames = null;
    String selectedItems = null;
    List<NodeRef> submitted = null;
    submitted = (List<NodeRef>) getSubmittedValue();
    if (submitted == null) {
        Object objSubmitted = getValue();
        // special case to submit empty lists on multi-select values
        if ((objSubmitted != null) && (objSubmitted.toString().equals("empty"))) {
            submitted = null;
            this.setValue(null);
        } else {
            submitted = (List<NodeRef>) getValue();
        }
    }
    if (submitted != null) {
        UserTransaction tx = null;
        try {
            tx = Repository.getUserTransaction(fc, true);
            tx.begin();
            StringBuilder nameBuf = new StringBuilder(128);
            StringBuilder valueBuf = new StringBuilder(128);
            StringBuilder itemBuf = new StringBuilder(256);
            NodeService nodeService = (NodeService) FacesContextUtils.getRequiredWebApplicationContext(fc).getBean("nodeService");
            for (NodeRef value : submitted) {
                String name = (String) nodeService.getProperty(value, ContentModel.PROP_NAME);
                String icon = (String) nodeService.getProperty(value, ApplicationModel.PROP_ICON);
                if (nameBuf.length() != 0) {
                    nameBuf.append(", ");
                    valueBuf.append(",");
                    itemBuf.append(",");
                }
                nameBuf.append(name);
                valueBuf.append(value.toString());
                itemBuf.append(getItemJson(value.toString(), name, icon));
            }
            selectedNames = nameBuf.toString();
            selectedValues = valueBuf.toString();
            selectedItems = "[" + itemBuf.toString() + "]";
            // commit the transaction
            tx.commit();
        } catch (Throwable err) {
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception tex) {
            }
        }
    }
    // generate the Ids for our script object and containing DIV element
    String divId = getId();
    String objId = divId + "Obj";
    // generate the script to create and init our script object
    String contextPath = fc.getExternalContext().getRequestContextPath();
    out.write("<script type='text/javascript'>");
    out.write("function init" + divId + "() {");
    out.write(" window." + objId + " = new AlfTagger('" + divId + "','" + objId + "','" + getServiceCall() + "','" + formClientId + "','" + msg.getString(MSG_ADD) + "','" + msg.getString(MSG_REMOVE) + "');");
    out.write(" window." + objId + ".setChildNavigation(false);");
    if (getDefaultIcon() != null) {
        out.write(" window." + objId + ".setDefaultIcon('" + getDefaultIcon() + "');");
    }
    if (selectedItems != null) {
        out.write(" window." + objId + ".setSelectedItems('" + selectedItems + "');");
    }
    out.write("}");
    out.write("window.addEvent('domready', init" + divId + ");");
    out.write("</script>");
    // generate the DIV structure for our component as expected by the script object
    out.write("<div id='" + divId + "' class='picker'>");
    out.write(" <input id='" + getHiddenFieldName() + "' name='" + getHiddenFieldName() + "' type='hidden' value='");
    if (selectedValues != null) {
        out.write(selectedValues);
    }
    out.write("'>");
    // current selection displayed as link and message to launch the selector
    out.write(" <div id='" + divId + "-noitems'");
    if (attrs.get("style") != null) {
        out.write(" style=\"");
        out.write((String) attrs.get("style"));
        out.write('"');
    }
    if (attrs.get("styleClass") != null) {
        out.write(" class=");
        out.write((String) attrs.get("styleClass"));
    }
    out.write(">");
    if (isDisabled()) {
        out.write("   <span>");
        if (selectedNames != null) {
            out.write(selectedNames);
        }
        out.write("   </span>");
    } else {
        out.write("  <span class='pickerActionButton'><a href='javascript:" + objId + ".showSelector();'>");
        if (selectedNames == null) {
            if ("".equals(getLabel())) {
                setLabel(msg.getString(MSG_CLICK_TO_SELECT_TAG));
            }
            out.write(getLabel());
        } else {
            out.write(selectedNames);
        }
        out.write("   </a></span>");
    }
    out.write(" </div>");
    // container for item navigation
    out.write(" <div id='" + divId + "-selector' class='pickerSelector'>");
    out.write("  <div class='pickerResults'>");
    out.write("   <div class='pickerResultsHeader'>");
    out.write("    <div class='pickerNavControls'>");
    out.write("     <span class='pickerNavUp'>");
    out.write("      <a id='" + divId + "-nav-up' href='#'><img src='");
    out.write(contextPath);
    out.write("/images/icons/arrow_up.gif' border='0' alt='");
    out.write(msg.getString(MSG_GO_UP));
    out.write("' title='");
    out.write(msg.getString(MSG_GO_UP));
    out.write("'></a>");
    out.write("     </span>");
    out.write("     <span class='pickerNavBreadcrumb'>");
    out.write("      <span id='" + divId + "-nav-txt' class='pickerNavBreadcrumbText'></span></a>");
    out.write("     </span>");
    out.write("     <span class='pickerNavAddTag'>");
    out.write("      <span class='pickerAddTagIcon'></span>");
    out.write("      <span id='" + divId + "-addTag-linkContainer' class='pickerAddTagLinkContainer'>");
    out.write("       <a href='#' onclick='window." + objId + ".showAddTagForm(); return false;'>");
    out.write(msg.getString(MSG_ADD_A_TAG));
    out.write("</a>");
    out.write("      </span>");
    out.write("      <span id='" + divId + "-addTag-formContainer' class='pickerAddTagFormContainer'>");
    out.write("       <input id='" + divId + "-addTag-box' class='pickerAddTagBox' name='" + divId + "-addTag-box' type='text'>");
    out.write("       <img id='" + divId + "-addTag-ok' class='pickerAddTagImage' src='");
    out.write(contextPath);
    out.write("/images/office/action_successful.gif' alt='");
    out.write(msg.getString(MSG_ADD));
    out.write("' title='");
    out.write(msg.getString(MSG_ADD));
    out.write("'>");
    out.write("       <img id='" + divId + "-addTag-cancel' class='pickerAddTagImage' src='");
    out.write(contextPath);
    out.write("/images/office/action_failed.gif' alt='");
    out.write(msg.getString(MSG_CANCEL));
    out.write("' title='");
    out.write(msg.getString(MSG_CANCEL));
    out.write("'>");
    out.write("      </span>");
    out.write("     </span>");
    out.write("     <span id='" + divId + "-nav-add'></span>");
    out.write("    </div>");
    out.write("   </div>");
    // container for item selection
    out.write("   <div>");
    out.write("    <div id='" + divId + "-ajax-wait' class='pickerAjaxWait'");
    String height = getHeight();
    if (height != null) {
        out.write(" style='height:" + height + "'");
    }
    out.write("></div>");
    out.write("    <div id='" + divId + "-results-list' class='pickerResultsList'");
    if (height != null) {
        out.write(" style='height:" + height + "'");
    }
    out.write("></div>");
    out.write("   </div>");
    out.write("  </div>");
    // controls (OK & Cancel buttons etc.)
    out.write("  <div class='pickerFinishControls'>");
    out.write("   <div id='" + divId + "-finish' style='float:left' class='pickerButtons'><a href='javascript:" + objId + ".doneClicked();'>");
    out.write(msg.getString(MSG_OK));
    out.write("</a></div>");
    out.write("   <div style='float:right' class='pickerButtons'><a href='javascript:" + objId + ".cancelClicked();'>");
    out.write(msg.getString(MSG_CANCEL));
    out.write("</a></div>");
    out.write("  </div>");
    out.write(" </div>");
    // container for the selected items
    out.write(" <div id='" + divId + "-selected' class='pickerSelectedItems'></div>");
    out.write("</div>");
}
Also used : UserTransaction(javax.transaction.UserTransaction) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ResponseWriter(javax.faces.context.ResponseWriter) NodeService(org.alfresco.service.cmr.repository.NodeService) ResourceBundle(java.util.ResourceBundle) Map(java.util.Map) IOException(java.io.IOException)

Example 49 with UserTransaction

use of javax.transaction.UserTransaction in project acs-community-packaging by Alfresco.

the class BaseAjaxItemPicker method encodeBegin.

/**
 * @see javax.faces.component.UIComponentBase#encodeBegin(javax.faces.context.FacesContext)
 */
public void encodeBegin(FacesContext fc) throws IOException {
    if (isRendered() == false) {
        return;
    }
    ResponseWriter out = fc.getResponseWriter();
    String formClientId = Utils.getParentForm(fc, this).getClientId(fc);
    Map attrs = this.getAttributes();
    ResourceBundle msg = Application.getBundle(fc);
    // get values from submitted value or none selected
    String selectedValues = null;
    String selectedNames = null;
    String selectedItems = null;
    List<NodeRef> submitted = null;
    if (getSingleSelect() == true) {
        NodeRef ref = (NodeRef) getSubmittedValue();
        if (ref == null) {
            Object objRef = getValue();
            if (objRef instanceof String) {
                ref = new NodeRef((String) objRef);
            } else if (objRef instanceof NodeRef) {
                ref = (NodeRef) objRef;
            }
        }
        if (ref != null) {
            submitted = new ArrayList<NodeRef>(1);
            submitted.add(ref);
        }
    } else {
        Object value = getSubmittedValue();
        if (value == null) {
            value = getValue();
        }
        if (value instanceof List) {
            submitted = (List<NodeRef>) value;
        } else if (value instanceof String) {
            // special case for "empty" submitted value
            if (!value.equals(EMPTY)) {
                submitted = new ArrayList<NodeRef>(1);
                submitted.add(new NodeRef(value.toString()));
            }
        }
    }
    if (submitted != null) {
        UserTransaction tx = null;
        try {
            tx = Repository.getUserTransaction(fc, true);
            tx.begin();
            StringBuilder nameBuf = new StringBuilder(128);
            StringBuilder valueBuf = new StringBuilder(128);
            StringBuilder itemBuf = new StringBuilder(256);
            NodeService nodeService = (NodeService) FacesContextUtils.getRequiredWebApplicationContext(fc).getBean("nodeService");
            for (NodeRef value : submitted) {
                String name = (String) nodeService.getProperty(value, ContentModel.PROP_NAME);
                String icon = (String) nodeService.getProperty(value, ApplicationModel.PROP_ICON);
                if (nameBuf.length() != 0) {
                    nameBuf.append(", ");
                    valueBuf.append(",");
                    itemBuf.append(",");
                }
                nameBuf.append(name);
                valueBuf.append(value.toString());
                itemBuf.append(getItemJson(value.toString(), name, icon));
            }
            selectedNames = nameBuf.toString();
            selectedValues = valueBuf.toString();
            selectedItems = "[" + itemBuf.toString() + "]";
            // commit the transaction
            tx.commit();
        } catch (Throwable err) {
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception tex) {
            }
        }
    }
    // generate the Ids for our script object and containing DIV element
    String divId = getId();
    String objId = divId + "Obj";
    // generate the script to create and init our script object
    String contextPath = fc.getExternalContext().getRequestContextPath();
    out.write("<script type='text/javascript'>");
    out.write("function init" + divId + "() {");
    out.write(" window." + objId + " = new AlfPicker('" + divId + "','" + objId + "','" + getServiceCall() + "','" + formClientId + "'," + getSingleSelect() + ");");
    if (getInitialSelection() != null) {
        out.write(" window." + objId + ".setStartId('" + getInitialSelection() + "');");
    }
    if (getDefaultIcon() != null) {
        out.write(" window." + objId + ".setDefaultIcon('" + getDefaultIcon() + "');");
    }
    if ((!getSingleSelect()) && (selectedItems != null)) {
        out.write(" window." + objId + ".setSelectedItems('" + selectedItems + "');");
    }
    // write any addition custom request attributes required by specific picker implementations
    String requestProps = getRequestAttributes();
    if (requestProps != null) {
        out.write(" window." + objId + ".setRequestAttributes('" + requestProps + "');");
    }
    out.write("}");
    out.write("window.addEvent('domready', init" + divId + ");");
    out.write("</script>");
    // generate the DIV structure for our component as expected by the script object
    out.write("<div id='" + divId + "' class='picker'>");
    out.write(" <input id='" + getHiddenFieldName() + "' name='" + getHiddenFieldName() + "' type='hidden' value='");
    if (selectedValues != null) {
        out.write(selectedValues);
    }
    out.write("'>");
    // current selection displayed as link and message to launch the selector
    out.write(" <div id='" + divId + "-noitems'");
    if (attrs.get("style") != null) {
        out.write(" style=\"");
        out.write((String) attrs.get("style"));
        out.write('"');
    }
    if (attrs.get("styleClass") != null) {
        out.write(" class=");
        out.write((String) attrs.get("styleClass"));
    }
    out.write(">");
    out.write("  <span class='pickerActionButton'><a href='javascript:" + objId + ".showSelector();'>");
    if (selectedNames == null) {
        out.write(getLabel());
    } else {
        out.write(selectedNames);
    }
    out.write("</a></span>");
    out.write(" </div>");
    // container for item navigation
    out.write(" <div id='" + divId + "-selector' class='pickerSelector'>");
    out.write("  <div class='pickerResults'>");
    out.write("   <div class='pickerResultsHeader'>");
    out.write("    <div class='pickerNavControls'>");
    out.write("     <span class='pickerNavUp'>");
    out.write("      <a id='" + divId + "-nav-up' href='#'><img src='");
    out.write(contextPath);
    out.write("/images/icons/arrow_up.gif' border='0' alt='");
    out.write(msg.getString(MSG_GO_UP));
    out.write("' title='");
    out.write(msg.getString(MSG_GO_UP));
    out.write("'></a>");
    out.write("     </span>");
    out.write("     <span class='pickerNavBreadcrumb'>");
    out.write("      <div id='" + divId + "-nav-bread' class='pickerNavBreadcrumbPanel'></div>");
    out.write("      <a href='javascript:" + objId + ".breadcrumbToggle();'><span id='" + divId + "-nav-txt'></span><img border='0' src='");
    out.write(contextPath);
    out.write("/images/icons/arrow_open.gif'></a>");
    out.write("     </span>");
    out.write("     <span id='" + divId + "-nav-add'></span>");
    out.write("    </div>");
    out.write("   </div>");
    // container for item selection
    out.write("   <div>");
    out.write("    <div id='" + divId + "-ajax-wait' class='pickerAjaxWait'");
    String height = getHeight();
    if (height != null) {
        out.write(" style='height:" + height + "'");
    }
    out.write("></div>");
    out.write("    <div id='" + divId + "-results-list' class='pickerResultsList'");
    if (height != null) {
        out.write(" style='height:" + height + "'");
    }
    out.write("></div>");
    out.write("   </div>");
    out.write("  </div>");
    // controls (OK & Cancel buttons etc.)
    out.write("  <div class='pickerFinishControls'>");
    out.write("   <div id='" + divId + "-finish' style='float:left' class='pickerButtons'><a href='javascript:" + objId + ".doneClicked();'>");
    out.write(msg.getString(MSG_OK));
    out.write("</a></div>");
    out.write("   <div style='float:right' class='pickerButtons'><a href='javascript:" + objId + ".cancelClicked();'>");
    out.write(msg.getString(MSG_CANCEL));
    out.write("</a></div>");
    out.write("  </div>");
    out.write(" </div>");
    // container for the selected items
    out.write(" <div id='" + divId + "-selected' class='pickerSelectedItems'></div>");
    out.write("</div>");
}
Also used : UserTransaction(javax.transaction.UserTransaction) NodeService(org.alfresco.service.cmr.repository.NodeService) ArrayList(java.util.ArrayList) IOException(java.io.IOException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ResponseWriter(javax.faces.context.ResponseWriter) ResourceBundle(java.util.ResourceBundle) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 50 with UserTransaction

use of javax.transaction.UserTransaction 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)

Aggregations

UserTransaction (javax.transaction.UserTransaction)642 EntityManager (javax.persistence.EntityManager)244 Test (org.testng.annotations.Test)187 Test (org.junit.Test)157 JPATest (org.jpwh.env.JPATest)138 InitialContext (javax.naming.InitialContext)62 BigDecimal (java.math.BigDecimal)53 HashMap (java.util.HashMap)52 IOException (java.io.IOException)50 Context (javax.naming.Context)49 List (java.util.List)47 FacesContext (javax.faces.context.FacesContext)43 NamingException (javax.naming.NamingException)43 NodeRef (org.alfresco.service.cmr.repository.NodeRef)43 Node (javax.jcr.Node)42 KieSession (org.kie.api.runtime.KieSession)42 Query (javax.persistence.Query)38 QueryingTest (org.jpwh.test.querying.QueryingTest)36 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)35 Item (org.jpwh.model.querying.Item)35