use of org.alfresco.traitextender.Extend 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.traitextender.Extend in project alfresco-repository by Alfresco.
the class DbNodeServiceImpl method getTargetAssocsByPropertyValue.
@Override
@Extend(traitAPI = NodeServiceTrait.class, extensionAPI = NodeServiceExtension.class)
public List<AssociationRef> getTargetAssocsByPropertyValue(NodeRef sourceRef, QNamePattern qnamePattern, QName propertyQName, Serializable propertyValue) {
Pair<Long, NodeRef> sourceNodePair = getNodePairNotNull(sourceRef);
Long sourceNodeId = sourceNodePair.getFirst();
QName qnameFilter = null;
if (qnamePattern instanceof QName) {
qnameFilter = (QName) qnamePattern;
}
// Check the QName is not one of the "special" system maintained ones.
if (getChildAssocsByPropertyValueBannedProps.contains(propertyQName)) {
throw new IllegalArgumentException("getTargetAssocsByPropertyValue does not allow search of system maintained properties: " + propertyQName);
}
Collection<Pair<Long, AssociationRef>> assocPairs = nodeDAO.getTargetAssocsByPropertyValue(sourceNodeId, qnameFilter, propertyQName, propertyValue);
List<AssociationRef> nodeAssocRefs = new ArrayList<AssociationRef>(assocPairs.size());
for (Pair<Long, AssociationRef> assocPair : assocPairs) {
AssociationRef assocRef = assocPair.getSecond();
// check qname pattern, if not already filtered
if (qnameFilter == null && !qnamePattern.isMatch(assocRef.getTypeQName())) {
// the assoc name doesn't match the pattern given
continue;
}
nodeAssocRefs.add(assocRef);
}
// done
return nodeAssocRefs;
}
use of org.alfresco.traitextender.Extend in project alfresco-repository by Alfresco.
the class DbNodeServiceImpl method removeChildAssociation.
@Extend(traitAPI = NodeServiceTrait.class, extensionAPI = NodeServiceExtension.class)
public boolean removeChildAssociation(ChildAssociationRef childAssocRef) {
// The node(s) involved may not be pending deletion
checkPendingDelete(childAssocRef.getParentRef());
checkPendingDelete(childAssocRef.getChildRef());
Long parentNodeId = getNodePairNotNull(childAssocRef.getParentRef()).getFirst();
Long childNodeId = getNodePairNotNull(childAssocRef.getChildRef()).getFirst();
QName assocTypeQName = childAssocRef.getTypeQName();
QName assocQName = childAssocRef.getQName();
Pair<Long, ChildAssociationRef> assocPair = nodeDAO.getChildAssoc(parentNodeId, childNodeId, assocTypeQName, assocQName);
if (assocPair == null) {
// No association exists
return false;
}
Long assocId = assocPair.getFirst();
ChildAssociationRef assocRef = assocPair.getSecond();
if (assocRef.isPrimary()) {
NodeRef childNodeRef = assocRef.getChildRef();
// Delete the child node
this.deleteNode(childNodeRef);
// Done
return true;
} else {
// Delete the association
invokeBeforeDeleteChildAssociation(childAssocRef);
nodeDAO.deleteChildAssoc(assocId);
invokeOnDeleteChildAssociation(childAssocRef);
// Done
return true;
}
}
use of org.alfresco.traitextender.Extend in project alfresco-repository by Alfresco.
the class DbNodeServiceImpl method deleteStore.
/**
* @throws UnsupportedOperationException Always
*/
@Extend(traitAPI = NodeServiceTrait.class, extensionAPI = NodeServiceExtension.class)
public void deleteStore(StoreRef storeRef) throws InvalidStoreRefException {
// Cannot delete the root node but we can delete, without archive, all immediate children
NodeRef rootNodeRef = nodeDAO.getRootNode(storeRef).getSecond();
List<ChildAssociationRef> childAssocRefs = getChildAssocs(rootNodeRef);
for (ChildAssociationRef childAssocRef : childAssocRefs) {
NodeRef childNodeRef = childAssocRef.getChildRef();
// We do NOT want to archive these, so mark them as temporary
deleteNode(childNodeRef, false);
}
// Rename the store. This takes all the nodes with it.
StoreRef deletedStoreRef = new StoreRef(StoreRef.PROTOCOL_DELETED, GUID.generate());
nodeDAO.moveStore(storeRef, deletedStoreRef);
// Done
if (logger.isDebugEnabled()) {
logger.debug("Marked store for deletion: " + storeRef + " --> " + deletedStoreRef);
}
}
use of org.alfresco.traitextender.Extend in project alfresco-repository by Alfresco.
the class DbNodeServiceImpl method getProperty.
@Extend(traitAPI = NodeServiceTrait.class, extensionAPI = NodeServiceExtension.class)
public Serializable getProperty(NodeRef nodeRef, QName qname) throws InvalidNodeRefException {
Long nodeId = getNodePairNotNull(nodeRef).getFirst();
// Spoof referencable properties
if (qname.equals(ContentModel.PROP_STORE_PROTOCOL)) {
return nodeRef.getStoreRef().getProtocol();
} else if (qname.equals(ContentModel.PROP_STORE_IDENTIFIER)) {
return nodeRef.getStoreRef().getIdentifier();
} else if (qname.equals(ContentModel.PROP_NODE_UUID)) {
return nodeRef.getId();
} else if (qname.equals(ContentModel.PROP_NODE_DBID)) {
return nodeId;
}
Serializable property = nodeDAO.getNodeProperty(nodeId, qname);
// check if we need to provide a spoofed name
if (property == null && qname.equals(ContentModel.PROP_NAME)) {
return nodeRef.getId();
}
// done
return property;
}
Aggregations