@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj instanceof ReferenceChange) { ReferenceChange that = (ReferenceChange) obj; return super.equals(that) && Objects.equals(this.getLeft(), that.getLeft()) && Objects.equals(this.getRight(), that.getRight()); } return false; }
@Override public void onReferenceChange(ReferenceChange referenceChange) { appendln(" reference changed on '" + referenceChange.getPropertyName() + "' property: '" + referenceChange.getLeft() + "' -> '" + referenceChange.getRight() + "'"); }
@Override public String prettyPrint(PrettyValuePrinter valuePrinter) { Validate.argumentIsNotNull(valuePrinter); return valuePrinter.formatWithQuotes(getPropertyNameWithPath()) + " changed from " + valuePrinter.formatWithQuotes(getLeft()) + " to " + valuePrinter.formatWithQuotes(getRight()); }
assertThat(change.getAffectedLocalId()).isEqualTo("Great Developer"); assertThat(change.getLeft().value()).endsWith("Manager One"); assertThat(change.getRight().value()).endsWith("Manager Second");
@Override public ReferenceChange fromJson(JsonElement json, JsonDeserializationContext context) { JsonObject jsonObject = (JsonObject) json; PropertyChangeStub stub = deserializeStub(jsonObject, context); GlobalId leftRef = context.deserialize(jsonObject.get(LEFT_REFERENCE_FIELD), GlobalId.class); GlobalId rightRef = context.deserialize(jsonObject.get(RIGHT_REFERENCE_FIELD), GlobalId.class); CommitMetadata commitMetadata = deserializeCommitMetadata(jsonObject, context); return new ReferenceChange(stub.id, stub.getPropertyName(), leftRef, rightRef, null, null, ofNullable(commitMetadata)); }
@Override public ReferenceChange calculateChanges(NodePair pair, JaversProperty property) { GlobalId leftId = pair.getLeftGlobalId(property); GlobalId rightId = pair.getRightGlobalId(property); if (Objects.equals(leftId, rightId)) { return null; } return new ReferenceChange(pair.getGlobalId(), property.getName(), leftId, rightId, pair.getLeftPropertyValue(property), pair.getRightPropertyValue(property)); }
public PropertyChange calculateChanges(Object leftValue, Object rightValue, GlobalId affectedId, JaversProperty property) { OptionalType optionalType = ((JaversProperty) property).getType(); JaversType contentType = typeMapper.getJaversType(optionalType.getItemType()); Optional leftOptional = normalize((Optional) leftValue); Optional rightOptional = normalize((Optional) rightValue); if (contentType instanceof ManagedType){ GlobalId leftId = getAndDehydrate(leftOptional, contentType); GlobalId rightId = getAndDehydrate(rightOptional, contentType); if (Objects.equals(leftId, rightId)) { return null; } return new ReferenceChange(affectedId, property.getName(), leftId, rightId, leftValue, rightValue); } if (contentType instanceof PrimitiveOrValueType) { if (leftOptional.equals(rightOptional)) { return null; } return new ValueChange(affectedId, property.getName(), leftOptional, rightOptional); } throw new JaversException(UNSUPPORTED_OPTIONAL_CONTENT_TYPE, contentType); }
@Override public void onReferenceChange(final ReferenceChange referenceChange) { if (isPhantom(referenceChange) || hiddenAuditLog.isPresent()) { return; } builder.append(" from ").append(safeRepresentation(referenceChange.getLeft())).append(" to ").append(safeRepresentation(referenceChange.getRight())); }
@Override public JsonElement toJson(ReferenceChange change, JsonSerializationContext context) { final JsonObject jsonObject = createJsonObject(change, context); jsonObject.add(LEFT_REFERENCE_FIELD, context.serialize(change.getLeft())); jsonObject.add(RIGHT_REFERENCE_FIELD, context.serialize(change.getRight())); return jsonObject; }