Search in sources :

Example 21 with Reference

use of org.alfresco.repo.virtual.ref.Reference in project alfresco-repository by Alfresco.

the class VirtualNodeServiceExtension method createAssociation.

@Override
public AssociationRef createAssociation(NodeRef sourceRef, NodeRef targetRef, QName assocTypeQName) {
    Reference targetReference = Reference.fromNodeRef(targetRef);
    if (targetReference != null && getTrait().getType(materializeIfPossible(sourceRef)).equals(DownloadModel.TYPE_DOWNLOAD)) {
        // NOTE : this is enables downloads of virtual structures
        createDownloadAssociation(sourceRef, targetRef);
        AssociationRef assocRef = new AssociationRef(sourceRef, assocTypeQName, targetRef);
        return assocRef;
    } else {
        return getTrait().createAssociation(materializeIfPossible(sourceRef), materializeIfPossible(targetRef), assocTypeQName);
    }
}
Also used : Reference(org.alfresco.repo.virtual.ref.Reference) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 22 with Reference

use of org.alfresco.repo.virtual.ref.Reference in project alfresco-repository by Alfresco.

the class VirtualNodeServiceExtension method getChildAssocs.

@Override
public List<ChildAssociationRef> getChildAssocs(NodeRef nodeRef) {
    NodeServiceTrait theTrait = getTrait();
    boolean canVirtualize = canVirtualizeAssocNodeRef(nodeRef);
    if (canVirtualize) {
        Reference reference = smartStore.virtualize(nodeRef);
        List<ChildAssociationRef> virtualAssociations = smartStore.getChildAssocs(reference, RegexQNamePattern.MATCH_ALL, RegexQNamePattern.MATCH_ALL, Integer.MAX_VALUE, false);
        List<ChildAssociationRef> associations = new LinkedList<>(virtualAssociations);
        if (smartStore.canMaterialize(reference)) {
            NodeRef materialReference = smartStore.materialize(reference);
            List<ChildAssociationRef> actualAssociations = theTrait.getChildAssocs(materialReference, RegexQNamePattern.MATCH_ALL, RegexQNamePattern.MATCH_ALL, Integer.MAX_VALUE, false);
            associations.addAll(actualAssociations);
        }
        return associations;
    } else {
        return theTrait.getChildAssocs(nodeRef);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) NodeServiceTrait(org.alfresco.repo.node.db.traitextender.NodeServiceTrait) Reference(org.alfresco.repo.virtual.ref.Reference) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) LinkedList(java.util.LinkedList)

Example 23 with Reference

use of org.alfresco.repo.virtual.ref.Reference in project alfresco-repository by Alfresco.

the class VirtualPreferenceServiceExtension method setPreferences.

/**
 * If the favorites preferences are changed then for virtual references the
 * actual nodeRef is added/removed from favorites preferences instead of
 * virtual nodeRef. For non virtual entries or for preferences that are not
 * related to favorites the original implementation from
 * PreferenceServiceImpl is used.
 */
@Override
public void setPreferences(String userName, Map<String, Serializable> preferences) throws Throwable {
    final String comma = ",";
    String extKey = getExtPreferenceKey(preferences);
    if (extKey != null) {
        String extFavKey;
        String favKey;
        if (extKey.startsWith(EXT_DOCUMENTS_FAVOURITES)) // favorites for documents
        {
            extFavKey = EXT_DOCUMENTS_FAVOURITES;
            favKey = DOCUMENTS_FAVOURITES_KEY;
        } else // favorites for folders
        {
            extFavKey = EXT_FOLDERS_FAVOURITES;
            favKey = FOLDERS_FAVOURITES_KEY;
        }
        String pattern = "^" + extFavKey + "(\\S+)" + CREATED_AT + "$";
        Pattern p = Pattern.compile(pattern);
        Matcher m = p.matcher(extKey);
        if (m.find()) {
            String documentNodeRefStr = m.group(1);
            String favorites = (String) preferences.get(favKey);
            if (documentNodeRefStr != null && !documentNodeRefStr.isEmpty()) {
                NodeRef documentNodeRef = new NodeRef(documentNodeRefStr);
                Reference reference = Reference.fromNodeRef(documentNodeRef);
                if (reference != null) {
                    NodeRef actualNodeRef = reference.execute(new GetActualNodeRefMethod(null));
                    String actualNodeRefStr = actualNodeRef.toString();
                    String actualExtPreference = extFavKey + actualNodeRefStr + CREATED_AT;
                    List<String> elements = new ArrayList<String>(Arrays.asList(favorites.split(comma)));
                    boolean elementsChanged = false;
                    if (favorites.contains(documentNodeRefStr)) // add favorite
                    {
                        if (!preferences.containsKey(actualExtPreference)) {
                            Serializable value = preferences.get(extKey);
                            preferences.put(actualExtPreference, value);
                        }
                        preferences.remove(extKey);
                        if (!favorites.contains(actualNodeRefStr)) {
                            favorites = favorites.replace(documentNodeRefStr, actualNodeRefStr);
                        } else {
                            if (elements.contains(documentNodeRefStr)) {
                                elements.remove(documentNodeRefStr);
                                elementsChanged = true;
                            }
                        }
                    } else // remove favorite
                    {
                        if (elements.contains(actualNodeRefStr)) {
                            elements.remove(actualNodeRefStr);
                            preferenceService.clearPreferences(userName, actualExtPreference);
                            elementsChanged = true;
                        }
                    }
                    if (elementsChanged) {
                        favorites = EMPTY_STRING;
                        for (String element : elements) {
                            if (favorites.isEmpty()) {
                                favorites = element;
                            } else {
                                favorites = favorites + comma + element;
                            }
                        }
                    }
                    preferences.put(favKey, favorites);
                }
            }
        }
    }
    getTrait().setPreferences(userName, preferences);
}
Also used : Pattern(java.util.regex.Pattern) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) Matcher(java.util.regex.Matcher) Reference(org.alfresco.repo.virtual.ref.Reference) ArrayList(java.util.ArrayList) GetActualNodeRefMethod(org.alfresco.repo.virtual.ref.GetActualNodeRefMethod)

Example 24 with Reference

use of org.alfresco.repo.virtual.ref.Reference in project alfresco-repository by Alfresco.

the class VirtualVersionServiceExtension method isVersioned.

@Override
public boolean isVersioned(NodeRef nodeRef) {
    VersionServiceTrait theTrait = getTrait();
    Reference reference = Reference.fromNodeRef(nodeRef);
    if (reference == null) {
        return theTrait.isVersioned(nodeRef);
    } else {
        NodeRef materialNode = smartStore.materialize(reference);
        return theTrait.isVersioned(materialNode);
    }
}
Also used : VersionServiceTrait(org.alfresco.repo.version.traitextender.VersionServiceTrait) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Reference(org.alfresco.repo.virtual.ref.Reference)

Example 25 with Reference

use of org.alfresco.repo.virtual.ref.Reference in project alfresco-repository by Alfresco.

the class VirtualVersionServiceExtension method deleteVersion.

@Override
public void deleteVersion(NodeRef nodeRef, Version version) {
    VersionServiceTrait theTrait = getTrait();
    Reference reference = Reference.fromNodeRef(nodeRef);
    if (reference == null) {
        theTrait.deleteVersion(nodeRef, version);
    } else {
        NodeRef materialNode = smartStore.materialize(reference);
        Version actualVersion = materializeVersionIfReference(version);
        theTrait.deleteVersion(materialNode, actualVersion);
    }
}
Also used : VersionServiceTrait(org.alfresco.repo.version.traitextender.VersionServiceTrait) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Version(org.alfresco.service.cmr.version.Version) Reference(org.alfresco.repo.virtual.ref.Reference)

Aggregations

Reference (org.alfresco.repo.virtual.ref.Reference)81 NodeRef (org.alfresco.service.cmr.repository.NodeRef)59 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)23 VersionServiceTrait (org.alfresco.repo.version.traitextender.VersionServiceTrait)16 LinkedList (java.util.LinkedList)15 VirtualizationIntegrationTest (org.alfresco.repo.virtual.VirtualizationIntegrationTest)15 Test (org.junit.Test)15 PermissionReference (org.alfresco.repo.security.permissions.PermissionReference)13 NodeServiceTrait (org.alfresco.repo.node.db.traitextender.NodeServiceTrait)12 QName (org.alfresco.service.namespace.QName)10 Serializable (java.io.Serializable)9 GetParentReferenceMethod (org.alfresco.repo.virtual.ref.GetParentReferenceMethod)9 Version (org.alfresco.service.cmr.version.Version)9 GetActualNodeRefMethod (org.alfresco.repo.virtual.ref.GetActualNodeRefMethod)8 VirtualFolderDefinition (org.alfresco.repo.virtual.template.VirtualFolderDefinition)6 FileInfo (org.alfresco.service.cmr.model.FileInfo)6 PermissionServiceTrait (org.alfresco.repo.security.permissions.impl.traitextender.PermissionServiceTrait)5 VirtualizationException (org.alfresco.repo.virtual.VirtualizationException)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4