use of org.alfresco.service.cmr.repository.AssociationRef in project alfresco-repository by Alfresco.
the class AbstractNodeDAOImpl method getNodeAssocsToAndFrom.
@Override
public Collection<Pair<Long, AssociationRef>> getNodeAssocsToAndFrom(Long nodeId) {
List<NodeAssocEntity> nodeAssocEntities = selectNodeAssocs(nodeId);
List<Pair<Long, AssociationRef>> results = new ArrayList<Pair<Long, AssociationRef>>(nodeAssocEntities.size());
for (NodeAssocEntity nodeAssocEntity : nodeAssocEntities) {
Long assocId = nodeAssocEntity.getId();
AssociationRef assocRef = nodeAssocEntity.getAssociationRef(qnameDAO);
results.add(new Pair<Long, AssociationRef>(assocId, assocRef));
}
return results;
}
use of org.alfresco.service.cmr.repository.AssociationRef in project alfresco-repository by Alfresco.
the class AbstractNodeDAOImpl method getTargetAssocsByPropertyValue.
@Override
public Collection<Pair<Long, AssociationRef>> getTargetAssocsByPropertyValue(Long sourceNodeId, QName typeQName, QName propertyQName, Serializable propertyValue) {
Long typeQNameId = null;
if (typeQName != null) {
Pair<Long, QName> typeQNamePair = qnameDAO.getQName(typeQName);
if (typeQNamePair == null) {
// No such QName
return Collections.emptyList();
}
typeQNameId = typeQNamePair.getFirst();
}
Long propertyQNameId = null;
NodePropertyValue nodeValue = null;
if (propertyQName != null) {
Pair<Long, QName> propQNamePair = qnameDAO.getQName(propertyQName);
if (propQNamePair == null) {
// No such QName
return Collections.emptyList();
}
propertyQNameId = propQNamePair.getFirst();
PropertyDefinition propertyDef = dictionaryService.getProperty(propertyQName);
nodeValue = nodePropertyHelper.makeNodePropertyValue(propertyDef, propertyValue);
if (nodeValue != null) {
switch(nodeValue.getPersistedType()) {
// Boolean
case 1:
// long
case 3:
// double
case 5:
case // string
6:
// no floats due to the range errors testing equality on a float.
break;
default:
throw new IllegalArgumentException("method not supported for persisted value type " + nodeValue.getPersistedType());
}
}
}
List<NodeAssocEntity> nodeAssocEntities = selectNodeAssocsBySourceAndPropertyValue(sourceNodeId, typeQNameId, propertyQNameId, nodeValue);
// Create custom result
List<Pair<Long, AssociationRef>> results = new ArrayList<Pair<Long, AssociationRef>>(nodeAssocEntities.size());
for (NodeAssocEntity nodeAssocEntity : nodeAssocEntities) {
Long assocId = nodeAssocEntity.getId();
AssociationRef assocRef = nodeAssocEntity.getAssociationRef(qnameDAO);
results.add(new Pair<Long, AssociationRef>(assocId, assocRef));
}
return results;
}
use of org.alfresco.service.cmr.repository.AssociationRef in project alfresco-repository by Alfresco.
the class MultiTNodeServiceInterceptor method convertOutboundValue.
/**
* Convert outbound single value to spoofed (ie. without tenant prefix) value.
*/
@SuppressWarnings("unchecked")
private Object convertOutboundValue(Object rawValue) {
if (rawValue == null) {
return null;
}
Object value = rawValue;
if (rawValue instanceof Collection) {
// Deal with collections
value = convertOutboundValues((Collection<Object>) rawValue);
} else if (rawValue instanceof StoreRef) {
StoreRef ref = (StoreRef) rawValue;
value = tenantService.getBaseName(ref);
} else if (rawValue instanceof NodeRef) {
NodeRef ref = (NodeRef) rawValue;
value = tenantService.getBaseName(ref);
} else if (rawValue instanceof ChildAssociationRef) {
ChildAssociationRef ref = (ChildAssociationRef) rawValue;
value = tenantService.getBaseName(ref);
} else if (rawValue instanceof AssociationRef) {
AssociationRef ref = (AssociationRef) rawValue;
value = tenantService.getBaseName(ref);
} else if (rawValue instanceof Path) {
Path ref = (Path) rawValue;
Path outboundPath = new Path();
Iterator<Path.Element> itr = ref.iterator();
while (itr.hasNext()) {
Path.Element pathElement = itr.next();
if (pathElement instanceof Path.ChildAssocElement) {
pathElement = new Path.ChildAssocElement(tenantService.getBaseName(((Path.ChildAssocElement) pathElement).getRef()));
}
outboundPath.append(pathElement);
}
value = outboundPath;
}
// Done
return value;
}
use of org.alfresco.service.cmr.repository.AssociationRef in project alfresco-repository by Alfresco.
the class TemplateNode method getSourceAssocs.
/**
* @return Source associations for this Node. As a Map of assoc name to a List of TemplateNodes.
*/
public Map<String, List<TemplateNode>> getSourceAssocs() {
if (this.sourceAssocs == null) {
List<AssociationRef> refs = this.services.getNodeService().getSourceAssocs(this.nodeRef, RegexQNamePattern.MATCH_ALL);
this.sourceAssocs = new QNameMap<String, List<TemplateNode>>(this);
for (AssociationRef ref : refs) {
String qname = ref.getTypeQName().toString();
List<TemplateNode> nodes = this.sourceAssocs.get(qname);
if (nodes == null) {
// first access for the list for this qname
nodes = new ArrayList<TemplateNode>(4);
this.sourceAssocs.put(ref.getTypeQName().toString(), nodes);
}
nodes.add(new TemplateNode(ref.getSourceRef(), this.services, this.imageResolver));
}
}
return this.sourceAssocs;
}
use of org.alfresco.service.cmr.repository.AssociationRef in project alfresco-repository by Alfresco.
the class NodeStoreInspector method outputNode.
/**
* Output the node
*
* @param iIndent int
* @param nodeService NodeService
* @param nodeRef NodeRef
* @return String
*/
private static String outputNode(int iIndent, NodeService nodeService, NodeRef nodeRef) {
StringBuilder builder = new StringBuilder();
try {
QName nodeType = nodeService.getType(nodeRef);
builder.append(getIndent(iIndent)).append("node: ").append(nodeRef.getId()).append(" (").append(nodeType.getLocalName());
Collection<QName> aspects = nodeService.getAspects(nodeRef);
for (QName aspect : aspects) {
builder.append(", ").append(aspect.getLocalName());
}
builder.append(")\n");
Map<QName, Serializable> props = nodeService.getProperties(nodeRef);
for (QName name : props.keySet()) {
String valueAsString = "null";
Serializable value = props.get(name);
if (value != null) {
valueAsString = value.toString();
}
builder.append(getIndent(iIndent + 1)).append("@").append(name.getLocalName()).append(" = ").append(valueAsString).append("\n");
}
Collection<ChildAssociationRef> childAssocRefs = nodeService.getChildAssocs(nodeRef);
for (ChildAssociationRef childAssocRef : childAssocRefs) {
builder.append(getIndent(iIndent + 1)).append("-> ").append(childAssocRef.getQName().toString()).append(" (").append(childAssocRef.getQName().toString()).append(")\n");
builder.append(outputNode(iIndent + 2, nodeService, childAssocRef.getChildRef()));
}
Collection<AssociationRef> assocRefs = nodeService.getTargetAssocs(nodeRef, RegexQNamePattern.MATCH_ALL);
for (AssociationRef assocRef : assocRefs) {
builder.append(getIndent(iIndent + 1)).append("-> associated to ").append(assocRef.getTargetRef().getId()).append("\n");
}
} catch (InvalidNodeRefException invalidNode) {
invalidNode.printStackTrace();
}
return builder.toString();
}
Aggregations