use of org.alfresco.service.cmr.repository.AssociationRef in project alfresco-repository by Alfresco.
the class XMLTransferManifestReader method endElement.
// startElement
/**
* End Element
*/
@SuppressWarnings("unchecked")
public void endElement(String uri, String localName, String prefixName) throws SAXException {
namespaces.removeFirst();
QName elementQName = QName.resolveToQName(this, prefixName);
if (elementQName == null) {
return;
}
if (elementQName.getNamespaceURI().equals(TRANSFER_URI))
;
{
// This is one of the transfer manifest elements
String elementName = elementQName.getLocalName();
if (elementName.equals(ManifestModel.LOCALNAME_TRANSFER_MAINIFEST)) {
} else if (elementName.equals(ManifestModel.LOCALNAME_TRANSFER_HEADER)) {
TransferManifestHeader header = (TransferManifestHeader) props.get("header");
// User to process the header
processor.processTransferManifiestHeader(header);
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_NODE)) {
TransferManifestNormalNode node = (TransferManifestNormalNode) props.get("node");
processor.processTransferManifestNode(node);
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_DELETED_NODE)) {
TransferManifestDeletedNode node = (TransferManifestDeletedNode) props.get("node");
processor.processTransferManifestNode(node);
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_ASPECTS)) {
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_ASPECT)) {
TransferManifestNormalNode node = (TransferManifestNormalNode) props.get("node");
node.getAspects().add(QName.createQName(buffer.toString()));
buffer = null;
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_PROPERTIES)) {
// nothing to do
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_PROPERTY)) {
TransferManifestNormalNode node = (TransferManifestNormalNode) props.get("node");
QName name = (QName) props.get("name");
Serializable value = (Serializable) props.get("value");
node.getProperties().put(name, value);
} else if (elementName.equals(ManifestModel.LOCALNAME_HEADER_CREATED_DATE)) {
TransferManifestHeader header = (TransferManifestHeader) props.get("header");
header.setCreatedDate(ISO8601DateFormat.parse(buffer.toString()));
buffer = null;
} else if (elementName.equals(ManifestModel.LOCALNAME_HEADER_NODE_COUNT)) {
TransferManifestHeader header = (TransferManifestHeader) props.get("header");
header.setNodeCount(Integer.parseInt(buffer.toString()));
buffer = null;
} else if (elementName.equals(ManifestModel.LOCALNAME_HEADER_SYNC)) {
TransferManifestHeader header = (TransferManifestHeader) props.get("header");
header.setSync(true);
} else if (elementName.equals(ManifestModel.LOCALNAME_HEADER_RONLY)) {
TransferManifestHeader header = (TransferManifestHeader) props.get("header");
header.setReadOnly(true);
} else if (elementName.equals(ManifestModel.LOCALNAME_HEADER_REPOSITORY_ID)) {
TransferManifestHeader header = (TransferManifestHeader) props.get("header");
header.setRepositoryId(buffer.toString());
buffer = null;
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_PARENT_ASSOCS)) {
// No-op
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_CHILD_ASSOCS)) {
// No-op
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_CHILD_ASSOC)) {
String value = buffer.toString();
QName name = QName.createQName(value);
NodeRef to = (NodeRef) props.get("to");
QName type = (QName) props.get("type");
Boolean isPrimary = (Boolean) props.get("isPrimary");
TransferManifestNormalNode node = (TransferManifestNormalNode) props.get("node");
ChildAssociationRef childAssociationRef = new ChildAssociationRef(type, node.getNodeRef(), name, to, isPrimary, -1);
node.getChildAssocs().add(childAssociationRef);
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_PARENT_ASSOC)) {
String value = buffer.toString();
QName name = QName.createQName(value);
NodeRef from = (NodeRef) props.get("from");
QName type = (QName) props.get("type");
Boolean isPrimary = (Boolean) props.get("isPrimary");
TransferManifestNode node = (TransferManifestNode) props.get("node");
List<ChildAssociationRef> parentAssocs = (List<ChildAssociationRef>) props.get("parentAssocs");
ChildAssociationRef childAssociationRef = new ChildAssociationRef(type, from, name, node.getNodeRef(), isPrimary, -1);
parentAssocs.add(childAssociationRef);
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_TARGET_ASSOCS)) {
// TransferManifestNode node = (TransferManifestNode)props.get("node");
// node.getTargetAssocs().add((AssociationRef)props.get("assoc"));
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_SOURCE_ASSOCS)) {
// TransferManifestNode node = (TransferManifestNode)props.get("node");
// node.getSourceAssocs().add((AssociationRef)props.get("assoc"));
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_ASSOC)) {
NodeRef source = (NodeRef) props.get("source");
NodeRef target = (NodeRef) props.get("target");
QName type = (QName) props.get("type");
List<AssociationRef> assocs = (List<AssociationRef>) props.get("assocs");
AssociationRef assoc = new AssociationRef(null, source, type, target);
assocs.add(assoc);
props.put("assoc", new AssociationRef(null, source, type, target));
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_PRIMARY_PARENT)) {
TransferManifestNode node = (TransferManifestNode) props.get("node");
List<ChildAssociationRef> parentAssocs = (List<ChildAssociationRef>) props.get("parentAssocs");
if (parentAssocs != null) {
// Size should allways be 1.
assert (parentAssocs.size() == 1);
node.setPrimaryParentAssoc(parentAssocs.get(0));
}
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_PRIMARY_PATH)) {
TransferManifestNode node = (TransferManifestNode) props.get("node");
String value = buffer.toString();
Path path = PathHelper.stringToPath(value);
node.setParentPath(path);
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_VALUES)) {
props.put("value", props.get("values"));
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_VALUE_STRING)) {
Collection<Serializable> values = (Collection<Serializable>) props.get("values");
String className = (String) props.get("className");
Serializable value = buffer.toString();
if (className != null && !className.equals("java.lang.String")) {
// value is not a string and needs to be converted
try {
value = (Serializable) DefaultTypeConverter.INSTANCE.convert(Class.forName(className), value);
} catch (TypeConversionException tcf) {
// leave value as string
} catch (ClassNotFoundException cnf) {
// leave value as string
}
}
if (values != null) {
values.add(value);
} else {
props.put("value", value);
}
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_VALUE_NULL)) {
Collection<Serializable> values = (Collection<Serializable>) props.get("values");
if (values != null) {
values.add(null);
} else {
props.put("value", null);
}
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_VALUE_SERIALIZED)) {
Collection<Serializable> values = (Collection<Serializable>) props.get("values");
String encoding = (String) props.get("encoding");
String strValue = buffer.toString();
Object value = null;
if (encoding.equalsIgnoreCase("base64/ObjectOutputStream")) {
try {
byte[] data = Base64.decode(strValue.getBytes("UTF-8"));
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(data));
value = ois.readObject();
} catch (IOException error) {
throw new TransferException(MSG_UNABLE_DESERIALIZE, error);
} catch (ClassNotFoundException error) {
throw new TransferException(MSG_UNABLE_DESERIALIZE, error);
}
} else {
throw new TransferException(MSG_NO_ENCODING, new Object[] { encoding });
}
if (values != null) {
// This is a values array
values.add((Serializable) value);
} else {
// This is a single value
props.put("value", value);
}
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_MLVALUE)) {
MLText mltext = (MLText) props.get("mlvalues");
Locale locale = (Locale) props.get("locale");
String value = buffer.toString();
mltext.addValue(locale, value);
props.put("value", mltext);
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_CONTENT_HEADER)) {
ContentData data = (ContentData) props.get("contentHeader");
props.put("value", data);
} else if (elementName.equals(ManifestModel.LOCALNAME_HEADER_VERSION)) {
TransferManifestHeader header = (TransferManifestHeader) props.get("header");
TransferVersion version = (TransferVersion) props.get("headerVersion");
header.setTransferVersion(version);
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_ACL)) {
TransferManifestNormalNode node = (TransferManifestNormalNode) props.get("node");
ManifestAccessControl acl = (ManifestAccessControl) props.get("acl");
node.setAccessControl(acl);
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_ACL_PERMISSION)) {
ManifestAccessControl acl = (ManifestAccessControl) props.get("acl");
ManifestPermission permission = (ManifestPermission) props.get("permission");
acl.addPermission(permission);
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_CATEGORIES)) {
TransferManifestNormalNode node = (TransferManifestNormalNode) props.get("node");
Map<NodeRef, ManifestCategory> categories = (Map<NodeRef, ManifestCategory>) props.get("categories");
node.setManifestCategories(categories);
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_CATEGORY)) {
Map<NodeRef, ManifestCategory> categories = (Map<NodeRef, ManifestCategory>) props.get("categories");
ManifestCategory category = (ManifestCategory) props.get("category");
categories.put(new NodeRef(buffer.toString().trim()), category);
}
}
// if transfer URI
}
use of org.alfresco.service.cmr.repository.AssociationRef in project alfresco-repository by Alfresco.
the class NodeFormProcessor method getAssociationValues.
@Override
protected Map<QName, Serializable> getAssociationValues(NodeRef item) {
HashMap<QName, Serializable> assocs = new HashMap<QName, Serializable>();
List<AssociationRef> targetAssocs = nodeService.getTargetAssocs(item, RegexQNamePattern.MATCH_ALL);
List<ChildAssociationRef> childAssocs = nodeService.getChildAssocs(item);
for (ChildAssociationRef childAssoc : childAssocs) {
QName name = childAssoc.getTypeQName();
NodeRef target = childAssoc.getChildRef();
addAssocToMap(name, target, assocs);
}
for (AssociationRef associationRef : targetAssocs) {
QName name = associationRef.getTypeQName();
NodeRef target = associationRef.getTargetRef();
if (nodeService.exists(target) && (permissionService.hasPermission(target, PermissionService.READ) == AccessStatus.ALLOWED)) {
addAssocToMap(name, target, assocs);
}
}
return assocs;
}
use of org.alfresco.service.cmr.repository.AssociationRef in project alfresco-repository by Alfresco.
the class RemoveChildAssocCommand method updateAssociations.
@Override
protected void updateAssociations(NodeService nodeService) {
List<AssociationRef> existingAssocs = nodeService.getTargetAssocs(sourceNodeRef, assocQName);
boolean assocDoesNotExist = true;
for (AssociationRef assoc : existingAssocs) {
if (assoc.getTargetRef().equals(targetNodeRef)) {
assocDoesNotExist = false;
break;
}
}
if (assocDoesNotExist) {
if (logger.isWarnEnabled()) {
StringBuilder msg = new StringBuilder();
msg.append("Attempt to remove non-existent association prevented. ").append(sourceNodeRef).append("|").append(targetNodeRef).append(assocQName);
logger.warn(msg.toString());
}
return;
}
nodeService.removeAssociation(sourceNodeRef, targetNodeRef, assocQName);
}
use of org.alfresco.service.cmr.repository.AssociationRef in project alfresco-repository by Alfresco.
the class DbNodeServiceImpl method deleteNode.
/**
* Delete a node
*
* @param nodeRef the node to delete
* @param allowArchival <tt>true</tt> if normal archival may occur or
* <tt>false</tt> if the node must be forcibly deleted
*/
private void deleteNode(NodeRef nodeRef, boolean allowArchival) {
// The node(s) involved may not be pending deletion
checkPendingDelete(nodeRef);
// Pair contains NodeId, NodeRef
Pair<Long, NodeRef> nodePair = getNodePairNotNull(nodeRef);
Long nodeId = nodePair.getFirst();
Boolean requiresDelete = null;
// get type and aspect QNames as they will be unavailable after the delete
QName nodeTypeQName = nodeDAO.getNodeType(nodeId);
Set<QName> nodeAspectQNames = nodeDAO.getNodeAspects(nodeId);
// Have we been asked to delete a store?
if (nodeTypeQName.equals(ContentModel.TYPE_STOREROOT)) {
throw new IllegalArgumentException("A store root node cannot be deleted: " + nodeRef);
}
// get the primary parent-child relationship before it is gone
Pair<Long, ChildAssociationRef> childAssocPair = nodeDAO.getPrimaryParentAssoc(nodeId);
ChildAssociationRef childAssocRef = childAssocPair.getSecond();
// Is this store
StoreRef storeRef = nodeRef.getStoreRef();
StoreRef archiveStoreRef = storeArchiveMap.get(storeRef);
// Gather information about the hierarchy
NodeHierarchyWalker walker = new NodeHierarchyWalker(nodeDAO);
walker.walkHierarchy(nodePair, childAssocPair);
// Protect the nodes from being link/unlinked for the remainder of the process
Set<NodeRef> nodesPendingDelete = new HashSet<NodeRef>(walker.getNodes(false).size());
for (VisitedNode visitedNode : walker.getNodes(true)) {
nodesPendingDelete.add(visitedNode.nodeRef);
}
Set<NodeRef> nodesPendingDeleteTxn = TransactionalResourceHelper.getSet(KEY_PENDING_DELETE_NODES);
// We need to remove these later, again
nodesPendingDeleteTxn.addAll(nodesPendingDelete);
// Work out whether we need to archive or delete the node.
if (!allowArchival) {
// No archival allowed
requiresDelete = true;
} else if (archiveStoreRef == null) {
// The store does not specify archiving
requiresDelete = true;
} else {
// get the type and check if we need archiving.
TypeDefinition typeDef = dictionaryService.getType(nodeTypeQName);
if (typeDef != null) {
Boolean requiresArchive = typeDef.getArchive();
if (requiresArchive != null) {
requiresDelete = !requiresArchive;
}
}
// If the type hasn't asked for deletion, check whether any applied aspects have
Iterator<QName> i = nodeAspectQNames.iterator();
while ((requiresDelete == null || !requiresDelete) && i.hasNext()) {
QName nodeAspectQName = i.next();
AspectDefinition aspectDef = dictionaryService.getAspect(nodeAspectQName);
if (aspectDef != null) {
Boolean requiresArchive = aspectDef.getArchive();
if (requiresArchive != null) {
requiresDelete = !requiresArchive;
}
}
}
}
// Propagate timestamps
propagateTimeStamps(childAssocRef);
// Archive, if necessary
boolean archive = requiresDelete != null && !requiresDelete.booleanValue();
// Fire pre-delete events
// Prevents duplicate firing
Set<Long> childAssocIds = new HashSet<Long>(23);
// Prevents duplicate firing
Set<Long> peerAssocIds = new HashSet<Long>(23);
List<VisitedNode> nodesToDelete = walker.getNodes(true);
for (VisitedNode nodeToDelete : nodesToDelete) {
// Target associations
for (Pair<Long, AssociationRef> targetAssocPair : nodeToDelete.targetAssocs) {
if (!peerAssocIds.add(targetAssocPair.getFirst())) {
// Already fired
continue;
}
invokeBeforeDeleteAssociation(targetAssocPair.getSecond());
}
// Source associations
for (Pair<Long, AssociationRef> sourceAssocPair : nodeToDelete.sourceAssocs) {
if (!peerAssocIds.add(sourceAssocPair.getFirst())) {
// Already fired
continue;
}
invokeBeforeDeleteAssociation(sourceAssocPair.getSecond());
}
// Secondary child associations
for (Pair<Long, ChildAssociationRef> secondaryChildAssocPair : nodeToDelete.secondaryChildAssocs) {
if (!childAssocIds.add(secondaryChildAssocPair.getFirst())) {
// Already fired
continue;
}
invokeBeforeDeleteChildAssociation(secondaryChildAssocPair.getSecond());
}
// Secondary parent associations
for (Pair<Long, ChildAssociationRef> secondaryParentAssocPair : nodeToDelete.secondaryParentAssocs) {
if (!childAssocIds.add(secondaryParentAssocPair.getFirst())) {
// Already fired
continue;
}
invokeBeforeDeleteChildAssociation(secondaryParentAssocPair.getSecond());
}
// Primary child associations
if (archive) {
invokeBeforeArchiveNode(nodeToDelete.nodeRef);
}
invokeBeforeDeleteNode(nodeToDelete.nodeRef);
}
// Archive, if necessary
if (archive) {
// Archive node
archiveHierarchy(walker, archiveStoreRef);
}
// Delete/Archive and fire post-delete events incl. updating indexes
// Prevents duplicate firing
childAssocIds.clear();
// Prevents duplicate firing
peerAssocIds.clear();
for (VisitedNode nodeToDelete : nodesToDelete) {
// Target associations
for (Pair<Long, AssociationRef> targetAssocPair : nodeToDelete.targetAssocs) {
if (!peerAssocIds.add(targetAssocPair.getFirst())) {
// Already fired
continue;
}
nodeDAO.removeNodeAssocs(Collections.singletonList(targetAssocPair.getFirst()));
invokeOnDeleteAssociation(targetAssocPair.getSecond());
}
// Source associations
for (Pair<Long, AssociationRef> sourceAssocPair : nodeToDelete.sourceAssocs) {
if (!peerAssocIds.add(sourceAssocPair.getFirst())) {
// Already fired
continue;
}
nodeDAO.removeNodeAssocs(Collections.singletonList(sourceAssocPair.getFirst()));
invokeOnDeleteAssociation(sourceAssocPair.getSecond());
}
// Secondary child associations
for (Pair<Long, ChildAssociationRef> secondaryChildAssocPair : nodeToDelete.secondaryChildAssocs) {
if (!childAssocIds.add(secondaryChildAssocPair.getFirst())) {
// Already fired
continue;
}
nodeDAO.deleteChildAssoc(secondaryChildAssocPair.getFirst());
invokeOnDeleteChildAssociation(secondaryChildAssocPair.getSecond());
}
// Secondary parent associations
for (Pair<Long, ChildAssociationRef> secondaryParentAssocPair : nodeToDelete.secondaryParentAssocs) {
if (!childAssocIds.add(secondaryParentAssocPair.getFirst())) {
// Already fired
continue;
}
nodeDAO.deleteChildAssoc(secondaryParentAssocPair.getFirst());
invokeOnDeleteChildAssociation(secondaryParentAssocPair.getSecond());
}
QName childNodeTypeQName = nodeDAO.getNodeType(nodeToDelete.id);
Set<QName> childAspectQnames = nodeDAO.getNodeAspects(nodeToDelete.id);
// Delete the node
nodeDAO.deleteChildAssoc(nodeToDelete.primaryParentAssocPair.getFirst());
nodeDAO.deleteNode(nodeToDelete.id);
invokeOnDeleteNode(nodeToDelete.primaryParentAssocPair.getSecond(), childNodeTypeQName, childAspectQnames, archive);
}
// Clear out the list of nodes pending delete
nodesPendingDeleteTxn = TransactionalResourceHelper.getSet(KEY_PENDING_DELETE_NODES);
nodesPendingDeleteTxn.removeAll(nodesPendingDelete);
}
use of org.alfresco.service.cmr.repository.AssociationRef in project alfresco-repository by Alfresco.
the class DbNodeServiceImpl method getSourceAssocs.
@Extend(traitAPI = NodeServiceTrait.class, extensionAPI = NodeServiceExtension.class)
public List<AssociationRef> getSourceAssocs(NodeRef targetRef, QNamePattern qnamePattern) {
Pair<Long, NodeRef> targetNodePair = getNodePairNotNull(targetRef);
Long targetNodeId = targetNodePair.getFirst();
QName qnameFilter = null;
if (qnamePattern instanceof QName) {
qnameFilter = (QName) qnamePattern;
}
Collection<Pair<Long, AssociationRef>> assocPairs = nodeDAO.getSourceNodeAssocs(targetNodeId, qnameFilter);
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;
}
Aggregations