Search in sources :

Example 46 with InvalidNodeRefException

use of org.alfresco.service.cmr.repository.InvalidNodeRefException in project acs-community-packaging by Alfresco.

the class UserShortcutsBean method click.

/**
 * Action handler bound to the user shortcuts Shelf component called when a node is clicked
 */
public void click(ActionEvent event) {
    // work out which node was clicked from the event data
    UIShortcutsShelfItem.ShortcutEvent shortcutEvent = (UIShortcutsShelfItem.ShortcutEvent) event;
    Node selectedNode = getShortcuts().get(shortcutEvent.Index);
    try {
        if (getPermissionService().hasPermission(selectedNode.getNodeRef(), PermissionService.READ) == AccessStatus.ALLOWED) {
            if (getNodeService().exists(selectedNode.getNodeRef()) == false) {
                throw new InvalidNodeRefException(selectedNode.getNodeRef());
            }
            DictionaryService dd = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getDictionaryService();
            if (dd.isSubClass(selectedNode.getType(), ContentModel.TYPE_FOLDER)) {
                // then navigate to the appropriate node in UI
                // use browse bean functionality for this as it will update the breadcrumb for us
                this.browseBean.updateUILocation(selectedNode.getNodeRef());
            } else if (dd.isSubClass(selectedNode.getType(), ContentModel.TYPE_CONTENT)) {
                // view details for document
                this.browseBean.setupContentAction(selectedNode.getId(), true);
                FacesContext fc = FacesContext.getCurrentInstance();
                fc.getApplication().getNavigationHandler().handleNavigation(fc, null, "dialog:showDocDetails");
            }
        } else {
            Utils.addErrorMessage(Application.getMessage(FacesContext.getCurrentInstance(), "error_shortcut_permissions"));
        }
    } catch (InvalidNodeRefException refErr) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { selectedNode.getId() }));
        // remove item from the shortcut list
        UserTransaction tx = null;
        try {
            FacesContext context = FacesContext.getCurrentInstance();
            tx = Repository.getUserTransaction(context);
            tx.begin();
            List<String> shortcuts = getShortcutList(context);
            if (shortcuts.size() > shortcutEvent.Index) {
                // remove the shortcut from the saved list and persist back
                shortcuts.remove(shortcutEvent.Index);
                PreferencesService.getPreferences(context).setValue(PREF_SHORTCUTS, (Serializable) shortcuts);
                // commit the transaction
                tx.commit();
                // remove shortcut Node from the in-memory list
                Node node = getShortcuts().remove(shortcutEvent.Index);
                if (logger.isDebugEnabled())
                    logger.debug("Removed deleted node: " + node.getName() + " from the user shortcuts list.");
            }
        } catch (Throwable err) {
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception tex) {
            }
        }
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) Serializable(java.io.Serializable) Node(org.alfresco.web.bean.repository.Node) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) ArrayList(java.util.ArrayList) List(java.util.List) UIShortcutsShelfItem(org.alfresco.web.ui.repo.component.shelf.UIShortcutsShelfItem) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException)

Example 47 with InvalidNodeRefException

use of org.alfresco.service.cmr.repository.InvalidNodeRefException in project acs-community-packaging by Alfresco.

the class DeleteUserDialog method search.

public String search() {
    if (this.searchCriteria == null || this.searchCriteria.length() == 0) {
        this.users = Collections.<Node>emptyList();
    } else {
        FacesContext context = FacesContext.getCurrentInstance();
        UserTransaction tx = null;
        try {
            tx = Repository.getUserTransaction(context, true);
            tx.begin();
            // define the query to find people by their first or last name
            String search = ISO9075.encode(this.searchCriteria);
            List<Pair<QName, String>> filter = Utils.generatePersonFilter(search);
            if (logger.isDebugEnabled()) {
                logger.debug("Query filter: " + filter);
            }
            List<PersonInfo> persons = getPersonService().getPeople(filter, true, Utils.generatePersonSort(), new PagingRequest(Utils.getPersonMaxResults(), null)).getPage();
            if (logger.isDebugEnabled()) {
                logger.debug("Found " + persons.size() + " users");
            }
            this.users = new ArrayList<Node>(persons.size());
            for (PersonInfo person : persons) {
                // create our Node representation
                MapNode node = new MapNode(person.getNodeRef());
                // set data binding properties
                // this will also force initialisation of the props now during the UserTransaction
                // it is much better for performance to do this now rather than during page bind
                Map<String, Object> props = node.getProperties();
                props.put("fullName", ((String) props.get("firstName")) + ' ' + ((String) props.get("lastName")));
                NodeRef homeFolderNodeRef = (NodeRef) props.get("homeFolder");
                if (homeFolderNodeRef != null) {
                    props.put("homeSpace", homeFolderNodeRef);
                }
                this.users.add(node);
            }
            // commit the transaction
            tx.commit();
        } catch (InvalidNodeRefException refErr) {
            Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, Repository.ERROR_NODEREF), new Object[] { "root" }));
            this.users = Collections.<Node>emptyList();
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception tex) {
            }
        } catch (Exception err) {
            Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, Repository.ERROR_GENERIC), err.getMessage()), err);
            this.users = Collections.<Node>emptyList();
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception tex) {
            }
        }
    }
    // return null to stay on the same page
    return null;
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) PersonInfo(org.alfresco.service.cmr.security.PersonService.PersonInfo) Node(org.alfresco.web.bean.repository.Node) MapNode(org.alfresco.web.bean.repository.MapNode) MapNode(org.alfresco.web.bean.repository.MapNode) PagingRequest(org.alfresco.query.PagingRequest) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) ReportedException(org.alfresco.web.ui.common.ReportedException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) Pair(org.alfresco.util.Pair)

Example 48 with InvalidNodeRefException

use of org.alfresco.service.cmr.repository.InvalidNodeRefException in project acs-community-packaging by Alfresco.

the class Repository method getUsers.

/**
 * Query a list of Person type nodes from the repo
 * It is currently assumed that all Person nodes exist below the Repository root node
 *
 * @param context Faces Context
 * @param nodeService The node service
 * @param personService PersonService
 * @return List of Person node objects
 */
public static List<Node> getUsers(FacesContext context, NodeService nodeService, PersonService personService) {
    List<Node> personNodes = null;
    UserTransaction tx = null;
    try {
        tx = Repository.getUserTransaction(context, true);
        tx.begin();
        NodeRef peopleRef = personService.getPeopleContainer();
        // TODO: better to perform an XPath search or a get for a specific child type here?
        List<ChildAssociationRef> childRefs = nodeService.getChildAssocs(peopleRef);
        personNodes = new ArrayList<Node>(childRefs.size());
        for (ChildAssociationRef ref : childRefs) {
            // create our Node representation from the NodeRef
            NodeRef nodeRef = ref.getChildRef();
            if (nodeService.getType(nodeRef).equals(ContentModel.TYPE_PERSON)) {
                // create our Node representation
                MapNode node = new MapNode(nodeRef);
                // set data binding properties
                // this will also force initialisation of the props now during the UserTransaction
                // it is much better for performance to do this now rather than during page bind
                Map<String, Object> props = node.getProperties();
                String firstName = (String) props.get("firstName");
                String lastName = (String) props.get("lastName");
                props.put("fullName", (firstName != null ? firstName : "") + ' ' + (lastName != null ? lastName : ""));
                NodeRef homeFolderNodeRef = (NodeRef) props.get("homeFolder");
                if (homeFolderNodeRef != null) {
                    props.put("homeSpace", homeFolderNodeRef);
                }
                personNodes.add(node);
            }
        }
        // commit the transaction
        tx.commit();
    } catch (InvalidNodeRefException refErr) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, Repository.ERROR_NODEREF), new Object[] { "root" }));
        personNodes = Collections.<Node>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);
        personNodes = Collections.<Node>emptyList();
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception tex) {
        }
    }
    return personNodes;
}
Also used : UserTransaction(javax.transaction.UserTransaction) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException)

Example 49 with InvalidNodeRefException

use of org.alfresco.service.cmr.repository.InvalidNodeRefException in project acs-community-packaging by Alfresco.

the class EditContentPropertiesDialog method formatErrorMessage.

/**
 * Formats the error message to display if an error occurs during finish processing
 *
 * @param exception The exception
 * @return The formatted message
 */
@Override
protected String formatErrorMessage(Throwable exception) {
    if (editableNode != null) {
        // special case for Mimetype - since this is a sub-property of the ContentData object
        // we must extract it so it can be edited in the client, then we check for it later
        // and create a new ContentData object to wrap it and it's associated URL
        ContentData content = (ContentData) this.editableNode.getProperties().get(ContentModel.PROP_CONTENT);
        if (content != null) {
            this.editableNode.getProperties().put(TEMP_PROP_MIMETYPE, content.getMimetype());
            this.editableNode.getProperties().put(TEMP_PROP_ENCODING, content.getEncoding());
        }
    }
    if (exception instanceof FileExistsException) {
        return MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_EXISTS), ((FileExistsException) exception).getName());
    } else if (exception instanceof InvalidNodeRefException) {
        return MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { this.browseBean.getDocument().getId() });
    } else {
        return super.formatErrorMessage(exception);
    }
}
Also used : ContentData(org.alfresco.service.cmr.repository.ContentData) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) FileExistsException(org.alfresco.service.cmr.model.FileExistsException)

Example 50 with InvalidNodeRefException

use of org.alfresco.service.cmr.repository.InvalidNodeRefException in project acs-community-packaging by Alfresco.

the class VersionedDocumentDetailsDialog method setBrowsingVersion.

/**
 * Implementation of setBrowsingVersion action event to be use with the needed parameters.
 */
private void setBrowsingVersion(String id, String versionLabel, String lang) {
    // test if the mandatories parameter are valid
    ParameterCheck.mandatoryString("The id of the node", id);
    ParameterCheck.mandatoryString("The version of the node", versionLabel);
    try {
        // try to get the nodeRef with the given ID. This node is not a versioned node.
        NodeRef currentNodeRef = new NodeRef(Repository.getStoreRef(), id);
        // the threatment is different if the node is a translation or a mlContainer
        if (getNodeService().getType(currentNodeRef).equals(ContentModel.TYPE_MULTILINGUAL_CONTAINER)) {
            // test if the lang parameter is valid
            ParameterCheck.mandatoryString("The lang of the node", lang);
            fromPreviousEditon = true;
            versionLabel = cleanVersionLabel(versionLabel);
            // set the edition information of the mlContainer of the selected translation version
            this.editionHistory = getEditionService().getEditions(currentNodeRef);
            this.documentEdition = editionHistory.getVersion(versionLabel);
            // set the version to display
            this.documentVersion = getBrowsingVersionForMLContainer(currentNodeRef, versionLabel, lang);
        } else {
            fromPreviousEditon = false;
            // set the version history
            this.versionHistory = getVersionService().getVersionHistory(currentNodeRef);
            // set the version to display
            this.documentVersion = getBrowsingVersionForDocument(currentNodeRef, versionLabel);
        }
    } catch (InvalidNodeRefException refErr) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { id }));
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException)

Aggregations

InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)61 NodeRef (org.alfresco.service.cmr.repository.NodeRef)49 Node (org.alfresco.web.bean.repository.Node)21 FacesContext (javax.faces.context.FacesContext)20 UserTransaction (javax.transaction.UserTransaction)16 MapNode (org.alfresco.web.bean.repository.MapNode)12 InvalidSharedIdException (org.alfresco.service.cmr.quickshare.InvalidSharedIdException)10 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)9 QName (org.alfresco.service.namespace.QName)9 IOException (java.io.IOException)8 HashMap (java.util.HashMap)8 AbortProcessingException (javax.faces.event.AbortProcessingException)8 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)8 UIActionLink (org.alfresco.web.ui.common.component.UIActionLink)8 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)7 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)7 Serializable (java.io.Serializable)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)4