@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); }