use of org.alfresco.repo.virtual.ref.Reference in project alfresco-repository by Alfresco.
the class ReferenceComparator method compareImpl.
private int compareImpl(Reference ref1In, Reference ref2In, List<Pair<QName, Boolean>> sortProps) throws VirtualizationException {
Object pv1 = null;
Object pv2 = null;
QName sortPropQName = (QName) sortProps.get(0).getFirst();
boolean sortAscending = sortProps.get(0).getSecond();
Reference ref1 = ref1In;
Reference ref2 = ref2In;
if (sortAscending == false) {
ref1 = ref2In;
ref2 = ref1In;
}
int result = 0;
Map<QName, Serializable> properties1 = smartStore.getProperties(ref1);
pv1 = properties1.get(sortPropQName);
Map<QName, Serializable> properties2 = smartStore.getProperties(ref2);
pv2 = properties2.get(sortPropQName);
if (pv1 == null) {
if (pv2 == null && sortProps.size() > 1) {
return compareImpl(ref1In, ref2In, sortProps.subList(1, sortProps.size()));
} else {
return (pv2 == null ? 0 : -1);
}
} else if (pv2 == null) {
return 1;
}
if (pv1 instanceof String) {
// TODO: use collation keys (re: performance)
result = collator.compare((String) pv1, (String) pv2);
} else if (pv1 instanceof Date) {
result = (((Date) pv1).compareTo((Date) pv2));
} else if (pv1 instanceof Long) {
result = (((Long) pv1).compareTo((Long) pv2));
} else if (pv1 instanceof Integer) {
result = (((Integer) pv1).compareTo((Integer) pv2));
} else if (pv1 instanceof QName) {
result = (((QName) pv1).compareTo((QName) pv2));
} else if (pv1 instanceof Boolean) {
result = (((Boolean) pv1).compareTo((Boolean) pv2));
} else {
throw new RuntimeException("Unsupported sort type: " + pv1.getClass().getName());
}
if ((result == 0) && (sortProps.size() > 1)) {
return compareImpl(ref1In, ref2In, sortProps.subList(1, sortProps.size()));
}
return result;
}
use of org.alfresco.repo.virtual.ref.Reference in project alfresco-repository by Alfresco.
the class VirtualStoreImpl method createChildReferences.
private List<Reference> createChildReferences(Reference parent, VirtualFolderDefinition structure) throws ProtocolMethodException {
List<VirtualFolderDefinition> structureChildren = structure.getChildren();
List<Reference> childReferences = new LinkedList<Reference>();
for (VirtualFolderDefinition child : structureChildren) {
childReferences.add(parent.execute(new GetChildByIdMethod(child.getId())));
}
return childReferences;
}
use of org.alfresco.repo.virtual.ref.Reference in project alfresco-repository by Alfresco.
the class VirtualStoreImpl method list.
@Override
public List<Reference> list(Reference reference) throws VirtualizationException {
VirtualFolderDefinition structure = resolveVirtualFolderDefinition(reference);
List<Reference> result = createChildReferences(reference, structure);
final VirtualQuery query = structure.getQuery();
if (query != null) {
PagingResults<Reference> queryNodes = query.perform(environment, new FilesFoldersConstraint(BasicConstraint.INSTANCE, true, true), null, reference);
result.addAll(queryNodes.getPage());
}
return result;
}
use of org.alfresco.repo.virtual.ref.Reference in project alfresco-repository by Alfresco.
the class VirtualStoreImpl method nodeProtocolNodeRef.
private NodeRef nodeProtocolNodeRef(NodeRef nodeRef) throws ProtocolMethodException, ReferenceParseException, ReferenceEncodingException {
NodeRef theNodeRef = nodeRef;
Reference ref = Reference.fromNodeRef(theNodeRef);
if (ref != null) {
if (Protocols.NODE.protocol.equals(ref.getProtocol())) {
theNodeRef = ref.execute(new GetActualNodeRefMethod(environment));
}
}
return theNodeRef;
}
use of org.alfresco.repo.virtual.ref.Reference in project alfresco-repository by Alfresco.
the class GetChildAssocsMethod method execute.
@Override
public List<ChildAssociationRef> execute(VirtualProtocol virtualProtocol, Reference reference) throws ProtocolMethodException {
if (typeQNamePattern.isMatch(ContentModel.ASSOC_CONTAINS)) {
List<ChildAssociationRef> childAssocs = new LinkedList<>();
List<Reference> children = smartStore.list(reference);
NodeRef nodeRefReference = reference.toNodeRef();
int count = 0;
for (Reference child : children) {
if (count >= maxResults) {
break;
}
NodeRef childNodeRef = child.toNodeRef();
Serializable childName = environment.getProperty(childNodeRef, ContentModel.PROP_NAME);
QName childAssocQName = QName.createQNameWithValidLocalName(VirtualContentModel.VIRTUAL_CONTENT_MODEL_1_0_URI, childName.toString());
if (qnamePattern.isMatch(childAssocQName)) {
ChildAssociationRef childAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, nodeRefReference, childAssocQName, childNodeRef, true, -1);
childAssocs.add(childAssoc);
count++;
}
}
return childAssocs;
} else {
return Collections.emptyList();
}
}
Aggregations