Java Code Examples for org.alfresco.util.EqualsHelper#nullSafeEquals()

The following examples show how to use org.alfresco.util.EqualsHelper#nullSafeEquals() . 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: TransactionalCache.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public boolean equals(Object obj)
{
    if (obj == this)
    {
        return true;
    }
    if (obj == null)
    {
        return false;
    }
    if (!(obj instanceof TransactionalCache<?, ?>))
    {
        return false;
    }
    @SuppressWarnings("rawtypes")
    TransactionalCache that = (TransactionalCache) obj;
    return EqualsHelper.nullSafeEquals(this.name, that.name);
}
 
Example 2
Source File: NodePropertyKey.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public boolean equals(Object obj)
{
    if (this == obj)
    {
        return true;
    }
    else if (!(obj instanceof NodePropertyKey))
    {
        return false;
    }
    // Compare in order of selectivity
    NodePropertyKey that = (NodePropertyKey) obj;
    return (EqualsHelper.nullSafeEquals(this.qnameId, that.qnameId) &&
            EqualsHelper.nullSafeEquals(this.listIndex, that.listIndex) &&
            EqualsHelper.nullSafeEquals(this.localeId, that.localeId)
            );
}
 
Example 3
Source File: TenantEntity.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean equals(Object obj)
{
    if (this == obj)
    {
        return true;
    }
    else if (obj instanceof TenantEntity)
    {
        TenantEntity that = (TenantEntity)obj;
        return (EqualsHelper.nullSafeEquals(this.tenantDomain.toLowerCase(), that.tenantDomain.toLowerCase()));
    }
    else
    {
        return false;
    }
}
 
Example 4
Source File: DocumentNavigator.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public String getAttributeQName(Object o)
{
    QName qName = ((Property) o).qname;
    String escapedLocalName = ISO9075.encode(qName.getLocalName());
    if (EqualsHelper.nullSafeEquals(escapedLocalName, qName.getLocalName()))        
    {
        return qName.toString();
    }
    else
    {
        return QName.createQName(qName.getNamespaceURI(), escapedLocalName).toString();
    }
}
 
Example 5
Source File: EventGenerationBehaviours.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onContentPropertyUpdate(NodeRef nodeRef, QName propertyQName, ContentData beforeValue, ContentData afterValue)
{
    boolean hasContentBefore = ContentData.hasContent(beforeValue) && beforeValue.getSize() > 0;
    boolean hasContentAfter = ContentData.hasContent(afterValue) && afterValue.getSize() > 0;
    
    // There are some shortcuts here
    if (!hasContentBefore && !hasContentAfter)
    {
        // Really, nothing happened
        return;
    }
    else if (EqualsHelper.nullSafeEquals(beforeValue, afterValue))
    {
        // Still, nothing happening
        return;
    }

    eventsService.contentWrite(nodeRef, propertyQName, afterValue);
}
 
Example 6
Source File: AbstractPropertyValueDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean equals(Object obj)
{
    if (this == obj)
    {
        return true;
    }
    else if (!(obj instanceof CachePucKey))
    {
        return false;
    }
    CachePucKey that = (CachePucKey) obj;
    return EqualsHelper.nullSafeEquals(this.key1, that.key1) && 
           EqualsHelper.nullSafeEquals(this.key2, that.key2) &&
           EqualsHelper.nullSafeEquals(this.key3, that.key3);
}
 
Example 7
Source File: PropertyStringValueEntity.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean equals(Object obj)
{
    if (this == obj)
    {
        return true;
    }
    else if (obj != null && obj instanceof PropertyStringValueEntity)
    {
        PropertyStringValueEntity that = (PropertyStringValueEntity) obj;
        return EqualsHelper.nullSafeEquals(this.stringValue, that.stringValue);
    }
    else
    {
        return false;
    }
}
 
Example 8
Source File: LocaleEntity.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean equals(Object obj)
{
    if (obj == null)
    {
        return false;
    }
    else if (obj == this)
    {
        return true;
    }
    else if (!(obj instanceof LocaleEntity))
    {
        return false;
    }
    LocaleEntity that = (LocaleEntity) obj;
    return EqualsHelper.nullSafeEquals(this.localeStr, that.localeStr);
}
 
Example 9
Source File: SelectorPropertyContentStore.java    From alfresco-simple-content-stores with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void onUpdateProperties(final NodeRef nodeRef, final Map<QName, Serializable> before, final Map<QName, Serializable> after)
{
    // don't handle creations - here we can actually properly and efficiently eliminate the scenario (other than during onAddAspect)
    if (!before.isEmpty())
    {
        LOGGER.debug("Processing onUpdateProperties for {}", nodeRef);

        final Serializable selectorValueBefore = before.get(this.selectorPropertyQName);
        final Serializable selectorValueAfter = after.get(this.selectorPropertyQName);

        if (!EqualsHelper.nullSafeEquals(selectorValueBefore, selectorValueAfter))
        {
            LOGGER.debug("Selector property value changed from {} to {} for {}", selectorValueBefore, selectorValueAfter, nodeRef);
            this.checkAndProcessContentPropertiesMove(nodeRef, this.moveStoresOnChange, this.moveStoresOnChangeOptionPropertyQName,
                    selectorValueAfter);
        }
        else
        {
            LOGGER.debug("No change in selector property value found for {}", nodeRef);
        }
    }
}
 
Example 10
Source File: AbstractIntegrityEvent.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Compares based on the class of this instance and the incoming instance, before
 * comparing based on all the internal data.  If derived classes store additional
 * data for their functionality, then they should override this.
 */
@Override
public boolean equals(Object obj)
{
    if (obj == null)
        return false;
    else if (this == obj)
        return true;
    else if (this.getClass() != obj.getClass())
        return false;
    // we can safely cast
    AbstractIntegrityEvent that = (AbstractIntegrityEvent) obj;
    return
            EqualsHelper.nullSafeEquals(this.nodeRef, that.nodeRef) &&
            EqualsHelper.nullSafeEquals(this.typeQName, that.typeQName) &&
            EqualsHelper.nullSafeEquals(this.qname, that.qname);
}
 
Example 11
Source File: TransformerDebug.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean equals(Object obj)
{
    if (this == obj)
    {
        return true;
    }
    else if (obj instanceof UnavailableTransformer)
    {
        UnavailableTransformer that = (UnavailableTransformer) obj;
        return
            EqualsHelper.nullSafeEquals(name, that.name) &&
            maxSourceSizeKBytes == that.maxSourceSizeKBytes;
    }
    else
    {
        return false;
    }
}
 
Example 12
Source File: RepositoryAuthenticationDao.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
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));
    String uidAfter = DefaultTypeConverter.INSTANCE.convert(String.class, after.get(ContentModel.PROP_USERNAME));
    if (uidBefore != null && !EqualsHelper.nullSafeEquals(uidBefore, uidAfter))
    {
        NodeRef userNode = getUserOrNull(uidBefore);
        if (userNode != null)
        {
            nodeService.setProperty(userNode, ContentModel.PROP_USER_USERNAME, uidAfter);
            nodeService.moveNode(userNode, nodeService.getPrimaryParent(userNode).getParentRef(),
                    ContentModel.ASSOC_CHILDREN, QName.createQName(ContentModel.USER_MODEL_URI, uidAfter));
            removeAuthenticationFromCache(uidBefore);
        }
    }
    removeAuthenticationFromCache(uidAfter);
}
 
Example 13
Source File: TransformationOptionLimits.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean equals(Object obj)
{
    if (this == obj)
    {
        return true;
    }
    else if (obj instanceof TransformationOptionLimits)
    {
        TransformationOptionLimits that = (TransformationOptionLimits) obj;
        return
            EqualsHelper.nullSafeEquals(time, that.time) &&
            EqualsHelper.nullSafeEquals(kbytes, that.kbytes) &&
            EqualsHelper.nullSafeEquals(pages, that.pages);
    }
    else
    {
        return false;
    }
}
 
Example 14
Source File: EntityLookupCacheTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Pair<Long, Object> findByValue(Object value)
{
    assertTrue(value == null || value instanceof TestValue);
    String dbValue = (value == null) ? null : ((TestValue)value).val;

    for (Map.Entry<Long, String> entry : database.entrySet())
    {
        if (EqualsHelper.nullSafeEquals(entry.getValue(), dbValue))
        {
            return new Pair<Long, Object>(entry.getKey(), entry.getValue());
        }
    }
    return null;
}
 
Example 15
Source File: FixedValueLuceneBuilder.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public <Q, S, E extends Throwable> Q buildLuceneInequality(LuceneQueryParserAdaptor<Q, S, E> lqpa, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws E
{
    if (!EqualsHelper.nullSafeEquals(value, value))
    {
        return lqpa.getMatchAllQuery();
    }
    else
    {
        return lqpa.getMatchNoneQuery();
    }
}
 
Example 16
Source File: OngoingAsyncAction.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean equals(Object otherObj)
{
    if (otherObj == null || !otherObj.getClass().equals(this.getClass()))
    {
        return false;
    }
    OngoingAsyncAction otherNodeBeingActioned = (OngoingAsyncAction)otherObj;
    
    return EqualsHelper.nullSafeEquals(this.node, otherNodeBeingActioned.node) &&
        EqualsHelper.nullSafeEquals(this.action.getActionDefinitionName(), otherNodeBeingActioned.action.getActionDefinitionName());
}
 
Example 17
Source File: PersonServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
private boolean isSystemUserName(String userName)
{
    return EqualsHelper.nullSafeEquals(userName, AuthenticationUtil.getSystemUserName(), true);
}
 
Example 18
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 19
Source File: HostConfigurableSocketFactory.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean equals(Object obj)
{
    return (obj instanceof HostConfigurableSocketFactory)
            && EqualsHelper.nullSafeEquals(this.host, ((HostConfigurableSocketFactory) obj).host);
}
 
Example 20
Source File: SiteRoutingFileContentStore.java    From alfresco-simple-content-stores with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void onMoveNode(final ChildAssociationRef oldChildAssocRef, final ChildAssociationRef newChildAssocRef)
{
    // only act on active nodes which can actually be in a site
    // only act on active nodes which can actually be in a site
    final NodeRef movedNode = oldChildAssocRef.getChildRef();
    final NodeRef oldParent = oldChildAssocRef.getParentRef();
    final NodeRef newParent = newChildAssocRef.getParentRef();
    if (StoreRef.STORE_REF_WORKSPACE_SPACESSTORE.equals(movedNode.getStoreRef()) && !EqualsHelper.nullSafeEquals(oldParent, newParent))
    {
        LOGGER.debug("Processing onMoveNode for {} from {} to {}", movedNode, oldChildAssocRef, newChildAssocRef);

        // check for actual move-relevant site move
        final Boolean moveRelevant = AuthenticationUtil.runAsSystem(() -> {
            final NodeRef sourceSite = this.resolveSiteForNode(oldParent);
            final NodeRef targetSite = this.resolveSiteForNode(newParent);

            final SiteAwareFileContentStore sourceStore = this.resolveStoreForSite(sourceSite);
            final SiteAwareFileContentStore targetStore = this.resolveStoreForSite(targetSite);

            boolean moveRelevantB = sourceStore != targetStore;
            if (!moveRelevantB && !EqualsHelper.nullSafeEquals(sourceSite, targetSite)
                    && targetStore.isUseSiteFolderInGenericDirectories())
            {
                moveRelevantB = true;
            }
            return Boolean.valueOf(moveRelevantB);
        });

        if (Boolean.TRUE.equals(moveRelevant))
        {
            LOGGER.debug("Node {} was moved to a location for which content should be stored in a different store", movedNode);
            this.checkAndProcessContentPropertiesMove(movedNode);
        }
        else
        {
            LOGGER.debug("Node {} was not moved into a location for which content should be stored in a different store", movedNode);
        }
    }
}