Search in sources :

Example 1 with MultilingualContentService

use of org.alfresco.service.cmr.ml.MultilingualContentService in project acs-community-packaging by Alfresco.

the class WorkspaceClipboardItem method paste.

/**
 * @see org.alfresco.web.bean.clipboard.ClipboardItem#paste(javax.faces.context.FacesContext, java.lang.String, int)
 */
public boolean paste(final FacesContext fc, String viewId, final int action) {
    final ServiceRegistry serviceRegistry = getServiceRegistry();
    final RetryingTransactionHelper retryingTransactionHelper = serviceRegistry.getTransactionService().getRetryingTransactionHelper();
    if (super.canCopyToViewId(viewId) || WORKSPACE_PASTE_VIEW_ID.equals(viewId) || FORUMS_PASTE_VIEW_ID.equals(viewId) || FORUM_PASTE_VIEW_ID.equals(viewId)) {
        NavigationBean navigator = (NavigationBean) FacesHelper.getManagedBean(fc, NavigationBean.BEAN_NAME);
        final NodeRef destRef = new NodeRef(Repository.getStoreRef(), navigator.getCurrentNodeId());
        final DictionaryService dd = serviceRegistry.getDictionaryService();
        final NodeService nodeService = serviceRegistry.getNodeService();
        final FileFolderService fileFolderService = serviceRegistry.getFileFolderService();
        final CopyService copyService = serviceRegistry.getCopyService();
        final MultilingualContentService multilingualContentService = serviceRegistry.getMultilingualContentService();
        final boolean isPrimaryParent;
        final ChildAssociationRef assocRef;
        if (getParent() == null) {
            assocRef = nodeService.getPrimaryParent(getNodeRef());
            isPrimaryParent = true;
        } else {
            NodeRef parentNodeRef = getParent();
            List<ChildAssociationRef> assocList = nodeService.getParentAssocs(getNodeRef());
            ChildAssociationRef foundRef = null;
            if (assocList != null) {
                for (ChildAssociationRef assocListEntry : assocList) {
                    if (parentNodeRef.equals(assocListEntry.getParentRef())) {
                        foundRef = assocListEntry;
                        break;
                    }
                }
            }
            assocRef = foundRef;
            isPrimaryParent = parentNodeRef.equals(nodeService.getPrimaryParent(getNodeRef()).getParentRef());
        }
        // initial name to attempt the copy of the item with
        String name = getName();
        String translationPrefix = "";
        if (action == UIClipboardShelfItem.ACTION_PASTE_LINK) {
            // copy as link was specifically requested by the user
            String linkTo = Application.getMessage(fc, MSG_LINK_TO);
            name = linkTo + ' ' + name;
        }
        // Loop until we find a target name that doesn't exist
        for (; ; ) {
            try {
                final String currentTranslationPrefix = translationPrefix;
                final String currentName = name;
                // attempt each copy/paste in its own transaction
                retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Void>() {

                    public Void execute() throws Throwable {
                        if (getMode() == ClipboardStatus.COPY) {
                            if (action == UIClipboardShelfItem.ACTION_PASTE_LINK) {
                                // LINK operation
                                if (logger.isDebugEnabled())
                                    logger.debug("Attempting to link node ID: " + getNodeRef() + " into node: " + destRef.toString());
                                // create the node using the nodeService (can only use FileFolderService for content)
                                if (checkExists(currentName + LINK_NODE_EXTENSION, destRef) == false) {
                                    Map<QName, Serializable> props = new HashMap<QName, Serializable>(2, 1.0f);
                                    String newName = currentName + LINK_NODE_EXTENSION;
                                    props.put(ContentModel.PROP_NAME, newName);
                                    props.put(ContentModel.PROP_LINK_DESTINATION, getNodeRef());
                                    if (dd.isSubClass(getType(), ContentModel.TYPE_CONTENT)) {
                                        // create File Link node
                                        ChildAssociationRef childRef = nodeService.createNode(destRef, ContentModel.ASSOC_CONTAINS, QName.createQName(assocRef.getQName().getNamespaceURI(), newName), ApplicationModel.TYPE_FILELINK, props);
                                        // apply the titled aspect - title and description
                                        Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>(2, 1.0f);
                                        titledProps.put(ContentModel.PROP_TITLE, currentName);
                                        titledProps.put(ContentModel.PROP_DESCRIPTION, currentName);
                                        nodeService.addAspect(childRef.getChildRef(), ContentModel.ASPECT_TITLED, titledProps);
                                    } else {
                                        // create Folder link node
                                        ChildAssociationRef childRef = nodeService.createNode(destRef, ContentModel.ASSOC_CONTAINS, assocRef.getQName(), ApplicationModel.TYPE_FOLDERLINK, props);
                                        // apply the uifacets aspect - icon, title and description props
                                        Map<QName, Serializable> uiFacetsProps = new HashMap<QName, Serializable>(4, 1.0f);
                                        uiFacetsProps.put(ApplicationModel.PROP_ICON, "space-icon-link");
                                        uiFacetsProps.put(ContentModel.PROP_TITLE, currentName);
                                        uiFacetsProps.put(ContentModel.PROP_DESCRIPTION, currentName);
                                        nodeService.addAspect(childRef.getChildRef(), ApplicationModel.ASPECT_UIFACETS, uiFacetsProps);
                                    }
                                }
                            } else {
                                // COPY operation
                                if (logger.isDebugEnabled())
                                    logger.debug("Attempting to copy node: " + getNodeRef() + " into node ID: " + destRef.toString());
                                // first check that we are not attempting to copy a duplicate into the same parent
                                if (destRef.equals(assocRef.getParentRef()) && currentName.equals(getName())) {
                                    // manually change the name if this occurs
                                    throw new FileExistsException(destRef, currentName);
                                }
                                if (dd.isSubClass(getType(), ContentModel.TYPE_CONTENT) || dd.isSubClass(getType(), ContentModel.TYPE_FOLDER)) {
                                    // copy the file/folder
                                    fileFolderService.copy(getNodeRef(), destRef, currentName);
                                } else if (dd.isSubClass(getType(), ContentModel.TYPE_MULTILINGUAL_CONTAINER)) {
                                    // copy the mlContainer and its translations
                                    multilingualContentService.copyTranslationContainer(getNodeRef(), destRef, currentTranslationPrefix);
                                } else {
                                    // copy the node
                                    if (checkExists(currentName, destRef) == false) {
                                        copyService.copyAndRename(getNodeRef(), destRef, ContentModel.ASSOC_CONTAINS, assocRef.getQName(), true);
                                    }
                                }
                            }
                        } else {
                            // MOVE operation
                            if (logger.isDebugEnabled())
                                logger.debug("Attempting to move node: " + getNodeRef() + " into node ID: " + destRef.toString());
                            if (dd.isSubClass(getType(), ContentModel.TYPE_CONTENT) || dd.isSubClass(getType(), ContentModel.TYPE_FOLDER)) {
                                // move the file/folder
                                fileFolderService.moveFrom(getNodeRef(), getParent(), destRef, currentName);
                            } else if (dd.isSubClass(getType(), ContentModel.TYPE_MULTILINGUAL_CONTAINER)) {
                                // copy the mlContainer and its translations
                                multilingualContentService.moveTranslationContainer(getNodeRef(), destRef);
                            } else {
                                if (isPrimaryParent) {
                                    // move the node
                                    nodeService.moveNode(getNodeRef(), destRef, ContentModel.ASSOC_CONTAINS, assocRef.getQName());
                                } else {
                                    nodeService.removeChild(getParent(), getNodeRef());
                                    nodeService.addChild(destRef, getNodeRef(), assocRef.getTypeQName(), assocRef.getQName());
                                }
                            }
                        }
                        return null;
                    }
                });
                // We got here without error, so no need to loop with a new name
                break;
            } catch (FileExistsException fileExistsErr) {
                // If mode is COPY, have another go around the loop with a new name
                if (getMode() == ClipboardStatus.COPY) {
                    String copyOf = Application.getMessage(fc, MSG_COPY_OF);
                    name = copyOf + ' ' + name;
                    translationPrefix = copyOf + ' ' + translationPrefix;
                } else {
                    // we should not rename an item when it is being moved - so exit
                    throw fileExistsErr;
                }
            }
        }
        return true;
    } else {
        return false;
    }
}
Also used : MultilingualContentService(org.alfresco.service.cmr.ml.MultilingualContentService) Serializable(java.io.Serializable) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) QName(org.alfresco.service.namespace.QName) NodeService(org.alfresco.service.cmr.repository.NodeService) FileFolderService(org.alfresco.service.cmr.model.FileFolderService) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) CopyService(org.alfresco.service.cmr.repository.CopyService) NodeRef(org.alfresco.service.cmr.repository.NodeRef) DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) NavigationBean(org.alfresco.web.bean.NavigationBean) ServiceRegistry(org.alfresco.service.ServiceRegistry) HashMap(java.util.HashMap) Map(java.util.Map) FileExistsException(org.alfresco.service.cmr.model.FileExistsException)

Example 2 with MultilingualContentService

use of org.alfresco.service.cmr.ml.MultilingualContentService in project acs-community-packaging by Alfresco.

the class MultilingualUtils method canMoveEachTranslation.

/**
 * Returns true if the current user can move each translation of the mlContainer of the given node
 *
 * @param multlingualDocument Node
 * @param fc FacesContext
 * @return boolean
 */
public static boolean canMoveEachTranslation(Node multlingualDocument, FacesContext fc) {
    boolean can = true;
    MultilingualContentService mlservice = getMultilingualContentService(fc);
    Map<Locale, NodeRef> translations = mlservice.getTranslations(multlingualDocument.getNodeRef());
    for (Map.Entry<Locale, NodeRef> entry : translations.entrySet()) {
        Node translation = new Node(entry.getValue());
        if (translation.hasPermission(PermissionService.DELETE_NODE) == false) {
            can = false;
            break;
        }
    }
    return can;
}
Also used : Locale(java.util.Locale) MultilingualContentService(org.alfresco.service.cmr.ml.MultilingualContentService) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Node(org.alfresco.web.bean.repository.Node) Map(java.util.Map)

Example 3 with MultilingualContentService

use of org.alfresco.service.cmr.ml.MultilingualContentService in project acs-community-packaging by Alfresco.

the class MultilingualUtils method canDeleteEachTranslation.

/**
 * Returns true if the current user can delete each translation of the mlContainer of the given node
 *
 * @param multlingualDocument Node
 * @param fc FacesContext
 * @return boolean
 */
public static boolean canDeleteEachTranslation(Node multlingualDocument, FacesContext fc) {
    boolean can = true;
    MultilingualContentService mlservice = getMultilingualContentService(fc);
    Map<Locale, NodeRef> translations = mlservice.getTranslations(multlingualDocument.getNodeRef());
    for (Map.Entry<Locale, NodeRef> entry : translations.entrySet()) {
        Node translation = new Node(entry.getValue());
        if (translation.hasPermission(PermissionService.DELETE_NODE) == false || translation.isLocked() == true || translation.hasAspect(ContentModel.ASPECT_WORKING_COPY) == true) {
            can = false;
            break;
        }
    }
    return can;
}
Also used : Locale(java.util.Locale) MultilingualContentService(org.alfresco.service.cmr.ml.MultilingualContentService) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Node(org.alfresco.web.bean.repository.Node) Map(java.util.Map)

Example 4 with MultilingualContentService

use of org.alfresco.service.cmr.ml.MultilingualContentService in project acs-community-packaging by Alfresco.

the class MultilingualUtils method canAddChildrenToPivotSpace.

/**
 * Returns true if the current user has enough right to add a content to the space
 * where the pivot translation is located in.
 *
 * @param multlingualDocument Node
 * @param fc FacesContext
 * @return boolean
 */
public static boolean canAddChildrenToPivotSpace(Node multlingualDocument, FacesContext fc) {
    MultilingualContentService mlservice = getMultilingualContentService(fc);
    NodeService nodeService = getNodeService(fc);
    // get the pivot translation and get the space where it's located
    NodeRef pivot = mlservice.getPivotTranslation(multlingualDocument.getNodeRef());
    NodeRef space = nodeService.getPrimaryParent(pivot).getParentRef();
    // return if the current user can add a content to the space of the pivot
    return new Node(space).hasPermission(PermissionService.ADD_CHILDREN);
}
Also used : MultilingualContentService(org.alfresco.service.cmr.ml.MultilingualContentService) NodeRef(org.alfresco.service.cmr.repository.NodeRef) NodeService(org.alfresco.service.cmr.repository.NodeService) Node(org.alfresco.web.bean.repository.Node)

Example 5 with MultilingualContentService

use of org.alfresco.service.cmr.ml.MultilingualContentService in project acs-community-packaging by Alfresco.

the class DeleteDocEvaluator method evaluate.

/**
 * @see org.alfresco.web.action.ActionEvaluator#evaluate(org.alfresco.web.bean.repository.Node)
 */
public boolean evaluate(Node node) {
    FacesContext fc = FacesContext.getCurrentInstance();
    // the node to delete is a ml container, test if the user has enought right on each translation
    if (node.getType().equals(ContentModel.TYPE_MULTILINGUAL_CONTAINER)) {
        return MultilingualUtils.canDeleteEachTranslation(node, fc);
    }
    boolean isPivot = false;
    // special case for multilingual documents
    if (node.getAspects().contains(ContentModel.ASPECT_MULTILINGUAL_DOCUMENT)) {
        MultilingualContentService mlservice = (MultilingualContentService) FacesHelper.getManagedBean(fc, "MultilingualContentService");
        // if the translation is the last translation, user can delete it
        if (mlservice.getTranslations(node.getNodeRef()).size() == 1) {
            isPivot = false;
        } else // Else if the node is the pivot language, user can't delete it
        if (mlservice.getPivotTranslation(node.getNodeRef()).getId().equalsIgnoreCase(node.getNodeRef().getId())) {
            isPivot = true;
        }
    // finally, the node is not the pivot translation, user can delete it
    }
    return (node.isLocked() == false && node.hasAspect(ContentModel.ASPECT_WORKING_COPY) == false && isPivot == false);
}
Also used : FacesContext(javax.faces.context.FacesContext) MultilingualContentService(org.alfresco.service.cmr.ml.MultilingualContentService)

Aggregations

MultilingualContentService (org.alfresco.service.cmr.ml.MultilingualContentService)6 NodeRef (org.alfresco.service.cmr.repository.NodeRef)4 Map (java.util.Map)3 Node (org.alfresco.web.bean.repository.Node)3 Locale (java.util.Locale)2 FacesContext (javax.faces.context.FacesContext)2 NodeService (org.alfresco.service.cmr.repository.NodeService)2 Serializable (java.io.Serializable)1 HashMap (java.util.HashMap)1 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)1 ServiceRegistry (org.alfresco.service.ServiceRegistry)1 DictionaryService (org.alfresco.service.cmr.dictionary.DictionaryService)1 FileExistsException (org.alfresco.service.cmr.model.FileExistsException)1 FileFolderService (org.alfresco.service.cmr.model.FileFolderService)1 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)1 CopyService (org.alfresco.service.cmr.repository.CopyService)1 QName (org.alfresco.service.namespace.QName)1 NavigationBean (org.alfresco.web.bean.NavigationBean)1 UserPreferencesBean (org.alfresco.web.bean.users.UserPreferencesBean)1