Example usage for java.io Serializable equals

List of usage examples for java.io Serializable equals

Introduction

In this page you can find the example usage for java.io Serializable equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Indicates whether some other object is "equal to" this one.

Usage

From source file:org.alfresco.repo.action.evaluator.ComparePropertyValueEvaluator.java

/**
 * @see ActionConditionEvaluatorAbstractBase#evaluateImpl(ActionCondition, NodeRef)
 *///from  w w  w  .  ja v a  2  s. com
public boolean evaluateImpl(ActionCondition ruleCondition, NodeRef actionedUponNodeRef) {
    boolean result = false;

    if (this.nodeService.exists(actionedUponNodeRef) == true) {
        // Get the name value of the node
        QName propertyQName = (QName) ruleCondition.getParameterValue(PARAM_PROPERTY);
        if (propertyQName == null) {
            if (logger.isWarnEnabled())
                logger.warn("ComparePropertyValue - Property is NULL.  Setting to " + DEFAULT_PROPERTY);

            propertyQName = DEFAULT_PROPERTY;
        }

        // Get the original value and the value to match
        Serializable propertyValue = this.nodeService.getProperty(actionedUponNodeRef, propertyQName);
        Serializable compareValue = ruleCondition.getParameterValue(PARAM_VALUE);

        // Get the operation
        ComparePropertyValueOperation operation = null;
        String operationString = (String) ruleCondition.getParameterValue(PARAM_OPERATION);
        if (operationString != null) {
            operation = ComparePropertyValueOperation.valueOf(operationString);
        }

        // Look at the type of the property (assume to be ANY if none found in dictionary)
        QName propertyTypeQName = DataTypeDefinition.ANY;
        PropertyDefinition propertyDefintion = this.dictionaryService.getProperty(propertyQName);
        if (propertyDefintion != null) {
            propertyTypeQName = propertyDefintion.getDataType().getName();
        }

        if (logger.isDebugEnabled()) {
            logger.debug(
                    "Evaluating Property Parameters, propertyQName - [" + propertyQName + "] getInverted? ["
                            + ruleCondition.getInvertCondition() + "] operation [" + operation + "]");
            logger.debug("Compare Value [" + compareValue + "] Actual Value [" + propertyValue + "]");
        }

        // Sort out what to do if the property is a content property
        if (DataTypeDefinition.CONTENT.equals(propertyTypeQName) == true) {
            // Get the content property name
            ContentPropertyName contentProperty = null;
            String contentPropertyString = (String) ruleCondition.getParameterValue(PARAM_CONTENT_PROPERTY);
            if (contentPropertyString == null) {
                //  Error if no content property has been set
                throw new ActionServiceException(MSGID_NO_CONTENT_PROPERTY);
            } else {
                contentProperty = ContentPropertyName.valueOf(contentPropertyString);
            }

            // Get the content data
            if (propertyValue != null) {
                ContentData contentData = DefaultTypeConverter.INSTANCE.convert(ContentData.class,
                        propertyValue);
                switch (contentProperty) {
                case ENCODING: {
                    propertyTypeQName = DataTypeDefinition.TEXT;
                    propertyValue = contentData.getEncoding();
                    break;
                }
                case SIZE: {
                    propertyTypeQName = DataTypeDefinition.LONG;
                    propertyValue = contentData.getSize();
                    break;
                }
                case MIME_TYPE: {
                    propertyTypeQName = DataTypeDefinition.TEXT;
                    propertyValue = contentData.getMimetype();
                    break;
                }
                }
            }
        }

        if (propertyValue != null) {
            // Try and get a matching comparator
            PropertyValueComparator comparator = this.comparators.get(propertyTypeQName);
            if (comparator != null) {
                // Figure out if property is multivalued, compare all of the entries till finding a match
                PropertyDefinition propertyDef = dictionaryService.getProperty(propertyQName);
                if (propertyDef.isMultiValued()) {
                    for (Serializable value : ((ArrayList<Serializable>) propertyValue)) {
                        boolean success = comparator.compare(value, compareValue, operation);
                        if (success) {
                            result = true;
                            break;
                        }
                    }
                } else {
                    // Call the comparator for the property type
                    result = comparator.compare(propertyValue, compareValue, operation);
                }
            } else {
                if (logger.isWarnEnabled()) {
                    logger.warn("Comparator not found for property type " + propertyTypeQName);
                }
                // The default behaviour is to assume the property can only be compared using equals
                if (operation != null && operation != ComparePropertyValueOperation.EQUALS) {
                    // Error since only the equals operation is valid
                    throw new ActionServiceException(MSGID_INVALID_OPERATION,
                            new Object[] { operation.toString(), propertyTypeQName.toString() });
                }

                // Use equals to compare the values
                result = compareValue.equals(propertyValue);
            }
        } else {
            if (logger.isInfoEnabled()) {
                logger.info(
                        "Condition Comparator encountered null value for property [" + propertyTypeQName + "]");
            }
        }
    }

    if (logger.isDebugEnabled()) {
        logger.debug("Returning result " + result);
    }

    return result;
}

From source file:org.alfresco.repo.events.node.EventGenerationBehaviours.java

private Map<String, Property> getChanges(Map<QName, Serializable> before, Map<QName, Serializable> after) {
    Map<String, Property> ret = new HashMap<>();

    Set<QName> intersect = new HashSet<QName>(before.keySet());
    intersect.retainAll(after.keySet());

    Map<QName, Serializable> properties = new HashMap<>();
    for (QName propQName : intersect) {
        Serializable valueBefore = before.get(propQName);
        Serializable valueAfter = after.get(propQName);

        Serializable value = null;
        if (valueBefore == null && valueAfter == null) {
            continue;
        } else if (valueBefore == null && valueAfter != null) {
            value = valueAfter;// w w  w .  j  ava 2  s . c  o m
        } else if (valueBefore != null && valueAfter == null) {
            value = valueAfter;
        } else if (!valueBefore.equals(valueAfter)) {
            value = valueAfter;
        }

        properties.put(propQName, value);
    }

    ret = propertySerializer.serialize(properties);
    return ret;
}

From source file:org.alfresco.repo.node.AbstractNodeServiceImpl.java

/**
 * @see NodeServicePolicies.OnUpdatePropertiesPolicy#onUpdateProperties(NodeRef, Map, Map)
 *//* ww w .  j a va2  s  . c o  m*/
protected void invokeOnUpdateProperties(NodeRef nodeRef, Map<QName, Serializable> before,
        Map<QName, Serializable> after) {
    if (ignorePolicy(nodeRef)) {
        return;
    }

    // Some logging so we can see which properties have been modified
    if (logger.isDebugEnabled() == true) {
        if (before == null) {
            logger.debug(
                    "The properties are being set for the first time.  (nodeRef=" + nodeRef.toString() + ")");
        } else if (after == null) {
            logger.debug("All the properties are being cleared.  (nodeRef=" + nodeRef.toString() + ")");
        } else {
            logger.debug("The following properties have been updated:  (nodeRef=" + nodeRef.toString() + ")");
            for (Map.Entry<QName, Serializable> entry : after.entrySet()) {
                Serializable beforeValue = before.get(entry.getKey());
                if (beforeValue == null) {
                    // Property has been set for the first time
                    logger.debug("   - The property " + entry.getKey().toString()
                            + " has been set for the first time.");
                } else {
                    // Compare the before and after value
                    if (beforeValue.equals(entry.getValue()) == false) {
                        logger.debug("   - The property " + entry.getKey().toString() + " has been updated.");
                    }
                }

            }
        }

    }

    // get qnames to invoke against
    Set<QName> qnames = getTypeAndAspectQNames(nodeRef);
    // execute policy for node type and aspects
    NodeServicePolicies.OnUpdatePropertiesPolicy policy = onUpdatePropertiesDelegate.get(nodeRef, qnames);
    policy.onUpdateProperties(nodeRef, before, after);
}

From source file:org.alfresco.repo.node.db.DbNodeServiceImpl.java

private NodeRef restoreNodeImpl(NodeRef archivedNodeRef, NodeRef destinationParentNodeRef, QName assocTypeQName,
        QName assocQName) {/*from   w ww .java  2s.c om*/
    Pair<Long, NodeRef> archivedNodePair = getNodePairNotNull(archivedNodeRef);
    Long archivedNodeId = archivedNodePair.getFirst();
    Set<QName> existingAspects = nodeDAO.getNodeAspects(archivedNodeId);
    Set<QName> newAspects = new HashSet<QName>(5);
    Map<QName, Serializable> existingProperties = nodeDAO.getNodeProperties(archivedNodeId);
    Map<QName, Serializable> newProperties = new HashMap<QName, Serializable>(11);

    // the node must be a top-level archive node
    if (!existingAspects.contains(ContentModel.ASPECT_ARCHIVED)) {
        throw new AlfrescoRuntimeException("The node to restore is not an archive node");
    }

    // Remove the secondary link to the user that deleted the node
    List<ChildAssociationRef> parentAssocsToRemove = getParentAssocs(archivedNodeRef,
            ContentModel.ASSOC_ARCHIVED_LINK, RegexQNamePattern.MATCH_ALL);
    for (ChildAssociationRef parentAssocToRemove : parentAssocsToRemove) {
        this.removeSecondaryChildAssociation(parentAssocToRemove);
    }

    ChildAssociationRef originalPrimaryParentAssocRef = (ChildAssociationRef) existingProperties
            .get(ContentModel.PROP_ARCHIVED_ORIGINAL_PARENT_ASSOC);
    Serializable originalOwner = existingProperties.get(ContentModel.PROP_ARCHIVED_ORIGINAL_OWNER);
    // remove the archived aspect
    Set<QName> removePropertyQNames = new HashSet<QName>(11);
    Set<QName> removeAspectQNames = new HashSet<QName>(3);
    removePropertyQNames.add(ContentModel.PROP_ARCHIVED_ORIGINAL_PARENT_ASSOC);
    removePropertyQNames.add(ContentModel.PROP_ARCHIVED_BY);
    removePropertyQNames.add(ContentModel.PROP_ARCHIVED_DATE);
    removePropertyQNames.add(ContentModel.PROP_ARCHIVED_ORIGINAL_OWNER);
    removeAspectQNames.add(ContentModel.ASPECT_ARCHIVED);

    // restore the original ownership
    if (originalOwner == null || originalOwner.equals(OwnableService.NO_OWNER)) {
        // The ownable aspect was not present before
        removeAspectQNames.add(ContentModel.ASPECT_OWNABLE);
        removePropertyQNames.add(ContentModel.PROP_OWNER);
    } else {
        newAspects.add(ContentModel.ASPECT_OWNABLE);
        newProperties.put(ContentModel.PROP_OWNER, originalOwner);
    }

    // Prepare the node for restoration: remove old aspects and properties; add new aspects and properties
    nodeDAO.removeNodeProperties(archivedNodeId, removePropertyQNames);
    nodeDAO.removeNodeAspects(archivedNodeId, removeAspectQNames);
    nodeDAO.addNodeProperties(archivedNodeId, newProperties);
    nodeDAO.addNodeAspects(archivedNodeId, newAspects);

    if (destinationParentNodeRef == null) {
        // we must restore to the original location
        destinationParentNodeRef = originalPrimaryParentAssocRef.getParentRef();
    }
    // check the associations
    if (assocTypeQName == null) {
        assocTypeQName = originalPrimaryParentAssocRef.getTypeQName();
    }
    if (assocQName == null) {
        assocQName = originalPrimaryParentAssocRef.getQName();
    }

    // move the node to the target parent, which may or may not be the original parent
    ChildAssociationRef newChildAssocRef = moveNode(archivedNodeRef, destinationParentNodeRef, assocTypeQName,
            assocQName);

    // the node reference has changed due to the store move
    NodeRef restoredNodeRef = newChildAssocRef.getChildRef();
    invokeOnRestoreNode(newChildAssocRef);
    // done
    if (logger.isDebugEnabled()) {
        logger.debug(
                "Restored node: \n" + "   original noderef: " + archivedNodeRef + "\n" + "   restored noderef: "
                        + restoredNodeRef + "\n" + "   new parent: " + destinationParentNodeRef);
    }
    return restoredNodeRef;
}

From source file:org.alfresco.repo.preference.PreferenceServiceImpl.java

@Extend(traitAPI = PreferenceServiceTrait.class, extensionAPI = PreferenceServiceExtension.class)
public void setPreferences(final String userName, final Map<String, Serializable> preferences) {
    // Get the user node reference
    final NodeRef personNodeRef = this.personService.getPerson(userName);
    if (personNodeRef == null) {
        throw new AlfrescoRuntimeException(
                "Cannot update preferences for " + userName + " because he/she does not exist.");
    }/*from   w  w  w.  ja  va 2s  . c  om*/

    if (userCanWritePreferences(userName, personNodeRef)) {
        AuthenticationUtil.runAs(new RunAsWork<Object>() {
            public Object doWork() throws Exception {
                // Apply the preferences aspect if required
                if (PreferenceServiceImpl.this.nodeService.hasAspect(personNodeRef,
                        ContentModel.ASPECT_PREFERENCES) == false) {
                    PreferenceServiceImpl.this.nodeService.addAspect(personNodeRef,
                            ContentModel.ASPECT_PREFERENCES, null);
                }

                try {
                    // Get the current preferences
                    JSONObject jsonPrefs = new JSONObject();
                    ContentReader reader = PreferenceServiceImpl.this.contentService.getReader(personNodeRef,
                            ContentModel.PROP_PREFERENCE_VALUES);
                    if (reader != null) {
                        jsonPrefs = new JSONObject(reader.getContentString());
                    }

                    // Update with the new preference values
                    for (Map.Entry<String, Serializable> entry : preferences.entrySet()) {
                        String key = entry.getKey();

                        // CLOUD-1518: remove extraneous site preferences, if present
                        if (key.startsWith(SHARE_SITES_PREFERENCE_KEY)) {
                            // remove any extraneous keys, if present
                            String siteId = key.substring(SHARE_SITES_PREFERENCE_KEY_LEN);

                            StringBuilder sb = new StringBuilder(SHARE_SITES_PREFERENCE_KEY);
                            sb.append(siteId);
                            sb.append(".favourited");
                            String testKey = sb.toString();
                            if (jsonPrefs.has(testKey)) {
                                jsonPrefs.remove(testKey);
                            }

                            sb = new StringBuilder(SHARE_SITES_PREFERENCE_KEY);
                            sb.append(siteId);
                            sb.append(".createdAt");
                            testKey = sb.toString();
                            if (jsonPrefs.has(testKey)) {
                                jsonPrefs.remove(testKey);
                            }
                        }

                        Serializable value = entry.getValue();
                        if (value != null && value.equals("CURRENT_DATE")) {
                            Date date = new Date();
                            value = ISO8601DateFormat.format(date);
                        }
                        jsonPrefs.put(key, value);
                    }

                    // Save the updated preferences
                    ContentWriter contentWriter = PreferenceServiceImpl.this.contentService
                            .getWriter(personNodeRef, ContentModel.PROP_PREFERENCE_VALUES, true);
                    contentWriter.setEncoding("UTF-8");
                    contentWriter.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
                    contentWriter.putContent(jsonPrefs.toString());
                } catch (JSONException exception) {
                    throw new AlfrescoRuntimeException("Can not update preferences for " + userName
                            + " because there was an error pasing the JSON data.", exception);
                }

                return null;
            }
        }, AuthenticationUtil.SYSTEM_USER_NAME);
    } else {
        // The current user does not have sufficient permissions to update
        // the preferences for this user
        throw new AccessDeniedException("The current user " + AuthenticationUtil.getFullyAuthenticatedUser()
                + " does not have sufficient permissions to update the preferences of the user " + userName);
    }
}

From source file:org.alfresco.repo.virtual.store.VirtualStoreImpl.java

@Override
public List<ChildAssociationRef> getChildAssocsByPropertyValue(Reference parentReference, QName propertyQName,
        Serializable value) {
    List<ChildAssociationRef> allAssociations = getChildAssocs(parentReference, RegexQNamePattern.MATCH_ALL,
            RegexQNamePattern.MATCH_ALL, Integer.MAX_VALUE, false);

    List<ChildAssociationRef> associations = new LinkedList<>();

    for (ChildAssociationRef childAssociationRef : allAssociations) {
        Serializable propertyValue = environment.getProperty(childAssociationRef.getChildRef(), propertyQName);

        if ((value == null && propertyValue == null) || (value != null && value.equals(propertyValue))) {
            associations.add(childAssociationRef);
        }/*  w ww  . jav a  2 s.  c  o  m*/
    }

    return associations;
}

From source file:org.alfresco.repo.virtual.VirtualizationIntegrationTest.java

protected void assertVirtualNode(NodeRef nodeRef, Map<QName, Serializable> expectedProperties) {
    assertTrue(Reference.isReference(nodeRef));

    assertTrue(nodeService.hasAspect(nodeRef, VirtualContentModel.ASPECT_VIRTUAL));
    Set<QName> aspects = nodeService.getAspects(nodeRef);
    assertTrue("Smart virtual node missing virtual aspect",
            aspects.contains(VirtualContentModel.ASPECT_VIRTUAL));
    //ACE-5303 injected properties title and description  require the titled aspect 
    assertTrue("Smaft virtual node missing titled aspect", aspects.contains(ContentModel.ASPECT_TITLED));

    Map<QName, Serializable> nodeProperties = nodeService.getProperties(nodeRef);

    List<QName> mandatoryProperties = Arrays.asList(ContentModel.PROP_STORE_IDENTIFIER,
            ContentModel.PROP_STORE_PROTOCOL, ContentModel.PROP_LOCALE, ContentModel.PROP_MODIFIED,
            ContentModel.PROP_MODIFIER, ContentModel.PROP_CREATED, ContentModel.PROP_CREATOR,
            ContentModel.PROP_NODE_DBID, ContentModel.PROP_DESCRIPTION);

    Set<QName> missingPropreties = new HashSet<>(mandatoryProperties);
    missingPropreties.removeAll(nodeProperties.keySet());

    assertTrue("Mandatory properties are missing" + missingPropreties, missingPropreties.isEmpty());

    assertFalse("ACE-5303 : ContentModel.PROP_TITLE should remain unset",
            nodeProperties.containsKey(ContentModel.PROP_TITLE));

    Set<Entry<QName, Serializable>> epEntries = expectedProperties.entrySet();
    StringBuilder unexpectedBuilder = new StringBuilder();
    for (Entry<QName, Serializable> entry : epEntries) {
        Serializable actualValue = nodeProperties.get(entry.getKey());
        Serializable expectedValue = expectedProperties.get(entry.getKey());
        boolean fail = false;
        String expectedValueStr = null;

        if (expectedValue != null) {
            expectedValueStr = expectedValue.toString();

            if (!expectedValue.equals(actualValue)) {
                fail = true;//from  ww  w .j  ava  2  s . co  m
            }

        } else if (actualValue != null) {
            fail = true;
            expectedValueStr = "<null>";
        }

        if (fail) {
            unexpectedBuilder.append("\n");
            unexpectedBuilder.append(entry.getKey());
            unexpectedBuilder.append(" expected[");
            unexpectedBuilder.append(expectedValueStr);
            unexpectedBuilder.append("] != actua[");
            unexpectedBuilder.append(actualValue);
            unexpectedBuilder.append("]");
        }
    }
    String unexpectedStr = unexpectedBuilder.toString();
    assertTrue("Unexpected property values : " + unexpectedStr, unexpectedStr.isEmpty());
}

From source file:org.alfresco.repo.web.scripts.workflow.TaskInstancesGet.java

/**
 * Determine if the given task should be included in the response.
 * /* w  w  w  .j a  v  a2s  .c  o  m*/
 * @param task The task to check
 * @param filters The list of filters the task must match to be included
 * @return true if the task matches and should therefore be returned
 */
private boolean matches(WorkflowTask task, Map<String, Object> filters) {
    // by default we assume that workflow task should be included
    boolean result = true;

    for (String key : filters.keySet()) {
        Object filterValue = filters.get(key);

        // skip null filters (null value means that filter was not specified)
        if (filterValue != null) {
            if (key.equals(PARAM_EXCLUDE)) {
                ExcludeFilter excludeFilter = (ExcludeFilter) filterValue;
                String type = task.getDefinition().getMetadata().getName()
                        .toPrefixString(this.namespaceService);
                if (excludeFilter.isMatch(type)) {
                    result = false;
                    break;
                }
            } else if (key.equals(PARAM_DUE_BEFORE)) {
                Date dueDate = (Date) task.getProperties().get(WorkflowModel.PROP_DUE_DATE);

                if (!isDateMatchForFilter(dueDate, filterValue, true)) {
                    result = false;
                    break;
                }
            } else if (key.equals(PARAM_DUE_AFTER)) {
                Date dueDate = (Date) task.getProperties().get(WorkflowModel.PROP_DUE_DATE);

                if (!isDateMatchForFilter(dueDate, filterValue, false)) {
                    result = false;
                    break;
                }
            } else if (key.equals(PARAM_PRIORITY)) {
                if (!filterValue.equals(task.getProperties().get(WorkflowModel.PROP_PRIORITY).toString())) {
                    result = false;
                    break;
                }
            } else if (key.equals(PARAM_PROPERTY)) {
                int propQNameEnd = filterValue.toString().indexOf('/');
                if (propQNameEnd < 1) {
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug("Ignoring invalid property filter:" + filterValue.toString());
                    }
                    break;
                }
                String propValue = filterValue.toString().substring(propQNameEnd + 1);
                if (propValue.isEmpty()) {
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug("Ignoring empty property value filter [" + propValue + "]");
                    }
                    break;
                }
                String propQNameStr = filterValue.toString().substring(0, propQNameEnd);
                QName propertyQName;
                try {
                    propertyQName = QName.createQName(propQNameStr, namespaceService);
                } catch (Exception ex) {
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug("Ignoring invalid QName property filter [" + propQNameStr + "]");
                    }
                    break;
                }
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Filtering with property [" + propertyQName.toPrefixString(namespaceService)
                            + "=" + propValue + "]");
                }
                Serializable value = task.getProperties().get(propertyQName);
                if (value != null && !value.equals(propValue)) {
                    result = false;
                    break;
                }
            }
        }
    }

    return result;
}

From source file:org.alfresco.repo.workflow.WorkflowServiceImpl.java

/**
 * Determines if the given user is a member of the pooled actors assigned to the task
 * //from  w  ww .  j a v a  2  s .  c  o m
 * @param task The task instance to check
 * @param username The username to check
 * @return true if the user is a pooled actor, false otherwise
 */
@SuppressWarnings("unchecked")
private boolean isUserInPooledActors(WorkflowTask task, String username) {
    // Get the pooled actors
    Collection<NodeRef> actors = (Collection<NodeRef>) task.getProperties()
            .get(WorkflowModel.ASSOC_POOLED_ACTORS);
    if (actors != null) {
        for (NodeRef actor : actors) {
            QName type = nodeService.getType(actor);
            if (dictionaryService.isSubClass(type, ContentModel.TYPE_PERSON)) {
                Serializable name = nodeService.getProperty(actor, ContentModel.PROP_USERNAME);
                if (name != null && name.equals(username)) {
                    return true;
                }
            } else if (dictionaryService.isSubClass(type, ContentModel.TYPE_AUTHORITY_CONTAINER)) {
                if (isUserInGroup(username, actor)) {
                    // The user is a member of the group
                    return true;
                }
            }
        }
    }
    return false;
}

From source file:org.alfresco.web.bean.actions.BaseActionWizard.java

protected boolean isActionPresent(String actionName) {
    for (Map<String, Serializable> prop : allActionsProperties) {
        Serializable name = prop.get(PROP_ACTION_NAME);
        if (name != null) {
            if (name.equals(actionName)) {
                return true;
            }//from   w  w  w  . ja v a2 s  .  com
        }
    }

    return false;
}