use of org.alfresco.repo.domain.node.NodeDAO.ChildAssocRefQueryCallback in project alfresco-repository by Alfresco.
the class DbNodeServiceImpl method getParentAssocs.
/**
* Filters out any associations if their qname is not a match to the given pattern.
*/
@Extend(traitAPI = NodeServiceTrait.class, extensionAPI = NodeServiceExtension.class)
public List<ChildAssociationRef> getParentAssocs(final NodeRef nodeRef, final QNamePattern typeQNamePattern, final QNamePattern qnamePattern) {
// Get the node
Pair<Long, NodeRef> nodePair = getNodePairNotNull(nodeRef);
Long nodeId = nodePair.getFirst();
final List<ChildAssociationRef> results = new ArrayList<ChildAssociationRef>(10);
// We have a callback handler to filter results
ChildAssocRefQueryCallback callback = new ChildAssocRefQueryCallback() {
public boolean preLoadNodes() {
return false;
}
@Override
public boolean orderResults() {
return false;
}
public boolean handle(Pair<Long, ChildAssociationRef> childAssocPair, Pair<Long, NodeRef> parentNodePair, Pair<Long, NodeRef> childNodePair) {
if (!typeQNamePattern.isMatch(childAssocPair.getSecond().getTypeQName())) {
return true;
}
if (!qnamePattern.isMatch(childAssocPair.getSecond().getQName())) {
return true;
}
results.add(childAssocPair.getSecond());
return true;
}
public void done() {
}
};
// Get the assocs pointing to it
QName typeQName = (typeQNamePattern instanceof QName) ? (QName) typeQNamePattern : null;
QName qname = (qnamePattern instanceof QName) ? (QName) qnamePattern : null;
nodeDAO.getParentAssocs(nodeId, typeQName, qname, null, callback);
// done
return results;
}
use of org.alfresco.repo.domain.node.NodeDAO.ChildAssocRefQueryCallback in project alfresco-repository by Alfresco.
the class DbNodeServiceImpl method getChildAssocs.
/**
* Fetches the first n child associations in an efficient manner
*/
@Extend(traitAPI = NodeServiceTrait.class, extensionAPI = NodeServiceExtension.class)
public List<ChildAssociationRef> getChildAssocs(NodeRef nodeRef, final QNamePattern typeQNamePattern, final QNamePattern qnamePattern, final int maxResults, final boolean preload) {
// Get the node
Pair<Long, NodeRef> nodePair = getNodePairNotNull(nodeRef);
// We have a callback handler to filter results
final List<ChildAssociationRef> results = new ArrayList<ChildAssociationRef>(10);
ChildAssocRefQueryCallback callback = new ChildAssocRefQueryCallback() {
public boolean preLoadNodes() {
return preload;
}
@Override
public boolean orderResults() {
return true;
}
public boolean handle(Pair<Long, ChildAssociationRef> childAssocPair, Pair<Long, NodeRef> parentNodePair, Pair<Long, NodeRef> childNodePair) {
if (typeQNamePattern != null && !typeQNamePattern.isMatch(childAssocPair.getSecond().getTypeQName())) {
return true;
}
if (qnamePattern != null && !qnamePattern.isMatch(childAssocPair.getSecond().getQName())) {
return true;
}
results.add(childAssocPair.getSecond());
return true;
}
public void done() {
}
};
// Get the assocs pointing to it
QName typeQName = (typeQNamePattern instanceof QName) ? (QName) typeQNamePattern : null;
QName qname = (qnamePattern instanceof QName) ? (QName) qnamePattern : null;
nodeDAO.getChildAssocs(nodePair.getFirst(), typeQName, qname, maxResults, callback);
// Done
return results;
}
use of org.alfresco.repo.domain.node.NodeDAO.ChildAssocRefQueryCallback in project alfresco-repository by Alfresco.
the class DbNodeServiceImpl method getChildAssocsByPropertyValue.
@Override
@Extend(traitAPI = NodeServiceTrait.class, extensionAPI = NodeServiceExtension.class)
public List<ChildAssociationRef> getChildAssocsByPropertyValue(NodeRef nodeRef, QName propertyQName, Serializable value) {
// Get the node
Pair<Long, NodeRef> nodePair = getNodePairNotNull(nodeRef);
Long nodeId = nodePair.getFirst();
if (getChildAssocsByPropertyValueBannedProps.contains(propertyQName)) {
throw new IllegalArgumentException("getChildAssocsByPropertyValue does not allow search of system maintained properties: " + propertyQName);
}
final List<ChildAssociationRef> results = new ArrayList<ChildAssociationRef>(10);
// We have a callback handler to filter results
ChildAssocRefQueryCallback callback = new ChildAssocRefQueryCallback() {
public boolean preLoadNodes() {
return false;
}
@Override
public boolean orderResults() {
return true;
}
public boolean handle(Pair<Long, ChildAssociationRef> childAssocPair, Pair<Long, NodeRef> parentNodePair, Pair<Long, NodeRef> childNodePair) {
results.add(childAssocPair.getSecond());
return true;
}
public void done() {
}
};
// Get the assocs pointing to it
nodeDAO.getChildAssocsByPropertyValue(nodeId, propertyQName, value, callback);
// Done
return results;
}
use of org.alfresco.repo.domain.node.NodeDAO.ChildAssocRefQueryCallback in project alfresco-repository by Alfresco.
the class SOLRTrackingComponentImpl method getNodesMetadata.
/**
* {@inheritDoc}
*/
public void getNodesMetadata(NodeMetaDataParameters nodeMetaDataParameters, MetaDataResultsFilter resultFilter, NodeMetaDataQueryCallback callback) {
if (false == enabled) {
return;
}
NodeMetaDataQueryRowHandler rowHandler = new NodeMetaDataQueryRowHandler(callback);
boolean includeType = (resultFilter == null ? true : resultFilter.getIncludeType());
boolean includeProperties = (resultFilter == null ? true : resultFilter.getIncludeProperties());
boolean includeAspects = (resultFilter == null ? true : resultFilter.getIncludeAspects());
boolean includePaths = (resultFilter == null ? true : resultFilter.getIncludePaths());
boolean includeNodeRef = (resultFilter == null ? true : resultFilter.getIncludeNodeRef());
boolean includeParentAssociations = (resultFilter == null ? true : resultFilter.getIncludeParentAssociations());
boolean includeChildAssociations = (resultFilter == null ? true : resultFilter.getIncludeChildAssociations());
boolean includeOwner = (resultFilter == null ? true : resultFilter.getIncludeOwner());
boolean includeChildIds = (resultFilter == null ? true : resultFilter.getIncludeChildIds());
boolean includeTxnId = (resultFilter == null ? true : resultFilter.getIncludeTxnId());
List<Long> nodeIds = preCacheNodes(nodeMetaDataParameters);
for (Long nodeId : nodeIds) {
Status status = nodeDAO.getNodeIdStatus(nodeId);
if (status == null) {
// See org.alfresco.solr.tracker.CoreTracker.updateDescendantAuxDocs(NodeMetaData, boolean, SolrIndexSearcher)
continue;
}
NodeRef nodeRef = status.getNodeRef();
NodeRef unversionedNodeRef = null;
if (isVersionNodeRef(nodeRef)) {
unversionedNodeRef = convertVersionNodeRefToVersionedNodeRef(VersionUtil.convertNodeRef(nodeRef));
}
NodeMetaData nodeMetaData = new NodeMetaData();
nodeMetaData.setNodeId(nodeId);
if (includeNodeRef) {
nodeMetaData.setNodeRef(tenantService.getBaseName(nodeRef, true));
}
if (includeTxnId) {
nodeMetaData.setTxnId(status.getDbTxnId());
}
if (status.isDeleted()) {
rowHandler.processResult(nodeMetaData);
continue;
}
Map<QName, Serializable> props = null;
Set<QName> aspects = null;
Status unversionedStatus = null;
if (unversionedNodeRef != null) {
unversionedStatus = nodeDAO.getNodeRefStatus(unversionedNodeRef);
}
if (unversionedStatus != null) {
nodeMetaData.setAclId(nodeDAO.getNodeAclId(unversionedStatus.getDbId()));
} else {
nodeMetaData.setAclId(nodeDAO.getNodeAclId(nodeId));
}
if (includeType) {
QName nodeType = getNodeType(nodeId);
if (nodeType != null) {
nodeMetaData.setNodeType(nodeType);
} else {
QName typeQName = null;
TypeDefinition typeDefinition = null;
String errorMessage = "NodeId " + nodeId + " with nodeRef " + nodeRef;
typeQName = nodeDAO.getNodeType(nodeId);
if (typeQName != null) {
errorMessage += " has type " + typeQName + ", but this type is not registered in DictionaryService.";
} else {
errorMessage += " has no type.";
}
throw new AlfrescoRuntimeException(errorMessage + " It will be ignored by SOLR.");
}
}
if (includeProperties) {
if (props == null) {
props = getProperties(nodeId);
}
nodeMetaData.setProperties(props);
} else {
nodeMetaData.setProperties(Collections.<QName, Serializable>emptyMap());
}
if (includeAspects || includePaths || includeParentAssociations) {
aspects = getNodeAspects(nodeId);
}
nodeMetaData.setAspects(aspects);
boolean ignoreLargeMetadata = (typeIndexFilter.shouldBeIgnored(getNodeType(nodeId)) || aspectIndexFilter.shouldBeIgnored(getNodeAspects(nodeId)));
CategoryPaths categoryPaths = new CategoryPaths(new ArrayList<Pair<Path, QName>>(), new ArrayList<ChildAssociationRef>());
if (!ignoreLargeMetadata && (includePaths || includeParentAssociations)) {
if (props == null) {
props = getProperties(nodeId);
}
categoryPaths = getCategoryPaths(status.getNodeRef(), aspects, props);
}
if (!ignoreLargeMetadata && (typeIndexFilter.isIgnorePathsForSpecificTypes() || aspectIndexFilter.isIgnorePathsForSpecificAspects() || includeParentAssociations)) {
// check if parent should be ignored
final List<Long> parentIds = new LinkedList<Long>();
final List<ChildAssociationRef> parentAssocs = new ArrayList<ChildAssociationRef>(100);
nodeDAO.getParentAssocs(nodeId, null, null, true, new ChildAssocRefQueryCallback() {
@Override
public boolean preLoadNodes() {
return false;
}
@Override
public boolean orderResults() {
return false;
}
@Override
public boolean handle(Pair<Long, ChildAssociationRef> childAssocPair, Pair<Long, NodeRef> parentNodePair, Pair<Long, NodeRef> childNodePair) {
parentIds.add(parentNodePair.getFirst());
parentAssocs.add(tenantService.getBaseName(childAssocPair.getSecond(), true));
return false;
}
@Override
public void done() {
}
});
if (!parentIds.isEmpty()) {
Long parentId = parentIds.iterator().next();
if (typeIndexFilter.isIgnorePathsForSpecificTypes()) {
QName parentType = getNodeType(parentId);
ignoreLargeMetadata = typeIndexFilter.shouldBeIgnored(parentType);
}
if (!ignoreLargeMetadata && aspectIndexFilter.isIgnorePathsForSpecificAspects()) {
ignoreLargeMetadata = aspectIndexFilter.shouldBeIgnored(getNodeAspects(parentId));
}
}
if (includeParentAssociations) {
for (ChildAssociationRef ref : categoryPaths.getCategoryParents()) {
parentAssocs.add(tenantService.getBaseName(ref, true));
}
CRC32 crc = new CRC32();
for (ChildAssociationRef car : parentAssocs) {
try {
crc.update(car.toString().getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("UTF-8 encoding is not supported");
}
}
nodeMetaData.setParentAssocs(parentAssocs, crc.getValue());
}
}
nodeMetaData.setTenantDomain(tenantService.getDomain(nodeRef.getStoreRef().getIdentifier()));
if (includeChildAssociations || includeChildIds) {
final List<ChildAssociationRef> childAssocs = new ArrayList<ChildAssociationRef>(100);
final List<Long> childIds = new ArrayList<Long>(100);
nodeDAO.getChildAssocs(nodeId, null, null, null, null, null, new ChildAssocRefQueryCallback() {
@Override
public boolean preLoadNodes() {
return false;
}
@Override
public boolean orderResults() {
return false;
}
@Override
public boolean handle(Pair<Long, ChildAssociationRef> childAssocPair, Pair<Long, NodeRef> parentNodePair, Pair<Long, NodeRef> childNodePair) {
QName nodeType = nodeDAO.getNodeType(childNodePair.getFirst());
if (includeChildAssociations) {
boolean addCurrentChildAssoc = true;
if (typeIndexFilter.isIgnorePathsForSpecificTypes()) {
addCurrentChildAssoc = !typeIndexFilter.shouldBeIgnored(nodeType);
}
if (!addCurrentChildAssoc && aspectIndexFilter.isIgnorePathsForSpecificAspects()) {
addCurrentChildAssoc = !aspectIndexFilter.shouldBeIgnored(getNodeAspects(childNodePair.getFirst()));
}
if (addCurrentChildAssoc) {
childAssocs.add(tenantService.getBaseName(childAssocPair.getSecond(), true));
}
}
if (includeChildIds) {
boolean addCurrentId = true;
if (typeIndexFilter.isIgnorePathsForSpecificTypes()) {
addCurrentId = !typeIndexFilter.shouldBeIgnored(nodeType);
}
if (!addCurrentId) {
addCurrentId = !aspectIndexFilter.shouldBeIgnored(getNodeAspects(childNodePair.getFirst()));
}
if (addCurrentId) {
childIds.add(childNodePair.getFirst());
}
}
return true;
}
@Override
public void done() {
}
});
nodeMetaData.setChildAssocs(childAssocs);
nodeMetaData.setChildIds(childIds);
}
if (includePaths && !ignoreLargeMetadata) {
List<Path> directPaths = nodeDAO.getPaths(new Pair<Long, NodeRef>(nodeId, status.getNodeRef()), false);
Collection<Pair<Path, QName>> paths = new ArrayList<Pair<Path, QName>>(directPaths.size() + categoryPaths.getPaths().size());
for (Path path : directPaths) {
paths.add(new Pair<Path, QName>(path.getBaseNamePath(tenantService), null));
}
for (Pair<Path, QName> catPair : categoryPaths.getPaths()) {
paths.add(new Pair<Path, QName>(catPair.getFirst().getBaseNamePath(tenantService), catPair.getSecond()));
}
if (unversionedStatus != null) {
List<Path> unversionedPaths = nodeDAO.getPaths(new Pair<Long, NodeRef>(unversionedStatus.getDbId(), unversionedStatus.getNodeRef()), false);
for (Path path : unversionedPaths) {
paths.add(new Pair<Path, QName>(path.getBaseNamePath(tenantService), null));
}
}
nodeMetaData.setPaths(paths);
// Calculate name path
Collection<Collection<String>> namePaths = new ArrayList<Collection<String>>(2);
nodeMetaData.setNamePaths(namePaths);
for (Pair<Path, QName> catPair : paths) {
Path path = catPair.getFirst();
boolean added = false;
List<String> namePath = new ArrayList<String>(path.size());
NEXT_ELEMENT: for (Path.Element pathElement : path) {
if (!(pathElement instanceof ChildAssocElement)) {
// This is some path element that is terminal to a cm:name path
break;
}
ChildAssocElement pathChildAssocElement = (ChildAssocElement) pathElement;
NodeRef childNodeRef = pathChildAssocElement.getRef().getChildRef();
Pair<Long, NodeRef> childNodePair = nodeDAO.getNodePair(childNodeRef);
if (childNodePair == null) {
// Gone
break;
}
Long childNodeId = childNodePair.getFirst();
String childNodeName = (String) nodeDAO.getNodeProperty(childNodeId, ContentModel.PROP_NAME);
if (childNodeName == null) {
// We have hit a non-name node, which acts as a root for cm:name
// DH: There is no particular constraint here. This is just a decision made.
namePath.clear();
// We have to continue down the path as there could be a name path lower down
continue NEXT_ELEMENT;
}
// We can finally add the name to the path
namePath.add(childNodeName);
// Add the path if this is the first entry in the name path
if (!added) {
namePaths.add(namePath);
added = true;
}
}
}
}
if (includeOwner) {
// cached in OwnableService
nodeMetaData.setOwner(ownableService.getOwner(status.getNodeRef()));
}
rowHandler.processResult(nodeMetaData);
}
}
use of org.alfresco.repo.domain.node.NodeDAO.ChildAssocRefQueryCallback in project alfresco-repository by Alfresco.
the class SOLRTrackingComponentImpl method getCRC.
public long getCRC(Long nodeId) {
// Status status = nodeDAO.getNodeIdStatus(nodeId);
// Set<QName> aspects = getNodeAspects(nodeId);
// Map<QName, Serializable> props = getProperties(nodeId);
// Category membership does not cascade to children - only the node needs reindexing, not its children
// This was producing cascade updates that were not required
// //CategoryPaths categoryPaths = new CategoryPaths(new ArrayList<Pair<Path, QName>>(), new ArrayList<ChildAssociationRef>());
// //categoryPaths = getCategoryPaths(status.getNodeRef(), aspects, props);
final List<ChildAssociationRef> parentAssocs = new ArrayList<ChildAssociationRef>(100);
nodeDAO.getParentAssocs(nodeId, null, null, null, new ChildAssocRefQueryCallback() {
@Override
public boolean preLoadNodes() {
return false;
}
@Override
public boolean orderResults() {
return false;
}
@Override
public boolean handle(Pair<Long, ChildAssociationRef> childAssocPair, Pair<Long, NodeRef> parentNodePair, Pair<Long, NodeRef> childNodePair) {
parentAssocs.add(tenantService.getBaseName(childAssocPair.getSecond(), true));
return true;
}
@Override
public void done() {
}
});
// for(ChildAssociationRef ref : categoryPaths.getCategoryParents())
// {
// parentAssocs.add(tenantService.getBaseName(ref, true));
// }
CRC32 crc = new CRC32();
for (ChildAssociationRef car : parentAssocs) {
try {
crc.update(car.toString().getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("UTF-8 encoding is not supported");
}
}
return crc.getValue();
}
Aggregations