use of org.alfresco.repo.virtual.ref.GetParentReferenceMethod in project alfresco-repository by Alfresco.
the class VirtualNodeServiceExtension method getTargetAssocs.
@Override
public List<AssociationRef> getTargetAssocs(NodeRef sourceRef, QNamePattern qnamePattern) {
NodeServiceTrait theTrait = getTrait();
List<AssociationRef> targetAssocs = null;
Reference reference = Reference.fromNodeRef(sourceRef);
if (reference != null) {
if (smartStore.canMaterialize(reference)) {
NodeRef materializedReferece = smartStore.materialize(reference);
targetAssocs = theTrait.getTargetAssocs(materializedReferece, qnamePattern);
} else {
targetAssocs = new LinkedList<>();
}
} else {
targetAssocs = theTrait.getTargetAssocs(sourceRef, qnamePattern);
}
List<AssociationRef> virtualizedIfNeededTargetAssocs = null;
Reference sourceReference = Reference.fromNodeRef(sourceRef);
if (sourceReference != null) {
virtualizedIfNeededTargetAssocs = new LinkedList<>();
for (AssociationRef associationRef : targetAssocs) {
NodeRef targetNodeRef = associationRef.getTargetRef();
Reference targetReference = NodeProtocol.newReference(targetNodeRef, sourceReference.execute(new GetParentReferenceMethod()));
AssociationRef virtualAssocRef = new AssociationRef(associationRef.getId(), sourceRef, associationRef.getTypeQName(), targetReference.toNodeRef(targetNodeRef.getStoreRef()));
virtualizedIfNeededTargetAssocs.add(virtualAssocRef);
}
} else {
virtualizedIfNeededTargetAssocs = targetAssocs;
if (DownloadModel.TYPE_DOWNLOAD.equals(environment.getType(sourceRef))) {
if (qnamePattern.isMatch(DownloadModel.ASSOC_REQUESTED_NODES)) {
List<AssociationRef> virtualTargetAssocs = getDownloadTargetAssocs(sourceRef);
virtualizedIfNeededTargetAssocs.addAll(virtualTargetAssocs);
}
}
}
return virtualizedIfNeededTargetAssocs;
}
use of org.alfresco.repo.virtual.ref.GetParentReferenceMethod in project alfresco-repository by Alfresco.
the class VirtualNodeServiceExtension method getSourceAssocs.
@Override
public List<AssociationRef> getSourceAssocs(NodeRef targetRef, QNamePattern qnamePattern) {
NodeServiceTrait theTrait = getTrait();
Reference reference = Reference.fromNodeRef(targetRef);
if (reference != null) {
List<AssociationRef> materialAssocs = new ArrayList<AssociationRef>();
if (smartStore.canMaterialize(reference)) {
List<AssociationRef> sourceAssocs = theTrait.getSourceAssocs(smartStore.materialize(reference), qnamePattern);
for (AssociationRef associationRef : sourceAssocs) {
NodeRef sourceRef = associationRef.getSourceRef();
Reference sourceReference = NodeProtocol.newReference(sourceRef, reference.execute(new GetParentReferenceMethod()));
AssociationRef virtualAssocRef = new AssociationRef(associationRef.getId(), sourceReference.toNodeRef(), associationRef.getTypeQName(), targetRef);
materialAssocs.add(virtualAssocRef);
}
}
return materialAssocs;
} else {
return theTrait.getSourceAssocs(targetRef, qnamePattern);
}
}
use of org.alfresco.repo.virtual.ref.GetParentReferenceMethod in project alfresco-repository by Alfresco.
the class VirtualNodeServiceExtension method getParentAssocs.
@Override
public List<ChildAssociationRef> getParentAssocs(NodeRef nodeRef, QNamePattern typeQNamePattern, QNamePattern qnamePattern) {
NodeServiceTrait theTrait = getTrait();
Reference reference = Reference.fromNodeRef(nodeRef);
if (reference != null) {
Reference parent = reference.execute(new GetParentReferenceMethod());
if (parent == null) {
return theTrait.getParentAssocs(reference.execute(new GetActualNodeRefMethod(environment)), typeQNamePattern, qnamePattern);
} else {
if (typeQNamePattern.isMatch(ContentModel.ASSOC_CONTAINS)) {
Reference parentsParent = parent.execute(new GetParentReferenceMethod());
NodeRef parentNodeRef = parent.toNodeRef();
if (parentsParent == null) {
parentNodeRef = parent.execute(new GetActualNodeRefMethod(environment));
}
NodeRef referenceNodeRef = reference.toNodeRef();
Map<QName, Serializable> properties = smartStore.getProperties(reference);
Serializable name = properties.get(ContentModel.PROP_NAME);
QName assocChildName = QName.createQNameWithValidLocalName(VirtualContentModel.VIRTUAL_CONTENT_MODEL_1_0_URI, name.toString());
if (qnamePattern.isMatch(assocChildName)) {
ChildAssociationRef assoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, parentNodeRef, assocChildName, referenceNodeRef);
return Arrays.asList(assoc);
} else {
return Collections.emptyList();
}
} else {
return Collections.emptyList();
}
}
} else {
return theTrait.getParentAssocs(nodeRef, typeQNamePattern, qnamePattern);
}
}
use of org.alfresco.repo.virtual.ref.GetParentReferenceMethod in project alfresco-repository by Alfresco.
the class VirtualNodeServiceExtension method getPrimaryParent.
@Override
public ChildAssociationRef getPrimaryParent(NodeRef nodeRef) {
Reference reference = Reference.fromNodeRef(nodeRef);
if (reference != null) {
Reference parent = reference.execute(new GetParentReferenceMethod());
if (parent == null) {
return getTrait().getPrimaryParent(reference.execute(new GetActualNodeRefMethod(environment)));
} else {
Reference parentsParent = parent.execute(new GetParentReferenceMethod());
NodeRef parentNodeRef = parent.toNodeRef();
if (parentsParent == null) {
parentNodeRef = parent.execute(new GetActualNodeRefMethod(environment));
}
NodeRef referenceNodeRef = reference.toNodeRef();
Map<QName, Serializable> refProperties = smartStore.getProperties(reference);
Serializable childName = refProperties.get(ContentModel.PROP_NAME);
QName childAssocQName = QName.createQNameWithValidLocalName(VirtualContentModel.VIRTUAL_CONTENT_MODEL_1_0_URI, childName.toString());
ChildAssociationRef assoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, parentNodeRef, childAssocQName, referenceNodeRef, true, -1);
return assoc;
}
} else {
return getTrait().getPrimaryParent(nodeRef);
}
}
use of org.alfresco.repo.virtual.ref.GetParentReferenceMethod in project alfresco-repository by Alfresco.
the class VirtualCheckOutCheckInServiceExtension method virtualizeOriginalIfNeeded.
private NodeRef virtualizeOriginalIfNeeded(NodeRef workingCopyNodeRef, NodeRef materialOriginalNode) {
Reference workingCopyReference = Reference.fromNodeRef(workingCopyNodeRef);
if ((materialOriginalNode != null) && (workingCopyReference != null)) {
Reference parentReference = workingCopyReference.execute(new GetParentReferenceMethod());
Reference originalReference = NodeProtocol.newReference(materialOriginalNode, parentReference);
return originalReference.toNodeRef(materialOriginalNode.getStoreRef());
} else {
return materialOriginalNode;
}
}
Aggregations