Java Code Examples for org.alfresco.service.cmr.dictionary.AssociationDefinition#isChild()

The following examples show how to use org.alfresco.service.cmr.dictionary.AssociationDefinition#isChild() . 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: ChildAssociatedNodeFinder.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void init()
{
    super.init();
    // Quickly scan the supplied association types and remove any that either
    // do not exist or are not child association types.
    DictionaryService dictionaryService = serviceRegistry.getDictionaryService();
    childAssociationTypes.clear();
    for (QName associationType : suppliedAssociationTypes)
    {
        AssociationDefinition assocDef = dictionaryService.getAssociation(associationType);
        if (assocDef != null && assocDef.isChild())
        {
            childAssociationTypes.add(associationType);
        }
    }
    initialised = true;
}
 
Example 2
Source File: PeerAssociatedNodeFinder.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void init()
{
    super.init();
    DictionaryService dictionaryService = serviceRegistry.getDictionaryService();
    peerAssociationTypes.clear();
    for (QName associationType : suppliedAssociationTypes)
    {
        AssociationDefinition assocDef = dictionaryService.getAssociation(associationType);
        if (assocDef != null && !assocDef.isChild())
        {
            peerAssociationTypes.add(associationType);
        }
    }
    initialised = true;
}
 
Example 3
Source File: AssocTargetRoleIntegrityEvent.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void checkIntegrity(List<IntegrityRecord> eventResults)
{
    QName assocTypeQName = getTypeQName();
    QName assocQName = getQName();
    NodeRef sourceNodeRef = getNodeRef();
    
    // get the association def
    AssociationDefinition assocDef = getAssocDef(eventResults, assocTypeQName);
    // the association definition must exist
    if (assocDef == null)
    {
        IntegrityRecord result = new IntegrityRecord(
                "Association type does not exist: \n" +
                "   Association Type: " + assocTypeQName);
        eventResults.add(result);
        return;
    }
    
    // check that we are dealing with child associations
    if (assocQName == null)
    {
        throw new IllegalArgumentException("The association qualified name must be supplied");
    }
    if (!assocDef.isChild())
    {
        throw new UnsupportedOperationException("This operation is only relevant to child associations");
    }
    ChildAssociationDefinition childAssocDef = (ChildAssociationDefinition) assocDef;
    
    // perform required checks
    checkAssocQNameRegex(eventResults, childAssocDef, assocQName, sourceNodeRef);
}
 
Example 4
Source File: IncompleteNodeTagger.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @param nodeRef NodeRef
 * @param assocDef AssociationDefinition
 * @return boolean
 */
private boolean checkAssociation(NodeRef nodeRef, AssociationDefinition assocDef)
{
    boolean complete = true;
    
    if (assocDef.isTargetMandatory() && !assocDef.isTargetMandatoryEnforced())
    {
        int actualSize = 0;
        if (assocDef.isChild())
        {
            // check the child assocs present
            List<ChildAssociationRef> childAssocRefs = nodeService.getChildAssocs(
                    nodeRef,
                    assocDef.getName(),
                    RegexQNamePattern.MATCH_ALL);
            actualSize = childAssocRefs.size();
        }
        else
        {
            // check the target assocs present
            List<AssociationRef> targetAssocRefs = nodeService.getTargetAssocs(nodeRef, assocDef.getName());
            actualSize = targetAssocRefs.size();
        }
        if (assocDef.isTargetMandatory() && actualSize == 0)
        {
            complete = false;
        }
    }
    return complete;
}
 
Example 5
Source File: CMISMapping.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Is an association valid in CMIS? It must be a non-child relationship and
 * the source and target must both be valid CMIS types.
 * 
 * @param associationQName QName
 * @return boolean
 */
public boolean isValidCmisRelationship(QName associationQName)
{
    if (associationQName == null)
    {
        return false;
    }
    if (associationQName.equals(RELATIONSHIP_QNAME))
    {
        return true;
    }
    AssociationDefinition associationDefinition = dictionaryService.getAssociation(
            associationQName);
    if (associationDefinition == null)
    {
        return false;
    }
    if (associationDefinition.isChild())
    {
        return false;
    }
    if(!isValidCmisRelationshipEndPoint(associationDefinition.getTargetClass().getName()))
    {
        return false;
    }
    if(!isValidCmisRelationshipEndPoint(associationDefinition.getSourceClass().getName()))
    {
        return false;
    }
    return true;
}
 
Example 6
Source File: ImporterComponent.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Link an existing Node
 * 
 * @param context  node to link in
 * @return  node reference of child linked in
 */
private NodeRef linkNode(ImportNode context)
{
    ImportParent parentContext = context.getParentContext();
    NodeRef parentRef = parentContext.getParentRef();
    
    // determine the node reference to link to
    String uuid = context.getUUID();
    if (uuid == null || uuid.length() == 0)
    {
        throw new ImporterException("Node reference does not specify a reference to follow.");
    }
    NodeRef referencedRef = new NodeRef(rootRef.getStoreRef(), uuid);

    // Note: do not link references that are defined in the root of the import
    if (!parentRef.equals(getRootRef()))
    {
        // determine child assoc type
        QName assocType = getAssocType(context);
        AssociationDefinition assocDef = dictionaryService.getAssociation(assocType);
        if (assocDef.isChild())
        {
            // determine child name
            QName childQName = getChildName(context);
            if (childQName == null)
            {
                String name = (String)nodeService.getProperty(referencedRef, ContentModel.PROP_NAME);
                if (name == null || name.length() == 0)
                {
                    throw new ImporterException("Cannot determine node reference child name");
                }
                String localName = QName.createValidLocalName(name);
                childQName = QName.createQName(assocType.getNamespaceURI(), localName);
            }
        
            // create the secondary link
            nodeService.addChild(parentRef, referencedRef, assocType, childQName);
            reportNodeLinked(referencedRef, parentRef, assocType, childQName);
        }
        else
        {
            nodeService.createAssociation(parentRef, referencedRef, assocType);
            reportNodeLinked(parentRef, referencedRef, assocType, null);
        }
    }
    
    // second, perform any specified udpates to the node
    updateStrategy.importNode(context);
    return referencedRef; 
}
 
Example 7
Source File: DbNodeServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Propagate, if necessary, a <b>cm:modified</b> timestamp change to the parent of the
 * given association, along with the <b>cm:modifier</b> of who changed it.  
 * The parent node has to be <b>cm:auditable</b> and the association
 * has to be marked for propagation as well.
 * 
 * @param assocRef          the association to propagate along
 */
private void propagateTimeStamps(ChildAssociationRef assocRef)
{
    if (!enableTimestampPropagation)
    {
        return;         // Bypassed on a system-wide basis
    }
    // First check if the association type warrants propagation in the first place
    AssociationDefinition assocDef = dictionaryService.getAssociation(assocRef.getTypeQName());
    if (assocDef == null || !assocDef.isChild())
    {
        if (logger.isDebugEnabled())
        {
            logger.debug("Not propagating cm:auditable for unknown association type " + assocRef.getTypeQName());
        }
        return;
    }
    ChildAssociationDefinition childAssocDef = (ChildAssociationDefinition) assocDef;
    if (!childAssocDef.getPropagateTimestamps())
    {
        if (logger.isDebugEnabled())
        {
            logger.debug("Not propagating cm:auditable for association type " + childAssocDef.getName());
        }
        return;
    }
    
    // The dictionary says propagate.  Now get the parent node and prompt the touch.
    NodeRef parentNodeRef = assocRef.getParentRef();
    
    // Do not propagate if the cm:auditable behaviour is off
    if (!policyBehaviourFilter.isEnabled(parentNodeRef, ContentModel.ASPECT_AUDITABLE))
    {
        if (logger.isDebugEnabled())
        {
            logger.debug("Not propagating cm:auditable for non-auditable parent on " + assocRef);
        }
        return;
    }
    
    Pair<Long, NodeRef> parentNodePair = getNodePairNotNull(parentNodeRef);
    Long parentNodeId = parentNodePair.getFirst();
    
    // Get the ID of the child that triggered this update
    NodeRef childNodeRef = assocRef.getChildRef();
    Pair<Long, NodeRef> childNodePair = getNodePairNotNull(childNodeRef);
    Long childNodeId = childNodePair.getFirst();
    
    // If we have already modified a particular parent node in the current txn,
    // it is not necessary to start a new transaction to tweak the cm:modified date.
    // But if the parent node was NOT touched, then doing so in this transaction would
    // create excessive concurrency and retries; in latter case we defer to a small,
    // post-commit isolated transaction.
    if (TransactionalResourceHelper.getMap(KEY_AUDITABLE_PROPAGATION_PRE).containsKey(parentNodeId))
    {
        // It is already registered in the current transaction.
        // Modified By will be taken from the previous node to touch it
        if (logger.isDebugEnabled())
        {
            logger.debug("Update of cm:auditable already requested for " + parentNodePair);
        }
        return;
    }
    
    if (nodeDAO.isInCurrentTxn(parentNodeId))
    {
        // The parent and child are in the same transaction
        TransactionalResourceHelper.getMap(KEY_AUDITABLE_PROPAGATION_PRE).put(parentNodeId, childNodeId);
        // Make sure that it is not processed after the transaction
        TransactionalResourceHelper.getMap(KEY_AUDITABLE_PROPAGATION_POST).remove(parentNodeId);
        
        if (logger.isDebugEnabled())
        {
            logger.debug("Performing in-transaction cm:auditable update for " + parentNodePair + " from " + childNodePair);
        }
    }
    else
    {
        TransactionalResourceHelper.getMap(KEY_AUDITABLE_PROPAGATION_POST).put(parentNodeId, childNodeId);
        
        if (logger.isDebugEnabled())
        {
            logger.debug("Requesting later cm:auditable update for " + parentNodePair + " from " + childNodePair);
        }
    }
    
    // Bind a listener for post-transaction manipulation
    AlfrescoTransactionSupport.bindListener(auditableTransactionListener);
}
 
Example 8
Source File: AssocSourceMultiplicityIntegrityEvent.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Checks that the source multiplicity has not been violated for the
 * target of the association.
 */
protected void checkSourceMultiplicity(
        List<IntegrityRecord> eventResults,
        AssociationDefinition assocDef,
        QName assocTypeQName,
        NodeRef targetNodeRef)
{
    // get the source multiplicity
    boolean mandatory = assocDef.isSourceMandatory();
    boolean allowMany = assocDef.isSourceMany();
    // do we need to check
    if (!mandatory && allowMany)
    {
        // it is not mandatory and it allows many on both sides of the assoc
        return;
    }
    
    // check the target of the association if this is a delete
    if (isDelete)
    {
        // get the class the association is defined for and see if it is an aspect
        ClassDefinition classDef = assocDef.getTargetClass(); 
        if (classDef.isAspect())
        {
            // see if the target node has the aspect applied, if it does not
            // there's no need to check multiplicity
            if (!this.nodeService.hasAspect(targetNodeRef, classDef.getName()))
            {
                return;
            }
        }
    }
    
    int actualSize = 0;
    if (assocDef.isChild())
    {
        // check the parent assocs present
        List<ChildAssociationRef> parentAssocRefs = nodeService.getParentAssocs(
                targetNodeRef,
                assocTypeQName,
                RegexQNamePattern.MATCH_ALL);
        actualSize = parentAssocRefs.size();
    }
    else
    {
        // check the source assocs present
        List<AssociationRef> sourceAssocRefs = nodeService.getSourceAssocs(targetNodeRef, assocTypeQName);
        actualSize = sourceAssocRefs.size();
    }
    
    if ((mandatory && actualSize == 0) || (!allowMany && actualSize > 1))
    {
        if (actualSize == 0)
        {
            // ALF-9591: Integrity check: Association source multiplicity checking is incorrect
            //           At this point, there is no point worrying.  There are no more associations
            //           pointing *to* this node and therefore the checking of the source
            //           multiplicity (a feature of the source type/aspect) is not relevant
            return;
        }
        
        String parentOrSourceStr = (assocDef.isChild() ? "parent" : "source");
        IntegrityRecord result = new IntegrityRecord(
                "The association " + parentOrSourceStr + " multiplicity has been violated: \n" +
                "   Target Node: " + targetNodeRef + "\n" +
                "   Association: " + assocDef + "\n" +
                "   Required " + parentOrSourceStr + " Multiplicity: " + getMultiplicityString(mandatory, allowMany) + "\n" +
                "   Actual " + parentOrSourceStr + " Multiplicity: " + actualSize);
        eventResults.add(result);
    }
}
 
Example 9
Source File: ChildAssocEntity.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Apply the <b>cm:name</b> to the child association. If the child name is <tt>null</tt> then a GUID is generated as
 * a substitute.
 * <p>
 * Unknown associations or associations that do not require unique name checking will use a GUID for the child
 * name and the CRC value used <b>will be negative</b>.
 * 
 * @param childName the <b>cm:name</b> applying to the association.
 */
public static Pair<String, Long> getChildNameUnique(
        DictionaryService dictionaryService,
        QName assocTypeQName,
        String childName)
{
    if (childName == null)
    {
        throw new IllegalArgumentException("Child name may not be null.  Use the Node ID ...");
    }
    
    String childNameNewShort; // 
    long childNameNewCrc = -1L; // By default, they don't compete

    AssociationDefinition assocDef = dictionaryService.getAssociation(assocTypeQName);
    if (assocDef == null || !assocDef.isChild())
    {
        if (logger.isWarnEnabled())
        {
            logger.warn("No child association of this type could be found: " + assocTypeQName);
        }
        childNameNewShort = GUID.generate();
        childNameNewCrc = -1L * getChildNodeNameCrc(childNameNewShort);
    }
    else
    {
        ChildAssociationDefinition childAssocDef = (ChildAssociationDefinition) assocDef;
        if (childAssocDef.getDuplicateChildNamesAllowed())
        {
            childNameNewShort = GUID.generate();
            childNameNewCrc = -1L * getChildNodeNameCrc(childNameNewShort);
        }
        else
        {
            String childNameNewLower = childName.toLowerCase();
            childNameNewShort = getChildNodeNameShort(childNameNewLower);
            childNameNewCrc = getChildNodeNameCrc(childNameNewLower);
        }
    }
    return new Pair<String, Long>(childNameNewShort, childNameNewCrc);
}
 
Example 10
Source File: AbstractAssociationsGet.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Override  method from DeclarativeWebScript
 */
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
    String associationFilter = req.getParameter(REQ_URL_TEMPL_VAR_ASSOCIATION_FILTER);
    String namespacePrefix = req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX);
    String name = req.getParameter(REQ_URL_TEMPL_VAR_NAME);
	
    Map<String, Object> model = new HashMap<String, Object>();
    Map<QName, AssociationDefinition> assocdef = new HashMap<QName, AssociationDefinition>();
    QName associationQname = null;
    QName classQname = getClassQname(req);
   
    if(associationFilter == null)
    {
    	associationFilter = "all";
    }
    
    //validate association filter
    if(isValidAssociationFilter(associationFilter) == false)
    {
    	throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the associationFilter - " + associationFilter + " - parameter in the URL");
    }
    
    // validate  for the presence of both name and namespaceprefix 
    if((name == null && namespacePrefix != null) || 
       (name != null && namespacePrefix == null))
    {
    	throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing either name or namespaceprefix parameter in the URL - both combination of name and namespaceprefix is needed");
    }
    
    // check for association filters
    if(associationFilter.equals("child"))
	{
		model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, this.dictionaryservice.getClass(classQname).getChildAssociations().values());
	}
    else if(associationFilter.equals("general"))
	{
		for(AssociationDefinition assocname:this.dictionaryservice.getClass(classQname).getAssociations().values())
     {
			if(assocname.isChild() == false)
			{
				assocdef.put(assocname.getName(), assocname);
			}
     }
		model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, assocdef.values());
	}
    else if(associationFilter.equals("all"))
	{
		model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, this.dictionaryservice.getClass(classQname).getAssociations().values());
    }

    // if both namespaceprefix and name parameters are given then, the combination namespaceprefix_name is used as the index to create the qname
    if(name != null && namespacePrefix != null)
    {        	
    	// validate the class combination namespaceprefix_name
    	associationQname = getAssociationQname(namespacePrefix, name);
    	
    	if(this.dictionaryservice.getClass(classQname).getAssociations().get(associationQname)== null)
    	{
    		throw new WebScriptException(Status.STATUS_NOT_FOUND, "not a Valid - namespaceprefix_name combination");
    	}
    	
    	model.put(MODEL_PROP_KEY_INDIVIDUAL_PROPERTY_DEFS, this.dictionaryservice.getClass(classQname).getAssociations().get(associationQname));
    }

    model.put(MODEL_PROP_KEY_MESSAGE_LOOKUP, this.dictionaryservice);
    
    return model;
}