Java Code Examples for org.alfresco.service.namespace.QName#equals()

The following examples show how to use org.alfresco.service.namespace.QName#equals() . 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: ExporterComponent.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Is the aspect unexportable?
 * 
 * @param aspectQName           the aspect name
 * @return                      <tt>true</tt> if the aspect can't be exported
 */
private boolean isExcludedAspect(QName[] excludeAspects, QName aspectQName)
{
    if (aspectQName.equals(ContentModel.ASPECT_MULTILINGUAL_DOCUMENT) ||
            aspectQName.equals(ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION))
    {
        return true;
    }
    else
    {
        for (QName excludeAspect : excludeAspects)
        {
            if (aspectQName.equals(excludeAspect))
            {
                return true;
            }
        }
    }
    return false;
}
 
Example 2
Source File: PolicyScope.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Add an association
 * 
 * @param classRef QName
 * @param nodeAssocRef AssociationRef
 */
public void addAssociation(QName classRef, AssociationRef nodeAssocRef)
{
	if (classRef.equals(this.classRef) == true)
	{
		addAssociation(nodeAssocRef);
	}
	else
	{
		AspectDetails aspectDetails = this.aspectCopyDetails.get(classRef);
		if (aspectDetails == null)
		{
			// Add the aspect
			aspectDetails = addAspect(classRef);
		}
		aspectDetails.addAssociation(nodeAssocRef);
	}
}
 
Example 3
Source File: DBQuery.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @param propertyQName QName
 * @return DBQueryBuilderJoinCommandType
 */
public static DBQueryBuilderJoinCommandType getJoinCommandType(QName propertyQName)
{
    if(propertyQName.equals(ContentModel.PROP_CREATED)
            || propertyQName.equals(ContentModel.PROP_CREATOR) || propertyQName.equals(ContentModel.PROP_MODIFIED) || propertyQName.equals(ContentModel.PROP_MODIFIER))
    {
        return DBQueryBuilderJoinCommandType.NODE;
    }
    else if(propertyQName.toString().endsWith(".mimetype"))
    {
        return DBQueryBuilderJoinCommandType.CONTENT_MIMETYPE;
    }
    else if(propertyQName.toString().endsWith(".size"))
    {
        return DBQueryBuilderJoinCommandType.CONTENT_URL;
    }
    else
    {
        return DBQueryBuilderJoinCommandType.PROPERTY;
    }
}
 
Example 4
Source File: OwnableServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Don't copy certain auditable p
 */
@Override
public Map<QName, Serializable> getCopyProperties(
        QName classQName, CopyDetails copyDetails, Map<QName, Serializable> properties)
{
    if(classQName.equals(ContentModel.ASPECT_OWNABLE))
    {
        // The owner should become the user doing the copying
        if(properties.containsKey(ContentModel.PROP_OWNER))
        {
            properties.put(ContentModel.PROP_OWNER, AuthenticationUtil.getFullyAuthenticatedUser());
        }
    }
    else if(classQName.equals(ContentModel.ASPECT_AUDITABLE))
    {
        // Have the key properties reset by the aspect
        properties.remove(ContentModel.PROP_CREATED);
        properties.remove(ContentModel.PROP_CREATOR);
        properties.remove(ContentModel.PROP_MODIFIED);
        properties.remove(ContentModel.PROP_MODIFIER);
    }
    
    return properties;
}
 
Example 5
Source File: PolicyScope.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Removes a property from the list
 * 
 * @param classRef	the class reference
 * @param qName		the qualified name
 */
public void removeProperty(QName classRef, QName qName) 
{
	if (classRef.equals(this.classRef) == true)
	{
		removeProperty(qName);
	}
	else
	{
		AspectDetails aspectDetails = this.aspectCopyDetails.get(classRef);
		if (aspectDetails != null)
		{
			aspectDetails.removeProperty(qName);
		}				
	}
}
 
Example 6
Source File: RenditionNodeManager.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * This method copies properties from the temporary rendition node onto the targetNode. It also sets the node type.
 * {@link #unchangedProperties Some properties} are not copied.
 * @param finalRenditionAssoc ChildAssociationRef
 */
private void transferNodeProperties(ChildAssociationRef finalRenditionAssoc)
{
    NodeRef targetNode = finalRenditionAssoc.getChildRef();
    if (logger.isDebugEnabled())
    {
        StringBuilder msg = new StringBuilder();
        msg.append("Transferring some properties from ").append(tempRenditionNode).append(" to ").append(targetNode);
        logger.debug(msg.toString());
    }

    // Copy the type from the temporary rendition to the real rendition, if required
    QName type = nodeService.getType(tempRenditionNode);
    if ((null != type) && !type.equals(nodeService.getType(targetNode)))
    {
        nodeService.setType(targetNode, type);
    }
    
    // Copy over all regular properties from the temporary rendition
    Map<QName, Serializable> newProps = nodeService.getProperties(targetNode);
    for(Entry<QName,Serializable> entry : nodeService.getProperties(tempRenditionNode).entrySet())
    {
        QName propKey = entry.getKey();
        if(unchangedProperties.contains(propKey) ||
           NamespaceService.SYSTEM_MODEL_1_0_URI.equals(propKey.getNamespaceURI()))
        {
            // These shouldn't be copied over
            continue;
        }
        newProps.put(propKey, entry.getValue());
    }
    nodeService.setProperties(targetNode, newProps);
}
 
Example 7
Source File: AbstractQNameDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Pair<Long, QName> updateQName(QName qnameOld, QName qnameNew)
{
    if (qnameOld == null|| qnameNew == null)
    {
        throw new IllegalArgumentException("QName cannot be null");
    }
    if (qnameOld.equals(qnameNew))
    {
        throw new IllegalArgumentException("Cannot update QNames: they are the same");
    }
    // See if the old QName exists
    Pair<Long, QName> qnameOldPair = qnameCache.getByValue(qnameOld);
    if (qnameOldPair == null)
    {
        throw new IllegalArgumentException("Cannot rename QName.  QName " + qnameOld + " does not exist");
    }
    // See if the new QName exists
    if (qnameCache.getByValue(qnameNew) != null)
    {
        throw new IllegalArgumentException("Cannot rename QName.  QName " + qnameNew + " already exists");
    }
    // Update
    Long qnameId = qnameOldPair.getFirst();
    int updated = qnameCache.updateValue(qnameId, qnameNew);
    if (updated != 1)
    {
        throw new ConcurrencyFailureException("Failed to update QName entity " + qnameId);
    }
    return new Pair<Long, QName>(qnameId, qnameNew);
}
 
Example 8
Source File: IncompleteNodeTagger.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Recheck the node as an aspect was removed.
 */
public void onRemoveAspect(NodeRef nodeRef, QName aspectTypeQName)
{
    if (! storesToIgnore.contains(nodeRef.getStoreRef().toString()))
    {
        if (aspectTypeQName.equals(ContentModel.ASPECT_INCOMPLETE))
        {
            if (logger.isDebugEnabled())
            {
                logger.debug("Ignoring aspect removal: " + ContentModel.ASPECT_INCOMPLETE);
            }
        }
        save(nodeRef);
    }
}
 
Example 9
Source File: CommentDelete.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * deletes comment node
 * 
 * @param commentNodeRef
 */
private void deleteComment(NodeRef commentNodeRef)
{
    QName nodeType = nodeService.getType(commentNodeRef);
    if (!nodeType.equals(ForumModel.TYPE_POST))
    {
        throw new IllegalArgumentException("Node to delete is not a comment node.");
    }

    nodeService.deleteNode(commentNodeRef);
}
 
Example 10
Source File: CMISMapping.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Is this a valid CMIS folder type?
 * 
 * @param typeQName QName
 * @return boolean
 */
public boolean isValidCmisFolder(QName typeQName)
{
	if(isExcluded(typeQName))
	{
        return false;
    }
    
    if (typeQName == null)
    {
        return false;
    }
    if (typeQName.equals(FOLDER_QNAME))
    {
        return true;
    }

    if (dictionaryService.isSubClass(typeQName, ContentModel.TYPE_FOLDER))
    {
        if (typeQName.equals(ContentModel.TYPE_FOLDER))
        {
            return false;
        } else
        {
            return true;
        }
    }

    return false;
}
 
Example 11
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 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;
}
 
Example 12
Source File: ImporterComponent.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public boolean isExcludedClass(QName className)
{
    for (QName excludedClass : excludedClasses)
    {
        if (excludedClass.equals(className))
        {
            return true;
        }
    }
    return false;
}
 
Example 13
Source File: PersonServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void deletePerson(NodeRef personRef)
{
    QName typeQName = nodeService.getType(personRef);
    if (typeQName.equals(ContentModel.TYPE_PERSON))
    {
        String userName = (String) this.nodeService.getProperty(personRef, ContentModel.PROP_USERNAME);
        deletePersonAndAuthenticationImpl(userName, personRef);  
    }
    else
    {
        throw new AlfrescoRuntimeException("deletePerson: invalid type of node "+personRef+" (actual="+typeQName+", expected="+ContentModel.TYPE_PERSON+")");
    }
}
 
Example 14
Source File: WorkingCopyAspect.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Disallows copying of the {@link ContentModel#ASPECT_WORKING_COPY <b>cm:workingCopy</b>} aspect.
 */
@Override
public boolean getMustCopy(QName classQName, CopyDetails copyDetails)
{
    if (classQName.equals(ContentModel.ASPECT_WORKING_COPY))
    {
        return false;
    }
    else
    {
        return true;
    }
}
 
Example 15
Source File: AliasableAspectCopyBehaviourCallback.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Disallows copying of the {@link EmailServerModel#ASPECT_ALIASABLE} aspect.
 */
@Override
public boolean getMustCopy(QName classQName, CopyDetails copyDetails)
{
    if (classQName.equals(EmailServerModel.ASPECT_ALIASABLE))
    {
        return false;
    }
    else
    {
        return true;
    }
}
 
Example 16
Source File: OnPropertyUpdateRuleTrigger.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
private boolean havePropertiesBeenModified(NodeRef nodeRef, Map<QName, Serializable> before, Map<QName, Serializable> after, boolean newNode, boolean newContentOnly)
{
    if (newContentOnly && nodeService.hasAspect(nodeRef, ContentModel.ASPECT_NO_CONTENT))
    {
        return false;
    }        

    Set<QName> keys = new HashSet<QName>(after.keySet());
    keys.addAll(before.keySet());

    // Compare all properties, ignoring protected properties and giving special treatment to content properties
    boolean nonNullContentProperties = false;
    boolean newContentProperties = false;
    boolean nonNewModifiedContentProperties = false;
    boolean modifiedNonContentProperties = false;
    for (QName name : keys)
    {
        // Skip rule firing on this content property for performance reasons
        if (name.equals(ContentModel.PROP_PREFERENCE_VALUES))
        {
            continue;
        }
        Serializable beforeValue = before.get(name);
        Serializable afterValue = after.get(name);
        PropertyDefinition propertyDefinition = this.dictionaryService.getProperty(name);
        if (propertyDefinition == null)
        {
            if (!EqualsHelper.nullSafeEquals(beforeValue, afterValue))
            {
                modifiedNonContentProperties = true;
            }
        }
        // Ignore protected properties
        else if (!propertyDefinition.isProtected())
        {
            if (propertyDefinition.getDataType().getName().equals(DataTypeDefinition.CONTENT)
                    && !propertyDefinition.isMultiValued())
            {
                // Remember whether the property was populated, regardless of the ignore setting
                if (afterValue != null)
                {
                    nonNullContentProperties = true;
                }                    
                if (this.ignoreEmptyContent)
                {
                    ContentData beforeContent = toContentData(before.get(name));
                    ContentData afterContent = toContentData(after.get(name));
                    if (!ContentData.hasContent(beforeContent) || beforeContent.getSize() == 0)
                    {
                        beforeValue = null;
                    }
                    if (!ContentData.hasContent(afterContent) || afterContent.getSize() == 0)
                    {
                        afterValue = null;
                    }
                }
                if (newNode)
                {
                    if (afterValue != null)
                    {
                        newContentProperties = true;
                    }
                }
                else if (!EqualsHelper.nullSafeEquals(beforeValue, afterValue))
                {
                    if (beforeValue == null)
                    {
                        newContentProperties = true;                            
                    }
                    else
                    {
                        nonNewModifiedContentProperties = true;                            
                    }
                }
            }
            else if (!EqualsHelper.nullSafeEquals(beforeValue, afterValue))
            {
                modifiedNonContentProperties = true;
            }
        }
    }

    if (newContentOnly)
    {
        return (newNode && !nonNullContentProperties ) || newContentProperties;
    }
    else
    {
        return modifiedNonContentProperties || nonNewModifiedContentProperties;
    }
}
 
Example 17
Source File: JobLockServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void getTransactionalLock(QName lockQName, long timeToLive, long retryWait, int retryCount)
{
    // Check that transaction is present
    final String txnId = AlfrescoTransactionSupport.getTransactionId();
    if (txnId == null)
    {
        throw new IllegalStateException("Locking requires an active transaction");
    }
    // Get the set of currently-held locks
    TreeSet<QName> heldLocks = TransactionalResourceHelper.getTreeSet(KEY_RESOURCE_LOCKS);
    // We don't want the lock registered as being held if something goes wrong
    TreeSet<QName> heldLocksTemp = new TreeSet<QName>(heldLocks);
    boolean added = heldLocksTemp.add(lockQName);
    if (!added)
    {
        // It's a refresh.  Ordering is not important here as we already hold the lock.
        refreshLock(txnId, lockQName, timeToLive);
    }
    else
    {
        QName lastLock = heldLocksTemp.last();
        if (lastLock.equals(lockQName))
        {
            if (logger.isDebugEnabled())
            {
                logger.debug(
                        "Attempting to acquire ordered lock: \n" +
                        "   Lock:     " + lockQName + "\n" +
                        "   TTL:      " + timeToLive + "\n" +
                        "   Txn:      " + txnId);
            }
            // If it was last in the set, then the order is correct and we use the
            // full retry behaviour.
            getLockImpl(txnId, lockQName, timeToLive, retryWait, retryCount);
        }
        else
        {
            if (logger.isDebugEnabled())
            {
                logger.debug(
                        "Attempting to acquire UNORDERED lock: \n" +
                        "   Lock:     " + lockQName + "\n" +
                        "   TTL:      " + timeToLive + "\n" +
                        "   Txn:      " + txnId);
            }
            // The lock request is made out of natural order.
            // Unordered locks do not get any retry behaviour
            getLockImpl(txnId, lockQName, timeToLive, retryWait, 1);
        }
    }
    // It went in, so add it to the transactionally-stored set
    heldLocks.add(lockQName);
    // Done
}
 
Example 18
Source File: PersonServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Set<NodeRef> getPeopleFilteredByProperty(QName propertyKey, Serializable propertyValue, int count)
{
    if (count > 1000)
    {
        throw new IllegalArgumentException("Only 1000 results are allowed but got a request for " + count + ". Use getPeople.");
    }
    
    // check that given property key is defined for content model type 'cm:person'
    // and throw exception if it isn't
    if (this.dictionaryService.getProperty(ContentModel.TYPE_PERSON, propertyKey) == null)
    {
        throw new AlfrescoRuntimeException("Property '" + propertyKey + "' is not defined " + "for content model type cm:person");
    }
    if (!propertyKey.equals(ContentModel.PROP_FIRSTNAME) &&
        !propertyKey.equals(ContentModel.PROP_LASTNAME) &&
        !propertyKey.equals(ContentModel.PROP_USERNAME))
    {
        logger.warn("PersonService.getPeopleFilteredByProperty() is being called to find people by "+propertyKey+
                ". Only PROP_FIRSTNAME, PROP_LASTNAME, PROP_USERNAME are now used in the search, so fewer nodes may " +
                "be returned than expected of there are more than "+count+" users in total.");
    }
    
    List<Pair<QName, String>> filterProps = new ArrayList<Pair<QName, String>>(1);
    filterProps.add(new Pair<QName, String>(propertyKey, (String)propertyValue));
    
    PagingRequest pagingRequest = new PagingRequest(count, null);
    List<PersonInfo> personInfos = getPeople(filterProps, true, null, pagingRequest).getPage();
    
    Set<NodeRef> refs = new HashSet<NodeRef>(personInfos.size());
    for (PersonInfo personInfo : personInfos)
    {
        NodeRef nodeRef = personInfo.getNodeRef();
        String value = (String) this.nodeService.getProperty(nodeRef, propertyKey);
        if (EqualsHelper.nullSafeEquals(value, propertyValue))
        {
            refs.add(nodeRef);
        }
    }
    
    return refs;
}
 
Example 19
Source File: ImporterComponent.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Get the child name to import node under
 * 
 * @param context  the node
 * @return  the child name
 */
private QName getChildName(ImportNode context)
{
    QName assocType = getAssocType(context);
    QName childQName = null;
    
    // Determine child name
    String childName = context.getChildName();
    if (childName != null)
    {
        childName = bindPlaceHolder(childName, binding);
        // <Fix for ETHREEOH-2299>
        if (ContentModel.TYPE_PERSON.equals(context.getTypeDefinition().getName())
                && assocType.equals(ContentModel.ASSOC_CHILDREN))
        {
            childName = childName.toLowerCase();
        }
        // </Fix for ETHREEOH-2299>
        String[] qnameComponents = QName.splitPrefixedQName(childName);
        childQName = QName.createQName(qnameComponents[0], QName.createValidLocalName(qnameComponents[1]), namespaceService); 
    }
    else
    {
        Map<QName, Serializable> typeProperties = context.getProperties();
        
        Serializable nameValue = typeProperties.get(ContentModel.PROP_NAME);

        if(nameValue != null && !String.class.isAssignableFrom(nameValue.getClass()))
        {
            throw new  ImporterException("Unable to use childName property: "+ ContentModel.PROP_NAME + " is not a string");  
        }
        
        String name = (String)nameValue;
        
        if (name != null && name.length() > 0)
        {
            name = bindPlaceHolder(name, binding);
            String localName = QName.createValidLocalName(name);
            childQName = QName.createQName(assocType.getNamespaceURI(), localName);
        }
    }
    
    return childQName;
}
 
Example 20
Source File: UserUsageTrackingComponent.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
private boolean collapseUsage(final NodeRef usageNodeRef)
{
    RetryingTransactionCallback<Boolean> collapseUsages = new RetryingTransactionCallback<Boolean>()
    {
        public Boolean execute() throws Throwable
        {
            if (!nodeService.exists(usageNodeRef))
            {
                // Ignore
                return false;
            }
            QName nodeType = nodeService.getType(usageNodeRef);
            
            if (nodeType.equals(ContentModel.TYPE_PERSON))
            {
                NodeRef personNodeRef = usageNodeRef;
                String userName = (String)nodeService.getProperty(personNodeRef, ContentModel.PROP_USERNAME);
                
                long currentUsage = contentUsageImpl.getUserStoredUsage(personNodeRef);
                if (currentUsage != -1)
                {
                    // Collapse the usage deltas
                    // Calculate and remove deltas in one go to guard against deletion of
                    // deltas from another transaction that have not been included in the
                    // calculation
                    currentUsage = contentUsageImpl.getUserUsage(personNodeRef, true);
                    contentUsageImpl.setUserStoredUsage(personNodeRef, currentUsage);
                    
                    if (logger.isTraceEnabled()) 
                    {
                        logger.trace("Collapsed usage: username=" + userName + ", usage=" + currentUsage);
                    }
                }
                else
                {
                    if (logger.isWarnEnabled())
                    {
                        logger.warn("Initial usage for user has not yet been calculated: " + userName);
                    }
                }
            }
            return true;
        }
    };
    
    // execute in READ-WRITE txn
    return transactionService.getRetryingTransactionHelper().doInTransaction(collapseUsages, false);
}