Search in sources :

Example 56 with Reference

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

the class VirtualVersionServiceExtension method virtualizeVersion.

private Version virtualizeVersion(Reference versionedReference, Version actualVersion) {
    if (actualVersion == null) {
        return null;
    }
    NodeRef frozenStateNodeRef = actualVersion.getFrozenStateNodeRef();
    StoreRef frozenStoreRef = frozenStateNodeRef.getStoreRef();
    Reference parentReference = versionedReference.execute(new GetParentReferenceMethod());
    Reference virtualFrozenReference = NodeProtocol.newReference(frozenStateNodeRef, parentReference);
    Map<String, Serializable> properties = actualVersion.getVersionProperties();
    Map<String, Serializable> virtualProperties = new HashMap<String, Serializable>(properties);
    // Switch VersionStore depending on configured impl
    if (frozenStoreRef.getIdentifier().equals(Version2Model.STORE_ID)) {
        // V2 version store (eg. workspace://version2Store)
        NodeRef propFrozenNodeRef = (NodeRef) virtualProperties.get(Version2Model.PROP_FROZEN_NODE_REF);
        Reference virtualPropFrozenReference = NodeProtocol.newReference(propFrozenNodeRef, parentReference);
        virtualProperties.put(Version2Model.PROP_FROZEN_NODE_REF, virtualPropFrozenReference.toNodeRef(propFrozenNodeRef.getStoreRef()));
    } else if (frozenStoreRef.getIdentifier().equals(VersionModel.STORE_ID)) {
        // Deprecated V1 version store (eg.
        // workspace://lightWeightVersionStore)
        String frozenNodeStoreProtocol = (String) virtualProperties.get(VersionModel.PROP_FROZEN_NODE_STORE_PROTOCOL);
        String frozenNodeStoreId = (String) virtualProperties.get(VersionModel.PROP_FROZEN_NODE_STORE_ID);
        String frozenNodeId = (String) virtualProperties.get(VersionModel.PROP_FROZEN_NODE_ID);
        StoreRef propFrozenStoreRef = new StoreRef(frozenNodeStoreProtocol, frozenNodeStoreId);
        NodeRef propFrozenNode = new NodeRef(propFrozenStoreRef, frozenNodeId);
        Reference virtualPropFrozenReference = NodeProtocol.newReference(propFrozenNode, parentReference);
        NodeRef virtualPropFrozenNodeRef = virtualPropFrozenReference.toNodeRef(propFrozenStoreRef);
        virtualProperties.put(VersionModel.PROP_FROZEN_NODE_STORE_PROTOCOL, propFrozenStoreRef.getProtocol());
        virtualProperties.put(VersionModel.PROP_FROZEN_NODE_STORE_ID, propFrozenStoreRef.getIdentifier());
        virtualProperties.put(VersionModel.PROP_FROZEN_NODE_ID, virtualPropFrozenNodeRef.getId());
    }
    return new VersionImpl(virtualProperties, virtualFrozenReference.toNodeRef(frozenStateNodeRef.getStoreRef()));
}
Also used : GetParentReferenceMethod(org.alfresco.repo.virtual.ref.GetParentReferenceMethod) NodeRef(org.alfresco.service.cmr.repository.NodeRef) StoreRef(org.alfresco.service.cmr.repository.StoreRef) Serializable(java.io.Serializable) HashMap(java.util.HashMap) Reference(org.alfresco.repo.virtual.ref.Reference) VersionImpl(org.alfresco.repo.version.common.VersionImpl)

Example 57 with Reference

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

the class VirtualVersionServiceExtension method createVersion.

@Override
public Version createVersion(NodeRef nodeRef, Map<String, Serializable> versionProperties) throws ReservedVersionNameException, AspectMissingException {
    VersionServiceTrait theTrait = getTrait();
    Reference reference = Reference.fromNodeRef(nodeRef);
    if (reference == null) {
        return theTrait.createVersion(nodeRef, versionProperties);
    } else {
        NodeRef materialNode = smartStore.materializeIfPossible(nodeRef);
        Version actualVersion = theTrait.createVersion(materialNode, versionProperties);
        return virtualizeVersion(reference, 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)

Example 58 with Reference

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

the class VirtualVersionServiceExtension method getCurrentVersion.

@Override
public Version getCurrentVersion(NodeRef nodeRef) {
    VersionServiceTrait theTrait = getTrait();
    Reference reference = Reference.fromNodeRef(nodeRef);
    if (reference == null) {
        return theTrait.getCurrentVersion(nodeRef);
    } else {
        NodeRef materialNode = smartStore.materialize(reference);
        Reference versionedReference = Reference.fromNodeRef(nodeRef);
        Version actualVersion = theTrait.getCurrentVersion(materialNode);
        return virtualizeVersion(versionedReference, 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)

Example 59 with Reference

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

the class VirtualVersionServiceExtension method materializeVersionIfReference.

private Version materializeVersionIfReference(Version virtualVersion) {
    NodeRef frozenStateNodeRef = virtualVersion.getFrozenStateNodeRef();
    StoreRef frozenStoreRef = frozenStateNodeRef.getStoreRef();
    NodeRef materialFrozenNodeRef = frozenStateNodeRef;
    Reference frozenReference = Reference.fromNodeRef(frozenStateNodeRef);
    if (frozenReference != null) {
        materialFrozenNodeRef = smartStore.materialize(frozenReference);
    }
    Map<String, Serializable> virtualProperties = virtualVersion.getVersionProperties();
    Map<String, Serializable> actualProperties = new HashMap<>(virtualProperties);
    if (frozenStoreRef.getIdentifier().equals(Version2Model.STORE_ID)) {
        // V2 version store (eg. workspace://version2Store)
        NodeRef propFrozenNode = (NodeRef) virtualProperties.get(Version2Model.PROP_FROZEN_NODE_REF);
        NodeRef propActualFrozenNode = propFrozenNode;
        Reference propFrozenReference = Reference.fromNodeRef(propFrozenNode);
        if (propFrozenReference != null) {
            propActualFrozenNode = smartStore.materialize(propFrozenReference);
        }
        actualProperties.put(Version2Model.PROP_FROZEN_NODE_REF, propActualFrozenNode);
    } else if (frozenStoreRef.getIdentifier().equals(VersionModel.STORE_ID)) {
        // Deprecated V1 version store (eg.
        // workspace://lightWeightVersionStore)
        String frozenNodeStoreProtocol = (String) virtualProperties.get(VersionModel.PROP_FROZEN_NODE_STORE_PROTOCOL);
        String frozenNodeStoreId = (String) virtualProperties.get(VersionModel.PROP_FROZEN_NODE_STORE_ID);
        String frozenNodeId = (String) virtualProperties.get(VersionModel.PROP_FROZEN_NODE_ID);
        NodeRef propFrozenNode = new NodeRef(frozenNodeStoreProtocol, frozenNodeStoreId, frozenNodeId);
        NodeRef propActualFrozenNode = propFrozenNode;
        Reference propFrozenReference = Reference.fromNodeRef(propFrozenNode);
        if (propFrozenReference != null) {
            propActualFrozenNode = smartStore.materialize(propFrozenReference);
        }
        StoreRef propActualStoreRef = propFrozenNode.getStoreRef();
        actualProperties.put(VersionModel.PROP_FROZEN_NODE_STORE_PROTOCOL, propActualStoreRef.getProtocol());
        actualProperties.put(VersionModel.PROP_FROZEN_NODE_STORE_ID, propActualStoreRef.getIdentifier());
        actualProperties.put(VersionModel.PROP_FROZEN_NODE_ID, propActualFrozenNode.getId());
    }
    Version actualVersion = new VersionImpl(actualProperties, materialFrozenNodeRef);
    return actualVersion;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) StoreRef(org.alfresco.service.cmr.repository.StoreRef) Serializable(java.io.Serializable) HashMap(java.util.HashMap) Version(org.alfresco.service.cmr.version.Version) Reference(org.alfresco.repo.virtual.ref.Reference) VersionImpl(org.alfresco.repo.version.common.VersionImpl)

Example 60 with Reference

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

the class VirtualVersionServiceExtension method restore.

@Override
public NodeRef restore(NodeRef nodeRef, NodeRef parentNodeRef, QName assocTypeQName, QName assocQName) {
    VersionServiceTrait theTrait = getTrait();
    Reference reference = Reference.fromNodeRef(nodeRef);
    if (reference == null) {
        return theTrait.restore(nodeRef, parentNodeRef, assocTypeQName, assocQName);
    } else {
        NodeRef materialNode = smartStore.materialize(reference);
        return theTrait.restore(materialNode, parentNodeRef, assocTypeQName, assocQName);
    }
}
Also used : VersionServiceTrait(org.alfresco.repo.version.traitextender.VersionServiceTrait) NodeRef(org.alfresco.service.cmr.repository.NodeRef) 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