Java Code Examples for org.alfresco.service.cmr.repository.ChildAssociationRef#isPrimary()

The following examples show how to use org.alfresco.service.cmr.repository.ChildAssociationRef#isPrimary() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RepoTransferReceiverImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * move transfer node to new parent.
 * @param childNode
 * @param newParent
 */
private void moveNode(TransferManifestNormalNode childNode, TransferManifestNormalNode newParent)
{
    List<ChildAssociationRef> currentParents = childNode.getParentAssocs();
    List<ChildAssociationRef> newParents = new ArrayList<ChildAssociationRef>();

    for (ChildAssociationRef parent : currentParents)
    {
        if (!parent.isPrimary())
        {
            newParents.add(parent);
        }
        else
        {
            ChildAssociationRef newPrimaryAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, newParent
                    .getNodeRef(), parent.getQName(), parent.getChildRef(), true, -1);
            newParents.add(newPrimaryAssoc);
            childNode.setPrimaryParentAssoc(newPrimaryAssoc);
            Path newParentPath = new Path();
            newParentPath.append(newParent.getParentPath());
            newParentPath.append(new Path.ChildAssocElement(newParent.getPrimaryParentAssoc()));
            childNode.setParentPath(newParentPath);
        }
    }
    childNode.setParentAssocs(newParents);
}
 
Example 2
Source File: MultiTServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public ChildAssociationRef getBaseName(ChildAssociationRef childAssocRef, boolean forceForNonTenant)
{
    if (childAssocRef == null)
    {
        return null;
    }

    return new ChildAssociationRef(
            childAssocRef.getTypeQName(),
            getBaseName(childAssocRef.getParentRef(), forceForNonTenant),
            childAssocRef.getQName(),
            getBaseName(childAssocRef.getChildRef(), forceForNonTenant),
            childAssocRef.isPrimary(),
            childAssocRef.getNthSibling());
}
 
Example 3
Source File: XMLTransferManifestWriter.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void writeParentAssoc(ChildAssociationRef assoc) throws SAXException
{
    if (assoc != null)
    {
        AttributesImpl attributes = new AttributesImpl();
        attributes.addAttribute(TransferModel.TRANSFER_MODEL_1_0_URI, "from", "from", "String",
                    assoc.getParentRef().toString());
        attributes.addAttribute(TransferModel.TRANSFER_MODEL_1_0_URI, "type", "type", "String",
                    formatQName(assoc.getTypeQName()));
        attributes.addAttribute(TransferModel.TRANSFER_MODEL_1_0_URI, "type", "isPrimary",
                    "Boolean", assoc.isPrimary() ? "true" : "false");
        writer.startElement(TransferModel.TRANSFER_MODEL_1_0_URI,
                    ManifestModel.LOCALNAME_ELEMENT_PARENT_ASSOC, PREFIX + ":"
                                + ManifestModel.LOCALNAME_ELEMENT_PARENT_ASSOC, attributes);
        String name = formatQName(assoc.getQName());
        writer.characters(name.toCharArray(), 0, name.length());
        assoc.isPrimary();

        writer.endElement(TransferModel.TRANSFER_MODEL_1_0_URI,
                    ManifestModel.LOCALNAME_ELEMENT_PARENT_ASSOC, PREFIX + ":"
                                + ManifestModel.LOCALNAME_ELEMENT_PARENT_ASSOC);
    }
}
 
Example 4
Source File: XMLTransferReportWriter.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void writeParentAssoc(ChildAssociationRef assoc) throws SAXException
{
    if(assoc != null)
    {
        AttributesImpl attributes = new AttributesImpl();
        attributes.addAttribute(TransferModel.TRANSFER_MODEL_1_0_URI, "from", "from", "String", assoc.getParentRef().toString());     
        attributes.addAttribute(TransferModel.TRANSFER_MODEL_1_0_URI, "type", "type", "String", formatQName(assoc.getTypeQName()));
        attributes.addAttribute(TransferModel.TRANSFER_MODEL_1_0_URI, "type", "isPrimary", "Boolean", assoc.isPrimary()?"true":"false");
        writer.startElement(TransferModel.TRANSFER_MODEL_1_0_URI, ManifestModel.LOCALNAME_ELEMENT_PARENT_ASSOC, PREFIX + ":" + ManifestModel.LOCALNAME_ELEMENT_PARENT_ASSOC,  attributes);
        String name= formatQName(assoc.getQName());
        writer.characters(name.toCharArray(), 0, name.length());            
        assoc.isPrimary();

        writer.endElement(TransferModel.TRANSFER_MODEL_1_0_URI, ManifestModel.LOCALNAME_ELEMENT_PARENT_ASSOC, PREFIX + ":" + ManifestModel.LOCALNAME_ELEMENT_PARENT_ASSOC); 
    }
}
 
Example 5
Source File: MultiTServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public ChildAssociationRef getName(ChildAssociationRef childAssocRef)
{
    if (childAssocRef == null)
    {
        return null;
    }

    return new ChildAssociationRef(
            childAssocRef.getTypeQName(),
            getName(childAssocRef.getParentRef()),
            childAssocRef.getQName(),
            getName(childAssocRef.getChildRef()),
            childAssocRef.isPrimary(),
            childAssocRef.getNthSibling());
}
 
Example 6
Source File: RuleServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public NodeRef getLinkedToRuleNode(NodeRef nodeRef)
{
    NodeRef result = null;
    
    // Check whether the node reference has the rule aspect
    if (nodeService.hasAspect(nodeRef, RuleModel.ASPECT_RULES) == true)
    {
        ChildAssociationRef assoc = getSavedRuleFolderAssoc(nodeRef);
        if (assoc.isPrimary() == false)
        {
            result = nodeService.getPrimaryParent(assoc.getChildRef()).getParentRef();
        }
    }
    
    return result;
}
 
Example 7
Source File: RuleServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public List<NodeRef> getLinkedFromRuleNodes(NodeRef nodeRef)
{
    List<NodeRef> result = new ArrayList<NodeRef>();
    
    if (nodeService.hasAspect(nodeRef, RuleModel.ASPECT_RULES) == true)
    {
        ChildAssociationRef assoc = getSavedRuleFolderAssoc(nodeRef);
        if (assoc.isPrimary() == true)
        {
            List<ChildAssociationRef> linkedAssocs = nodeService.getParentAssocs(assoc.getChildRef());
            for (ChildAssociationRef linkAssoc : linkedAssocs)
            {
                if (linkAssoc.isPrimary() == false)
                {
                    result.add(linkAssoc.getParentRef());
                }
            }
        }
    }
    return result;
}
 
Example 8
Source File: DbNodeServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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;
    }
}
 
Example 9
Source File: EventGenerator.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void sendEvent(ChildAssociationRef childAssociationRef, ChildAssociationEventConsolidator consolidator)
{
    if (consolidator.isTemporaryChildAssociation())
    {
        if (LOGGER.isTraceEnabled())
        {
            LOGGER.trace("Ignoring temporary child association: " + childAssociationRef);
        }
        return;
    }

    final String user = AuthenticationUtil.getFullyAuthenticatedUser();
    // Get the repo event before the filtering,
    // so we can take the latest association info into account
    final RepoEvent<?> event = consolidator.getRepoEvent(getEventInfo(user));

    final QName childAssocType = consolidator.getChildAssocType();
    if (isFilteredChildAssociation(childAssocType, user))
    {
        if (LOGGER.isTraceEnabled())
        {
            LOGGER.trace("EventFilter - Excluding child association: '" + childAssociationRef + "' of type: '"
                    + ((childAssocType == null) ? "Unknown' " : childAssocType.toPrefixString())
                    + "' created by: " + user);
        }
        return;
    } else if (childAssociationRef.isPrimary())
    {
        if (LOGGER.isTraceEnabled())
        {
            LOGGER.trace("EventFilter - Excluding primary child association: '" + childAssociationRef + "' of type: '"
                    + ((childAssocType == null) ? "Unknown' " : childAssocType.toPrefixString())
                    + "' created by: " + user);
        }
        return;
    }

    logAndSendEvent(event, consolidator.getEventTypes());
}
 
Example 10
Source File: DbNodeServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
@Extend(traitAPI=NodeServiceTrait.class,extensionAPI=NodeServiceExtension.class)
public boolean removeSecondaryChildAssociation(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())
    {
        throw new IllegalArgumentException(
                "removeSeconaryChildAssociation can not be applied to a primary association: \n" +
                "   Child Assoc: " + assocRef);
    }
    // Delete the secondary association
    invokeBeforeDeleteChildAssociation(childAssocRef);
    nodeDAO.deleteChildAssoc(assocId);
    invokeOnDeleteChildAssociation(childAssocRef);
    // Done
    return true;
}
 
Example 11
Source File: EventGenerationBehaviours.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onDeleteChildAssociation(ChildAssociationRef childAssocRef)
{
    if (!childAssocRef.isPrimary())
    {
        eventsService.secondaryAssociationDeleted(childAssocRef);
    }
}
 
Example 12
Source File: GetChildAssocsMethod.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public List<ChildAssociationRef> execute(NodeProtocol protocol, Reference reference) throws ProtocolMethodException
{
    NodeRef actualNodeRef = reference.execute(new GetActualNodeRefMethod(null));
    NodeRef nodeRefReference = reference.toNodeRef();
    List<ChildAssociationRef> referenceAssociations = new LinkedList<>();
    if (!environment.isSubClass(environment.getType(nodeRefReference), ContentModel.TYPE_FOLDER))
    {
        List<ChildAssociationRef> actualAssociations = environment.getChildAssocs(actualNodeRef,
                                                                                  typeQNamePattern,
                                                                                  qnamePattern,
                                                                                  maxResults,
                                                                                  preload);

        for (ChildAssociationRef actualAssoc : actualAssociations)
        {
            ChildAssociationRef referenceChildAssocRef = new ChildAssociationRef(actualAssoc.getTypeQName(),
                                                                                 nodeRefReference,
                                                                                 actualAssoc.getQName(),
                                                                                 actualAssoc.getChildRef(),
                                                                                 actualAssoc.isPrimary(),
                                                                                 actualAssoc.getNthSibling());

            referenceAssociations.add(referenceChildAssocRef);
        }
    }
    return referenceAssociations;
}
 
Example 13
Source File: RulesAspect.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * The rule folder & below will be deleted automatically in the normal way, so we don't need to worry about them.
 * But we need additional handling for any other folders which have rules linked to this folder's rules. See
 * ALF-11923, ALF-15262.
 * 
 * @see org.alfresco.repo.node.NodeServicePolicies.BeforeRemoveAspectPolicy#beforeRemoveAspect(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
 */
@Override
public void beforeRemoveAspect(NodeRef nodeRef, QName aspectTypeQName)
{
    if (!aspectTypeQName.equals(RuleModel.ASPECT_RULES))
    {
        return;
    }

    this.ruleService.disableRules(nodeRef);
    try
    {
        for (ChildAssociationRef childAssocRef : nodeService.getChildAssocs(nodeRef, RuleModel.ASSOC_RULE_FOLDER,
                RuleModel.ASSOC_RULE_FOLDER, false))
        {
            // We are only interested in the deletion of primary associations to a rule folder, which usually
            // happens when all rules in a folder are deleted and the ASPECT_RULES aspect is removed
            if (!childAssocRef.isPrimary())
            {
                continue;
            }
            NodeRef savedRuleFolderRef = childAssocRef.getChildRef();
            // Cascade the removal to all secondary (linked) parents
            List<ChildAssociationRef> linkedAssocs = nodeService.getParentAssocs(savedRuleFolderRef);
            for (ChildAssociationRef linkAssoc : linkedAssocs)
            {
                if (!linkAssoc.isPrimary())
                {
                    // Remove the aspect from linked parents; this will also delete the linking secondary
                    // association
                    nodeService.removeAspect(linkAssoc.getParentRef(), RuleModel.ASPECT_RULES);
                }
            }
        }
    }
    finally
    {
        this.ruleService.enableRules(nodeRef);
    }
}
 
Example 14
Source File: AbstractNodeRelation.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected CollectionWithPagingInfo<Node> listNodeChildAssocs(List<ChildAssociationRef> childAssocRefs, Parameters parameters, Boolean isPrimary, boolean returnChild)
{
    Map<QName, String> qnameMap = new HashMap<>(3);

    Map<String, UserInfo> mapUserInfo = new HashMap<>(10);

    List<String> includeParam = parameters.getInclude();

    List<Node> collection = new ArrayList<Node>(childAssocRefs.size());
    for (ChildAssociationRef childAssocRef : childAssocRefs)
    {
        if (isPrimary == null || (isPrimary == childAssocRef.isPrimary()))
        {
            // minimal info by default (unless "include"d otherwise)
            NodeRef nodeRef = (returnChild ? childAssocRef.getChildRef() : childAssocRef.getParentRef());

            Node node = nodes.getFolderOrDocument(nodeRef, null, null, includeParam, mapUserInfo);

            QName assocTypeQName = childAssocRef.getTypeQName();

            if (!EXCLUDED_NS.contains(assocTypeQName.getNamespaceURI()))
            {
                String assocType = qnameMap.get(assocTypeQName);
                if (assocType == null)
                {
                    assocType = assocTypeQName.toPrefixString(namespaceService);
                    qnameMap.put(assocTypeQName, assocType);
                }

                node.setAssociation(new AssocChild(assocType, childAssocRef.isPrimary()));
                
                collection.add(node);
            }
        }
    }
    
    return listPage(collection, parameters.getPaging());
}
 
Example 15
Source File: TaggingServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void onMoveNode(ChildAssociationRef oldChildAssocRef, ChildAssociationRef newChildAssocRef)
{
    NodeRef oldRef = oldChildAssocRef.getChildRef();
    NodeRef oldParent = oldChildAssocRef.getParentRef();
    NodeRef newRef = newChildAssocRef.getChildRef();
    NodeRef newParent = newChildAssocRef.getParentRef();
    
    // Do nothing if it's a "rename" not a move
    if (oldParent.equals(newParent))
    {
        return;
    }
    
    // It has moved somewhere
    // Remove the tags from the old location
    if (this.nodeService.hasAspect(oldRef, ContentModel.ASPECT_TAGGABLE))
    {
        // Use the parent we were passed in, rather than re-fetching
        // via the node, as we need to reference the old scope!
        ChildAssociationRef scopeParent;
        if (oldChildAssocRef.isPrimary())
        {
            scopeParent = oldChildAssocRef;
        }
        else
        {
            scopeParent = this.nodeService.getPrimaryParent(oldParent);
        }
        if (scopeParent != null)
        {
            updateAllScopeTags(oldRef, scopeParent.getParentRef(), Boolean.FALSE);
        }
    }
    // Add the tags at its new location
    if (this.nodeService.hasAspect(newRef, ContentModel.ASPECT_TAGGABLE))
    {
        updateAllScopeTags(newRef, Boolean.TRUE);
    }
}
 
Example 16
Source File: TransferManifestNodeHelper.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
* Gets the primary parent association 
* @param node the node to process
* @return the primary parent association or null if this is a root node
*/
public static ChildAssociationRef getPrimaryParentAssoc(TransferManifestNormalNode node)
{
    List<ChildAssociationRef> assocs = node.getParentAssocs();

    for(ChildAssociationRef assoc : assocs)
    {
        if(assoc.isPrimary())
        {
            return assoc;
        }
    }
    return null;
}
 
Example 17
Source File: Node2ServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Child Assocs translation for version store
 */
public List<ChildAssociationRef> getChildAssocs(NodeRef nodeRef, QNamePattern typeQNamePattern, QNamePattern qnamePattern) throws InvalidNodeRefException
{
    // Get the child assoc references from the version store
    List<ChildAssociationRef> childAssocRefs = this.dbNodeService.getChildAssocs(
            VersionUtil.convertNodeRef(nodeRef),
            typeQNamePattern, qnamePattern);
    
    List<ChildAssociationRef> result = new ArrayList<ChildAssociationRef>(childAssocRefs.size());
    
    for (ChildAssociationRef childAssocRef : childAssocRefs)
    {
        if (! childAssocRef.getTypeQName().equals(Version2Model.CHILD_QNAME_VERSIONED_ASSOCS))
        {
            // Get the child reference
            NodeRef childRef = childAssocRef.getChildRef();
            NodeRef referencedNode = (NodeRef)this.dbNodeService.getProperty(childRef, ContentModel.PROP_REFERENCE);
            
            if (this.dbNodeService.exists(referencedNode))
            {
                // Build a child assoc ref to add to the returned list
                ChildAssociationRef newChildAssocRef = new ChildAssociationRef(
                        childAssocRef.getTypeQName(),
                        childAssocRef.getParentRef(),
                        childAssocRef.getQName(),
                        referencedNode,
                        childAssocRef.isPrimary(),
                        childAssocRef.getNthSibling());
                
                result.add(newChildAssocRef);
            }
        }
    }
    
    // sort the results so that the order appears to be exactly as it was originally
    Collections.sort(result);
    
    return result;
}
 
Example 18
Source File: RepoSecondaryManifestProcessorImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void processParentChildAssociations(List<ChildAssociationRef> requiredAssocs, 
        List<ChildAssociationRef> currentAssocs, NodeRef nodeRef, boolean isParent) {
    
    if (requiredAssocs == null) {
        requiredAssocs = new ArrayList<ChildAssociationRef>();
    }
    if (currentAssocs == null) {
        currentAssocs = new ArrayList<ChildAssociationRef>();
    }
    
    List<ChildAssociationRef> assocsToAdd = new ArrayList<ChildAssociationRef>();
    List<ChildAssociationRef> assocsToRemove = new ArrayList<ChildAssociationRef>();
    
    Map<NodeRef, ChildAssociationRef> currentAssocMap = new HashMap<NodeRef, ChildAssociationRef>();
    
    for (ChildAssociationRef currentAssoc : currentAssocs) {
        if (!currentAssoc.isPrimary()) {
            NodeRef key = isParent ? currentAssoc.getChildRef() : currentAssoc.getParentRef();
            currentAssocMap.put(key, currentAssoc);
        }
    }
    
    for (ChildAssociationRef requiredAssoc : requiredAssocs)
    {
        // We skip the primary parent, since this has already been handled
        if (!requiredAssoc.isPrimary())
        {
            NodeRef otherNode = isParent ? requiredAssoc.getChildRef() : requiredAssoc.getParentRef();
            ChildAssociationRef existingAssociation = currentAssocMap.remove(otherNode);
            if (existingAssociation != null) {
                //We already have an association with the required parent. 
                //Check whether it is correct
                if (!existingAssociation.getQName().equals(requiredAssoc.getQName()) ||
                        !existingAssociation.getTypeQName().equals(requiredAssoc.getTypeQName())) {
                    //No, the existing one doesn't match the required one
                    assocsToRemove.add(existingAssociation);
                    assocsToAdd.add(requiredAssoc);
                }
            } else {
                //We don't have an existing association with this required parent
                //Check that the requiredParent exists in this repo, and record it for adding
                //if it does
                if (nodeService.exists(otherNode)) {
                    assocsToAdd.add(requiredAssoc);
                }
            }
        }
    }
    //Once we get here, any entries remaining in currentParentMap are associations that need to be deleted.
    assocsToRemove.addAll(currentAssocMap.values());
    //Deal with associations to be removed
    for (ChildAssociationRef assocToRemove : assocsToRemove) {
        nodeService.removeChildAssociation(assocToRemove);
    }
    //Deal with associations to be added
    for (ChildAssociationRef assocToAdd : assocsToAdd) {
        NodeRef parent = isParent ? nodeRef : assocToAdd.getParentRef();
        NodeRef child = isParent ? assocToAdd.getChildRef() : nodeRef;
        nodeService.addChild(parent, child, 
                assocToAdd.getTypeQName(), assocToAdd.getQName());
    }
}
 
Example 19
Source File: PersonServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * When a uid is changed we need to create an alias for the old uid so permissions are not broken. This can happen
 * when an already existing user is updated via LDAP e.g. migration to LDAP, or when a user is auto created and then
 * updated by LDAP This is probably less likely after 3.2 and sync on missing person See
 * https://issues.alfresco.com/jira/browse/ETWOTWO-389 (non-Javadoc)
 */
public void onUpdateProperties(NodeRef nodeRef, Map<QName, Serializable> before, Map<QName, Serializable> after)
{
    String uidBefore = DefaultTypeConverter.INSTANCE.convert(String.class, before.get(ContentModel.PROP_USERNAME));
    if (uidBefore == null)
    {
        // Node has just been created; nothing to do
        return;
    }
    String uidAfter = DefaultTypeConverter.INSTANCE.convert(String.class, after.get(ContentModel.PROP_USERNAME));
    if (!EqualsHelper.nullSafeEquals(uidBefore, uidAfter))
    {
        // Only allow UID update if we are in the special split processing txn or we are just changing case
        if (AlfrescoTransactionSupport.getResource(KEY_ALLOW_UID_UPDATE) != null || uidBefore.equalsIgnoreCase(uidAfter))
        {
            if (uidBefore != null)
            {
                // Fix any ACLs
                aclDao.renameAuthority(uidBefore, uidAfter);
            }
            
            // Fix primary association local name
            QName newAssocQName = getChildNameLower(uidAfter);
            ChildAssociationRef assoc = nodeService.getPrimaryParent(nodeRef);
            nodeService.moveNode(nodeRef, assoc.getParentRef(), assoc.getTypeQName(), newAssocQName);
            
            // Fix other non-case sensitive parent associations
            QName oldAssocQName = QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, uidBefore, namespacePrefixResolver);
            newAssocQName = QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, uidAfter, namespacePrefixResolver);
            for (ChildAssociationRef parent : nodeService.getParentAssocs(nodeRef))
            {
                if (!parent.isPrimary() && parent.getQName().equals(oldAssocQName))
                {
                    nodeService.removeChildAssociation(parent);
                    nodeService.addChild(parent.getParentRef(), parent.getChildRef(), parent.getTypeQName(), newAssocQName);
                }
            }
            
            // Fix cache
            // We are going to be pessimistic here.  Even though the properties have changed and
            // should always be seen correctly by other policy listeners, we are not entirely sure
            // that there won't be some sort of corruption i.e. the behaviour was pessimistic before
            // this change so I'm leaving it that way.
            removeFromCache(uidBefore, true);
        }
        else
        {
            throw new UnsupportedOperationException("The user name on a person can not be changed");
        }
    }
    
    
    if(validUserUpdateEvent(before, after))
    {
    	publishEvent("user.update", after);
    }
  
}
 
Example 20
Source File: AuthorityDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void onUpdateProperties(NodeRef nodeRef, Map<QName, Serializable> before, Map<QName, Serializable> after)
{
    boolean isAuthority = dictionaryService.isSubClass(nodeService.getType(nodeRef), ContentModel.TYPE_AUTHORITY_CONTAINER);
    QName idProp = isAuthority ? ContentModel.PROP_AUTHORITY_NAME  : ContentModel.PROP_USERNAME;
    String authBefore = DefaultTypeConverter.INSTANCE.convert(String.class, before.get(idProp));
    if (authBefore == null)
    {
        // Node has just been created; nothing to do
        return;
    }
    String authAfter = DefaultTypeConverter.INSTANCE.convert(String.class, after.get(idProp));
    if (!EqualsHelper.nullSafeEquals(authBefore, authAfter))
    {
        if (AlfrescoTransactionSupport.getResource(PersonServiceImpl.KEY_ALLOW_UID_UPDATE) != null || authBefore.equalsIgnoreCase(authAfter))
        {
            if (isAuthority)
            {
                if (authBefore != null)
                {
                    // Fix any ACLs
                    aclDao.renameAuthority(authBefore, authAfter);
                }

                // Fix primary association local name
                QName newAssocQName = QName.createQName("cm", authAfter, namespacePrefixResolver);
                ChildAssociationRef assoc = nodeService.getPrimaryParent(nodeRef);
                nodeService.moveNode(nodeRef, assoc.getParentRef(), assoc.getTypeQName(), newAssocQName);

                // Fix other non-case sensitive parent associations
                QName oldAssocQName = QName.createQName("cm", authBefore, namespacePrefixResolver);
                newAssocQName = QName.createQName("cm", authAfter, namespacePrefixResolver);
                for (ChildAssociationRef parent : nodeService.getParentAssocs(nodeRef))
                {
                    if (!parent.isPrimary() && parent.getQName().equals(oldAssocQName))
                    {
                        nodeService.removeChildAssociation(parent);
                        nodeService.addChild(parent.getParentRef(), parent.getChildRef(), parent.getTypeQName(),
                                newAssocQName);
                    }
                }
                authorityLookupCache.clear();
                authorityBridgeTableCache.refresh();
                
                // Cache is out of date
                userAuthorityCache.clear();
            }
            else
            {
                userAuthorityCache.remove(authBefore);
            }
            // Remove cache entires for the parents.  No need to lock because the data has already been updated.
            removeParentsFromChildAuthorityCache(nodeRef, false);
        }
        else
        {
            throw new UnsupportedOperationException("The name of an authority can not be changed");
        }
    }
}