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;
}
}
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;
}
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()));
}
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);
}
Aggregations