Search in sources :

Example 6 with GetParentReferenceMethod

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

the class VirtualCheckOutCheckInServiceExtension method virtualizeVersionIfNeeded.

private NodeRef virtualizeVersionIfNeeded(NodeRef originalNodeRef, NodeRef materialVersion) {
    Reference reference = Reference.fromNodeRef(originalNodeRef);
    if ((materialVersion != null) && (reference != null) && (Reference.fromNodeRef(materialVersion) == null)) {
        Reference parentReference = reference.execute(new GetParentReferenceMethod());
        Reference workingCopyReference = NodeProtocol.newReference(materialVersion, parentReference);
        return workingCopyReference.toNodeRef(materialVersion.getStoreRef());
    } else {
        return materialVersion;
    }
}
Also used : GetParentReferenceMethod(org.alfresco.repo.virtual.ref.GetParentReferenceMethod) Reference(org.alfresco.repo.virtual.ref.Reference)

Example 7 with GetParentReferenceMethod

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

the class VirtualStoreImpl method getPath.

@Override
public Path getPath(Reference reference) throws VirtualizationException {
    Reference virtualPathElement = reference;
    Reference virtualPathParent = reference.execute(new GetParentReferenceMethod());
    Path virtualPath = new Path();
    while (virtualPathElement != null && virtualPathParent != null) {
        NodeRef parentNodeRef;
        parentNodeRef = virtualPathParent.toNodeRef();
        NodeRef parent = parentNodeRef;
        NodeRef virtualPathNodeRef = virtualPathElement.toNodeRef();
        // TODO: extract node reference name into protocol method in order
        // to enforce path processing code reuse and consistency
        String templatePath = virtualPathElement.execute(new GetTemplatePathMethod()).trim();
        final String pathSeparator = "/";
        if (pathSeparator.equals(templatePath)) {
            // found root
            break;
        } else if (templatePath.endsWith(pathSeparator)) {
            templatePath = templatePath.substring(0, templatePath.length() - 1);
        }
        int lastSeparator = templatePath.lastIndexOf(pathSeparator);
        String childId = templatePath.substring(lastSeparator + 1);
        VirtualFolderDefinition structure = resolveVirtualFolderDefinition(virtualPathParent);
        VirtualFolderDefinition child = structure.findChildById(childId);
        if (child == null) {
            throw new VirtualizationException("Invalid reference: " + reference.encode());
        }
        String childName = child.getName();
        QName childQName = QName.createQName(VirtualContentModel.VIRTUAL_CONTENT_MODEL_1_0_URI, childName);
        ChildAssociationRef assocRef = new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, parent, childQName, virtualPathNodeRef, true, -1);
        ChildAssocElement assocRefElement = new ChildAssocElement(assocRef);
        virtualPath.prepend(assocRefElement);
        virtualPathElement = virtualPathParent;
        virtualPathParent = virtualPathParent.execute(new GetParentReferenceMethod());
    }
    return virtualPath;
}
Also used : GetParentReferenceMethod(org.alfresco.repo.virtual.ref.GetParentReferenceMethod) Path(org.alfresco.service.cmr.repository.Path) NodeRef(org.alfresco.service.cmr.repository.NodeRef) GetTemplatePathMethod(org.alfresco.repo.virtual.ref.GetTemplatePathMethod) ChildAssocElement(org.alfresco.service.cmr.repository.Path.ChildAssocElement) PermissionReference(org.alfresco.repo.security.permissions.PermissionReference) Reference(org.alfresco.repo.virtual.ref.Reference) QName(org.alfresco.service.namespace.QName) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) NamePatternPropertyValueConstraint(org.alfresco.repo.virtual.template.NamePatternPropertyValueConstraint) PropertyValueConstraint(org.alfresco.repo.virtual.template.PropertyValueConstraint) FilesFoldersConstraint(org.alfresco.repo.virtual.template.FilesFoldersConstraint) VirtualQueryConstraint(org.alfresco.repo.virtual.template.VirtualQueryConstraint) BasicConstraint(org.alfresco.repo.virtual.template.BasicConstraint) VirtualFolderDefinition(org.alfresco.repo.virtual.template.VirtualFolderDefinition) VirtualizationException(org.alfresco.repo.virtual.VirtualizationException)

Example 8 with GetParentReferenceMethod

use of org.alfresco.repo.virtual.ref.GetParentReferenceMethod 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 9 with GetParentReferenceMethod

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

the class VirtualNodeServiceExtensionTest method assertNewVirtualChildAssocRef.

/**
 * Assets that the given {@link ChildAssociationRef} was created within the
 * given container {@link Reference}.
 *
 * @param nodeRef
 * @param childAssocsRef
 */
private void assertNewVirtualChildAssocRef(Reference reference, ChildAssociationRef childAssocsRef) {
    assertNotNull(childAssocsRef);
    NodeRef childNodeRef = childAssocsRef.getChildRef();
    NodeRef parentNodeRef = childAssocsRef.getParentRef();
    Reference parentNodeRefV = Reference.fromNodeRef(parentNodeRef);
    assertNotNull(parentNodeRefV);
    assertEquals(reference, parentNodeRefV);
    Reference childReference = Reference.fromNodeRef(childNodeRef);
    assertNotNull(childReference);
    Reference parent = childReference.execute(new GetParentReferenceMethod());
    assertEquals(reference, parent);
}
Also used : GetParentReferenceMethod(org.alfresco.repo.virtual.ref.GetParentReferenceMethod) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Reference(org.alfresco.repo.virtual.ref.Reference)

Aggregations

GetParentReferenceMethod (org.alfresco.repo.virtual.ref.GetParentReferenceMethod)9 Reference (org.alfresco.repo.virtual.ref.Reference)9 NodeRef (org.alfresco.service.cmr.repository.NodeRef)7 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)5 Serializable (java.io.Serializable)3 NodeServiceTrait (org.alfresco.repo.node.db.traitextender.NodeServiceTrait)3 QName (org.alfresco.service.namespace.QName)3 GetActualNodeRefMethod (org.alfresco.repo.virtual.ref.GetActualNodeRefMethod)2 AssociationRef (org.alfresco.service.cmr.repository.AssociationRef)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 PermissionReference (org.alfresco.repo.security.permissions.PermissionReference)1 VersionImpl (org.alfresco.repo.version.common.VersionImpl)1 VirtualizationException (org.alfresco.repo.virtual.VirtualizationException)1 GetTemplatePathMethod (org.alfresco.repo.virtual.ref.GetTemplatePathMethod)1 BasicConstraint (org.alfresco.repo.virtual.template.BasicConstraint)1 FilesFoldersConstraint (org.alfresco.repo.virtual.template.FilesFoldersConstraint)1 NamePatternPropertyValueConstraint (org.alfresco.repo.virtual.template.NamePatternPropertyValueConstraint)1 PropertyValueConstraint (org.alfresco.repo.virtual.template.PropertyValueConstraint)1 VirtualFolderDefinition (org.alfresco.repo.virtual.template.VirtualFolderDefinition)1