Java Code Examples for org.alfresco.model.ContentModel#TYPE_MULTILINGUAL_CONTAINER

The following examples show how to use org.alfresco.model.ContentModel#TYPE_MULTILINGUAL_CONTAINER . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultilingualContentServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/** @inheritDoc */
public void deleteTranslationContainer(NodeRef mlContainerNodeRef)
{
    if (!ContentModel.TYPE_MULTILINGUAL_CONTAINER.equals(nodeService.getType(mlContainerNodeRef)))
    {
        throw new IllegalArgumentException(
                "Node type must be " + ContentModel.TYPE_MULTILINGUAL_CONTAINER);
    }

    // get the translations
    Map<Locale, NodeRef> translations = this.getTranslations(mlContainerNodeRef);

    // remember the number of childs
    int translationCount = translations.size();

    // remove the translations
    for(NodeRef translationToRemove : translations.values())
    {
        if (!nodeService.exists(translationToRemove))
        {
            // We've just queried for these
            throw new ConcurrencyFailureException("Translation has been deleted externally: " + translationToRemove);
        }
        nodeService.deleteNode(translationToRemove);
    }

    // Keep track of the container for pre-commit deletion
    TransactionalResourceHelper.getSet(KEY_ML_CONTAINERS_TO_DELETE).add(mlContainerNodeRef);
    AlfrescoTransactionSupport.bindListener(mlContainerCleaner);

    // done
    if (logger.isDebugEnabled())
    {
        logger.debug("ML container removed: \n" +
                "   Container:  " + mlContainerNodeRef + "\n" +
                "   Number of translations: " + translationCount);
    }
}
 
Example 2
Source File: MultilingualDocumentAspect.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Ensure that the locale is unique inside the <b>mlContainer</b>.
 *
 * If the locale of a pivot translation is modified, the pivot locale reference of the mlContainer
 * must be modified too.
 */
public void onUpdateProperties(NodeRef nodeRef, Map<QName, Serializable> before, Map<QName, Serializable> after)
{
    Locale localeBefore = (Locale)before.get(ContentModel.PROP_LOCALE);
    
    Locale localeAfter = null;
    Serializable objLocaleAfter = after.get(ContentModel.PROP_LOCALE);
    if (objLocaleAfter != null)
    {
        localeAfter = DefaultTypeConverter.INSTANCE.convert(Locale.class, objLocaleAfter);
    }
    
    // if the local has been modified
    if (localeBefore == null || !localeBefore.equals(localeAfter))
    {
        NodeRef mlContainer = multilingualContentService.getTranslationContainer(nodeRef);

        // Since the map returned by the getTranslations doesn't duplicate keys, the size of this map will be
        // different of the size of the number of children of the mlContainer if a duplicate locale is found.
        int transSize = multilingualContentService.getTranslations(mlContainer).size();
        int childSize = nodeService.getChildAssocs(mlContainer, ContentModel.ASSOC_MULTILINGUAL_CHILD, RegexQNamePattern.MATCH_ALL).size();

        // if duplicate locale found
        if(transSize != childSize)
        {
            // throw an exception and the current transaction will be rolled back. The properties will not be
            // longer in an illegal state.
            throw new IllegalArgumentException("The locale " + localeAfter +
                    " can't be changed for the node " + nodeRef +
                    " because this locale is already in use in an other translation of the same " +
                    ContentModel.TYPE_MULTILINGUAL_CONTAINER + ".");
        }

        // get the locale of ML Container
        Locale localMlContainer = (Locale) nodeService.getProperty(
                    mlContainer,
                    ContentModel.PROP_LOCALE);

        // if locale of the container is equals to the locale of
        // the node (before update). The nodeRef is the pivot language
        // and the locale of the mlContainer must be modified
        if(localeBefore != null && localeBefore.equals(localMlContainer))
        {
            nodeService.setProperty(
                    mlContainer,
                    ContentModel.PROP_LOCALE,
                    localeAfter);
        }

    }

    // else no action to perform
}
 
Example 3
Source File: MultilingualContentServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @inheritDoc
 */
public void moveTranslationContainer(NodeRef mlContainerNodeRef, NodeRef newParentRef) throws FileExistsException, FileNotFoundException
{
    if(!ContentModel.TYPE_MULTILINGUAL_CONTAINER.equals(nodeService.getType(mlContainerNodeRef)))
    {
        throw new IllegalArgumentException(
                "Node type must be " + ContentModel.TYPE_MULTILINGUAL_CONTAINER);
    }

    // if the container has no translation: nothing to do
    if(nodeService.getChildAssocs(mlContainerNodeRef, ContentModel.ASSOC_MULTILINGUAL_CHILD, RegexQNamePattern.MATCH_ALL).size() < 1)
    {
        if (logger.isDebugEnabled())
        {
            logger.debug("MLContainer has no translation " + mlContainerNodeRef);
        }

        return;
    }

    // keep a reference to the containing space before moving
    NodeRef spaceBefore = nodeService.getPrimaryParent(getPivotTranslation(mlContainerNodeRef)).getParentRef();

    if(spaceBefore.equals(newParentRef))
    {
        // nothing to do
        return;
    }

    // move each translation
    for(NodeRef translationToMove : getTranslations(mlContainerNodeRef).values())
    {
        fileFolderService.move(translationToMove, newParentRef, null);
    }

    if (logger.isDebugEnabled())
    {
        logger.debug("MLContainer moved: \n" +
                "   Old location of " + mlContainerNodeRef + " : " + spaceBefore + ") \n" +
                "   New location of " + mlContainerNodeRef + " : " + newParentRef + ")");
    }
}